File tree Expand file tree Collapse file tree 13 files changed +148
-79
lines changed
SelectTutorial/TutorialOverview Expand file tree Collapse file tree 13 files changed +148
-79
lines changed Original file line number Diff line number Diff line change 11import * as React from 'react'
2- import { ConfigProvider } from '@alifd/next'
3- import enUS from '@alifd/next/lib/locale/en-us'
4- import ErrorBoundary from './components/ErrorBoundary'
5- import Workspace from './components/Workspace'
6- import { ThemeProvider } from 'emotion-theming'
7- import theme from './styles/theme'
2+ import Provider from './Provider'
83import Routes from './Routes'
94
105const App = ( ) => (
11- /* @ts -ignore invalid in enUS locale typings for @alifd/next@1.20.20 https://github.com/alibaba-fusion/next/commit/e3b934b */
12- < ConfigProvider locale = { enUS } >
13- < Workspace >
14- < ErrorBoundary >
15- < ThemeProvider theme = { theme } >
16- < Routes />
17- </ ThemeProvider >
18- </ ErrorBoundary >
19- </ Workspace >
20- </ ConfigProvider >
6+ < Provider >
7+ < Routes />
8+ </ Provider >
219)
2210
2311export default App
Original file line number Diff line number Diff line change 1+ import * as React from 'react'
2+ import { css , jsx } from '@emotion/core'
3+ import { ConfigProvider } from '@alifd/next'
4+ import enUS from '@alifd/next/lib/locale/en-us'
5+ import ErrorBoundary from './components/ErrorBoundary'
6+ import { ThemeProvider } from 'emotion-theming'
7+ import { AdminProvider } from './services/admin/context'
8+ import theme , { Theme } from './styles/theme'
9+
10+ type Props = {
11+ children : React . ReactElement
12+ }
13+
14+ const styles = {
15+ page : ( theme : Theme ) => ( {
16+ display : 'flex' as 'flex' ,
17+ position : 'relative' as 'relative' ,
18+ margin : 0 ,
19+ width : '100vw' ,
20+ maxWidth : '100%' ,
21+ minHeight : '100vh' ,
22+ backgroundColor : theme [ '$color-white' ] ,
23+ overflow : 'auto' ,
24+ } ) ,
25+ }
26+
27+ const Provider = ( props : Props ) => (
28+ /* @ts -ignore invalid in enUS locale typings for @alifd/next@1.20.20 https://github.com/alibaba-fusion/next/commit/e3b934b */
29+ < ConfigProvider locale = { enUS } >
30+ < div css = { styles . page } >
31+ < AdminProvider >
32+ < ErrorBoundary >
33+ < ThemeProvider theme = { theme } > { props . children } </ ThemeProvider >
34+ </ ErrorBoundary >
35+ </ AdminProvider >
36+ </ div >
37+ </ ConfigProvider >
38+ )
39+
40+ export default Provider
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -11,17 +11,19 @@ interface Props {
1111
1212const styles = {
1313 page : {
14- position : 'relative' as 'relative' ,
1514 display : 'flex' as 'flex' ,
1615 flexDirection : 'column' as 'column' ,
1716 alignItems : 'center' as 'center' ,
1817 justifyContent : 'center' as 'center' ,
19- height : '100vh' ,
20- width : '100vw' ,
18+ position : 'absolute' as 'absolute' ,
19+ top : 0 ,
20+ bottom : 0 ,
21+ left : 0 ,
22+ right : 0 ,
2123 } ,
2224 processes : {
2325 padding : '0 1rem' ,
24- position : 'fixed ' as 'fixed ' ,
26+ position : 'absolute ' as 'absolute ' ,
2527 bottom : 0 ,
2628 left : 0 ,
2729 right : 0 ,
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ const styles = {
1111 display : 'flex' as 'flex' ,
1212 flexDirection : 'column' as 'column' ,
1313 width : '100%' ,
14+ height : '100%' ,
1415 } ,
1516 nav : ( theme : Theme ) => ( {
1617 height : theme [ '$nav-height' ] ,
@@ -22,6 +23,7 @@ const styles = {
2223 cursor : 'pointer' ,
2324 } ) ,
2425 content : {
26+ height : '100%' ,
2527 paddingBottom : '5rem' ,
2628 } ,
2729 header : ( theme : Theme ) => ( {
@@ -45,7 +47,7 @@ const styles = {
4547 paddingLeft : '1.1rem' ,
4648 } ,
4749 footer : ( theme : Theme ) => ( {
48- position : 'fixed ' as 'fixed ' ,
50+ position : 'absolute ' as 'absolute ' ,
4951 bottom : 0 ,
5052 left : 0 ,
5153 right : 0 ,
@@ -54,10 +56,11 @@ const styles = {
5456 alignItems : 'center' as 'center' ,
5557 justifyContent : 'flex-end' as 'flex-end' ,
5658 height : theme [ '$footer-height' ] ,
57- padding : '1rem ' ,
59+ padding : '0rem 0.5rem ' ,
5860 paddingRight : '2rem' ,
5961 backgroundColor : theme [ '$color-black' ] ,
6062 width : '100%' ,
63+ zIndex : 100 ,
6164 } ) ,
6265}
6366
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ import BetaBadge from '../../components/BetaBadge'
66import { css , jsx } from '@emotion/core'
77import Button from '../../components/Button'
88import { Theme } from '../../styles/theme'
9+ import { ADMIN_MODE } from '../../environment'
10+ import AdminToggle from '../../services/admin/AdminToggle'
911
1012const styles = {
1113 page : ( theme : Theme ) => ( {
@@ -104,6 +106,7 @@ export const StartPage = (props: Props) => (
104106 </ div >
105107 ) }
106108 </ div >
109+ { ADMIN_MODE ? < AdminToggle /> : null }
107110 </ div >
108111)
109112
Original file line number Diff line number Diff line change @@ -56,23 +56,23 @@ const styles = {
5656 fontSize : '1rem' ,
5757 lineHeight : '1rem' ,
5858 padding : '10px 0rem' ,
59- position : 'fixed ' as 'fixed ' ,
59+ position : 'absolute ' as 'absolute ' ,
6060 bottom : 0 ,
6161 left : 0 ,
6262 right : 0 ,
6363 color : theme [ '$color-white' ] ,
6464 zIndex : 1000 ,
6565 } ) ,
6666 completeFooter : {
67- position : 'fixed ' as 'fixed ' ,
67+ position : 'absolute ' as 'absolute ' ,
6868 bottom : 0 ,
6969 left : 0 ,
7070 right : 0 ,
7171 zIndex : 1000 ,
7272 } ,
7373 processes : ( theme : Theme ) => ( {
7474 padding : '0 1rem' ,
75- position : 'fixed ' as 'fixed ' ,
75+ position : 'absolute ' as 'absolute ' ,
7676 bottom : theme [ '$footer-height' ] ,
7777 left : 0 ,
7878 right : 0 ,
Original file line number Diff line number Diff line change @@ -14,3 +14,6 @@ export const TUTORIAL_LIST_URL: string = process.env.REACT_APP_TUTORIAL_LIST_URL
1414
1515// config variables
1616export const DISPLAY_RUN_TEST_BUTTON = ( process . env . CODEROAD_DISPLAY_RUN_TEST_BUTTON || 'true' ) . toLowerCase ( ) === 'true'
17+
18+ export const ADMIN_MODE =
19+ ( process . env . CODEROAD_ADMIN_MODE || process . env . STORYBOOK_ADMIN_MODE || '' ) . toLowerCase ( ) === 'true'
Original file line number Diff line number Diff line change 1+ import * as React from 'react'
2+ import { css , jsx } from '@emotion/core'
3+ import { Form , Switch } from '@alifd/next'
4+ import AdminContext , { AdminContextType } from './context'
5+
6+ type Props = { }
7+
8+ const AdminToggle = ( props : Props ) => {
9+ const { state, dispatch } = React . useContext < AdminContextType > ( AdminContext )
10+ return (
11+ < Form . Item label = "Admin Mode" >
12+ < Switch
13+ checked = { state . adminMode }
14+ onChange = { ( checked : boolean ) => dispatch ( { type : checked ? 'ADMIN_MODE_ON' : 'ADMIN_MODE_OFF' } ) }
15+ />
16+ </ Form . Item >
17+ )
18+ }
19+
20+ export default AdminToggle
Original file line number Diff line number Diff line change 1+ import * as React from 'react'
2+
3+ type Props = {
4+ children : React . ReactElement
5+ }
6+
7+ type State = {
8+ adminMode : boolean
9+ }
10+
11+ type Action = { type : 'ADMIN_MODE_ON' | 'ADMIN_MODE_OFF' }
12+
13+ export type AdminContextType = { state : State ; dispatch : ( action : Action ) => void }
14+
15+ const AdminContext = React . createContext < AdminContextType > ( {
16+ state : { adminMode : false } ,
17+ dispatch : ( ) => { } ,
18+ } )
19+
20+ export default AdminContext
21+
22+ export const AdminProvider = ( props : Props ) => {
23+ const [ state , dispatch ] = React . useReducer (
24+ ( state : State , action : Action ) => {
25+ console . log ( 'action.type' , action . type )
26+ switch ( action . type ) {
27+ case 'ADMIN_MODE_ON' :
28+ return { ...state , adminMode : true }
29+ case 'ADMIN_MODE_OFF' :
30+ return { ...state , adminMode : false }
31+ default :
32+ throw new Error ( )
33+ }
34+ } ,
35+ { adminMode : false } ,
36+ )
37+ return < AdminContext . Provider value = { { state, dispatch } } > { props . children } </ AdminContext . Provider >
38+ }
39+
40+ export const AdminConsumer = AdminContext . Consumer
You can’t perform that action at this time.
0 commit comments