MFlisar/ComposeColors

Provides sets of color definitions for KMP (Material, X11)

โ˜… 1Forks 0KotlinGitHub โ†—Compare

Project website โ†—

README

Maven Central API Kotlin Kotlin Multiplatform

ComposeColors

Platforms Android iOS Windows macOS WebAssembly

This library offers you compose color definitions and optionally also palettes for the colors.

Note

All features are splitted into separate modules, just include the modules you want to use!

Table of Contents

๐Ÿ“ท Screenshots

material

material

x11

x11

๐Ÿ’ป Supported Platforms

Module android iOS windows macOS wasm Notes
core โœ… โœ… โœ… โœ… โœ… provides all the basic classes
material โœ… โœ… โœ… โœ… โœ… provides constants for all material colors
material-palette โœ… โœ… โœ… โœ… โœ… provides a palette class for all material colors
x11 โœ… โœ… โœ… โœ… โœ… provides constants for all x11 colors
x11-palette โœ… โœ… โœ… โœ… โœ… provides a palette class for all x11 colors

โžก๏ธ Versions

Dependency Version
Kotlin 2.4.0
Jetbrains Compose 1.11.1
Jetbrains Compose Material3 1.9.0

๐Ÿ”ง Setup

Using Version Catalogs

Define the dependencies inside your libs.versions.toml file.

[versions]

composecolors = "<LATEST-VERSION>"

[libraries]

composecolors-core = { module = "io.github.mflisar.composecolors:core", version.ref = "composecolors" }
composecolors-material = { module = "io.github.mflisar.composecolors:material", version.ref = "composecolors" }
composecolors-material-palette = { module = "io.github.mflisar.composecolors:material-palette", version.ref = "composecolors" }
composecolors-x11 = { module = "io.github.mflisar.composecolors:x11", version.ref = "composecolors" }
composecolors-x11-palette = { module = "io.github.mflisar.composecolors:x11-palette", version.ref = "composecolors" }

And then use the definitions in your projects build.gradle.kts file like following:

implementation(libs.composecolors.core)
implementation(libs.composecolors.material)
implementation(libs.composecolors.material.palette)
implementation(libs.composecolors.x11)
implementation(libs.composecolors.x11.palette)
Direct Dependency Notation

Simply add the dependencies inside your build.gradle.kts file.

val composecolors = "<LATEST-VERSION>"

implementation("io.github.mflisar.composecolors:core:${composecolors}")
implementation("io.github.mflisar.composecolors:material:${composecolors}")
implementation("io.github.mflisar.composecolors:material-palette:${composecolors}")
implementation("io.github.mflisar.composecolors:x11:${composecolors}")
implementation("io.github.mflisar.composecolors:x11-palette:${composecolors}")

๐Ÿš€ Usage

Basic examples

// returns instance of `androidx.compose.ui.graphics.Color`

// Material Colors
val red500 = MaterialColor.Red500
val blue500 = MaterialColor.Blue500
// ...

// X11 Colors
val aliceBlue = X11.AliceBlue
val antiqueWhite = X11.AntiqueWhite
// ...

Color Palettes

If desired, I offer *-palette modules that offer string names, enums and groups.

val palette = MaterialColor.Palette
when (palette) {
    is ColorPalette.Definition -> {
        // this palette does simple provide you a list of all available colors
        val paletteName: String = palette.name
        palette.colors.forEach {
            val colorName: String = it.name // e.g. AliceBlue, AntiqueWhite, Aqua, ...
            val color: Color = it.color
            // ...
        }
    }
    is ColorPalette.Grouped -> {
        val paletteName: String = palette.name
        palette.groups.forEach {
            val groupName: String = it.name // e.g. Red, Green, Blue, ...
            it.colors.forEach {
                val colorName: String = it.name  // e.g. Red500, Blue500, ...
                val color: Color = it.color
                // ...
            }
        }
    }
}

โœจ Demo

A full demo is included inside the demo module, it shows nearly every usage with working examples.

๐Ÿ“š API

Check out the API documentation.

๐Ÿ’ก Other Libraries

You can find more libraries (all multiplatform) of mine that all do work together nicely here.

Contributors

MFlisarMFlisarWorkgithub-actions[bot]

Issues