11import React , { useMemo } from "react" ;
2- import { useConfig , withWQ } from "@wq/react" ;
2+ import { withWQ } from "@wq/react" ;
33import {
44 MD2LightTheme ,
55 MD3LightTheme ,
@@ -18,37 +18,45 @@ const THEMES = {
1818 "dark-3" : MD3DarkTheme ,
1919} ;
2020
21- const defaultConfig = {
22- material : {
23- theme : {
24- primary : "#7500ae" ,
25- secondary : "#0088bd" ,
26- } ,
27- } ,
21+ const defaultTheme = {
22+ type : "light" ,
23+ version : 3 ,
24+ primary : "#7500ae" ,
25+ secondary : "#0088bd" ,
2826} ;
2927
30- function Root ( { children } ) {
31- const { material : { theme : configTheme } = { } } = useConfig ( ) ,
32- theme = useMemo ( ( ) => createTheme ( configTheme ) , [ configTheme ] ) ;
33- return < PaperProvider theme = { theme } > { children } </ PaperProvider > ;
28+ function Root ( { children, theme } ) {
29+ if ( theme ) {
30+ return < ThemeRoot theme = { theme } > { children } </ ThemeRoot > ;
31+ } else {
32+ return children || null ;
33+ }
34+ }
35+
36+ function ThemeRoot ( { children, theme } ) {
37+ const paperTheme = useMemo ( ( ) => createTheme ( theme ) , [ theme ] ) ;
38+ return < PaperProvider theme = { paperTheme } > { children } </ PaperProvider > ;
3439}
3540
3641export default withWQ ( Root , {
3742 defaults : {
38- config : defaultConfig ,
3943 components : { ...components , useMinWidth } ,
40- icons : { ...icons , List : icons . ListIcon } ,
44+ icons : { ...icons , List : icons . ListIcon , Menu : icons . MenuIcon } ,
4145 } ,
4246} ) ;
4347
44- function createTheme ( {
45- type = "light" ,
46- version = 3 ,
47- primary,
48- secondary,
49- background,
50- } ) {
51- const colors = { } ,
48+ function createTheme ( theme ) {
49+ if ( theme === true ) {
50+ theme = defaultTheme ;
51+ }
52+ const {
53+ type = "light" ,
54+ version = 3 ,
55+ primary,
56+ secondary,
57+ background,
58+ } = theme || { } ,
59+ colors = { } ,
5260 base = THEMES [ `${ type } -${ version } ` ] ;
5361 if ( ! base ) {
5462 console . warn ( `Unknown base theme type=${ type } version=${ version } ` ) ;
0 commit comments