You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 804c556
Browse filesBrowse the repository at this point in the historyBrowse files
feat(Color)!: Color object model by default (#2789 Blocker B) (#3064)
* refactor(Color)!: one convert-on-demand color engine
channel.ts re-implemented every rgb/hsl/hsb conversion from convert.ts.
It now reads and writes channels through convert.ts only:
- getChannelValue reads a channel from the color's own space when it
has one (hue and saturation of an HSB color no longer go through HSL)
- setChannelValues sets every channel in one space that holds them all,
preferring the color's own space; getChannelColorSpace resolves it
- convertToHsl/convertToHsb convert HSL<->HSB directly, keeping the hue
of a grey; convertToSpace is the shared entry point
- isEqualColor is symmetric, accepts strings and is exported
- area gradients take a dir argument for right-to-left
- RGB slider gradients use the real channels of HSL/HSB colors
- parseColor accepts hsv() as documented
Adds direct unit tests for parse, convert and channel (#2789).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* feat(Color)!: emit Color objects from ColorArea, ColorField and ColorSlider
The model-of-record is now the plain `Color` object (#2789 Blocker B).
`modelValue`/`defaultValue` accept `string | Color`; a string is parsed
once. `update:modelValue`, `beforeUpdate:modelValue`, `update:color`,
`change` and `changeEnd` carry a `Color` in the component's color space,
and the new `update:hex` event (`onHexUpdate`) is the opt-in lossy hex
output. Forms still submit hex through the hidden input.
useControllableState compares with `isEqual: isEqualColor`, so the
shadow-precision machinery is gone: ColorArea's `hueValue`, `isUpdating`
guards and `precisionColor`/`precisionChanged`, ColorSlider's
`internalColor`, 2% threshold and achromatic drift handling, and the
same-hex `update:modelValue` exception. Channel values are derived from
the model, so a controlled ColorArea no longer desyncs its thumb from a
parent that rejects an update.
- ColorField edits a channel in the space that holds it: saturation
steps on #050404 no longer stick, and a hue typed for #808080 is kept
- ColorField emits `change` and `changeEnd`; `changeEnd` fires only
after an interaction that changed the color, on every component
- ColorArea gets a `dir` prop (ConfigProvider-aware): mirrored pointer
x, swapped ArrowLeft/ArrowRight, mirrored thumb and gradient
- ColorSwatchPicker root and items accept `string | Color` and compare
structurally
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* docs(Color): document the Color object model and its migration
- component pages: a "Color model" section (v-model emits `Color`,
`update:hex` for hex, `isEqualColor`), ColorArea right-to-left, and
ColorSwatchPicker `string | Color` values
- demos and the color picker example share one `v-model` and derive
their hex label with `colorToHex`
- migration guide and agent guide: new color section; the "known
exception" about same-hex emits is removed
- regenerated docs/content/meta
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(Color): report changeEnd only once the model holds the change
ColorSlider tracked the uncommitted color only until the next commit, and
SliderRoot sends no valueCommit after a drag that ends where it started, so
changeEnd lagged one keyboard step behind from then on. A controlled parent
that rejected updates caused the same lag, and ColorArea reported changeEnd
for updates such a parent rejected.
A shared tracker now records each interaction's start and last color and
reports it only when the model holds the last color and it differs from the
start, waiting a tick for a controlled parent to re-render. A keyboard
valueCommit drops leftover state from an uncommitted drag.
ColorField now watches the formatted value, so an in-place mutation of the
parent's Color updates the input.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* docs(Color): note repeated update:hex strings and changeEnd timing
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* docs(ColorField): regenerate meta for the changeEnd description
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/content/docs/components/color-area.md
+38-4Lines changed: 38 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,8 @@ A two-dimensional area control that allows users to select color values by inter
24
24
'Full keyboard navigation support.',
25
25
'Pointer/touch interaction for value selection.',
26
26
'Preserves hue information when saturation is 0.',
27
+
'Emits a lossless Color object, with an opt-in hex output.',
28
+
'Supports right-to-left direction.',
27
29
'Form integration with hidden inputs.',
28
30
]"
29
31
/>
@@ -66,7 +68,7 @@ import {
66
68
67
69
These composables are experimental. Reactive options accept refs or getters. Pass a writable `modelValue` ref for ref-owned state, or use `onUpdate` to handle controlled updates. `onBeforeUpdate(value, details)` can synchronously call `details.cancel()` to prevent a change. Component users can use `@before-update:model-value` for the same behavior.
68
70
69
-
`useColorArea()` exposes the model, exact channel values, background styles, and shared root and thumb surfaces. Call it in component setup (or an effect scope) so its synchronization watchers are disposed. Create one area surface per element and bind `setThumbElement` to the thumb so pointer interaction can focus it.
71
+
`useColorArea()` exposes the model, exact channel values, background styles, and shared root and thumb surfaces. The channel values and the thumb position are derived from the model, so a controlled parent that rejects an update keeps the thumb where the model is. Create one area surface per element and bind `setThumbElement` to the thumb so pointer interaction can focus it. Pass `dir: 'rtl'` to mirror the x axis.
70
72
71
73
```vue
72
74
<script setup>
@@ -99,7 +101,37 @@ updateValues(75, 50)
99
101
100
102
Hidden form inputs remain part of `ColorAreaRoot`; add them yourself when rendering the composable directly.
101
103
102
-
`onColorUpdate` receives accepted color objects and `onChange` / `onChangeEnd` receive interaction and commit notifications. These callbacks work without a component `emit` function. Returned state refs are read-only; use the exposed actions to request changes.
104
+
`onUpdate`, `onColorUpdate`, `onChange` and `onChangeEnd` receive `Color` objects, and `onHexUpdate` receives the hex serialization of each accepted color. `onChange` fires for every change, `onChangeEnd` once the pointer is released and after each keyboard step. These callbacks work without a component `emit` function. Returned state refs are read-only; use the exposed actions to request changes.
105
+
106
+
## Color model
107
+
108
+
`v-model` accepts a color string (`'#3b82f6'`, `'hsl(217, 91%, 60%)'`) or a `Color` object, and every emitted value is a `Color` object: a plain `{ space, ... }` object in the component's color space, such as `{ space: 'hsl', h: 217, s: 91, l: 60, alpha: 1 }`. A string is parsed once on the way in. Keeping the object keeps information a hex string cannot hold, such as the hue of a grey and fractional channel values, so several color components can share one `v-model` without drift.
109
+
110
+
`update:color` carries the same `Color` as `update:modelValue`. Listen to `update:hex` when you need a hex string, for example for an API or a text label. Hex is lossy: it drops the hue of greys and anything finer than one 8-bit step, so feed the `Color` back into `v-model`, not the hex. For the same reason `update:hex` can repeat the same string when the color moves by less than one step. A form submits the hex value through the hidden input either way.
111
+
112
+
```vue
113
+
<script setup>
114
+
import { ColorAreaArea, ColorAreaRoot, ColorAreaThumb } from 'reka-ui'
115
+
import { ref } from 'vue'
116
+
117
+
const color = ref('#3b82f6') // becomes a Color object after the first change
118
+
const hex = ref('#3b82f6')
119
+
</script>
120
+
121
+
<template>
122
+
<ColorAreaRoot
123
+
v-slot="{ style }"
124
+
v-model="color"
125
+
@update:hex="hex = $event"
126
+
>
127
+
<ColorAreaArea :style="style">
128
+
<ColorAreaThumb />
129
+
</ColorAreaArea>
130
+
</ColorAreaRoot>
131
+
</template>
132
+
```
133
+
134
+
Use `isEqualColor(a, b)` to compare two colors (strings or objects) structurally, and `colorToHex` or `colorToString` to format one.
103
135
104
136
## API Reference
105
137
@@ -227,5 +259,7 @@ const color = ref('#3b82f6')
227
259
|`Shift + ArrowKey`| Changes values by 10 steps at a time. |
228
260
|`PageUp`| Increases the y-axis channel value by a larger step. |
229
261
|`PageDown`| Decreases the y-axis channel value by a larger step. |
230
-
|`Home`| Jumps left (decreases x-axis value). |
231
-
|`End`| Jumps right (increases x-axis value). |
262
+
|`Home`| Decreases the x-axis channel value by a larger step. |
263
+
|`End`| Increases the x-axis channel value by a larger step. |
264
+
265
+
In right-to-left mode (`dir="rtl"`, or inherited from `ConfigProvider`) the x axis runs from right to left: `ArrowLeft` increases and `ArrowRight` decreases the x-axis value, and the thumb and the background gradient are mirrored.
The return also exposes `updateValue`, `commit`, `increment`, `decrement`, page stepping, and min/max actions. Hidden form input rendering remains in `ColorFieldRoot`.
88
89
89
-
`onColorUpdate` receives accepted color objects. These callbacks work without a component `emit` function. Returned state refs are read-only; use the exposed actions to request changes.
90
+
`onUpdate`, `onColorUpdate`, `onChange` and `onChangeEnd` receive `Color` objects, and `onHexUpdate` receives the hex serialization of each accepted color. A field changes only when an edit is committed (Enter or blur) or a value is stepped, so `onChange` and `onChangeEnd` fire together for each change. These callbacks work without a component `emit` function. Returned state refs are read-only; use the exposed actions to request changes.
91
+
92
+
## Color model
93
+
94
+
`v-model` accepts a color string (`'#3b82f6'`, `'hsl(217, 91%, 60%)'`) or a `Color` object, and every emitted value is a `Color` object: a plain `{ space, ... }` object in the component's color space, such as `{ space: 'hsl', h: 217, s: 91, l: 60, alpha: 1 }`. A string is parsed once on the way in. Keeping the object keeps information a hex string cannot hold, such as the hue of a grey and fractional channel values, so several color components can share one `v-model` without drift.
95
+
96
+
`update:color` carries the same `Color` as `update:modelValue`. Listen to `update:hex` when you need a hex string, for example for an API or a text label. Hex is lossy: it drops the hue of greys and anything finer than one 8-bit step, so feed the `Color` back into `v-model`, not the hex. For the same reason `update:hex` can repeat the same string when the color moves by less than one step. A form submits the hex value through the hidden input either way.
97
+
98
+
```vue
99
+
<script setup>
100
+
import { ColorFieldInput, ColorFieldRoot } from 'reka-ui'
101
+
import { ref } from 'vue'
102
+
103
+
const color = ref('#3b82f6') // becomes a Color object after the first change
104
+
const hex = ref('#3b82f6')
105
+
</script>
106
+
107
+
<template>
108
+
<ColorFieldRoot
109
+
v-model="color"
110
+
@update:hex="hex = $event"
111
+
>
112
+
<ColorFieldInput />
113
+
</ColorFieldRoot>
114
+
</template>
115
+
```
116
+
117
+
Use `isEqualColor(a, b)` to compare two colors (strings or objects) structurally, and `colorToHex` or `colorToString` to format one.
118
+
119
+
A channel field edits the color in the space that holds its channel (the `color-space` prop when it does). So with `channel="hue"`, typing a hue for a grey keeps it, and stepping `saturation` moves by whole steps even when a hex input rounded the channel to a fraction.
0 commit comments