Giter Club home page Giter Club logo

compose-multiplatform-material's Introduction

Compose Multiplatform Material (better name pending): unified Compose Multiplatform common extensions and Material wrappers for androidx.compose and Compose HTML

Maven Central Kotlin version

Unified Compose Multiplatform wrappers of common components, layouts, and Material Design components for androidx.compose (officially supported on Android, desktop (JVM), iOS, and web (Kotlin/Wasm)) and Compose HTML (mainly based on Kobweb Silk Compose, KMDC, and Compose HTML Material (which is then based on Material Web))

We try to provide a set of common extensions and composable component APIs akin to those in androidx.compose (androidx.compose.foundation, androidx.compose.material, and androidx.compose.material3), meanwhile making them compatible with the Compose HTML APIs. However, only subsets of the composables and composable parameters are supported due to the API differences, limitations of the JS (web) platform and the Compose HTML composables this project depends on, and our limited effort.

Complete visual consistency across different platforms is not guaranteed.

This project is still in development and has not reached the stable state yet. Some APIs are likely to be changed and there is no detailed documentation yet. Check out the demo project on how to use the components in addition to the information below.

Supported features

Components

Foundation components

  • BasicText
ext components
  • InlineBasicText
Layouts
  • Box
  • Column (via flexbox on JS)
  • Row (via flexbox on JS)
  • Spacer
Lazy
  • LazyColumn
  • LazyRow

Material 2 components

  • Button
  • Card
  • Checkbox
  • Divider (not working properly on JS yet)
  • Icon
  • IconButton
  • Switch
  • Text
ext components
  • Button
  • IconButton
  • RadioRow, RadioGroupRow
  • SwitchWithLabel
  • MaterialText, InlineText
  • TextField, OutlinedTextField
  • TopAppBarScaffold
lazy.ext components
  • List/LazyColumnList (visually inconsistent for now)

Material 3 components

  • Button (FilledButton), ElevatedButton, FilledTonalButton, OutlinedButton, TextButton
  • Card (FilledCard), ElevatedCard, OutlinedCard
  • Checkbox
  • FloatingActionButton, SmallFloatingActionButton, LargeFloatingActionButton, ExtendedFloatingActionButton
  • Icon
  • IconButton, IconToggleButton, FilledIconButton, FilledIconToggleButton, FilledTonalIconButton, FilledTonalIconToggleButton, OutlinedIconButton, OutlinedIconToggleButton
  • Switch
  • Text
ext components
  • Button (FilledButton), ElevatedButton, FilledTonalButton, OutlinedButton, TextButton
  • Card (FilledCard), ElevatedCard, OutlinedCard
  • FloatingActionButton, SmallFloatingActionButton, LargeFloatingActionButton, ExtendedFloatingActionButton
  • IconButton, IconToggleButton, FilledIconButton, FilledIconToggleButton, FilledTonalIconButton, FilledTonalIconToggleButton, OutlinedIconButton, OutlinedIconToggleButton
  • NavigationBar, NavigationBarItem
  • MaterialText, InlineText
  • TextField, OutlinedTextField
lazy.ext components
  • List/LazyColumnList (slightly visually inconsistent)

About ext components (components in the ext packages)

The components in the ext packages don't follow the androidx.compose APIs exactly, but rather provide wrappers are more idiomatic and conventional on both kinds of targets, wrapping different APIs which can't be unified following the androidx.compose APIs.

Material Icons

The com.huanshankeji.compose.material.icons.Icon class delegates to both kinds of targets, but only a few Material Icons are added as PoC. You need to add your concrete icon implementations following the style of the existing ones in com.huanshankeji.compose.material.icons to use the icons you need. Track the progress of full icon support in #4.

Modifiers

  • size modifiers
    • size, sizeIn, fillMaxSize
    • width, widthIn, fillMaxWidth
    • height, heightIn, fillMaxHeight
  • padding
  • background
  • border (visually inconsistent)
  • onClick
  • verticalScroll, horizontalScroll (ScrollState not supported on JS yet)

ext modifiers

  • outerBorder
  • roundedCornerBackgroundAndOuterBorder

Other APIs

  • Alignment
  • Arrangement
  • KeyboardOptions
  • KeyboardActions

Add the libraries to your dependency

Maven coordinate:

"com.huanshankeji:compose-multiplatform-$module:$version"

More specifically:

"com.huanshankeji:compose-multiplatform-common:$version"
"com.huanshankeji:compose-multiplatform-material-icons-core:$version"
"com.huanshankeji:compose-multiplatform-material2:$version"
"com.huanshankeji:compose-multiplatform-material3:$version"

For example, depend on the Material 3 module with Gradle:

kotlin {
    sourceSets {
        commonMain {
            dependencies {
                // ...
                implementation("com.huanshankeji:compose-multiplatform-material3:$version")
            }
        }
    }
}

View all the artifacts on Maven Central.

This project depends on Kobweb which is not published to Maven Central yet, so you have to add the following Maven repository:

repositories {
    mavenCentral()
    maven("https://us-central1-maven.pkg.dev/varabyte-repos/public")
}

Material Symbols & Icons on JS

See the corresponding section in Compose HTML Material for configuring Material Icons on JS.

About Kobweb Silk

The Kotlin/JS (Compose HTML) portion of this project depends on Kobweb Compose of Kobweb Silk which is a UI layer built upon Compose HTML that provides Modifier (type-safe CSS API wrappers) and layout APIs. Here is a list of topics in their README.md that should be helpful when you use this library in Compose HTML, especially if you need to customize the components further on Kotlin/JS (Compose HTML):

  1. Silk
    1. Modifier
      1. attrsModifier and styleModifier
  2. General purpose improvements on top of Compose HTML and Kotlin/JS
  3. What about Compose Multiplatform for Web?

compose-multiplatform-material's People

Contributors

shreckye avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

compose-multiplatform-material's Issues

Rename the Material 2 module's name and package to `material2` explicitly

Since Material 3 is the major version used now, I think the Material 2 module's name and package should be renamed to material2 explicitly to prevent anyone from thinking that's the recommended module. Jetpack Compose (or androidx.compose) probably keeps the name for compatibility reasons.

Consider using `Modifier`s and layouts from Kobweb Silk

Kobweb Silk already provides a set of Modifier and layout implementations that look quite comprehensive. Use their implementation directly instead implementing them by ourselves if possible.

See code in https://github.com/varabyte/kobweb/tree/main/frontend/kobweb-compose/src/jsMain/kotlin/com/varabyte/kobweb/compose/ui and https://github.com/varabyte/kobweb/tree/main/frontend/kobweb-compose/src/jsMain/kotlin/com/varabyte/kobweb/compose/ui/modifiers.

A common interface for `Modifier` and CSS styles instead of HTML attributes

After working on this project for a while it seems to me that a Compose Modifier is more similar to the CSS styles in the style attribute instead of all the attributes of an HTML element, while HTML attributes are more similar to a Composable's arguments. If this is investigated to be true in most cases, modify the existing ModifierOrAttrs interface into a common interface for Modifier and CSS styles instead of HTML attributes.

Make the demo UI friendly on mobile

Currently the demo shows 3 columns which don't fit well on a mobile device narrow screen. Also consider integrating the navigation library at the same time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.