Skip to content

Commit 1664af8

Browse files
committed
Set up the project and add a Button composable to make sure it works
1 parent 7fa51e6 commit 1664af8

File tree

13 files changed

+2735
-77
lines changed

13 files changed

+2735
-77
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Ignore Gradle project-specific cache directory
21
.gradle
3-
4-
# Ignore Gradle build output directory
52
build
3+
local.properties
4+
5+
.idea

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Compose Multiplatform Material wrappers
22

33
Compose Multiplatform Material Design component wrappers for Desktop, Android, and Web (mainly based on [KMDC](https://github.com/mpetuska/kmdc))
4+
5+
We try to make sure the styles of the `Composable` components follow those in `com.huanshankeji.compose.material`, with, however, only a subset of the `Composable` arguments supported due to the API differences and limitations of the JS components this project depends on.

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tasks.wrapper {
2+
distributionType = Wrapper.DistributionType.ALL
3+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
plugins {
2+
kotlin("multiplatform")
3+
id("org.jetbrains.compose") version "1.2.1"
4+
// TODO: `id("com.android.library") version "7.2.2"`?
5+
id("com.huanshankeji.kotlin-multiplatform-jvm-and-js-browser-sonatype-ossrh-publish-conventions")
6+
}
7+
8+
group = "com.huanshankeji"
9+
version = "0.1.0-SNAPSHOT"
10+
11+
repositories {
12+
mavenCentral()
13+
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
14+
google()
15+
}
16+
17+
kotlin {
18+
jvm() // TODO: `jvm("desktop")`?
19+
// TODO: `android()`?
20+
js(IR) {
21+
browser()
22+
}
23+
24+
sourceSets {
25+
val commonMain by getting {
26+
dependencies {
27+
implementation(compose.runtime)
28+
}
29+
}
30+
// TODO: a `jvmCommon` source set to share code for `jvm`/`desktop` and `android`
31+
named("jvmMain") {
32+
dependencies {
33+
implementation(compose.foundation)
34+
implementation(compose.material)
35+
}
36+
}
37+
named("jsMain") {
38+
dependencies {
39+
// Be lazy and use the shortcut
40+
implementation("dev.petuska:kmdc:0.0.5")
41+
implementation("dev.petuska:kmdcx:0.0.5")
42+
// TODO: pick and choose exact components to reduce bundle size
43+
}
44+
}
45+
}
46+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.huanshankeji.compose.material
2+
3+
import androidx.compose.runtime.Composable
4+
5+
expect /*value*/ class ButtonScope {
6+
@Composable
7+
fun Label(text: String)
8+
}
9+
10+
@Composable
11+
expect fun Button(onClick: () -> Unit, content: @Composable ButtonScope.() -> Unit)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.huanshankeji.compose.material
2+
3+
import androidx.compose.runtime.Composable
4+
import dev.petuska.kmdc.button.Label
5+
import dev.petuska.kmdc.button.MDCButton
6+
import dev.petuska.kmdc.button.MDCButtonScope
7+
import org.w3c.dom.HTMLButtonElement
8+
9+
actual class ButtonScope(val mdcButtonScope: MDCButtonScope<HTMLButtonElement>) {
10+
@Composable
11+
actual fun Label(text: String) =
12+
mdcButtonScope.Label(text)
13+
}
14+
15+
@Composable
16+
actual fun Button(onClick: () -> Unit, content: @Composable ButtonScope.() -> Unit) =
17+
MDCButton(attrs = { onClick { onClick() } }) { ButtonScope(this).content() }
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.huanshankeji.compose.material
2+
3+
import androidx.compose.foundation.layout.RowScope
4+
import androidx.compose.material.Text
5+
import androidx.compose.runtime.Composable
6+
7+
actual class ButtonScope(val rowScope: RowScope) {
8+
@Composable
9+
actual fun Label(text: String) =
10+
Text(text)
11+
}
12+
13+
@Composable
14+
actual fun Button(onClick: () -> Unit, content: @Composable ButtonScope.() -> Unit) =
15+
androidx.compose.material.Button(onClick = onClick) { ButtonScope(this).content() }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
44
networkTimeout=10000
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)