Skip to content

Commit 2b04671

Browse files
authored
Merge pull request #357 from side-codes/module-split
Split the pickers into colorpicker-foundation and colorpicker-material3
2 parents 2417f41 + 581139b commit 2b04671

143 files changed

Lines changed: 2069 additions & 1643 deletions

File tree

Some content is hidden

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

‎.gitattributes‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@
2929

3030
# Generated, and noisy in review.
3131
kotlin-js-store/** linguist-generated=true
32-
colorpicker/api/** linguist-generated=true
32+
*/api/** linguist-generated=true

‎.github/workflows/build.yml‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ jobs:
3030
java-version: '21'
3131
- uses: gradle/actions/setup-gradle@v6
3232
- name: Build libraries
33-
run: ./gradlew :colorpicker:assemble :color:assemble :color-compose:assemble
33+
run: ./gradlew :colorpicker-foundation:assemble :colorpicker-material3:assemble :color:assemble :color-compose:assemble
3434
- name: Run tests
35-
run: ./gradlew :colorpicker:allTests :color:allTests :color-compose:allTests
35+
run: ./gradlew :colorpicker-foundation:allTests :colorpicker-material3:allTests :color:allTests :color-compose:allTests
36+
# colorpicker-foundation is for apps on another design system; Material must not reach them through it.
37+
- name: Check the foundation carries no Material
38+
run: ./gradlew :colorpicker-foundation:checkNoMaterial
3639
# Fails when public API drifts from each library's api/. Without this the
3740
# binary-compatibility plugin is configured but never consulted.
3841
- name: Check the public API matches the committed dump
@@ -93,6 +96,6 @@ jobs:
9396
xcodebuild -version
9497
9598
- name: Build iOS framework
96-
run: ./gradlew :colorpicker:linkDebugFrameworkIosSimulatorArm64
99+
run: ./gradlew :colorpicker-material3:linkDebugFrameworkIosSimulatorArm64
97100
- name: Run iOS simulator tests
98-
run: ./gradlew :colorpicker:iosSimulatorArm64Test :color:iosSimulatorArm64Test :color-compose:iosSimulatorArm64Test
101+
run: ./gradlew :colorpicker-foundation:iosSimulatorArm64Test :colorpicker-material3:iosSimulatorArm64Test :color:iosSimulatorArm64Test :color-compose:iosSimulatorArm64Test

‎.github/workflows/publish.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
fi
7272
7373
- name: Run tests
74-
run: ./gradlew :colorpicker:allTests :color:allTests :color-compose:allTests
74+
run: ./gradlew :colorpicker-foundation:allTests :colorpicker-material3:allTests :color:allTests :color-compose:allTests
7575

7676
- name: Check the public API matches the committed dump
7777
run: ./gradlew apiCheck

‎CHANGELOG.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
## 2.0.0 (unreleased)
44

5-
2.0 builds the pickers on a color model of its own, following CSS Color 4, and removes 1.x's color classes, sliders and planes. [Migrating from 1.x](README.md#-migrating-from-1x) maps each removed declaration to its replacement.
5+
2.0 builds the pickers on a color model of its own, following CSS Color 4, publishes them as Material 3 components over a foundation any design system can draw, and removes 1.x's color classes, sliders and planes. [Migrating from 1.x](README.md#-migrating-from-1x) maps each removed declaration to its replacement.
66

77
### Breaking changes
88

9+
- **`codes.side:colorpicker` stops at 1.2.1.** 2.0 is `codes.side:colorpicker-material3`, which brings `codes.side:colorpicker-foundation`: the state, the `Basic*` components and the strings, with no Material dependency, for an app on another design system.
10+
- **The Material components, `ColorPickerTheme`, `ColorPickerDefaults` and the theme classes are in `codes.side.colorpicker.material3`,** one package as `androidx.compose.material3` is, where 1.x had `codes.side.colorpicker.ui` and `codes.side.colorpicker.theme`.
911
- **A color is a `ColorValue`.** The `model`, `conversion` and `util` packages are gone: `HslColor`, `RgbColor`, `CmykColor`, `LabColor`, `OklabColor`, `OklchColor`, `OkhslColor`, `OkhsvColor`, `PickerColor`, their conversions and hex functions, and `randomHslColor`. A `ColorValue` is a color in one of fifteen spaces, in CSS's units, so HSL's saturation and lightness run 0–100 rather than 0–1.
1012
- **`ColorPickerState` holds a `ColorValue`.** It is built from a `ColorValue` or a Compose `Color`, with no default. `state.value`, `state[channel]` and fifteen typed views (`state.hsl`, `state.okLch`, …) replace the eight typed getters, `pickerColor` and `argbInt`, and `state[channel] = x` and `state.set(view)` replace the thirty `update…` functions. Writing NaN or a value outside a channel's limit throws where 1.x ignored or clamped it.
1113
- **The 21 channel sliders and the three planes are gone.** `ChannelSlider(state, channel)` and `ChannelPlane(state, x, y)` take any channel of any space.
@@ -24,7 +26,7 @@
2426
- **`PlaneActionLabels` moves to `codes.side.colorpicker.foundation`.**
2527
- **`ColorPickerColors`, `ColorPickerShapes` and `ColorPickerDimensions` are no longer data classes,** so they have no `componentN`. `copy` keeps a color or size left `Unspecified` and a shape left `null`, as Material's own color and shape classes do, and so do `ColorPickerDefaults.colors()`, `shapes()` and `dimensions()`.
2628
- **`LocalColorPickerColors`, `LocalColorPickerShapes` and `LocalColorPickerDimensions` are no longer public.** `ColorPickerTheme` provides the values, and `ColorPickerDefaults.currentColors()`, `currentShapes()` and `currentDimensions()` read them.
27-
- **A `thumb` slot reads its component's scope** instead of being handed an `InteractionSource`: `thumb = { MyThumb(interactionSource, thumbColor) }`. A slider's scope carries its position, whether it is enabled, its interactions and the opaque color under the thumb, and a channel or alpha slider's its channel and value, or its alpha, too; a plane's carries its position, and a channel plane's its channels and the color under the thumb. A picker's `thumb` reaches its sliders the same way.
29+
- **A `thumb` slot reads its component's scope** instead of being handed an `InteractionSource`: `thumb = { MyThumb(interactionSource, thumbColor) }`. A slider's scope carries its position, whether it is enabled, its interactions and the opaque color under the thumb, and a channel or alpha slider's its channel and value, or its alpha, too; a plane's carries its position, and a channel plane's its channels and the color under the thumb. A picker's `thumb` reaches its sliders the same way. It is no longer nullable: leave it out for the default.
2830
- **Sliders and planes take `dimensions`** in place of `thumbWidth`, `thumbTrackGap` and `ColorSlider`'s `trackHeight`. `dimensions = ColorPickerDefaults.currentDimensions().copy(thumbWidth = 48.dp)` changes one size and keeps the theme's others.
2931
- **`ColorSlider` takes `trackColors: List<Color>`** in place of `gradientColors: ImmutableList<Color>`. kotlinx-collections-immutable is no longer a dependency.
3032

@@ -49,6 +51,8 @@
4951
- **`ColorPickerDefaults.SliderThumb` and `ColorPickerDefaults.PlaneThumb`,** the default slider and plane thumbs, for a `thumb` slot that draws them beside something of its own.
5052
- **`ColorPickerDefaults.plane()`, `channelSlider()` and `alphaSlider()`,** the slots a picker draws by default, for a slot that wraps one.
5153
- **`orientation` and `dimensions` on every picker.** `Orientation.Horizontal` puts the plane beside the sliders.
54+
- **`LocalColorPickerEnabled`,** false inside a disabled `BasicColorPicker`: for a label or frame of your own, outside every slot's scope, that should look disabled with the picker.
55+
- **`rememberCheckerboardBrush(light, dark)`,** the checkerboard `Modifier.checkerboard` draws, as a `Brush` for a shape of your own.
5256

5357
## 1.2.1
5458

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ In order to create a new feature request or bug report just file an issue. To fi
1818
- Send pull requests targeting **master** (fork the repository if you don't have write access).
1919
- CI (`build.yml`) must pass before a pull request can be merged.
2020

21-
Versioning follows [Semantic Versioning](https://semver.org): public API is added only in a minor release and removed or changed incompatibly only in a major one, and a patch leaves it alone. CI runs `scripts/check-api-removals.sh`, which fails when a declaration in the API dumps at the last release tag is missing from `colorpicker/api/`; run it before proposing an API change. It catches removed declarations and changed signatures, not a class losing a supertype, so that still needs a reviewer's eye.
21+
Versioning follows [Semantic Versioning](https://semver.org): public API is added only in a minor release and removed or changed incompatibly only in a major one, and a patch leaves it alone. CI runs `scripts/check-api-removals.sh`, which fails when a declaration in the API dumps at the last release tag is missing from its module's `api/`; run it before proposing an API change. It catches removed declarations and changed signatures, not a class losing a supertype, so that still needs a reviewer's eye.
2222

2323
Our code style is defined via the [`.editorconfig`](.editorconfig) file at the repository root; most IDEs (including IntelliJ IDEA and Android Studio) pick it up automatically.
2424

‎README.md‎

Lines changed: 87 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# anyColorPicker
44

5-
Kotlin Multiplatform color picker library for Android, iOS, Desktop (JVM), and Web (Wasm), built with Compose Multiplatform and Material 3.
5+
Kotlin Multiplatform color picker library for Android, iOS, Desktop (JVM), and Web (Wasm), built with Compose Multiplatform: ready-made Material 3 pickers, and the same pickers without Material for a design system of your own.
66

77
> **This README describes 2.0, which is not released yet.** The latest release is 1.2.1, documented at the [v1.2.1 tag](https://github.com/side-codes/anyColorPicker/tree/v1.2.1#readme). [Migrating from 1.x](#-migrating-from-1x) maps one API onto the other.
88
@@ -19,6 +19,7 @@ Kotlin Multiplatform color picker library for Android, iOS, Desktop (JVM), and W
1919
- Alpha channel support
2020
- Color picker dialog
2121
- Material 3 theming via `ColorPickerDefaults` and `ColorPickerTheme`
22+
- The same components without Material, as `Basic*` components that draw what their slots draw, for any other design system
2223
- Accessibility semantics throughout — sliders step by each channel's own unit, and planes take focus, move with the arrow keys, and offer a screen reader one named action per direction
2324
- Words and numbers from one `ColorPickerStrings`, with numbers in the device's format — `40 %` in French, `٤٠٪` in Egyptian Arabic; reword or translate by providing your own
2425
- RTL layout support everywhere but the planes, which map a color space rather than showing progress
@@ -27,7 +28,7 @@ Kotlin Multiplatform color picker library for Android, iOS, Desktop (JVM), and W
2728

2829
```kotlin
2930
// build.gradle.kts
30-
implementation("codes.side:colorpicker:2.0.0")
31+
implementation("codes.side:colorpicker-material3:2.0.0")
3132
```
3233

3334
In a Kotlin Multiplatform project, add it to `commonMain`:
@@ -36,18 +37,23 @@ In a Kotlin Multiplatform project, add it to `commonMain`:
3637
kotlin {
3738
sourceSets {
3839
commonMain.dependencies {
39-
implementation("codes.side:colorpicker:2.0.0")
40+
implementation("codes.side:colorpicker-material3:2.0.0")
4041
}
4142
}
4243
}
4344
```
4445

45-
It brings two smaller modules with it, which also work on their own:
46+
On a design system other than Material, depend on `codes.side:colorpicker-foundation` instead and draw
47+
the pickers yourself: see [Without Material](#without-material).
4648

47-
| Artifact | Holds |
48-
|----------------------------|---------------------------------------------------------------------------------------------|
49-
| `codes.side:color` | `ColorValue`, the color spaces, conversion, gamut mapping, CSS strings and hex. No Compose. |
50-
| `codes.side:color-compose` | `ColorValue.toComposeColor()` and `Color.toColorValue()`. |
49+
Each artifact brings the ones below it, and each works on its own:
50+
51+
| Artifact | Holds |
52+
|-------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
53+
| `codes.side:colorpicker-material3` | The Material 3 pickers, sliders, planes, swatch, dialog and theme, in `codes.side.colorpicker.material3`. |
54+
| `codes.side:colorpicker-foundation` | `ColorPickerState`, in `codes.side.colorpicker.state`; the `Basic*` components and `ColorPickerStrings`, in `codes.side.colorpicker.foundation`. No Material. |
55+
| `codes.side:color-compose` | `ColorValue.toComposeColor()` and `Color.toColorValue()`. |
56+
| `codes.side:color` | `ColorValue`, the color spaces, conversion, gamut mapping, CSS strings and hex. No Compose. |
5157

5258
Published targets: `android`, `jvm`, `iosArm64`, `iosSimulatorArm64`, `wasmJs`.
5359

@@ -589,8 +595,9 @@ keeps them. A string passed to a component still wins over the provided ones.
589595

590596
### Theming
591597

592-
All pickers and components accept `colors`, `shapes` and `dimensions` built with
593-
`ColorPickerDefaults`; the colors and shapes derive from `MaterialTheme` by default:
598+
Every slider, plane and picker accepts `colors`, `shapes` and `dimensions` built with
599+
`ColorPickerDefaults`, and `ColorSwatch` its `colors` and a `shape`; the colors and shapes derive
600+
from `MaterialTheme` by default:
594601

595602
```kotlin
596603
ColorPicker(
@@ -625,6 +632,71 @@ whatever an enclosing `ColorPickerTheme` provided.
625632
each class's `copy` does the same from one you already have, such as
626633
`ColorPickerDefaults.currentColors()`.
627634

635+
### Without Material
636+
637+
`codes.side:colorpicker-foundation` holds the same components with no look of their own. Each draws
638+
what its slots draw, and a slot reads what it needs from a scope: a slider's position, its color and
639+
whether it is enabled, a plane's position, a channel slider's gradient. Dragging, the keyboard, a
640+
screen reader and the picker's disabled state work as they do in the Material components, which are
641+
built on these.
642+
643+
| Material 3 | Foundation |
644+
|-----------------|--------------------------------------------------|
645+
| `ColorPicker` | `BasicColorPicker` |
646+
| `ChannelSlider` | `BasicChannelSlider` |
647+
| `AlphaSlider` | `BasicAlphaSlider` |
648+
| `ColorSlider` | `BasicColorSlider` |
649+
| `ChannelPlane` | `BasicChannelPlane` |
650+
| `ColorPlane` | `BasicColorPlane` |
651+
| `ColorSwatch` | a clip, `Modifier.checkerboard` and a background |
652+
653+
A picker with round thumbs and pill tracks, and nothing from Material:
654+
655+
```kotlin
656+
BasicColorPicker(
657+
state = state,
658+
space = Okhsv,
659+
plane = { s, x, y ->
660+
BasicChannelPlane(
661+
s, x, y,
662+
Modifier.fillMaxWidth().aspectRatio(1.6f),
663+
shape = RoundedCornerShape(16.dp),
664+
thumb = { RoundThumb(thumbColor) },
665+
)
666+
},
667+
channelSlider = { s, channel ->
668+
BasicChannelSlider(
669+
s, channel, Modifier.fillMaxWidth(),
670+
track = { Box(Modifier.fillMaxWidth().height(12.dp).clip(CircleShape).background(gradient)) },
671+
thumb = { RoundThumb(thumbColor) },
672+
)
673+
},
674+
alphaSlider = { s ->
675+
BasicAlphaSlider(
676+
s, Modifier.fillMaxWidth(),
677+
track = {
678+
Box(
679+
Modifier.fillMaxWidth().height(12.dp).clip(CircleShape)
680+
.checkerboard(Color.White, Color.LightGray)
681+
.background(gradient),
682+
)
683+
},
684+
thumb = { RoundThumb(thumbColor) },
685+
)
686+
},
687+
spacing = 16.dp,
688+
)
689+
690+
@Composable
691+
fun RoundThumb(color: Color) {
692+
Box(Modifier.size(24.dp).background(Color.White, CircleShape).padding(3.dp).background(color, CircleShape))
693+
}
694+
```
695+
696+
A slot reads from its scope whether it is enabled. What lies outside every scope, such as a label
697+
drawn above a slider, reads `LocalColorPickerEnabled` to look disabled with the picker. The sample
698+
app's *Built on foundation* section runs a picker like this one.
699+
628700
## 🔗 State Management
629701

630702
`ColorPickerState` holds the color a picker edits, as one `ColorValue`, and the hues it
@@ -709,10 +781,12 @@ produces.
709781
## 🚚 Migrating from 1.x
710782

711783
2.0 replaces 1.x's color classes with `ColorValue` and its per-channel components with ones that
712-
take a channel. The color types live in `codes.side.color`, which `colorpicker` brings with it.
784+
take a channel. The color types live in `codes.side.color`, which `colorpicker-material3` brings with it.
713785

714786
| 1.x | 2.0 | Note |
715787
|---------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|------------------------------------------------------------|
788+
| `implementation("codes.side:colorpicker:1.2.1")` | `implementation("codes.side:colorpicker-material3:2.0.0")` | `codes.side:colorpicker` stops at 1.2.1 |
789+
| `codes.side.colorpicker.ui.*`, `codes.side.colorpicker.theme.*` | `codes.side.colorpicker.material3.*` | |
716790
| `HslColor(hue = 200f, saturation = 0.8f, lightness = 0.5f)` | `Hsl(200.0, 80.0, 50.0)` | CSS's units: HSL's S and L are 0–100 |
717791
| `RgbColor`, `CmykColor`, `LabColor`, `OkhslColor`, `OkhsvColor`, `OklabColor`, `OklchColor` | `Srgb(…)`, `Cmyk(…)`, `Lab(…)`, `Okhsl(…)`, `Okhsv(…)`, `Oklab(…)`, `OkLch(…)` | each a `ColorValue` |
718792
| `hsl.toRgb()`, `rgb.toOklch()`, … | `value.to(Srgb)`, `value.to(OkLch)` | |
@@ -750,12 +824,12 @@ The View-based `codes.side:andcolorpicker` artifact (XML `HSLColorPickerSeekBar`
750824

751825
```diff
752826
- implementation("codes.side:andcolorpicker:0.6.2")
753-
+ implementation("codes.side:colorpicker:2.0.0")
827+
+ implementation("codes.side:colorpicker-material3:2.0.0")
754828
```
755829

756830
There is no 1:1 API mapping — migrate by concept:
757831

758-
| andcolorpicker (View-based) | colorpicker (Compose) |
832+
| andcolorpicker (View-based) | colorpicker-material3 (Compose) |
759833
|----------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|
760834
| `HSLColorPickerSeekBar` (`hslMode` = hue/saturation/lightness) | `ChannelSlider(state, Hsl.H)`, `Hsl.S` or `Hsl.L`, or `HslColorPicker` for all three |
761835
| `RGBColorPickerSeekBar` | `ChannelSlider(state, Srgb.R)`, `Srgb.G` or `Srgb.B`, or `RgbColorPicker` |

0 commit comments

Comments
 (0)