@pickle-ui/react 1.0.0-beta.14 → 1.0.0-beta.16
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/README.md +23 -12
- package/dist/components/Alert.d.ts +1 -1
- package/dist/components/Alert.d.ts.map +1 -1
- package/dist/components/Alert.js.map +1 -1
- package/dist/components/AlertDialog.d.ts.map +1 -1
- package/dist/components/AlertDialog.js +3 -3
- package/dist/components/AlertDialog.js.map +1 -1
- package/dist/components/Avatar.d.ts +1 -1
- package/dist/components/Avatar.d.ts.map +1 -1
- package/dist/components/Avatar.js.map +1 -1
- package/dist/components/Badge.d.ts +2 -2
- package/dist/components/Badge.d.ts.map +1 -1
- package/dist/components/Badge.js.map +1 -1
- package/dist/components/Button.d.ts +2 -2
- package/dist/components/Button.d.ts.map +1 -1
- package/dist/components/Button.js +1 -1
- package/dist/components/Button.js.map +1 -1
- package/dist/components/Card.d.ts +1 -1
- package/dist/components/Card.d.ts.map +1 -1
- package/dist/components/Card.js +1 -1
- package/dist/components/Card.js.map +1 -1
- package/dist/components/Dialog.d.ts.map +1 -1
- package/dist/components/Dialog.js.map +1 -1
- package/dist/components/Drawer.d.ts +2 -2
- package/dist/components/Drawer.d.ts.map +1 -1
- package/dist/components/Drawer.js.map +1 -1
- package/dist/components/Flex.d.ts +7 -7
- package/dist/components/Flex.d.ts.map +1 -1
- package/dist/components/Grid.d.ts +42 -42
- package/dist/components/Grid.d.ts.map +1 -1
- package/dist/components/Grid.js +4 -3
- package/dist/components/Grid.js.map +1 -1
- package/dist/components/Group.d.ts.map +1 -1
- package/dist/components/Group.js.map +1 -1
- package/dist/components/Menu.d.ts +1 -1
- package/dist/components/Menu.d.ts.map +1 -1
- package/dist/components/Menu.js +1 -1
- package/dist/components/Menu.js.map +1 -1
- package/dist/components/Popover.d.ts.map +1 -1
- package/dist/components/Popover.js.map +1 -1
- package/dist/components/Progress.d.ts +1 -1
- package/dist/components/Progress.d.ts.map +1 -1
- package/dist/components/Progress.js +1 -1
- package/dist/components/Progress.js.map +1 -1
- package/dist/components/ScrollArea.d.ts.map +1 -1
- package/dist/components/ScrollArea.js +1 -1
- package/dist/components/ScrollArea.js.map +1 -1
- package/dist/components/Separator.d.ts.map +1 -1
- package/dist/components/Separator.js.map +1 -1
- package/dist/components/Sidebar.d.ts.map +1 -1
- package/dist/components/Sidebar.js +1 -1
- package/dist/components/Sidebar.js.map +1 -1
- package/dist/components/Spinner.d.ts.map +1 -1
- package/dist/components/Spinner.js.map +1 -1
- package/dist/components/Table.d.ts +1 -1
- package/dist/components/Table.d.ts.map +1 -1
- package/dist/components/Table.js +2 -2
- package/dist/components/Table.js.map +1 -1
- package/dist/components/Tabs.d.ts +26 -0
- package/dist/components/Tabs.d.ts.map +1 -0
- package/dist/components/Tabs.js +78 -0
- package/dist/components/Tabs.js.map +1 -0
- package/dist/components/Text.d.ts.map +1 -1
- package/dist/components/Text.js.map +1 -1
- package/dist/components/Toast.d.ts.map +1 -1
- package/dist/components/Toast.js +1 -1
- package/dist/components/Toast.js.map +1 -1
- package/dist/components/Tooltip.d.ts +1 -1
- package/dist/components/Tooltip.d.ts.map +1 -1
- package/dist/components/Tooltip.js.map +1 -1
- package/dist/components/XStack.d.ts.map +1 -1
- package/dist/components/XStack.js.map +1 -1
- package/dist/components/YStack.d.ts.map +1 -1
- package/dist/components/YStack.js.map +1 -1
- package/dist/components/_internal/VisuallyHiddenInput.d.ts.map +1 -1
- package/dist/components/_internal/VisuallyHiddenInput.js +2 -4
- package/dist/components/_internal/VisuallyHiddenInput.js.map +1 -1
- package/dist/components/_internal/dialog-styles.d.ts +1 -1
- package/dist/components/_internal/dialog-styles.d.ts.map +1 -1
- package/dist/components/_internal/dialog-styles.js.map +1 -1
- package/dist/components/_internal/layout.d.ts +27 -27
- package/dist/components/_internal/layout.d.ts.map +1 -1
- package/dist/components/_internal/layout.js +1 -1
- package/dist/components/_internal/layout.js.map +1 -1
- package/dist/components/_internal/separate.d.ts +1 -1
- package/dist/components/_internal/separate.d.ts.map +1 -1
- package/dist/components/_internal/separate.js.map +1 -1
- package/dist/components/form/Checkbox.d.ts.map +1 -1
- package/dist/components/form/Checkbox.js.map +1 -1
- package/dist/components/form/ColorPicker.d.ts.map +1 -1
- package/dist/components/form/ColorPicker.js.map +1 -1
- package/dist/components/form/ColorPickerPrimitive.d.ts.map +1 -1
- package/dist/components/form/ColorPickerPrimitive.js +9 -14
- package/dist/components/form/ColorPickerPrimitive.js.map +1 -1
- package/dist/components/form/Combobox.d.ts.map +1 -1
- package/dist/components/form/Combobox.js +11 -12
- package/dist/components/form/Combobox.js.map +1 -1
- package/dist/components/form/Form.context.d.ts.map +1 -1
- package/dist/components/form/Form.context.js +2 -4
- package/dist/components/form/Form.context.js.map +1 -1
- package/dist/components/form/Form.d.ts +1 -1
- package/dist/components/form/Form.d.ts.map +1 -1
- package/dist/components/form/FormCheckbox.d.ts.map +1 -1
- package/dist/components/form/FormCheckbox.js.map +1 -1
- package/dist/components/form/FormCombobox.d.ts +1 -1
- package/dist/components/form/FormCombobox.d.ts.map +1 -1
- package/dist/components/form/FormCombobox.js +1 -1
- package/dist/components/form/FormCombobox.js.map +1 -1
- package/dist/components/form/FormField.d.ts.map +1 -1
- package/dist/components/form/FormField.js +1 -1
- package/dist/components/form/FormField.js.map +1 -1
- package/dist/components/form/FormInput.d.ts.map +1 -1
- package/dist/components/form/FormInput.js +1 -1
- package/dist/components/form/FormInput.js.map +1 -1
- package/dist/components/form/FormInputGroup.d.ts.map +1 -1
- package/dist/components/form/FormInputGroup.js +2 -6
- package/dist/components/form/FormInputGroup.js.map +1 -1
- package/dist/components/form/FormRadioGroup.d.ts +1 -1
- package/dist/components/form/FormRadioGroup.d.ts.map +1 -1
- package/dist/components/form/FormSwitch.d.ts.map +1 -1
- package/dist/components/form/FormSwitch.js.map +1 -1
- package/dist/components/form/FormTextarea.d.ts.map +1 -1
- package/dist/components/form/FormTextarea.js +1 -1
- package/dist/components/form/FormTextarea.js.map +1 -1
- package/dist/components/form/Input.d.ts.map +1 -1
- package/dist/components/form/Input.js.map +1 -1
- package/dist/components/form/InputGroup.d.ts +1 -1
- package/dist/components/form/InputGroup.d.ts.map +1 -1
- package/dist/components/form/InputGroup.js.map +1 -1
- package/dist/components/form/RadioGroup.d.ts.map +1 -1
- package/dist/components/form/RadioGroup.js.map +1 -1
- package/dist/components/form/Select.d.ts.map +1 -1
- package/dist/components/form/Select.js +1 -1
- package/dist/components/form/Select.js.map +1 -1
- package/dist/components/form/Slider.d.ts +1 -1
- package/dist/components/form/Slider.d.ts.map +1 -1
- package/dist/components/form/Slider.js.map +1 -1
- package/dist/components/form/Switch.d.ts.map +1 -1
- package/dist/components/form/Switch.js.map +1 -1
- package/dist/components/form/Textarea.d.ts.map +1 -1
- package/dist/components/form/Textarea.js.map +1 -1
- package/dist/entries/checkbox.d.ts +1 -1
- package/dist/entries/checkbox.d.ts.map +1 -1
- package/dist/entries/group.d.ts +1 -1
- package/dist/entries/group.d.ts.map +1 -1
- package/dist/entries/radio-group.d.ts +1 -1
- package/dist/entries/radio-group.d.ts.map +1 -1
- package/dist/entries/tabs.d.ts +3 -0
- package/dist/entries/tabs.d.ts.map +1 -0
- package/dist/entries/tabs.js +2 -0
- package/dist/entries/tabs.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/color.d.ts +1 -1
- package/dist/lib/color.d.ts.map +1 -1
- package/dist/lib/color.js +1 -3
- package/dist/lib/color.js.map +1 -1
- package/dist/lib/compose-refs.js +1 -1
- package/dist/lib/compose-refs.js.map +1 -1
- package/package.json +33 -32
- package/skills/pickle-ui-react/SKILL.md +38 -0
- package/src/agent-skill.test.ts +30 -0
- package/src/components/Alert.test.tsx +3 -12
- package/src/components/Alert.tsx +2 -4
- package/src/components/AlertDialog.stories.tsx +10 -35
- package/src/components/AlertDialog.test.tsx +6 -23
- package/src/components/AlertDialog.tsx +12 -40
- package/src/components/Avatar.stories.tsx +3 -8
- package/src/components/Avatar.tsx +4 -18
- package/src/components/Badge.stories.tsx +1 -5
- package/src/components/Badge.test.tsx +1 -4
- package/src/components/Badge.tsx +5 -14
- package/src/components/Button.stories.tsx +4 -16
- package/src/components/Button.test.tsx +8 -9
- package/src/components/Button.tsx +2 -7
- package/src/components/Card.stories.tsx +1 -3
- package/src/components/Card.test.tsx +1 -3
- package/src/components/Card.tsx +1 -9
- package/src/components/Dialog.stories.tsx +9 -23
- package/src/components/Dialog.test.tsx +6 -23
- package/src/components/Dialog.tsx +4 -17
- package/src/components/Drawer.stories.tsx +9 -34
- package/src/components/Drawer.test.tsx +8 -29
- package/src/components/Drawer.tsx +4 -15
- package/src/components/Grid.stories.tsx +1 -4
- package/src/components/Grid.test.tsx +1 -3
- package/src/components/Grid.tsx +4 -4
- package/src/components/Group.stories.tsx +4 -20
- package/src/components/Group.test.tsx +2 -9
- package/src/components/Group.tsx +3 -12
- package/src/components/Menu.stories.tsx +5 -18
- package/src/components/Menu.test.tsx +11 -17
- package/src/components/Menu.tsx +7 -27
- package/src/components/Popover.stories.tsx +4 -10
- package/src/components/Popover.tsx +3 -13
- package/src/components/Progress.tsx +5 -24
- package/src/components/ScrollArea.test.tsx +4 -6
- package/src/components/ScrollArea.tsx +10 -28
- package/src/components/Separator.test.tsx +2 -8
- package/src/components/Separator.tsx +1 -5
- package/src/components/Sidebar.stories.tsx +1 -5
- package/src/components/Sidebar.tsx +4 -22
- package/src/components/Spinner.tsx +1 -5
- package/src/components/Table.stories.tsx +1 -3
- package/src/components/Table.tsx +5 -30
- package/src/components/Tabs.stories.tsx +101 -0
- package/src/components/Tabs.test.tsx +129 -0
- package/src/components/Tabs.tsx +142 -0
- package/src/components/Text.stories.tsx +8 -13
- package/src/components/Text.tsx +1 -4
- package/src/components/Toast.test.tsx +6 -17
- package/src/components/Toast.tsx +4 -17
- package/src/components/Tooltip.stories.tsx +6 -28
- package/src/components/Tooltip.test.tsx +2 -8
- package/src/components/Tooltip.tsx +3 -12
- package/src/components/XStack.stories.tsx +4 -8
- package/src/components/XStack.test.tsx +9 -20
- package/src/components/XStack.tsx +2 -13
- package/src/components/YStack.stories.tsx +2 -8
- package/src/components/YStack.tsx +2 -13
- package/src/components/_internal/Story.tsx +6 -23
- package/src/components/_internal/VisuallyHiddenInput.tsx +4 -9
- package/src/components/_internal/dialog-styles.ts +1 -2
- package/src/components/_internal/layout.ts +1 -7
- package/src/components/_internal/separate.tsx +6 -9
- package/src/components/form/Checkbox.test.tsx +5 -16
- package/src/components/form/Checkbox.tsx +1 -4
- package/src/components/form/ColorPicker.stories.tsx +3 -10
- package/src/components/form/ColorPicker.test.tsx +1 -3
- package/src/components/form/ColorPicker.tsx +2 -6
- package/src/components/form/ColorPickerPrimitive.tsx +40 -151
- package/src/components/form/Combobox.stories.tsx +7 -31
- package/src/components/form/Combobox.test.tsx +10 -27
- package/src/components/form/Combobox.tsx +31 -89
- package/src/components/form/Form.context.ts +5 -19
- package/src/components/form/Form.stories.tsx +6 -28
- package/src/components/form/Form.test.tsx +21 -38
- package/src/components/form/FormCheckbox.tsx +1 -5
- package/src/components/form/FormCombobox.tsx +4 -10
- package/src/components/form/FormField.tsx +4 -15
- package/src/components/form/FormInput.tsx +2 -12
- package/src/components/form/FormInputGroup.tsx +3 -11
- package/src/components/form/FormSwitch.tsx +1 -5
- package/src/components/form/FormTextarea.tsx +3 -11
- package/src/components/form/Input.stories.tsx +1 -5
- package/src/components/form/Input.test.tsx +20 -31
- package/src/components/form/Input.tsx +1 -4
- package/src/components/form/InputGroup.stories.tsx +4 -23
- package/src/components/form/InputGroup.tsx +5 -10
- package/src/components/form/RadioGroup.test.tsx +14 -28
- package/src/components/form/RadioGroup.tsx +1 -5
- package/src/components/form/Select.stories.tsx +2 -10
- package/src/components/form/Select.test.tsx +4 -14
- package/src/components/form/Select.tsx +9 -38
- package/src/components/form/Slider.stories.tsx +7 -17
- package/src/components/form/Slider.test.tsx +4 -12
- package/src/components/form/Slider.tsx +4 -20
- package/src/components/form/Switch.test.tsx +3 -9
- package/src/components/form/Switch.tsx +2 -9
- package/src/components/form/Textarea.test.tsx +2 -6
- package/src/components/form/Textarea.tsx +1 -6
- package/src/entries/checkbox.ts +1 -4
- package/src/entries/group.ts +1 -5
- package/src/entries/radio-group.ts +1 -4
- package/src/entries/tabs.ts +8 -0
- package/src/index.ts +1 -0
- package/src/lib/color.test.ts +2 -6
- package/src/lib/color.ts +3 -11
- package/src/lib/compose-refs.ts +1 -1
- package/src/public-api.test.ts +7 -8
|
@@ -31,13 +31,7 @@ import { Button } from '../Button';
|
|
|
31
31
|
import { Popover, PopoverContent, PopoverTrigger } from '../Popover';
|
|
32
32
|
import { Input } from './Input';
|
|
33
33
|
import { InputGroup, InputGroupInput } from './InputGroup';
|
|
34
|
-
import {
|
|
35
|
-
Select,
|
|
36
|
-
SelectContent,
|
|
37
|
-
SelectItem,
|
|
38
|
-
SelectTrigger,
|
|
39
|
-
SelectValue,
|
|
40
|
-
} from './Select';
|
|
34
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './Select';
|
|
41
35
|
import { Slider } from './Slider';
|
|
42
36
|
|
|
43
37
|
const ROOT_NAME = 'ColorPicker';
|
|
@@ -85,11 +79,7 @@ interface Store {
|
|
|
85
79
|
notify: () => void;
|
|
86
80
|
setFormat: (value: ColorFormat) => void;
|
|
87
81
|
setOpen: (value: boolean) => void;
|
|
88
|
-
setValue: (
|
|
89
|
-
color: ColorValue,
|
|
90
|
-
hsv: HSVColorValue,
|
|
91
|
-
options?: { emit?: boolean },
|
|
92
|
-
) => void;
|
|
82
|
+
setValue: (color: ColorValue, hsv: HSVColorValue, options?: { emit?: boolean }) => void;
|
|
93
83
|
subscribe: (cb: () => void) => () => void;
|
|
94
84
|
}
|
|
95
85
|
|
|
@@ -113,10 +103,7 @@ interface ColorPickerContextValue {
|
|
|
113
103
|
function useStore<U>(selector: (state: StoreState) => U): U {
|
|
114
104
|
const store = useStoreContext('useStore');
|
|
115
105
|
|
|
116
|
-
const getSnapshot = React.useCallback(
|
|
117
|
-
() => selector(store.getState()),
|
|
118
|
-
[store, selector],
|
|
119
|
-
);
|
|
106
|
+
const getSnapshot = React.useCallback(() => selector(store.getState()), [store, selector]);
|
|
120
107
|
|
|
121
108
|
return React.useSyncExternalStore(store.subscribe, getSnapshot, getSnapshot);
|
|
122
109
|
}
|
|
@@ -129,9 +116,7 @@ function useStoreContext(consumerName: string) {
|
|
|
129
116
|
return context;
|
|
130
117
|
}
|
|
131
118
|
|
|
132
|
-
const ColorPickerContext = React.createContext<ColorPickerContextValue | null>(
|
|
133
|
-
null,
|
|
134
|
-
);
|
|
119
|
+
const ColorPickerContext = React.createContext<ColorPickerContextValue | null>(null);
|
|
135
120
|
|
|
136
121
|
type ColorPickerContentProps = Omit<
|
|
137
122
|
React.ComponentProps<typeof PopoverContent>,
|
|
@@ -146,16 +131,10 @@ interface ColorPickerFormatSelectProps
|
|
|
146
131
|
Omit<React.ComponentProps<typeof Select>, 'onValueChange' | 'value'>,
|
|
147
132
|
Pick<React.ComponentProps<typeof SelectTrigger>, 'className'> {}
|
|
148
133
|
|
|
149
|
-
|
|
150
|
-
interface ColorPickerImplProps extends Omit<
|
|
134
|
+
type ColorPickerImplProps = Omit<
|
|
151
135
|
ColorPickerProps,
|
|
152
|
-
| '
|
|
153
|
-
|
|
154
|
-
| 'format'
|
|
155
|
-
| 'onFormatChange'
|
|
156
|
-
| 'onOpenChange'
|
|
157
|
-
| 'onValueChange'
|
|
158
|
-
> {}
|
|
136
|
+
'defaultFormat' | 'defaultValue' | 'format' | 'onFormatChange' | 'onOpenChange' | 'onValueChange'
|
|
137
|
+
>;
|
|
159
138
|
|
|
160
139
|
interface ColorPickerInputProps extends Omit<
|
|
161
140
|
React.ComponentProps<typeof Input>,
|
|
@@ -168,10 +147,7 @@ interface ColorPickerInputProps extends Omit<
|
|
|
168
147
|
interface ColorPickerProps
|
|
169
148
|
extends
|
|
170
149
|
Omit<DivProps, 'onValueChange'>,
|
|
171
|
-
Pick<
|
|
172
|
-
React.ComponentProps<typeof Popover>,
|
|
173
|
-
'defaultOpen' | 'modal' | 'open'
|
|
174
|
-
> {
|
|
150
|
+
Pick<React.ComponentProps<typeof Popover>, 'defaultOpen' | 'modal' | 'open'> {
|
|
175
151
|
defaultFormat?: ColorFormat;
|
|
176
152
|
defaultValue?: string;
|
|
177
153
|
dir?: Direction;
|
|
@@ -277,11 +253,7 @@ function ColorPicker(props: ColorPickerProps) {
|
|
|
277
253
|
stateRef.current.color = color;
|
|
278
254
|
stateRef.current.hsv = hsv;
|
|
279
255
|
|
|
280
|
-
if (
|
|
281
|
-
options?.emit !== false &&
|
|
282
|
-
colorChanged &&
|
|
283
|
-
propsRef.current.onValueChange
|
|
284
|
-
) {
|
|
256
|
+
if (options?.emit !== false && colorChanged && propsRef.current.onValueChange) {
|
|
285
257
|
const colorString = colorToString(color, prevState.format);
|
|
286
258
|
propsRef.current.onValueChange(colorString);
|
|
287
259
|
}
|
|
@@ -385,10 +357,7 @@ function ColorPickerArea(props: DivProps) {
|
|
|
385
357
|
|
|
386
358
|
const rect = areaRef.current.getBoundingClientRect();
|
|
387
359
|
const x = Math.max(0, Math.min(1, (clientX - rect.left) / rect.width));
|
|
388
|
-
const y = Math.max(
|
|
389
|
-
0,
|
|
390
|
-
Math.min(1, 1 - (clientY - rect.top) / rect.height),
|
|
391
|
-
);
|
|
360
|
+
const y = Math.max(0, Math.min(1, 1 - (clientY - rect.top) / rect.height));
|
|
392
361
|
|
|
393
362
|
const newHsv: HSVColorValue = {
|
|
394
363
|
a: hsv?.a ?? 1,
|
|
@@ -492,15 +461,7 @@ function ColorPickerArea(props: DivProps) {
|
|
|
492
461
|
}
|
|
493
462
|
|
|
494
463
|
function ColorPickerContent(props: ColorPickerContentProps) {
|
|
495
|
-
const {
|
|
496
|
-
align,
|
|
497
|
-
children,
|
|
498
|
-
className,
|
|
499
|
-
render,
|
|
500
|
-
side,
|
|
501
|
-
sideOffset,
|
|
502
|
-
...popoverContentProps
|
|
503
|
-
} = props;
|
|
464
|
+
const { align, children, className, render, side, sideOffset, ...popoverContentProps } = props;
|
|
504
465
|
|
|
505
466
|
const context = useColorPickerContext(CONTENT_NAME);
|
|
506
467
|
const inlineContent = useRender({
|
|
@@ -605,10 +566,7 @@ function ColorPickerFormatSelect(props: ColorPickerFormatSelectProps) {
|
|
|
605
566
|
onValueChange={(value) => onFormatChange(value as ColorFormat)}
|
|
606
567
|
value={format}
|
|
607
568
|
>
|
|
608
|
-
<SelectTrigger
|
|
609
|
-
className={cn(className)}
|
|
610
|
-
data-slot="color-picker-format-select-trigger"
|
|
611
|
-
>
|
|
569
|
+
<SelectTrigger className={cn(className)} data-slot="color-picker-format-select-trigger">
|
|
612
570
|
<SelectValue />
|
|
613
571
|
</SelectTrigger>
|
|
614
572
|
<SelectContent>
|
|
@@ -684,18 +642,14 @@ function ColorPickerImpl(props: ColorPickerImplProps) {
|
|
|
684
642
|
const contextDir = useDirection();
|
|
685
643
|
const dir = dirProp ?? contextDir;
|
|
686
644
|
|
|
687
|
-
const [formTrigger, setFormTrigger] = React.useState<null | RootElement>(
|
|
688
|
-
null,
|
|
689
|
-
);
|
|
645
|
+
const [formTrigger, setFormTrigger] = React.useState<null | RootElement>(null);
|
|
690
646
|
const composedRef = useComposedRefs(ref, (node) => setFormTrigger(node));
|
|
691
647
|
const isFormControl = formTrigger ? !!formTrigger.closest('form') : true;
|
|
692
648
|
|
|
693
649
|
useIsomorphicLayoutEffect(() => {
|
|
694
650
|
if (valueProp !== undefined) {
|
|
695
651
|
const currentState = store.getState();
|
|
696
|
-
const color =
|
|
697
|
-
parseColorString(valueProp) ??
|
|
698
|
-
hexToRgb(valueProp, currentState.color.a);
|
|
652
|
+
const color = parseColorString(valueProp) ?? hexToRgb(valueProp, currentState.color.a);
|
|
699
653
|
const hsv = rgbToHsv(color, currentState.hsv.h);
|
|
700
654
|
store.setValue(color, hsv, { emit: false });
|
|
701
655
|
}
|
|
@@ -749,12 +703,7 @@ function ColorPickerImpl(props: ColorPickerImplProps) {
|
|
|
749
703
|
|
|
750
704
|
return (
|
|
751
705
|
<ColorPickerContext.Provider value={contextValue}>
|
|
752
|
-
<Popover
|
|
753
|
-
defaultOpen={defaultOpen}
|
|
754
|
-
modal={modal}
|
|
755
|
-
onOpenChange={store.setOpen}
|
|
756
|
-
open={open}
|
|
757
|
-
>
|
|
706
|
+
<Popover defaultOpen={defaultOpen} modal={modal} onOpenChange={store.setOpen} open={open}>
|
|
758
707
|
{root}
|
|
759
708
|
{isFormControl && (
|
|
760
709
|
<VisuallyHiddenInput
|
|
@@ -789,47 +738,19 @@ function ColorPickerInput(props: ColorPickerInputProps) {
|
|
|
789
738
|
);
|
|
790
739
|
|
|
791
740
|
if (format === 'hex') {
|
|
792
|
-
return
|
|
793
|
-
<HexInput
|
|
794
|
-
color={color}
|
|
795
|
-
context={context}
|
|
796
|
-
onColorChange={onColorChange}
|
|
797
|
-
{...props}
|
|
798
|
-
/>
|
|
799
|
-
);
|
|
741
|
+
return <HexInput color={color} context={context} onColorChange={onColorChange} {...props} />;
|
|
800
742
|
}
|
|
801
743
|
|
|
802
744
|
if (format === 'rgb') {
|
|
803
|
-
return
|
|
804
|
-
<RgbInput
|
|
805
|
-
color={color}
|
|
806
|
-
context={context}
|
|
807
|
-
onColorChange={onColorChange}
|
|
808
|
-
{...props}
|
|
809
|
-
/>
|
|
810
|
-
);
|
|
745
|
+
return <RgbInput color={color} context={context} onColorChange={onColorChange} {...props} />;
|
|
811
746
|
}
|
|
812
747
|
|
|
813
748
|
if (format === 'hsl') {
|
|
814
|
-
return
|
|
815
|
-
<HslInput
|
|
816
|
-
color={color}
|
|
817
|
-
context={context}
|
|
818
|
-
onColorChange={onColorChange}
|
|
819
|
-
{...props}
|
|
820
|
-
/>
|
|
821
|
-
);
|
|
749
|
+
return <HslInput color={color} context={context} onColorChange={onColorChange} {...props} />;
|
|
822
750
|
}
|
|
823
751
|
|
|
824
752
|
if (format === 'hsb') {
|
|
825
|
-
return
|
|
826
|
-
<HsbInput
|
|
827
|
-
context={context}
|
|
828
|
-
hsv={hsv}
|
|
829
|
-
onColorChange={onColorChange}
|
|
830
|
-
{...props}
|
|
831
|
-
/>
|
|
832
|
-
);
|
|
753
|
+
return <HsbInput context={context} hsv={hsv} onColorChange={onColorChange} {...props} />;
|
|
833
754
|
}
|
|
834
755
|
}
|
|
835
756
|
|
|
@@ -862,9 +783,7 @@ function ColorPickerSwatch(props: DivProps) {
|
|
|
862
783
|
};
|
|
863
784
|
}, [color]);
|
|
864
785
|
|
|
865
|
-
const ariaLabel = !color
|
|
866
|
-
? 'No color selected'
|
|
867
|
-
: `Current color: ${colorToString(color, format)}`;
|
|
786
|
+
const ariaLabel = !color ? 'No color selected' : `Current color: ${colorToString(color, format)}`;
|
|
868
787
|
|
|
869
788
|
return useRender({
|
|
870
789
|
defaultTagName: 'div',
|
|
@@ -905,14 +824,7 @@ function ColorPickerTrigger(props: ColorPickerTriggerProps) {
|
|
|
905
824
|
}
|
|
906
825
|
|
|
907
826
|
function HexInput(props: FormatInputProps) {
|
|
908
|
-
const {
|
|
909
|
-
className,
|
|
910
|
-
color,
|
|
911
|
-
context,
|
|
912
|
-
onColorChange,
|
|
913
|
-
withoutAlpha,
|
|
914
|
-
...inputProps
|
|
915
|
-
} = props;
|
|
827
|
+
const { className, color, context, onColorChange, withoutAlpha, ...inputProps } = props;
|
|
916
828
|
|
|
917
829
|
const hexValue = rgbToHex(color);
|
|
918
830
|
const alphaValue = Math.round((color?.a ?? 1) * 100);
|
|
@@ -981,27 +893,19 @@ function HexInput(props: FormatInputProps) {
|
|
|
981
893
|
}
|
|
982
894
|
|
|
983
895
|
function HsbInput(props: HsbInputProps) {
|
|
984
|
-
const {
|
|
985
|
-
className,
|
|
986
|
-
context,
|
|
987
|
-
hsv,
|
|
988
|
-
onColorChange,
|
|
989
|
-
withoutAlpha,
|
|
990
|
-
...inputProps
|
|
991
|
-
} = props;
|
|
896
|
+
const { className, context, hsv, onColorChange, withoutAlpha, ...inputProps } = props;
|
|
992
897
|
|
|
993
898
|
const alphaValue = Math.round((hsv?.a ?? 1) * 100);
|
|
994
899
|
|
|
995
900
|
const onHsvChannelChange = React.useCallback(
|
|
996
|
-
(channel: 'h' | 's' | 'v', max: number) =>
|
|
997
|
-
(event
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
},
|
|
901
|
+
(channel: 'h' | 's' | 'v', max: number) => (event: React.ChangeEvent<InputElement>) => {
|
|
902
|
+
const value = Number.parseInt(event.target.value, 10);
|
|
903
|
+
if (!Number.isNaN(value) && value >= 0 && value <= max) {
|
|
904
|
+
const newHsv = { ...hsv, [channel]: value };
|
|
905
|
+
const newColor = hsvToRgb(newHsv);
|
|
906
|
+
onColorChange(newColor);
|
|
907
|
+
}
|
|
908
|
+
},
|
|
1005
909
|
[hsv, onColorChange],
|
|
1006
910
|
);
|
|
1007
911
|
|
|
@@ -1077,28 +981,20 @@ function HsbInput(props: HsbInputProps) {
|
|
|
1077
981
|
}
|
|
1078
982
|
|
|
1079
983
|
function HslInput(props: FormatInputProps) {
|
|
1080
|
-
const {
|
|
1081
|
-
className,
|
|
1082
|
-
color,
|
|
1083
|
-
context,
|
|
1084
|
-
onColorChange,
|
|
1085
|
-
withoutAlpha,
|
|
1086
|
-
...inputProps
|
|
1087
|
-
} = props;
|
|
984
|
+
const { className, color, context, onColorChange, withoutAlpha, ...inputProps } = props;
|
|
1088
985
|
|
|
1089
986
|
const hsl = React.useMemo(() => rgbToHsl(color), [color]);
|
|
1090
987
|
const alphaValue = Math.round((color?.a ?? 1) * 100);
|
|
1091
988
|
|
|
1092
989
|
const onHslChannelChange = React.useCallback(
|
|
1093
|
-
(channel: 'h' | 'l' | 's', max: number) =>
|
|
1094
|
-
(event
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
},
|
|
990
|
+
(channel: 'h' | 'l' | 's', max: number) => (event: React.ChangeEvent<InputElement>) => {
|
|
991
|
+
const value = Number.parseInt(event.target.value, 10);
|
|
992
|
+
if (!Number.isNaN(value) && value >= 0 && value <= max) {
|
|
993
|
+
const newHsl = { ...hsl, [channel]: value };
|
|
994
|
+
const newColor = hslToRgb(newHsl, color?.a ?? 1);
|
|
995
|
+
onColorChange(newColor);
|
|
996
|
+
}
|
|
997
|
+
},
|
|
1102
998
|
[hsl, color, onColorChange],
|
|
1103
999
|
);
|
|
1104
1000
|
|
|
@@ -1173,14 +1069,7 @@ function HslInput(props: FormatInputProps) {
|
|
|
1173
1069
|
}
|
|
1174
1070
|
|
|
1175
1071
|
function RgbInput(props: FormatInputProps) {
|
|
1176
|
-
const {
|
|
1177
|
-
className,
|
|
1178
|
-
color,
|
|
1179
|
-
context,
|
|
1180
|
-
onColorChange,
|
|
1181
|
-
withoutAlpha,
|
|
1182
|
-
...inputProps
|
|
1183
|
-
} = props;
|
|
1072
|
+
const { className, color, context, onColorChange, withoutAlpha, ...inputProps } = props;
|
|
1184
1073
|
|
|
1185
1074
|
const rValue = Math.round(color?.r ?? 0);
|
|
1186
1075
|
const gValue = Math.round(color?.g ?? 0);
|
|
@@ -113,11 +113,7 @@ function CreatableFruit() {
|
|
|
113
113
|
return fruit;
|
|
114
114
|
}}
|
|
115
115
|
>
|
|
116
|
-
<Combobox.Input
|
|
117
|
-
aria-label="Fruit"
|
|
118
|
-
className="w-64"
|
|
119
|
-
placeholder="Type a new fruit…"
|
|
120
|
-
/>
|
|
116
|
+
<Combobox.Input aria-label="Fruit" className="w-64" placeholder="Type a new fruit…" />
|
|
121
117
|
<Combobox.Content>
|
|
122
118
|
<Combobox.List>
|
|
123
119
|
{(fruit: Fruit) => (
|
|
@@ -178,12 +174,7 @@ function CreatableTags() {
|
|
|
178
174
|
);
|
|
179
175
|
}
|
|
180
176
|
|
|
181
|
-
function FruitCombobox({
|
|
182
|
-
disabled,
|
|
183
|
-
focus,
|
|
184
|
-
invalid,
|
|
185
|
-
value,
|
|
186
|
-
}: FruitComboboxStateProps) {
|
|
177
|
+
function FruitCombobox({ disabled, focus, invalid, value }: FruitComboboxStateProps) {
|
|
187
178
|
return (
|
|
188
179
|
<Combobox defaultValue={value} disabled={disabled} items={FRUITS}>
|
|
189
180
|
<Combobox.Input
|
|
@@ -212,9 +203,7 @@ function FruitCombobox({
|
|
|
212
203
|
function StartsWithFruit() {
|
|
213
204
|
return (
|
|
214
205
|
<Combobox
|
|
215
|
-
filter={(fruit: Fruit, query) =>
|
|
216
|
-
fruit.label.toLowerCase().startsWith(query.toLowerCase())
|
|
217
|
-
}
|
|
206
|
+
filter={(fruit: Fruit, query) => fruit.label.toLowerCase().startsWith(query.toLowerCase())}
|
|
218
207
|
items={FRUITS}
|
|
219
208
|
>
|
|
220
209
|
<Combobox.Input
|
|
@@ -253,17 +242,10 @@ export const All: StoryDefinition = {
|
|
|
253
242
|
<Story.Section title="Label and clear">
|
|
254
243
|
<Combobox defaultValue={FRUITS[6]} items={FRUITS}>
|
|
255
244
|
<div className="flex w-64 flex-col gap-2">
|
|
256
|
-
<label
|
|
257
|
-
className="text-sm leading-none font-medium"
|
|
258
|
-
htmlFor="favorite-fruit"
|
|
259
|
-
>
|
|
245
|
+
<label className="text-sm leading-none font-medium" htmlFor="favorite-fruit">
|
|
260
246
|
Favorite fruit
|
|
261
247
|
</label>
|
|
262
|
-
<Combobox.Input
|
|
263
|
-
id="favorite-fruit"
|
|
264
|
-
placeholder="Search fruits…"
|
|
265
|
-
showClear
|
|
266
|
-
/>
|
|
248
|
+
<Combobox.Input id="favorite-fruit" placeholder="Search fruits…" showClear />
|
|
267
249
|
</div>
|
|
268
250
|
<Combobox.Content>
|
|
269
251
|
<Combobox.Empty>No fruit found.</Combobox.Empty>
|
|
@@ -305,11 +287,7 @@ export const All: StoryDefinition = {
|
|
|
305
287
|
|
|
306
288
|
<Story.Section title="Groups">
|
|
307
289
|
<Combobox items={PRODUCE}>
|
|
308
|
-
<Combobox.Input
|
|
309
|
-
aria-label="Produce"
|
|
310
|
-
className="w-64"
|
|
311
|
-
placeholder="Search produce…"
|
|
312
|
-
/>
|
|
290
|
+
<Combobox.Input aria-label="Produce" className="w-64" placeholder="Search produce…" />
|
|
313
291
|
<Combobox.Content>
|
|
314
292
|
<Combobox.Empty>Nothing found.</Combobox.Empty>
|
|
315
293
|
<Combobox.List>
|
|
@@ -338,9 +316,7 @@ export const All: StoryDefinition = {
|
|
|
338
316
|
{(value: Fruit[]) => (
|
|
339
317
|
<>
|
|
340
318
|
{value.map((fruit) => (
|
|
341
|
-
<Combobox.Chip key={fruit.value}>
|
|
342
|
-
{fruit.label}
|
|
343
|
-
</Combobox.Chip>
|
|
319
|
+
<Combobox.Chip key={fruit.value}>{fruit.label}</Combobox.Chip>
|
|
344
320
|
))}
|
|
345
321
|
<Combobox.ChipsInput
|
|
346
322
|
aria-label="Fruits"
|
|
@@ -36,9 +36,7 @@ describe('Combobox', () => {
|
|
|
36
36
|
</Combobox>,
|
|
37
37
|
);
|
|
38
38
|
|
|
39
|
-
expect(screen.getByRole('combobox', { name: 'Fruit' })).toHaveValue(
|
|
40
|
-
'Banana',
|
|
41
|
-
);
|
|
39
|
+
expect(screen.getByRole('combobox', { name: 'Fruit' })).toHaveValue('Banana');
|
|
42
40
|
});
|
|
43
41
|
|
|
44
42
|
it('filters items as the user types', () => {
|
|
@@ -53,9 +51,7 @@ describe('Combobox', () => {
|
|
|
53
51
|
target: { value: 'ch' },
|
|
54
52
|
});
|
|
55
53
|
|
|
56
|
-
expect(screen.getAllByRole('option').map((o) => o.textContent)).toEqual([
|
|
57
|
-
'Cherry',
|
|
58
|
-
]);
|
|
54
|
+
expect(screen.getAllByRole('option').map((o) => o.textContent)).toEqual(['Cherry']);
|
|
59
55
|
});
|
|
60
56
|
|
|
61
57
|
it('shows the empty state when nothing matches', () => {
|
|
@@ -151,9 +147,7 @@ describe('Combobox', () => {
|
|
|
151
147
|
{(value: Fruit[]) => (
|
|
152
148
|
<>
|
|
153
149
|
{value.map((fruit) => (
|
|
154
|
-
<Combobox.Chip key={fruit.value}>
|
|
155
|
-
{fruit.label}
|
|
156
|
-
</Combobox.Chip>
|
|
150
|
+
<Combobox.Chip key={fruit.value}>{fruit.label}</Combobox.Chip>
|
|
157
151
|
))}
|
|
158
152
|
<Combobox.ChipsInput aria-label="Fruit" />
|
|
159
153
|
</>
|
|
@@ -188,9 +182,7 @@ describe('Combobox', () => {
|
|
|
188
182
|
|
|
189
183
|
type('Papaya');
|
|
190
184
|
|
|
191
|
-
expect(screen.getAllByRole('option').map((o) => o.textContent)).toEqual([
|
|
192
|
-
'Create "Papaya"',
|
|
193
|
-
]);
|
|
185
|
+
expect(screen.getAllByRole('option').map((o) => o.textContent)).toEqual(['Create "Papaya"']);
|
|
194
186
|
expect(screen.queryByText('No fruit found.')).not.toBeInTheDocument();
|
|
195
187
|
});
|
|
196
188
|
|
|
@@ -199,9 +191,7 @@ describe('Combobox', () => {
|
|
|
199
191
|
|
|
200
192
|
type('cherry ');
|
|
201
193
|
|
|
202
|
-
expect(screen.getAllByRole('option').map((o) => o.textContent)).toEqual([
|
|
203
|
-
'Cherry',
|
|
204
|
-
]);
|
|
194
|
+
expect(screen.getAllByRole('option').map((o) => o.textContent)).toEqual(['Cherry']);
|
|
205
195
|
});
|
|
206
196
|
|
|
207
197
|
it('creates and selects the new item', () => {
|
|
@@ -212,9 +202,7 @@ describe('Combobox', () => {
|
|
|
212
202
|
fireEvent.click(screen.getByRole('option', { name: 'Create "Papaya"' }));
|
|
213
203
|
|
|
214
204
|
expect(handleCreate).toHaveBeenCalledWith('Papaya');
|
|
215
|
-
expect(screen.getByRole('combobox', { name: 'Fruit' })).toHaveValue(
|
|
216
|
-
'Papaya',
|
|
217
|
-
);
|
|
205
|
+
expect(screen.getByRole('combobox', { name: 'Fruit' })).toHaveValue('Papaya');
|
|
218
206
|
});
|
|
219
207
|
|
|
220
208
|
it('adds the created item as a chip in multiple mode', () => {
|
|
@@ -223,10 +211,7 @@ describe('Combobox', () => {
|
|
|
223
211
|
type('Papaya');
|
|
224
212
|
fireEvent.click(screen.getByRole('option', { name: 'Create "Papaya"' }));
|
|
225
213
|
|
|
226
|
-
expect(screen.getByText('Papaya')).toHaveAttribute(
|
|
227
|
-
'data-slot',
|
|
228
|
-
'combobox-chip',
|
|
229
|
-
);
|
|
214
|
+
expect(screen.getByText('Papaya')).toHaveAttribute('data-slot', 'combobox-chip');
|
|
230
215
|
});
|
|
231
216
|
|
|
232
217
|
it('appends the create option after grouped items', () => {
|
|
@@ -291,11 +276,9 @@ describe('Combobox', () => {
|
|
|
291
276
|
|
|
292
277
|
typeQuery('an');
|
|
293
278
|
expect(options()).toEqual([]);
|
|
294
|
-
expect(
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
),
|
|
298
|
-
).toBe(true);
|
|
279
|
+
expect(filter.mock.calls.some(([item, query]) => item === FRUITS[1] && query === 'an')).toBe(
|
|
280
|
+
true,
|
|
281
|
+
);
|
|
299
282
|
|
|
300
283
|
typeQuery('ba');
|
|
301
284
|
expect(options()).toEqual(['Banana']);
|