Skip to content

Commit 066bcf0

Browse files
committed
Merge branch 'main' into release
v0.3.0 release
2 parents 1d1aa70 + 6227939 commit 066bcf0

File tree

48 files changed

+1632
-75
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1632
-75
lines changed

README.md

Lines changed: 74 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,93 @@
1-
# Compose for Web (now Compose HTML) Material
1+
# Compose HTML Material
22

3-
[![Maven Central](https://img.shields.io/maven-central/v/com.huanshankeji/compose-web-material)](https://search.maven.org/artifact/com.huanshankeji/compose-web-material)
4-
[![Gradle Plugin Portal](https://img.shields.io/gradle-plugin-portal/v/com.huanshankeji.compose-web-material-conventions)](https://plugins.gradle.org/plugin/com.huanshankeji.compose-web-material-conventions)
3+
[![Maven Central](https://img.shields.io/maven-central/v/com.huanshankeji/compose-html-material3)](https://search.maven.org/artifact/com.huanshankeji/compose-html-material3)
54

6-
Some Material components for Compose for Web, based on [Material Web (with Web Components) (or material-web, or `mwc`)](https://github.com/material-components/material-web) (preferred) and [Material Components for the web (or material-components-web, or `mdc`)](https://github.com/material-components/material-components-web) (fallback)
5+
Material 3 wrapper components for Compose HTML based on [Material Web](https://github.com/material-components/material-web)
76

8-
~~This project is in prototype and the components are not complete. More components will be added. It will probably go through huge refactors and API changes, too.~~
7+
For unified multiplatform APIs which are more akin to those in `androidx.compose`, check out [Compose Multiplatform Material](https://github.com/huanshankeji/compose-multiplatform-material).
98

10-
**This project is not currently under active development. Here is a list of reasons and alternatives:**
9+
For Material 2 support, you are recommended to check out [KMDC](https://github.com/mpetuska/kmdc) instead. For information on our obsolete work on legacy Material 2 components, check out [the legacy README](/legacy/README.md).
1110

12-
1. The [material-web](https://github.com/material-components/material-web) team is working on Material You (Material Design 3) support and [the Material 2 branch (`mwc`)](https://github.com/material-components/material-web/tree/mwc) is no longer under active development. Existing Compose wrappers of their Material 2 components are still kept in [the `:compose-web-material` subproject](compose-web-material) but not updated.
13-
1. [KMDC](https://github.com/mpetuska/kmdc) wrapping around [material-components-web (`mdc`)](https://github.com/material-components/material-components-web) provides a much more complete set of Material Design components for Compose for Web.
14-
1. We are currently focusing more on [compose-multiplatform-material](https://github.com/huanshankeji/compose-multiplatform-material) to provide multiplatform Compose Material wrappers, whose web portion depends on KMDC and [the `:compose-web-common` subproject](compose-web-common), which may be occasionally updated for the dependent project.
11+
## Supported components
1512

16-
## Instructions on how to use
13+
Not all components of Material Web are supported yet. Also, not all Material Design components are supported by Material Web yet (see [their roadmap](https://github.com/material-components/material-web/blob/main/docs/roadmap.md)).
1714

18-
Some configurations are needed to use this library due to the immaturities of this project and Kotlin/JS.
15+
Here is a list of supported compoent APIs:
1916

20-
### Add the dependency
17+
- `MdElevatedButton`, `MdFilledButton`, `MdFilledTonalButton`, `MdOutlinedButton`, `MdTextButton`
18+
- `MdCheckbox`
19+
- `MdFab`, `MdBrandedFab`
20+
- `MdIcon`
21+
- `MdIconButton`, `MdFilledIconButton`, `MdFilledTonalIconButton`, `MdOutlinedIconButton`
22+
- `MdList`, `MdListItem`
23+
- `MdSwitch`, `LabelWithMdSwitch`
24+
- `MdFilledTextField`, `MdOutlinedTextField`
2125

22-
```kotlin
23-
implementation("com.huanshankeji:compose-web-material:$version")
24-
```
26+
### "labs" components
2527

26-
### In code
28+
Here is a list of supported component APIs in the [Material Web "labs" directory](https://github.com/material-components/material-web/tree/main/labs), which "contains experimental features that are not recommended for production" as they state:
2729

28-
Call `mwcRequires()` in your `main` function before calling any component Composable functions.
30+
- `MdElevatedCard`, `MdOutlinedCard`
31+
- `MdNavigationBar`
32+
- `MdNavigationTab`
2933

30-
### Kotlin/JS Webpack configuration
34+
You should opt-in to `@MaterialWebLabsApi` to use them.
3135

32-
If you use this library in an app project with Webpack [which Kotlin/JS currently uses](https://kotlinlang.org/docs/js-project-setup.html), you might want to configure it as recommended by Material Web and Material Components for the web. Some instructions on how to do this simply are as below.
36+
## Brief Instructions
37+
38+
### Add the dependency
3339

34-
This plugin helps add the dependency to this project (if you do this you can skip the "Add the dependency" step above) and the `devNpm` dependencies:
40+
With Gradle:
3541

3642
```kotlin
37-
plugins {
38-
id("com.huanshankeji.compose-web-material-conventions") version someVersion
43+
kotlin {
44+
sourceSets {
45+
jsMain {
46+
dependencies {
47+
// ...
48+
implementation("com.huanshankeji:compose-html-material3:$version")
49+
}
50+
}
51+
}
3952
}
4053
```
4154

42-
However, the plugin doesn't [make further adjustments to the webpack configuration](https://kotlinlang.org/docs/js-project-setup.html#webpack-configuration-file), so you also need to refer to [the demo further adjustments](demo/webpack.config.d/further_adjustments.js) and [the demo HTML page](demo/html/demo.html) to add your own. Just copy and possibly adapt them as you like.
55+
### Material Symbols & Icons
56+
57+
The Material 3 module uses [Material Symbols & Icons](https://fonts.google.com/icons), but doesn't depend on the stylesheet directly. For Material Icons to work properly, you may need to configure your project following the quick instructions below or [the developer guide](https://developers.google.com/fonts/docs/material_symbols).
58+
59+
#### Quick instructions
60+
61+
In short, there are 3 ways to add the Material Symbols & Icons dependency:
62+
63+
1. Add the stylesheet hosted by Google directly in your HTML file `head`:
64+
65+
```html
66+
<link href="https://fonts.googleapis.com/icon?family=Material+Symbols+Outlined" rel="stylesheet">
67+
```
68+
69+
1. Use [Marella's self-hosted Material Symbols](https://www.npmjs.com/package/material-symbols).
70+
71+
First add the dependency in your build script:
72+
73+
```kotlin
74+
implementation(npm("material-symbols", "0.17.4"))
75+
```
76+
77+
And then import the icons in your program. For example you can use CommonJS `require`:
78+
79+
```kotlin
80+
external fun require(module: String): dynamic
81+
fun main() {
82+
require("material-symbols/outlined.css")
83+
renderComposableInBody { App() }
84+
}
85+
```
86+
87+
If you are familiar with web development and Kotlin/JS, you can depend on the stylesheet in any way that works and you prefer. For example, you can use `@JsModule` corresponding to the UMD import, or configure it as a Webpack entry point. See the following docs fore more details:
88+
1. [JavaScript modules | Kotlin Documentation](https://kotlinlang.org/docs/js-modules.html)
89+
1. [the "webpack configuration file" section in Set up a Kotlin/JS project | Kotlin Documentation](https://kotlinlang.org/docs/js-project-setup.html#webpack-configuration-file)
90+
1. [Code Splitting | webpack](https://webpack.js.org/guides/code-splitting/)
91+
1. [Advanced entry | webpack](https://webpack.js.org/guides/entry-advanced/)
92+
93+
1. [Download and self-host the latest font](https://developers.google.com/fonts/docs/material_symbols#self-hosting_the_font).

buildSrc/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ val huanshankejiGradlePluginsVersion = "0.5.1"
1111

1212
dependencies {
1313
implementation(kotlin("gradle-plugin", "1.9.23"))
14-
implementation("org.jetbrains.compose:compose-gradle-plugin:1.6.1")
14+
implementation("org.jetbrains.compose:compose-gradle-plugin:1.6.2")
1515
implementation("com.huanshankeji:kotlin-common-gradle-plugins:$huanshankejiGradlePluginsVersion")
1616
implementation("com.huanshankeji.team:gradle-plugins:$huanshankejiGradlePluginsVersion")
1717
implementation("com.huanshankeji:common-gradle-dependencies:0.7.1-20240314")

buildSrc/src/main/kotlin/VersionsAndDependencies.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import com.huanshankeji.CommonDependencies
22

3-
const val projectVersion = "0.2.2"
3+
const val projectVersion = "0.3.0"
44

55
object DependencyVersions {
6+
val kobweb = "0.17.3"
7+
val materialWeb = "1.4.1"
8+
9+
10+
// legacy versions that don't need to be updated
11+
612
val webcomponents = "2.6.0"
713
val mwc = "0.25.3"
814

buildSrc/src/main/kotlin/lib-conventions.gradle.kts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
import com.huanshankeji.team.`Shreck Ye`
2-
import com.huanshankeji.team.pomForTeamDefaultOpenSource
3-
import org.gradle.api.publish.maven.MavenPublication
4-
import org.gradle.api.tasks.bundling.Jar
5-
import org.gradle.kotlin.dsl.*
6-
71
plugins {
82
id("com.huanshankeji.kotlin-multiplatform-js-browser-conventions")
93
id("org.jetbrains.compose")
@@ -12,6 +6,7 @@ plugins {
126

137
repositories {
148
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
9+
maven("https://us-central1-maven.pkg.dev/varabyte-repos/public") // for Kobweb
1510
}
1611

1712
group = "com.huanshankeji"

compose-web-common/build.gradle.kts renamed to compose-html-common/build.gradle.kts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ kotlin {
1111
dependencies {
1212
implementation(compose.html.core)
1313
implementation(compose.runtime)
14-
implementation(commonDependencies.kotlinx.coroutines.core())
14+
api("com.varabyte.kobweb:compose-html-ext:${DependencyVersions.kobweb}")
15+
//implementation(commonDependencies.kotlinx.coroutines.core())
1516
}
1617
}
1718
}
@@ -20,8 +21,8 @@ kotlin {
2021
publishing.publications.withType<MavenPublication> {
2122
pomForTeamDefaultOpenSource(
2223
project,
23-
"Huanshankeji Compose for Web common",
24-
"Huanshankeji's common code for Compose for Web"
24+
"Huanshankeji Compose HTML common",
25+
"Huanshankeji's common code for Compose HTML"
2526
) {
2627
`Shreck Ye`()
2728
}

compose-web-common/src/jsMain/kotlin/com/huanshankeji/compose/web/Layouts.kt renamed to compose-html-common/src/jsMain/kotlin/com/huanshankeji/compose/web/Layouts.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ fun Flexbox(
3030
}
3131
} + attrs, content)
3232

33-
@Composable
33+
@PreferringKobwebComposeLayoutApi
3434
@Deprecated(WITH_STYLES_DEPRECATED_MESSAGE)
35+
@Composable
3536
fun FlexboxS(styles: Styles? = null, content: ContentBuilder<HTMLDivElement>) =
3637
Flexbox(styles.wrapInAttrs(), content)
3738

39+
@PreferringKobwebComposeLayoutApi
3840
@Composable
3941
fun Column(
4042
attrs: AttrBuilderContext<HTMLDivElement>? = null,
@@ -48,11 +50,13 @@ fun Column(
4850
}
4951
} + attrs, content)
5052

51-
@Composable
53+
@PreferringKobwebComposeLayoutApi
5254
@Deprecated(WITH_STYLES_DEPRECATED_MESSAGE)
55+
@Composable
5356
fun ColumnS(styles: Styles? = null, fitContent: Boolean = true, content: ContentBuilder<HTMLDivElement>) =
5457
Column(styles.wrapInAttrs(), fitContent, content)
5558

59+
@PreferringKobwebComposeLayoutApi
5660
@Composable
5761
fun ColumnWithSpaceBetween(
5862
attrs: AttrBuilderContext<HTMLDivElement>? = null,
@@ -66,6 +70,7 @@ fun ColumnWithSpaceBetween(
6670
} + attrs, fitContent, content)
6771

6872

73+
@PreferringKobwebComposeLayoutApi
6974
@Composable
7075
fun Row(
7176
attrs: AttrBuilderContext<HTMLDivElement>? = null,
@@ -77,14 +82,16 @@ fun Row(
7782
}
7883
} + attrs, content)
7984

80-
@Composable
85+
@PreferringKobwebComposeLayoutApi
8186
@Deprecated(WITH_STYLES_DEPRECATED_MESSAGE)
87+
@Composable
8288
fun RowS(
8389
styles: Styles? = null,
8490
content: ContentBuilder<HTMLDivElement>
8591
) =
8692
Row(styles.wrapInAttrs(), content)
8793

94+
@PreferringKobwebComposeLayoutApi
8895
@Composable
8996
fun RowWithSpaceBetween(
9097
attrs: AttrBuilderContext<HTMLDivElement>? = null,
@@ -96,6 +103,7 @@ fun RowWithSpaceBetween(
96103
}
97104
} + attrs, content)
98105

106+
@PreferringKobwebComposeLayoutApi
99107
@Composable
100108
fun ColumnWithGaps(
101109
attrs: AttrBuilderContext<HTMLDivElement>? = null,
@@ -109,6 +117,7 @@ fun ColumnWithGaps(
109117
}
110118
} + attrs, fitContent, content)
111119

120+
@PreferringKobwebComposeLayoutApi
112121
@Composable
113122
fun RowWithGaps(
114123
attrs: AttrBuilderContext<HTMLDivElement>? = null,
@@ -158,6 +167,8 @@ fun FrGrid(
158167
}
159168
}, content)
160169

170+
@PreferringKobwebComposeLayoutApi
171+
@Deprecated("This API is not implemented yet.")
161172
@Composable
162173
fun Spacer(numPxs: Int) =
163174
TODO() as Unit
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.huanshankeji.compose.web
2+
3+
@RequiresOptIn(
4+
"You are recommend to use the similar layout APIs in Kobweb Compose. See \"https://github.com/varabyte/kobweb/tree/main/frontend/kobweb-compose/src/jsMain/kotlin/com/varabyte/kobweb/compose/foundation/layout\".",
5+
RequiresOptIn.Level.WARNING
6+
)
7+
@Retention(AnnotationRetention.BINARY)
8+
@Target(AnnotationTarget.FUNCTION)
9+
annotation class PreferringKobwebComposeLayoutApi

0 commit comments

Comments
 (0)