-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dependent-on-compose-web-material-snapshot'
- Loading branch information
Showing
62 changed files
with
1,075 additions
and
133 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,53 @@ | ||
# Compose Multiplatform Material wrappers | ||
|
||
Some simple Compose Multiplatform Material Design component wrappers for desktop, Android, and web (mainly based on [KMDC](https://github.com/mpetuska/kmdc)) | ||
[![Maven Central](https://img.shields.io/maven-central/v/com.huanshankeji/compose-multiplatform-material)](https://search.maven.org/artifact/com.huanshankeji/compose-multiplatform-material) | ||
|
||
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. | ||
Some simple Compose Multiplatform wrappers of common components, layouts, and Material Design components for desktop, | ||
Android, and web (mainly based on [KMDC](https://github.com/mpetuska/kmdc)) | ||
|
||
Customizing styles (using `Modifier`s for desktop and Android, and `attrs: AttrBuilderContext<*>?` for web) is not supported yet. | ||
We try to make the function types of the composable components follow those of the desktop and Android ones | ||
in `androidx.compose.foundation` and `androidx.compose.material`, meanwhile being compatible with the Web APIs. However, | ||
only subsets of the composables and composable arguments are supported due to the API differences, limitations of the | ||
web composables this project depends on, and our limited effort. | ||
|
||
Visual consistency across different platforms is not guaranteed. | ||
|
||
There is no documentation for this project yet. Check out the demo project on how to use the components. | ||
This project is prototype and there is no documentation yet. Check out [the demo project](demo) on how to use the components. | ||
|
||
## Supported components | ||
<!-- | ||
There is no plan to support Apple platforms until there is official support from [Compose Multiplatform](https://github.com/JetBrains/compose-jb). Check out <https://github.com/cl3m/multiplatform-compose> for some experiments and prototypes on supporting iOS with Compose Multiplatform. | ||
--> | ||
|
||
## Supported features | ||
|
||
### Components | ||
|
||
#### Common (Foundation) components | ||
|
||
- `BasicText` | ||
- `RawText` | ||
|
||
##### Layouts | ||
|
||
- `Box` | ||
- `Column` (via flexbox on web) | ||
- `Row` (via flexbox on web) | ||
|
||
#### Material components | ||
|
||
- `Button` | ||
- `Card` | ||
- `Icon` | ||
- `IconButton` | ||
- `ScrollableList`/`LazyColumn` (visually inconsistent for now) | ||
- `Text`/`MaterialText` | ||
- `TopAppBarScaffold` | ||
|
||
### styles | ||
|
||
- `height` | ||
- `margin` | ||
- `width` | ||
- `backgroundColor` | ||
- `border` | ||
- `outerBorder` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
object DependencyVersions { | ||
val huanshankejiComposeWeb = "0.2.0" | ||
} |
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
6 changes: 5 additions & 1 deletion
6
compose-multiplatform-common/src/commonMain/kotlin/com/huanshankeji/compose/BasicText.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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
package com.huanshankeji.compose | ||
|
||
import androidx.compose.runtime.Composable | ||
import com.huanshankeji.compose.ui.Element | ||
import com.huanshankeji.compose.ui.ModifierOrAttrs | ||
|
||
expect abstract class BasicTextElement : Element | ||
|
||
@Composable | ||
expect fun BasicText(text: String) | ||
expect fun BasicText(text: String, modifierOrAttrs: ModifierOrAttrs<BasicTextElement> = null) |
7 changes: 7 additions & 0 deletions
7
compose-multiplatform-common/src/commonMain/kotlin/com/huanshankeji/compose/RawText.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,7 @@ | ||
package com.huanshankeji.compose | ||
|
||
import androidx.compose.runtime.Composable | ||
|
||
/** A raw text composable which doesn't add any element on web. */ | ||
@Composable | ||
expect fun RawText(text: String) |
File renamed without changes.
11 changes: 11 additions & 0 deletions
11
compose-multiplatform-common/src/commonMain/kotlin/com/huanshankeji/compose/layout/Column.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,11 @@ | ||
package com.huanshankeji.compose.layout | ||
|
||
import androidx.compose.runtime.Composable | ||
import com.huanshankeji.compose.ui.Element | ||
import com.huanshankeji.compose.ui.ModifierOrAttrs | ||
|
||
expect abstract class ColumnElement : Element | ||
expect interface ColumnScope | ||
|
||
@Composable | ||
expect fun Column(modifierOrAttrs: ModifierOrAttrs<ColumnElement> = null, content: @Composable ColumnScope.() -> Unit) |
11 changes: 11 additions & 0 deletions
11
compose-multiplatform-common/src/commonMain/kotlin/com/huanshankeji/compose/layout/Row.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,11 @@ | ||
package com.huanshankeji.compose.layout | ||
|
||
import androidx.compose.runtime.Composable | ||
import com.huanshankeji.compose.ui.Element | ||
import com.huanshankeji.compose.ui.ModifierOrAttrs | ||
|
||
expect abstract class RowElement : Element | ||
expect interface RowScope | ||
|
||
@Composable | ||
expect fun Row(modifierOrAttrs: ModifierOrAttrs<RowElement> = null, content: @Composable RowScope.() -> Unit) |
68 changes: 63 additions & 5 deletions
68
...platform-common/src/commonMain/kotlin/com/huanshankeji/compose/ui/ModifierOrAttrsScope.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
16 changes: 16 additions & 0 deletions
16
...ose-multiplatform-common/src/commonMain/kotlin/com/huanshankeji/compose/ui/color/Color.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,16 @@ | ||
package com.huanshankeji.compose.ui.color | ||
|
||
expect class Color | ||
|
||
internal fun UByte.alphaToFloatRatio(): Float = | ||
toFloat() / 255 | ||
|
||
internal fun Float.alphaToUByte(): UByte { | ||
require(this in 0f..1f) | ||
return (this * 255).toInt().toUByte() | ||
} | ||
|
||
expect fun rgbaColor(red: UByte, green: UByte, blue: UByte, alpha: UByte): Color | ||
expect fun rgbaColor(red: UByte, green: UByte, blue: UByte, alpha: Float): Color | ||
|
||
expect fun rgbColor(red: UByte, green: UByte, blue: UByte): Color |
10 changes: 10 additions & 0 deletions
10
...se-multiplatform-common/src/commonMain/kotlin/com/huanshankeji/compose/ui/color/Colors.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,10 @@ | ||
package com.huanshankeji.compose.ui.color | ||
|
||
expect object Colors { | ||
val black: Color | ||
val white: Color | ||
val gray : Color | ||
val red: Color | ||
val green: Color | ||
val blue: Color | ||
} |
19 changes: 16 additions & 3 deletions
19
compose-multiplatform-common/src/commonMain/kotlin/com/huanshankeji/compose/ui/unit/Sizes.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 |
---|---|---|
@@ -1,6 +1,19 @@ | ||
package com.huanshankeji.compose.ui.unit | ||
|
||
expect abstract class SizeValue | ||
expect class DpOrPxValue : SizeValue | ||
// Percentage is only supported on JS. | ||
expect sealed interface LengthOrPercentage | ||
expect sealed interface Length : LengthOrPercentage | ||
expect class Percentage : LengthOrPercentage | ||
|
||
expect val Int.dpOrPx: DpOrPxValue | ||
expect val Int.percent: Percentage | ||
|
||
expect class DpOrPx : Length | ||
|
||
expect val Int.dpOrPx: DpOrPx | ||
|
||
|
||
sealed class HeightOrWidth { | ||
class Numeric(val value: LengthOrPercentage) : HeightOrWidth() | ||
object FillMax : HeightOrWidth() | ||
object FitContent : HeightOrWidth() | ||
} |
10 changes: 8 additions & 2 deletions
10
compose-multiplatform-common/src/jsMain/kotlin/com/huanshankeji/compose/BasicText.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 |
---|---|---|
@@ -1,8 +1,14 @@ | ||
package com.huanshankeji.compose | ||
|
||
import androidx.compose.runtime.Composable | ||
import com.huanshankeji.compose.ui.ModifierOrAttrs | ||
import com.huanshankeji.compose.ui.toAttrs | ||
import org.jetbrains.compose.web.dom.Span | ||
import org.jetbrains.compose.web.dom.Text | ||
import org.w3c.dom.HTMLSpanElement | ||
|
||
actual typealias BasicTextElement = HTMLSpanElement | ||
|
||
@Composable | ||
actual fun BasicText(text: String) = | ||
Text(text) | ||
actual fun BasicText(text: String, modifierOrAttrs: ModifierOrAttrs<HTMLSpanElement>) = | ||
Span(modifierOrAttrs.toAttrs()) { Text(text) } |
8 changes: 8 additions & 0 deletions
8
compose-multiplatform-common/src/jsMain/kotlin/com/huanshankeji/compose/RawText.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,8 @@ | ||
package com.huanshankeji.compose | ||
|
||
import androidx.compose.runtime.Composable | ||
import org.jetbrains.compose.web.dom.Text | ||
|
||
@Composable | ||
actual fun RawText(text: String) = | ||
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
21 changes: 21 additions & 0 deletions
21
compose-multiplatform-common/src/jsMain/kotlin/com/huanshankeji/compose/layout/Column.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,21 @@ | ||
package com.huanshankeji.compose.layout | ||
|
||
import androidx.compose.runtime.Composable | ||
import com.huanshankeji.compose.ui.ModifierOrAttrs | ||
import com.huanshankeji.compose.ui.toAttrs | ||
import org.jetbrains.compose.web.dom.ElementScope | ||
import org.w3c.dom.HTMLDivElement | ||
|
||
actual typealias ColumnElement = HTMLDivElement | ||
|
||
actual interface ColumnScope { | ||
val elementScope: ElementScope<HTMLDivElement> | ||
|
||
class Impl(override val elementScope: ElementScope<HTMLDivElement>) : ColumnScope | ||
} | ||
|
||
@Composable | ||
actual fun Column(modifierOrAttrs: ModifierOrAttrs<ColumnElement>, content: @Composable ColumnScope.() -> Unit) = | ||
com.huanshankeji.compose.web.Column(modifierOrAttrs.toAttrs()) { | ||
ColumnScope.Impl(this).content() | ||
} |
21 changes: 21 additions & 0 deletions
21
compose-multiplatform-common/src/jsMain/kotlin/com/huanshankeji/compose/layout/Row.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,21 @@ | ||
package com.huanshankeji.compose.layout | ||
|
||
import androidx.compose.runtime.Composable | ||
import com.huanshankeji.compose.ui.ModifierOrAttrs | ||
import com.huanshankeji.compose.ui.toAttrs | ||
import org.jetbrains.compose.web.dom.ElementScope | ||
import org.w3c.dom.HTMLDivElement | ||
|
||
actual typealias RowElement = HTMLDivElement | ||
|
||
actual interface RowScope { | ||
val elementScope: ElementScope<HTMLDivElement> | ||
|
||
class Impl(override val elementScope: ElementScope<HTMLDivElement>) : RowScope | ||
} | ||
|
||
@Composable | ||
actual fun Row(modifierOrAttrs: ModifierOrAttrs<RowElement>, content: @Composable RowScope.() -> Unit) = | ||
com.huanshankeji.compose.web.Row(modifierOrAttrs.toAttrs()) { | ||
RowScope.Impl(this).content() | ||
} |
Oops, something went wrong.