@tangible/ui 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/ColorPicker/ColorArea.d.ts +24 -0
- package/components/ColorPicker/ColorArea.js +62 -0
- package/components/ColorPicker/ColorField.d.ts +59 -0
- package/components/ColorPicker/ColorField.js +88 -0
- package/components/ColorPicker/ColorPicker.d.ts +36 -0
- package/components/ColorPicker/ColorPicker.js +215 -0
- package/components/ColorPicker/ColorSlider.d.ts +20 -0
- package/components/ColorPicker/ColorSlider.js +38 -0
- package/components/ColorPicker/index.d.ts +14 -0
- package/components/ColorPicker/index.js +7 -0
- package/components/ColorPicker/labels.d.ts +42 -0
- package/components/ColorPicker/labels.js +38 -0
- package/components/ColorPicker/tracks.d.ts +4 -0
- package/components/ColorPicker/tracks.js +4 -0
- package/components/ColorPicker/usePointerDrag.d.ts +13 -0
- package/components/ColorPicker/usePointerDrag.js +34 -0
- package/components/Popover/index.d.ts +1 -1
- package/components/index.d.ts +3 -0
- package/components/index.js +1 -0
- package/icons/icons.svg +1 -0
- package/icons/manifest.json +8 -0
- package/icons/registry.d.ts +2 -0
- package/icons/registry.js +1 -0
- package/icons/system/index.d.ts +2 -0
- package/icons/system/index.js +11 -0
- package/package.json +5 -1
- package/styles/all.css +1 -1
- package/styles/all.expanded.css +273 -0
- package/styles/all.expanded.unlayered.css +273 -0
- package/styles/all.unlayered.css +1 -1
- package/styles/components/_bundle.scss +2 -0
- package/styles/components/color-picker.scss +378 -0
- package/tui-manifest.json +94 -4
- package/utils/color/color.d.ts +61 -0
- package/utils/color/color.js +293 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Hsva } from '../../utils/color/color';
|
|
2
|
+
export type ColorAreaProps = {
|
|
3
|
+
hsva: Hsva;
|
|
4
|
+
/** Fires with the new saturation/value (0..1) as the thumb moves. */
|
|
5
|
+
onValueChange: (next: {
|
|
6
|
+
s: number;
|
|
7
|
+
v: number;
|
|
8
|
+
}) => void;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
'aria-label'?: string;
|
|
11
|
+
/** Overrides the default "Saturation X%, brightness Y%" announcement. */
|
|
12
|
+
valueText?: string;
|
|
13
|
+
className?: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* 2D saturation × value surface. The background is the current hue with a
|
|
17
|
+
* white→hue horizontal gradient (saturation) and a transparent→black vertical
|
|
18
|
+
* gradient (value); the thumb sits at (s, 1 − v). Pointer-draggable and
|
|
19
|
+
* keyboard-adjustable (arrows; Shift = coarse).
|
|
20
|
+
*
|
|
21
|
+
* role="slider" with a 2D aria-valuetext — a pragmatic model for a 2D picker;
|
|
22
|
+
* the a11y pass may refine to paired sliders.
|
|
23
|
+
*/
|
|
24
|
+
export declare function ColorArea({ hsva, onValueChange, disabled, 'aria-label': ariaLabel, valueText, className, }: ColorAreaProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
import { cx } from '../../utils/cx.js';
|
|
4
|
+
import { formatColor } from '../../utils/color/color.js';
|
|
5
|
+
import { usePointerDrag, clamp01 } from './usePointerDrag.js';
|
|
6
|
+
/**
|
|
7
|
+
* 2D saturation × value surface. The background is the current hue with a
|
|
8
|
+
* white→hue horizontal gradient (saturation) and a transparent→black vertical
|
|
9
|
+
* gradient (value); the thumb sits at (s, 1 − v). Pointer-draggable and
|
|
10
|
+
* keyboard-adjustable (arrows; Shift = coarse).
|
|
11
|
+
*
|
|
12
|
+
* role="slider" with a 2D aria-valuetext — a pragmatic model for a 2D picker;
|
|
13
|
+
* the a11y pass may refine to paired sliders.
|
|
14
|
+
*/
|
|
15
|
+
export function ColorArea({ hsva, onValueChange, disabled, 'aria-label': ariaLabel = 'Saturation and brightness', valueText, className, }) {
|
|
16
|
+
const ref = useRef(null);
|
|
17
|
+
const drag = usePointerDrag((clientX, clientY) => {
|
|
18
|
+
const el = ref.current;
|
|
19
|
+
if (!el)
|
|
20
|
+
return;
|
|
21
|
+
const rect = el.getBoundingClientRect();
|
|
22
|
+
onValueChange({
|
|
23
|
+
s: clamp01((clientX - rect.left) / rect.width),
|
|
24
|
+
v: clamp01(1 - (clientY - rect.top) / rect.height),
|
|
25
|
+
});
|
|
26
|
+
}, disabled);
|
|
27
|
+
const handleKeyDown = (e) => {
|
|
28
|
+
if (disabled)
|
|
29
|
+
return;
|
|
30
|
+
const step = e.shiftKey ? 0.1 : 0.01;
|
|
31
|
+
let { s, v } = hsva;
|
|
32
|
+
switch (e.key) {
|
|
33
|
+
case 'ArrowLeft':
|
|
34
|
+
s -= step;
|
|
35
|
+
break;
|
|
36
|
+
case 'ArrowRight':
|
|
37
|
+
s += step;
|
|
38
|
+
break;
|
|
39
|
+
case 'ArrowUp':
|
|
40
|
+
v += step;
|
|
41
|
+
break;
|
|
42
|
+
case 'ArrowDown':
|
|
43
|
+
v -= step;
|
|
44
|
+
break;
|
|
45
|
+
default:
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
onValueChange({ s: clamp01(s), v: clamp01(v) });
|
|
50
|
+
};
|
|
51
|
+
const hue = `hsl(${Math.round(hsva.h)} 100% 50%)`;
|
|
52
|
+
const thumbColor = formatColor({ ...hsva, a: 1 }, 'hex');
|
|
53
|
+
return (_jsx("div", { ref: ref, className: cx('tui-color-area', disabled && 'is-disabled', className), role: "slider", tabIndex: disabled ? -1 : 0, "aria-label": ariaLabel, "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": Math.round(hsva.s * 100), "aria-valuetext": valueText ??
|
|
54
|
+
`Saturation ${Math.round(hsva.s * 100)}%, brightness ${Math.round(hsva.v * 100)}%`, "aria-disabled": disabled || undefined, style: {
|
|
55
|
+
// value (black) layer on top of the saturation (white → hue) layer
|
|
56
|
+
background: `linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, ${hue})`,
|
|
57
|
+
}, onKeyDown: handleKeyDown, ...drag, children: _jsx("span", { className: "tui-color-area__thumb", "aria-hidden": "true", style: {
|
|
58
|
+
left: `${hsva.s * 100}%`,
|
|
59
|
+
top: `${(1 - hsva.v) * 100}%`,
|
|
60
|
+
'--_swatch': thumbColor,
|
|
61
|
+
} }) }));
|
|
62
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type ColorPickerLabels } from './labels';
|
|
2
|
+
import { type ColorFormat } from '../../utils/color/color';
|
|
3
|
+
import type { SizeStandard } from '../../types';
|
|
4
|
+
import type { IconName } from '../../icons/registry';
|
|
5
|
+
import type { Side, Align } from '../Popover';
|
|
6
|
+
export type ColorFieldLabels = ColorPickerLabels & {
|
|
7
|
+
/** Base accessible name for the trigger (the label/value is appended). */
|
|
8
|
+
trigger?: string;
|
|
9
|
+
/** Suffix appended to the accessible name for `dynamic` values. @default 'dynamic' */
|
|
10
|
+
dynamic?: string;
|
|
11
|
+
};
|
|
12
|
+
export type ColorFieldProps = {
|
|
13
|
+
/** Controlled value — a CSS colour OR a `var(--x[, fallback])` reference. */
|
|
14
|
+
value?: string;
|
|
15
|
+
/** Uncontrolled initial value. @default '#000000' */
|
|
16
|
+
defaultValue?: string;
|
|
17
|
+
onValueChange?: (value: string) => void;
|
|
18
|
+
format?: ColorFormat;
|
|
19
|
+
defaultFormat?: ColorFormat;
|
|
20
|
+
onFormatChange?: (format: ColorFormat) => void;
|
|
21
|
+
/** Formats offered in the picker's format selector, in order. @default all */
|
|
22
|
+
formats?: ColorFormat[];
|
|
23
|
+
alpha?: boolean;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Human-readable name shown on the trigger (e.g. "Primary"). Falls back to
|
|
27
|
+
* the current value / variable name when omitted.
|
|
28
|
+
*/
|
|
29
|
+
label?: React.ReactNode;
|
|
30
|
+
/** Show the label text beside the swatch. @default true */
|
|
31
|
+
showLabel?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Dynamic-data treatment — a neutral swatch with a bolt icon, for values
|
|
34
|
+
* bound to dynamic sources rather than a fixed colour.
|
|
35
|
+
*/
|
|
36
|
+
dynamic?: boolean;
|
|
37
|
+
/** Override the swatch icon. @default 'system/edit-small' ('system/bolt-fill' when `dynamic`) */
|
|
38
|
+
icon?: IconName;
|
|
39
|
+
size?: SizeStandard;
|
|
40
|
+
/** Popover side relative to the trigger. @default 'bottom' */
|
|
41
|
+
side?: Side;
|
|
42
|
+
/** Popover alignment. @default 'start' */
|
|
43
|
+
align?: Align;
|
|
44
|
+
open?: boolean;
|
|
45
|
+
defaultOpen?: boolean;
|
|
46
|
+
onOpenChange?: (open: boolean) => void;
|
|
47
|
+
/** Override any user-facing string for i18n (picker strings + `trigger`). */
|
|
48
|
+
labels?: ColorFieldLabels;
|
|
49
|
+
'aria-label'?: string;
|
|
50
|
+
'aria-labelledby'?: string;
|
|
51
|
+
className?: string;
|
|
52
|
+
id?: string;
|
|
53
|
+
} & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'onChange' | 'color' | 'value' | 'defaultValue' | 'aria-label'>;
|
|
54
|
+
/**
|
|
55
|
+
* Popover-wrapped colour selector — a pill trigger with a circular icon-swatch
|
|
56
|
+
* and a label that opens a {@link ColorPicker} in a dialog popover. This is the
|
|
57
|
+
* reusable field-level control for colour inputs; the picker itself is the panel.
|
|
58
|
+
*/
|
|
59
|
+
export declare function ColorField({ value: controlledValue, defaultValue, onValueChange, format: controlledFormat, defaultFormat, onFormatChange, formats, alpha, disabled, label, showLabel, dynamic, icon, size, side, align, open, defaultOpen, onOpenChange, labels, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, className, id, ...rest }: ColorFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { isValidElement, useLayoutEffect, useRef, useState } from 'react';
|
|
3
|
+
import { cx } from '../../utils/cx.js';
|
|
4
|
+
import { isDev } from '../../utils/is-dev.js';
|
|
5
|
+
import { Popover } from '../Popover/index.js';
|
|
6
|
+
import { Icon } from '../Icon/index.js';
|
|
7
|
+
import { ColorPicker } from './ColorPicker.js';
|
|
8
|
+
import { resolveLabels } from './labels.js';
|
|
9
|
+
import { parseColor, resolveVarColor, formatColor, } from '../../utils/color/color.js';
|
|
10
|
+
import { getContrastForeground } from '../../utils/color/contrast.js';
|
|
11
|
+
/** Best-effort text extraction from a ReactNode, for the accessible name. */
|
|
12
|
+
function nodeToText(node) {
|
|
13
|
+
if (node == null || typeof node === 'boolean')
|
|
14
|
+
return undefined;
|
|
15
|
+
if (typeof node === 'string' || typeof node === 'number')
|
|
16
|
+
return String(node);
|
|
17
|
+
if (Array.isArray(node)) {
|
|
18
|
+
const text = node.map(nodeToText).filter(Boolean).join('');
|
|
19
|
+
return text || undefined;
|
|
20
|
+
}
|
|
21
|
+
if (isValidElement(node)) {
|
|
22
|
+
return nodeToText(node.props.children);
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Popover-wrapped colour selector — a pill trigger with a circular icon-swatch
|
|
28
|
+
* and a label that opens a {@link ColorPicker} in a dialog popover. This is the
|
|
29
|
+
* reusable field-level control for colour inputs; the picker itself is the panel.
|
|
30
|
+
*/
|
|
31
|
+
export function ColorField({ value: controlledValue, defaultValue = '#000000', onValueChange, format: controlledFormat, defaultFormat = 'hex', onFormatChange, formats, alpha = true, disabled, label, showLabel = true, dynamic = false, icon, size = 'md', side = 'bottom', align = 'start', open, defaultOpen, onOpenChange, labels, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledby, className, id, ...rest }) {
|
|
32
|
+
const triggerRef = useRef(null);
|
|
33
|
+
const isValueControlled = useRef(controlledValue !== undefined).current;
|
|
34
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);
|
|
35
|
+
const value = isValueControlled ? controlledValue ?? '' : uncontrolledValue;
|
|
36
|
+
const isFormatControlled = controlledFormat !== undefined;
|
|
37
|
+
const [uncontrolledFormat, setUncontrolledFormat] = useState(defaultFormat);
|
|
38
|
+
const format = isFormatControlled ? controlledFormat : uncontrolledFormat;
|
|
39
|
+
// Re-render once after mount so the trigger swatch can resolve a var().
|
|
40
|
+
const [, setMounted] = useState(false);
|
|
41
|
+
useLayoutEffect(() => setMounted(true), []);
|
|
42
|
+
const L = resolveLabels(labels);
|
|
43
|
+
const triggerBase = labels?.trigger ?? 'Select color';
|
|
44
|
+
const dynamicSuffix = labels?.dynamic ?? 'dynamic';
|
|
45
|
+
const commitValue = (next) => {
|
|
46
|
+
if (!isValueControlled)
|
|
47
|
+
setUncontrolledValue(next);
|
|
48
|
+
onValueChange?.(next);
|
|
49
|
+
};
|
|
50
|
+
const commitFormat = (next) => {
|
|
51
|
+
if (!isFormatControlled)
|
|
52
|
+
setUncontrolledFormat(next);
|
|
53
|
+
onFormatChange?.(next);
|
|
54
|
+
};
|
|
55
|
+
const parsed = parseColor(value);
|
|
56
|
+
const isVar = parsed.kind === 'var';
|
|
57
|
+
const resolvedHex = isVar
|
|
58
|
+
? resolveVarColor(parsed, triggerRef.current) ?? '#000000'
|
|
59
|
+
: parsed.kind === 'color'
|
|
60
|
+
? formatColor(parsed.hsva, 'hex')
|
|
61
|
+
: '#000000';
|
|
62
|
+
// Dynamic values get a neutral swatch + bolt; concrete colours get the colour
|
|
63
|
+
// + an edit affordance. Icon colour is contrast-picked so it stays legible.
|
|
64
|
+
const swatchBg = dynamic ? 'var(--tui-color-fg, #111)' : resolvedHex;
|
|
65
|
+
const swatchIcon = icon ?? (dynamic ? 'system/bolt-fill' : 'system/edit-small');
|
|
66
|
+
const iconColor = dynamic ? '#fff' : getContrastForeground(resolvedHex);
|
|
67
|
+
// Trigger text: explicit label wins, else the variable name or the value.
|
|
68
|
+
const fallbackText = isVar ? parsed.name : parsed.kind === 'color' ? formatColor(parsed.hsva, format) : value;
|
|
69
|
+
const labelNode = label ?? fallbackText;
|
|
70
|
+
const labelText = nodeToText(labelNode);
|
|
71
|
+
if (isDev() &&
|
|
72
|
+
label != null &&
|
|
73
|
+
typeof label !== 'string' &&
|
|
74
|
+
!labelText &&
|
|
75
|
+
!ariaLabel &&
|
|
76
|
+
!ariaLabelledby) {
|
|
77
|
+
console.warn('[ColorField] `label` is a node with no derivable text — pass `aria-label` so the control has an accessible name.');
|
|
78
|
+
}
|
|
79
|
+
// Name context includes the value/label and the dynamic state, so both the
|
|
80
|
+
// trigger and the (focus-trapped) popover dialog identify which field this is.
|
|
81
|
+
const nameContext = (labelText ? `${triggerBase}: ${labelText}` : triggerBase) +
|
|
82
|
+
(dynamic ? ` (${dynamicSuffix})` : '');
|
|
83
|
+
// Trigger: an external labelledby wins; else our computed name.
|
|
84
|
+
const computedAriaLabel = ariaLabel ?? (ariaLabelledby ? undefined : nameContext);
|
|
85
|
+
// Popover dialog: always named with context (a labelledby id can't name it).
|
|
86
|
+
const popoverLabel = ariaLabel ?? nameContext;
|
|
87
|
+
return (_jsxs(Popover, { open: open, defaultOpen: defaultOpen, onOpenChange: onOpenChange, children: [_jsx(Popover.Trigger, { asChild: true, children: _jsxs("button", { ref: triggerRef, type: "button", id: id, className: cx('tui-color-field', size !== 'md' && `is-size-${size}`, !showLabel && 'is-swatch-only', disabled && 'is-disabled', className), disabled: disabled, "aria-label": computedAriaLabel, "aria-labelledby": ariaLabelledby, ...rest, children: [_jsx("span", { className: "tui-color-field__swatch", "aria-hidden": "true", style: { '--_swatch': swatchBg, '--_swatch-icon': iconColor }, children: _jsx(Icon, { name: swatchIcon, className: "tui-color-field__swatch-icon" }) }), showLabel && _jsx("span", { className: "tui-color-field__label", children: labelNode })] }) }), _jsx(Popover.Content, { side: side, align: align, modal: true, "aria-label": popoverLabel, className: "tui-color-field__popover", children: _jsx(ColorPicker, { value: value, onValueChange: commitValue, format: format, onFormatChange: commitFormat, formats: formats, alpha: alpha, labels: labels, "aria-label": L.group }) })] }));
|
|
88
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type ColorFormat } from '../../utils/color/color';
|
|
2
|
+
import { type ColorPickerLabels } from './labels';
|
|
3
|
+
export type ColorPickerProps = {
|
|
4
|
+
/** Controlled value — a CSS colour OR a `var(--x[, fallback])` reference. */
|
|
5
|
+
value?: string;
|
|
6
|
+
/** Uncontrolled initial value. @default '#000000' */
|
|
7
|
+
defaultValue?: string;
|
|
8
|
+
onValueChange?: (value: string) => void;
|
|
9
|
+
/** Controlled format for the value field. */
|
|
10
|
+
format?: ColorFormat;
|
|
11
|
+
/** Uncontrolled initial format. @default 'hex' */
|
|
12
|
+
defaultFormat?: ColorFormat;
|
|
13
|
+
onFormatChange?: (format: ColorFormat) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Formats offered in the format selector, in order. The selector is hidden
|
|
16
|
+
* when only one is supplied. @default ['hex','rgb','hsl','hwb','oklch']
|
|
17
|
+
*/
|
|
18
|
+
formats?: ColorFormat[];
|
|
19
|
+
/** Show the alpha slider (and keep alpha in the emitted value). @default true */
|
|
20
|
+
alpha?: boolean;
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
/** Override any user-facing string for i18n. */
|
|
23
|
+
labels?: ColorPickerLabels;
|
|
24
|
+
/** Accessible name for the picker group. Takes precedence over `labels.group`. */
|
|
25
|
+
'aria-label'?: string;
|
|
26
|
+
className?: string;
|
|
27
|
+
} & Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange' | 'color' | 'role'>;
|
|
28
|
+
/**
|
|
29
|
+
* Solid colour picker: 2D area + hue/alpha sliders + a format-aware value row.
|
|
30
|
+
* The format selector switches the value field between a single hex string and
|
|
31
|
+
* per-channel inputs (rgb/hsl/hwb/oklch — hex default; parses/edits on commit)
|
|
32
|
+
* with a copy button. Accepts a `var(--x)` value: it's shown as a variable badge
|
|
33
|
+
* with an opportunistically resolved swatch (never required to resolve — admin
|
|
34
|
+
* contexts) and editing any control overrides it with a concrete colour.
|
|
35
|
+
*/
|
|
36
|
+
export declare function ColorPicker({ value: controlledValue, defaultValue, onValueChange, format: controlledFormat, defaultFormat, onFormatChange, formats, alpha, disabled, labels, 'aria-label': ariaLabel, className, ...rest }: ColorPickerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
3
|
+
import { cx } from '../../utils/cx.js';
|
|
4
|
+
import { Select } from '../Select/index.js';
|
|
5
|
+
import { IconButton } from '../IconButton/index.js';
|
|
6
|
+
import { Tooltip } from '../Tooltip/index.js';
|
|
7
|
+
import { ColorArea } from './ColorArea.js';
|
|
8
|
+
import { ColorSlider } from './ColorSlider.js';
|
|
9
|
+
import { HUE_TRACK, alphaTrack } from './tracks.js';
|
|
10
|
+
import { parseColor, formatColor, resolveVarColor, COLOR_FORMATS, hsvToRgb, rgbToHsv, rgbToHsl, hslToRgb, rgbToHwb, hwbToRgb, rgbToOklch, oklchToRgb, } from '../../utils/color/color.js';
|
|
11
|
+
import { resolveLabels } from './labels.js';
|
|
12
|
+
const NEUTRAL = { h: 0, s: 0, v: 0, a: 1 };
|
|
13
|
+
const CHANNEL_DEFS = {
|
|
14
|
+
rgb: [
|
|
15
|
+
{ key: 'r', label: 'R', ariaKey: 'red', min: 0, max: 255, step: 1, decimals: 0 },
|
|
16
|
+
{ key: 'g', label: 'G', ariaKey: 'green', min: 0, max: 255, step: 1, decimals: 0 },
|
|
17
|
+
{ key: 'b', label: 'B', ariaKey: 'blue', min: 0, max: 255, step: 1, decimals: 0 },
|
|
18
|
+
],
|
|
19
|
+
hsl: [
|
|
20
|
+
{ key: 'h', label: 'H', ariaKey: 'hue', min: 0, max: 360, step: 1, decimals: 0 },
|
|
21
|
+
{ key: 's', label: 'S', ariaKey: 'saturation', min: 0, max: 100, step: 1, decimals: 0 },
|
|
22
|
+
{ key: 'l', label: 'L', ariaKey: 'lightness', min: 0, max: 100, step: 1, decimals: 0 },
|
|
23
|
+
],
|
|
24
|
+
hwb: [
|
|
25
|
+
{ key: 'h', label: 'H', ariaKey: 'hue', min: 0, max: 360, step: 1, decimals: 0 },
|
|
26
|
+
{ key: 'w', label: 'W', ariaKey: 'whiteness', min: 0, max: 100, step: 1, decimals: 0 },
|
|
27
|
+
{ key: 'b', label: 'B', ariaKey: 'blackness', min: 0, max: 100, step: 1, decimals: 0 },
|
|
28
|
+
],
|
|
29
|
+
oklch: [
|
|
30
|
+
{ key: 'l', label: 'L', ariaKey: 'lightness', min: 0, max: 1, step: 0.01, decimals: 3 },
|
|
31
|
+
{ key: 'c', label: 'C', ariaKey: 'chroma', min: 0, max: 0.5, step: 0.005, decimals: 3 },
|
|
32
|
+
{ key: 'h', label: 'H', ariaKey: 'hue', min: 0, max: 360, step: 1, decimals: 1 },
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
const ALPHA_DEF = {
|
|
36
|
+
key: 'a',
|
|
37
|
+
label: 'A',
|
|
38
|
+
ariaKey: 'alpha',
|
|
39
|
+
min: 0,
|
|
40
|
+
max: 100,
|
|
41
|
+
step: 1,
|
|
42
|
+
decimals: 0,
|
|
43
|
+
};
|
|
44
|
+
const clampN = (n, min, max) => Math.min(max, Math.max(min, n));
|
|
45
|
+
const stripNum = (n, decimals) => {
|
|
46
|
+
const f = 10 ** decimals;
|
|
47
|
+
return String(Math.round(n * f) / f);
|
|
48
|
+
};
|
|
49
|
+
/** Current channel values (in each channel's display units) for a format. */
|
|
50
|
+
function channelValues(format, hsva) {
|
|
51
|
+
const rgb = hsvToRgb(hsva);
|
|
52
|
+
const a = hsva.a * 100;
|
|
53
|
+
switch (format) {
|
|
54
|
+
case 'rgb':
|
|
55
|
+
return { r: rgb.r * 255, g: rgb.g * 255, b: rgb.b * 255, a };
|
|
56
|
+
case 'hsl': {
|
|
57
|
+
const { h, s, l } = rgbToHsl(rgb);
|
|
58
|
+
return { h, s: s * 100, l: l * 100, a };
|
|
59
|
+
}
|
|
60
|
+
case 'hwb': {
|
|
61
|
+
const { h, w, b } = rgbToHwb(rgb);
|
|
62
|
+
return { h, w: w * 100, b: b * 100, a };
|
|
63
|
+
}
|
|
64
|
+
case 'oklch': {
|
|
65
|
+
const { l, c, h } = rgbToOklch(rgb);
|
|
66
|
+
return { l, c, h, a };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** Rebuild an HSVA from a full set of channel values (display units). */
|
|
71
|
+
function hsvaFromChannels(format, v, alpha) {
|
|
72
|
+
const a = alpha ? clampN((v.a ?? 100) / 100, 0, 1) : 1;
|
|
73
|
+
switch (format) {
|
|
74
|
+
case 'rgb':
|
|
75
|
+
return { ...rgbToHsv({ r: v.r / 255, g: v.g / 255, b: v.b / 255 }), a };
|
|
76
|
+
case 'hsl':
|
|
77
|
+
return { ...rgbToHsv(hslToRgb(v.h, v.s / 100, v.l / 100)), a };
|
|
78
|
+
case 'hwb':
|
|
79
|
+
return { ...rgbToHsv(hwbToRgb(v.h, v.w / 100, v.b / 100)), a };
|
|
80
|
+
case 'oklch':
|
|
81
|
+
return { ...rgbToHsv(oklchToRgb(v.l, v.c, v.h)), a };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function Channels({ format, hsva, alpha, disabled, onChange, channelLabels, groupLabel, }) {
|
|
85
|
+
const defs = alpha ? [...CHANNEL_DEFS[format], ALPHA_DEF] : CHANNEL_DEFS[format];
|
|
86
|
+
const values = channelValues(format, hsva);
|
|
87
|
+
// A local draft only for the field being edited, so typing isn't clobbered by
|
|
88
|
+
// the round-trip through HSVA. Cleared on blur → shows the canonical value.
|
|
89
|
+
const [drafts, setDrafts] = useState({});
|
|
90
|
+
const commit = (key, raw) => {
|
|
91
|
+
const next = {};
|
|
92
|
+
for (const d of defs)
|
|
93
|
+
next[d.key] = Math.round(values[d.key] * 10 ** d.decimals) / 10 ** d.decimals;
|
|
94
|
+
const def = defs.find((d) => d.key === key);
|
|
95
|
+
next[key] = clampN(raw, def.min, def.max);
|
|
96
|
+
onChange(hsvaFromChannels(format, next, alpha));
|
|
97
|
+
};
|
|
98
|
+
return (_jsx("div", { className: "tui-color-picker__channels", role: "group", "aria-label": groupLabel, children: defs.map((def) => {
|
|
99
|
+
const display = drafts[def.key] ?? stripNum(values[def.key], def.decimals);
|
|
100
|
+
return (_jsxs("span", { className: "tui-color-picker__channel", children: [_jsx("span", { className: "tui-color-picker__channel-letter", "aria-hidden": "true", children: def.label }), _jsx("input", { className: "tui-color-picker__channel-input", type: "text", inputMode: "decimal", autoComplete: "off", spellCheck: false, value: display, disabled: disabled, role: "spinbutton", "aria-label": channelLabels[def.ariaKey], "aria-valuenow": Math.round(values[def.key] * 10 ** def.decimals) / 10 ** def.decimals, "aria-valuemin": def.min, "aria-valuemax": def.max, onChange: (e) => {
|
|
101
|
+
const text = e.target.value;
|
|
102
|
+
setDrafts((d) => ({ ...d, [def.key]: text }));
|
|
103
|
+
const num = parseFloat(text);
|
|
104
|
+
if (!Number.isNaN(num))
|
|
105
|
+
commit(def.key, num);
|
|
106
|
+
}, onBlur: () => setDrafts((d) => {
|
|
107
|
+
const next = { ...d };
|
|
108
|
+
delete next[def.key];
|
|
109
|
+
return next;
|
|
110
|
+
}), onKeyDown: (e) => {
|
|
111
|
+
if (e.key !== 'ArrowUp' && e.key !== 'ArrowDown')
|
|
112
|
+
return;
|
|
113
|
+
e.preventDefault();
|
|
114
|
+
const delta = def.step * (e.shiftKey ? 10 : 1) * (e.key === 'ArrowUp' ? 1 : -1);
|
|
115
|
+
const base = parseFloat(drafts[def.key] ?? String(values[def.key]));
|
|
116
|
+
const num = clampN((Number.isNaN(base) ? 0 : base) + delta, def.min, def.max);
|
|
117
|
+
setDrafts((d) => ({ ...d, [def.key]: stripNum(num, def.decimals) }));
|
|
118
|
+
commit(def.key, num);
|
|
119
|
+
} })] }, def.key));
|
|
120
|
+
}) }));
|
|
121
|
+
}
|
|
122
|
+
/** Derive a working HSVA from a parsed value; var is resolved opportunistically. */
|
|
123
|
+
function deriveHsva(value, el) {
|
|
124
|
+
const parsed = parseColor(value);
|
|
125
|
+
if (parsed.kind === 'color')
|
|
126
|
+
return parsed.hsva;
|
|
127
|
+
if (parsed.kind === 'var') {
|
|
128
|
+
const resolved = resolveVarColor(parsed, el);
|
|
129
|
+
if (resolved) {
|
|
130
|
+
const rp = parseColor(resolved);
|
|
131
|
+
if (rp.kind === 'color')
|
|
132
|
+
return rp.hsva;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return NEUTRAL;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Solid colour picker: 2D area + hue/alpha sliders + a format-aware value row.
|
|
139
|
+
* The format selector switches the value field between a single hex string and
|
|
140
|
+
* per-channel inputs (rgb/hsl/hwb/oklch — hex default; parses/edits on commit)
|
|
141
|
+
* with a copy button. Accepts a `var(--x)` value: it's shown as a variable badge
|
|
142
|
+
* with an opportunistically resolved swatch (never required to resolve — admin
|
|
143
|
+
* contexts) and editing any control overrides it with a concrete colour.
|
|
144
|
+
*/
|
|
145
|
+
export function ColorPicker({ value: controlledValue, defaultValue = '#000000', onValueChange, format: controlledFormat, defaultFormat = 'hex', onFormatChange, formats, alpha = true, disabled, labels, 'aria-label': ariaLabel, className, ...rest }) {
|
|
146
|
+
const rootRef = useRef(null);
|
|
147
|
+
const L = resolveLabels(labels);
|
|
148
|
+
const isValueControlled = useRef(controlledValue !== undefined).current;
|
|
149
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);
|
|
150
|
+
const value = isValueControlled ? controlledValue ?? '' : uncontrolledValue;
|
|
151
|
+
// Offered formats (deduped, valid, order preserved); falls back to all.
|
|
152
|
+
const availableFormats = formats?.filter((f) => COLOR_FORMATS.includes(f)) ?? [];
|
|
153
|
+
const offeredFormats = availableFormats.length ? availableFormats : COLOR_FORMATS;
|
|
154
|
+
const isFormatControlled = controlledFormat !== undefined;
|
|
155
|
+
const [uncontrolledFormat, setUncontrolledFormat] = useState(defaultFormat);
|
|
156
|
+
const rawFormat = isFormatControlled ? controlledFormat : uncontrolledFormat;
|
|
157
|
+
// Clamp to an offered format so the active format is always selectable.
|
|
158
|
+
const format = offeredFormats.includes(rawFormat) ? rawFormat : offeredFormats[0];
|
|
159
|
+
// Force one re-render after mount so var resolution can read the DOM element.
|
|
160
|
+
const [, setMounted] = useState(false);
|
|
161
|
+
useLayoutEffect(() => setMounted(true), []);
|
|
162
|
+
// Transient "Copied" confirmation (tooltip label + SR live announcement).
|
|
163
|
+
const [copied, setCopied] = useState(false);
|
|
164
|
+
const copyTimer = useRef(null);
|
|
165
|
+
useEffect(() => () => void (copyTimer.current && clearTimeout(copyTimer.current)), []);
|
|
166
|
+
const parsed = parseColor(value);
|
|
167
|
+
const isVar = parsed.kind === 'var';
|
|
168
|
+
const hsva = deriveHsva(value, rootRef.current);
|
|
169
|
+
const commit = useCallback((next) => {
|
|
170
|
+
if (!isValueControlled)
|
|
171
|
+
setUncontrolledValue(next);
|
|
172
|
+
onValueChange?.(next);
|
|
173
|
+
}, [isValueControlled, onValueChange]);
|
|
174
|
+
// Any edit produces a concrete colour (overrides a var).
|
|
175
|
+
const commitHsva = useCallback((next) => {
|
|
176
|
+
const withAlpha = alpha ? next : { ...next, a: 1 };
|
|
177
|
+
commit(formatColor(withAlpha, format));
|
|
178
|
+
}, [alpha, format, commit]);
|
|
179
|
+
const patch = useCallback((partial) => commitHsva({ ...hsva, ...partial }), [hsva, commitHsva]);
|
|
180
|
+
const setFormat = (f) => {
|
|
181
|
+
if (!isFormatControlled)
|
|
182
|
+
setUncontrolledFormat(f);
|
|
183
|
+
onFormatChange?.(f);
|
|
184
|
+
if (!isVar)
|
|
185
|
+
commit(formatColor(hsva, f)); // re-emit the same colour in the new format
|
|
186
|
+
};
|
|
187
|
+
// Editable text field (hex, or a var reference): local draft, parsed on commit.
|
|
188
|
+
const [draft, setDraft] = useState(null);
|
|
189
|
+
const fieldText = draft ?? (isVar ? parsed.raw : formatColor(hsva, format));
|
|
190
|
+
const commitText = () => {
|
|
191
|
+
if (draft == null)
|
|
192
|
+
return;
|
|
193
|
+
const p = parseColor(draft.trim());
|
|
194
|
+
if (p.kind === 'color')
|
|
195
|
+
commit(formatColor(p.hsva, format));
|
|
196
|
+
else if (p.kind === 'var')
|
|
197
|
+
commit(draft.trim());
|
|
198
|
+
// invalid → revert (drop the draft)
|
|
199
|
+
setDraft(null);
|
|
200
|
+
};
|
|
201
|
+
const opaqueHex = formatColor({ ...hsva, a: 1 }, 'hex');
|
|
202
|
+
const emitted = isVar ? parsed.raw : formatColor(hsva, format);
|
|
203
|
+
const useChannels = !isVar && format !== 'hex';
|
|
204
|
+
const handleCopy = () => {
|
|
205
|
+
navigator.clipboard?.writeText(emitted);
|
|
206
|
+
setCopied(true);
|
|
207
|
+
if (copyTimer.current)
|
|
208
|
+
clearTimeout(copyTimer.current);
|
|
209
|
+
copyTimer.current = setTimeout(() => setCopied(false), 1200);
|
|
210
|
+
};
|
|
211
|
+
return (_jsxs("div", { ref: rootRef, className: cx('tui-color-picker', disabled && 'is-disabled', className), role: "group", "aria-label": ariaLabel ?? L.group, ...rest, children: [_jsx(ColorArea, { hsva: hsva, onValueChange: ({ s, v }) => patch({ s, v }), disabled: disabled, "aria-label": L.area, valueText: L.areaValueText(Math.round(hsva.s * 100), Math.round(hsva.v * 100)) }), _jsx(ColorSlider, { "aria-label": L.hue, value: hsva.h, min: 0, max: 360, track: HUE_TRACK, valueText: L.hueValueText(Math.round(hsva.h)), onValueChange: (h) => patch({ h }), disabled: disabled }), alpha && (_jsx(ColorSlider, { "aria-label": L.alpha, value: hsva.a * 100, min: 0, max: 100, checkerboard: true, track: alphaTrack(opaqueHex), valueText: L.alphaValueText(Math.round(hsva.a * 100)), onValueChange: (a) => patch({ a: a / 100 }), disabled: disabled })), _jsxs("div", { className: "tui-color-picker__value", children: [offeredFormats.length > 1 && (_jsxs(Select, { value: format, onValueChange: (v) => setFormat(v), disabled: disabled, "aria-label": L.format, children: [_jsx(Select.Trigger, { className: "tui-color-picker__format" }), _jsx(Select.Content, { children: offeredFormats.map((f) => (_jsx(Select.Option, { value: f, children: L.formats[f] }, f))) })] })), _jsx("div", { className: "tui-color-picker__field-group", children: useChannels ? (_jsx(Channels, { format: format, hsva: hsva, alpha: alpha, disabled: disabled, onChange: commitHsva, channelLabels: L.channels, groupLabel: L.channelGroup(L.formats[format] ?? format) })) : (_jsx("input", { className: "tui-color-picker__field-input", type: "text", autoComplete: "off", spellCheck: false, value: fieldText, onChange: (e) => setDraft(e.target.value), onBlur: commitText, onKeyDown: (e) => {
|
|
212
|
+
if (e.key === 'Enter')
|
|
213
|
+
commitText();
|
|
214
|
+
}, "aria-label": L.value, disabled: disabled })) }), _jsxs(Tooltip, { children: [_jsx(Tooltip.Trigger, { asChild: true, children: _jsx(IconButton, { className: "tui-color-picker__copy", icon: "system/copy", label: L.copy, variant: "ghost", size: "sm", disabled: disabled, onClick: handleCopy }) }), _jsx(Tooltip.Content, { children: copied ? L.copied : L.copy })] })] }), _jsx("span", { className: "tui-visually-hidden", role: "status", "aria-live": "polite", children: copied ? L.copied : '' }), _jsx("p", { className: cx('tui-color-picker__var', !isVar && 'is-empty'), "aria-live": "polite", children: isVar && (_jsxs(_Fragment, { children: [L.variable, " ", _jsx("code", { children: parsed.name })] })) })] }));
|
|
215
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type ColorSliderProps = {
|
|
2
|
+
value: number;
|
|
3
|
+
min?: number;
|
|
4
|
+
max?: number;
|
|
5
|
+
step?: number;
|
|
6
|
+
onValueChange: (value: number) => void;
|
|
7
|
+
/** CSS background for the gradient track. */
|
|
8
|
+
track: string;
|
|
9
|
+
/** Show the alpha checkerboard behind the track. */
|
|
10
|
+
checkerboard?: boolean;
|
|
11
|
+
'aria-label'?: string;
|
|
12
|
+
valueText?: string;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
className?: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* 1D colour slider — the hue and alpha controls both use this. Pointer-draggable
|
|
18
|
+
* and keyboard-adjustable (arrows / Home / End; Shift = coarse).
|
|
19
|
+
*/
|
|
20
|
+
export declare function ColorSlider({ value, min, max, step, onValueChange, track, checkerboard, 'aria-label': ariaLabel, valueText, disabled, className, }: ColorSliderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
import { cx } from '../../utils/cx.js';
|
|
4
|
+
import { usePointerDrag, clamp01 } from './usePointerDrag.js';
|
|
5
|
+
/**
|
|
6
|
+
* 1D colour slider — the hue and alpha controls both use this. Pointer-draggable
|
|
7
|
+
* and keyboard-adjustable (arrows / Home / End; Shift = coarse).
|
|
8
|
+
*/
|
|
9
|
+
export function ColorSlider({ value, min = 0, max = 100, step = 1, onValueChange, track, checkerboard, 'aria-label': ariaLabel, valueText, disabled, className, }) {
|
|
10
|
+
const ref = useRef(null);
|
|
11
|
+
const pct = clamp01((value - min) / (max - min));
|
|
12
|
+
const drag = usePointerDrag((clientX) => {
|
|
13
|
+
const el = ref.current;
|
|
14
|
+
if (!el)
|
|
15
|
+
return;
|
|
16
|
+
const rect = el.getBoundingClientRect();
|
|
17
|
+
onValueChange(min + clamp01((clientX - rect.left) / rect.width) * (max - min));
|
|
18
|
+
}, disabled);
|
|
19
|
+
const handleKeyDown = (e) => {
|
|
20
|
+
if (disabled)
|
|
21
|
+
return;
|
|
22
|
+
const s = e.shiftKey ? step * 10 : step;
|
|
23
|
+
let next = value;
|
|
24
|
+
if (e.key === 'ArrowLeft' || e.key === 'ArrowDown')
|
|
25
|
+
next -= s;
|
|
26
|
+
else if (e.key === 'ArrowRight' || e.key === 'ArrowUp')
|
|
27
|
+
next += s;
|
|
28
|
+
else if (e.key === 'Home')
|
|
29
|
+
next = min;
|
|
30
|
+
else if (e.key === 'End')
|
|
31
|
+
next = max;
|
|
32
|
+
else
|
|
33
|
+
return;
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
onValueChange(Math.min(max, Math.max(min, next)));
|
|
36
|
+
};
|
|
37
|
+
return (_jsxs("div", { ref: ref, className: cx('tui-color-slider', checkerboard && 'has-checkerboard', disabled && 'is-disabled', className), role: "slider", tabIndex: disabled ? -1 : 0, "aria-label": ariaLabel, "aria-valuemin": min, "aria-valuemax": max, "aria-valuenow": Math.round(value), "aria-valuetext": valueText, "aria-disabled": disabled || undefined, onKeyDown: handleKeyDown, ...drag, children: [_jsx("div", { className: "tui-color-slider__track", style: { background: track } }), _jsx("span", { className: "tui-color-slider__thumb", "aria-hidden": "true", style: { left: `${pct * 100}%` } })] }));
|
|
38
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { ColorPicker } from './ColorPicker';
|
|
2
|
+
export type { ColorPickerProps } from './ColorPicker';
|
|
3
|
+
export { ColorField } from './ColorField';
|
|
4
|
+
export type { ColorFieldProps, ColorFieldLabels } from './ColorField';
|
|
5
|
+
export type { Side as ColorFieldSide, Align as ColorFieldAlign } from '../Popover';
|
|
6
|
+
export { defaultColorPickerLabels } from './labels';
|
|
7
|
+
export type { ColorPickerLabels } from './labels';
|
|
8
|
+
export { ColorArea } from './ColorArea';
|
|
9
|
+
export type { ColorAreaProps } from './ColorArea';
|
|
10
|
+
export { ColorSlider } from './ColorSlider';
|
|
11
|
+
export type { ColorSliderProps } from './ColorSlider';
|
|
12
|
+
export { HUE_TRACK, alphaTrack } from './tracks';
|
|
13
|
+
export { parseColor, formatColor, resolveVarColor, COLOR_FORMATS, } from '../../utils/color/color';
|
|
14
|
+
export type { ColorFormat, Hsva, ParsedColor } from '../../utils/color/color';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { ColorPicker } from './ColorPicker.js';
|
|
2
|
+
export { ColorField } from './ColorField.js';
|
|
3
|
+
export { defaultColorPickerLabels } from './labels.js';
|
|
4
|
+
export { ColorArea } from './ColorArea.js';
|
|
5
|
+
export { ColorSlider } from './ColorSlider.js';
|
|
6
|
+
export { HUE_TRACK, alphaTrack } from './tracks.js';
|
|
7
|
+
export { parseColor, formatColor, resolveVarColor, COLOR_FORMATS, } from '../../utils/color/color.js';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ColorFormat } from '../../utils/color/color';
|
|
2
|
+
/**
|
|
3
|
+
* Semantic keys for channel accessible names, shared across formats — e.g. Hue
|
|
4
|
+
* is used by hsl/hwb/oklch, Lightness by hsl/oklch. Keyed by meaning (not by
|
|
5
|
+
* channel letter) so `b` never collides (Blue in rgb vs Blackness in hwb).
|
|
6
|
+
*/
|
|
7
|
+
export type ChannelAriaKey = 'red' | 'green' | 'blue' | 'hue' | 'saturation' | 'lightness' | 'whiteness' | 'blackness' | 'chroma' | 'alpha';
|
|
8
|
+
export type ColorPickerLabels = {
|
|
9
|
+
/** Accessible name for the whole picker group. */
|
|
10
|
+
group?: string;
|
|
11
|
+
/** Accessible name for the 2D saturation/brightness area. */
|
|
12
|
+
area?: string;
|
|
13
|
+
/** Accessible name for the hue slider. */
|
|
14
|
+
hue?: string;
|
|
15
|
+
/** Accessible name for the alpha slider. */
|
|
16
|
+
alpha?: string;
|
|
17
|
+
/** Accessible name for the format selector. */
|
|
18
|
+
format?: string;
|
|
19
|
+
/** Accessible name for the single value text field (hex / var). */
|
|
20
|
+
value?: string;
|
|
21
|
+
/** Copy button label + idle tooltip. */
|
|
22
|
+
copy?: string;
|
|
23
|
+
/** Tooltip + SR announcement shown briefly after a successful copy. */
|
|
24
|
+
copied?: string;
|
|
25
|
+
/** Prefix before the variable name in the var badge. */
|
|
26
|
+
variable?: string;
|
|
27
|
+
/** Display names per format in the format selector. */
|
|
28
|
+
formats?: Partial<Record<ColorFormat, string>>;
|
|
29
|
+
/** Accessible names for each colour channel input. */
|
|
30
|
+
channels?: Partial<Record<ChannelAriaKey, string>>;
|
|
31
|
+
/** Builds the channel group's accessible name, e.g. `(l) => `${l} value``. */
|
|
32
|
+
channelGroup?: (formatLabel: string) => string;
|
|
33
|
+
/** Builds the hue slider's value text, e.g. `(d) => `${d} degrees``. */
|
|
34
|
+
hueValueText?: (degrees: number) => string;
|
|
35
|
+
/** Builds the alpha slider's value text, e.g. `(p) => `${p} percent``. */
|
|
36
|
+
alphaValueText?: (percent: number) => string;
|
|
37
|
+
/** Builds the area's value text. */
|
|
38
|
+
areaValueText?: (saturation: number, brightness: number) => string;
|
|
39
|
+
};
|
|
40
|
+
export declare const defaultColorPickerLabels: Required<ColorPickerLabels>;
|
|
41
|
+
/** Merge consumer overrides over the defaults (shallow, plus the nested maps). */
|
|
42
|
+
export declare function resolveLabels(labels?: ColorPickerLabels): Required<ColorPickerLabels>;
|