|
1 | | -# Compose for Web (now Compose HTML) Material |
| 1 | +# Compose HTML Material |
2 | 2 |
|
3 | | -[](https://search.maven.org/artifact/com.huanshankeji/compose-web-material) |
4 | | -[](https://plugins.gradle.org/plugin/com.huanshankeji.compose-web-material-conventions) |
| 3 | +[](https://search.maven.org/artifact/com.huanshankeji/compose-html-material3) |
5 | 4 |
|
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) |
7 | 6 |
|
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). |
9 | 8 |
|
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). |
11 | 10 |
|
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 |
15 | 12 |
|
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)). |
17 | 14 |
|
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: |
19 | 16 |
|
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` |
21 | 25 |
|
22 | | -```kotlin |
23 | | -implementation("com.huanshankeji:compose-web-material:$version") |
24 | | -``` |
| 26 | +### "labs" components |
25 | 27 |
|
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: |
27 | 29 |
|
28 | | -Call `mwcRequires()` in your `main` function before calling any component Composable functions. |
| 30 | +- `MdElevatedCard`, `MdOutlinedCard` |
| 31 | +- `MdNavigationBar` |
| 32 | +- `MdNavigationTab` |
29 | 33 |
|
30 | | -### Kotlin/JS Webpack configuration |
| 34 | +You should opt-in to `@MaterialWebLabsApi` to use them. |
31 | 35 |
|
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 |
33 | 39 |
|
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: |
35 | 41 |
|
36 | 42 | ```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 | + } |
39 | 52 | } |
40 | 53 | ``` |
41 | 54 |
|
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). |
0 commit comments