Skip to content

Commit 545862f

Browse files
committed
Move switches to different page
1 parent 675b5d5 commit 545862f

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

src/jsMain/kotlin/Application.kt

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import org.jetbrains.compose.web.renderComposableInBody
2525
import pages.CatFactPage
2626
import pages.HelloWorldPage
2727
import pages.HomePage
28+
import pages.SwitchesPage
2829

2930
fun main() {
3031
val client =
@@ -68,6 +69,9 @@ fun main() {
6869
route("/") {
6970
HomePage()
7071
}
72+
route("/switches") {
73+
SwitchesPage()
74+
}
7175
route("/hello-world") {
7276
HelloWorldPage()
7377
}

src/jsMain/kotlin/components/Switch.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import org.jetbrains.compose.web.dom.Text
2121
internal class SwitchStyles(
2222
invertedColors: Boolean,
2323
) : StyleSheet() {
24+
val animationDuration = 0.3.s
25+
2426
val switch by style {
2527
position(Position.Relative)
2628
display(DisplayStyle.InlineBlock)
@@ -53,7 +55,7 @@ internal class SwitchStyles(
5355
},
5456
)
5557
transitions {
56-
defaultDuration(0.4.s)
58+
"" { duration = animationDuration }
5759
}
5860
borderRadius(34.px)
5961

@@ -82,7 +84,7 @@ internal class SwitchStyles(
8284
},
8385
)
8486
transitions {
85-
defaultDuration(0.4.s)
87+
"" { duration = animationDuration }
8688
}
8789
borderRadius(50.percent)
8890
}

src/jsMain/kotlin/pages/HomePage.kt

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
package pages
22

33
import androidx.compose.runtime.Composable
4-
import androidx.compose.runtime.mutableStateOf
54
import app.softwork.routingcompose.NavLink
6-
import components.Switch
75
import org.jetbrains.compose.web.dom.Text
86

97
@Composable
108
fun HomePage() {
11-
val state = mutableStateOf(false)
12-
Switch("123", state = state)
13-
Switch("Disabled", disabled = true, state = state)
149
NavLink("/hello-world") {
1510
Text("To Hello world!")
1611
}
1712
NavLink("/cat-fact") {
1813
Text("To Cat Facts!")
1914
}
15+
NavLink("/switches") {
16+
Text("To Switches!")
17+
}
2018
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package pages
2+
3+
import androidx.compose.runtime.Composable
4+
import androidx.compose.runtime.mutableStateOf
5+
import app.softwork.routingcompose.NavLink
6+
import components.Switch
7+
import org.jetbrains.compose.web.dom.Text
8+
9+
@Composable
10+
fun SwitchesPage() {
11+
val state = mutableStateOf(false)
12+
Switch("123", state = state)
13+
Switch("Disabled", disabled = true, state = state)
14+
15+
NavLink("/") {
16+
Text("Back to the main page")
17+
}
18+
}

0 commit comments

Comments
 (0)