Skip to content

Commit 71d9287

Browse files
CopilotShreckYe
andauthored
Adapt to compose-html-material PR #21 API changes (#74)
* Initial plan * Adapt to compose-html-material PR #21 changes: slot enums, MdOutlinedSegmentedButtonSet, disabled in attrs Co-authored-by: ShreckYe <27768951+ShreckYe@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ShreckYe <27768951+ShreckYe@users.noreply.github.com>
1 parent f16f9ce commit 71d9287

File tree

10 files changed

+28
-20
lines changed

10 files changed

+28
-20
lines changed

material3/src/jsMain/kotlin/com/huanshankeji/compose/material3/Chips.js.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable
44
import com.huanshankeji.compose.foundation.layout.RowScope
55
import com.huanshankeji.compose.html.material3.MdAssistChip
66
import com.huanshankeji.compose.html.material3.MdChipScope
7+
import com.huanshankeji.compose.html.material3.MdChipScope.Slot
78
import com.huanshankeji.compose.html.material3.MdFilterChip
89
import com.huanshankeji.compose.html.material3.MdInputChip
910
import com.huanshankeji.compose.html.material3.MdSuggestionChip
@@ -29,7 +30,7 @@ actual fun AssistChip(
2930
) {
3031
leadingIcon?.let { icon ->
3132
Div({
32-
slotEqIcon()
33+
slot(Slot.Icon)
3334
}) {
3435
icon()
3536
}
@@ -55,7 +56,7 @@ actual fun FilterChip(
5556
) {
5657
leadingIcon?.let { icon ->
5758
Div({
58-
slotEqIcon()
59+
slot(Slot.Icon)
5960
}) {
6061
icon()
6162
}
@@ -81,7 +82,7 @@ actual fun InputChip(
8182
) {
8283
leadingIcon?.let { icon ->
8384
Div({
84-
slotEqIcon()
85+
slot(Slot.Icon)
8586
}) {
8687
icon()
8788
}
@@ -105,7 +106,7 @@ actual fun SuggestionChip(
105106
) {
106107
icon?.let { iconContent ->
107108
Div({
108-
slotEqIcon()
109+
slot(Slot.Icon)
109110
}) {
110111
iconContent()
111112
}

material3/src/jsMain/kotlin/com/huanshankeji/compose/material3/Dialog.js.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import androidx.compose.runtime.mutableStateOf
66
import androidx.compose.runtime.remember
77
import androidx.compose.runtime.setValue
88
import com.huanshankeji.compose.html.material3.MdDialog
9+
import com.huanshankeji.compose.html.material3.MdDialogScope.Slot
910
import com.huanshankeji.compose.ui.Modifier
1011
import com.huanshankeji.compose.ui.toAttrs
1112
import org.jetbrains.compose.web.dom.Div
@@ -29,7 +30,7 @@ actual fun AlertDialog(
2930
) {
3031
title?.let { titleContent ->
3132
Div({
32-
slotEqHeadline()
33+
slot(Slot.Headline)
3334
}) {
3435
icon?.let { iconContent -> iconContent() }
3536
titleContent()
@@ -38,14 +39,14 @@ actual fun AlertDialog(
3839

3940
text?.let { textContent ->
4041
Div({
41-
slotEqContent()
42+
slot(Slot.Content)
4243
}) {
4344
textContent()
4445
}
4546
}
4647

4748
Div({
48-
slotEqActions()
49+
slot(Slot.Actions)
4950
}) {
5051
dismissButton?.let { dismissBtn -> dismissBtn() }
5152
confirmButton()

material3/src/jsMain/kotlin/com/huanshankeji/compose/material3/FloatingActionButton.js.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import com.huanshankeji.compose.ui.toCommonModifier
1212
import com.varabyte.kobweb.compose.ui.attrsModifier
1313

1414
internal val MdFabScope.slotEqIconModifier
15-
get() = PlatformModifier.attrsModifier { slotEqIcon() }.toCommonModifier()
15+
get() = PlatformModifier.attrsModifier { slot(MdFabScope.Slot.Icon) }.toCommonModifier()
1616

1717
private fun (@Composable () -> Unit).toBoxedContentWithModifier(): @Composable (Modifier) -> Unit =
1818
{ modifier ->

material3/src/jsMain/kotlin/com/huanshankeji/compose/material3/IconButton.js.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal fun Modifier.toCommonIconToggleButtonAttrs(
2323
}
2424

2525
internal fun MdIconButtonScope.slotEqSelectedModifier() =
26-
PlatformModifier.attrsModifier { slotEqSelected() }.toCommonModifier()
26+
PlatformModifier.attrsModifier { slot(MdIconButtonScope.Slot.Selected) }.toCommonModifier()
2727

2828
private fun (@Composable () -> Unit).toCommonIconButtonContent(): @Composable MdIconButtonScope.() -> Unit = {
2929
Box { this@toCommonIconButtonContent() }

material3/src/jsMain/kotlin/com/huanshankeji/compose/material3/RadioButton.js.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable
44
import com.huanshankeji.compose.html.material3.MdRadio
55
import com.huanshankeji.compose.ui.Modifier
66
import com.huanshankeji.compose.ui.toAttrs
7+
import com.huanshankeji.compose.web.attributes.ext.disabled
78
import com.huanshankeji.compose.web.attributes.isFalseOrNull
89
import com.huanshankeji.compose.web.attributes.isTrueOrNull
910

@@ -16,8 +17,8 @@ actual fun RadioButton(
1617
) =
1718
MdRadio(
1819
checked = selected.isTrueOrNull(),
19-
disabled = enabled.isFalseOrNull(),
2020
attrs = modifier.toAttrs {
21+
disabled(enabled.isFalseOrNull())
2122
onClick?.let { callback ->
2223
this.onClick { callback() }
2324
}

material3/src/jsMain/kotlin/com/huanshankeji/compose/material3/SegmentedButton.js.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import androidx.compose.runtime.Composable
44
import androidx.compose.ui.unit.Dp
55
import com.huanshankeji.compose.html.material3.MaterialWebLabsApi
66
import com.huanshankeji.compose.html.material3.MdOutlinedSegmentedButton
7-
import com.huanshankeji.compose.html.material3.MdSegmentedButtonSet
7+
import com.huanshankeji.compose.html.material3.MdOutlinedSegmentedButtonSet
8+
import com.huanshankeji.compose.html.material3.MdSegmentedButtonScope
9+
import com.huanshankeji.compose.html.material3.MdSegmentedButtonScope.Slot
810
import com.huanshankeji.compose.ui.Modifier
911
import com.huanshankeji.compose.ui.toAttrs
1012
import com.huanshankeji.compose.web.attributes.isFalseOrNull
@@ -20,7 +22,7 @@ actual fun SingleChoiceSegmentedButtonRow(
2022
space: Dp?,
2123
content: @Composable SingleChoiceSegmentedButtonRowScope.() -> Unit
2224
) =
23-
MdSegmentedButtonSet(false, modifier.toAttrs()) {
25+
MdOutlinedSegmentedButtonSet(attrs = modifier.toAttrs()) {
2426
SingleChoiceSegmentedButtonRowScope(this).content()
2527
}
2628

@@ -31,7 +33,7 @@ actual fun MultiChoiceSegmentedButtonRow(
3133
space: Dp?,
3234
content: @Composable MultiChoiceSegmentedButtonRowScope.() -> Unit
3335
) =
34-
MdSegmentedButtonSet(true, modifier.toAttrs()) {
36+
MdOutlinedSegmentedButtonSet(multiselect = true, attrs = modifier.toAttrs()) {
3537
MultiChoiceSegmentedButtonRowScope(this).content()
3638
}
3739

@@ -58,7 +60,7 @@ actual class SingleChoiceSegmentedButtonRowScope(val elementScope: ElementScope<
5860
) {
5961
icon?.let { iconContent ->
6062
Div({
61-
slotEqIcon()
63+
slot(Slot.Icon)
6264
}) {
6365
iconContent()
6466
}
@@ -90,7 +92,7 @@ actual class MultiChoiceSegmentedButtonRowScope(val elementScope: ElementScope<H
9092
) {
9193
icon?.let { iconContent ->
9294
Div({
93-
slotEqIcon()
95+
slot(Slot.Icon)
9496
}) {
9597
iconContent()
9698
}

material3/src/jsMain/kotlin/com/huanshankeji/compose/material3/Slider.js.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable
44
import com.huanshankeji.compose.html.material3.MdSlider
55
import com.huanshankeji.compose.ui.Modifier
66
import com.huanshankeji.compose.ui.toAttrs
7+
import com.huanshankeji.compose.web.attributes.ext.disabled
78
import com.huanshankeji.compose.web.attributes.ext.onInput
89
import com.huanshankeji.compose.web.attributes.isFalseOrNull
910
import org.w3c.dom.HTMLElement
@@ -20,12 +21,12 @@ actual fun Slider(
2021
onValueChangeFinished: (() -> Unit)?
2122
) =
2223
MdSlider(
23-
disabled = enabled.isFalseOrNull(),
2424
min = valueRange.start,
2525
max = valueRange.endInclusive,
2626
value = value,
2727
step = if (steps > 0) (valueRange.endInclusive - valueRange.start) / (steps + 1) else null,
2828
attrs = modifier.toAttrs {
29+
disabled(enabled.isFalseOrNull())
2930
onInput { event ->
3031
// MdSlider uses input event for value changes
3132
val target = event.target.asDynamic()

material3/src/jsMain/kotlin/com/huanshankeji/compose/material3/Tabs.js.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.huanshankeji.compose.material3
33
import androidx.compose.runtime.Composable
44
import com.huanshankeji.compose.foundation.layout.RowScope
55
import com.huanshankeji.compose.html.material3.MdPrimaryTab
6+
import com.huanshankeji.compose.html.material3.MdTabScope.Slot
67
import com.huanshankeji.compose.html.material3.MdTabs
78
import com.huanshankeji.compose.ui.Modifier
89
import com.huanshankeji.compose.ui.toAttrs
@@ -39,7 +40,7 @@ actual fun Tab(
3940
) {
4041
icon?.let { iconContent ->
4142
Div({
42-
slotEqIcon()
43+
slot(Slot.Icon)
4344
}) {
4445
iconContent()
4546
}

material3/src/jsMain/kotlin/com/huanshankeji/compose/material3/ext/Button.js.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ private fun (@Composable () -> Unit).toMdButtonScopeContent(
1414
// see https://github.com/material-components/material-web/blob/main/docs/components/button.md#icon
1515

1616
this@toMdButtonScopeContent()
17-
icon?.invoke(PlatformModifier.attrsModifier { slotEqIcon() }.toCommonModifier())
17+
icon?.invoke(PlatformModifier.attrsModifier { slot(MdButtonScope.Slot.Icon) }.toCommonModifier())
1818
}
1919

2020

material3/src/jsMain/kotlin/com/huanshankeji/compose/material3/ext/Select.js.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.huanshankeji.compose.html.material3.MdOutlinedSelect
66
import com.huanshankeji.compose.html.material3.MdSelectOption
77
import com.huanshankeji.compose.ui.Modifier
88
import com.huanshankeji.compose.ui.toAttrs
9+
import com.huanshankeji.compose.web.attributes.ext.disabled
910
import com.huanshankeji.compose.web.attributes.ext.onInput
1011
import com.huanshankeji.compose.web.attributes.isFalseOrNull
1112
import org.jetbrains.compose.web.dom.Text
@@ -21,9 +22,9 @@ actual fun FilledSelect(
2122
options: @Composable () -> Unit
2223
) =
2324
MdFilledSelect(
24-
disabled = enabled.isFalseOrNull(),
2525
label = label,
2626
attrs = modifier.toAttrs {
27+
disabled(enabled.isFalseOrNull())
2728
onInput { event ->
2829
((event.target as? HTMLElement)?.asDynamic()?.value as? String)?.let { newValue ->
2930
onValueChange(newValue)
@@ -44,9 +45,9 @@ actual fun OutlinedSelect(
4445
options: @Composable () -> Unit
4546
) =
4647
MdOutlinedSelect(
47-
disabled = enabled.isFalseOrNull(),
4848
label = label,
4949
attrs = modifier.toAttrs {
50+
disabled(enabled.isFalseOrNull())
5051
onInput { event ->
5152
((event.target as? HTMLElement)?.asDynamic()?.value as? String)?.let { newValue ->
5253
onValueChange(newValue)

0 commit comments

Comments
 (0)