@pickle-ui/react-native 1.0.0-beta.0 → 1.0.0-beta.2
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 +70 -11
- package/dist/components/Badge.d.ts +6 -3
- package/dist/components/Badge.d.ts.map +1 -1
- package/dist/components/Badge.js +36 -7
- package/dist/components/Badge.js.map +1 -1
- package/dist/components/Button.d.ts +11 -4
- package/dist/components/Button.d.ts.map +1 -1
- package/dist/components/Button.js +100 -15
- package/dist/components/Button.js.map +1 -1
- package/dist/components/Card.d.ts +15 -5
- package/dist/components/Card.d.ts.map +1 -1
- package/dist/components/Card.js +28 -10
- package/dist/components/Card.js.map +1 -1
- package/dist/components/Flex.d.ts +25 -0
- package/dist/components/Flex.d.ts.map +1 -0
- package/dist/components/Flex.js +24 -0
- package/dist/components/Flex.js.map +1 -0
- package/dist/components/Grid.d.ts +36 -0
- package/dist/components/Grid.d.ts.map +1 -0
- package/dist/components/Grid.js +68 -0
- package/dist/components/Grid.js.map +1 -0
- package/dist/components/Separator.d.ts +11 -0
- package/dist/components/Separator.d.ts.map +1 -0
- package/dist/components/Separator.js +12 -0
- package/dist/components/Separator.js.map +1 -0
- package/dist/components/Spinner.d.ts +14 -0
- package/dist/components/Spinner.d.ts.map +1 -0
- package/dist/components/Spinner.js +41 -0
- package/dist/components/Spinner.js.map +1 -0
- package/dist/components/Text.d.ts +7 -3
- package/dist/components/Text.d.ts.map +1 -1
- package/dist/components/Text.js +23 -11
- package/dist/components/Text.js.map +1 -1
- package/dist/components/XStack.d.ts +4 -0
- package/dist/components/XStack.d.ts.map +1 -0
- package/dist/components/XStack.js +6 -0
- package/dist/components/XStack.js.map +1 -0
- package/dist/components/YStack.d.ts +4 -0
- package/dist/components/YStack.d.ts.map +1 -0
- package/dist/components/YStack.js +6 -0
- package/dist/components/YStack.js.map +1 -0
- package/dist/components/_internal/InputFrame.d.ts +13 -0
- package/dist/components/_internal/InputFrame.d.ts.map +1 -0
- package/dist/components/_internal/InputFrame.js +14 -0
- package/dist/components/_internal/InputFrame.js.map +1 -0
- package/dist/components/_internal/StoryItem.d.ts +6 -0
- package/dist/components/_internal/StoryItem.d.ts.map +1 -0
- package/dist/components/_internal/StoryItem.js +9 -0
- package/dist/components/_internal/StoryItem.js.map +1 -0
- package/dist/components/_internal/layout.d.ts +79 -0
- package/dist/components/_internal/layout.d.ts.map +1 -0
- package/dist/components/_internal/layout.js +73 -0
- package/dist/components/_internal/layout.js.map +1 -0
- package/dist/components/_internal/useControllableState.d.ts +7 -0
- package/dist/components/_internal/useControllableState.d.ts.map +1 -0
- package/dist/components/_internal/useControllableState.js +17 -0
- package/dist/components/_internal/useControllableState.js.map +1 -0
- package/dist/components/form/Checkbox.d.ts +26 -0
- package/dist/components/form/Checkbox.d.ts.map +1 -0
- package/dist/components/form/Checkbox.js +41 -0
- package/dist/components/form/Checkbox.js.map +1 -0
- package/dist/components/form/Form.context.d.ts +34 -0
- package/dist/components/form/Form.context.d.ts.map +1 -0
- package/dist/components/form/Form.context.js +53 -0
- package/dist/components/form/Form.context.js.map +1 -0
- package/dist/components/form/Form.d.ts +33 -0
- package/dist/components/form/Form.d.ts.map +1 -0
- package/dist/components/form/Form.js +36 -0
- package/dist/components/form/Form.js.map +1 -0
- package/dist/components/form/FormCheckbox.d.ts +7 -0
- package/dist/components/form/FormCheckbox.d.ts.map +1 -0
- package/dist/components/form/FormCheckbox.js +24 -0
- package/dist/components/form/FormCheckbox.js.map +1 -0
- package/dist/components/form/FormDescription.d.ts +4 -0
- package/dist/components/form/FormDescription.d.ts.map +1 -0
- package/dist/components/form/FormDescription.js +7 -0
- package/dist/components/form/FormDescription.js.map +1 -0
- package/dist/components/form/FormError.d.ts +5 -0
- package/dist/components/form/FormError.d.ts.map +1 -0
- package/dist/components/form/FormError.js +8 -0
- package/dist/components/form/FormError.js.map +1 -0
- package/dist/components/form/FormField.d.ts +17 -0
- package/dist/components/form/FormField.d.ts.map +1 -0
- package/dist/components/form/FormField.js +36 -0
- package/dist/components/form/FormField.js.map +1 -0
- package/dist/components/form/FormInput.d.ts +10 -0
- package/dist/components/form/FormInput.d.ts.map +1 -0
- package/dist/components/form/FormInput.js +36 -0
- package/dist/components/form/FormInput.js.map +1 -0
- package/dist/components/form/FormInputGroup.d.ts +8 -0
- package/dist/components/form/FormInputGroup.d.ts.map +1 -0
- package/dist/components/form/FormInputGroup.js +18 -0
- package/dist/components/form/FormInputGroup.js.map +1 -0
- package/dist/components/form/FormLabel.d.ts +4 -0
- package/dist/components/form/FormLabel.d.ts.map +1 -0
- package/dist/components/form/FormLabel.js +7 -0
- package/dist/components/form/FormLabel.js.map +1 -0
- package/dist/components/form/FormRadioGroup.d.ts +11 -0
- package/dist/components/form/FormRadioGroup.d.ts.map +1 -0
- package/dist/components/form/FormRadioGroup.js +24 -0
- package/dist/components/form/FormRadioGroup.js.map +1 -0
- package/dist/components/form/FormRoot.d.ts +13 -0
- package/dist/components/form/FormRoot.d.ts.map +1 -0
- package/dist/components/form/FormRoot.js +19 -0
- package/dist/components/form/FormRoot.js.map +1 -0
- package/dist/components/form/FormTextarea.d.ts +7 -0
- package/dist/components/form/FormTextarea.d.ts.map +1 -0
- package/dist/components/form/FormTextarea.js +27 -0
- package/dist/components/form/FormTextarea.js.map +1 -0
- package/dist/components/form/Input.d.ts +17 -0
- package/dist/components/form/Input.d.ts.map +1 -0
- package/dist/components/form/Input.js +32 -0
- package/dist/components/form/Input.js.map +1 -0
- package/dist/components/form/InputGroup.context.d.ts +10 -0
- package/dist/components/form/InputGroup.context.d.ts.map +1 -0
- package/dist/components/form/InputGroup.context.js +8 -0
- package/dist/components/form/InputGroup.context.js.map +1 -0
- package/dist/components/form/InputGroup.d.ts +31 -0
- package/dist/components/form/InputGroup.d.ts.map +1 -0
- package/dist/components/form/InputGroup.js +123 -0
- package/dist/components/form/InputGroup.js.map +1 -0
- package/dist/components/form/RadioGroup.d.ts +29 -0
- package/dist/components/form/RadioGroup.d.ts.map +1 -0
- package/dist/components/form/RadioGroup.js +42 -0
- package/dist/components/form/RadioGroup.js.map +1 -0
- package/dist/components/form/Textarea.d.ts +19 -0
- package/dist/components/form/Textarea.d.ts.map +1 -0
- package/dist/components/form/Textarea.js +26 -0
- package/dist/components/form/Textarea.js.map +1 -0
- package/dist/entries/card.d.ts +1 -1
- package/dist/entries/card.d.ts.map +1 -1
- package/dist/entries/checkbox.d.ts +3 -0
- package/dist/entries/checkbox.d.ts.map +1 -0
- package/dist/entries/checkbox.js +2 -0
- package/dist/entries/checkbox.js.map +1 -0
- package/dist/entries/flex.d.ts +3 -0
- package/dist/entries/flex.d.ts.map +1 -0
- package/dist/entries/flex.js +2 -0
- package/dist/entries/flex.js.map +1 -0
- package/dist/entries/form.d.ts +3 -0
- package/dist/entries/form.d.ts.map +1 -0
- package/dist/entries/form.js +2 -0
- package/dist/entries/form.js.map +1 -0
- package/dist/entries/grid.d.ts +3 -0
- package/dist/entries/grid.d.ts.map +1 -0
- package/dist/entries/grid.js +2 -0
- package/dist/entries/grid.js.map +1 -0
- package/dist/entries/input-group.d.ts +3 -0
- package/dist/entries/input-group.d.ts.map +1 -0
- package/dist/entries/input-group.js +2 -0
- package/dist/entries/input-group.js.map +1 -0
- package/dist/entries/input.d.ts +3 -0
- package/dist/entries/input.d.ts.map +1 -0
- package/dist/entries/input.js +2 -0
- package/dist/entries/input.js.map +1 -0
- package/dist/entries/radio-group.d.ts +3 -0
- package/dist/entries/radio-group.d.ts.map +1 -0
- package/dist/entries/radio-group.js +2 -0
- package/dist/entries/radio-group.js.map +1 -0
- package/dist/entries/separator.d.ts +3 -0
- package/dist/entries/separator.d.ts.map +1 -0
- package/dist/entries/separator.js +2 -0
- package/dist/entries/separator.js.map +1 -0
- package/dist/entries/spinner.d.ts +3 -0
- package/dist/entries/spinner.d.ts.map +1 -0
- package/dist/entries/spinner.js +2 -0
- package/dist/entries/spinner.js.map +1 -0
- package/dist/entries/textarea.d.ts +3 -0
- package/dist/entries/textarea.d.ts.map +1 -0
- package/dist/entries/textarea.js +2 -0
- package/dist/entries/textarea.js.map +1 -0
- package/dist/entries/theme.d.ts +3 -0
- package/dist/entries/theme.d.ts.map +1 -0
- package/dist/entries/theme.js +2 -0
- package/dist/entries/theme.js.map +1 -0
- package/dist/entries/x-stack.d.ts +3 -0
- package/dist/entries/x-stack.d.ts.map +1 -0
- package/dist/entries/x-stack.js +2 -0
- package/dist/entries/x-stack.js.map +1 -0
- package/dist/entries/y-stack.d.ts +3 -0
- package/dist/entries/y-stack.d.ts.map +1 -0
- package/dist/entries/y-stack.js +2 -0
- package/dist/entries/y-stack.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/cn.d.ts.map +1 -1
- package/dist/lib/cn.js +13 -1
- package/dist/lib/cn.js.map +1 -1
- package/package.json +10 -3
- package/src/base.css +7 -2
- package/src/components/Badge.stories.tsx +51 -6
- package/src/components/Badge.test.tsx +15 -0
- package/src/components/Badge.tsx +73 -17
- package/src/components/Button.stories.tsx +96 -8
- package/src/components/Button.test.tsx +69 -0
- package/src/components/Button.tsx +159 -18
- package/src/components/Card.stories.tsx +17 -4
- package/src/components/Card.test.tsx +24 -1
- package/src/components/Card.tsx +71 -13
- package/src/components/Flex.stories.tsx +58 -0
- package/src/components/Flex.test.tsx +57 -0
- package/src/components/Flex.tsx +52 -0
- package/src/components/Grid.stories.tsx +55 -0
- package/src/components/Grid.test.tsx +140 -0
- package/src/components/Grid.tsx +166 -0
- package/src/components/Separator.stories.tsx +39 -0
- package/src/components/Separator.test.tsx +25 -0
- package/src/components/Separator.tsx +30 -0
- package/src/components/Spinner.stories.tsx +35 -0
- package/src/components/Spinner.test.tsx +30 -0
- package/src/components/Spinner.tsx +75 -0
- package/src/components/Text.stories.tsx +52 -2
- package/src/components/Text.test.tsx +35 -3
- package/src/components/Text.tsx +42 -12
- package/src/components/XStack.stories.tsx +46 -0
- package/src/components/XStack.test.tsx +13 -0
- package/src/components/XStack.tsx +7 -0
- package/src/components/YStack.stories.tsx +46 -0
- package/src/components/YStack.test.tsx +13 -0
- package/src/components/YStack.tsx +7 -0
- package/src/components/_internal/InputFrame.tsx +50 -0
- package/src/components/_internal/Story.tsx +34 -0
- package/src/components/_internal/StoryItem.tsx +24 -0
- package/src/components/_internal/layout.ts +103 -0
- package/src/components/_internal/useControllableState.ts +25 -0
- package/src/components/form/Checkbox.stories.tsx +67 -0
- package/src/components/form/Checkbox.test.tsx +88 -0
- package/src/components/form/Checkbox.tsx +141 -0
- package/src/components/form/Form.context.ts +91 -0
- package/src/components/form/Form.stories.tsx +152 -0
- package/src/components/form/Form.test.tsx +195 -0
- package/src/components/form/Form.tsx +51 -0
- package/src/components/form/FormCheckbox.tsx +42 -0
- package/src/components/form/FormDescription.tsx +14 -0
- package/src/components/form/FormError.tsx +17 -0
- package/src/components/form/FormField.tsx +82 -0
- package/src/components/form/FormInput.tsx +70 -0
- package/src/components/form/FormInputGroup.tsx +30 -0
- package/src/components/form/FormLabel.tsx +17 -0
- package/src/components/form/FormRadioGroup.tsx +48 -0
- package/src/components/form/FormRoot.tsx +41 -0
- package/src/components/form/FormTextarea.tsx +56 -0
- package/src/components/form/Input.stories.tsx +105 -0
- package/src/components/form/Input.test.tsx +76 -0
- package/src/components/form/Input.tsx +81 -0
- package/src/components/form/InputGroup.context.ts +11 -0
- package/src/components/form/InputGroup.stories.tsx +129 -0
- package/src/components/form/InputGroup.test.tsx +95 -0
- package/src/components/form/InputGroup.tsx +266 -0
- package/src/components/form/RadioGroup.stories.tsx +62 -0
- package/src/components/form/RadioGroup.test.tsx +98 -0
- package/src/components/form/RadioGroup.tsx +151 -0
- package/src/components/form/Textarea.stories.tsx +61 -0
- package/src/components/form/Textarea.test.tsx +35 -0
- package/src/components/form/Textarea.tsx +74 -0
- package/src/entries/card.ts +2 -0
- package/src/entries/checkbox.ts +2 -0
- package/src/entries/flex.ts +2 -0
- package/src/entries/form.ts +13 -0
- package/src/entries/grid.ts +2 -0
- package/src/entries/input-group.ts +8 -0
- package/src/entries/input.ts +2 -0
- package/src/entries/radio-group.ts +5 -0
- package/src/entries/separator.ts +2 -0
- package/src/entries/spinner.ts +2 -0
- package/src/entries/textarea.ts +2 -0
- package/src/entries/theme.ts +7 -0
- package/src/entries/x-stack.ts +2 -0
- package/src/entries/y-stack.ts +2 -0
- package/src/index.ts +13 -0
- package/src/lib/cn.test.ts +6 -0
- package/src/lib/cn.ts +14 -1
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { createContext, use, useMemo } from 'react';
|
|
2
|
+
import { Pressable, Text, View } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { cn } from '../../lib/cn';
|
|
5
|
+
import { useControllableState } from '../_internal/useControllableState';
|
|
6
|
+
|
|
7
|
+
// Same sizes as `RadioGroup` in @pickle-ui/react. `hitSlop` stretches the
|
|
8
|
+
// circle to a 44pt touch target, vertically only when a label widens it.
|
|
9
|
+
const controlClasses = { md: 'size-4', sm: 'size-3.5' } as const;
|
|
10
|
+
const indicatorClasses = { md: 'size-2', sm: 'size-1.5' } as const;
|
|
11
|
+
const controlHitSlop = { md: 14, sm: 15 } as const;
|
|
12
|
+
const fieldHitSlop = {
|
|
13
|
+
md: { bottom: 14, top: 14 },
|
|
14
|
+
sm: { bottom: 15, top: 15 },
|
|
15
|
+
} as const;
|
|
16
|
+
|
|
17
|
+
type RadioGroupContextValue = {
|
|
18
|
+
disabled: boolean;
|
|
19
|
+
onSelect: (value: string) => void;
|
|
20
|
+
value: string | undefined;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const RadioGroupContext = createContext<null | RadioGroupContextValue>(null);
|
|
24
|
+
|
|
25
|
+
export type RadioGroupItemProps = Omit<
|
|
26
|
+
React.ComponentProps<typeof Pressable>,
|
|
27
|
+
'children' | 'disabled'
|
|
28
|
+
> & {
|
|
29
|
+
/** Class overrides for the row around the circle and label, the dot and the label. */
|
|
30
|
+
classNames?: { field?: string; indicator?: string; label?: string };
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
/** Marks the choice as invalid, like the web's `aria-invalid`. */
|
|
33
|
+
invalid?: boolean;
|
|
34
|
+
/** Text next to the circle; pressing it selects the item and names it. */
|
|
35
|
+
label?: React.ReactNode;
|
|
36
|
+
size?: 'md' | 'sm';
|
|
37
|
+
value: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type RadioGroupProps = React.ComponentProps<typeof View> & {
|
|
41
|
+
defaultValue?: string;
|
|
42
|
+
disabled?: boolean;
|
|
43
|
+
onValueChange?: (value: string) => void;
|
|
44
|
+
value?: string;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
function RadioGroupItem({
|
|
48
|
+
accessibilityState,
|
|
49
|
+
className,
|
|
50
|
+
classNames,
|
|
51
|
+
disabled: disabledProp = false,
|
|
52
|
+
invalid = false,
|
|
53
|
+
label,
|
|
54
|
+
size = 'md',
|
|
55
|
+
value,
|
|
56
|
+
...props
|
|
57
|
+
}: RadioGroupItemProps) {
|
|
58
|
+
const group = use(RadioGroupContext);
|
|
59
|
+
if (!group) throw new Error('RadioGroup.Item must be inside a RadioGroup.');
|
|
60
|
+
|
|
61
|
+
const checked = group.value === value;
|
|
62
|
+
const disabled = group.disabled || disabledProp;
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<Pressable
|
|
66
|
+
accessibilityState={{ ...accessibilityState, checked, disabled }}
|
|
67
|
+
aria-checked={checked}
|
|
68
|
+
aria-disabled={disabled}
|
|
69
|
+
className={
|
|
70
|
+
label
|
|
71
|
+
? cn('flex-row items-center gap-2', classNames?.field)
|
|
72
|
+
: 'self-start'
|
|
73
|
+
}
|
|
74
|
+
disabled={disabled}
|
|
75
|
+
hitSlop={label ? fieldHitSlop[size] : controlHitSlop[size]}
|
|
76
|
+
onPress={() => group.onSelect(value)}
|
|
77
|
+
role="radio"
|
|
78
|
+
{...props}
|
|
79
|
+
>
|
|
80
|
+
<View
|
|
81
|
+
className={cn(
|
|
82
|
+
'border-input bg-background items-center justify-center rounded-full border',
|
|
83
|
+
controlClasses[size],
|
|
84
|
+
checked && 'border-primary',
|
|
85
|
+
invalid && 'border-destructive',
|
|
86
|
+
disabled && 'opacity-50',
|
|
87
|
+
className,
|
|
88
|
+
)}
|
|
89
|
+
>
|
|
90
|
+
{checked ? (
|
|
91
|
+
<View
|
|
92
|
+
className={cn(
|
|
93
|
+
'bg-primary rounded-full',
|
|
94
|
+
indicatorClasses[size],
|
|
95
|
+
classNames?.indicator,
|
|
96
|
+
)}
|
|
97
|
+
/>
|
|
98
|
+
) : null}
|
|
99
|
+
</View>
|
|
100
|
+
{label ? (
|
|
101
|
+
<Text
|
|
102
|
+
className={cn(
|
|
103
|
+
'text-sm leading-none font-medium',
|
|
104
|
+
disabled ? 'text-muted-foreground' : 'text-foreground',
|
|
105
|
+
classNames?.label,
|
|
106
|
+
)}
|
|
107
|
+
>
|
|
108
|
+
{label}
|
|
109
|
+
</Text>
|
|
110
|
+
) : null}
|
|
111
|
+
</Pressable>
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function RadioGroupRoot({
|
|
116
|
+
className,
|
|
117
|
+
defaultValue,
|
|
118
|
+
disabled = false,
|
|
119
|
+
onValueChange,
|
|
120
|
+
value: valueProp,
|
|
121
|
+
...props
|
|
122
|
+
}: RadioGroupProps) {
|
|
123
|
+
const [value, setValue] = useControllableState(
|
|
124
|
+
valueProp,
|
|
125
|
+
defaultValue,
|
|
126
|
+
onValueChange as ((value: string | undefined) => void) | undefined,
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const context = useMemo(
|
|
130
|
+
() => ({
|
|
131
|
+
disabled,
|
|
132
|
+
onSelect: (next: string) => {
|
|
133
|
+
if (next !== value) setValue(next);
|
|
134
|
+
},
|
|
135
|
+
value,
|
|
136
|
+
}),
|
|
137
|
+
[disabled, setValue, value],
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<RadioGroupContext value={context}>
|
|
142
|
+
<View className={cn('gap-2', className)} role="radiogroup" {...props} />
|
|
143
|
+
</RadioGroupContext>
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const RadioGroup = Object.assign(RadioGroupRoot, {
|
|
148
|
+
Item: RadioGroupItem,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
export { RadioGroup, RadioGroupItem };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-native-web-vite';
|
|
2
|
+
|
|
3
|
+
import { type ComponentMatrixCellProps, Story } from '../_internal/Story';
|
|
4
|
+
import { Textarea, type TextareaProps } from './Textarea';
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
component: Textarea,
|
|
8
|
+
parameters: { layout: 'fullscreen' },
|
|
9
|
+
title: 'components/form/Textarea',
|
|
10
|
+
} satisfies Meta<typeof Textarea>;
|
|
11
|
+
|
|
12
|
+
export default meta;
|
|
13
|
+
type StoryDefinition = StoryObj<typeof meta>;
|
|
14
|
+
|
|
15
|
+
// No focus column: React Native can't force a focus state. Tap a field.
|
|
16
|
+
const STATE_COLUMNS = [
|
|
17
|
+
{ key: 'empty', label: 'Empty' },
|
|
18
|
+
{ key: 'filled', label: 'Filled' },
|
|
19
|
+
{ key: 'disabled', label: 'Disabled' },
|
|
20
|
+
{ key: 'invalid', label: 'Invalid' },
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const SIZE_ROWS = [
|
|
24
|
+
{ key: 'sm', label: 'Small' },
|
|
25
|
+
{ key: 'md', label: 'Medium' },
|
|
26
|
+
{ key: 'lg', label: 'Large' },
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
function TextareaMatrixCell({ column, row }: ComponentMatrixCellProps) {
|
|
30
|
+
const isInvalid = column.key === 'invalid';
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<Textarea
|
|
34
|
+
accessibilityLabel={`${row.label} ${column.label}`}
|
|
35
|
+
defaultValue={
|
|
36
|
+
column.key === 'filled'
|
|
37
|
+
? 'Pickle UI grows this field with its content, line after line.'
|
|
38
|
+
: undefined
|
|
39
|
+
}
|
|
40
|
+
disabled={column.key === 'disabled'}
|
|
41
|
+
invalid={isInvalid}
|
|
42
|
+
placeholder={isInvalid ? 'Tell us a bit more' : 'Write a message'}
|
|
43
|
+
size={row.key as NonNullable<TextareaProps['size']>}
|
|
44
|
+
/>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const All: StoryDefinition = {
|
|
49
|
+
render: () => (
|
|
50
|
+
<Story.Layout className="max-w-6xl" title="Textarea">
|
|
51
|
+
<Story.Section title="Sizes and states">
|
|
52
|
+
<Story.Matrix
|
|
53
|
+
Cell={TextareaMatrixCell}
|
|
54
|
+
cellClassName="items-stretch"
|
|
55
|
+
columns={STATE_COLUMNS}
|
|
56
|
+
rows={SIZE_ROWS}
|
|
57
|
+
/>
|
|
58
|
+
</Story.Section>
|
|
59
|
+
</Story.Layout>
|
|
60
|
+
),
|
|
61
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react-native';
|
|
2
|
+
|
|
3
|
+
import { Textarea } from './Textarea';
|
|
4
|
+
|
|
5
|
+
describe('Textarea', () => {
|
|
6
|
+
it('renders a multi-line field', async () => {
|
|
7
|
+
await render(
|
|
8
|
+
<Textarea accessibilityLabel="Message" defaultValue="Hello" />,
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
const field = screen.getByLabelText('Message');
|
|
12
|
+
expect(field).toHaveProp('multiline', true);
|
|
13
|
+
expect(field).toHaveDisplayValue('Hello');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('styles the control with className and the field with classNames.textarea', async () => {
|
|
17
|
+
await render(
|
|
18
|
+
<Textarea
|
|
19
|
+
accessibilityLabel="Message"
|
|
20
|
+
className="control-x"
|
|
21
|
+
classNames={{ textarea: 'textarea-x' }}
|
|
22
|
+
/>,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const field = screen.getByLabelText('Message');
|
|
26
|
+
expect(field).toHaveProp(
|
|
27
|
+
'className',
|
|
28
|
+
expect.stringContaining('textarea-x'),
|
|
29
|
+
);
|
|
30
|
+
expect(field.parent).toHaveProp(
|
|
31
|
+
'className',
|
|
32
|
+
expect.stringContaining('control-x'),
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { TextInput } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { cn } from '../../lib/cn';
|
|
5
|
+
import { InputFrame } from '../_internal/InputFrame';
|
|
6
|
+
|
|
7
|
+
const sizeClasses = {
|
|
8
|
+
lg: 'min-h-18 px-[11px]',
|
|
9
|
+
md: 'min-h-17.5 px-[11px]',
|
|
10
|
+
sm: 'min-h-16 px-[9px]',
|
|
11
|
+
} as const;
|
|
12
|
+
|
|
13
|
+
export type TextareaProps = Omit<
|
|
14
|
+
React.ComponentProps<typeof TextInput>,
|
|
15
|
+
'multiline'
|
|
16
|
+
> & {
|
|
17
|
+
/** Class overrides for the inner `TextInput`; `className` styles the control around it. */
|
|
18
|
+
classNames?: { textarea?: string };
|
|
19
|
+
/** Dims the field and stops editing, like the web's `disabled`. */
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
/** Marks the value as invalid, like the web's `aria-invalid`. */
|
|
22
|
+
invalid?: boolean;
|
|
23
|
+
size?: 'lg' | 'md' | 'sm';
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A multi-line text field that grows with its content from three lines, like
|
|
28
|
+
* `Textarea` in @pickle-ui/react. Set a `min-h-*` class on
|
|
29
|
+
* `classNames.textarea` to change the minimum.
|
|
30
|
+
*/
|
|
31
|
+
export function Textarea({
|
|
32
|
+
className,
|
|
33
|
+
classNames,
|
|
34
|
+
disabled = false,
|
|
35
|
+
editable = true,
|
|
36
|
+
invalid = false,
|
|
37
|
+
onBlur,
|
|
38
|
+
onFocus,
|
|
39
|
+
size = 'md',
|
|
40
|
+
...props
|
|
41
|
+
}: TextareaProps) {
|
|
42
|
+
const [focused, setFocused] = useState(false);
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<InputFrame
|
|
46
|
+
className={className}
|
|
47
|
+
disabled={disabled}
|
|
48
|
+
focused={focused}
|
|
49
|
+
invalid={invalid}
|
|
50
|
+
>
|
|
51
|
+
<TextInput
|
|
52
|
+
accessibilityState={{ disabled }}
|
|
53
|
+
className={cn(
|
|
54
|
+
'text-foreground web:field-sizing-content web:resize-none flex-1 py-2 text-sm outline-none',
|
|
55
|
+
sizeClasses[size],
|
|
56
|
+
classNames?.textarea,
|
|
57
|
+
)}
|
|
58
|
+
editable={editable && !disabled}
|
|
59
|
+
multiline
|
|
60
|
+
onBlur={(event) => {
|
|
61
|
+
setFocused(false);
|
|
62
|
+
onBlur?.(event);
|
|
63
|
+
}}
|
|
64
|
+
onFocus={(event) => {
|
|
65
|
+
setFocused(true);
|
|
66
|
+
onFocus?.(event);
|
|
67
|
+
}}
|
|
68
|
+
placeholderTextColorClassName="accent-muted-foreground/72"
|
|
69
|
+
textAlignVertical="top"
|
|
70
|
+
{...props}
|
|
71
|
+
/>
|
|
72
|
+
</InputFrame>
|
|
73
|
+
);
|
|
74
|
+
}
|
package/src/entries/card.ts
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { Form } from '../components/form/Form';
|
|
2
|
+
export type {
|
|
3
|
+
FormCheckboxProps,
|
|
4
|
+
FormDescriptionProps,
|
|
5
|
+
FormErrorProps,
|
|
6
|
+
FormFieldProps,
|
|
7
|
+
FormInputGroupProps,
|
|
8
|
+
FormInputProps,
|
|
9
|
+
FormLabelProps,
|
|
10
|
+
FormProps,
|
|
11
|
+
FormRadioGroupProps,
|
|
12
|
+
FormTextareaProps,
|
|
13
|
+
} from '../components/form/Form';
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
export * from './entries/badge';
|
|
4
4
|
export * from './entries/button';
|
|
5
5
|
export * from './entries/card';
|
|
6
|
+
export * from './entries/checkbox';
|
|
6
7
|
export * from './entries/cn';
|
|
8
|
+
export * from './entries/flex';
|
|
9
|
+
export * from './entries/form';
|
|
10
|
+
export * from './entries/grid';
|
|
11
|
+
export * from './entries/input';
|
|
12
|
+
export * from './entries/input-group';
|
|
13
|
+
export * from './entries/radio-group';
|
|
14
|
+
export * from './entries/separator';
|
|
15
|
+
export * from './entries/spinner';
|
|
7
16
|
export * from './entries/text';
|
|
17
|
+
export * from './entries/textarea';
|
|
18
|
+
export * from './entries/theme';
|
|
8
19
|
export * from './entries/use-color-token';
|
|
20
|
+
export * from './entries/x-stack';
|
|
21
|
+
export * from './entries/y-stack';
|
package/src/lib/cn.test.ts
CHANGED
package/src/lib/cn.ts
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { extendTailwindMerge } from 'tailwind-merge';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Teaches tailwind-merge Pickle's type scale: `text-body`, `text-h1`, … are
|
|
5
|
+
* font sizes, so they must not be mistaken for text colors and dropped next
|
|
6
|
+
* to one.
|
|
7
|
+
*/
|
|
8
|
+
const twMerge = extendTailwindMerge({
|
|
9
|
+
extend: {
|
|
10
|
+
theme: {
|
|
11
|
+
text: ['body', 'code', 'h1', 'h2', 'h3', 'h4', 'lead', 'small'],
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
});
|
|
2
15
|
|
|
3
16
|
/** Joins class names; later classes win, like `@pickle-ui/react/cn`. */
|
|
4
17
|
export function cn(...classes: Array<false | null | string | undefined>) {
|