Skip to content

Commit 7470ab6

Browse files
committed
Move every component into a single Kotlin source file
1 parent 8539226 commit 7470ab6

File tree

15 files changed

+116
-90
lines changed

15 files changed

+116
-90
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.huanshankeji.compose.material
2+
3+
import androidx.compose.runtime.Composable
4+
5+
expect /*value*/ class ButtonScope {
6+
@Composable
7+
fun Label(text: String)
8+
}
9+
10+
@Composable
11+
expect fun Button(onClick: () -> Unit, content: @Composable ButtonScope.() -> Unit)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.huanshankeji.compose.material
2+
3+
import androidx.compose.runtime.Composable
4+
5+
@Composable
6+
expect fun Card(content: @Composable () -> Unit)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.huanshankeji.compose.material
2+
3+
import androidx.compose.runtime.Composable
4+
import com.huanshankeji.compose.material.icon.MaterialIcon
5+
6+
@Composable
7+
expect fun Icon(materialIcon: MaterialIcon)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.huanshankeji.compose.material
2+
3+
import androidx.compose.runtime.Composable
4+
5+
@Composable
6+
expect fun IconButton(onClick: () -> Unit, content: @Composable () -> Unit)
Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,6 @@ package com.huanshankeji.compose.material
33
import androidx.compose.runtime.Composable
44
import com.huanshankeji.compose.material.icon.MaterialIcon
55

6-
expect /*value*/ class ButtonScope {
7-
@Composable
8-
fun Label(text: String)
9-
}
10-
11-
@Composable
12-
expect fun Button(onClick: () -> Unit, content: @Composable ButtonScope.() -> Unit)
13-
14-
15-
@Composable
16-
expect fun Card(content: @Composable () -> Unit)
17-
18-
19-
@Composable
20-
expect fun Icon(materialIcon: MaterialIcon)
21-
22-
23-
@Composable
24-
expect fun IconButton(onClick: () -> Unit, content: @Composable () -> Unit)
25-
26-
276
expect class NavigationIconScope {
287
@Composable
298
fun NavButton(onClick: () -> Unit, content: @Composable () -> Unit)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.huanshankeji.compose.material
2+
3+
import androidx.compose.runtime.Composable
4+
import dev.petuska.kmdc.button.Label
5+
import dev.petuska.kmdc.button.MDCButton
6+
import dev.petuska.kmdc.button.MDCButtonScope
7+
import org.w3c.dom.HTMLButtonElement
8+
9+
actual class ButtonScope(val mdcButtonScope: MDCButtonScope<HTMLButtonElement>) {
10+
@Composable
11+
actual fun Label(text: String) =
12+
mdcButtonScope.Label(text)
13+
}
14+
15+
@Composable
16+
actual fun Button(onClick: () -> Unit, content: @Composable ButtonScope.() -> Unit) =
17+
MDCButton(attrs = { onClick { onClick() } }) { ButtonScope(this).content() }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.huanshankeji.compose.material
2+
3+
import androidx.compose.runtime.Composable
4+
import dev.petuska.kmdc.card.MDCCard
5+
6+
@Composable
7+
actual fun Card(content: @Composable () -> Unit) =
8+
MDCCard { content() }
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.huanshankeji.compose.material
2+
3+
import androidx.compose.runtime.Composable
4+
import com.huanshankeji.compose.material.icon.MaterialIcon
5+
import dev.petuska.kmdcx.icons.MDCIconSpan
6+
7+
/**
8+
* There is often a better alternative of adding the CSS rule to the parent element to using this composable directly.
9+
*/
10+
@Composable
11+
actual fun Icon(materialIcon: MaterialIcon) =
12+
MDCIconSpan(materialIcon.mdcIcon)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.huanshankeji.compose.material
2+
3+
import androidx.compose.runtime.Composable
4+
import dev.petuska.kmdc.icon.button.MDCIconButton
5+
6+
@Composable
7+
actual fun IconButton(onClick: () -> Unit, content: @Composable () -> Unit) =
8+
MDCIconButton(attrs = {
9+
onClick { onClick() }
10+
}) { content() }
Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,8 @@ package com.huanshankeji.compose.material
22

33
import androidx.compose.runtime.Composable
44
import com.huanshankeji.compose.material.icon.MaterialIcon
5-
import dev.petuska.kmdc.button.Label
6-
import dev.petuska.kmdc.button.MDCButton
7-
import dev.petuska.kmdc.button.MDCButtonScope
8-
import dev.petuska.kmdc.card.MDCCard
9-
import dev.petuska.kmdc.icon.button.MDCIconButton
105
import dev.petuska.kmdc.top.app.bar.*
11-
import dev.petuska.kmdcx.icons.MDCIconSpan
126
import dev.petuska.kmdcx.icons.mdcIcon
13-
import org.jetbrains.compose.web.dom.Text
14-
import org.w3c.dom.HTMLButtonElement
15-
16-
actual class ButtonScope(val mdcButtonScope: MDCButtonScope<HTMLButtonElement>) {
17-
@Composable
18-
actual fun Label(text: String) =
19-
mdcButtonScope.Label(text)
20-
}
21-
22-
@Composable
23-
actual fun Button(onClick: () -> Unit, content: @Composable ButtonScope.() -> Unit) =
24-
MDCButton(attrs = { onClick { onClick() } }) { ButtonScope(this).content() }
25-
26-
27-
@Composable
28-
actual fun Card(content: @Composable () -> Unit) =
29-
MDCCard { content() }
30-
31-
32-
/**
33-
* There is often a better alternative of adding the CSS rule to the parent element to using this composable directly.
34-
*/
35-
@Composable
36-
actual fun Icon(materialIcon: MaterialIcon) =
37-
MDCIconSpan(materialIcon.mdcIcon)
38-
39-
40-
@Composable
41-
actual fun IconButton(onClick: () -> Unit, content: @Composable () -> Unit) =
42-
MDCIconButton(attrs = {
43-
onClick { onClick() }
44-
}) { content() }
45-
467

478
actual class NavigationIconScope(val mdcTopAppBarSectionScope: MDCTopAppBarSectionScope) {
489
@Composable
@@ -51,7 +12,7 @@ actual class NavigationIconScope(val mdcTopAppBarSectionScope: MDCTopAppBarSecti
5112

5213
@Composable
5314
actual fun MaterialIconNavButton(onClick: () -> Unit, materialIcon: MaterialIcon) =
54-
mdcTopAppBarSectionScope.NavButton(attrs = { mdcIcon() }) { Text(materialIcon.mdcIcon.type) }
15+
mdcTopAppBarSectionScope.NavButton(attrs = { mdcIcon() }) { org.jetbrains.compose.web.dom.Text(materialIcon.mdcIcon.type) }
5516
}
5617

5718
actual class TopAppBarActionsScope(val mdcTopAppBarSectionScope: MDCTopAppBarSectionScope) {
@@ -64,7 +25,7 @@ actual class TopAppBarActionsScope(val mdcTopAppBarSectionScope: MDCTopAppBarSec
6425
onClick: () -> Unit,
6526
materialIcon: MaterialIcon
6627
) =
67-
mdcTopAppBarSectionScope.ActionButton(attrs = { mdcIcon() }) { Text(materialIcon.mdcIcon.type) }
28+
mdcTopAppBarSectionScope.ActionButton(attrs = { mdcIcon() }) { org.jetbrains.compose.web.dom.Text(materialIcon.mdcIcon.type) }
6829
}
6930

7031
@Composable

0 commit comments

Comments
 (0)