@utilitywarehouse/hearth-react-native 0.27.3 → 0.28.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/.turbo/turbo-build.log +1 -1
- package/.turbo/turbo-lint.log +18 -19
- package/CHANGELOG.md +110 -0
- package/build/components/Combobox/Combobox.context.d.ts +13 -0
- package/build/components/Combobox/Combobox.context.js +9 -0
- package/build/components/Combobox/Combobox.d.ts +6 -0
- package/build/components/Combobox/Combobox.js +246 -0
- package/build/components/Combobox/Combobox.props.d.ts +180 -0
- package/build/components/Combobox/Combobox.props.js +1 -0
- package/build/components/Combobox/ComboboxOption.d.ts +6 -0
- package/build/components/Combobox/ComboboxOption.js +56 -0
- package/build/components/Combobox/index.d.ts +4 -0
- package/build/components/Combobox/index.js +3 -0
- package/build/components/Modal/Modal.js +26 -42
- package/build/components/Modal/Modal.web.js +3 -3
- package/build/components/Pagination/Pagination.d.ts +6 -0
- package/build/components/Pagination/Pagination.js +125 -0
- package/build/components/Pagination/Pagination.props.d.ts +26 -0
- package/build/components/Pagination/Pagination.props.js +1 -0
- package/build/components/Pagination/Pagination.utils.d.ts +2 -0
- package/build/components/Pagination/Pagination.utils.js +20 -0
- package/build/components/Pagination/Pagination.utils.test.d.ts +1 -0
- package/build/components/Pagination/Pagination.utils.test.js +16 -0
- package/build/components/Pagination/index.d.ts +2 -0
- package/build/components/Pagination/index.js +1 -0
- package/build/components/SafeAreaView/SafeAreaView.d.ts +5 -0
- package/build/components/SafeAreaView/SafeAreaView.js +117 -0
- package/build/components/SafeAreaView/SafeAreaView.props.d.ts +17 -0
- package/build/components/SafeAreaView/SafeAreaView.props.js +1 -0
- package/build/components/SafeAreaView/index.d.ts +2 -0
- package/build/components/SafeAreaView/index.js +1 -0
- package/build/components/Select/Select.js +3 -2
- package/build/components/Table/Table.context.d.ts +12 -0
- package/build/components/Table/Table.context.js +9 -0
- package/build/components/Table/Table.d.ts +6 -0
- package/build/components/Table/Table.js +71 -0
- package/build/components/Table/Table.props.d.ts +56 -0
- package/build/components/Table/Table.props.js +1 -0
- package/build/components/Table/Table.utils.d.ts +5 -0
- package/build/components/Table/Table.utils.js +48 -0
- package/build/components/Table/Table.utils.test.d.ts +1 -0
- package/build/components/Table/Table.utils.test.js +71 -0
- package/build/components/Table/TableBody.d.ts +6 -0
- package/build/components/Table/TableBody.js +16 -0
- package/build/components/Table/TableCell.d.ts +10 -0
- package/build/components/Table/TableCell.js +44 -0
- package/build/components/Table/TableHeader.d.ts +6 -0
- package/build/components/Table/TableHeader.js +24 -0
- package/build/components/Table/TableHeaderCell.d.ts +10 -0
- package/build/components/Table/TableHeaderCell.js +97 -0
- package/build/components/Table/TablePagination.d.ts +6 -0
- package/build/components/Table/TablePagination.js +7 -0
- package/build/components/Table/TableRow.d.ts +8 -0
- package/build/components/Table/TableRow.js +25 -0
- package/build/components/Table/index.d.ts +8 -0
- package/build/components/Table/index.js +7 -0
- package/build/components/Timeline/Timeline.d.ts +6 -0
- package/build/components/Timeline/Timeline.js +34 -0
- package/build/components/Timeline/Timeline.props.d.ts +47 -0
- package/build/components/Timeline/Timeline.props.js +1 -0
- package/build/components/Timeline/TimelineItem.d.ts +6 -0
- package/build/components/Timeline/TimelineItem.js +235 -0
- package/build/components/Timeline/index.d.ts +3 -0
- package/build/components/Timeline/index.js +2 -0
- package/build/components/index.d.ts +5 -0
- package/build/components/index.js +5 -0
- package/build/tokens/components/dark/timeline.d.ts +2 -2
- package/build/tokens/components/dark/timeline.js +2 -2
- package/docs/components/AllComponents.web.tsx +106 -23
- package/docs/llm-docs/unistyles-llms-full.txt +1132 -534
- package/docs/llm-docs/unistyles-llms-small.txt +37 -37
- package/package.json +2 -2
- package/src/components/Combobox/Combobox.context.ts +26 -0
- package/src/components/Combobox/Combobox.docs.mdx +277 -0
- package/src/components/Combobox/Combobox.figma.tsx +60 -0
- package/src/components/Combobox/Combobox.props.ts +187 -0
- package/src/components/Combobox/Combobox.stories.tsx +233 -0
- package/src/components/Combobox/Combobox.tsx +446 -0
- package/src/components/Combobox/ComboboxOption.tsx +100 -0
- package/src/components/Combobox/index.ts +9 -0
- package/src/components/Modal/Modal.tsx +52 -74
- package/src/components/Modal/Modal.web.tsx +3 -3
- package/src/components/Pagination/Pagination.docs.mdx +99 -0
- package/src/components/Pagination/Pagination.figma.tsx +20 -0
- package/src/components/Pagination/Pagination.props.ts +28 -0
- package/src/components/Pagination/Pagination.stories.tsx +88 -0
- package/src/components/Pagination/Pagination.tsx +248 -0
- package/src/components/Pagination/Pagination.utils.test.ts +20 -0
- package/src/components/Pagination/Pagination.utils.ts +37 -0
- package/src/components/Pagination/index.ts +2 -0
- package/src/components/SafeAreaView/SafeAreaView.props.ts +20 -0
- package/src/components/SafeAreaView/SafeAreaView.tsx +173 -0
- package/src/components/SafeAreaView/index.ts +2 -0
- package/src/components/Select/Select.tsx +30 -27
- package/src/components/Table/Table.context.tsx +23 -0
- package/src/components/Table/Table.docs.mdx +239 -0
- package/src/components/Table/Table.figma.tsx +65 -0
- package/src/components/Table/Table.props.ts +65 -0
- package/src/components/Table/Table.stories.tsx +399 -0
- package/src/components/Table/Table.tsx +127 -0
- package/src/components/Table/Table.utils.test.ts +82 -0
- package/src/components/Table/Table.utils.ts +72 -0
- package/src/components/Table/TableBody.tsx +25 -0
- package/src/components/Table/TableCell.tsx +67 -0
- package/src/components/Table/TableHeader.tsx +41 -0
- package/src/components/Table/TableHeaderCell.tsx +136 -0
- package/src/components/Table/TablePagination.tsx +10 -0
- package/src/components/Table/TableRow.tsx +42 -0
- package/src/components/Table/index.ts +16 -0
- package/src/components/Timeline/Timeline.docs.mdx +177 -0
- package/src/components/Timeline/Timeline.figma.tsx +89 -0
- package/src/components/Timeline/Timeline.props.ts +51 -0
- package/src/components/Timeline/Timeline.stories.tsx +102 -0
- package/src/components/Timeline/Timeline.tsx +48 -0
- package/src/components/Timeline/TimelineItem.tsx +293 -0
- package/src/components/Timeline/index.ts +9 -0
- package/src/components/index.ts +5 -0
- package/src/tokens/components/dark/timeline.ts +2 -2
package/.turbo/turbo-build.log
CHANGED
package/.turbo/turbo-lint.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @utilitywarehouse/hearth-react-native@0.
|
|
2
|
+
> @utilitywarehouse/hearth-react-native@0.28.0 lint /home/runner/work/hearth/hearth/packages/react-native
|
|
3
3
|
> TIMING=1 eslint .
|
|
4
4
|
|
|
5
5
|
|
|
@@ -30,16 +30,15 @@
|
|
|
30
30
|
/home/runner/work/hearth/hearth/packages/react-native/src/components/Input/Input.tsx
|
|
31
31
|
78:8 warning React Hook useEffect has a missing dependency: 'formFieldContext'. Either include it or remove the dependency array react-hooks/exhaustive-deps
|
|
32
32
|
|
|
33
|
-
/home/runner/work/hearth/hearth/packages/react-native/src/components/Modal/Modal.tsx
|
|
34
|
-
93:6 warning React Hook useCallback has an unnecessary dependency: 'Platform.OS'. Either exclude it or remove the dependency array. Outer scope values like 'Platform.OS' aren't valid dependencies because mutating them doesn't re-render the component react-hooks/exhaustive-deps
|
|
35
|
-
330:5 warning React Hook useCallback has a missing dependency: 'footer'. Either include it or remove the dependency array react-hooks/exhaustive-deps
|
|
36
|
-
|
|
37
33
|
/home/runner/work/hearth/hearth/packages/react-native/src/components/Modal/Modal.web.tsx
|
|
38
34
|
66:6 warning React Hook useCallback has an unnecessary dependency: 'Platform.OS'. Either exclude it or remove the dependency array. Outer scope values like 'Platform.OS' aren't valid dependencies because mutating them doesn't re-render the component react-hooks/exhaustive-deps
|
|
39
35
|
|
|
40
36
|
/home/runner/work/hearth/hearth/packages/react-native/src/components/PillGroup/PillGroup.tsx
|
|
41
37
|
17:9 warning The 'normalizedValue' conditional could make the dependencies of useMemo Hook (at line 33) change on every render. Move it inside the useMemo callback. Alternatively, wrap the initialization of 'normalizedValue' in its own useMemo() Hook react-hooks/exhaustive-deps
|
|
42
38
|
|
|
39
|
+
/home/runner/work/hearth/hearth/packages/react-native/src/components/Table/Table.context.tsx
|
|
40
|
+
23:14 warning Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components react-refresh/only-export-components
|
|
41
|
+
|
|
43
42
|
/home/runner/work/hearth/hearth/packages/react-native/src/components/Tabs/Tabs.tsx
|
|
44
43
|
53:6 warning React Hook useEffect has a missing dependency: 'tabValues'. Either include it or remove the dependency array react-hooks/exhaustive-deps
|
|
45
44
|
53:7 warning React Hook useEffect has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked react-hooks/exhaustive-deps
|
|
@@ -53,17 +52,17 @@
|
|
|
53
52
|
14:14 warning Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components react-refresh/only-export-components
|
|
54
53
|
106:14 warning Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components react-refresh/only-export-components
|
|
55
54
|
|
|
56
|
-
✖
|
|
57
|
-
|
|
58
|
-
Rule
|
|
59
|
-
|
|
60
|
-
@typescript-eslint/no-unused-vars
|
|
61
|
-
react-hooks/exhaustive-deps
|
|
62
|
-
no-global-assign
|
|
63
|
-
react-hooks/rules-of-hooks
|
|
64
|
-
no-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
no-
|
|
68
|
-
no-
|
|
69
|
-
|
|
55
|
+
✖ 23 problems (0 errors, 23 warnings)
|
|
56
|
+
|
|
57
|
+
Rule | Time (ms) | Relative
|
|
58
|
+
:---------------------------------|----------:|--------:
|
|
59
|
+
@typescript-eslint/no-unused-vars | 1525.743 | 62.8%
|
|
60
|
+
react-hooks/exhaustive-deps | 120.190 | 4.9%
|
|
61
|
+
no-global-assign | 94.322 | 3.9%
|
|
62
|
+
react-hooks/rules-of-hooks | 73.690 | 3.0%
|
|
63
|
+
no-unexpected-multiline | 49.929 | 2.1%
|
|
64
|
+
@typescript-eslint/ban-ts-comment | 44.011 | 1.8%
|
|
65
|
+
no-loss-of-precision | 35.100 | 1.4%
|
|
66
|
+
no-misleading-character-class | 32.579 | 1.3%
|
|
67
|
+
no-useless-escape | 32.193 | 1.3%
|
|
68
|
+
no-control-regex | 21.498 | 0.9%
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,115 @@
|
|
|
1
1
|
# @utilitywarehouse/hearth-react-native
|
|
2
2
|
|
|
3
|
+
## 0.28.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#1014](https://github.com/utilitywarehouse/hearth/pull/1014) [`c10ff82`](https://github.com/utilitywarehouse/hearth/commit/c10ff82243265217acd95f687d48d803b3c7a4bd) Thanks [@jordmccord](https://github.com/jordmccord)! - 🌟 [FEATURE]: Add `Combobox` and `SafeAreaView` to the React Native library
|
|
8
|
+
|
|
9
|
+
The React Native package now includes a `Combobox` component for searchable selection in a bottom sheet, plus a `SafeAreaView` primitive that applies Unistyles runtime insets only when a view actually overlaps a screen edge. `Combobox` supports the built-in options API for fixed lists, controlled search values for dynamic results, and custom bottom sheet content for cases where you need to bring your own `BottomSheetFlatList` or bespoke option layout. `Modal` now uses `SafeAreaView` in its full-screen navigation modal path so content like search inputs no longer sits behind the dynamic island on iOS.
|
|
10
|
+
|
|
11
|
+
**Components affected**:
|
|
12
|
+
- `Combobox`
|
|
13
|
+
- `ComboboxOption`
|
|
14
|
+
- `SafeAreaView`
|
|
15
|
+
- `Modal`
|
|
16
|
+
|
|
17
|
+
**Developer changes**:
|
|
18
|
+
|
|
19
|
+
Import the new components from `@utilitywarehouse/hearth-react-native` and choose the API that fits your layout. Use `options` for straightforward searchable lists, render custom sheet content when you need virtualised or dynamic results, and wrap full-screen content in `SafeAreaView` when it should only pick up edge insets if it actually touches that edge.
|
|
20
|
+
|
|
21
|
+
- [`8e37595`](https://github.com/utilitywarehouse/hearth/commit/8e375958559357ce5c1703505fa7438887d9e18e) Thanks [@jordmccord](https://github.com/jordmccord)! - 🌟 [FEATURE]: Add `Pagination` component
|
|
22
|
+
|
|
23
|
+
The package now includes a `Pagination` component for moving between pages of content. It supports numbered pagination, a condensed layout for smaller spaces, optional skip buttons for jumping to the first and last page, and controlled page state so it can be wired into lists, tables, or other paged views.
|
|
24
|
+
|
|
25
|
+
**Components affected**:
|
|
26
|
+
- `Pagination`
|
|
27
|
+
|
|
28
|
+
**Developer changes**:
|
|
29
|
+
|
|
30
|
+
Import `Pagination` from `@utilitywarehouse/hearth-react-native` and control the current page in your screen or feature state.
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import { useState } from 'react';
|
|
34
|
+
import { Pagination } from '@utilitywarehouse/hearth-react-native';
|
|
35
|
+
|
|
36
|
+
const MyComponent = () => {
|
|
37
|
+
const [page, setPage] = useState(1);
|
|
38
|
+
|
|
39
|
+
return <Pagination currentPage={page} onPageChange={setPage} totalPages={10} />;
|
|
40
|
+
};
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
- [`8e37595`](https://github.com/utilitywarehouse/hearth/commit/8e375958559357ce5c1703505fa7438887d9e18e) Thanks [@jordmccord](https://github.com/jordmccord)! - 🌟 [FEATURE]: Add `Table` component
|
|
44
|
+
|
|
45
|
+
The package now includes a composable `Table` API for presenting structured data with headers, rows, cells, optional card-style containers, horizontal scrolling for narrow viewports, configurable column widths, and pagination support through `TablePagination`. Header cells support trailing actions such as sort controls, and the API is split into smaller building blocks so layouts can be assembled to fit different datasets.
|
|
46
|
+
|
|
47
|
+
**Components affected**:
|
|
48
|
+
- `Table`
|
|
49
|
+
- `TableHeader`
|
|
50
|
+
- `TableHeaderCell`
|
|
51
|
+
- `TableBody`
|
|
52
|
+
- `TableRow`
|
|
53
|
+
- `TableCell`
|
|
54
|
+
- `TablePagination`
|
|
55
|
+
|
|
56
|
+
**Developer changes**:
|
|
57
|
+
|
|
58
|
+
Import the table primitives from `@utilitywarehouse/hearth-react-native` and compose them to match your data shape. Add `columnWidths` when you need fixed or weighted columns, and pass `pagination` when rows should be paged.
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
import {
|
|
62
|
+
Table,
|
|
63
|
+
TableBody,
|
|
64
|
+
TableCell,
|
|
65
|
+
TableHeader,
|
|
66
|
+
TableHeaderCell,
|
|
67
|
+
TableRow,
|
|
68
|
+
} from '@utilitywarehouse/hearth-react-native';
|
|
69
|
+
|
|
70
|
+
const MyComponent = () => (
|
|
71
|
+
<Table columnWidths={[180, '2fr', '1fr']} container="subtle">
|
|
72
|
+
<TableHeader color="purple">
|
|
73
|
+
<TableHeaderCell>Name</TableHeaderCell>
|
|
74
|
+
<TableHeaderCell>Email</TableHeaderCell>
|
|
75
|
+
<TableHeaderCell>Status</TableHeaderCell>
|
|
76
|
+
</TableHeader>
|
|
77
|
+
<TableBody>
|
|
78
|
+
<TableRow>
|
|
79
|
+
<TableHeaderCell row>Alex Morgan</TableHeaderCell>
|
|
80
|
+
<TableCell>alex@example.com</TableCell>
|
|
81
|
+
<TableCell>Active</TableCell>
|
|
82
|
+
</TableRow>
|
|
83
|
+
</TableBody>
|
|
84
|
+
</Table>
|
|
85
|
+
);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
- [#1016](https://github.com/utilitywarehouse/hearth/pull/1016) [`33baa9e`](https://github.com/utilitywarehouse/hearth/commit/33baa9e8edb091bbd1d17c9a3838352a7f1b87ea) Thanks [@jordmccord](https://github.com/jordmccord)! - 🌟 [FEATURE]: Adds `Timeline` and `TimelineItem`
|
|
89
|
+
|
|
90
|
+
The package now includes `Timeline` and `TimelineItem` components for showing a sequence of static stops or progress steps. The new API supports labelled items, optional helper text, progress states for complete or active steps, and custom content within an item when you need to show extra context or actions.
|
|
91
|
+
|
|
92
|
+
**Components affected**:
|
|
93
|
+
- `Timeline`
|
|
94
|
+
- `TimelineItem`
|
|
95
|
+
|
|
96
|
+
**Developer changes**:
|
|
97
|
+
|
|
98
|
+
Import `Timeline` and `TimelineItem` from `@utilitywarehouse/hearth-react-native`. Use `variant="static"` for simple ordered events, or `variant="progress"` with item `state` values to communicate step progress.
|
|
99
|
+
|
|
100
|
+
```tsx
|
|
101
|
+
import { Timeline, TimelineItem } from '@utilitywarehouse/hearth-react-native';
|
|
102
|
+
|
|
103
|
+
const MyComponent = () => (
|
|
104
|
+
<Timeline variant="progress">
|
|
105
|
+
<TimelineItem label="Ordered" helperText="We have received your order" state="complete" />
|
|
106
|
+
<TimelineItem label="Packed" helperText="Your items are ready" state="complete" />
|
|
107
|
+
<TimelineItem label="Out for delivery" helperText="Arriving today" state="active" />
|
|
108
|
+
<TimelineItem label="Delivered" helperText="Pending" state="incomplete" />
|
|
109
|
+
</Timeline>
|
|
110
|
+
);
|
|
111
|
+
```
|
|
112
|
+
|
|
3
113
|
## 0.27.3
|
|
4
114
|
|
|
5
115
|
### Patch Changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface ComboboxSelection {
|
|
2
|
+
label: string;
|
|
3
|
+
value: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ComboboxContextValue {
|
|
6
|
+
close: () => void;
|
|
7
|
+
search: string;
|
|
8
|
+
selectedValue?: string | null;
|
|
9
|
+
selectOption: (option: ComboboxSelection) => void;
|
|
10
|
+
setSearch: (value: string) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare const ComboboxContext: import("react").Context<ComboboxContextValue | undefined>;
|
|
13
|
+
export declare const useComboboxContext: () => ComboboxContextValue;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
export const ComboboxContext = createContext(undefined);
|
|
3
|
+
export const useComboboxContext = () => {
|
|
4
|
+
const context = useContext(ComboboxContext);
|
|
5
|
+
if (!context) {
|
|
6
|
+
throw new Error('useComboboxContext must be used within a Combobox');
|
|
7
|
+
}
|
|
8
|
+
return context;
|
|
9
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import ComboboxProps from './Combobox.props';
|
|
2
|
+
declare const Combobox: {
|
|
3
|
+
({ options, value, onValueChange, inputValue, onInputValueChange, label, labelVariant, placeholder, searchPlaceholder, disabled, validationStatus, helperText, helperIcon, invalidText, validText, required, children, bottomSheetProps, menuHeading, noOptionsFoundText, listProps, loading, readonly, getValueLabel, filterOption, ...rest }: ComboboxProps): import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
displayName: string;
|
|
5
|
+
};
|
|
6
|
+
export default Combobox;
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CloseSmallIcon, SearchMediumIcon } from '@utilitywarehouse/hearth-react-native-icons';
|
|
3
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import { Pressable, View } from 'react-native';
|
|
5
|
+
import { StyleSheet } from 'react-native-unistyles';
|
|
6
|
+
import { useTheme } from '../../hooks';
|
|
7
|
+
import { BodyText } from '../BodyText';
|
|
8
|
+
import { BottomSheetFlatList, BottomSheetModal, BottomSheetView } from '../BottomSheet';
|
|
9
|
+
import { DetailText } from '../DetailText';
|
|
10
|
+
import { FormField, useFormFieldContext } from '../FormField';
|
|
11
|
+
import { Icon } from '../Icon';
|
|
12
|
+
import { Input } from '../Input';
|
|
13
|
+
import { Spinner } from '../Spinner';
|
|
14
|
+
import { UnstyledIconButton } from '../UnstyledIconButton';
|
|
15
|
+
import { ComboboxContext } from './Combobox.context';
|
|
16
|
+
import { SafeAreaView } from '../SafeAreaView';
|
|
17
|
+
import ComboboxOption from './ComboboxOption';
|
|
18
|
+
const DEFAULT_SNAP_POINTS = ['25%', '40%', '80%'];
|
|
19
|
+
const Combobox = ({ options = [], value, onValueChange, inputValue, onInputValueChange, label, labelVariant = 'body', placeholder = 'Search', searchPlaceholder = 'Search', disabled = false, validationStatus = 'initial', helperText, helperIcon, invalidText, validText, required = true, children, bottomSheetProps, menuHeading, noOptionsFoundText = 'No options found', listProps, loading = false, readonly = false, getValueLabel, filterOption, ...rest }) => {
|
|
20
|
+
const formFieldContext = useFormFieldContext();
|
|
21
|
+
const validationStatusFromContext = formFieldContext?.validationStatus ?? validationStatus;
|
|
22
|
+
const isRequired = formFieldContext?.required ?? required;
|
|
23
|
+
const isDisabled = formFieldContext?.disabled ?? disabled;
|
|
24
|
+
const isReadonly = formFieldContext?.readonly ?? readonly;
|
|
25
|
+
const { color } = useTheme();
|
|
26
|
+
const bottomSheetModalRef = useRef(null);
|
|
27
|
+
const searchInputRef = useRef(null);
|
|
28
|
+
const focusTimeoutRef = useRef(null);
|
|
29
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
30
|
+
const [selectedChildLabel, setSelectedChildLabel] = useState(undefined);
|
|
31
|
+
const [uncontrolledInputValue, setUncontrolledInputValue] = useState('');
|
|
32
|
+
const isInputControlled = inputValue !== undefined;
|
|
33
|
+
const selectedOption = options.find(option => option.value === value);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (typeof children === 'function' || !children || selectedOption || !value || getValueLabel) {
|
|
36
|
+
setSelectedChildLabel(undefined);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
let nextLabel;
|
|
40
|
+
React.Children.forEach(children, child => {
|
|
41
|
+
if (!React.isValidElement(child) || nextLabel) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (child.props.value === value) {
|
|
45
|
+
nextLabel = child.props.label;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
setSelectedChildLabel(nextLabel);
|
|
49
|
+
}, [children, getValueLabel, selectedOption, value]);
|
|
50
|
+
const selectedLabel = useMemo(() => {
|
|
51
|
+
return getValueLabel?.(value) || selectedOption?.label || selectedChildLabel || '';
|
|
52
|
+
}, [getValueLabel, selectedChildLabel, selectedOption?.label, value]);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (isInputControlled) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
setUncontrolledInputValue(selectedLabel);
|
|
58
|
+
}, [isInputControlled, selectedLabel]);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
return () => {
|
|
61
|
+
if (focusTimeoutRef.current) {
|
|
62
|
+
clearTimeout(focusTimeoutRef.current);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}, []);
|
|
66
|
+
const search = isInputControlled ? (inputValue ?? '') : uncontrolledInputValue;
|
|
67
|
+
const accessibilityLabel = useMemo(() => {
|
|
68
|
+
if (!label) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
return isRequired ? `${label}, required` : label;
|
|
72
|
+
}, [isRequired, label]);
|
|
73
|
+
const accessibilityHint = useMemo(() => {
|
|
74
|
+
const hints = [];
|
|
75
|
+
if (helperText) {
|
|
76
|
+
hints.push(helperText);
|
|
77
|
+
}
|
|
78
|
+
if (validationStatusFromContext === 'invalid' && invalidText) {
|
|
79
|
+
hints.push(invalidText);
|
|
80
|
+
}
|
|
81
|
+
if (validationStatusFromContext === 'valid' && validText) {
|
|
82
|
+
hints.push(validText);
|
|
83
|
+
}
|
|
84
|
+
return hints.length > 0 ? hints.join(', ') : undefined;
|
|
85
|
+
}, [helperText, invalidText, validText, validationStatusFromContext]);
|
|
86
|
+
styles.useVariants({
|
|
87
|
+
disabled: isDisabled,
|
|
88
|
+
hasValue: search.length > 0,
|
|
89
|
+
readonly: isReadonly,
|
|
90
|
+
validationStatus: validationStatusFromContext,
|
|
91
|
+
});
|
|
92
|
+
const setSearch = useCallback((nextValue) => {
|
|
93
|
+
if (!isInputControlled) {
|
|
94
|
+
setUncontrolledInputValue(nextValue);
|
|
95
|
+
}
|
|
96
|
+
onInputValueChange?.(nextValue);
|
|
97
|
+
}, [isInputControlled, onInputValueChange]);
|
|
98
|
+
const handleClose = useCallback((index) => {
|
|
99
|
+
if (index === -1) {
|
|
100
|
+
setIsOpen(false);
|
|
101
|
+
setSearch('');
|
|
102
|
+
}
|
|
103
|
+
}, [setSearch]);
|
|
104
|
+
const focusSearchInput = useCallback(() => {
|
|
105
|
+
if (focusTimeoutRef.current) {
|
|
106
|
+
clearTimeout(focusTimeoutRef.current);
|
|
107
|
+
}
|
|
108
|
+
focusTimeoutRef.current = setTimeout(() => {
|
|
109
|
+
searchInputRef.current?.focus();
|
|
110
|
+
}, 300);
|
|
111
|
+
}, []);
|
|
112
|
+
const openBottomSheet = useCallback(() => {
|
|
113
|
+
if (isDisabled || isReadonly) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
bottomSheetModalRef.current?.present();
|
|
117
|
+
setIsOpen(true);
|
|
118
|
+
focusSearchInput();
|
|
119
|
+
}, [focusSearchInput, isDisabled, isReadonly]);
|
|
120
|
+
const closeBottomSheet = useCallback(() => {
|
|
121
|
+
bottomSheetModalRef.current?.dismiss();
|
|
122
|
+
setIsOpen(false);
|
|
123
|
+
}, []);
|
|
124
|
+
const selectOption = useCallback(({ label: optionLabel, value: optionValue }) => {
|
|
125
|
+
setSearch(optionLabel);
|
|
126
|
+
onValueChange?.(optionValue);
|
|
127
|
+
closeBottomSheet();
|
|
128
|
+
}, [closeBottomSheet, onValueChange, setSearch]);
|
|
129
|
+
const handleClear = useCallback(() => {
|
|
130
|
+
setSearch('');
|
|
131
|
+
onValueChange?.(null);
|
|
132
|
+
}, [onValueChange, setSearch]);
|
|
133
|
+
const handleClearPress = useCallback((event) => {
|
|
134
|
+
event.stopPropagation();
|
|
135
|
+
handleClear();
|
|
136
|
+
}, [handleClear]);
|
|
137
|
+
const defaultFilterOption = useCallback((option, query) => {
|
|
138
|
+
const normalizedQuery = query.trim().toLowerCase();
|
|
139
|
+
if (!normalizedQuery) {
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
const haystack = [option.label, ...(option.keywords ?? [])].map(term => term.toLowerCase());
|
|
143
|
+
return haystack.some(term => term.includes(normalizedQuery));
|
|
144
|
+
}, []);
|
|
145
|
+
const filteredOptions = useMemo(() => {
|
|
146
|
+
const optionFilter = filterOption ?? defaultFilterOption;
|
|
147
|
+
return options.filter(option => optionFilter(option, search));
|
|
148
|
+
}, [defaultFilterOption, filterOption, options, search]);
|
|
149
|
+
const renderSelectOption = useCallback(({ item }) => (_jsx(ComboboxOption, { label: item.label, value: item.value, disabled: item.disabled, leadingIcon: item.leadingIcon, trailingIcon: item.trailingIcon })), []);
|
|
150
|
+
const renderEmptyComponent = useCallback(() => (_jsx(BottomSheetView, { style: styles.emptyContainer, children: _jsx(DetailText, { children: noOptionsFoundText }) })), [noOptionsFoundText]);
|
|
151
|
+
const renderContentProps = useMemo(() => ({
|
|
152
|
+
close: closeBottomSheet,
|
|
153
|
+
search,
|
|
154
|
+
selectedValue: value,
|
|
155
|
+
selectOption,
|
|
156
|
+
setSearch,
|
|
157
|
+
}), [closeBottomSheet, search, selectOption, setSearch, value]);
|
|
158
|
+
const customContent = typeof children === 'function' ? children(renderContentProps) : children;
|
|
159
|
+
return (_jsxs(View, { ...rest, style: [styles.container, rest.style], children: [_jsx(FormField, { label: label, labelVariant: labelVariant, helperText: helperText, helperIcon: helperIcon, validationStatus: validationStatusFromContext, required: isRequired, disabled: isDisabled, readonly: isReadonly, invalidText: invalidText, validText: validText, accessibilityHandledByChildren: true, children: _jsxs(Pressable, { onPress: openBottomSheet, disabled: isDisabled || isReadonly, accessibilityRole: "button", accessibilityLabel: accessibilityLabel, accessibilityHint: accessibilityHint, accessibilityState: { expanded: isOpen, disabled: isDisabled || isReadonly }, style: ({ pressed }) => [styles.trigger, (pressed || isOpen) && styles.triggerFocused], children: [_jsx(View, { style: styles.leadingIconContainer, children: _jsx(Icon, { as: SearchMediumIcon, style: styles.icon }) }), _jsx(View, { style: styles.valueContainer, children: _jsx(BodyText, { numberOfLines: 1, style: styles.valueText, children: search || placeholder }) }), loading && _jsx(Spinner, { size: "xs", color: color.icon.primary }), !!search && (_jsx(UnstyledIconButton, { accessibilityLabel: "Clear search", onPress: handleClearPress, icon: CloseSmallIcon }))] }) }), _jsx(BottomSheetModal, { ref: bottomSheetModalRef, snapPoints: DEFAULT_SNAP_POINTS, onChange: handleClose, enableDynamicSizing: false, ...bottomSheetProps, children: _jsxs(ComboboxContext.Provider, { value: {
|
|
160
|
+
close: closeBottomSheet,
|
|
161
|
+
search,
|
|
162
|
+
selectedValue: value,
|
|
163
|
+
selectOption,
|
|
164
|
+
setSearch,
|
|
165
|
+
}, children: [_jsxs(SafeAreaView, { edges: ['top'], children: [menuHeading && (_jsx(View, { style: styles.headingContainer, children: _jsx(DetailText, { size: "lg", children: menuHeading }) })), _jsx(View, { style: styles.searchContainer, children: _jsx(Input, { ref: searchInputRef, placeholder: searchPlaceholder, value: search, inBottomSheet: true, onChangeText: setSearch, type: "search", clearable: true, onClear: handleClear, loading: loading }) })] }), customContent || (_jsx(BottomSheetFlatList, { data: filteredOptions, keyExtractor: (option) => option.value, renderItem: renderSelectOption, ListEmptyComponent: renderEmptyComponent, ...listProps }))] }) })] }));
|
|
166
|
+
};
|
|
167
|
+
const styles = StyleSheet.create(theme => ({
|
|
168
|
+
container: {
|
|
169
|
+
gap: theme.components.select.gap,
|
|
170
|
+
},
|
|
171
|
+
trigger: {
|
|
172
|
+
flexDirection: 'row',
|
|
173
|
+
alignItems: 'center',
|
|
174
|
+
minHeight: theme.components.input.height,
|
|
175
|
+
backgroundColor: theme.color.surface.neutral.strong,
|
|
176
|
+
borderWidth: theme.components.input.borderWidth,
|
|
177
|
+
borderColor: theme.color.border.strong,
|
|
178
|
+
borderRadius: theme.components.input.borderRadius,
|
|
179
|
+
paddingHorizontal: theme.components.input.paddingHorizontal,
|
|
180
|
+
gap: theme.components.input.gap,
|
|
181
|
+
outlineStyle: 'solid',
|
|
182
|
+
outlineWidth: theme.components.input.borderWidth,
|
|
183
|
+
outlineColor: theme.color.border.strong,
|
|
184
|
+
variants: {
|
|
185
|
+
disabled: {
|
|
186
|
+
true: {
|
|
187
|
+
opacity: theme.opacity.disabled,
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
readonly: {
|
|
191
|
+
true: {
|
|
192
|
+
borderColor: theme.color.border.subtle,
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
validationStatus: {
|
|
196
|
+
initial: {},
|
|
197
|
+
valid: {
|
|
198
|
+
borderColor: theme.color.feedback.positive.border,
|
|
199
|
+
outlineColor: theme.color.feedback.positive.border,
|
|
200
|
+
},
|
|
201
|
+
invalid: {
|
|
202
|
+
borderColor: theme.color.feedback.danger.border,
|
|
203
|
+
outlineColor: theme.color.feedback.danger.border,
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
triggerFocused: {
|
|
209
|
+
outlineWidth: theme.components.input.borderWidthFocused,
|
|
210
|
+
},
|
|
211
|
+
leadingIconContainer: {
|
|
212
|
+
alignItems: 'center',
|
|
213
|
+
justifyContent: 'center',
|
|
214
|
+
},
|
|
215
|
+
valueContainer: {
|
|
216
|
+
flex: 1,
|
|
217
|
+
},
|
|
218
|
+
valueText: {
|
|
219
|
+
variants: {
|
|
220
|
+
hasValue: {
|
|
221
|
+
false: {
|
|
222
|
+
color: theme.color.text.secondary,
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
icon: {
|
|
228
|
+
color: theme.color.icon.primary,
|
|
229
|
+
},
|
|
230
|
+
headingContainer: {
|
|
231
|
+
paddingHorizontal: theme.components.bottomSheet.padding,
|
|
232
|
+
marginBottom: theme.components.select.gap,
|
|
233
|
+
},
|
|
234
|
+
searchContainer: {
|
|
235
|
+
paddingTop: 1,
|
|
236
|
+
paddingHorizontal: theme.components.bottomSheet.padding,
|
|
237
|
+
paddingBottom: theme.components.select.gap,
|
|
238
|
+
},
|
|
239
|
+
emptyContainer: {
|
|
240
|
+
alignItems: 'center',
|
|
241
|
+
justifyContent: 'center',
|
|
242
|
+
marginTop: theme.space.md,
|
|
243
|
+
},
|
|
244
|
+
}));
|
|
245
|
+
Combobox.displayName = 'Combobox';
|
|
246
|
+
export default Combobox;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { BottomSheetFlatListProps } from '@gorhom/bottom-sheet/lib/typescript/components/bottomSheetScrollable/types';
|
|
2
|
+
import { ComponentType, ReactNode } from 'react';
|
|
3
|
+
import { ViewProps } from 'react-native';
|
|
4
|
+
import { BottomSheetProps } from '../BottomSheet';
|
|
5
|
+
import { ComboboxSelection } from './Combobox.context';
|
|
6
|
+
type ValidationStatus = 'initial' | 'valid' | 'invalid';
|
|
7
|
+
export interface ComboboxOptionItemProps {
|
|
8
|
+
/**
|
|
9
|
+
* Label shown for this option.
|
|
10
|
+
*/
|
|
11
|
+
label: string;
|
|
12
|
+
/**
|
|
13
|
+
* Value returned when this option is selected.
|
|
14
|
+
*/
|
|
15
|
+
value: string;
|
|
16
|
+
/**
|
|
17
|
+
* Optional icon shown before the option label.
|
|
18
|
+
*/
|
|
19
|
+
leadingIcon?: ComponentType;
|
|
20
|
+
/**
|
|
21
|
+
* Optional icon shown after the option label.
|
|
22
|
+
*/
|
|
23
|
+
trailingIcon?: ComponentType;
|
|
24
|
+
/**
|
|
25
|
+
* Additional searchable terms for this option.
|
|
26
|
+
*/
|
|
27
|
+
keywords?: string[];
|
|
28
|
+
/**
|
|
29
|
+
* Whether this option is disabled.
|
|
30
|
+
*/
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface ComboboxRenderContentProps {
|
|
34
|
+
/**
|
|
35
|
+
* Current search value used by both the trigger and bottom sheet input.
|
|
36
|
+
*/
|
|
37
|
+
search: string;
|
|
38
|
+
/**
|
|
39
|
+
* Update the search value.
|
|
40
|
+
*/
|
|
41
|
+
setSearch: (value: string) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Close the bottom sheet.
|
|
44
|
+
*/
|
|
45
|
+
close: () => void;
|
|
46
|
+
/**
|
|
47
|
+
* Select an option, update the trigger text and close the bottom sheet.
|
|
48
|
+
*/
|
|
49
|
+
selectOption: (option: ComboboxSelection) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Currently selected value.
|
|
52
|
+
*/
|
|
53
|
+
selectedValue?: string | null;
|
|
54
|
+
}
|
|
55
|
+
export interface ComboboxOptionProps extends ComboboxOptionItemProps {
|
|
56
|
+
/**
|
|
57
|
+
* Whether this option is selected.
|
|
58
|
+
*/
|
|
59
|
+
selected?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Custom press handler for this option.
|
|
62
|
+
*/
|
|
63
|
+
onPress?: (value: string) => void;
|
|
64
|
+
}
|
|
65
|
+
type ComboboxChildren = ReactNode | ((props: ComboboxRenderContentProps) => ReactNode);
|
|
66
|
+
interface ComboboxProps extends Omit<ViewProps, 'children'> {
|
|
67
|
+
/**
|
|
68
|
+
* Array of options to render using the default bottom sheet list.
|
|
69
|
+
*/
|
|
70
|
+
options?: ComboboxOptionItemProps[];
|
|
71
|
+
/**
|
|
72
|
+
* Currently selected value.
|
|
73
|
+
*/
|
|
74
|
+
value?: string | null;
|
|
75
|
+
/**
|
|
76
|
+
* Callback fired when the selected value changes.
|
|
77
|
+
*/
|
|
78
|
+
onValueChange?: (value: string | null) => void;
|
|
79
|
+
/**
|
|
80
|
+
* Controlled search value used by the trigger and bottom sheet input.
|
|
81
|
+
*/
|
|
82
|
+
inputValue?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Callback fired when the search value changes.
|
|
85
|
+
*/
|
|
86
|
+
onInputValueChange?: (value: string) => void;
|
|
87
|
+
/**
|
|
88
|
+
* Label shown above the combobox.
|
|
89
|
+
*/
|
|
90
|
+
label?: string;
|
|
91
|
+
/**
|
|
92
|
+
* The variant of the label text.
|
|
93
|
+
*
|
|
94
|
+
* @default 'body'
|
|
95
|
+
*/
|
|
96
|
+
labelVariant?: 'heading' | 'body';
|
|
97
|
+
/**
|
|
98
|
+
* Helper text shown below the label.
|
|
99
|
+
*/
|
|
100
|
+
helperText?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Optional helper icon.
|
|
103
|
+
*/
|
|
104
|
+
helperIcon?: ComponentType;
|
|
105
|
+
/**
|
|
106
|
+
* Text shown for invalid state.
|
|
107
|
+
*/
|
|
108
|
+
invalidText?: string;
|
|
109
|
+
/**
|
|
110
|
+
* Text shown for valid state.
|
|
111
|
+
*/
|
|
112
|
+
validText?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Placeholder shown when the combobox is empty.
|
|
115
|
+
*
|
|
116
|
+
* @default 'Search'
|
|
117
|
+
*/
|
|
118
|
+
placeholder?: string;
|
|
119
|
+
/**
|
|
120
|
+
* Placeholder shown in the bottom sheet search input.
|
|
121
|
+
*
|
|
122
|
+
* @default 'Search'
|
|
123
|
+
*/
|
|
124
|
+
searchPlaceholder?: string;
|
|
125
|
+
/**
|
|
126
|
+
* Whether the combobox is disabled.
|
|
127
|
+
*/
|
|
128
|
+
disabled?: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Validation status for the combobox.
|
|
131
|
+
*
|
|
132
|
+
* @default 'initial'
|
|
133
|
+
*/
|
|
134
|
+
validationStatus?: ValidationStatus;
|
|
135
|
+
/**
|
|
136
|
+
* Whether the combobox is required.
|
|
137
|
+
*
|
|
138
|
+
* @default true
|
|
139
|
+
*/
|
|
140
|
+
required?: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Heading displayed above the bottom sheet search input.
|
|
143
|
+
*/
|
|
144
|
+
menuHeading?: string;
|
|
145
|
+
/**
|
|
146
|
+
* Custom bottom sheet content, or a render function for fully custom list rendering.
|
|
147
|
+
*/
|
|
148
|
+
children?: ComboboxChildren;
|
|
149
|
+
/**
|
|
150
|
+
* Props passed to the BottomSheetModal.
|
|
151
|
+
*/
|
|
152
|
+
bottomSheetProps?: Partial<BottomSheetProps>;
|
|
153
|
+
/**
|
|
154
|
+
* Text shown when no options match the current search.
|
|
155
|
+
*
|
|
156
|
+
* @default 'No options found'
|
|
157
|
+
*/
|
|
158
|
+
noOptionsFoundText?: string;
|
|
159
|
+
/**
|
|
160
|
+
* Props passed to the default BottomSheetFlatList renderer.
|
|
161
|
+
*/
|
|
162
|
+
listProps?: Partial<BottomSheetFlatListProps<ComboboxOptionItemProps>>;
|
|
163
|
+
/**
|
|
164
|
+
* Whether the combobox should show a loading spinner.
|
|
165
|
+
*/
|
|
166
|
+
loading?: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Whether the combobox is readonly.
|
|
169
|
+
*/
|
|
170
|
+
readonly?: boolean;
|
|
171
|
+
/**
|
|
172
|
+
* Resolve a label for a selected value when the current options array does not contain it.
|
|
173
|
+
*/
|
|
174
|
+
getValueLabel?: (value: string | null | undefined) => string;
|
|
175
|
+
/**
|
|
176
|
+
* Override the default filtering behaviour for the default options list.
|
|
177
|
+
*/
|
|
178
|
+
filterOption?: (option: ComboboxOptionItemProps, search: string) => boolean;
|
|
179
|
+
}
|
|
180
|
+
export default ComboboxProps;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ComboboxOptionProps } from './Combobox.props';
|
|
2
|
+
declare const ComboboxOption: {
|
|
3
|
+
({ label, value, leadingIcon: LeftIcon, trailingIcon: RightIcon, selected, disabled, onPress, }: ComboboxOptionProps): import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
displayName: string;
|
|
5
|
+
};
|
|
6
|
+
export default ComboboxOption;
|