|
| 1 | +package com.huanshankeji.compose.html.material3 |
| 2 | + |
| 3 | +import androidx.compose.runtime.Composable |
| 4 | +import com.huanshankeji.compose.html.material3.attributes.indeterminate |
| 5 | +import com.huanshankeji.compose.web.attributes.Attrs |
| 6 | +import com.huanshankeji.compose.web.attributes.attrIfNotNull |
| 7 | +import org.jetbrains.compose.web.dom.ElementScope |
| 8 | +import org.jetbrains.compose.web.dom.TagElement |
| 9 | +import org.w3c.dom.HTMLElement |
| 10 | + |
| 11 | +/* |
| 12 | +https://github.com/material-components/material-web/blob/main/docs/components/progress.md |
| 13 | +https://material-web.dev/components/progress/ |
| 14 | +https://material-web.dev/components/progress/stories/ |
| 15 | + */ |
| 16 | + |
| 17 | +@Composable |
| 18 | +private fun CommonMdProgress( |
| 19 | + tagName: String, |
| 20 | + attrsBefore: Attrs<HTMLElement>?, |
| 21 | + value: Number?, |
| 22 | + max: Number?, |
| 23 | + indeterminate: Boolean?, |
| 24 | + fourColor: Boolean?, |
| 25 | + attrs: Attrs<HTMLElement>?, |
| 26 | + content: @Composable (ElementScope<HTMLElement>.() -> Unit)? |
| 27 | +) = |
| 28 | + TagElement(tagName, { |
| 29 | + attrsBefore?.invoke(this) |
| 30 | + |
| 31 | + attrIfNotNull("value", value) |
| 32 | + attrIfNotNull("max", max) |
| 33 | + indeterminate(indeterminate) |
| 34 | + attrIfNotNull("four-color", fourColor) |
| 35 | + |
| 36 | + attrs?.invoke(this) |
| 37 | + }, content) |
| 38 | + |
| 39 | +@Composable |
| 40 | +fun MdLinearProgress( |
| 41 | + buffer: Number? = null, |
| 42 | + value: Number? = null, |
| 43 | + max: Number? = null, |
| 44 | + indeterminate: Boolean? = null, |
| 45 | + fourColor: Boolean? = null, |
| 46 | + attrs: Attrs<HTMLElement>? = null, |
| 47 | + content: @Composable (ElementScope<HTMLElement>.() -> Unit)? = null |
| 48 | +) { |
| 49 | + require("@material/web/progress/linear-progress.js") |
| 50 | + |
| 51 | + CommonMdProgress( |
| 52 | + "md-linear-progress", |
| 53 | + { attrIfNotNull("buffer", buffer) }, |
| 54 | + value, max, indeterminate, fourColor, attrs, content |
| 55 | + ) |
| 56 | +} |
| 57 | + |
| 58 | +@Composable |
| 59 | +fun MdCircularProgress( |
| 60 | + value: Number? = null, |
| 61 | + max: Number? = null, |
| 62 | + indeterminate: Boolean? = null, |
| 63 | + fourColor: Boolean? = null, |
| 64 | + attrs: Attrs<HTMLElement>? = null, |
| 65 | + content: @Composable (ElementScope<HTMLElement>.() -> Unit)? = null |
| 66 | +) { |
| 67 | + require("@material/web/progress/circular-progress.js") |
| 68 | + |
| 69 | + CommonMdProgress( |
| 70 | + "md-circular-progress", |
| 71 | + null, |
| 72 | + value, max, indeterminate, fourColor, attrs, content |
| 73 | + ) |
| 74 | +} |
0 commit comments