@boostdev/design-system-react-native 0.1.0 → 0.2.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/CHANGELOG.md +55 -0
- package/LICENSE +15 -0
- package/README.md +104 -2
- package/dist/index.cjs +106 -60
- package/dist/index.d.cts +61 -6
- package/dist/index.d.ts +61 -6
- package/dist/index.js +106 -60
- 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 +212 -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 +81 -0
- package/src/components/interaction/form/FormInput/FormInput.stories.tsx +54 -0
- package/src/components/interaction/form/FormInput/FormInput.tsx +123 -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 +199 -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,99 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
import { ThemeProvider } from '../../../../native/ThemeContext';
|
|
4
|
+
import { SegmentedControl } from './SegmentedControl';
|
|
5
|
+
|
|
6
|
+
const meta = {
|
|
7
|
+
tags: ['!stable', 'alpha'],
|
|
8
|
+
title: 'React Native/Form/SegmentedControl',
|
|
9
|
+
component: SegmentedControl,
|
|
10
|
+
decorators: [(Story) => <ThemeProvider colorScheme="light"><Story /></ThemeProvider>],
|
|
11
|
+
parameters: { layout: 'padded' },
|
|
12
|
+
} satisfies Meta<typeof SegmentedControl>;
|
|
13
|
+
|
|
14
|
+
export default meta;
|
|
15
|
+
type Story = StoryObj<typeof meta>;
|
|
16
|
+
|
|
17
|
+
export const Outline: Story = {
|
|
18
|
+
args: {
|
|
19
|
+
variant: 'outline',
|
|
20
|
+
selectedIndex: 0,
|
|
21
|
+
children: ['Day', 'Week', 'Month'],
|
|
22
|
+
accessibilityLabel: 'View mode',
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const Filled: Story = {
|
|
27
|
+
args: {
|
|
28
|
+
variant: 'filled',
|
|
29
|
+
selectedIndex: 1,
|
|
30
|
+
children: ['Day', 'Week', 'Month'],
|
|
31
|
+
accessibilityLabel: 'View mode',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const Small: Story = {
|
|
36
|
+
args: {
|
|
37
|
+
size: 'small',
|
|
38
|
+
selectedIndex: 0,
|
|
39
|
+
children: ['On', 'Off'],
|
|
40
|
+
accessibilityLabel: 'Toggle',
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const Large: Story = {
|
|
45
|
+
args: {
|
|
46
|
+
size: 'large',
|
|
47
|
+
selectedIndex: 2,
|
|
48
|
+
children: ['First', 'Second', 'Third'],
|
|
49
|
+
accessibilityLabel: 'Selection',
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const Disabled: Story = {
|
|
54
|
+
args: {
|
|
55
|
+
selectedIndex: 0,
|
|
56
|
+
disabled: true,
|
|
57
|
+
children: ['Day', 'Week', 'Month'],
|
|
58
|
+
accessibilityLabel: 'View mode',
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
function InteractiveComponent() {
|
|
63
|
+
const [index, setIndex] = useState(0);
|
|
64
|
+
return (
|
|
65
|
+
<SegmentedControl
|
|
66
|
+
selectedIndex={index}
|
|
67
|
+
onValueChange={setIndex}
|
|
68
|
+
accessibilityLabel="View mode"
|
|
69
|
+
>
|
|
70
|
+
{'Day'}
|
|
71
|
+
{'Week'}
|
|
72
|
+
{'Month'}
|
|
73
|
+
</SegmentedControl>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export const Interactive: Story = {
|
|
78
|
+
render: () => <InteractiveComponent />,
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
function InteractiveFilledComponent() {
|
|
82
|
+
const [index, setIndex] = useState(0);
|
|
83
|
+
return (
|
|
84
|
+
<SegmentedControl
|
|
85
|
+
variant="filled"
|
|
86
|
+
selectedIndex={index}
|
|
87
|
+
onValueChange={setIndex}
|
|
88
|
+
accessibilityLabel="Category"
|
|
89
|
+
>
|
|
90
|
+
{'All'}
|
|
91
|
+
{'Active'}
|
|
92
|
+
{'Completed'}
|
|
93
|
+
</SegmentedControl>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export const InteractiveFilled: Story = {
|
|
98
|
+
render: () => <InteractiveFilledComponent />,
|
|
99
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Children, ReactNode } from 'react';
|
|
2
|
+
import { StyleSheet, View, Pressable, Text, StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
import { spacing, font, border } from '../../../../native/tokens';
|
|
4
|
+
import { useTheme } from '../../../../native/ThemeContext';
|
|
5
|
+
|
|
6
|
+
type SegmentedControlSize = 'small' | 'medium' | 'large';
|
|
7
|
+
type SegmentedControlVariant = 'outline' | 'filled';
|
|
8
|
+
|
|
9
|
+
interface SegmentedControlProps {
|
|
10
|
+
selectedIndex?: number;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
size?: SegmentedControlSize;
|
|
13
|
+
variant?: SegmentedControlVariant;
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
accessibilityLabel?: string;
|
|
16
|
+
onValueChange?: (index: number) => void;
|
|
17
|
+
style?: StyleProp<ViewStyle>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const sizeTokens: Record<SegmentedControlSize, { height: number; fontSize: number; px: number }> = {
|
|
21
|
+
small: { height: 32, fontSize: font.size.bodyS, px: spacing.s },
|
|
22
|
+
medium: { height: 40, fontSize: font.size.body, px: spacing.m },
|
|
23
|
+
large: { height: 48, fontSize: font.size.body, px: spacing.l },
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const styles = StyleSheet.create({
|
|
27
|
+
track: {
|
|
28
|
+
flexDirection: 'row',
|
|
29
|
+
borderRadius: border.radius.full,
|
|
30
|
+
overflow: 'hidden',
|
|
31
|
+
},
|
|
32
|
+
item: {
|
|
33
|
+
flex: 1,
|
|
34
|
+
alignItems: 'center',
|
|
35
|
+
justifyContent: 'center',
|
|
36
|
+
minHeight: 44,
|
|
37
|
+
},
|
|
38
|
+
label: {
|
|
39
|
+
fontFamily: font.family.body,
|
|
40
|
+
fontWeight: font.weight.semibold,
|
|
41
|
+
textAlign: 'center',
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export function SegmentedControl({
|
|
46
|
+
selectedIndex = 0,
|
|
47
|
+
disabled = false,
|
|
48
|
+
size = 'medium',
|
|
49
|
+
variant = 'outline',
|
|
50
|
+
children,
|
|
51
|
+
accessibilityLabel,
|
|
52
|
+
onValueChange,
|
|
53
|
+
style,
|
|
54
|
+
}: Readonly<SegmentedControlProps>) {
|
|
55
|
+
const { colors } = useTheme();
|
|
56
|
+
const { height, fontSize, px } = sizeTokens[size];
|
|
57
|
+
const items = Children.toArray(children);
|
|
58
|
+
|
|
59
|
+
const trackStyle: ViewStyle = variant === 'filled'
|
|
60
|
+
? { backgroundColor: colors.colorBgSubtle }
|
|
61
|
+
: { backgroundColor: 'transparent', borderWidth: 1, borderColor: colors.colorBgSubtle };
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<View
|
|
65
|
+
style={[styles.track, trackStyle, { borderRadius: border.radius.full }, style]}
|
|
66
|
+
accessibilityRole="tablist"
|
|
67
|
+
accessibilityLabel={accessibilityLabel}
|
|
68
|
+
>
|
|
69
|
+
{items.map((child, index) => {
|
|
70
|
+
const isActive = index === selectedIndex;
|
|
71
|
+
|
|
72
|
+
const activeStyle: ViewStyle = variant === 'filled'
|
|
73
|
+
? { backgroundColor: colors.colorInteractive }
|
|
74
|
+
: { borderWidth: 2, borderColor: colors.colorInteractive };
|
|
75
|
+
|
|
76
|
+
const inactiveStyle: ViewStyle = variant === 'filled'
|
|
77
|
+
? {}
|
|
78
|
+
: {};
|
|
79
|
+
|
|
80
|
+
const textColor = variant === 'filled' && isActive
|
|
81
|
+
? colors.colorOnInteractive
|
|
82
|
+
: isActive
|
|
83
|
+
? colors.colorInteractive
|
|
84
|
+
: colors.colorOnBgSubtle;
|
|
85
|
+
|
|
86
|
+
// Extract label from child: if it's a string, use it directly.
|
|
87
|
+
// Otherwise render the child as-is.
|
|
88
|
+
const label = typeof child === 'string' || typeof child === 'number'
|
|
89
|
+
? String(child)
|
|
90
|
+
: null;
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<Pressable
|
|
94
|
+
key={index}
|
|
95
|
+
onPress={() => !disabled && onValueChange?.(index)}
|
|
96
|
+
disabled={disabled}
|
|
97
|
+
accessibilityRole="tab"
|
|
98
|
+
accessibilityLabel={label ?? undefined}
|
|
99
|
+
accessibilityState={{ selected: isActive, disabled }}
|
|
100
|
+
style={({ pressed }) => [
|
|
101
|
+
styles.item,
|
|
102
|
+
{ height, paddingHorizontal: px },
|
|
103
|
+
isActive ? activeStyle : inactiveStyle,
|
|
104
|
+
variant === 'filled' && isActive && { borderRadius: border.radius.full },
|
|
105
|
+
pressed && !disabled && { opacity: 0.7 },
|
|
106
|
+
disabled && { opacity: 0.4 },
|
|
107
|
+
]}
|
|
108
|
+
>
|
|
109
|
+
{label !== null ? (
|
|
110
|
+
<Text style={[styles.label, { fontSize, color: textColor }]}>
|
|
111
|
+
{label}
|
|
112
|
+
</Text>
|
|
113
|
+
) : (
|
|
114
|
+
child
|
|
115
|
+
)}
|
|
116
|
+
</Pressable>
|
|
117
|
+
);
|
|
118
|
+
})}
|
|
119
|
+
</View>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Meta, Canvas, ArgTypes } from '@storybook/blocks';
|
|
2
|
+
import * as Stories from './Select.stories';
|
|
3
|
+
|
|
4
|
+
<Meta of={Stories} />
|
|
5
|
+
|
|
6
|
+
# Select (React Native)
|
|
7
|
+
|
|
8
|
+
Dropdown-style select component. Renders a trigger button that opens a bottom sheet modal with a scrollable list of options.
|
|
9
|
+
|
|
10
|
+
> **Status: alpha** — API may change before stable release.
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import { Select } from '@boostdev/design-system-components';
|
|
16
|
+
import { useState } from 'react';
|
|
17
|
+
|
|
18
|
+
const options = [
|
|
19
|
+
{ value: 'apple', label: 'Apple' },
|
|
20
|
+
{ value: 'banana', label: 'Banana' },
|
|
21
|
+
{ value: 'cherry', label: 'Cherry' },
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
function Example() {
|
|
25
|
+
const [value, setValue] = useState('');
|
|
26
|
+
return (
|
|
27
|
+
<Select
|
|
28
|
+
label="Fruit"
|
|
29
|
+
name="fruit"
|
|
30
|
+
options={options}
|
|
31
|
+
placeholder="Choose a fruit..."
|
|
32
|
+
value={value}
|
|
33
|
+
onChange={setValue}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Examples
|
|
40
|
+
|
|
41
|
+
### Default
|
|
42
|
+
<Canvas of={Stories.Default} />
|
|
43
|
+
|
|
44
|
+
### With placeholder
|
|
45
|
+
<Canvas of={Stories.WithPlaceholder} />
|
|
46
|
+
|
|
47
|
+
### With selected value
|
|
48
|
+
<Canvas of={Stories.WithValue} />
|
|
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` | ReactNode | — | Visible label text |
|
|
71
|
+
| `name` | string | — | Field name (used for accessibility) |
|
|
72
|
+
| `options` | `SelectOption[]` | — | Array of `{ value, label, disabled? }` |
|
|
73
|
+
| `placeholder` | string | `'Select an option'` | Placeholder when no value is selected |
|
|
74
|
+
| `value` | string | — | Currently selected value |
|
|
75
|
+
| `error` | string | — | Error message displayed below the trigger |
|
|
76
|
+
| `hint` | string | — | Hint text displayed below the trigger |
|
|
77
|
+
| `disabled` | boolean | `false` | Prevents interaction, reduces opacity |
|
|
78
|
+
| `onChange` | `(value: string) => void` | — | Called with the selected option value |
|
|
79
|
+
|
|
80
|
+
## Accessibility
|
|
81
|
+
|
|
82
|
+
- Trigger announces the label and current value via `accessibilityLabel`
|
|
83
|
+
- `accessibilityState.expanded` reflects whether the modal is open
|
|
84
|
+
- Each option announces its label and selected state
|
|
85
|
+
- Disabled options are communicated via `accessibilityState.disabled`
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { ThemeProvider } from '../../../../native/ThemeContext';
|
|
3
|
+
import { Select } from './Select';
|
|
4
|
+
|
|
5
|
+
const options = [
|
|
6
|
+
{ value: 'apple', label: 'Apple' },
|
|
7
|
+
{ value: 'banana', label: 'Banana' },
|
|
8
|
+
{ value: 'cherry', label: 'Cherry' },
|
|
9
|
+
];
|
|
10
|
+
|
|
11
|
+
function renderWithTheme(ui: React.ReactElement) {
|
|
12
|
+
return render(<ThemeProvider>{ui}</ThemeProvider>);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe('Select (native)', () => {
|
|
16
|
+
it('renders the label', () => {
|
|
17
|
+
renderWithTheme(<Select label="Fruit" name="fruit" options={options} />);
|
|
18
|
+
expect(screen.getByText('Fruit')).toBeInTheDocument();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('shows placeholder when no value is selected', () => {
|
|
22
|
+
renderWithTheme(
|
|
23
|
+
<Select label="Fruit" name="fruit" options={options} placeholder="Choose..." />,
|
|
24
|
+
);
|
|
25
|
+
expect(screen.getByText('Choose...')).toBeInTheDocument();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('shows the selected option label', () => {
|
|
29
|
+
renderWithTheme(
|
|
30
|
+
<Select label="Fruit" name="fruit" options={options} value="cherry" />,
|
|
31
|
+
);
|
|
32
|
+
expect(screen.getByText('Cherry')).toBeInTheDocument();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('shows error message', () => {
|
|
36
|
+
renderWithTheme(
|
|
37
|
+
<Select label="Fruit" name="fruit" options={options} error="Required." />,
|
|
38
|
+
);
|
|
39
|
+
expect(screen.getByRole('alert')).toHaveTextContent('Required.');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('shows hint message', () => {
|
|
43
|
+
renderWithTheme(
|
|
44
|
+
<Select label="Fruit" name="fruit" options={options} hint="Pick one." />,
|
|
45
|
+
);
|
|
46
|
+
expect(screen.getByText('Pick one.')).toBeInTheDocument();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('renders the trigger button with correct accessibility', () => {
|
|
50
|
+
renderWithTheme(
|
|
51
|
+
<Select label="Fruit" name="fruit" options={options} />,
|
|
52
|
+
);
|
|
53
|
+
const trigger = screen.getByRole('button', { name: /Fruit/ });
|
|
54
|
+
expect(trigger).toBeInTheDocument();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('applies disabled opacity', () => {
|
|
58
|
+
renderWithTheme(
|
|
59
|
+
<Select label="Fruit" name="fruit" options={options} disabled value="banana" />,
|
|
60
|
+
);
|
|
61
|
+
const trigger = screen.getByRole('button', { name: /Fruit/ });
|
|
62
|
+
expect(trigger).toBeDisabled();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
+
import { ThemeProvider } from '../../../../native/ThemeContext';
|
|
4
|
+
import { Select } from './Select';
|
|
5
|
+
|
|
6
|
+
const fruitOptions = [
|
|
7
|
+
{ value: 'apple', label: 'Apple' },
|
|
8
|
+
{ value: 'banana', label: 'Banana' },
|
|
9
|
+
{ value: 'cherry', label: 'Cherry' },
|
|
10
|
+
{ value: 'dragonfruit', label: 'Dragonfruit' },
|
|
11
|
+
{ value: 'elderberry', label: 'Elderberry' },
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
const meta = {
|
|
15
|
+
tags: ['!stable', 'alpha'],
|
|
16
|
+
title: 'React Native/Form/Select',
|
|
17
|
+
component: Select,
|
|
18
|
+
decorators: [(Story) => <ThemeProvider colorScheme="light"><Story /></ThemeProvider>],
|
|
19
|
+
parameters: { layout: 'padded' },
|
|
20
|
+
} satisfies Meta<typeof Select>;
|
|
21
|
+
|
|
22
|
+
export default meta;
|
|
23
|
+
type Story = StoryObj<typeof meta>;
|
|
24
|
+
|
|
25
|
+
export const Default: Story = {
|
|
26
|
+
args: { label: 'Fruit', name: 'fruit', options: fruitOptions },
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const WithPlaceholder: Story = {
|
|
30
|
+
args: { label: 'Fruit', name: 'fruit', options: fruitOptions, placeholder: 'Choose a fruit...' },
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const WithValue: Story = {
|
|
34
|
+
args: { label: 'Fruit', name: 'fruit', options: fruitOptions, value: 'cherry' },
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const WithError: Story = {
|
|
38
|
+
args: { label: 'Fruit', name: 'fruit', options: fruitOptions, error: 'Please select a fruit.' },
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const WithHint: Story = {
|
|
42
|
+
args: { label: 'Fruit', name: 'fruit', options: fruitOptions, hint: 'Pick your favourite.' },
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const Disabled: Story = {
|
|
46
|
+
args: { label: 'Fruit', name: 'fruit', options: fruitOptions, disabled: true, value: 'banana' },
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const WithDisabledOption: Story = {
|
|
50
|
+
args: {
|
|
51
|
+
label: 'Fruit',
|
|
52
|
+
name: 'fruit',
|
|
53
|
+
options: [
|
|
54
|
+
{ value: 'apple', label: 'Apple' },
|
|
55
|
+
{ value: 'banana', label: 'Banana', disabled: true },
|
|
56
|
+
{ value: 'cherry', label: 'Cherry' },
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const Interactive: Story = {
|
|
62
|
+
render: () => {
|
|
63
|
+
const [value, setValue] = useState('');
|
|
64
|
+
return (
|
|
65
|
+
<Select
|
|
66
|
+
label="Favourite fruit"
|
|
67
|
+
name="fruit"
|
|
68
|
+
options={fruitOptions}
|
|
69
|
+
placeholder="Choose a fruit..."
|
|
70
|
+
value={value}
|
|
71
|
+
onChange={setValue}
|
|
72
|
+
/>
|
|
73
|
+
);
|
|
74
|
+
},
|
|
75
|
+
};
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { ReactNode, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
StyleSheet,
|
|
4
|
+
View,
|
|
5
|
+
Text,
|
|
6
|
+
Pressable,
|
|
7
|
+
Modal,
|
|
8
|
+
FlatList,
|
|
9
|
+
SafeAreaView,
|
|
10
|
+
StyleProp,
|
|
11
|
+
ViewStyle,
|
|
12
|
+
} from 'react-native';
|
|
13
|
+
import { spacing, font, border, lineHeight } from '../../../../native/tokens';
|
|
14
|
+
import { useTheme } from '../../../../native/ThemeContext';
|
|
15
|
+
import { Label } from '../atoms/Label';
|
|
16
|
+
import { Message } from '../atoms/Message';
|
|
17
|
+
|
|
18
|
+
export interface SelectOption {
|
|
19
|
+
value: string;
|
|
20
|
+
label: string;
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface SelectProps {
|
|
25
|
+
label: ReactNode;
|
|
26
|
+
name: string;
|
|
27
|
+
options: SelectOption[];
|
|
28
|
+
placeholder?: string;
|
|
29
|
+
value?: string;
|
|
30
|
+
error?: string;
|
|
31
|
+
hint?: string;
|
|
32
|
+
disabled?: boolean;
|
|
33
|
+
onChange?: (value: string) => void;
|
|
34
|
+
style?: StyleProp<ViewStyle>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const styles = StyleSheet.create({
|
|
38
|
+
container: {
|
|
39
|
+
gap: spacing.xxs,
|
|
40
|
+
},
|
|
41
|
+
trigger: {
|
|
42
|
+
flexDirection: 'row',
|
|
43
|
+
alignItems: 'center',
|
|
44
|
+
justifyContent: 'space-between',
|
|
45
|
+
paddingHorizontal: spacing.s,
|
|
46
|
+
paddingVertical: spacing.xs,
|
|
47
|
+
borderWidth: 1,
|
|
48
|
+
borderRadius: border.radius.full,
|
|
49
|
+
minHeight: 44,
|
|
50
|
+
},
|
|
51
|
+
triggerText: {
|
|
52
|
+
fontFamily: font.family.body,
|
|
53
|
+
fontSize: font.size.body,
|
|
54
|
+
lineHeight: lineHeight.body,
|
|
55
|
+
flex: 1,
|
|
56
|
+
},
|
|
57
|
+
chevron: {
|
|
58
|
+
fontFamily: font.family.body,
|
|
59
|
+
fontSize: font.size.body,
|
|
60
|
+
marginStart: spacing.xs,
|
|
61
|
+
},
|
|
62
|
+
overlay: {
|
|
63
|
+
flex: 1,
|
|
64
|
+
justifyContent: 'flex-end',
|
|
65
|
+
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
66
|
+
},
|
|
67
|
+
sheet: {
|
|
68
|
+
maxHeight: '60%',
|
|
69
|
+
borderTopStartRadius: border.radius.m,
|
|
70
|
+
borderTopEndRadius: border.radius.m,
|
|
71
|
+
paddingTop: spacing.m,
|
|
72
|
+
paddingBottom: spacing.xxxl,
|
|
73
|
+
},
|
|
74
|
+
sheetHeader: {
|
|
75
|
+
flexDirection: 'row',
|
|
76
|
+
justifyContent: 'space-between',
|
|
77
|
+
alignItems: 'center',
|
|
78
|
+
paddingHorizontal: spacing.m,
|
|
79
|
+
paddingBottom: spacing.s,
|
|
80
|
+
},
|
|
81
|
+
sheetTitle: {
|
|
82
|
+
fontFamily: font.family.body,
|
|
83
|
+
fontSize: font.size.heading3,
|
|
84
|
+
fontWeight: font.weight.semibold,
|
|
85
|
+
},
|
|
86
|
+
closeText: {
|
|
87
|
+
fontFamily: font.family.body,
|
|
88
|
+
fontSize: font.size.body,
|
|
89
|
+
fontWeight: font.weight.semibold,
|
|
90
|
+
},
|
|
91
|
+
optionItem: {
|
|
92
|
+
paddingHorizontal: spacing.m,
|
|
93
|
+
paddingVertical: spacing.s,
|
|
94
|
+
minHeight: 44,
|
|
95
|
+
justifyContent: 'center',
|
|
96
|
+
},
|
|
97
|
+
optionText: {
|
|
98
|
+
fontFamily: font.family.body,
|
|
99
|
+
fontSize: font.size.body,
|
|
100
|
+
lineHeight: lineHeight.body,
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
export function Select({
|
|
105
|
+
label,
|
|
106
|
+
name,
|
|
107
|
+
options,
|
|
108
|
+
placeholder = 'Select an option',
|
|
109
|
+
value,
|
|
110
|
+
error,
|
|
111
|
+
hint,
|
|
112
|
+
disabled = false,
|
|
113
|
+
onChange,
|
|
114
|
+
style,
|
|
115
|
+
}: Readonly<SelectProps>) {
|
|
116
|
+
const { colors } = useTheme();
|
|
117
|
+
const [open, setOpen] = useState(false);
|
|
118
|
+
|
|
119
|
+
const selectedOption = options.find((o) => o.value === value);
|
|
120
|
+
const displayText = selectedOption?.label ?? placeholder;
|
|
121
|
+
const isPlaceholder = !selectedOption;
|
|
122
|
+
|
|
123
|
+
const borderColor = error
|
|
124
|
+
? colors.colorError
|
|
125
|
+
: open
|
|
126
|
+
? colors.colorInteractive
|
|
127
|
+
: colors.colorOnBg;
|
|
128
|
+
|
|
129
|
+
const handleSelect = (optionValue: string) => {
|
|
130
|
+
onChange?.(optionValue);
|
|
131
|
+
setOpen(false);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<View style={[styles.container, style]}>
|
|
136
|
+
<Label label={label} />
|
|
137
|
+
<Pressable
|
|
138
|
+
accessibilityRole="button"
|
|
139
|
+
accessibilityLabel={typeof label === 'string' ? `${label}, ${displayText}` : name}
|
|
140
|
+
accessibilityState={{ disabled, expanded: open }}
|
|
141
|
+
accessibilityHint="Double tap to open options"
|
|
142
|
+
disabled={disabled}
|
|
143
|
+
onPress={() => setOpen(true)}
|
|
144
|
+
style={[
|
|
145
|
+
styles.trigger,
|
|
146
|
+
{
|
|
147
|
+
borderColor,
|
|
148
|
+
backgroundColor: colors.colorBg,
|
|
149
|
+
},
|
|
150
|
+
disabled && { opacity: 0.4 },
|
|
151
|
+
]}
|
|
152
|
+
>
|
|
153
|
+
<Text
|
|
154
|
+
style={[
|
|
155
|
+
styles.triggerText,
|
|
156
|
+
{
|
|
157
|
+
color: isPlaceholder ? colors.colorOnBgSubtle : colors.colorOnBg,
|
|
158
|
+
},
|
|
159
|
+
]}
|
|
160
|
+
>
|
|
161
|
+
{displayText}
|
|
162
|
+
</Text>
|
|
163
|
+
<Text style={[styles.chevron, { color: colors.colorOnBgSubtle }]} aria-hidden>
|
|
164
|
+
{'\u25BE'}
|
|
165
|
+
</Text>
|
|
166
|
+
</Pressable>
|
|
167
|
+
|
|
168
|
+
<Modal
|
|
169
|
+
visible={open}
|
|
170
|
+
transparent
|
|
171
|
+
animationType="slide"
|
|
172
|
+
onRequestClose={() => setOpen(false)}
|
|
173
|
+
>
|
|
174
|
+
<Pressable
|
|
175
|
+
style={styles.overlay}
|
|
176
|
+
onPress={() => setOpen(false)}
|
|
177
|
+
accessibilityRole="button"
|
|
178
|
+
accessibilityLabel="Close options"
|
|
179
|
+
>
|
|
180
|
+
<Pressable
|
|
181
|
+
style={[styles.sheet, { backgroundColor: colors.colorBg }]}
|
|
182
|
+
onPress={() => {
|
|
183
|
+
/* prevent close when tapping sheet */
|
|
184
|
+
}}
|
|
185
|
+
>
|
|
186
|
+
<SafeAreaView>
|
|
187
|
+
<View style={styles.sheetHeader}>
|
|
188
|
+
<Text style={[styles.sheetTitle, { color: colors.colorOnBg }]}>
|
|
189
|
+
{typeof label === 'string' ? label : 'Select'}
|
|
190
|
+
</Text>
|
|
191
|
+
<Pressable
|
|
192
|
+
accessibilityRole="button"
|
|
193
|
+
accessibilityLabel="Close"
|
|
194
|
+
onPress={() => setOpen(false)}
|
|
195
|
+
hitSlop={8}
|
|
196
|
+
>
|
|
197
|
+
<Text style={[styles.closeText, { color: colors.colorInteractive }]}>
|
|
198
|
+
Done
|
|
199
|
+
</Text>
|
|
200
|
+
</Pressable>
|
|
201
|
+
</View>
|
|
202
|
+
<FlatList
|
|
203
|
+
data={options}
|
|
204
|
+
keyExtractor={(item) => item.value}
|
|
205
|
+
renderItem={({ item }) => {
|
|
206
|
+
const isSelected = item.value === value;
|
|
207
|
+
return (
|
|
208
|
+
<Pressable
|
|
209
|
+
accessibilityRole="button"
|
|
210
|
+
accessibilityLabel={item.label}
|
|
211
|
+
accessibilityState={{
|
|
212
|
+
selected: isSelected,
|
|
213
|
+
disabled: item.disabled,
|
|
214
|
+
}}
|
|
215
|
+
disabled={item.disabled}
|
|
216
|
+
onPress={() => handleSelect(item.value)}
|
|
217
|
+
style={({ pressed }) => [
|
|
218
|
+
styles.optionItem,
|
|
219
|
+
isSelected && { backgroundColor: colors.colorBgSubtle },
|
|
220
|
+
pressed && { opacity: 0.7 },
|
|
221
|
+
item.disabled && { opacity: 0.4 },
|
|
222
|
+
]}
|
|
223
|
+
>
|
|
224
|
+
<Text
|
|
225
|
+
style={[
|
|
226
|
+
styles.optionText,
|
|
227
|
+
{
|
|
228
|
+
color: isSelected
|
|
229
|
+
? colors.colorInteractive
|
|
230
|
+
: colors.colorOnBg,
|
|
231
|
+
fontWeight: isSelected
|
|
232
|
+
? font.weight.semibold
|
|
233
|
+
: font.weight.body,
|
|
234
|
+
},
|
|
235
|
+
]}
|
|
236
|
+
>
|
|
237
|
+
{item.label}
|
|
238
|
+
</Text>
|
|
239
|
+
</Pressable>
|
|
240
|
+
);
|
|
241
|
+
}}
|
|
242
|
+
/>
|
|
243
|
+
</SafeAreaView>
|
|
244
|
+
</Pressable>
|
|
245
|
+
</Pressable>
|
|
246
|
+
</Modal>
|
|
247
|
+
|
|
248
|
+
<Message type="error" message={error} />
|
|
249
|
+
<Message type="hint" message={hint} />
|
|
250
|
+
</View>
|
|
251
|
+
);
|
|
252
|
+
}
|