Skip to content

Commit 07a25f9

Browse files
committed
Initially add TopAppBarScaffold and some definitions related to icons
1 parent 73c28dc commit 07a25f9

File tree

7 files changed

+91
-2
lines changed

7 files changed

+91
-2
lines changed

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Compose Multiplatform Material wrappers
22

3-
Compose Multiplatform Material Design component wrappers for Desktop, Android, and Web (mainly based on [KMDC](https://github.com/mpetuska/kmdc))
3+
Some simple Compose Multiplatform Material Design component wrappers for desktop, Android, and web (mainly based on [KMDC](https://github.com/mpetuska/kmdc))
44

5-
We try to make sure the styles of the `Composable` components follow those in `com.huanshankeji.compose.material`, with, however, only a subset of the `Composable` arguments supported due to the API differences and limitations of the JS components this project depends on.
5+
We try to make the styles of the composable components follow those of the desktop and Android ones in `com.huanshankeji.compose.material`, meanwhile being compatible with the Web APIs. However, only a subset of the composable arguments is supported due to the API differences and limitations of the web composables this project depends on.
6+
7+
Customizing styles (using `Modifier`s for desktop and Android, and `attrs: AttrBuilderContext<*>?` for web) is not supported yet.
8+
9+
Visual consistency across different platforms is not guaranteed.
10+
11+
## Supported components
12+
13+
- `Button`
14+
- `TopAppBarScaffold`

compose-multiplatform-material/src/commonMain/kotlin/com/huanshankeji/compose/material/Components.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,13 @@ expect /*value*/ class ButtonScope {
99

1010
@Composable
1111
expect fun Button(onClick: () -> Unit, content: @Composable ButtonScope.() -> Unit)
12+
13+
14+
//expect class TopAppBarActionsScope
15+
@Composable
16+
expect fun TopAppBarScaffold(
17+
title: @Composable () -> Unit,
18+
navigationIcon: @Composable (() -> Unit)? = null,
19+
actions: @Composable /*TopAppBarActionsScope.*/() -> Unit = {},
20+
content: @Composable () -> Unit
21+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.huanshankeji.compose.material.icons
2+
3+
expect class IconType
4+
5+
expect object Icons {
6+
val Search : IconType
7+
}

compose-multiplatform-material/src/jsMain/kotlin/com/huanshankeji/compose/material/Components.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable
44
import dev.petuska.kmdc.button.Label
55
import dev.petuska.kmdc.button.MDCButton
66
import dev.petuska.kmdc.button.MDCButtonScope
7+
import dev.petuska.kmdc.top.app.bar.*
78
import org.w3c.dom.HTMLButtonElement
89

910
actual class ButtonScope(val mdcButtonScope: MDCButtonScope<HTMLButtonElement>) {
@@ -15,3 +16,31 @@ actual class ButtonScope(val mdcButtonScope: MDCButtonScope<HTMLButtonElement>)
1516
@Composable
1617
actual fun Button(onClick: () -> Unit, content: @Composable ButtonScope.() -> Unit) =
1718
MDCButton(attrs = { onClick { onClick() } }) { ButtonScope(this).content() }
19+
20+
21+
@Composable
22+
actual fun TopAppBarScaffold(
23+
title: @Composable () -> Unit,
24+
navigationIcon: @Composable (() -> Unit)?,
25+
actions: @Composable () -> Unit,
26+
content: @Composable () -> Unit
27+
) =
28+
MDCTopAppBar {
29+
TopAppBar {
30+
Row {
31+
Section(align = MDCTopAppBarSectionAlign.Start) {
32+
navigationIcon?.let { NavButton { it() } }
33+
Title { title() }
34+
}
35+
Section(
36+
align = MDCTopAppBarSectionAlign.End,
37+
attrs = {
38+
attr("role", "toolbar")
39+
}
40+
) {
41+
actions()
42+
}
43+
}
44+
}
45+
Main { content() }
46+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.huanshankeji.compose.material.icons
2+
3+
import dev.petuska.kmdcx.icons.MDCIcon
4+
5+
actual class IconType(val mdcIcon: MDCIcon)
6+
7+
actual object Icons {
8+
actual val Search: IconType = IconType(MDCIcon.Search)
9+
}

compose-multiplatform-material/src/jvmMain/kotlin/com/huanshankeji/compose/material/Components.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.huanshankeji.compose.material
22

33
import androidx.compose.foundation.layout.RowScope
4+
import androidx.compose.material.Scaffold
45
import androidx.compose.material.Text
6+
import androidx.compose.material.TopAppBar
57
import androidx.compose.runtime.Composable
68

79
actual class ButtonScope(val rowScope: RowScope) {
@@ -13,3 +15,15 @@ actual class ButtonScope(val rowScope: RowScope) {
1315
@Composable
1416
actual fun Button(onClick: () -> Unit, content: @Composable ButtonScope.() -> Unit) =
1517
androidx.compose.material.Button(onClick) { ButtonScope(this).content() }
18+
19+
20+
@Composable
21+
actual fun TopAppBarScaffold(
22+
title: @Composable () -> Unit,
23+
navigationIcon: @Composable (() -> Unit)?,
24+
actions: @Composable () -> Unit,
25+
content: @Composable () -> Unit
26+
) =
27+
Scaffold(topBar = {
28+
TopAppBar(title = title, navigationIcon = navigationIcon, actions = { actions() })
29+
}) { content() }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.huanshankeji.compose.material.icons
2+
3+
import androidx.compose.material.icons.Icons
4+
import androidx.compose.material.icons.filled.Search
5+
import androidx.compose.ui.graphics.vector.ImageVector
6+
7+
actual typealias IconType = ImageVector
8+
9+
actual object Icons {
10+
actual val Search: IconType = Icons.Default.Search
11+
}

0 commit comments

Comments
 (0)