1
1
import { Cookie , SetCookie } from "@fastr/headers" ;
2
2
import {
3
- TEXT_SIZES ,
4
- type TextSize ,
3
+ type ColorName ,
4
+ COLORS ,
5
+ type FontName ,
6
+ FONTS ,
5
7
ThemeContext ,
6
- type ThemeName ,
7
8
ThemePrefs ,
8
- THEMES ,
9
9
} from "@keybr/lnf" ;
10
10
import { Component , type ReactNode } from "react" ;
11
11
import { installPolyfills } from "./fullscreen-polyfill.ts" ;
@@ -19,15 +19,15 @@ type Props = {
19
19
20
20
type State = {
21
21
readonly fullscreenState : boolean | null ;
22
- readonly themeName : ThemeName ;
23
- readonly textSize : TextSize ;
22
+ readonly color : ColorName ;
23
+ readonly font : FontName ;
24
24
} ;
25
25
26
26
export class ThemeProvider extends Component < Props , State > {
27
27
override state : State = {
28
28
fullscreenState : false ,
29
- themeName : "light" ,
30
- textSize : "normal " ,
29
+ color : "light" ,
30
+ font : "opensans " ,
31
31
} ;
32
32
33
33
override componentDidMount ( ) : void {
@@ -55,16 +55,16 @@ export class ThemeProvider extends Component<Props, State> {
55
55
}
56
56
57
57
override render ( ) : ReactNode {
58
- const { fullscreenState, themeName , textSize } = this . state ;
58
+ const { fullscreenState, color , font } = this . state ;
59
59
return (
60
60
< ThemeContext . Provider
61
61
value = { {
62
62
fullscreenState,
63
- themeName ,
64
- textSize ,
63
+ color ,
64
+ font ,
65
65
toggleFullscreen : this . toggleFullscreen ,
66
- switchTheme : this . switchTheme ,
67
- switchTextSize : this . switchTextSize ,
66
+ switchColor : this . switchColor ,
67
+ switchFont : this . switchFont ,
68
68
} }
69
69
>
70
70
{ this . props . children }
@@ -92,20 +92,20 @@ export class ThemeProvider extends Component<Props, State> {
92
92
}
93
93
} ;
94
94
95
- readonly switchTheme = ( themeName : ThemeName ) : void => {
96
- this . setState ( { themeName } , ( ) => {
95
+ readonly switchColor = ( color : ColorName ) : void => {
96
+ this . setState ( { color } , ( ) => {
97
97
const { state } = this ;
98
- const { id } = THEMES . findOption ( state . themeName ) ;
99
- document . documentElement . setAttribute ( "data-theme " , id ) ;
98
+ const { id } = COLORS . findOption ( state . color ) ;
99
+ document . documentElement . setAttribute ( "data-color " , id ) ;
100
100
storePrefs ( new ThemePrefs ( state ) ) ;
101
101
} ) ;
102
102
} ;
103
103
104
- readonly switchTextSize = ( textSize : TextSize ) : void => {
105
- this . setState ( { textSize } , ( ) => {
104
+ readonly switchFont = ( font : FontName ) : void => {
105
+ this . setState ( { font } , ( ) => {
106
106
const { state } = this ;
107
- const { id } = TEXT_SIZES . findOption ( state . textSize ) ;
108
- document . documentElement . setAttribute ( "data-text " , id ) ;
107
+ const { id } = FONTS . findOption ( state . font ) ;
108
+ document . documentElement . setAttribute ( "data-font " , id ) ;
109
109
storePrefs ( new ThemePrefs ( state ) ) ;
110
110
} ) ;
111
111
} ;
@@ -117,12 +117,12 @@ function getInitialState(): State {
117
117
if ( document . fullscreenEnabled ) {
118
118
fullscreenState = document . fullscreenElement != null ;
119
119
}
120
- const { themeName , textSize } = ThemePrefs . deserialize (
120
+ const { color , font } = ThemePrefs . deserialize (
121
121
Cookie . parse ( document . cookie ) . get ( ThemePrefs . cookieKey ) ,
122
122
) ;
123
- return { fullscreenState, themeName , textSize } ;
123
+ return { fullscreenState, color : color , font : font } ;
124
124
} catch {
125
- return { fullscreenState : null , themeName : "light" , textSize : "normal " } ;
125
+ return { fullscreenState : null , color : "light" , font : "opensans " } ;
126
126
}
127
127
}
128
128
0 commit comments