• Stars
    star
    114
  • Rank 301,863 (Top 7 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created over 2 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Kompose wrappers for material-components-web

Slack chat Dokka docs Version maven-central Version maven-snapshot

Kompose Material Design Components (KMDC)

The library is currently very experimental with no API stability guarantees. Breaking changes are being introduced each release.

A set of Kotlin wrappers over [email protected] library providing Jetbrains Compose DSL for building beautiful WEB UIs. The API surface is identical to JS version, except for few places where slight adjustments are made to make it more fluid for compose.

Setup

KMDC wraps each MDC module 1:1 and as such allows you to pick and choose which exact components you'd like to use. This is recommended approach as it helps in reducing bundle size. However, for the lazy ones out there, a "shortcut" module is also available, which brings in all KMDC modules as transitive dependencies under a single dependency.

Either approach can be installed by declaring relevant dependencies in your jsMain sourceSet.

Additionally, you need to enable SCSS support.

plugins {
    kotlin("multiplatform")
    id("org.jetbrains.compose")
}
kotlin {
    js {
        browser {
            commonWebpackConfig {
                cssSupport { enabled.set(true) }
                scssSupport { enabled.set(true) }
            }
        }
    }
    sourceSets {
        named("jsMain") {
            dependencies {
                // Be lazy and use the shortcut
                implementation("dev.petuska:kmdc:_")
                implementation("dev.petuska:kmdcx:_")

                // Do some work and see dem gains
                implementation("dev.petuska:kmdc-button:_")
                implementation("dev.petuska:kmdc-radio:_")
                implementation("dev.petuska:kmdcx-icons:_")
            }
        }
    }
}

Usage

Most of the API maps closely to MDC JS API, making all examples there semi-valid. KMDC components follow a specific naming convention to make its components more discoverable as well. The convention is MDC[UpperCamelCaseMDCComponentName] (e.g. MDCTopAppBar) for the top-level component and UpperCamelCaseLogicalName for all subcomponents. Most of the components also follow the same argument order schema:

  1. ...requiredMdcOptions - MDC-specific options with no default values
  2. ...optionalMdcOptions - MDC-specific options with default values 3.attrs: (AttrsBuilder<out HTMLElement>.() -> Unit)? = null - compose attributes builder for the underlying HTML element 4.content: (ComposableBuilder<out HTMLElement>.() -> Unit)? = null - compose inner content builder for the underlying HTML element

Here's a quick peek how these things come together (more showcases can be found in the sandbox)

@Composable
fun Showcase() {
    var checked by remember { mutableStateOf(false) } // Declaring controlled state

    MDCFormField { // Using implicit `content` argument to wrap MDCCheckbox inside MDCFormField UI as recommended by the MDC docs
        MDCCheckbox(
            checked = checked,
            label = "Yes/No",
            attrs = { // Overriding underlying HTMLInput element attributes
                onInput { checked = !checked }
            }
        ) // MDCCheckbox doesn't allow for additional inner content
    }
}

Progress

Here's a tracker list of currently completed material-components-web modules:

  • kmdc-animation (SASS)
  • kmdc-auto-init (won't wrap)
  • kmdc-banner
  • kmdc-base (won't wrap)
  • kmdc-button
  • kmdc-card
  • kmdc-checkbox
  • kmdc-chips
  • kmdc-circular-progress
  • kmdc-data-table
  • kmdc-density (won't wrap)
  • kmdc-dialog
  • kmdc-dom (won't wrap)
  • kmdc-drawer
  • kmdc-elevation
  • kmdc-fab
  • kmdc-feature-targeting (won't wrap)
  • kmdc-floating-label
  • kmdc-form-field
  • kmdc-icon-button
  • kmdc-image-list
  • kmdc-layout-grid
  • kmdc-line-ripple
  • kmdc-linear-progress
  • kmdc-list
  • kmdc-menu-surface
  • kmdc-menu
  • kmdc-notched-outline
  • kmdc-progress-indicator (won't wrap)
  • kmdc-radio
  • kmdc-ripple
  • kmdc-rtl (SASS)
  • kmdc-segmented-button
  • kmdc-select
  • kmdc-shape (SASS)
  • kmdc-slider
  • kmdc-snackbar
  • kmdc-switch
  • kmdc-tab-bar
  • kmdc-tab-indicator
  • kmdc-tab-scroller
  • kmdc-tab
  • kmdc-textfield
  • kmdc-theme (SASS)
  • kmdc-tokens (won't wrap)
  • kmdc-tooltip
  • kmdc-top-app-bar
  • kmdc-touch-target
  • kmdc-typography

Other libraries and extensions:

  • kmdc-icons

Module Structure

KMDC project modules can be categorised into three groups:

  • Core MDC wrappers - grouped under ./kmdc meta-module
  • Extensions of core wrappers or relevant non-kmdc wrappers - grouped under ./kmdcx meta-module

Developer Setup

  • Install JDK 11+
  • Run ./gradlew assemble to build js binaries
  • Use ./sandbox/ to render components in browser (needs to be linked separately in IDEA)
    • ./gradlew jsBrowserRun -t to start development server
    • Visit http://localhost:3000 to see your content
    • If you're adding a new component, render it by creating Showcases file for it
    • Thanks to gradle continuous mode, any change in kmdc modules will trigger automatic refresh of sandbox and the browser. It takes a few seconds after you save your changes, so be patient.

Further details can be found in Contributing Guidelines

Contributing

All contributions are welcome. Have a look for a good first issue in the issue tracker, or open your own issue if you have some ideas. If you want to chat, either start a discussion or ping me on slack.

Further details can be found in Contributing Guidelines

Thanks to all the people who contributed to kmdc so far!

More Repositories

1

npm-publish

Gradle plugin for NPM package publishing. Allows for arbitrary publishing as well as seamless integration with Kotlin JS/MPP plugins.
Kotlin
119
star
2

template-kmp-library

Kotlin multiplatform library template.
Kotlin
65
star
3

kamp

Package discovery website and scanner for Kotlin multiplatform.
Kotlin
54
star
4

kon

Kotlin Object Notation - Lightweight DSL to build fluid JSON trees
Kotlin
47
star
5

ktx

npx for kotlin and the JVM! Install and execute jars or kotlin scripts just like any other command line utility.
Kotlin
41
star
6

klip

Kotlin Multiplatform snapshot ((c|k)lip) manager for tests.
Kotlin
24
star
7

monko

Kotlin MPP bindings for mongodb driver.
Kotlin
8
star
8

gradle-kotlin-delegates

Various kotlin delegates to manage lazy gradle properties
Kotlin
8
star
9

khakra

Kotlin React bindings for ChakraUI
Kotlin
5
star
10

dekorator

Kotlin multiplatform decorators support
Kotlin
3
star
11

kommander

Kotlin MPP bindings for various clis
Kotlin
3
star
12

hazelcast-explorer

A webapp for direct access to Hazelcast data clusters.
Kotlin
3
star
13

aoc-2021-kmp

Advent of Code 2021 in Kotlin Multiplatform!
Kotlin
2
star
14

container-tasks-gradle

Gradlee plugin for managing jekyll workflows
Kotlin
2
star
15

transaction-api

Kotlin
2
star
16

kvdom

Kotlin Virtual DOM MPP implementation for WASM & JS
Kotlin
2
star
17

kwasm

A sample repo for new Kotlin/WASM setup
Kotlin
2
star
18

application.env

.env file loader for node and browser
TypeScript
1
star
19

kotlin-sandbox

A clean and minimal setup for kotlin experiments.
Kotlin
1
star
20

MyMiniMap

An addon for Elder Scrolls Online to provide a minimap functionality.
Lua
1
star
21

kursor

Kotlin Multiplatform implementation of JSON Path spec
Kotlin
1
star
22

template-azure-functions-kotlin-js

Sample project for NodeJS based azure functions with kotlin.
Kotlin
1
star