@boostdev/design-system-components 1.2.3 → 1.2.5
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/AGENTS.md +19 -11
- package/README.md +36 -1
- package/dist/client.cjs +50 -50
- package/dist/client.css +470 -470
- package/dist/client.js +50 -50
- package/dist/index.cjs +50 -50
- package/dist/index.css +470 -470
- package/dist/index.js +50 -50
- package/dist/native/index.cjs +3692 -352
- package/dist/native/index.d.cts +359 -3
- package/dist/native/index.d.ts +359 -3
- package/dist/native/index.js +3811 -364
- package/dist/utils.cjs +30 -0
- package/dist/utils.d.cts +8 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.js +5 -0
- package/package.json +10 -4
- package/src/client.ts +6 -0
- package/src/components/interaction/Button/Button.native.stories.tsx +10 -12
- package/src/components/interaction/Button/Button.native.tsx +3 -3
- package/src/components/interaction/Dialog/Dialog.native.mdx +61 -0
- package/src/components/interaction/Dialog/Dialog.native.spec.tsx +73 -0
- package/src/components/interaction/Dialog/Dialog.native.stories.tsx +53 -0
- package/src/components/interaction/Dialog/Dialog.native.tsx +128 -0
- package/src/components/interaction/Drawer/Drawer.native.mdx +58 -0
- package/src/components/interaction/Drawer/Drawer.native.spec.tsx +81 -0
- package/src/components/interaction/Drawer/Drawer.native.stories.tsx +33 -0
- package/src/components/interaction/Drawer/Drawer.native.tsx +175 -0
- package/src/components/interaction/DropdownMenu/DropdownMenu.native.mdx +74 -0
- package/src/components/interaction/DropdownMenu/DropdownMenu.native.spec.tsx +78 -0
- package/src/components/interaction/DropdownMenu/DropdownMenu.native.stories.tsx +51 -0
- package/src/components/interaction/DropdownMenu/DropdownMenu.native.tsx +254 -0
- package/src/components/interaction/Popover/Popover.native.mdx +61 -0
- package/src/components/interaction/Popover/Popover.native.spec.tsx +73 -0
- package/src/components/interaction/Popover/Popover.native.stories.tsx +44 -0
- package/src/components/interaction/Popover/Popover.native.tsx +87 -0
- package/src/components/interaction/Rating/Rating.native.mdx +55 -0
- package/src/components/interaction/Rating/Rating.native.spec.tsx +38 -0
- package/src/components/interaction/Rating/Rating.native.stories.tsx +37 -0
- package/src/components/interaction/Rating/Rating.native.tsx +50 -0
- package/src/components/interaction/Toast/Toast.native.mdx +81 -0
- package/src/components/interaction/Toast/Toast.native.spec.tsx +80 -0
- package/src/components/interaction/Toast/Toast.native.stories.tsx +47 -0
- package/src/components/interaction/Toast/Toast.native.tsx +202 -0
- package/src/components/interaction/form/Checkbox/Checkbox.native.stories.tsx +2 -4
- package/src/components/interaction/form/Checkbox/Checkbox.native.tsx +1 -1
- package/src/components/interaction/form/CheckboxGroup/CheckboxGroup.native.mdx +78 -0
- package/src/components/interaction/form/CheckboxGroup/CheckboxGroup.native.spec.tsx +57 -0
- package/src/components/interaction/form/CheckboxGroup/CheckboxGroup.native.stories.tsx +96 -0
- package/src/components/interaction/form/CheckboxGroup/CheckboxGroup.native.tsx +61 -0
- package/src/components/interaction/form/Combobox/Combobox.native.mdx +86 -0
- package/src/components/interaction/form/Combobox/Combobox.native.spec.tsx +60 -0
- package/src/components/interaction/form/Combobox/Combobox.native.stories.tsx +99 -0
- package/src/components/interaction/form/Combobox/Combobox.native.tsx +211 -0
- package/src/components/interaction/form/FileInput/FileInput.native.mdx +86 -0
- package/src/components/interaction/form/FileInput/FileInput.native.spec.tsx +73 -0
- package/src/components/interaction/form/FileInput/FileInput.native.stories.tsx +69 -0
- package/src/components/interaction/form/FileInput/FileInput.native.tsx +129 -0
- package/src/components/interaction/form/FormInput/FormInput.native.mdx +81 -0
- package/src/components/interaction/form/FormInput/FormInput.native.spec.tsx +51 -0
- package/src/components/interaction/form/FormInput/FormInput.native.stories.tsx +54 -0
- package/src/components/interaction/form/FormInput/FormInput.native.tsx +122 -0
- package/src/components/interaction/form/NumberInput/NumberInput.native.mdx +87 -0
- package/src/components/interaction/form/NumberInput/NumberInput.native.spec.tsx +63 -0
- package/src/components/interaction/form/NumberInput/NumberInput.native.stories.tsx +63 -0
- package/src/components/interaction/form/NumberInput/NumberInput.native.tsx +198 -0
- package/src/components/interaction/form/Radio/Radio.native.spec.tsx +79 -0
- package/src/components/interaction/form/Radio/Radio.native.stories.tsx +12 -14
- package/src/components/interaction/form/Radio/Radio.native.tsx +1 -1
- package/src/components/interaction/form/RadioGroup/RadioGroup.native.mdx +79 -0
- package/src/components/interaction/form/RadioGroup/RadioGroup.native.spec.tsx +66 -0
- package/src/components/interaction/form/RadioGroup/RadioGroup.native.stories.tsx +96 -0
- package/src/components/interaction/form/RadioGroup/RadioGroup.native.tsx +61 -0
- package/src/components/interaction/form/SegmentedControl/SegmentedControl.native.mdx +78 -0
- package/src/components/interaction/form/SegmentedControl/SegmentedControl.native.spec.tsx +82 -0
- package/src/components/interaction/form/SegmentedControl/SegmentedControl.native.stories.tsx +99 -0
- package/src/components/interaction/form/SegmentedControl/SegmentedControl.native.tsx +121 -0
- package/src/components/interaction/form/Select/Select.native.mdx +85 -0
- package/src/components/interaction/form/Select/Select.native.spec.tsx +64 -0
- package/src/components/interaction/form/Select/Select.native.stories.tsx +75 -0
- package/src/components/interaction/form/Select/Select.native.tsx +252 -0
- package/src/components/interaction/form/Slider/Slider.native.mdx +83 -0
- package/src/components/interaction/form/Slider/Slider.native.spec.tsx +51 -0
- package/src/components/interaction/form/Slider/Slider.native.stories.tsx +58 -0
- package/src/components/interaction/form/Slider/Slider.native.tsx +188 -0
- package/src/components/interaction/form/Switch/Switch.native.stories.tsx +2 -4
- package/src/components/interaction/form/Textarea/Textarea.native.mdx +76 -0
- package/src/components/interaction/form/Textarea/Textarea.native.spec.tsx +50 -0
- package/src/components/interaction/form/Textarea/Textarea.native.stories.tsx +50 -0
- package/src/components/interaction/form/Textarea/Textarea.native.tsx +108 -0
- package/src/components/interaction/form/atoms/Label.native.spec.tsx +39 -0
- package/src/components/interaction/form/atoms/Label.native.stories.tsx +1 -1
- package/src/components/interaction/form/atoms/Message.native.stories.tsx +1 -1
- package/src/components/layout/ButtonGroup/ButtonGroup.native.spec.tsx +83 -0
- package/src/components/layout/ButtonGroup/ButtonGroup.native.stories.tsx +13 -19
- package/src/components/layout/Card/Card.native.spec.tsx +102 -0
- package/src/components/layout/Card/Card.native.stories.tsx +9 -11
- package/src/components/layout/Card/Card.native.tsx +1 -1
- package/src/components/layout/IconWrapper/IconWrapper.native.stories.tsx +7 -11
- package/src/components/layout/SectionHeader/SectionHeader.native.spec.tsx +51 -0
- package/src/components/layout/SectionHeader/SectionHeader.native.stories.tsx +6 -8
- package/src/components/ui/Accordion/Accordion.native.mdx +65 -0
- package/src/components/ui/Accordion/Accordion.native.spec.tsx +69 -0
- package/src/components/ui/Accordion/Accordion.native.stories.tsx +52 -0
- package/src/components/ui/Accordion/Accordion.native.tsx +141 -0
- package/src/components/ui/Alert/Alert.native.spec.tsx +76 -0
- package/src/components/ui/Alert/Alert.native.stories.tsx +8 -10
- package/src/components/ui/Alert/Alert.native.tsx +7 -7
- package/src/components/ui/Avatar/Avatar.native.stories.tsx +6 -8
- package/src/components/ui/Avatar/Avatar.native.tsx +2 -2
- package/src/components/ui/Badge/Badge.native.spec.tsx +45 -0
- package/src/components/ui/Badge/Badge.native.stories.tsx +6 -8
- package/src/components/ui/Badge/Badge.native.tsx +2 -2
- package/src/components/ui/Breadcrumb/Breadcrumb.native.mdx +52 -0
- package/src/components/ui/Breadcrumb/Breadcrumb.native.spec.tsx +49 -0
- package/src/components/ui/Breadcrumb/Breadcrumb.native.stories.tsx +46 -0
- package/src/components/ui/Breadcrumb/Breadcrumb.native.tsx +83 -0
- package/src/components/ui/Calendar/Calendar.native.mdx +58 -0
- package/src/components/ui/Calendar/Calendar.native.spec.tsx +92 -0
- package/src/components/ui/Calendar/Calendar.native.stories.tsx +45 -0
- package/src/components/ui/Calendar/Calendar.native.tsx +294 -0
- package/src/components/ui/Carousel/Carousel.native.mdx +55 -0
- package/src/components/ui/Carousel/Carousel.native.spec.tsx +55 -0
- package/src/components/ui/Carousel/Carousel.native.stories.tsx +59 -0
- package/src/components/ui/Carousel/Carousel.native.tsx +184 -0
- package/src/components/ui/Collapsible/Collapsible.native.mdx +53 -0
- package/src/components/ui/Collapsible/Collapsible.native.spec.tsx +68 -0
- package/src/components/ui/Collapsible/Collapsible.native.stories.tsx +48 -0
- package/src/components/ui/Collapsible/Collapsible.native.tsx +139 -0
- package/src/components/ui/DescriptionList/DescriptionList.native.mdx +50 -0
- package/src/components/ui/DescriptionList/DescriptionList.native.spec.tsx +37 -0
- package/src/components/ui/DescriptionList/DescriptionList.native.stories.tsx +48 -0
- package/src/components/ui/DescriptionList/DescriptionList.native.tsx +54 -0
- package/src/components/ui/Link/Link.native.mdx +53 -0
- package/src/components/ui/Link/Link.native.spec.tsx +35 -0
- package/src/components/ui/Link/Link.native.stories.tsx +46 -0
- package/src/components/ui/Link/Link.native.tsx +48 -0
- package/src/components/ui/Loading/Loading.native.stories.tsx +6 -8
- package/src/components/ui/NotificationBanner/NotificationBanner.native.spec.tsx +85 -0
- package/src/components/ui/NotificationBanner/NotificationBanner.native.stories.tsx +8 -10
- package/src/components/ui/NotificationBanner/NotificationBanner.native.tsx +7 -7
- package/src/components/ui/Pagination/Pagination.native.mdx +62 -0
- package/src/components/ui/Pagination/Pagination.native.spec.tsx +86 -0
- package/src/components/ui/Pagination/Pagination.native.stories.tsx +47 -0
- package/src/components/ui/Pagination/Pagination.native.tsx +157 -0
- package/src/components/ui/Progress/Progress.native.spec.tsx +56 -0
- package/src/components/ui/Progress/Progress.native.stories.tsx +1 -1
- package/src/components/ui/Progress/Progress.native.tsx +2 -2
- package/src/components/ui/ProgressCircle/ProgressCircle.native.mdx +63 -0
- package/src/components/ui/ProgressCircle/ProgressCircle.native.spec.tsx +39 -0
- package/src/components/ui/ProgressCircle/ProgressCircle.native.stories.tsx +36 -0
- package/src/components/ui/ProgressCircle/ProgressCircle.native.tsx +176 -0
- package/src/components/ui/Separator/Separator.native.spec.tsx +39 -0
- package/src/components/ui/Separator/Separator.native.stories.tsx +10 -14
- package/src/components/ui/Skeleton/Skeleton.native.spec.tsx +39 -0
- package/src/components/ui/Skeleton/Skeleton.native.stories.tsx +6 -8
- package/src/components/ui/Skeleton/Skeleton.native.tsx +2 -1
- package/src/components/ui/Table/Table.native.mdx +72 -0
- package/src/components/ui/Table/Table.native.spec.tsx +83 -0
- package/src/components/ui/Table/Table.native.stories.tsx +55 -0
- package/src/components/ui/Table/Table.native.tsx +196 -0
- package/src/components/ui/Tabs/Tabs.native.mdx +65 -0
- package/src/components/ui/Tabs/Tabs.native.spec.tsx +65 -0
- package/src/components/ui/Tabs/Tabs.native.stories.tsx +57 -0
- package/src/components/ui/Tabs/Tabs.native.tsx +133 -0
- package/src/components/ui/Tooltip/Tooltip.native.mdx +47 -0
- package/src/components/ui/Tooltip/Tooltip.native.spec.tsx +37 -0
- package/src/components/ui/Tooltip/Tooltip.native.stories.tsx +38 -0
- package/src/components/ui/Tooltip/Tooltip.native.tsx +57 -0
- package/src/components/ui/Typography/Typography.native.spec.tsx +49 -0
- package/src/components/ui/Typography/Typography.native.stories.tsx +8 -10
- package/src/native/ThemeContext.tsx +3 -3
- package/src/native.ts +37 -0
- package/src/stories/ReactNative.mdx +48 -13
- package/src/utils.ts +6 -0
- package/src/web-components/interaction/BdsAccordion.stories.tsx +1 -1
- package/src/web-components/interaction/BdsCollapsible.stories.tsx +1 -1
- package/src/web-components/interaction/BdsSkipLink.stories.tsx +1 -1
- package/src/web-components/interaction/BdsTabs.stories.tsx +1 -1
- package/src/web-components/interaction/BdsTooltip.stories.tsx +1 -1
- package/src/web-components/interaction/form/BdsCheckbox.stories.tsx +1 -1
- package/src/web-components/interaction/form/BdsCheckboxGroup.stories.tsx +1 -1
- package/src/web-components/interaction/form/BdsCombobox.stories.tsx +1 -1
- package/src/web-components/interaction/form/BdsFileInput.stories.tsx +1 -1
- package/src/web-components/interaction/form/BdsFormInput.stories.tsx +1 -1
- package/src/web-components/interaction/form/BdsNumberInput.stories.tsx +1 -1
- package/src/web-components/interaction/form/BdsRadio.stories.tsx +1 -1
- package/src/web-components/interaction/form/BdsRadioGroup.stories.tsx +1 -1
- package/src/web-components/interaction/form/BdsSegmentedControl.stories.tsx +1 -1
- package/src/web-components/interaction/form/BdsSelect.stories.tsx +1 -1
- package/src/web-components/interaction/form/BdsSlider.stories.tsx +1 -1
- package/src/web-components/interaction/form/BdsSwitch.stories.tsx +1 -1
- package/src/web-components/interaction/form/BdsTextarea.stories.tsx +1 -1
- package/src/web-components/ui/BdsButtonGroup.stories.tsx +1 -1
- package/src/web-components/ui/BdsCard.stories.tsx +1 -1
- package/src/web-components/ui/BdsIconWrapper.stories.tsx +1 -1
- package/src/web-components/ui/BdsRating.stories.tsx +1 -1
- package/src/web-components/ui/BdsSectionHeader.stories.tsx +1 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Meta, Canvas, ArgTypes } from '@storybook/blocks';
|
|
2
|
+
import * as Stories from './FormInput.native.stories';
|
|
3
|
+
|
|
4
|
+
<Meta of={Stories} />
|
|
5
|
+
|
|
6
|
+
# FormInput (React Native)
|
|
7
|
+
|
|
8
|
+
Text input field with label, optional hint, and error state. Maps the `type` prop to the appropriate keyboard type and secure text entry mode.
|
|
9
|
+
|
|
10
|
+
> **Status: alpha** — API may change before stable release.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import { FormInput } from '@boostdev/components';
|
|
16
|
+
import { useState } from 'react';
|
|
17
|
+
|
|
18
|
+
function Example() {
|
|
19
|
+
const [email, setEmail] = useState('');
|
|
20
|
+
return (
|
|
21
|
+
<FormInput
|
|
22
|
+
label="Email"
|
|
23
|
+
name="email"
|
|
24
|
+
type="email"
|
|
25
|
+
placeholder="you@example.com"
|
|
26
|
+
value={email}
|
|
27
|
+
onChange={setEmail}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Examples
|
|
34
|
+
|
|
35
|
+
### Default
|
|
36
|
+
<Canvas of={Stories.Default} />
|
|
37
|
+
|
|
38
|
+
### With placeholder
|
|
39
|
+
<Canvas of={Stories.WithPlaceholder} />
|
|
40
|
+
|
|
41
|
+
### Password
|
|
42
|
+
<Canvas of={Stories.Password} />
|
|
43
|
+
|
|
44
|
+
### With error
|
|
45
|
+
<Canvas of={Stories.WithError} />
|
|
46
|
+
|
|
47
|
+
### With hint
|
|
48
|
+
<Canvas of={Stories.WithHint} />
|
|
49
|
+
|
|
50
|
+
### Disabled
|
|
51
|
+
<Canvas of={Stories.Disabled} />
|
|
52
|
+
|
|
53
|
+
### Interactive
|
|
54
|
+
<Canvas of={Stories.Interactive} />
|
|
55
|
+
|
|
56
|
+
## Props
|
|
57
|
+
|
|
58
|
+
<ArgTypes of={Stories} />
|
|
59
|
+
|
|
60
|
+
## Props reference
|
|
61
|
+
|
|
62
|
+
| Prop | Type | Default | Description |
|
|
63
|
+
|------|------|---------|-------------|
|
|
64
|
+
| `label` | ReactNode | — | Visible label text |
|
|
65
|
+
| `name` | string | — | Field name (used for accessibility) |
|
|
66
|
+
| `type` | `'text' \| 'email' \| 'password' \| 'tel' \| 'url' \| 'number' \| 'search'` | `'text'` | Input type, maps to keyboard type |
|
|
67
|
+
| `value` | string | — | Controlled value |
|
|
68
|
+
| `defaultValue` | string | — | Uncontrolled default value |
|
|
69
|
+
| `placeholder` | string | — | Placeholder text |
|
|
70
|
+
| `error` | string | — | Error message displayed below the input |
|
|
71
|
+
| `hint` | string | — | Hint text displayed below the input |
|
|
72
|
+
| `required` | boolean | `false` | Marks the field as required |
|
|
73
|
+
| `disabled` | boolean | `false` | Prevents interaction, reduces opacity |
|
|
74
|
+
| `onChange` | `(value: string) => void` | — | Called with the new text value |
|
|
75
|
+
|
|
76
|
+
## Accessibility
|
|
77
|
+
|
|
78
|
+
- The label is announced by screen readers via `accessibilityLabel`
|
|
79
|
+
- Hint text is announced via `accessibilityHint`
|
|
80
|
+
- `disabled` communicates the disabled state via `accessibilityState`
|
|
81
|
+
- Password type uses `secureTextEntry` for input masking
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { ThemeProvider } from '../../../../native/ThemeContext';
|
|
3
|
+
import { FormInput } from './FormInput.native';
|
|
4
|
+
|
|
5
|
+
function renderWithTheme(ui: React.ReactElement) {
|
|
6
|
+
return render(<ThemeProvider>{ui}</ThemeProvider>);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
describe('FormInput (native)', () => {
|
|
10
|
+
it('renders the label', () => {
|
|
11
|
+
renderWithTheme(<FormInput label="Full name" name="fullName" />);
|
|
12
|
+
expect(screen.getByText('Full name')).toBeInTheDocument();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('renders with placeholder text', () => {
|
|
16
|
+
renderWithTheme(
|
|
17
|
+
<FormInput label="Email" name="email" placeholder="you@example.com" />,
|
|
18
|
+
);
|
|
19
|
+
expect(screen.getByPlaceholderText('you@example.com')).toBeInTheDocument();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('renders with a value', () => {
|
|
23
|
+
renderWithTheme(
|
|
24
|
+
<FormInput label="Name" name="name" value="Jane" />,
|
|
25
|
+
);
|
|
26
|
+
expect(screen.getByDisplayValue('Jane')).toBeInTheDocument();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('shows error message', () => {
|
|
30
|
+
renderWithTheme(
|
|
31
|
+
<FormInput label="Email" name="email" error="Invalid email." />,
|
|
32
|
+
);
|
|
33
|
+
expect(screen.getByRole('alert')).toHaveTextContent('Invalid email.');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('shows hint message', () => {
|
|
37
|
+
renderWithTheme(
|
|
38
|
+
<FormInput label="Username" name="username" hint="At least 3 characters." />,
|
|
39
|
+
);
|
|
40
|
+
expect(screen.getByText('At least 3 characters.')).toBeInTheDocument();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('applies disabled opacity', () => {
|
|
44
|
+
const { container } = renderWithTheme(
|
|
45
|
+
<FormInput label="Name" name="name" disabled />,
|
|
46
|
+
);
|
|
47
|
+
// The TextInput should have opacity 0.4 when disabled
|
|
48
|
+
const inputs = container.querySelectorAll('input, [style*="opacity"]');
|
|
49
|
+
expect(inputs.length).toBeGreaterThan(0);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -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.native';
|
|
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.native';
|
|
13
|
+
import { Message } from '../atoms/Message.native';
|
|
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.native.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/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.native';
|
|
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.native';
|
|
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
|
+
};
|