|
| 1 | +package dev.petuska.kmdc.snackbar |
| 2 | + |
| 3 | +import androidx.compose.runtime.Composable |
| 4 | +import dev.petuska.kmdc.button.MDCButton |
| 5 | +import dev.petuska.kmdc.button.MDCButtonLabel |
| 6 | +import dev.petuska.kmdc.button.MDCButtonOpts |
| 7 | +import dev.petuska.kmdc.button.MDCButtonScope |
| 8 | +import dev.petuska.kmdc.core.Builder |
| 9 | +import dev.petuska.kmdc.core.ComposableBuilder |
| 10 | +import dev.petuska.kmdc.core.MDCDsl |
| 11 | +import dev.petuska.kmdc.icon.button.MDCIconButton |
| 12 | +import dev.petuska.kmdc.icon.button.MDCIconButtonOpts |
| 13 | +import dev.petuska.kmdc.icon.button.MDCIconButtonScope |
| 14 | +import org.jetbrains.compose.web.attributes.ButtonType |
| 15 | +import org.jetbrains.compose.web.attributes.type |
| 16 | +import org.jetbrains.compose.web.dom.AttrBuilderContext |
| 17 | +import org.jetbrains.compose.web.dom.Div |
| 18 | +import org.jetbrains.compose.web.dom.ElementScope |
| 19 | +import org.w3c.dom.HTMLButtonElement |
| 20 | +import org.w3c.dom.HTMLDivElement |
| 21 | + |
| 22 | +public class MDCSnackbarActionsScope(scope: ElementScope<HTMLDivElement>) : ElementScope<HTMLDivElement> by scope |
| 23 | + |
| 24 | +/** |
| 25 | + * [JS API](https://github.com/material-components/material-components-web/tree/v13.0.0/packages/mdc-snackbar) |
| 26 | + */ |
| 27 | +@MDCDsl |
| 28 | +@Composable |
| 29 | +public fun MDCSnackbarScope.MDCSnackbarActions( |
| 30 | + attrs: AttrBuilderContext<HTMLDivElement>? = null, |
| 31 | + content: ComposableBuilder<MDCSnackbarActionsScope>? = null, |
| 32 | +) { |
| 33 | + Div( |
| 34 | + attrs = { |
| 35 | + classes("mdc-snackbar__actions") |
| 36 | + attr("aria-atomic", "true") |
| 37 | + attrs?.invoke(this) |
| 38 | + }, |
| 39 | + content = content?.let { { MDCSnackbarActionsScope(this).it() } } |
| 40 | + ) |
| 41 | +} |
| 42 | + |
| 43 | +/** |
| 44 | + * [JS API](https://github.com/material-components/material-components-web/tree/v13.0.0/packages/mdc-snackbar) |
| 45 | + */ |
| 46 | +@MDCDsl |
| 47 | +@Composable |
| 48 | +public fun MDCSnackbarActionsScope.MDCSnackbarAction( |
| 49 | + opts: Builder<MDCButtonOpts>? = null, |
| 50 | + attrs: AttrBuilderContext<HTMLButtonElement>? = null, |
| 51 | + content: ComposableBuilder<MDCButtonScope>? = null, |
| 52 | +) { |
| 53 | + MDCButton( |
| 54 | + opts = opts, |
| 55 | + attrs = { |
| 56 | + classes("mdc-snackbar__action") |
| 57 | + type(ButtonType.Button) |
| 58 | + attrs?.invoke(this) |
| 59 | + }, |
| 60 | + content = content, |
| 61 | + ) |
| 62 | +} |
| 63 | + |
| 64 | +/** |
| 65 | + * [JS API](https://github.com/material-components/material-components-web/tree/v13.0.0/packages/mdc-snackbar) |
| 66 | + */ |
| 67 | +@MDCDsl |
| 68 | +@Composable |
| 69 | +public fun MDCSnackbarActionsScope.MDCSnackbarAction( |
| 70 | + text: String, |
| 71 | + opts: Builder<MDCButtonOpts>? = null, |
| 72 | + attrs: AttrBuilderContext<HTMLButtonElement>? = null, |
| 73 | +) { |
| 74 | + MDCSnackbarAction(opts, attrs) { MDCButtonLabel(text) } |
| 75 | +} |
| 76 | + |
| 77 | +/** |
| 78 | + * [JS API](https://github.com/material-components/material-components-web/tree/v13.0.0/packages/mdc-snackbar) |
| 79 | + */ |
| 80 | +@MDCDsl |
| 81 | +@Composable |
| 82 | +public fun MDCSnackbarActionsScope.MDCSnackbarDismiss( |
| 83 | + opts: Builder<MDCIconButtonOpts>? = null, |
| 84 | + attrs: AttrBuilderContext<HTMLButtonElement>? = null, |
| 85 | + content: ComposableBuilder<MDCIconButtonScope>? = null, |
| 86 | +) { |
| 87 | + MDCIconButton( |
| 88 | + opts = opts, |
| 89 | + attrs = { |
| 90 | + classes("mdc-snackbar__dismiss") |
| 91 | + attrs?.invoke(this) |
| 92 | + }, |
| 93 | + content = content, |
| 94 | + ) |
| 95 | +} |
0 commit comments