@tangible/ui 0.1.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/Button/types.d.ts +5 -2
- package/components/Chip/Chip.d.ts +28 -0
- package/components/Chip/Chip.js +19 -3
- 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/Combobox/Combobox.d.ts +1 -1
- package/components/Combobox/Combobox.js +2 -2
- package/components/Combobox/types.d.ts +13 -0
- package/components/IconButton/types.d.ts +2 -2
- package/components/MultiCombobox/MultiCombobox.d.ts +33 -0
- package/components/MultiCombobox/MultiCombobox.js +595 -0
- package/components/MultiCombobox/MultiComboboxContext.d.ts +8 -0
- package/components/MultiCombobox/MultiComboboxContext.js +36 -0
- package/components/MultiCombobox/index.d.ts +3 -0
- package/components/MultiCombobox/index.js +2 -0
- package/components/MultiCombobox/types.d.ts +244 -0
- package/components/MultiCombobox/types.js +7 -0
- package/components/MultiSelect/MultiSelect.js +22 -2
- package/components/Popover/index.d.ts +1 -1
- package/components/Select/Select.js +14 -0
- package/components/Slider/Slider.d.ts +2 -0
- package/components/Slider/Slider.js +29 -0
- package/components/Slider/index.d.ts +2 -0
- package/components/Slider/index.js +1 -0
- package/components/Slider/types.d.ts +39 -0
- package/components/Slider/types.js +1 -0
- package/components/index.d.ts +6 -0
- package/components/index.js +3 -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 +13 -1
- package/styles/all.css +1 -1
- package/styles/all.expanded.css +1063 -133
- package/styles/all.expanded.unlayered.css +1063 -133
- package/styles/all.unlayered.css +1 -1
- package/styles/components/_bundle.scss +6 -0
- package/styles/components/button.scss +45 -35
- package/styles/components/chip.scss +57 -0
- package/styles/components/color-picker.scss +378 -0
- package/styles/components/combobox.scss +16 -2
- package/styles/components/icon-button.scss +32 -26
- package/styles/components/input/index.scss +1 -2
- package/styles/components/multi-combobox.scss +457 -0
- package/styles/components/multi-select.scss +34 -18
- package/styles/components/pager.scss +4 -2
- package/styles/components/progress.scss +1 -1
- package/styles/components/segmented-control.scss +44 -18
- package/styles/components/select.scss +19 -3
- package/styles/components/slider.scss +184 -0
- package/styles/components/switch.scss +1 -1
- package/styles/core.css +1 -1
- package/styles/core.unlayered.css +1 -1
- package/styles/system/_tokens.scss +13 -0
- package/tui-manifest.json +307 -8
- package/utils/color/color.d.ts +61 -0
- package/utils/color/color.js +293 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IconName } from '../../icons/registry';
|
|
2
|
-
import type { Size, ThemeIntent } from '../../types';
|
|
2
|
+
import type { Size, ThemeIntent, ThemeStatus } from '../../types';
|
|
3
3
|
export type { Size };
|
|
4
4
|
/**
|
|
5
5
|
* Semantic color themes.
|
|
@@ -9,8 +9,11 @@ export type { Size };
|
|
|
9
9
|
* - `'destructive'`: Alias for `'danger'` — mapped internally before
|
|
10
10
|
* class generation. Provided for readability in consumer code where
|
|
11
11
|
* "destructive" better describes the intent (e.g. `theme="destructive"`).
|
|
12
|
+
* - `'success'` / `'warning'` / `'info'`: Status-coloured actions for
|
|
13
|
+
* surfaces where the action carries the status semantics (approve,
|
|
14
|
+
* proceed-with-caution, learn-more).
|
|
12
15
|
*/
|
|
13
|
-
export type Theme = ThemeIntent | 'destructive';
|
|
16
|
+
export type Theme = ThemeIntent | ThemeStatus | 'destructive';
|
|
14
17
|
/**
|
|
15
18
|
* Visual style variants.
|
|
16
19
|
* - `'solid'`: Filled background (default)
|
|
@@ -29,6 +29,20 @@ export type ChipProps = {
|
|
|
29
29
|
leftIcon?: React.ReactNode;
|
|
30
30
|
rightIcon?: React.ReactNode;
|
|
31
31
|
onClick?: React.MouseEventHandler<HTMLElement>;
|
|
32
|
+
/**
|
|
33
|
+
* When provided, renders a trailing remove (×) button after the content.
|
|
34
|
+
* The button is a real `<button>` — the only focusable target in the chip —
|
|
35
|
+
* so the chip body stays non-interactive. Intended for token/tag patterns
|
|
36
|
+
* (MultiSelect, MultiCombobox). Combining `onRemove` with an interactive
|
|
37
|
+
* chip (`onClick` or ChipGroup) nests interactive elements and warns in dev.
|
|
38
|
+
*/
|
|
39
|
+
onRemove?: React.MouseEventHandler<HTMLButtonElement>;
|
|
40
|
+
/**
|
|
41
|
+
* Accessible label for the remove button. Pass a specific label like
|
|
42
|
+
* `Remove Alice` for context.
|
|
43
|
+
* @default 'Remove'
|
|
44
|
+
*/
|
|
45
|
+
removeLabel?: string;
|
|
32
46
|
/** When inside ChipGroup, identifies this chip for selection tracking */
|
|
33
47
|
value?: OptionValue;
|
|
34
48
|
} & Omit<React.HTMLAttributes<HTMLSpanElement>, 'onClick'>;
|
|
@@ -57,6 +71,20 @@ export declare const Chip: React.ForwardRefExoticComponent<{
|
|
|
57
71
|
leftIcon?: React.ReactNode;
|
|
58
72
|
rightIcon?: React.ReactNode;
|
|
59
73
|
onClick?: React.MouseEventHandler<HTMLElement>;
|
|
74
|
+
/**
|
|
75
|
+
* When provided, renders a trailing remove (×) button after the content.
|
|
76
|
+
* The button is a real `<button>` — the only focusable target in the chip —
|
|
77
|
+
* so the chip body stays non-interactive. Intended for token/tag patterns
|
|
78
|
+
* (MultiSelect, MultiCombobox). Combining `onRemove` with an interactive
|
|
79
|
+
* chip (`onClick` or ChipGroup) nests interactive elements and warns in dev.
|
|
80
|
+
*/
|
|
81
|
+
onRemove?: React.MouseEventHandler<HTMLButtonElement>;
|
|
82
|
+
/**
|
|
83
|
+
* Accessible label for the remove button. Pass a specific label like
|
|
84
|
+
* `Remove Alice` for context.
|
|
85
|
+
* @default 'Remove'
|
|
86
|
+
*/
|
|
87
|
+
removeLabel?: string;
|
|
60
88
|
/** When inside ChipGroup, identifies this chip for selection tracking */
|
|
61
89
|
value?: OptionValue;
|
|
62
90
|
} & Omit<React.HTMLAttributes<HTMLSpanElement>, "onClick"> & React.RefAttributes<HTMLElement>>;
|
package/components/Chip/Chip.js
CHANGED
|
@@ -5,7 +5,8 @@ import { cx } from '../../utils/cx.js';
|
|
|
5
5
|
import { toKey } from '../../utils/value-key.js';
|
|
6
6
|
import { isDev } from '../../utils/is-dev.js';
|
|
7
7
|
import { useChipGroupContext } from '../ChipGroup/ChipGroupContext.js';
|
|
8
|
-
|
|
8
|
+
import { Icon } from '../Icon/index.js';
|
|
9
|
+
export const Chip = forwardRef(function Chip({ as = 'span', href, target, rel, children, size = 'md', theme = 'secondary', variant = 'default', selected: selectedProp, disabled: disabledProp, interactive, className, leftIcon, rightIcon, onClick: onClickProp, onRemove, removeLabel = 'Remove', value, ...rest }, ref) {
|
|
9
10
|
const groupContext = useChipGroupContext();
|
|
10
11
|
// Dev warning: inside ChipGroup without value
|
|
11
12
|
useEffect(() => {
|
|
@@ -13,6 +14,13 @@ export const Chip = forwardRef(function Chip({ as = 'span', href, target, rel, c
|
|
|
13
14
|
console.warn('Chip: Inside a ChipGroup but missing `value` prop. This chip will not be managed by the group.');
|
|
14
15
|
}
|
|
15
16
|
}, [groupContext, value]);
|
|
17
|
+
// Dev warning: onRemove nests a <button> — the chip body must not also be
|
|
18
|
+
// interactive, or we produce nested interactive elements (invalid a11y).
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (isDev() && onRemove && (onClickProp || groupContext)) {
|
|
21
|
+
console.warn('Chip: `onRemove` renders a nested <button>; do not combine it with an interactive chip (`onClick` or ChipGroup). Use a display-only chip with `onRemove` for token/tag patterns.');
|
|
22
|
+
}
|
|
23
|
+
}, [onRemove, onClickProp, groupContext]);
|
|
16
24
|
// Derive from group context when applicable
|
|
17
25
|
const isManaged = groupContext !== null && value !== undefined;
|
|
18
26
|
const selected = isManaged ? groupContext.selectedValues.has(toKey(value)) : selectedProp;
|
|
@@ -35,7 +43,7 @@ export const Chip = forwardRef(function Chip({ as = 'span', href, target, rel, c
|
|
|
35
43
|
onClick(e);
|
|
36
44
|
}
|
|
37
45
|
}, [isClickable, onClick]);
|
|
38
|
-
const classes = cx('tui-chip', size && `is-size-${size}`, theme && `is-theme-${theme}`, variant !== 'default' && `is-style-${variant}`, selected && 'is-selected', (interactive || isManaged) && 'is-interactive', className);
|
|
46
|
+
const classes = cx('tui-chip', size && `is-size-${size}`, theme && `is-theme-${theme}`, variant !== 'default' && `is-style-${variant}`, selected && 'is-selected', (interactive || isManaged) && 'is-interactive', onRemove && 'has-remove', className);
|
|
39
47
|
const anchorProps = as === 'a'
|
|
40
48
|
? {
|
|
41
49
|
href: disabled || isManaged ? undefined : href ?? '#',
|
|
@@ -60,5 +68,13 @@ export const Chip = forwardRef(function Chip({ as = 'span', href, target, rel, c
|
|
|
60
68
|
'aria-disabled': disabled || undefined,
|
|
61
69
|
}
|
|
62
70
|
: {};
|
|
63
|
-
return (_jsxs(Tag, { ref: ref, className: classes, ...anchorProps, ...buttonProps, onClick: disabled ? undefined : onClick, ...rest, children: [leftIcon && leftIcon, children != null && children !== '' && (_jsx("span", { className: "tui-chip__text", children: children })), rightIcon && rightIcon
|
|
71
|
+
return (_jsxs(Tag, { ref: ref, className: classes, ...anchorProps, ...buttonProps, onClick: disabled ? undefined : onClick, ...rest, children: [leftIcon && leftIcon, children != null && children !== '' && (_jsx("span", { className: "tui-chip__text", children: children })), rightIcon && rightIcon, onRemove && (_jsx("button", { type: "button", className: "tui-chip__remove", "aria-label": removeLabel, disabled: disabled, tabIndex: disabled ? -1 : undefined,
|
|
72
|
+
// Stop propagation so removing doesn't trigger any ancestor click
|
|
73
|
+
// (e.g. a token-field wrapper that focuses the input).
|
|
74
|
+
onClick: (e) => {
|
|
75
|
+
e.stopPropagation();
|
|
76
|
+
onRemove(e);
|
|
77
|
+
},
|
|
78
|
+
// Keep pointerdown from stealing focus/opening a parent listbox.
|
|
79
|
+
onPointerDown: (e) => e.stopPropagation(), children: _jsx(Icon, { name: "system/close", "aria-hidden": "true" }) }))] }));
|
|
64
80
|
});
|
|
@@ -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;
|