@boostdev/design-system-react-native 0.1.0 → 0.2.0
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/CHANGELOG.md +42 -0
- package/LICENSE +15 -0
- package/README.md +104 -2
- package/dist/index.cjs +100 -57
- package/dist/index.d.cts +61 -6
- package/dist/index.d.ts +61 -6
- package/dist/index.js +100 -57
- package/package.json +30 -10
- package/src/components/interaction/Button/Button.mdx +91 -0
- package/src/components/interaction/Button/Button.spec.tsx +55 -0
- package/src/components/interaction/Button/Button.stories.tsx +141 -0
- package/src/components/interaction/Button/Button.tsx +105 -0
- package/src/components/interaction/Dialog/Dialog.mdx +61 -0
- package/src/components/interaction/Dialog/Dialog.spec.tsx +73 -0
- package/src/components/interaction/Dialog/Dialog.stories.tsx +53 -0
- package/src/components/interaction/Dialog/Dialog.tsx +128 -0
- package/src/components/interaction/DropdownMenu/DropdownMenu.mdx +74 -0
- package/src/components/interaction/DropdownMenu/DropdownMenu.spec.tsx +78 -0
- package/src/components/interaction/DropdownMenu/DropdownMenu.stories.tsx +51 -0
- package/src/components/interaction/DropdownMenu/DropdownMenu.tsx +254 -0
- package/src/components/interaction/Popover/Popover.mdx +61 -0
- package/src/components/interaction/Popover/Popover.spec.tsx +73 -0
- package/src/components/interaction/Popover/Popover.stories.tsx +44 -0
- package/src/components/interaction/Popover/Popover.tsx +87 -0
- package/src/components/interaction/Rating/Rating.mdx +55 -0
- package/src/components/interaction/Rating/Rating.spec.tsx +38 -0
- package/src/components/interaction/Rating/Rating.stories.tsx +37 -0
- package/src/components/interaction/Rating/Rating.tsx +50 -0
- package/src/components/interaction/SideSheet/SideSheet.mdx +60 -0
- package/src/components/interaction/SideSheet/SideSheet.spec.tsx +80 -0
- package/src/components/interaction/SideSheet/SideSheet.stories.tsx +33 -0
- package/src/components/interaction/SideSheet/SideSheet.tsx +175 -0
- package/src/components/interaction/Toast/Toast.mdx +81 -0
- package/src/components/interaction/Toast/Toast.spec.tsx +80 -0
- package/src/components/interaction/Toast/Toast.stories.tsx +47 -0
- package/src/components/interaction/Toast/Toast.tsx +202 -0
- package/src/components/interaction/form/Checkbox/Checkbox.mdx +74 -0
- package/src/components/interaction/form/Checkbox/Checkbox.spec.tsx +42 -0
- package/src/components/interaction/form/Checkbox/Checkbox.stories.tsx +34 -0
- package/src/components/interaction/form/Checkbox/Checkbox.tsx +80 -0
- package/src/components/interaction/form/CheckboxGroup/CheckboxGroup.mdx +78 -0
- package/src/components/interaction/form/CheckboxGroup/CheckboxGroup.spec.tsx +57 -0
- package/src/components/interaction/form/CheckboxGroup/CheckboxGroup.stories.tsx +96 -0
- package/src/components/interaction/form/CheckboxGroup/CheckboxGroup.tsx +61 -0
- package/src/components/interaction/form/Combobox/Combobox.mdx +86 -0
- package/src/components/interaction/form/Combobox/Combobox.spec.tsx +60 -0
- package/src/components/interaction/form/Combobox/Combobox.stories.tsx +99 -0
- package/src/components/interaction/form/Combobox/Combobox.tsx +211 -0
- package/src/components/interaction/form/FileInput/FileInput.mdx +86 -0
- package/src/components/interaction/form/FileInput/FileInput.spec.tsx +73 -0
- package/src/components/interaction/form/FileInput/FileInput.stories.tsx +69 -0
- package/src/components/interaction/form/FileInput/FileInput.tsx +129 -0
- package/src/components/interaction/form/FormInput/FormInput.mdx +81 -0
- package/src/components/interaction/form/FormInput/FormInput.spec.tsx +51 -0
- package/src/components/interaction/form/FormInput/FormInput.stories.tsx +54 -0
- package/src/components/interaction/form/FormInput/FormInput.tsx +122 -0
- package/src/components/interaction/form/NumberInput/NumberInput.mdx +87 -0
- package/src/components/interaction/form/NumberInput/NumberInput.spec.tsx +63 -0
- package/src/components/interaction/form/NumberInput/NumberInput.stories.tsx +63 -0
- package/src/components/interaction/form/NumberInput/NumberInput.tsx +198 -0
- package/src/components/interaction/form/Radio/Radio.spec.tsx +79 -0
- package/src/components/interaction/form/Radio/Radio.stories.tsx +44 -0
- package/src/components/interaction/form/Radio/Radio.tsx +79 -0
- package/src/components/interaction/form/RadioGroup/RadioGroup.mdx +79 -0
- package/src/components/interaction/form/RadioGroup/RadioGroup.spec.tsx +66 -0
- package/src/components/interaction/form/RadioGroup/RadioGroup.stories.tsx +96 -0
- package/src/components/interaction/form/RadioGroup/RadioGroup.tsx +61 -0
- package/src/components/interaction/form/SegmentedControl/SegmentedControl.mdx +78 -0
- package/src/components/interaction/form/SegmentedControl/SegmentedControl.spec.tsx +82 -0
- package/src/components/interaction/form/SegmentedControl/SegmentedControl.stories.tsx +99 -0
- package/src/components/interaction/form/SegmentedControl/SegmentedControl.tsx +121 -0
- package/src/components/interaction/form/Select/Select.mdx +85 -0
- package/src/components/interaction/form/Select/Select.spec.tsx +64 -0
- package/src/components/interaction/form/Select/Select.stories.tsx +75 -0
- package/src/components/interaction/form/Select/Select.tsx +252 -0
- package/src/components/interaction/form/Slider/Slider.mdx +83 -0
- package/src/components/interaction/form/Slider/Slider.spec.tsx +51 -0
- package/src/components/interaction/form/Slider/Slider.stories.tsx +58 -0
- package/src/components/interaction/form/Slider/Slider.tsx +188 -0
- package/src/components/interaction/form/Switch/Switch.spec.tsx +60 -0
- package/src/components/interaction/form/Switch/Switch.stories.tsx +33 -0
- package/src/components/interaction/form/Switch/Switch.tsx +59 -0
- package/src/components/interaction/form/Textarea/Textarea.mdx +76 -0
- package/src/components/interaction/form/Textarea/Textarea.spec.tsx +50 -0
- package/src/components/interaction/form/Textarea/Textarea.stories.tsx +50 -0
- package/src/components/interaction/form/Textarea/Textarea.tsx +108 -0
- package/src/components/interaction/form/atoms/Label.spec.tsx +39 -0
- package/src/components/interaction/form/atoms/Label.stories.tsx +18 -0
- package/src/components/interaction/form/atoms/Label.tsx +29 -0
- package/src/components/interaction/form/atoms/Message.spec.tsx +30 -0
- package/src/components/interaction/form/atoms/Message.stories.tsx +22 -0
- package/src/components/interaction/form/atoms/Message.tsx +34 -0
- package/src/components/layout/ButtonGroup/ButtonGroup.spec.tsx +83 -0
- package/src/components/layout/ButtonGroup/ButtonGroup.stories.tsx +44 -0
- package/src/components/layout/ButtonGroup/ButtonGroup.tsx +44 -0
- package/src/components/layout/Card/Card.spec.tsx +102 -0
- package/src/components/layout/Card/Card.stories.tsx +51 -0
- package/src/components/layout/Card/Card.tsx +89 -0
- package/src/components/layout/IconWrapper/IconWrapper.spec.tsx +39 -0
- package/src/components/layout/IconWrapper/IconWrapper.stories.tsx +37 -0
- package/src/components/layout/IconWrapper/IconWrapper.tsx +20 -0
- package/src/components/layout/SectionHeader/SectionHeader.spec.tsx +51 -0
- package/src/components/layout/SectionHeader/SectionHeader.stories.tsx +36 -0
- package/src/components/layout/SectionHeader/SectionHeader.tsx +79 -0
- package/src/components/ui/Accordion/Accordion.mdx +65 -0
- package/src/components/ui/Accordion/Accordion.spec.tsx +69 -0
- package/src/components/ui/Accordion/Accordion.stories.tsx +52 -0
- package/src/components/ui/Accordion/Accordion.tsx +141 -0
- package/src/components/ui/Alert/Alert.mdx +62 -0
- package/src/components/ui/Alert/Alert.spec.tsx +76 -0
- package/src/components/ui/Alert/Alert.stories.tsx +41 -0
- package/src/components/ui/Alert/Alert.tsx +94 -0
- package/src/components/ui/Avatar/Avatar.mdx +50 -0
- package/src/components/ui/Avatar/Avatar.spec.tsx +47 -0
- package/src/components/ui/Avatar/Avatar.stories.tsx +32 -0
- package/src/components/ui/Avatar/Avatar.tsx +85 -0
- package/src/components/ui/Badge/Badge.mdx +54 -0
- package/src/components/ui/Badge/Badge.spec.tsx +45 -0
- package/src/components/ui/Badge/Badge.stories.tsx +34 -0
- package/src/components/ui/Badge/Badge.tsx +50 -0
- package/src/components/ui/Breadcrumb/Breadcrumb.mdx +52 -0
- package/src/components/ui/Breadcrumb/Breadcrumb.spec.tsx +49 -0
- package/src/components/ui/Breadcrumb/Breadcrumb.stories.tsx +46 -0
- package/src/components/ui/Breadcrumb/Breadcrumb.tsx +83 -0
- package/src/components/ui/Calendar/Calendar.mdx +58 -0
- package/src/components/ui/Calendar/Calendar.spec.tsx +92 -0
- package/src/components/ui/Calendar/Calendar.stories.tsx +45 -0
- package/src/components/ui/Calendar/Calendar.tsx +294 -0
- package/src/components/ui/Carousel/Carousel.mdx +55 -0
- package/src/components/ui/Carousel/Carousel.spec.tsx +55 -0
- package/src/components/ui/Carousel/Carousel.stories.tsx +59 -0
- package/src/components/ui/Carousel/Carousel.tsx +184 -0
- package/src/components/ui/Collapsible/Collapsible.mdx +53 -0
- package/src/components/ui/Collapsible/Collapsible.spec.tsx +68 -0
- package/src/components/ui/Collapsible/Collapsible.stories.tsx +48 -0
- package/src/components/ui/Collapsible/Collapsible.tsx +139 -0
- package/src/components/ui/DescriptionList/DescriptionList.mdx +50 -0
- package/src/components/ui/DescriptionList/DescriptionList.spec.tsx +37 -0
- package/src/components/ui/DescriptionList/DescriptionList.stories.tsx +48 -0
- package/src/components/ui/DescriptionList/DescriptionList.tsx +54 -0
- package/src/components/ui/Link/Link.mdx +53 -0
- package/src/components/ui/Link/Link.spec.tsx +35 -0
- package/src/components/ui/Link/Link.stories.tsx +46 -0
- package/src/components/ui/Link/Link.tsx +48 -0
- package/src/components/ui/Loading/Loading.spec.tsx +24 -0
- package/src/components/ui/Loading/Loading.stories.tsx +31 -0
- package/src/components/ui/Loading/Loading.tsx +29 -0
- package/src/components/ui/NotificationBanner/NotificationBanner.spec.tsx +85 -0
- package/src/components/ui/NotificationBanner/NotificationBanner.stories.tsx +37 -0
- package/src/components/ui/NotificationBanner/NotificationBanner.tsx +76 -0
- package/src/components/ui/Pagination/Pagination.mdx +62 -0
- package/src/components/ui/Pagination/Pagination.spec.tsx +86 -0
- package/src/components/ui/Pagination/Pagination.stories.tsx +47 -0
- package/src/components/ui/Pagination/Pagination.tsx +157 -0
- package/src/components/ui/Progress/Progress.spec.tsx +56 -0
- package/src/components/ui/Progress/Progress.stories.tsx +34 -0
- package/src/components/ui/Progress/Progress.tsx +84 -0
- package/src/components/ui/ProgressCircle/ProgressCircle.mdx +63 -0
- package/src/components/ui/ProgressCircle/ProgressCircle.spec.tsx +39 -0
- package/src/components/ui/ProgressCircle/ProgressCircle.stories.tsx +36 -0
- package/src/components/ui/ProgressCircle/ProgressCircle.tsx +176 -0
- package/src/components/ui/Separator/Separator.spec.tsx +39 -0
- package/src/components/ui/Separator/Separator.stories.tsx +38 -0
- package/src/components/ui/Separator/Separator.tsx +32 -0
- package/src/components/ui/Skeleton/Skeleton.spec.tsx +39 -0
- package/src/components/ui/Skeleton/Skeleton.stories.tsx +31 -0
- package/src/components/ui/Skeleton/Skeleton.tsx +42 -0
- package/src/components/ui/Table/Table.mdx +72 -0
- package/src/components/ui/Table/Table.spec.tsx +83 -0
- package/src/components/ui/Table/Table.stories.tsx +55 -0
- package/src/components/ui/Table/Table.tsx +196 -0
- package/src/components/ui/Tabs/Tabs.mdx +65 -0
- package/src/components/ui/Tabs/Tabs.spec.tsx +65 -0
- package/src/components/ui/Tabs/Tabs.stories.tsx +57 -0
- package/src/components/ui/Tabs/Tabs.tsx +133 -0
- package/src/components/ui/Tooltip/Tooltip.mdx +47 -0
- package/src/components/ui/Tooltip/Tooltip.spec.tsx +37 -0
- package/src/components/ui/Tooltip/Tooltip.stories.tsx +38 -0
- package/src/components/ui/Tooltip/Tooltip.tsx +57 -0
- package/src/components/ui/Typography/Typography.mdx +56 -0
- package/src/components/ui/Typography/Typography.spec.tsx +49 -0
- package/src/components/ui/Typography/Typography.stories.tsx +36 -0
- package/src/components/ui/Typography/Typography.tsx +65 -0
- package/src/index.ts +86 -0
- package/src/native/ReactNavigationTheme.mdx +140 -0
- package/src/native/ReactNavigationTheme.spec.tsx +35 -0
- package/src/native/ReactNavigationTheme.ts +102 -0
- package/src/native/ThemeContext.spec.tsx +57 -0
- package/src/native/ThemeContext.tsx +48 -0
- package/src/native/tokens.ts +13 -0
- package/src/test/setup.ts +1 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
import { ThemeProvider } from '../../../../native/ThemeContext';
|
|
4
|
+
import { FormInput } from './FormInput';
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
tags: ['!stable', 'alpha'],
|
|
8
|
+
title: 'React Native/Form/FormInput',
|
|
9
|
+
component: FormInput,
|
|
10
|
+
decorators: [(Story) => <ThemeProvider colorScheme="light"><Story /></ThemeProvider>],
|
|
11
|
+
parameters: { layout: 'padded' },
|
|
12
|
+
} satisfies Meta<typeof FormInput>;
|
|
13
|
+
|
|
14
|
+
export default meta;
|
|
15
|
+
type Story = StoryObj<typeof meta>;
|
|
16
|
+
|
|
17
|
+
export const Default: Story = {
|
|
18
|
+
args: { label: 'Full name', name: 'fullName' },
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const WithPlaceholder: Story = {
|
|
22
|
+
args: { label: 'Email', name: 'email', type: 'email', placeholder: 'you@example.com' },
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const Password: Story = {
|
|
26
|
+
args: { label: 'Password', name: 'password', type: 'password' },
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const WithError: Story = {
|
|
30
|
+
args: { label: 'Email', name: 'email', type: 'email', error: 'Please enter a valid email address.' },
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const WithHint: Story = {
|
|
34
|
+
args: { label: 'Username', name: 'username', hint: 'Must be at least 3 characters.' },
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const Disabled: Story = {
|
|
38
|
+
args: { label: 'Full name', name: 'fullName', disabled: true, value: 'Jane Doe' },
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const Interactive: Story = {
|
|
42
|
+
render: () => {
|
|
43
|
+
const [value, setValue] = useState('');
|
|
44
|
+
return (
|
|
45
|
+
<FormInput
|
|
46
|
+
label="Your name"
|
|
47
|
+
name="name"
|
|
48
|
+
placeholder="Enter your name"
|
|
49
|
+
value={value}
|
|
50
|
+
onChange={setValue}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { ReactNode, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
StyleSheet,
|
|
4
|
+
View,
|
|
5
|
+
TextInput,
|
|
6
|
+
KeyboardTypeOptions,
|
|
7
|
+
StyleProp,
|
|
8
|
+
ViewStyle,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import { spacing, font, border, lineHeight } from '../../../../native/tokens';
|
|
11
|
+
import { useTheme } from '../../../../native/ThemeContext';
|
|
12
|
+
import { Label } from '../atoms/Label';
|
|
13
|
+
import { Message } from '../atoms/Message';
|
|
14
|
+
|
|
15
|
+
type InputType = 'text' | 'email' | 'password' | 'tel' | 'url' | 'number' | 'search';
|
|
16
|
+
|
|
17
|
+
interface FormInputProps {
|
|
18
|
+
label: ReactNode;
|
|
19
|
+
name: string;
|
|
20
|
+
type?: InputType;
|
|
21
|
+
value?: string;
|
|
22
|
+
defaultValue?: string;
|
|
23
|
+
placeholder?: string;
|
|
24
|
+
error?: string;
|
|
25
|
+
hint?: string;
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
onChange?: (value: string) => void;
|
|
28
|
+
onBlur?: () => void;
|
|
29
|
+
onFocus?: () => void;
|
|
30
|
+
style?: StyleProp<ViewStyle>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const keyboardTypeMap: Record<InputType, KeyboardTypeOptions> = {
|
|
34
|
+
text: 'default',
|
|
35
|
+
email: 'email-address',
|
|
36
|
+
password: 'default',
|
|
37
|
+
tel: 'phone-pad',
|
|
38
|
+
url: 'url',
|
|
39
|
+
number: 'numeric',
|
|
40
|
+
search: 'default',
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const styles = StyleSheet.create({
|
|
44
|
+
container: {
|
|
45
|
+
gap: spacing.xxs,
|
|
46
|
+
},
|
|
47
|
+
input: {
|
|
48
|
+
fontFamily: font.family.body,
|
|
49
|
+
fontSize: font.size.body,
|
|
50
|
+
lineHeight: lineHeight.body,
|
|
51
|
+
paddingHorizontal: spacing.s,
|
|
52
|
+
paddingVertical: spacing.xs,
|
|
53
|
+
borderWidth: 1,
|
|
54
|
+
borderRadius: border.radius.full,
|
|
55
|
+
minHeight: 44,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export function FormInput({
|
|
60
|
+
label,
|
|
61
|
+
name,
|
|
62
|
+
type = 'text',
|
|
63
|
+
value,
|
|
64
|
+
defaultValue,
|
|
65
|
+
placeholder,
|
|
66
|
+
error,
|
|
67
|
+
hint,
|
|
68
|
+
disabled = false,
|
|
69
|
+
onChange,
|
|
70
|
+
onBlur,
|
|
71
|
+
onFocus,
|
|
72
|
+
style,
|
|
73
|
+
}: Readonly<FormInputProps>) {
|
|
74
|
+
const { colors } = useTheme();
|
|
75
|
+
const [focused, setFocused] = useState(false);
|
|
76
|
+
|
|
77
|
+
const borderColor = error
|
|
78
|
+
? colors.colorError
|
|
79
|
+
: focused
|
|
80
|
+
? colors.colorInteractive
|
|
81
|
+
: colors.colorOnBg;
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<View style={[styles.container, style]}>
|
|
85
|
+
<Label label={label} />
|
|
86
|
+
<TextInput
|
|
87
|
+
accessibilityLabel={typeof label === 'string' ? label : name}
|
|
88
|
+
accessibilityState={{ disabled }}
|
|
89
|
+
accessibilityHint={hint}
|
|
90
|
+
value={value}
|
|
91
|
+
defaultValue={defaultValue}
|
|
92
|
+
placeholder={placeholder}
|
|
93
|
+
placeholderTextColor={colors.colorOnBgSubtle}
|
|
94
|
+
keyboardType={keyboardTypeMap[type]}
|
|
95
|
+
secureTextEntry={type === 'password'}
|
|
96
|
+
autoCapitalize={type === 'email' || type === 'url' ? 'none' : 'sentences'}
|
|
97
|
+
autoComplete={type === 'email' ? 'email' : type === 'tel' ? 'tel' : undefined}
|
|
98
|
+
editable={!disabled}
|
|
99
|
+
onChangeText={onChange}
|
|
100
|
+
onFocus={() => {
|
|
101
|
+
setFocused(true);
|
|
102
|
+
onFocus?.();
|
|
103
|
+
}}
|
|
104
|
+
onBlur={() => {
|
|
105
|
+
setFocused(false);
|
|
106
|
+
onBlur?.();
|
|
107
|
+
}}
|
|
108
|
+
style={[
|
|
109
|
+
styles.input,
|
|
110
|
+
{
|
|
111
|
+
borderColor,
|
|
112
|
+
color: colors.colorOnBg,
|
|
113
|
+
backgroundColor: colors.colorBg,
|
|
114
|
+
},
|
|
115
|
+
disabled && { opacity: 0.4 },
|
|
116
|
+
]}
|
|
117
|
+
/>
|
|
118
|
+
<Message type="error" message={error} />
|
|
119
|
+
<Message type="hint" message={hint} />
|
|
120
|
+
</View>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Meta, Canvas, ArgTypes } from '@storybook/blocks';
|
|
2
|
+
import * as Stories from './NumberInput.stories';
|
|
3
|
+
|
|
4
|
+
<Meta of={Stories} />
|
|
5
|
+
|
|
6
|
+
# NumberInput (React Native)
|
|
7
|
+
|
|
8
|
+
Numeric input with stepper buttons on each side. Supports min/max clamping, configurable step, and controlled or uncontrolled usage.
|
|
9
|
+
|
|
10
|
+
> **Status: alpha** — API may change before stable release.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import { NumberInput } from '@boostdev/design-system-components';
|
|
16
|
+
import { useState } from 'react';
|
|
17
|
+
|
|
18
|
+
function Example() {
|
|
19
|
+
const [qty, setQty] = useState(1);
|
|
20
|
+
return (
|
|
21
|
+
<NumberInput
|
|
22
|
+
label="Quantity"
|
|
23
|
+
name="qty"
|
|
24
|
+
value={qty}
|
|
25
|
+
min={1}
|
|
26
|
+
max={20}
|
|
27
|
+
onChange={setQty}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Examples
|
|
34
|
+
|
|
35
|
+
### Default
|
|
36
|
+
<Canvas of={Stories.Default} />
|
|
37
|
+
|
|
38
|
+
### With min and max
|
|
39
|
+
<Canvas of={Stories.WithMinMax} />
|
|
40
|
+
|
|
41
|
+
### With step
|
|
42
|
+
<Canvas of={Stories.WithStep} />
|
|
43
|
+
|
|
44
|
+
### At minimum
|
|
45
|
+
<Canvas of={Stories.AtMinimum} />
|
|
46
|
+
|
|
47
|
+
### At maximum
|
|
48
|
+
<Canvas of={Stories.AtMaximum} />
|
|
49
|
+
|
|
50
|
+
### With error
|
|
51
|
+
<Canvas of={Stories.WithError} />
|
|
52
|
+
|
|
53
|
+
### With hint
|
|
54
|
+
<Canvas of={Stories.WithHint} />
|
|
55
|
+
|
|
56
|
+
### Disabled
|
|
57
|
+
<Canvas of={Stories.Disabled} />
|
|
58
|
+
|
|
59
|
+
### Interactive
|
|
60
|
+
<Canvas of={Stories.Interactive} />
|
|
61
|
+
|
|
62
|
+
## Props
|
|
63
|
+
|
|
64
|
+
<ArgTypes of={Stories} />
|
|
65
|
+
|
|
66
|
+
## Props reference
|
|
67
|
+
|
|
68
|
+
| Prop | Type | Default | Description |
|
|
69
|
+
|------|------|---------|-------------|
|
|
70
|
+
| `label` | string | — | Visible label text |
|
|
71
|
+
| `name` | string | — | Field name |
|
|
72
|
+
| `value` | number | — | Controlled value |
|
|
73
|
+
| `defaultValue` | number | — | Uncontrolled default value (defaults to `0`) |
|
|
74
|
+
| `min` | number | — | Minimum allowed value |
|
|
75
|
+
| `max` | number | — | Maximum allowed value |
|
|
76
|
+
| `step` | number | `1` | Increment/decrement amount |
|
|
77
|
+
| `disabled` | boolean | `false` | Prevents interaction, reduces opacity |
|
|
78
|
+
| `error` | string | — | Error message displayed below the input |
|
|
79
|
+
| `hint` | string | — | Hint text displayed below the input |
|
|
80
|
+
| `onChange` | `(value: number) => void` | — | Called with the clamped value |
|
|
81
|
+
|
|
82
|
+
## Accessibility
|
|
83
|
+
|
|
84
|
+
- Decrease and Increase buttons have `accessibilityLabel` and `accessibilityRole="button"`
|
|
85
|
+
- Stepper buttons are automatically disabled at min/max boundaries
|
|
86
|
+
- `accessibilityValue` on the input provides `min`, `max`, `now`, and `text`
|
|
87
|
+
- `disabled` communicates the disabled state via `accessibilityState`
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { ThemeProvider } from '../../../../native/ThemeContext';
|
|
3
|
+
import { NumberInput } from './NumberInput';
|
|
4
|
+
|
|
5
|
+
function renderWithTheme(ui: React.ReactElement) {
|
|
6
|
+
return render(<ThemeProvider>{ui}</ThemeProvider>);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
describe('NumberInput (native)', () => {
|
|
10
|
+
it('renders the label', () => {
|
|
11
|
+
renderWithTheme(<NumberInput label="Quantity" name="qty" />);
|
|
12
|
+
expect(screen.getByText('Quantity')).toBeInTheDocument();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('renders the current value in the input', () => {
|
|
16
|
+
renderWithTheme(<NumberInput label="Quantity" name="qty" value={5} />);
|
|
17
|
+
expect(screen.getByDisplayValue('5')).toBeInTheDocument();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('renders decrease and increase buttons', () => {
|
|
21
|
+
renderWithTheme(<NumberInput label="Quantity" name="qty" value={5} />);
|
|
22
|
+
expect(screen.getByRole('button', { name: 'Decrease' })).toBeInTheDocument();
|
|
23
|
+
expect(screen.getByRole('button', { name: 'Increase' })).toBeInTheDocument();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('disables decrease button at min boundary', () => {
|
|
27
|
+
renderWithTheme(
|
|
28
|
+
<NumberInput label="Quantity" name="qty" value={0} min={0} max={10} />,
|
|
29
|
+
);
|
|
30
|
+
expect(screen.getByRole('button', { name: 'Decrease' })).toBeDisabled();
|
|
31
|
+
expect(screen.getByRole('button', { name: 'Increase' })).not.toBeDisabled();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('disables increase button at max boundary', () => {
|
|
35
|
+
renderWithTheme(
|
|
36
|
+
<NumberInput label="Quantity" name="qty" value={10} min={0} max={10} />,
|
|
37
|
+
);
|
|
38
|
+
expect(screen.getByRole('button', { name: 'Increase' })).toBeDisabled();
|
|
39
|
+
expect(screen.getByRole('button', { name: 'Decrease' })).not.toBeDisabled();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('shows error message', () => {
|
|
43
|
+
renderWithTheme(
|
|
44
|
+
<NumberInput label="Quantity" name="qty" error="Minimum is 1." />,
|
|
45
|
+
);
|
|
46
|
+
expect(screen.getByRole('alert')).toHaveTextContent('Minimum is 1.');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('shows hint message', () => {
|
|
50
|
+
renderWithTheme(
|
|
51
|
+
<NumberInput label="Guests" name="guests" hint="Including yourself." />,
|
|
52
|
+
);
|
|
53
|
+
expect(screen.getByText('Including yourself.')).toBeInTheDocument();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('disables all controls when disabled', () => {
|
|
57
|
+
renderWithTheme(
|
|
58
|
+
<NumberInput label="Quantity" name="qty" value={5} disabled />,
|
|
59
|
+
);
|
|
60
|
+
expect(screen.getByRole('button', { name: 'Decrease' })).toBeDisabled();
|
|
61
|
+
expect(screen.getByRole('button', { name: 'Increase' })).toBeDisabled();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
import { ThemeProvider } from '../../../../native/ThemeContext';
|
|
4
|
+
import { NumberInput } from './NumberInput';
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
tags: ['!stable', 'alpha'],
|
|
8
|
+
title: 'React Native/Form/NumberInput',
|
|
9
|
+
component: NumberInput,
|
|
10
|
+
decorators: [(Story) => <ThemeProvider colorScheme="light"><Story /></ThemeProvider>],
|
|
11
|
+
parameters: { layout: 'padded' },
|
|
12
|
+
} satisfies Meta<typeof NumberInput>;
|
|
13
|
+
|
|
14
|
+
export default meta;
|
|
15
|
+
type Story = StoryObj<typeof meta>;
|
|
16
|
+
|
|
17
|
+
export const Default: Story = {
|
|
18
|
+
args: { label: 'Quantity', name: 'qty', value: 1 },
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const WithMinMax: Story = {
|
|
22
|
+
args: { label: 'Quantity', name: 'qty', value: 1, min: 0, max: 10 },
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const WithStep: Story = {
|
|
26
|
+
args: { label: 'Amount', name: 'amount', value: 0, step: 5, min: 0, max: 100 },
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const AtMinimum: Story = {
|
|
30
|
+
args: { label: 'Quantity', name: 'qty', value: 0, min: 0, max: 10 },
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const AtMaximum: Story = {
|
|
34
|
+
args: { label: 'Quantity', name: 'qty', value: 10, min: 0, max: 10 },
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const WithError: Story = {
|
|
38
|
+
args: { label: 'Quantity', name: 'qty', value: 0, error: 'Minimum quantity is 1.' },
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const WithHint: Story = {
|
|
42
|
+
args: { label: 'Guests', name: 'guests', value: 2, hint: 'Including yourself.' },
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const Disabled: Story = {
|
|
46
|
+
args: { label: 'Quantity', name: 'qty', value: 3, disabled: true },
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const Interactive: Story = {
|
|
50
|
+
render: () => {
|
|
51
|
+
const [value, setValue] = useState(1);
|
|
52
|
+
return (
|
|
53
|
+
<NumberInput
|
|
54
|
+
label="Guests"
|
|
55
|
+
name="guests"
|
|
56
|
+
value={value}
|
|
57
|
+
min={1}
|
|
58
|
+
max={20}
|
|
59
|
+
onChange={setValue}
|
|
60
|
+
/>
|
|
61
|
+
);
|
|
62
|
+
},
|
|
63
|
+
};
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
StyleSheet,
|
|
4
|
+
View,
|
|
5
|
+
TextInput,
|
|
6
|
+
Text,
|
|
7
|
+
Pressable,
|
|
8
|
+
StyleProp,
|
|
9
|
+
ViewStyle,
|
|
10
|
+
} from 'react-native';
|
|
11
|
+
import { spacing, font, border, lineHeight } from '../../../../native/tokens';
|
|
12
|
+
import { useTheme } from '../../../../native/ThemeContext';
|
|
13
|
+
import { Label } from '../atoms/Label';
|
|
14
|
+
import { Message } from '../atoms/Message';
|
|
15
|
+
|
|
16
|
+
interface NumberInputProps {
|
|
17
|
+
label: string;
|
|
18
|
+
name: string;
|
|
19
|
+
value?: number;
|
|
20
|
+
defaultValue?: number;
|
|
21
|
+
min?: number;
|
|
22
|
+
max?: number;
|
|
23
|
+
step?: number;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
error?: string;
|
|
26
|
+
hint?: string;
|
|
27
|
+
onChange?: (value: number) => void;
|
|
28
|
+
style?: StyleProp<ViewStyle>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const STEPPER_SIZE = 44;
|
|
32
|
+
|
|
33
|
+
const styles = StyleSheet.create({
|
|
34
|
+
container: {
|
|
35
|
+
gap: spacing.xxs,
|
|
36
|
+
},
|
|
37
|
+
inputRow: {
|
|
38
|
+
flexDirection: 'row',
|
|
39
|
+
alignItems: 'center',
|
|
40
|
+
},
|
|
41
|
+
stepper: {
|
|
42
|
+
width: STEPPER_SIZE,
|
|
43
|
+
height: STEPPER_SIZE,
|
|
44
|
+
alignItems: 'center',
|
|
45
|
+
justifyContent: 'center',
|
|
46
|
+
borderWidth: 1,
|
|
47
|
+
},
|
|
48
|
+
stepperStart: {
|
|
49
|
+
borderTopStartRadius: border.radius.full,
|
|
50
|
+
borderBottomStartRadius: border.radius.full,
|
|
51
|
+
borderEndWidth: 0,
|
|
52
|
+
},
|
|
53
|
+
stepperEnd: {
|
|
54
|
+
borderTopEndRadius: border.radius.full,
|
|
55
|
+
borderBottomEndRadius: border.radius.full,
|
|
56
|
+
borderStartWidth: 0,
|
|
57
|
+
},
|
|
58
|
+
stepperText: {
|
|
59
|
+
fontSize: 20,
|
|
60
|
+
fontWeight: font.weight.semibold,
|
|
61
|
+
lineHeight: 24,
|
|
62
|
+
},
|
|
63
|
+
input: {
|
|
64
|
+
flex: 1,
|
|
65
|
+
fontFamily: font.family.body,
|
|
66
|
+
fontSize: font.size.body,
|
|
67
|
+
lineHeight: lineHeight.body,
|
|
68
|
+
textAlign: 'center',
|
|
69
|
+
paddingHorizontal: spacing.xs,
|
|
70
|
+
paddingVertical: spacing.xs,
|
|
71
|
+
borderTopWidth: 1,
|
|
72
|
+
borderBottomWidth: 1,
|
|
73
|
+
minHeight: STEPPER_SIZE,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
export function NumberInput({
|
|
78
|
+
label,
|
|
79
|
+
name: _name, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
80
|
+
value,
|
|
81
|
+
defaultValue,
|
|
82
|
+
min,
|
|
83
|
+
max,
|
|
84
|
+
step = 1,
|
|
85
|
+
disabled = false,
|
|
86
|
+
error,
|
|
87
|
+
hint,
|
|
88
|
+
onChange,
|
|
89
|
+
style,
|
|
90
|
+
}: Readonly<NumberInputProps>) {
|
|
91
|
+
const { colors } = useTheme();
|
|
92
|
+
const isControlled = value !== undefined;
|
|
93
|
+
const [internalValue, setInternalValue] = useState(defaultValue ?? 0);
|
|
94
|
+
|
|
95
|
+
const currentValue = isControlled ? value : internalValue;
|
|
96
|
+
|
|
97
|
+
const clamp = (v: number): number => {
|
|
98
|
+
const withMin = min !== undefined ? Math.max(min, v) : v;
|
|
99
|
+
return max !== undefined ? Math.min(max, withMin) : withMin;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const update = (next: number) => {
|
|
103
|
+
const clamped = clamp(next);
|
|
104
|
+
if (!isControlled) setInternalValue(clamped);
|
|
105
|
+
onChange?.(clamped);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const canDecrease = min === undefined || currentValue > min;
|
|
109
|
+
const canIncrease = max === undefined || currentValue < max;
|
|
110
|
+
|
|
111
|
+
const borderColor = error ? colors.colorError : colors.colorOnBg;
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<View style={[styles.container, style]}>
|
|
115
|
+
<Label label={label} />
|
|
116
|
+
<View style={[styles.inputRow, disabled && { opacity: 0.4 }]}>
|
|
117
|
+
<Pressable
|
|
118
|
+
accessibilityRole="button"
|
|
119
|
+
accessibilityLabel="Decrease"
|
|
120
|
+
accessibilityState={{ disabled: disabled || !canDecrease }}
|
|
121
|
+
disabled={disabled || !canDecrease}
|
|
122
|
+
onPress={() => update(currentValue - step)}
|
|
123
|
+
style={({ pressed }) => [
|
|
124
|
+
styles.stepper,
|
|
125
|
+
styles.stepperStart,
|
|
126
|
+
{
|
|
127
|
+
borderColor,
|
|
128
|
+
backgroundColor: colors.colorBgSubtle,
|
|
129
|
+
},
|
|
130
|
+
pressed && { opacity: 0.7 },
|
|
131
|
+
(disabled || !canDecrease) && { opacity: 0.4 },
|
|
132
|
+
]}
|
|
133
|
+
>
|
|
134
|
+
<Text
|
|
135
|
+
style={[styles.stepperText, { color: colors.colorOnBg }]}
|
|
136
|
+
aria-hidden
|
|
137
|
+
>
|
|
138
|
+
{'\u2212'}
|
|
139
|
+
</Text>
|
|
140
|
+
</Pressable>
|
|
141
|
+
|
|
142
|
+
<TextInput
|
|
143
|
+
accessibilityLabel={label}
|
|
144
|
+
accessibilityState={{ disabled }}
|
|
145
|
+
accessibilityValue={{
|
|
146
|
+
min,
|
|
147
|
+
max,
|
|
148
|
+
now: currentValue,
|
|
149
|
+
text: String(currentValue),
|
|
150
|
+
}}
|
|
151
|
+
keyboardType="numeric"
|
|
152
|
+
value={String(currentValue)}
|
|
153
|
+
editable={!disabled}
|
|
154
|
+
onChangeText={(text) => {
|
|
155
|
+
const parsed = parseFloat(text);
|
|
156
|
+
const safe = isNaN(parsed) ? 0 : parsed;
|
|
157
|
+
update(safe);
|
|
158
|
+
}}
|
|
159
|
+
style={[
|
|
160
|
+
styles.input,
|
|
161
|
+
{
|
|
162
|
+
borderColor,
|
|
163
|
+
color: colors.colorOnBg,
|
|
164
|
+
backgroundColor: colors.colorBg,
|
|
165
|
+
},
|
|
166
|
+
]}
|
|
167
|
+
/>
|
|
168
|
+
|
|
169
|
+
<Pressable
|
|
170
|
+
accessibilityRole="button"
|
|
171
|
+
accessibilityLabel="Increase"
|
|
172
|
+
accessibilityState={{ disabled: disabled || !canIncrease }}
|
|
173
|
+
disabled={disabled || !canIncrease}
|
|
174
|
+
onPress={() => update(currentValue + step)}
|
|
175
|
+
style={({ pressed }) => [
|
|
176
|
+
styles.stepper,
|
|
177
|
+
styles.stepperEnd,
|
|
178
|
+
{
|
|
179
|
+
borderColor,
|
|
180
|
+
backgroundColor: colors.colorBgSubtle,
|
|
181
|
+
},
|
|
182
|
+
pressed && { opacity: 0.7 },
|
|
183
|
+
(disabled || !canIncrease) && { opacity: 0.4 },
|
|
184
|
+
]}
|
|
185
|
+
>
|
|
186
|
+
<Text
|
|
187
|
+
style={[styles.stepperText, { color: colors.colorOnBg }]}
|
|
188
|
+
aria-hidden
|
|
189
|
+
>
|
|
190
|
+
+
|
|
191
|
+
</Text>
|
|
192
|
+
</Pressable>
|
|
193
|
+
</View>
|
|
194
|
+
<Message type="error" message={error} />
|
|
195
|
+
<Message type="hint" message={hint} />
|
|
196
|
+
</View>
|
|
197
|
+
);
|
|
198
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
2
|
+
import { ThemeProvider } from '../../../../native/ThemeContext';
|
|
3
|
+
import { Radio } from './Radio';
|
|
4
|
+
|
|
5
|
+
function renderWithTheme(ui: React.ReactElement) {
|
|
6
|
+
return render(<ThemeProvider>{ui}</ThemeProvider>);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
describe('Radio (native)', () => {
|
|
10
|
+
it('has radio role with label', () => {
|
|
11
|
+
renderWithTheme(<Radio label="Option A" name="choice" />);
|
|
12
|
+
expect(screen.getByRole('radio', { name: 'Option A' })).toBeInTheDocument();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('renders unchecked by default (no inner dot)', () => {
|
|
16
|
+
renderWithTheme(<Radio label="Option A" name="choice" />);
|
|
17
|
+
// The outer circle is always present; the inner dot only renders when checked
|
|
18
|
+
const radio = screen.getByRole('radio');
|
|
19
|
+
// When unchecked, the inner filled circle should not be rendered
|
|
20
|
+
// The outer has 1 child (no inner dot) vs 2 when checked
|
|
21
|
+
expect(radio).toBeInTheDocument();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('renders inner dot when checked', () => {
|
|
25
|
+
const { container: uncheckedContainer } = renderWithTheme(
|
|
26
|
+
<Radio label="Unchecked" name="choice" />,
|
|
27
|
+
);
|
|
28
|
+
const { container: checkedContainer } = renderWithTheme(
|
|
29
|
+
<Radio label="Checked" name="choice" checked />,
|
|
30
|
+
);
|
|
31
|
+
// The checked variant has more DOM nodes (the inner filled circle)
|
|
32
|
+
expect(checkedContainer.innerHTML.length).toBeGreaterThan(
|
|
33
|
+
uncheckedContainer.innerHTML.length,
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('reflects disabled state', () => {
|
|
38
|
+
renderWithTheme(<Radio label="Option A" name="choice" disabled />);
|
|
39
|
+
const radio = screen.getByRole('radio');
|
|
40
|
+
expect(radio).toHaveAttribute('aria-disabled', 'true');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('calls onChange when clicked', () => {
|
|
44
|
+
const handleChange = vi.fn();
|
|
45
|
+
renderWithTheme(
|
|
46
|
+
<Radio label="Option A" name="choice" onChange={handleChange} />,
|
|
47
|
+
);
|
|
48
|
+
fireEvent.click(screen.getByRole('radio'));
|
|
49
|
+
expect(handleChange).toHaveBeenCalledTimes(1);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('does not call onChange when disabled', () => {
|
|
53
|
+
const handleChange = vi.fn();
|
|
54
|
+
renderWithTheme(
|
|
55
|
+
<Radio label="Option A" name="choice" disabled onChange={handleChange} />,
|
|
56
|
+
);
|
|
57
|
+
fireEvent.click(screen.getByRole('radio'));
|
|
58
|
+
expect(handleChange).not.toHaveBeenCalled();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('renders error message', () => {
|
|
62
|
+
renderWithTheme(
|
|
63
|
+
<Radio label="Option A" name="choice" error="Selection required." />,
|
|
64
|
+
);
|
|
65
|
+
expect(screen.getByRole('alert')).toHaveTextContent('Selection required.');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('renders hint message', () => {
|
|
69
|
+
renderWithTheme(
|
|
70
|
+
<Radio label="Option A" name="choice" hint="Select your preference." />,
|
|
71
|
+
);
|
|
72
|
+
expect(screen.getByText('Select your preference.')).toBeInTheDocument();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('uses name as accessibility label when label is not a string', () => {
|
|
76
|
+
renderWithTheme(<Radio label={<span>Custom</span>} name="fallback" />);
|
|
77
|
+
expect(screen.getByRole('radio', { name: 'fallback' })).toBeInTheDocument();
|
|
78
|
+
});
|
|
79
|
+
});
|