@urbint/cl 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cursor/rules +313 -0
- package/.rnstorybook/index.ts +11 -0
- package/.rnstorybook/main.ts +8 -0
- package/.rnstorybook/preview.tsx +14 -0
- package/.rnstorybook/storybook.requires.ts +49 -0
- package/.storybook/main.ts +16 -0
- package/.storybook/preview.ts +32 -0
- package/.storybook/vitest.setup.ts +7 -0
- package/App.tsx +422 -0
- package/README.md +229 -0
- package/app.json +33 -0
- package/assets/adaptive-icon.png +0 -0
- package/assets/favicon.png +0 -0
- package/assets/icon.png +0 -0
- package/assets/splash-icon.png +0 -0
- package/babel.config.js +16 -0
- package/docs/components/CodeBlock.tsx +80 -0
- package/docs/components/PropTable.tsx +93 -0
- package/docs/components/Sidebar.tsx +199 -0
- package/docs/components/index.ts +8 -0
- package/docs/data/colorTokens.ts +70 -0
- package/docs/data/componentData.tsx +1685 -0
- package/docs/data/index.ts +7 -0
- package/docs/index.ts +19 -0
- package/docs/navigation.ts +94 -0
- package/docs/pages/ColorsPage.tsx +226 -0
- package/docs/pages/ComponentPage.tsx +235 -0
- package/docs/pages/InstallationPage.tsx +232 -0
- package/docs/pages/IntroductionPage.tsx +163 -0
- package/docs/pages/ThemingPage.tsx +251 -0
- package/docs/pages/index.ts +10 -0
- package/docs/theme.ts +64 -0
- package/docs/types.ts +54 -0
- package/index.ts +8 -0
- package/llms.txt +1893 -0
- package/mcp-config.example.json +10 -0
- package/mcp-server/README.md +192 -0
- package/mcp-server/package-lock.json +1707 -0
- package/mcp-server/package.json +38 -0
- package/mcp-server/src/index.ts +1136 -0
- package/mcp-server/src/registry/components.ts +1446 -0
- package/mcp-server/src/registry/index.ts +3 -0
- package/mcp-server/src/registry/tokens.ts +256 -0
- package/mcp-server/tsconfig.json +19 -0
- package/package.json +92 -0
- package/src/components/Accordion/Accordion.stories.tsx +226 -0
- package/src/components/Accordion/Accordion.tsx +255 -0
- package/src/components/Accordion/index.ts +12 -0
- package/src/components/ActionSheet/ActionSheet.stories.tsx +393 -0
- package/src/components/ActionSheet/ActionSheet.tsx +258 -0
- package/src/components/ActionSheet/index.ts +2 -0
- package/src/components/Alert/Alert.stories.tsx +165 -0
- package/src/components/Alert/Alert.tsx +164 -0
- package/src/components/Alert/index.ts +2 -0
- package/src/components/AlertDialog/AlertDialog.stories.tsx +330 -0
- package/src/components/AlertDialog/AlertDialog.tsx +234 -0
- package/src/components/AlertDialog/index.ts +2 -0
- package/src/components/Avatar/Avatar.stories.tsx +154 -0
- package/src/components/Avatar/Avatar.tsx +219 -0
- package/src/components/Avatar/index.ts +2 -0
- package/src/components/Badge/Badge.stories.tsx +146 -0
- package/src/components/Badge/Badge.tsx +125 -0
- package/src/components/Badge/index.ts +2 -0
- package/src/components/Box/Box.stories.tsx +192 -0
- package/src/components/Box/Box.tsx +184 -0
- package/src/components/Box/index.ts +2 -0
- package/src/components/Button/Button.stories.tsx +157 -0
- package/src/components/Button/Button.tsx +180 -0
- package/src/components/Button/index.ts +2 -0
- package/src/components/Card/Card.stories.tsx +145 -0
- package/src/components/Card/Card.tsx +169 -0
- package/src/components/Card/index.ts +11 -0
- package/src/components/Center/Center.stories.tsx +215 -0
- package/src/components/Center/Center.tsx +29 -0
- package/src/components/Center/index.ts +2 -0
- package/src/components/Checkbox/Checkbox.stories.tsx +94 -0
- package/src/components/Checkbox/Checkbox.tsx +242 -0
- package/src/components/Checkbox/index.ts +2 -0
- package/src/components/DatePicker/DatePicker.stories.tsx +623 -0
- package/src/components/DatePicker/DatePicker.tsx +1228 -0
- package/src/components/DatePicker/index.ts +8 -0
- package/src/components/Divider/Divider.stories.tsx +224 -0
- package/src/components/Divider/Divider.tsx +73 -0
- package/src/components/Divider/index.ts +2 -0
- package/src/components/Drawer/Drawer.stories.tsx +414 -0
- package/src/components/Drawer/Drawer.tsx +342 -0
- package/src/components/Drawer/index.ts +11 -0
- package/src/components/Fab/Fab.stories.tsx +360 -0
- package/src/components/Fab/Fab.tsx +185 -0
- package/src/components/Fab/index.ts +2 -0
- package/src/components/FormControl/FormControl.stories.tsx +276 -0
- package/src/components/FormControl/FormControl.tsx +185 -0
- package/src/components/FormControl/index.ts +12 -0
- package/src/components/Grid/Grid.stories.tsx +244 -0
- package/src/components/Grid/Grid.tsx +93 -0
- package/src/components/Grid/index.ts +2 -0
- package/src/components/HStack/HStack.stories.tsx +230 -0
- package/src/components/HStack/HStack.tsx +80 -0
- package/src/components/HStack/index.ts +2 -0
- package/src/components/Heading/Heading.stories.tsx +111 -0
- package/src/components/Heading/Heading.tsx +85 -0
- package/src/components/Heading/index.ts +2 -0
- package/src/components/Icon/Icon.stories.tsx +320 -0
- package/src/components/Icon/Icon.tsx +117 -0
- package/src/components/Icon/index.ts +2 -0
- package/src/components/Image/Image.stories.tsx +357 -0
- package/src/components/Image/Image.tsx +168 -0
- package/src/components/Image/index.ts +2 -0
- package/src/components/Input/Input.stories.tsx +164 -0
- package/src/components/Input/Input.tsx +274 -0
- package/src/components/Input/index.ts +2 -0
- package/src/components/Link/Link.stories.tsx +187 -0
- package/src/components/Link/Link.tsx +104 -0
- package/src/components/Link/index.ts +2 -0
- package/src/components/Menu/Menu.stories.tsx +363 -0
- package/src/components/Menu/Menu.tsx +238 -0
- package/src/components/Menu/index.ts +2 -0
- package/src/components/Modal/Modal.stories.tsx +156 -0
- package/src/components/Modal/Modal.tsx +280 -0
- package/src/components/Modal/index.ts +11 -0
- package/src/components/Popover/Popover.stories.tsx +330 -0
- package/src/components/Popover/Popover.tsx +315 -0
- package/src/components/Popover/index.ts +11 -0
- package/src/components/Portal/Portal.stories.tsx +376 -0
- package/src/components/Portal/Portal.tsx +100 -0
- package/src/components/Portal/index.ts +2 -0
- package/src/components/Pressable/Pressable.stories.tsx +338 -0
- package/src/components/Pressable/Pressable.tsx +71 -0
- package/src/components/Pressable/index.ts +2 -0
- package/src/components/Progress/Progress.stories.tsx +131 -0
- package/src/components/Progress/Progress.tsx +219 -0
- package/src/components/Progress/index.ts +2 -0
- package/src/components/Radio/Radio.stories.tsx +101 -0
- package/src/components/Radio/Radio.tsx +234 -0
- package/src/components/Radio/index.ts +2 -0
- package/src/components/Select/Select.stories.tsx +908 -0
- package/src/components/Select/Select.tsx +659 -0
- package/src/components/Select/index.ts +8 -0
- package/src/components/Skeleton/Skeleton.stories.tsx +154 -0
- package/src/components/Skeleton/Skeleton.tsx +192 -0
- package/src/components/Skeleton/index.ts +8 -0
- package/src/components/Slider/Slider.stories.tsx +363 -0
- package/src/components/Slider/Slider.tsx +209 -0
- package/src/components/Slider/index.ts +2 -0
- package/src/components/Spinner/Spinner.stories.tsx +108 -0
- package/src/components/Spinner/Spinner.tsx +121 -0
- package/src/components/Spinner/index.ts +2 -0
- package/src/components/Switch/Switch.stories.tsx +116 -0
- package/src/components/Switch/Switch.tsx +172 -0
- package/src/components/Switch/index.ts +2 -0
- package/src/components/Table/Table.stories.tsx +417 -0
- package/src/components/Table/Table.tsx +233 -0
- package/src/components/Table/index.ts +2 -0
- package/src/components/Text/Text.stories.tsx +93 -0
- package/src/components/Text/Text.tsx +119 -0
- package/src/components/Text/index.ts +2 -0
- package/src/components/Textarea/Textarea.stories.tsx +280 -0
- package/src/components/Textarea/Textarea.tsx +212 -0
- package/src/components/Textarea/index.ts +2 -0
- package/src/components/Toast/Toast.stories.tsx +446 -0
- package/src/components/Toast/Toast.tsx +221 -0
- package/src/components/Toast/index.ts +2 -0
- package/src/components/Tooltip/Tooltip.stories.tsx +354 -0
- package/src/components/Tooltip/Tooltip.tsx +261 -0
- package/src/components/Tooltip/index.ts +2 -0
- package/src/components/VStack/VStack.stories.tsx +183 -0
- package/src/components/VStack/VStack.tsx +76 -0
- package/src/components/VStack/index.ts +2 -0
- package/src/components/index.ts +62 -0
- package/src/hooks/index.ts +7 -0
- package/src/hooks/useControllableState.ts +41 -0
- package/src/hooks/useDisclosure.ts +51 -0
- package/src/index.ts +22 -0
- package/src/stories/Button.stories.tsx +53 -0
- package/src/stories/Button.tsx +101 -0
- package/src/stories/Configure.mdx +364 -0
- package/src/stories/Header.stories.tsx +33 -0
- package/src/stories/Header.tsx +75 -0
- package/src/stories/Page.stories.tsx +25 -0
- package/src/stories/Page.tsx +154 -0
- package/src/stories/assets/accessibility.png +0 -0
- package/src/stories/assets/accessibility.svg +1 -0
- package/src/stories/assets/addon-library.png +0 -0
- package/src/stories/assets/assets.png +0 -0
- package/src/stories/assets/avif-test-image.avif +0 -0
- package/src/stories/assets/context.png +0 -0
- package/src/stories/assets/discord.svg +1 -0
- package/src/stories/assets/docs.png +0 -0
- package/src/stories/assets/figma-plugin.png +0 -0
- package/src/stories/assets/github.svg +1 -0
- package/src/stories/assets/share.png +0 -0
- package/src/stories/assets/styling.png +0 -0
- package/src/stories/assets/testing.png +0 -0
- package/src/stories/assets/theming.png +0 -0
- package/src/stories/assets/tutorials.svg +1 -0
- package/src/stories/assets/youtube.svg +1 -0
- package/src/styles/index.ts +7 -0
- package/src/styles/tokens.ts +318 -0
- package/src/styles/unistyles.ts +254 -0
- package/src/utils/createContext.tsx +25 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/mergeRefs.ts +21 -0
- package/tsconfig.json +26 -0
- package/urbint-cl-1.0.0.tgz +0 -0
- package/vitest.config.ts +37 -0
- package/vitest.shims.d.ts +1 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { View, StyleSheet } from 'react-native';
|
|
3
|
+
import { Textarea } from './Textarea';
|
|
4
|
+
import { VStack } from '../VStack';
|
|
5
|
+
import { Text } from '../Text';
|
|
6
|
+
import { colors, spacing, borderRadius } from '../../styles/tokens';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Story container with design system tokens
|
|
10
|
+
*/
|
|
11
|
+
const StoryContainer: React.FC<{ children: React.ReactNode }> = ({ children }) => (
|
|
12
|
+
<View style={styles.container}>{children}</View>
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
const meta: Meta<typeof Textarea> = {
|
|
16
|
+
title: 'Forms/Textarea',
|
|
17
|
+
component: Textarea,
|
|
18
|
+
decorators: [
|
|
19
|
+
(Story) => (
|
|
20
|
+
<StoryContainer>
|
|
21
|
+
<Story />
|
|
22
|
+
</StoryContainer>
|
|
23
|
+
),
|
|
24
|
+
],
|
|
25
|
+
argTypes: {
|
|
26
|
+
variant: {
|
|
27
|
+
control: 'select',
|
|
28
|
+
options: ['outline', 'filled'],
|
|
29
|
+
},
|
|
30
|
+
size: {
|
|
31
|
+
control: 'select',
|
|
32
|
+
options: ['sm', 'md', 'lg'],
|
|
33
|
+
},
|
|
34
|
+
isInvalid: { control: 'boolean' },
|
|
35
|
+
isDisabled: { control: 'boolean' },
|
|
36
|
+
isReadOnly: { control: 'boolean' },
|
|
37
|
+
isRequired: { control: 'boolean' },
|
|
38
|
+
showCount: { control: 'boolean' },
|
|
39
|
+
rows: { control: 'number' },
|
|
40
|
+
},
|
|
41
|
+
args: {
|
|
42
|
+
placeholder: 'Enter your text here...',
|
|
43
|
+
variant: 'outline',
|
|
44
|
+
size: 'md',
|
|
45
|
+
rows: 4,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default meta;
|
|
50
|
+
|
|
51
|
+
type Story = StoryObj<typeof Textarea>;
|
|
52
|
+
|
|
53
|
+
export const Default: Story = {
|
|
54
|
+
render: (args) => <Textarea {...args} />,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const WithLabel: Story = {
|
|
58
|
+
render: () => (
|
|
59
|
+
<VStack space={spacing.lg}>
|
|
60
|
+
<Textarea
|
|
61
|
+
label="Description"
|
|
62
|
+
placeholder="Enter a description..."
|
|
63
|
+
/>
|
|
64
|
+
<Textarea
|
|
65
|
+
label="Comments"
|
|
66
|
+
placeholder="Leave a comment..."
|
|
67
|
+
helperText="Share your thoughts"
|
|
68
|
+
/>
|
|
69
|
+
</VStack>
|
|
70
|
+
),
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export const Variants: Story = {
|
|
74
|
+
render: () => (
|
|
75
|
+
<VStack space={spacing.lg}>
|
|
76
|
+
<Text weight="semiBold">Textarea Variants</Text>
|
|
77
|
+
<Textarea
|
|
78
|
+
label="Outline"
|
|
79
|
+
variant="outline"
|
|
80
|
+
placeholder="Outline variant..."
|
|
81
|
+
/>
|
|
82
|
+
<Textarea
|
|
83
|
+
label="Filled"
|
|
84
|
+
variant="filled"
|
|
85
|
+
placeholder="Filled variant..."
|
|
86
|
+
/>
|
|
87
|
+
</VStack>
|
|
88
|
+
),
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const Sizes: Story = {
|
|
92
|
+
render: () => (
|
|
93
|
+
<VStack space={spacing.lg}>
|
|
94
|
+
<Text weight="semiBold">Textarea Sizes</Text>
|
|
95
|
+
<Textarea
|
|
96
|
+
label="Small"
|
|
97
|
+
size="sm"
|
|
98
|
+
placeholder="Small textarea..."
|
|
99
|
+
rows={3}
|
|
100
|
+
/>
|
|
101
|
+
<Textarea
|
|
102
|
+
label="Medium"
|
|
103
|
+
size="md"
|
|
104
|
+
placeholder="Medium textarea..."
|
|
105
|
+
rows={3}
|
|
106
|
+
/>
|
|
107
|
+
<Textarea
|
|
108
|
+
label="Large"
|
|
109
|
+
size="lg"
|
|
110
|
+
placeholder="Large textarea..."
|
|
111
|
+
rows={3}
|
|
112
|
+
/>
|
|
113
|
+
</VStack>
|
|
114
|
+
),
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export const States: Story = {
|
|
118
|
+
render: () => (
|
|
119
|
+
<VStack space={spacing.lg}>
|
|
120
|
+
<Text weight="semiBold">Textarea States</Text>
|
|
121
|
+
<Textarea
|
|
122
|
+
label="Normal"
|
|
123
|
+
placeholder="Normal state..."
|
|
124
|
+
/>
|
|
125
|
+
<Textarea
|
|
126
|
+
label="Disabled"
|
|
127
|
+
placeholder="Disabled state..."
|
|
128
|
+
isDisabled
|
|
129
|
+
value="This textarea is disabled"
|
|
130
|
+
/>
|
|
131
|
+
<Textarea
|
|
132
|
+
label="Read Only"
|
|
133
|
+
placeholder="Read only state..."
|
|
134
|
+
isReadOnly
|
|
135
|
+
value="This content is read-only"
|
|
136
|
+
/>
|
|
137
|
+
<Textarea
|
|
138
|
+
label="Required"
|
|
139
|
+
placeholder="Required field..."
|
|
140
|
+
isRequired
|
|
141
|
+
/>
|
|
142
|
+
</VStack>
|
|
143
|
+
),
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export const Validation: Story = {
|
|
147
|
+
render: () => (
|
|
148
|
+
<VStack space={spacing.lg}>
|
|
149
|
+
<Text weight="semiBold">Validation States</Text>
|
|
150
|
+
<Textarea
|
|
151
|
+
label="Valid Input"
|
|
152
|
+
placeholder="Enter text..."
|
|
153
|
+
value="This is valid content"
|
|
154
|
+
helperText="Looking good!"
|
|
155
|
+
/>
|
|
156
|
+
<Textarea
|
|
157
|
+
label="Invalid Input"
|
|
158
|
+
placeholder="Enter text..."
|
|
159
|
+
isInvalid
|
|
160
|
+
errorMessage="This field is required"
|
|
161
|
+
/>
|
|
162
|
+
<Textarea
|
|
163
|
+
label="With Error Message"
|
|
164
|
+
placeholder="Enter text..."
|
|
165
|
+
isInvalid
|
|
166
|
+
value="Too short"
|
|
167
|
+
errorMessage="Description must be at least 50 characters"
|
|
168
|
+
/>
|
|
169
|
+
</VStack>
|
|
170
|
+
),
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
export const CharacterCount: Story = {
|
|
174
|
+
render: () => (
|
|
175
|
+
<VStack space={spacing.lg}>
|
|
176
|
+
<Text weight="semiBold">Character Count</Text>
|
|
177
|
+
<Textarea
|
|
178
|
+
label="Bio"
|
|
179
|
+
placeholder="Tell us about yourself..."
|
|
180
|
+
showCount
|
|
181
|
+
maxLength={200}
|
|
182
|
+
helperText="Maximum 200 characters"
|
|
183
|
+
/>
|
|
184
|
+
<Textarea
|
|
185
|
+
label="Tweet"
|
|
186
|
+
placeholder="What's happening?"
|
|
187
|
+
showCount
|
|
188
|
+
maxLength={280}
|
|
189
|
+
rows={3}
|
|
190
|
+
/>
|
|
191
|
+
</VStack>
|
|
192
|
+
),
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export const DifferentRows: Story = {
|
|
196
|
+
render: () => (
|
|
197
|
+
<VStack space={spacing.lg}>
|
|
198
|
+
<Text weight="semiBold">Different Row Heights</Text>
|
|
199
|
+
<Textarea
|
|
200
|
+
label="2 Rows"
|
|
201
|
+
placeholder="Short text area..."
|
|
202
|
+
rows={2}
|
|
203
|
+
/>
|
|
204
|
+
<Textarea
|
|
205
|
+
label="4 Rows"
|
|
206
|
+
placeholder="Medium text area..."
|
|
207
|
+
rows={4}
|
|
208
|
+
/>
|
|
209
|
+
<Textarea
|
|
210
|
+
label="6 Rows"
|
|
211
|
+
placeholder="Large text area..."
|
|
212
|
+
rows={6}
|
|
213
|
+
/>
|
|
214
|
+
<Textarea
|
|
215
|
+
label="8 Rows"
|
|
216
|
+
placeholder="Extra large text area..."
|
|
217
|
+
rows={8}
|
|
218
|
+
/>
|
|
219
|
+
</VStack>
|
|
220
|
+
),
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export const FormExample: Story = {
|
|
224
|
+
render: () => (
|
|
225
|
+
<VStack space={spacing.lg}>
|
|
226
|
+
<Text weight="semiBold">Feedback Form</Text>
|
|
227
|
+
<VStack space={spacing.md}>
|
|
228
|
+
<Textarea
|
|
229
|
+
label="Subject"
|
|
230
|
+
placeholder="Brief summary..."
|
|
231
|
+
rows={2}
|
|
232
|
+
isRequired
|
|
233
|
+
/>
|
|
234
|
+
<Textarea
|
|
235
|
+
label="Description"
|
|
236
|
+
placeholder="Please provide details..."
|
|
237
|
+
rows={5}
|
|
238
|
+
isRequired
|
|
239
|
+
helperText="Be as specific as possible"
|
|
240
|
+
/>
|
|
241
|
+
<Textarea
|
|
242
|
+
label="Additional Notes"
|
|
243
|
+
placeholder="Any other information..."
|
|
244
|
+
rows={3}
|
|
245
|
+
showCount
|
|
246
|
+
maxLength={500}
|
|
247
|
+
/>
|
|
248
|
+
</VStack>
|
|
249
|
+
</VStack>
|
|
250
|
+
),
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
export const ContactForm: Story = {
|
|
254
|
+
render: () => (
|
|
255
|
+
<VStack space={spacing.lg}>
|
|
256
|
+
<Text weight="semiBold">Contact Form Message</Text>
|
|
257
|
+
<Textarea
|
|
258
|
+
label="Your Message"
|
|
259
|
+
placeholder="How can we help you today?"
|
|
260
|
+
rows={6}
|
|
261
|
+
isRequired
|
|
262
|
+
showCount
|
|
263
|
+
maxLength={1000}
|
|
264
|
+
helperText="We typically respond within 24 hours"
|
|
265
|
+
/>
|
|
266
|
+
</VStack>
|
|
267
|
+
),
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Styles using design system tokens
|
|
272
|
+
*/
|
|
273
|
+
const styles = StyleSheet.create({
|
|
274
|
+
container: {
|
|
275
|
+
padding: spacing.lg,
|
|
276
|
+
backgroundColor: colors.background.default,
|
|
277
|
+
borderRadius: borderRadius.lg,
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Textarea Component
|
|
3
|
+
* Multi-line text input
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { forwardRef, useState } from 'react';
|
|
7
|
+
import { View, TextInput, TextInputProps, Text, StyleSheet } from 'react-native';
|
|
8
|
+
import { colors, spacing, borderRadius, typography } from '../../styles/tokens';
|
|
9
|
+
|
|
10
|
+
export interface TextareaProps extends Omit<TextInputProps, 'style'> {
|
|
11
|
+
/** Textarea variant */
|
|
12
|
+
variant?: 'outline' | 'filled';
|
|
13
|
+
/** Textarea size */
|
|
14
|
+
size?: 'sm' | 'md' | 'lg';
|
|
15
|
+
/** Label text */
|
|
16
|
+
label?: string;
|
|
17
|
+
/** Helper text */
|
|
18
|
+
helperText?: string;
|
|
19
|
+
/** Error message */
|
|
20
|
+
errorMessage?: string;
|
|
21
|
+
/** Is invalid */
|
|
22
|
+
isInvalid?: boolean;
|
|
23
|
+
/** Is disabled */
|
|
24
|
+
isDisabled?: boolean;
|
|
25
|
+
/** Is read only */
|
|
26
|
+
isReadOnly?: boolean;
|
|
27
|
+
/** Is required */
|
|
28
|
+
isRequired?: boolean;
|
|
29
|
+
/** Number of rows */
|
|
30
|
+
rows?: number;
|
|
31
|
+
/** Show character count */
|
|
32
|
+
showCount?: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const Textarea = forwardRef<TextInput, TextareaProps>(
|
|
36
|
+
(
|
|
37
|
+
{
|
|
38
|
+
variant = 'outline',
|
|
39
|
+
size = 'md',
|
|
40
|
+
label,
|
|
41
|
+
helperText,
|
|
42
|
+
errorMessage,
|
|
43
|
+
isInvalid = false,
|
|
44
|
+
isDisabled = false,
|
|
45
|
+
isReadOnly = false,
|
|
46
|
+
isRequired = false,
|
|
47
|
+
rows = 4,
|
|
48
|
+
showCount = false,
|
|
49
|
+
maxLength,
|
|
50
|
+
value = '',
|
|
51
|
+
onFocus,
|
|
52
|
+
onBlur,
|
|
53
|
+
...props
|
|
54
|
+
},
|
|
55
|
+
ref
|
|
56
|
+
) => {
|
|
57
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
58
|
+
const [internalValue, setInternalValue] = useState(value);
|
|
59
|
+
|
|
60
|
+
const handleFocus = (e: any) => {
|
|
61
|
+
setIsFocused(true);
|
|
62
|
+
onFocus?.(e);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const handleBlur = (e: any) => {
|
|
66
|
+
setIsFocused(false);
|
|
67
|
+
onBlur?.(e);
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const handleChange = (text: string) => {
|
|
71
|
+
setInternalValue(text);
|
|
72
|
+
props.onChangeText?.(text);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const hasError = isInvalid || !!errorMessage;
|
|
76
|
+
const currentLength = (value || internalValue).length;
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<View style={styles.container}>
|
|
80
|
+
{label && (
|
|
81
|
+
<Text style={[styles.label, isDisabled && styles.labelDisabled]}>
|
|
82
|
+
{label}
|
|
83
|
+
{isRequired && <Text style={styles.required}> *</Text>}
|
|
84
|
+
</Text>
|
|
85
|
+
)}
|
|
86
|
+
<View
|
|
87
|
+
style={[
|
|
88
|
+
styles.textareaWrapper,
|
|
89
|
+
styles[variant],
|
|
90
|
+
styles[size],
|
|
91
|
+
isFocused && styles.focused,
|
|
92
|
+
hasError && styles.error,
|
|
93
|
+
isDisabled && styles.disabled,
|
|
94
|
+
{ minHeight: rows * 24 },
|
|
95
|
+
]}
|
|
96
|
+
>
|
|
97
|
+
<TextInput
|
|
98
|
+
ref={ref}
|
|
99
|
+
style={[styles.textarea, styles[`${size}Textarea` as keyof typeof styles], isDisabled && styles.disabledText]}
|
|
100
|
+
editable={!isDisabled && !isReadOnly}
|
|
101
|
+
placeholderTextColor={colors.text.disabled}
|
|
102
|
+
multiline
|
|
103
|
+
numberOfLines={rows}
|
|
104
|
+
textAlignVertical="top"
|
|
105
|
+
maxLength={maxLength}
|
|
106
|
+
value={value || internalValue}
|
|
107
|
+
onFocus={handleFocus}
|
|
108
|
+
onBlur={handleBlur}
|
|
109
|
+
onChangeText={handleChange}
|
|
110
|
+
{...props}
|
|
111
|
+
/>
|
|
112
|
+
</View>
|
|
113
|
+
<View style={styles.footer}>
|
|
114
|
+
{(helperText || errorMessage) && (
|
|
115
|
+
<Text style={[styles.helperText, hasError && styles.errorText]}>
|
|
116
|
+
{errorMessage || helperText}
|
|
117
|
+
</Text>
|
|
118
|
+
)}
|
|
119
|
+
{showCount && maxLength && (
|
|
120
|
+
<Text style={styles.charCount}>
|
|
121
|
+
{currentLength}/{maxLength}
|
|
122
|
+
</Text>
|
|
123
|
+
)}
|
|
124
|
+
</View>
|
|
125
|
+
</View>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
Textarea.displayName = 'Textarea';
|
|
131
|
+
|
|
132
|
+
const styles = StyleSheet.create({
|
|
133
|
+
container: {
|
|
134
|
+
width: '100%',
|
|
135
|
+
},
|
|
136
|
+
label: {
|
|
137
|
+
fontSize: typography.fontSize.componentLabel,
|
|
138
|
+
fontWeight: typography.fontWeight.semiBold,
|
|
139
|
+
color: colors.text.default,
|
|
140
|
+
marginBottom: spacing.base,
|
|
141
|
+
},
|
|
142
|
+
labelDisabled: {
|
|
143
|
+
color: colors.text.disabled,
|
|
144
|
+
},
|
|
145
|
+
required: {
|
|
146
|
+
color: colors.feedback.error.content,
|
|
147
|
+
},
|
|
148
|
+
textareaWrapper: {
|
|
149
|
+
borderRadius: borderRadius.md,
|
|
150
|
+
},
|
|
151
|
+
outline: {
|
|
152
|
+
borderWidth: 1,
|
|
153
|
+
borderColor: colors.border.default,
|
|
154
|
+
backgroundColor: colors.background.default,
|
|
155
|
+
},
|
|
156
|
+
filled: {
|
|
157
|
+
backgroundColor: colors.background.secondary,
|
|
158
|
+
},
|
|
159
|
+
sm: {
|
|
160
|
+
padding: spacing['2x'],
|
|
161
|
+
},
|
|
162
|
+
md: {
|
|
163
|
+
padding: spacing['3x'],
|
|
164
|
+
},
|
|
165
|
+
lg: {
|
|
166
|
+
padding: spacing['4x'],
|
|
167
|
+
},
|
|
168
|
+
focused: {
|
|
169
|
+
borderColor: colors.border.active,
|
|
170
|
+
},
|
|
171
|
+
error: {
|
|
172
|
+
borderColor: colors.border.danger,
|
|
173
|
+
},
|
|
174
|
+
disabled: {
|
|
175
|
+
backgroundColor: colors.background.secondary,
|
|
176
|
+
borderColor: colors.border.disabled,
|
|
177
|
+
},
|
|
178
|
+
textarea: {
|
|
179
|
+
color: colors.text.default,
|
|
180
|
+
},
|
|
181
|
+
smTextarea: {
|
|
182
|
+
fontSize: typography.fontSize.small,
|
|
183
|
+
},
|
|
184
|
+
mdTextarea: {
|
|
185
|
+
fontSize: typography.fontSize.body,
|
|
186
|
+
},
|
|
187
|
+
lgTextarea: {
|
|
188
|
+
fontSize: typography.fontSize.body,
|
|
189
|
+
},
|
|
190
|
+
disabledText: {
|
|
191
|
+
color: colors.text.disabled,
|
|
192
|
+
},
|
|
193
|
+
footer: {
|
|
194
|
+
flexDirection: 'row',
|
|
195
|
+
justifyContent: 'space-between',
|
|
196
|
+
alignItems: 'center',
|
|
197
|
+
marginTop: spacing.base,
|
|
198
|
+
},
|
|
199
|
+
helperText: {
|
|
200
|
+
fontSize: typography.fontSize.caption,
|
|
201
|
+
color: colors.text.secondary,
|
|
202
|
+
flex: 1,
|
|
203
|
+
},
|
|
204
|
+
errorText: {
|
|
205
|
+
color: colors.feedback.error.content,
|
|
206
|
+
},
|
|
207
|
+
charCount: {
|
|
208
|
+
fontSize: typography.fontSize.caption,
|
|
209
|
+
color: colors.text.secondary,
|
|
210
|
+
marginLeft: spacing['2x'],
|
|
211
|
+
},
|
|
212
|
+
});
|