1- import { AppBar , CssBaseline , Toolbar , Typography } from '@material-ui/core' ;
1+ import {
2+ AppBar ,
3+ CssBaseline ,
4+ IconButton ,
5+ Theme ,
6+ Toolbar ,
7+ Typography ,
8+ WithStyles ,
9+ withStyles ,
10+ } from '@material-ui/core' ;
211import { MuiThemeProvider } from '@material-ui/core/styles' ;
12+ import { SvgIconProps } from '@material-ui/core/SvgIcon' ;
313import { JSONSchema7 } from 'json-schema' ;
4- import React , { ComponentType } from 'react' ;
14+ import React , { ComponentType , createElement } from 'react' ;
515import { Observable as obs } from 'rxjs' ;
616import {
717 AuthorizationProvider ,
@@ -11,12 +21,16 @@ import {
1121 Notifications ,
1222 withAuthorization ,
1323} from './components' ;
14- import { SqlStreamStore } from './components/Icons' ;
24+ import {
25+ LightbulbFull ,
26+ LightbulbOutline ,
27+ SqlStreamStore ,
28+ } from './components/Icons' ;
1529import { connect , createState } from './reactive' ;
1630import { actions , store , Viewer } from './stream-store' ;
17- import theme from './theme ' ;
31+ import themes from './themes ' ;
1832import { AuthorizationProps , HalLink , HalLinks } from './types' ;
19- import { mediaTypes } from './utils' ;
33+ import { mediaTypes , preventDefault } from './utils' ;
2034
2135const getSelfAlias = ( links : HalLinks ) =>
2236 Object . keys ( links )
@@ -39,6 +53,7 @@ interface SqlStreamStoreBrowserState {
3953 mediaType : string ;
4054 _links : HalLinks ;
4155 self : HalLink ;
56+ theme : Theme ;
4257 forms : { [ rel : string ] : JSONSchema7 } ;
4358}
4459const state$ = createState < SqlStreamStoreBrowserState > (
@@ -48,6 +63,7 @@ const state$ = createState<SqlStreamStoreBrowserState>(
4863 store . hal$ . forms$ . map ( forms => [ 'forms' , ( ) => forms ] ) ,
4964 store . hal$ . loading$ . map ( loading => [ 'loading' , ( ) => loading ] ) ,
5065 store . hal$ . mediaType$ . map ( mediaType => [ 'mediaType' , ( ) => mediaType ] ) ,
66+ themes . theme$ . map ( theme => [ 'theme' , ( ) => theme ] ) ,
5167 ) ,
5268 obs . of ( {
5369 _links : { } ,
@@ -57,6 +73,7 @@ const state$ = createState<SqlStreamStoreBrowserState>(
5773 self : {
5874 href : '' ,
5975 } ,
76+ theme : themes . defaultTheme ,
6077 } ) ,
6178) ;
6279
@@ -70,26 +87,50 @@ const initialNavigation = ({ authorization }: AuthorizationProps) =>
7087 authorization ,
7188 ) ;
7289
73- const Hero = ( ) => (
74- < AppBar position = { 'static' } >
75- < Toolbar >
76- < SqlStreamStore color = { 'action' } />
77- < Typography variant = { 'h6' } color = { 'inherit' } >
78- Sql Stream Store
79- </ Typography >
80- </ Toolbar >
81- </ AppBar >
90+ const lightbulbs : { [ key : string ] : ComponentType < SvgIconProps > } = {
91+ dark : LightbulbFull ,
92+ light : LightbulbOutline ,
93+ } ;
94+
95+ const heroStyle = {
96+ themeToggle : {
97+ marginLeft : 'auto' ,
98+ } ,
99+ } ;
100+ interface HeroProps {
101+ theme : Theme ;
102+ }
103+
104+ const onThemeToggle = preventDefault ( ( ) => themes . actions . type . next ( void 0 ) ) ;
105+
106+ const Hero : ComponentType < HeroProps > = withStyles ( heroStyle ) (
107+ ( { theme, classes } : HeroProps & WithStyles < typeof heroStyle > ) => (
108+ < AppBar position = { 'static' } >
109+ < Toolbar >
110+ < SqlStreamStore color = { 'action' } />
111+ < Typography variant = { 'h6' } color = { 'inherit' } >
112+ Sql Stream Store
113+ </ Typography >
114+ < IconButton
115+ onClick = { onThemeToggle }
116+ className = { classes . themeToggle }
117+ >
118+ { createElement ( lightbulbs [ theme . palette . type ] ) }
119+ </ IconButton >
120+ </ Toolbar >
121+ </ AppBar >
122+ ) ,
82123) ;
83124
84125const SqlStreamStoreBrowser : ComponentType <
85126 SqlStreamStoreBrowserState
86127> = withAuthorization ( ) (
87128 mount < SqlStreamStoreBrowserState & AuthorizationProps > ( initialNavigation ) (
88- ( { loading, ...props } ) => (
129+ ( { loading, theme , ...props } ) => (
89130 < MuiThemeProvider theme = { theme } >
90131 < div >
91132 < CssBaseline />
92- < Hero />
133+ < Hero theme = { theme } />
93134 < Loading open = { loading } />
94135 < NavigationProvider onNavigate = { onNavigate } >
95136 < Viewer { ...props } />
0 commit comments