generated from mpetuska/template-kmp-library
-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
458 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
kmdc/kmdc-icon-button/src/jsMain/kotlin/MDCIconButtonModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package dev.petuska.kmdc.icon.button | ||
|
||
import dev.petuska.kmdc.core.Destroyable | ||
import org.w3c.dom.Element | ||
|
||
@JsModule("@material/icon-button") | ||
public external object MDCIconButtonModule { | ||
public class MDCIconButtonToggle(element: Element) : Destroyable { | ||
public companion object { | ||
public fun attachTo(element: Element): MDCIconButtonToggle | ||
} | ||
|
||
override fun destroy() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import util.mdcVersion | ||
|
||
plugins { | ||
id("plugin.library-compose") | ||
id("plugin.publishing-mpp") | ||
} | ||
|
||
kotlin { | ||
sourceSets { | ||
named("jsMain") { | ||
dependencies { | ||
api(project(":kmdc:kmdc-core")) | ||
api(project(":kmdc:kmdc-button")) | ||
api(project(":kmdc:kmdc-icon-button")) | ||
api(npm("@material/snackbar", mdcVersion)) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package dev.petuska.kmdc.snackbar | ||
|
||
import MDCSnackbarModule | ||
import androidx.compose.runtime.Composable | ||
import dev.petuska.kmdc.core.Builder | ||
import dev.petuska.kmdc.core.ComposableBuilder | ||
import dev.petuska.kmdc.core.MDCDsl | ||
import dev.petuska.kmdc.core.initialiseMDC | ||
import dev.petuska.kmdc.core.mdc | ||
import org.jetbrains.compose.web.dom.Aside | ||
import org.jetbrains.compose.web.dom.AttrBuilderContext | ||
import org.jetbrains.compose.web.dom.Div | ||
import org.jetbrains.compose.web.dom.ElementScope | ||
import org.w3c.dom.HTMLElement | ||
|
||
@JsModule("@material/snackbar/dist/mdc.snackbar.css") | ||
private external val MDCSnackbarCSS: dynamic | ||
|
||
public data class MDCSnackbarOpts( | ||
var type: Type = Type.Default, | ||
var open: Boolean = false, | ||
var dismissible: Boolean = false, | ||
) { | ||
public enum class Type(public vararg val classes: String) { | ||
Default, | ||
Stacked("mdc-snackbar--stacked"), | ||
Leading("mdc-snackbar--leading"), | ||
} | ||
} | ||
|
||
public class MDCSnackbarScope(scope: ElementScope<HTMLElement>) : ElementScope<HTMLElement> by scope | ||
|
||
/** | ||
* [JS API](https://github.com/material-components/material-components-web/tree/v13.0.0/packages/mdc-snackbar) | ||
*/ | ||
@MDCDsl | ||
@Composable | ||
public fun MDCSnackbar( | ||
opts: Builder<MDCSnackbarOpts>? = null, | ||
attrs: AttrBuilderContext<HTMLElement>? = null, | ||
content: ComposableBuilder<MDCSnackbarScope>? = null, | ||
) { | ||
val options = MDCSnackbarOpts().apply { opts?.invoke(this) } | ||
MDCSnackbarCSS | ||
Aside(attrs = { | ||
classes("mdc-snackbar", *options.type.classes) | ||
attrs?.invoke(this) | ||
initialiseMDC(MDCSnackbarModule.MDCSnackbar.Companion::attachTo) | ||
}) { | ||
DomSideEffect(options.open) { | ||
it.mdc<MDCSnackbarModule.MDCSnackbar> { | ||
if (options.open) { | ||
open() | ||
} else { | ||
close() | ||
} | ||
} | ||
} | ||
Div( | ||
attrs = { | ||
classes("mdc-snackbar__surface") | ||
attr("role", "status") | ||
attr("aria-relevant", "additions") | ||
}, | ||
content = content?.let { { MDCSnackbarScope(this).it() } } | ||
) | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
kmdc/kmdc-snackbar/src/jsMain/kotlin/MDCSnackbarActions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package dev.petuska.kmdc.snackbar | ||
|
||
import androidx.compose.runtime.Composable | ||
import dev.petuska.kmdc.button.MDCButton | ||
import dev.petuska.kmdc.button.MDCButtonLabel | ||
import dev.petuska.kmdc.button.MDCButtonOpts | ||
import dev.petuska.kmdc.button.MDCButtonScope | ||
import dev.petuska.kmdc.core.Builder | ||
import dev.petuska.kmdc.core.ComposableBuilder | ||
import dev.petuska.kmdc.core.MDCDsl | ||
import dev.petuska.kmdc.icon.button.MDCIconButton | ||
import dev.petuska.kmdc.icon.button.MDCIconButtonOpts | ||
import dev.petuska.kmdc.icon.button.MDCIconButtonScope | ||
import org.jetbrains.compose.web.attributes.ButtonType | ||
import org.jetbrains.compose.web.attributes.type | ||
import org.jetbrains.compose.web.dom.AttrBuilderContext | ||
import org.jetbrains.compose.web.dom.Div | ||
import org.jetbrains.compose.web.dom.ElementScope | ||
import org.w3c.dom.HTMLButtonElement | ||
import org.w3c.dom.HTMLDivElement | ||
|
||
public class MDCSnackbarActionsScope(scope: ElementScope<HTMLDivElement>) : ElementScope<HTMLDivElement> by scope | ||
|
||
/** | ||
* [JS API](https://github.com/material-components/material-components-web/tree/v13.0.0/packages/mdc-snackbar) | ||
*/ | ||
@MDCDsl | ||
@Composable | ||
public fun MDCSnackbarScope.MDCSnackbarActions( | ||
attrs: AttrBuilderContext<HTMLDivElement>? = null, | ||
content: ComposableBuilder<MDCSnackbarActionsScope>? = null, | ||
) { | ||
Div( | ||
attrs = { | ||
classes("mdc-snackbar__actions") | ||
attr("aria-atomic", "true") | ||
attrs?.invoke(this) | ||
}, | ||
content = content?.let { { MDCSnackbarActionsScope(this).it() } } | ||
) | ||
} | ||
|
||
/** | ||
* [JS API](https://github.com/material-components/material-components-web/tree/v13.0.0/packages/mdc-snackbar) | ||
*/ | ||
@MDCDsl | ||
@Composable | ||
public fun MDCSnackbarActionsScope.MDCSnackbarAction( | ||
opts: Builder<MDCButtonOpts>? = null, | ||
attrs: AttrBuilderContext<HTMLButtonElement>? = null, | ||
content: ComposableBuilder<MDCButtonScope>? = null, | ||
) { | ||
MDCButton( | ||
opts = opts, | ||
attrs = { | ||
classes("mdc-snackbar__action") | ||
type(ButtonType.Button) | ||
attrs?.invoke(this) | ||
}, | ||
content = content, | ||
) | ||
} | ||
|
||
/** | ||
* [JS API](https://github.com/material-components/material-components-web/tree/v13.0.0/packages/mdc-snackbar) | ||
*/ | ||
@MDCDsl | ||
@Composable | ||
public fun MDCSnackbarActionsScope.MDCSnackbarAction( | ||
text: String, | ||
opts: Builder<MDCButtonOpts>? = null, | ||
attrs: AttrBuilderContext<HTMLButtonElement>? = null, | ||
) { | ||
MDCSnackbarAction(opts, attrs) { MDCButtonLabel(text) } | ||
} | ||
|
||
/** | ||
* [JS API](https://github.com/material-components/material-components-web/tree/v13.0.0/packages/mdc-snackbar) | ||
*/ | ||
@MDCDsl | ||
@Composable | ||
public fun MDCSnackbarActionsScope.MDCSnackbarDismiss( | ||
opts: Builder<MDCIconButtonOpts>? = null, | ||
attrs: AttrBuilderContext<HTMLButtonElement>? = null, | ||
content: ComposableBuilder<MDCIconButtonScope>? = null, | ||
) { | ||
MDCIconButton( | ||
opts = opts, | ||
attrs = { | ||
classes("mdc-snackbar__dismiss") | ||
attrs?.invoke(this) | ||
}, | ||
content = content, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package dev.petuska.kmdc.snackbar | ||
|
||
import androidx.compose.runtime.Composable | ||
import dev.petuska.kmdc.core.MDCDsl | ||
import org.jetbrains.compose.web.dom.AttrBuilderContext | ||
import org.jetbrains.compose.web.dom.ContentBuilder | ||
import org.jetbrains.compose.web.dom.Div | ||
import org.jetbrains.compose.web.dom.Text | ||
import org.w3c.dom.HTMLDivElement | ||
|
||
/** | ||
* [JS API](https://github.com/material-components/material-components-web/tree/v13.0.0/packages/mdc-snackbar) | ||
*/ | ||
@MDCDsl | ||
@Composable | ||
public fun MDCSnackbarScope.MDCSnackbarLabel( | ||
attrs: AttrBuilderContext<HTMLDivElement>? = null, | ||
content: ContentBuilder<HTMLDivElement>? = null, | ||
) { | ||
Div( | ||
attrs = { | ||
classes("mdc-snackbar__label") | ||
attr("aria-atomic", "false") | ||
attrs?.invoke(this) | ||
}, | ||
content = content | ||
) | ||
} | ||
|
||
/** | ||
* [JS API](https://github.com/material-components/material-components-web/tree/v13.0.0/packages/mdc-snackbar) | ||
*/ | ||
@MDCDsl | ||
@Composable | ||
public fun MDCSnackbarScope.MDCSnackbarLabel( | ||
text: String, | ||
attrs: AttrBuilderContext<HTMLDivElement>? = null, | ||
) { | ||
MDCSnackbarLabel(attrs) { Text(text) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import dev.petuska.kmdc.core.Destroyable | ||
import dev.petuska.kmdc.core.MDCEvent | ||
import org.w3c.dom.Element | ||
|
||
@JsModule("@material/snackbar") | ||
public external object MDCSnackbarModule { | ||
public class MDCSnackbar(element: Element) : Destroyable { | ||
public companion object { | ||
public fun attachTo(element: Element): MDCSnackbar | ||
} | ||
|
||
public fun initialize( | ||
segmentFactory: ( | ||
el: Element, | ||
foundation: dynamic | ||
) -> (() -> (ariaEl: Element, labelEl: Element?) -> Unit) = definedExternally | ||
) | ||
|
||
public fun initialSyncWithDOM() | ||
public override fun destroy() | ||
public fun open() | ||
public fun close(reason: String = definedExternally) | ||
public fun getDefaultFoundation(): dynamic | ||
public var timeoutMs: Number | ||
public var closeOnEscape: Boolean | ||
public val isOpen: Boolean | ||
public var labelText: String | ||
public var actionButtonText: String | ||
} | ||
|
||
public interface MDCSnackbarOpenEventDetail | ||
public interface MDCSnackbarCloseEventDetail { | ||
public val reason: String? | ||
} | ||
|
||
public class MDCSnackbarOpenEvent : MDCEvent<MDCSnackbarOpenEventDetail> | ||
public class MDCSnackbarCloseEvent : MDCEvent<MDCSnackbarCloseEventDetail> | ||
} |
Oops, something went wrong.