@pickle-ui/react 1.0.0-beta.13 → 1.0.0-beta.15
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 +36 -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/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 +6 -2
- package/dist/components/form/Form.d.ts.map +1 -1
- package/dist/components/form/Form.js +2 -0
- package/dist/components/form/Form.js.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 +5 -2
- package/dist/components/form/FormField.d.ts.map +1 -1
- package/dist/components/form/FormField.js +20 -9
- package/dist/components/form/FormField.js.map +1 -1
- package/dist/components/form/FormGroupField.d.ts +13 -0
- package/dist/components/form/FormGroupField.d.ts.map +1 -0
- package/dist/components/form/FormGroupField.js +17 -0
- package/dist/components/form/FormGroupField.js.map +1 -0
- 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/form.d.ts +1 -1
- package/dist/entries/form.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/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 +35 -34
- 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/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 +34 -23
- package/src/components/form/Form.test.tsx +105 -23
- package/src/components/form/Form.tsx +8 -0
- package/src/components/form/FormCheckbox.tsx +1 -5
- package/src/components/form/FormCombobox.tsx +4 -10
- package/src/components/form/FormField.tsx +50 -31
- package/src/components/form/FormGroupField.tsx +25 -0
- 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/form.ts +2 -0
- package/src/entries/group.ts +1 -5
- package/src/entries/radio-group.ts +1 -4
- 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
|
@@ -5,21 +5,14 @@ import * as React from 'react';
|
|
|
5
5
|
import { useFormState } from 'react-hook-form';
|
|
6
6
|
|
|
7
7
|
import { cn } from '../../lib/utils';
|
|
8
|
-
import {
|
|
9
|
-
FormFieldContext,
|
|
10
|
-
getErrorMessage,
|
|
11
|
-
useFormMethods,
|
|
12
|
-
} from './Form.context';
|
|
8
|
+
import { FormFieldContext, getErrorMessage, useFormMethods } from './Form.context';
|
|
13
9
|
import { FormDescription } from './FormDescription';
|
|
14
10
|
import { FormError } from './FormError';
|
|
15
11
|
import { FormLabel } from './FormLabel';
|
|
16
12
|
import { type FormRadioGroupProps, FormRadioGroupRoot } from './FormRadioGroup';
|
|
17
13
|
import { type FormSelectProps, FormSelectRoot } from './FormSelect';
|
|
18
14
|
|
|
19
|
-
type FormFieldProps = Omit<
|
|
20
|
-
React.ComponentProps<typeof Field.Root>,
|
|
21
|
-
'children'
|
|
22
|
-
> & {
|
|
15
|
+
type FormFieldProps = Omit<React.ComponentProps<typeof Field.Root>, 'children'> & {
|
|
23
16
|
children: React.ReactNode;
|
|
24
17
|
controlId?: string;
|
|
25
18
|
description?: React.ReactNode;
|
|
@@ -27,15 +20,43 @@ type FormFieldProps = Omit<
|
|
|
27
20
|
label?: React.ReactNode;
|
|
28
21
|
};
|
|
29
22
|
|
|
30
|
-
function FormField({
|
|
23
|
+
function FormField(props: FormFieldProps) {
|
|
24
|
+
return <FormFieldRoot {...props} />;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Native inputs use htmlFor/id for label focus; Base UI composites and groups
|
|
28
|
+
// use non-native labels so their primitives can wire aria-labelledby.
|
|
29
|
+
function FormFieldLabel({
|
|
30
|
+
children,
|
|
31
|
+
controlId,
|
|
32
|
+
id,
|
|
33
|
+
native,
|
|
34
|
+
}: {
|
|
35
|
+
children: React.ReactNode;
|
|
36
|
+
controlId: string;
|
|
37
|
+
id: string;
|
|
38
|
+
native: boolean;
|
|
39
|
+
}) {
|
|
40
|
+
return native ? (
|
|
41
|
+
<FormLabel htmlFor={controlId}>{children}</FormLabel>
|
|
42
|
+
) : (
|
|
43
|
+
<FormLabel id={id} nativeLabel={false} render={<span />}>
|
|
44
|
+
{children}
|
|
45
|
+
</FormLabel>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Shared by Form.Field and Form.GroupField, which sets `group`.
|
|
50
|
+
function FormFieldRoot({
|
|
31
51
|
children,
|
|
32
52
|
className,
|
|
33
53
|
controlId: controlIdProp,
|
|
34
54
|
description,
|
|
35
55
|
error,
|
|
56
|
+
group = false,
|
|
36
57
|
label,
|
|
37
58
|
...props
|
|
38
|
-
}: FormFieldProps) {
|
|
59
|
+
}: FormFieldProps & { group?: boolean }) {
|
|
39
60
|
const { control, getFieldState } = useFormMethods();
|
|
40
61
|
const name = props.name;
|
|
41
62
|
const formState = useFormState({
|
|
@@ -50,33 +71,33 @@ function FormField({
|
|
|
50
71
|
// forms and rows.
|
|
51
72
|
const generatedControlId = React.useId();
|
|
52
73
|
const controlId = controlIdProp ?? generatedControlId;
|
|
53
|
-
const
|
|
74
|
+
const labelId = React.useId();
|
|
54
75
|
const contextValue = React.useMemo(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}),
|
|
59
|
-
[controlId, name],
|
|
76
|
+
// A group's rows each keep their own id.
|
|
77
|
+
() => ({ controlId: group ? undefined : controlId, name }),
|
|
78
|
+
[controlId, group, name],
|
|
60
79
|
);
|
|
61
80
|
|
|
62
81
|
return (
|
|
63
82
|
<Field.Root
|
|
64
83
|
className={cn('grid gap-2.5', className)}
|
|
65
84
|
data-slot="field"
|
|
85
|
+
{...(group && {
|
|
86
|
+
'aria-labelledby': label ? labelId : undefined,
|
|
87
|
+
role: 'group',
|
|
88
|
+
})}
|
|
66
89
|
{...props}
|
|
67
90
|
>
|
|
68
|
-
{
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
91
|
+
{label ? (
|
|
92
|
+
<FormFieldLabel
|
|
93
|
+
controlId={controlId}
|
|
94
|
+
id={labelId}
|
|
95
|
+
native={!group && shouldUseNativeFieldLabel(children)}
|
|
96
|
+
>
|
|
74
97
|
{label}
|
|
75
|
-
</
|
|
98
|
+
</FormFieldLabel>
|
|
76
99
|
) : null}
|
|
77
|
-
<FormFieldContext.Provider value={contextValue}>
|
|
78
|
-
{children}
|
|
79
|
-
</FormFieldContext.Provider>
|
|
100
|
+
<FormFieldContext.Provider value={contextValue}>{children}</FormFieldContext.Provider>
|
|
80
101
|
{errorMessage ? (
|
|
81
102
|
<FormError match>{errorMessage}</FormError>
|
|
82
103
|
) : description ? (
|
|
@@ -92,9 +113,7 @@ function isFormRadioGroupElement(
|
|
|
92
113
|
return React.isValidElement(child) && child.type === FormRadioGroupRoot;
|
|
93
114
|
}
|
|
94
115
|
|
|
95
|
-
function isFormSelectElement(
|
|
96
|
-
child: React.ReactNode,
|
|
97
|
-
): child is React.ReactElement<FormSelectProps> {
|
|
116
|
+
function isFormSelectElement(child: React.ReactNode): child is React.ReactElement<FormSelectProps> {
|
|
98
117
|
return React.isValidElement(child) && child.type === FormSelectRoot;
|
|
99
118
|
}
|
|
100
119
|
|
|
@@ -104,5 +123,5 @@ function shouldUseNativeFieldLabel(children: React.ReactNode) {
|
|
|
104
123
|
);
|
|
105
124
|
}
|
|
106
125
|
|
|
107
|
-
export { FormField };
|
|
126
|
+
export { FormField, FormFieldRoot };
|
|
108
127
|
export type { FormFieldProps };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Field } from '@base-ui/react/field';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
|
|
4
|
+
import { type FormFieldProps, FormFieldRoot } from './FormField';
|
|
5
|
+
|
|
6
|
+
type FormGroupFieldItemProps = React.ComponentProps<typeof Field.Item>;
|
|
7
|
+
type FormGroupFieldProps = Omit<FormFieldProps, 'controlId'>;
|
|
8
|
+
|
|
9
|
+
// One row: its control gets its own label and id instead of the field's.
|
|
10
|
+
function FormGroupFieldItem(props: FormGroupFieldItemProps) {
|
|
11
|
+
return <Field.Item data-slot="group-field-item" {...props} />;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// A field whose content is not one control (a list of rows, a stepper,
|
|
15
|
+
// buttons): a group named by its label. Each row's control goes in an Item.
|
|
16
|
+
function FormGroupFieldRoot(props: FormGroupFieldProps) {
|
|
17
|
+
return <FormFieldRoot data-slot="group-field" {...props} group />;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const FormGroupField = Object.assign(FormGroupFieldRoot, {
|
|
21
|
+
Item: FormGroupFieldItem,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export { FormGroupField };
|
|
25
|
+
export type { FormGroupFieldItemProps, FormGroupFieldProps };
|
|
@@ -19,21 +19,11 @@ function FormInput({ id: idProp, name: nameProp, ...props }: FormInputProps) {
|
|
|
19
19
|
const name = useRequiredFieldName(nameProp, 'Form.Input');
|
|
20
20
|
const methods = useFormMethods();
|
|
21
21
|
const registeredProps = methods.register(name);
|
|
22
|
-
const controlProps = useFormControlProps(
|
|
23
|
-
{ id: idProp },
|
|
24
|
-
{ enabled: !isInsideInputGroup },
|
|
25
|
-
);
|
|
22
|
+
const controlProps = useFormControlProps({ id: idProp }, { enabled: !isInsideInputGroup });
|
|
26
23
|
|
|
27
24
|
const InputComponent = isInsideInputGroup ? InputGroupInput : Input;
|
|
28
25
|
|
|
29
|
-
return
|
|
30
|
-
<InputComponent
|
|
31
|
-
{...props}
|
|
32
|
-
{...registeredProps}
|
|
33
|
-
{...controlProps}
|
|
34
|
-
name={name}
|
|
35
|
-
/>
|
|
36
|
-
);
|
|
26
|
+
return <InputComponent {...props} {...registeredProps} {...controlProps} name={name} />;
|
|
37
27
|
}
|
|
38
28
|
|
|
39
29
|
export { FormInput };
|
|
@@ -11,15 +11,9 @@ type FormInputGroupProps = React.ComponentProps<typeof InputGroup>;
|
|
|
11
11
|
function FormInputGroup({ children, ...props }: FormInputGroupProps) {
|
|
12
12
|
const field = React.useContext(FormFieldContext);
|
|
13
13
|
const childArray = React.Children.toArray(children);
|
|
14
|
-
const controlIndex = field?.controlId
|
|
15
|
-
? childArray.findIndex(isFormInputElement)
|
|
16
|
-
: -1;
|
|
14
|
+
const controlIndex = field?.controlId ? childArray.findIndex(isFormInputElement) : -1;
|
|
17
15
|
const controlChildren = childArray.map((child, index) => {
|
|
18
|
-
if (
|
|
19
|
-
index === controlIndex &&
|
|
20
|
-
field?.controlId &&
|
|
21
|
-
isFormInputElement(child)
|
|
22
|
-
) {
|
|
16
|
+
if (index === controlIndex && field?.controlId && isFormInputElement(child)) {
|
|
23
17
|
// A group-level label should focus the first input in the group.
|
|
24
18
|
return React.cloneElement(child, {
|
|
25
19
|
id: field.controlId,
|
|
@@ -36,9 +30,7 @@ function FormInputGroup({ children, ...props }: FormInputGroupProps) {
|
|
|
36
30
|
);
|
|
37
31
|
}
|
|
38
32
|
|
|
39
|
-
function isFormInputElement(
|
|
40
|
-
child: React.ReactNode,
|
|
41
|
-
): child is React.ReactElement<FormInputProps> {
|
|
33
|
+
function isFormInputElement(child: React.ReactNode): child is React.ReactElement<FormInputProps> {
|
|
42
34
|
return React.isValidElement(child) && child.type === FormInput;
|
|
43
35
|
}
|
|
44
36
|
|
|
@@ -12,11 +12,7 @@ import { Switch, type SwitchProps } from './Switch';
|
|
|
12
12
|
|
|
13
13
|
type FormSwitchProps = WithoutAriaInvalid<SwitchProps>;
|
|
14
14
|
|
|
15
|
-
function FormSwitchRoot({
|
|
16
|
-
id: idProp,
|
|
17
|
-
name: nameProp,
|
|
18
|
-
...props
|
|
19
|
-
}: FormSwitchProps) {
|
|
15
|
+
function FormSwitchRoot({ id: idProp, name: nameProp, ...props }: FormSwitchProps) {
|
|
20
16
|
const { control } = useFormMethods();
|
|
21
17
|
const name = useRequiredFieldName(nameProp, 'Form.Switch');
|
|
22
18
|
const { field } = useController({
|
|
@@ -10,23 +10,15 @@ import {
|
|
|
10
10
|
} from './Form.context';
|
|
11
11
|
import { Textarea } from './Textarea';
|
|
12
12
|
|
|
13
|
-
type FormTextareaProps = WithoutAriaInvalid<
|
|
14
|
-
React.ComponentProps<typeof Textarea>
|
|
15
|
-
>;
|
|
13
|
+
type FormTextareaProps = WithoutAriaInvalid<React.ComponentProps<typeof Textarea>>;
|
|
16
14
|
|
|
17
|
-
function FormTextarea({
|
|
18
|
-
id: idProp,
|
|
19
|
-
name: nameProp,
|
|
20
|
-
...props
|
|
21
|
-
}: FormTextareaProps) {
|
|
15
|
+
function FormTextarea({ id: idProp, name: nameProp, ...props }: FormTextareaProps) {
|
|
22
16
|
const name = useRequiredFieldName(nameProp, 'Form.Textarea');
|
|
23
17
|
const methods = useFormMethods();
|
|
24
18
|
const registeredProps = methods.register(name);
|
|
25
19
|
const controlProps = useFormControlProps({ id: idProp });
|
|
26
20
|
|
|
27
|
-
return
|
|
28
|
-
<Textarea {...props} {...registeredProps} {...controlProps} name={name} />
|
|
29
|
-
);
|
|
21
|
+
return <Textarea {...props} {...registeredProps} {...controlProps} name={name} />;
|
|
30
22
|
}
|
|
31
23
|
|
|
32
24
|
export { FormTextarea };
|
|
@@ -69,11 +69,7 @@ function InputSizeCell({ column }: ComponentMatrixCellProps) {
|
|
|
69
69
|
|
|
70
70
|
return (
|
|
71
71
|
<XStack className="w-full gap-2">
|
|
72
|
-
<Input
|
|
73
|
-
aria-label={`${column.label} email`}
|
|
74
|
-
placeholder="Email"
|
|
75
|
-
size={size}
|
|
76
|
-
/>
|
|
72
|
+
<Input aria-label={`${column.label} email`} placeholder="Email" size={size} />
|
|
77
73
|
<Button size={size} variant="outline">
|
|
78
74
|
Subscribe
|
|
79
75
|
</Button>
|
|
@@ -8,40 +8,29 @@ const heightClasses = (element: Element) =>
|
|
|
8
8
|
[...element.classList].filter((name) => /^(sm:)?h-/.test(name)).sort();
|
|
9
9
|
|
|
10
10
|
describe('Input', () => {
|
|
11
|
-
it.each(['sm', 'md', 'lg'] as const)(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
).getByRole('textbox', { name: 'Name' });
|
|
24
|
-
const button = screen.getByRole('button', { name: 'Submit' });
|
|
11
|
+
it.each(['sm', 'md', 'lg'] as const)('matches the Button height at size %s', (size) => {
|
|
12
|
+
const { container } = render(
|
|
13
|
+
<>
|
|
14
|
+
<Input aria-label="Email" size={size} />
|
|
15
|
+
<Button size={size}>Submit</Button>
|
|
16
|
+
</>,
|
|
17
|
+
);
|
|
18
|
+
const control = container.querySelector('[data-slot="input-control"]')!;
|
|
19
|
+
const unstyled = render(<Input aria-label="Name" size={size} unstyled />).getByRole('textbox', {
|
|
20
|
+
name: 'Name',
|
|
21
|
+
});
|
|
22
|
+
const button = screen.getByRole('button', { name: 'Submit' });
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
);
|
|
24
|
+
expect(heightClasses(control)).toEqual(heightClasses(button));
|
|
25
|
+
expect(heightClasses(unstyled)).toEqual(heightClasses(button));
|
|
26
|
+
});
|
|
30
27
|
|
|
31
28
|
it('styles the control wrapper with className and the input with classNames.input', () => {
|
|
32
29
|
const { container } = render(
|
|
33
|
-
<Input
|
|
34
|
-
aria-label="Email"
|
|
35
|
-
className="control-x"
|
|
36
|
-
classNames={{ input: 'input-x' }}
|
|
37
|
-
/>,
|
|
38
|
-
);
|
|
39
|
-
expect(container.querySelector('[data-slot="input-control"]')).toHaveClass(
|
|
40
|
-
'control-x',
|
|
41
|
-
);
|
|
42
|
-
expect(screen.getByRole('textbox', { name: 'Email' })).toHaveClass(
|
|
43
|
-
'input-x',
|
|
30
|
+
<Input aria-label="Email" className="control-x" classNames={{ input: 'input-x' }} />,
|
|
44
31
|
);
|
|
32
|
+
expect(container.querySelector('[data-slot="input-control"]')).toHaveClass('control-x');
|
|
33
|
+
expect(screen.getByRole('textbox', { name: 'Email' })).toHaveClass('input-x');
|
|
45
34
|
});
|
|
46
35
|
|
|
47
36
|
it('exposes the resolved size on the control wrapper', () => {
|
|
@@ -54,8 +43,8 @@ describe('Input', () => {
|
|
|
54
43
|
);
|
|
55
44
|
|
|
56
45
|
expect(
|
|
57
|
-
[...container.querySelectorAll('[data-slot="input-control"]')].map(
|
|
58
|
-
|
|
46
|
+
[...container.querySelectorAll('[data-slot="input-control"]')].map((control) =>
|
|
47
|
+
control.getAttribute('data-size'),
|
|
59
48
|
),
|
|
60
49
|
).toEqual(['md', 'sm', 'md']);
|
|
61
50
|
});
|
|
@@ -12,10 +12,7 @@ const inputControlHeights = {
|
|
|
12
12
|
sm: 'h-7',
|
|
13
13
|
} as const;
|
|
14
14
|
|
|
15
|
-
type InputProps = Omit<
|
|
16
|
-
InputPrimitive.Props & React.RefAttributes<HTMLInputElement>,
|
|
17
|
-
'size'
|
|
18
|
-
> & {
|
|
15
|
+
type InputProps = Omit<InputPrimitive.Props & React.RefAttributes<HTMLInputElement>, 'size'> & {
|
|
19
16
|
/** Class overrides for the inner `input`; `className` styles the control wrapper. */
|
|
20
17
|
classNames?: SlotClassNames<'input'>;
|
|
21
18
|
nativeInput?: boolean;
|
|
@@ -59,12 +59,7 @@ function InputGroupMatrixCell({ column, row }: ComponentMatrixCellProps) {
|
|
|
59
59
|
<InputGroup.Addon>
|
|
60
60
|
<IconSearch aria-hidden size={16} />
|
|
61
61
|
</InputGroup.Addon>
|
|
62
|
-
<InputGroup.Input
|
|
63
|
-
aria-label="Search"
|
|
64
|
-
placeholder="Search…"
|
|
65
|
-
type="search"
|
|
66
|
-
{...inputProps}
|
|
67
|
-
/>
|
|
62
|
+
<InputGroup.Input aria-label="Search" placeholder="Search…" type="search" {...inputProps} />
|
|
68
63
|
</InputGroup>
|
|
69
64
|
);
|
|
70
65
|
}
|
|
@@ -82,11 +77,7 @@ function InputGroupMatrixCell({ column, row }: ComponentMatrixCellProps) {
|
|
|
82
77
|
return (
|
|
83
78
|
<InputGroup className="w-full max-w-64">
|
|
84
79
|
<InputGroup.Addon>$</InputGroup.Addon>
|
|
85
|
-
<InputGroup.Input
|
|
86
|
-
aria-label="Amount in USD"
|
|
87
|
-
defaultValue="1200"
|
|
88
|
-
{...inputProps}
|
|
89
|
-
/>
|
|
80
|
+
<InputGroup.Input aria-label="Amount in USD" defaultValue="1200" {...inputProps} />
|
|
90
81
|
</InputGroup>
|
|
91
82
|
);
|
|
92
83
|
}
|
|
@@ -107,13 +98,7 @@ function InputGroupMatrixCell({ column, row }: ComponentMatrixCellProps) {
|
|
|
107
98
|
return null;
|
|
108
99
|
}
|
|
109
100
|
|
|
110
|
-
function PasswordInputGroupCell({
|
|
111
|
-
disabled,
|
|
112
|
-
invalid,
|
|
113
|
-
}: {
|
|
114
|
-
disabled?: boolean;
|
|
115
|
-
invalid?: boolean;
|
|
116
|
-
}) {
|
|
101
|
+
function PasswordInputGroupCell({ disabled, invalid }: { disabled?: boolean; invalid?: boolean }) {
|
|
117
102
|
const [showPassword, setShowPassword] = React.useState(false);
|
|
118
103
|
|
|
119
104
|
return (
|
|
@@ -134,11 +119,7 @@ function PasswordInputGroupCell({
|
|
|
134
119
|
type="button"
|
|
135
120
|
variant="ghost"
|
|
136
121
|
>
|
|
137
|
-
{showPassword ?
|
|
138
|
-
<IconEyeOff aria-hidden size={16} />
|
|
139
|
-
) : (
|
|
140
|
-
<IconEye aria-hidden size={16} />
|
|
141
|
-
)}
|
|
122
|
+
{showPassword ? <IconEyeOff aria-hidden size={16} /> : <IconEye aria-hidden size={16} />}
|
|
142
123
|
</Button>
|
|
143
124
|
</InputGroup.Addon>
|
|
144
125
|
</InputGroup>
|
|
@@ -31,8 +31,7 @@ const inputGroupAddonVariants = cva(
|
|
|
31
31
|
type InputGroupAddonProps = React.ComponentProps<'div'> &
|
|
32
32
|
VariantProps<typeof inputGroupAddonVariants>;
|
|
33
33
|
|
|
34
|
-
type InputGroupButtonProps = ButtonProps &
|
|
35
|
-
VariantProps<typeof inputGroupAddonVariants>;
|
|
34
|
+
type InputGroupButtonProps = ButtonProps & VariantProps<typeof inputGroupAddonVariants>;
|
|
36
35
|
|
|
37
36
|
type InputGroupInputProps = InputProps;
|
|
38
37
|
|
|
@@ -40,11 +39,7 @@ type InputGroupProps = React.ComponentProps<'div'>;
|
|
|
40
39
|
|
|
41
40
|
type InputGroupTextProps = React.ComponentProps<'span'>;
|
|
42
41
|
|
|
43
|
-
function InputGroupAddon({
|
|
44
|
-
align = 'inline-start',
|
|
45
|
-
className,
|
|
46
|
-
...props
|
|
47
|
-
}: InputGroupAddonProps) {
|
|
42
|
+
function InputGroupAddon({ align = 'inline-start', className, ...props }: InputGroupAddonProps) {
|
|
48
43
|
return (
|
|
49
44
|
// react-doctor-disable-next-line react-doctor/no-static-element-interactions -- mousedown delegates focus to the grouped input without making the addon itself a separate control
|
|
50
45
|
<div
|
|
@@ -64,9 +59,9 @@ function InputGroupAddon({
|
|
|
64
59
|
event.preventDefault();
|
|
65
60
|
|
|
66
61
|
const parent = event.currentTarget.parentElement;
|
|
67
|
-
const input = parent?.querySelector<
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
const input = parent?.querySelector<HTMLInputElement | HTMLTextAreaElement>(
|
|
63
|
+
'input, textarea',
|
|
64
|
+
);
|
|
70
65
|
|
|
71
66
|
if (input && !parent?.querySelector('input:focus, textarea:focus')) {
|
|
72
67
|
input.focus();
|
|
@@ -22,10 +22,7 @@ describe('RadioGroup', () => {
|
|
|
22
22
|
</RadioGroup>,
|
|
23
23
|
);
|
|
24
24
|
|
|
25
|
-
expect(screen.getByRole('radio', { name: 'Compact' })).toHaveAttribute(
|
|
26
|
-
'data-size',
|
|
27
|
-
'sm',
|
|
28
|
-
);
|
|
25
|
+
expect(screen.getByRole('radio', { name: 'Compact' })).toHaveAttribute('data-size', 'sm');
|
|
29
26
|
});
|
|
30
27
|
|
|
31
28
|
it('selects defaultValue on mount', () => {
|
|
@@ -35,10 +32,7 @@ describe('RadioGroup', () => {
|
|
|
35
32
|
<RadioGroup.Item label="Option B" value="b" />
|
|
36
33
|
</RadioGroup>,
|
|
37
34
|
);
|
|
38
|
-
expect(screen.getByRole('radio', { name: 'Option B' })).toHaveAttribute(
|
|
39
|
-
'aria-checked',
|
|
40
|
-
'true',
|
|
41
|
-
);
|
|
35
|
+
expect(screen.getByRole('radio', { name: 'Option B' })).toHaveAttribute('aria-checked', 'true');
|
|
42
36
|
expect(screen.getByRole('radio', { name: 'Option A' })).toHaveAttribute(
|
|
43
37
|
'aria-checked',
|
|
44
38
|
'false',
|
|
@@ -93,12 +87,12 @@ describe('RadioGroup', () => {
|
|
|
93
87
|
<RadioGroup.Item label="Enabled" value="e" />
|
|
94
88
|
</RadioGroup>,
|
|
95
89
|
);
|
|
96
|
-
expect(
|
|
97
|
-
|
|
98
|
-
)
|
|
99
|
-
expect(
|
|
100
|
-
|
|
101
|
-
)
|
|
90
|
+
expect(screen.getByText('Disabled').closest('[data-slot="radio-label"]')).toHaveClass(
|
|
91
|
+
'text-muted-foreground',
|
|
92
|
+
);
|
|
93
|
+
expect(screen.getByText('Enabled').closest('[data-slot="radio-label"]')).not.toHaveClass(
|
|
94
|
+
'text-muted-foreground',
|
|
95
|
+
);
|
|
102
96
|
});
|
|
103
97
|
|
|
104
98
|
it('supports arrow-key roving focus between items', () => {
|
|
@@ -115,10 +109,7 @@ describe('RadioGroup', () => {
|
|
|
115
109
|
expect(radioA).toHaveAttribute('aria-checked', 'true');
|
|
116
110
|
// Arrow-key roving focus is browser behavior jsdom lacks, so click.
|
|
117
111
|
fireEvent.click(screen.getByRole('radio', { name: 'Option C' }));
|
|
118
|
-
expect(screen.getByRole('radio', { name: 'Option C' })).toHaveAttribute(
|
|
119
|
-
'aria-checked',
|
|
120
|
-
'true',
|
|
121
|
-
);
|
|
112
|
+
expect(screen.getByRole('radio', { name: 'Option C' })).toHaveAttribute('aria-checked', 'true');
|
|
122
113
|
expect(radioA).toHaveAttribute('aria-checked', 'false');
|
|
123
114
|
});
|
|
124
115
|
|
|
@@ -143,10 +134,7 @@ describe('RadioGroup', () => {
|
|
|
143
134
|
</RadioGroup.Item.Label>
|
|
144
135
|
</RadioGroup>,
|
|
145
136
|
);
|
|
146
|
-
expect(screen.getByText('Custom label')).toHaveAttribute(
|
|
147
|
-
'data-slot',
|
|
148
|
-
'radio-label',
|
|
149
|
-
);
|
|
137
|
+
expect(screen.getByText('Custom label')).toHaveAttribute('data-slot', 'radio-label');
|
|
150
138
|
});
|
|
151
139
|
|
|
152
140
|
it('applies classNames to the indicator and label slots', () => {
|
|
@@ -159,11 +147,9 @@ describe('RadioGroup', () => {
|
|
|
159
147
|
/>
|
|
160
148
|
</RadioGroup>,
|
|
161
149
|
);
|
|
162
|
-
expect(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
screen.getByText('Option A').closest('[data-slot="radio-label"]'),
|
|
167
|
-
).toHaveClass('label-x');
|
|
150
|
+
expect(container.querySelector('[data-slot="radio-indicator"]')).toHaveClass('indicator-x');
|
|
151
|
+
expect(screen.getByText('Option A').closest('[data-slot="radio-label"]')).toHaveClass(
|
|
152
|
+
'label-x',
|
|
153
|
+
);
|
|
168
154
|
});
|
|
169
155
|
});
|
|
@@ -39,11 +39,7 @@ function RadioGroupItem({
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
return (
|
|
42
|
-
<RadioGroupItemLabel
|
|
43
|
-
className={classNames?.label}
|
|
44
|
-
disabled={disabled}
|
|
45
|
-
id={generatedLabelId}
|
|
46
|
-
>
|
|
42
|
+
<RadioGroupItemLabel className={classNames?.label} disabled={disabled} id={generatedLabelId}>
|
|
47
43
|
<RadioGroupItemControl
|
|
48
44
|
aria-labelledby={generatedLabelId}
|
|
49
45
|
className={className}
|
|
@@ -59,19 +59,11 @@ function SelectMatrixCell({ column }: ComponentMatrixCellProps) {
|
|
|
59
59
|
return <ThemeSelect {...STATE_PROPS[column.key]} />;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
function ThemeSelect({
|
|
63
|
-
disabled,
|
|
64
|
-
invalid,
|
|
65
|
-
triggerClassName,
|
|
66
|
-
value,
|
|
67
|
-
}: ThemeSelectStateProps) {
|
|
62
|
+
function ThemeSelect({ disabled, invalid, triggerClassName, value }: ThemeSelectStateProps) {
|
|
68
63
|
return (
|
|
69
64
|
<Select defaultValue={value} disabled={disabled}>
|
|
70
65
|
<Select.Label className="sr-only">Theme</Select.Label>
|
|
71
|
-
<Select.Trigger
|
|
72
|
-
aria-invalid={invalid || undefined}
|
|
73
|
-
className={cn('w-44', triggerClassName)}
|
|
74
|
-
>
|
|
66
|
+
<Select.Trigger aria-invalid={invalid || undefined} className={cn('w-44', triggerClassName)}>
|
|
75
67
|
<Select.Value placeholder="Theme" />
|
|
76
68
|
</Select.Trigger>
|
|
77
69
|
<Select.Content>
|
|
@@ -50,9 +50,7 @@ describe('Select', () => {
|
|
|
50
50
|
);
|
|
51
51
|
|
|
52
52
|
expect(screen.getByRole('combobox')).toHaveAttribute('data-popup-open');
|
|
53
|
-
expect(screen.getByRole('combobox')).toHaveClass(
|
|
54
|
-
'data-popup-open:border-ring/50',
|
|
55
|
-
);
|
|
53
|
+
expect(screen.getByRole('combobox')).toHaveClass('data-popup-open:border-ring/50');
|
|
56
54
|
});
|
|
57
55
|
|
|
58
56
|
it('labels the trigger with Select.Label', () => {
|
|
@@ -69,10 +67,7 @@ describe('Select', () => {
|
|
|
69
67
|
);
|
|
70
68
|
|
|
71
69
|
expect(screen.getByRole('combobox', { name: 'Role' })).toBeInTheDocument();
|
|
72
|
-
expect(screen.getByText('Role')).toHaveAttribute(
|
|
73
|
-
'data-slot',
|
|
74
|
-
'select-label',
|
|
75
|
-
);
|
|
70
|
+
expect(screen.getByText('Role')).toHaveAttribute('data-slot', 'select-label');
|
|
76
71
|
});
|
|
77
72
|
|
|
78
73
|
it('renders group labels separately from Select.Label', () => {
|
|
@@ -90,10 +85,7 @@ describe('Select', () => {
|
|
|
90
85
|
</Select>,
|
|
91
86
|
);
|
|
92
87
|
|
|
93
|
-
expect(screen.getByText('Appearance')).toHaveAttribute(
|
|
94
|
-
'data-slot',
|
|
95
|
-
'select-group-label',
|
|
96
|
-
);
|
|
88
|
+
expect(screen.getByText('Appearance')).toHaveAttribute('data-slot', 'select-group-label');
|
|
97
89
|
expect(screen.getByRole('combobox')).toHaveTextContent('Light');
|
|
98
90
|
});
|
|
99
91
|
|
|
@@ -108,8 +100,6 @@ describe('Select', () => {
|
|
|
108
100
|
</Select.Content>
|
|
109
101
|
</Select>,
|
|
110
102
|
);
|
|
111
|
-
expect(
|
|
112
|
-
container.querySelector('[data-slot="select-trigger-icon"]'),
|
|
113
|
-
).toHaveClass('icon-x');
|
|
103
|
+
expect(container.querySelector('[data-slot="select-trigger-icon"]')).toHaveClass('icon-x');
|
|
114
104
|
});
|
|
115
105
|
});
|