File tree Expand file tree Collapse file tree 2 files changed +33
-8
lines changed Expand file tree Collapse file tree 2 files changed +33
-8
lines changed Original file line number Diff line number Diff line change @@ -6,20 +6,50 @@ import components.Layout
6
6
import components.PageContent
7
7
import components.PageFooter
8
8
import components.PageHeader
9
- import org.jetbrains.compose.web.css.*
9
+ import org.jetbrains.compose.web.css.Color
10
+ import org.jetbrains.compose.web.css.Style
10
11
import org.jetbrains.compose.web.dom.*
11
12
import org.jetbrains.compose.web.renderComposableInBody
12
13
14
+ enum class Theme { Dark , Light }
15
+
13
16
fun main () {
14
17
renderComposableInBody {
18
+ var theme by remember { mutableStateOf(Theme .Light ) }
15
19
Style {
20
+ root {
21
+ when (theme) {
22
+ Theme .Light -> {
23
+ ThemeVariables .mainColor(Color (" #333" ))
24
+ ThemeVariables .accentColor(Color (" #6200ea" ))
25
+ ThemeVariables .backgroundColor(Color (" #f0f0f0" ))
26
+ }
27
+ Theme .Dark -> {
28
+ ThemeVariables .mainColor(Color (" #f0f0f0" ))
29
+ ThemeVariables .accentColor(Color (" #6200ea" ))
30
+ ThemeVariables .backgroundColor(Color (" #333" ))
31
+ }
32
+ }
33
+ }
16
34
}
17
35
18
36
Style (BaseStyles )
19
37
20
38
Layout {
21
39
PageHeader {
22
40
H1 { Text (" My delicious site" ) }
41
+ Div {
42
+ Button (attrs = {
43
+ onClick {
44
+ theme = when (theme) {
45
+ Theme .Light -> Theme .Dark
46
+ Theme .Dark -> Theme .Light
47
+ }
48
+ }
49
+ }) {
50
+ Text (" Switch theme" )
51
+ }
52
+ }
23
53
}
24
54
PageContent {
25
55
var counter: Int by remember { mutableStateOf(0 ) }
Original file line number Diff line number Diff line change @@ -8,12 +8,6 @@ object ThemeVariables {
8
8
9
9
object BaseStyles : StyleSheet() {
10
10
init {
11
- root {
12
- ThemeVariables .mainColor(Color (" #333" ))
13
- ThemeVariables .accentColor(Color (" #6200ea" ))
14
- ThemeVariables .backgroundColor(Color (" #f0f0f0" ))
15
- }
16
-
17
11
" #root" style {
18
12
display(DisplayStyle .Flex )
19
13
flexDirection(FlexDirection .Column )
@@ -28,8 +22,9 @@ object BaseStyles : StyleSheet() {
28
22
flex(0 , 0 , 60 .px)
29
23
display(DisplayStyle .Flex )
30
24
alignItems(AlignItems .Center )
31
- justifyContent(JustifyContent .Center )
25
+ justifyContent(JustifyContent .SpaceBetween )
32
26
fontSize(1.5 .cssRem)
27
+ padding(10 .px)
33
28
}
34
29
35
30
" main" style {
You can’t perform that action at this time.
0 commit comments