react-native-molecules 0.5.0-beta.22 → 0.5.0-beta.23
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/components/Button/Button.tsx +3 -1
- package/components/DatePicker/utils.ts +2 -0
- package/components/DatePickerInline/MonthPicker.tsx +24 -40
- package/components/DatePickerInline/YearPicker.tsx +44 -79
- package/components/List/List.tsx +154 -386
- package/components/List/context.tsx +2 -4
- package/components/List/index.ts +0 -1
- package/components/List/types.ts +77 -109
- package/components/List/utils.ts +4 -37
- package/components/Menu/Menu.tsx +13 -30
- package/components/Menu/index.tsx +0 -2
- package/components/Popover/Popover.tsx +7 -10
- package/components/Popover/PopoverRoot.tsx +6 -20
- package/components/Popover/common.ts +4 -0
- package/components/Popover/index.ts +2 -8
- package/components/Popover/usePlatformMeasure.ts +4 -2
- package/components/Select/Select.tsx +211 -47
- package/components/Select/context.tsx +27 -2
- package/components/Select/types.ts +41 -25
- package/components/Select/utils.ts +7 -0
- package/components/TouchableRipple/TouchableRipple.tsx +76 -152
- package/package.json +3 -2
|
@@ -81,6 +81,8 @@ export type Props = Omit<SurfaceProps, 'style'> &
|
|
|
81
81
|
disabledPress?: boolean;
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
+
const emptyObj = {};
|
|
85
|
+
|
|
84
86
|
const Button = (
|
|
85
87
|
{
|
|
86
88
|
disabled = false,
|
|
@@ -97,7 +99,7 @@ const Button = (
|
|
|
97
99
|
style: styleProp,
|
|
98
100
|
testID,
|
|
99
101
|
accessible,
|
|
100
|
-
stateLayerProps =
|
|
102
|
+
stateLayerProps = emptyObj,
|
|
101
103
|
elevation: elevationProp,
|
|
102
104
|
textRelatedStyle,
|
|
103
105
|
disabledPress,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { setMonth } from 'date-fns';
|
|
2
2
|
import { memo, useCallback, useMemo } from 'react';
|
|
3
|
-
import { FlatList,
|
|
3
|
+
import { FlatList, View, type ViewStyle } from 'react-native';
|
|
4
4
|
import { StyleSheet } from 'react-native-unistyles';
|
|
5
5
|
|
|
6
6
|
import { resolveStateVariant } from '../../utils';
|
|
@@ -9,7 +9,7 @@ import type { DatePickerLocale } from '../DatePicker/context';
|
|
|
9
9
|
import { datePickerMonthItemStyles, datePickerMonthPickerStyles } from '../DatePicker/utils';
|
|
10
10
|
import { Divider } from '../Divider';
|
|
11
11
|
import { Icon } from '../Icon';
|
|
12
|
-
import { List, type
|
|
12
|
+
import { List, type ListItemId, useListContextValue } from '../List';
|
|
13
13
|
import { Text } from '../Text';
|
|
14
14
|
import { useDatePickerInlineStore, useDatePickerInlineStoreValue } from './store';
|
|
15
15
|
|
|
@@ -28,48 +28,22 @@ export default function MonthPicker({ locale }: { locale?: DatePickerLocale }) {
|
|
|
28
28
|
);
|
|
29
29
|
|
|
30
30
|
const handleOnChange = useCallback(
|
|
31
|
-
(
|
|
32
|
-
if (
|
|
31
|
+
(value: ListItemId | null) => {
|
|
32
|
+
if (typeof value !== 'number') return;
|
|
33
33
|
setStore(prev => ({
|
|
34
|
-
localDate: setMonth(prev.localDate,
|
|
34
|
+
localDate: setMonth(prev.localDate, value),
|
|
35
35
|
pickerType: undefined,
|
|
36
36
|
}));
|
|
37
37
|
},
|
|
38
38
|
[setStore],
|
|
39
39
|
);
|
|
40
40
|
|
|
41
|
-
const processFlatListProps = useCallback(
|
|
42
|
-
({
|
|
43
|
-
props,
|
|
44
|
-
items,
|
|
45
|
-
}: ListContentProcessPropsArgs<
|
|
46
|
-
MonthListItem,
|
|
47
|
-
Omit<FlatListProps<MonthListItem>, 'children' | 'ref'>
|
|
48
|
-
>): FlatListProps<MonthListItem> => ({
|
|
49
|
-
...props,
|
|
50
|
-
data: items,
|
|
51
|
-
renderItem: ({ item }) => (
|
|
52
|
-
<Month
|
|
53
|
-
month={item.id}
|
|
54
|
-
monthStyles={datePickerMonthPickerStyles.root}
|
|
55
|
-
locale={locale}
|
|
56
|
-
/>
|
|
57
|
-
),
|
|
58
|
-
keyExtractor: item => `${item.id}`,
|
|
59
|
-
}),
|
|
60
|
-
[locale],
|
|
61
|
-
);
|
|
62
|
-
|
|
63
41
|
if (!selectingMonth) {
|
|
64
42
|
return null;
|
|
65
43
|
}
|
|
66
44
|
|
|
67
45
|
return (
|
|
68
|
-
<List
|
|
69
|
-
items={monthItems}
|
|
70
|
-
multiple={false}
|
|
71
|
-
value={localDate.getMonth()}
|
|
72
|
-
onChange={handleOnChange}>
|
|
46
|
+
<List multiple={false} value={localDate.getMonth()} onChange={handleOnChange}>
|
|
73
47
|
<View
|
|
74
48
|
style={[
|
|
75
49
|
StyleSheet.absoluteFill,
|
|
@@ -78,10 +52,17 @@ export default function MonthPicker({ locale }: { locale?: DatePickerLocale }) {
|
|
|
78
52
|
]}
|
|
79
53
|
pointerEvents={selectingMonth ? 'auto' : 'none'}>
|
|
80
54
|
<Divider />
|
|
81
|
-
<
|
|
82
|
-
ContainerComponent={FlatList<MonthListItem>}
|
|
55
|
+
<FlatList<MonthListItem>
|
|
83
56
|
style={styles.list}
|
|
84
|
-
|
|
57
|
+
data={monthItems}
|
|
58
|
+
renderItem={({ item }) => (
|
|
59
|
+
<Month
|
|
60
|
+
month={item.id}
|
|
61
|
+
monthStyles={datePickerMonthPickerStyles.root}
|
|
62
|
+
locale={locale}
|
|
63
|
+
/>
|
|
64
|
+
)}
|
|
65
|
+
keyExtractor={item => `${item.id}`}
|
|
85
66
|
/>
|
|
86
67
|
</View>
|
|
87
68
|
</List>
|
|
@@ -131,16 +112,16 @@ function MonthPure({
|
|
|
131
112
|
accessibilityLabel={String(month)}
|
|
132
113
|
accessibilityState={accessibilityState}
|
|
133
114
|
style={monthButtonStyle}
|
|
134
|
-
testID={`pick-month-${month}`}
|
|
135
|
-
|
|
136
|
-
isSelected ? (
|
|
115
|
+
testID={`pick-month-${month}`}>
|
|
116
|
+
<View style={styles.left}>
|
|
117
|
+
{isSelected ? (
|
|
137
118
|
<View style={styles.checkIconView}>
|
|
138
119
|
<Icon name="check" size={24} />
|
|
139
120
|
</View>
|
|
140
121
|
) : (
|
|
141
122
|
<View style={styles.spacer} />
|
|
142
|
-
)
|
|
143
|
-
|
|
123
|
+
)}
|
|
124
|
+
</View>
|
|
144
125
|
<View style={datePickerMonthItemStyles.monthInner}>
|
|
145
126
|
<Text style={datePickerMonthItemStyles.monthLabel} selectable={false}>
|
|
146
127
|
{monthLabel}
|
|
@@ -165,6 +146,9 @@ const styles = StyleSheet.create(theme => ({
|
|
|
165
146
|
spacer: {
|
|
166
147
|
width: 44,
|
|
167
148
|
},
|
|
149
|
+
left: {
|
|
150
|
+
marginRight: theme.spacings['2'],
|
|
151
|
+
},
|
|
168
152
|
|
|
169
153
|
list: {
|
|
170
154
|
flex: 1,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { setYear } from 'date-fns';
|
|
2
2
|
import { memo, useCallback, useLayoutEffect, useMemo, useRef } from 'react';
|
|
3
|
-
import { FlatList,
|
|
3
|
+
import { FlatList, StyleSheet, View } from 'react-native';
|
|
4
4
|
|
|
5
5
|
import { getYearRange, resolveStateVariant } from '../../utils';
|
|
6
6
|
import { datePickerMonthItemStyles, datePickerMonthPickerStyles } from '../DatePicker/utils';
|
|
7
7
|
import { Divider } from '../Divider';
|
|
8
8
|
import { Icon } from '../Icon';
|
|
9
|
-
import { List, type
|
|
9
|
+
import { List, type ListItemId, useListContextValue } from '../List';
|
|
10
10
|
import { Text } from '../Text';
|
|
11
11
|
import { useDatePickerInlineStore } from './store';
|
|
12
12
|
import { datePickerYearItemStyles, datePickerYearPickerStyles } from './utils';
|
|
@@ -69,10 +69,10 @@ function YearPickerGrid() {
|
|
|
69
69
|
}, [selectingYear]);
|
|
70
70
|
|
|
71
71
|
const handleOnChange = useCallback(
|
|
72
|
-
(
|
|
73
|
-
if (
|
|
72
|
+
(value: ListItemId | null) => {
|
|
73
|
+
if (typeof value !== 'number') return;
|
|
74
74
|
setStore(prev => ({
|
|
75
|
-
localDate: setYear(prev.localDate,
|
|
75
|
+
localDate: setYear(prev.localDate, value),
|
|
76
76
|
pickerType: undefined,
|
|
77
77
|
}));
|
|
78
78
|
},
|
|
@@ -88,48 +88,26 @@ function YearPickerGrid() {
|
|
|
88
88
|
[],
|
|
89
89
|
);
|
|
90
90
|
|
|
91
|
-
const processGridFlatListProps = useCallback(
|
|
92
|
-
({
|
|
93
|
-
props,
|
|
94
|
-
items,
|
|
95
|
-
isEmpty,
|
|
96
|
-
emptyState,
|
|
97
|
-
}: ListContentProcessPropsArgs<
|
|
98
|
-
YearListItem,
|
|
99
|
-
Omit<FlatListProps<YearListItem>, 'children' | 'ref'>
|
|
100
|
-
>): FlatListProps<YearListItem> => ({
|
|
101
|
-
...props,
|
|
102
|
-
data: items,
|
|
103
|
-
numColumns: NUM_COLUMNS,
|
|
104
|
-
contentContainerStyle: gridStyles.grid,
|
|
105
|
-
columnWrapperStyle: gridStyles.row,
|
|
106
|
-
renderItem: ({ item }) => (
|
|
107
|
-
<View style={gridStyles.cell}>
|
|
108
|
-
<YearPill year={item.id} yearStyles={yearStyle} />
|
|
109
|
-
</View>
|
|
110
|
-
),
|
|
111
|
-
keyExtractor: item => `${item.id}`,
|
|
112
|
-
getItemLayout: getRowLayout,
|
|
113
|
-
initialScrollIndex: Math.floor(initialScrollOffset / GRID_ITEM_HEIGHT),
|
|
114
|
-
removeClippedSubviews: true,
|
|
115
|
-
ListEmptyComponent: isEmpty
|
|
116
|
-
? function GridListEmpty() {
|
|
117
|
-
return <>{emptyState}</>;
|
|
118
|
-
}
|
|
119
|
-
: undefined,
|
|
120
|
-
}),
|
|
121
|
-
[getRowLayout, initialScrollOffset, yearStyle],
|
|
122
|
-
);
|
|
123
|
-
|
|
124
91
|
return (
|
|
125
|
-
<List
|
|
92
|
+
<List multiple={false} value={selectedYear} onChange={handleOnChange}>
|
|
126
93
|
<View style={containerStyle} pointerEvents={selectingYear ? 'auto' : 'none'}>
|
|
127
94
|
<Divider />
|
|
128
|
-
<
|
|
95
|
+
<FlatList<YearListItem>
|
|
129
96
|
ref={flatListRef}
|
|
130
|
-
ContainerComponent={FlatList<YearListItem>}
|
|
131
97
|
style={gridStyles.list}
|
|
132
|
-
|
|
98
|
+
data={yearItems}
|
|
99
|
+
numColumns={NUM_COLUMNS}
|
|
100
|
+
contentContainerStyle={gridStyles.grid}
|
|
101
|
+
columnWrapperStyle={gridStyles.row}
|
|
102
|
+
renderItem={({ item }) => (
|
|
103
|
+
<View style={gridStyles.cell}>
|
|
104
|
+
<YearPill year={item.id} yearStyles={yearStyle} />
|
|
105
|
+
</View>
|
|
106
|
+
)}
|
|
107
|
+
keyExtractor={item => `${item.id}`}
|
|
108
|
+
getItemLayout={getRowLayout}
|
|
109
|
+
initialScrollIndex={Math.floor(initialScrollOffset / GRID_ITEM_HEIGHT)}
|
|
110
|
+
removeClippedSubviews
|
|
133
111
|
/>
|
|
134
112
|
</View>
|
|
135
113
|
</List>
|
|
@@ -149,17 +127,18 @@ function YearPillPure({ year, yearStyles }: { year: number; yearStyles: Record<s
|
|
|
149
127
|
return (
|
|
150
128
|
<List.Item
|
|
151
129
|
value={year}
|
|
152
|
-
contentStyle={datePickerYearItemStyles.content}
|
|
153
130
|
accessibilityRole="button"
|
|
154
131
|
accessibilityLabel={String(year)}
|
|
155
132
|
style={[yearStyles, datePickerYearItemStyles.yearButton]}
|
|
156
133
|
testID={`pick-year-${year}`}>
|
|
157
|
-
<
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
134
|
+
<View style={datePickerYearItemStyles.content}>
|
|
135
|
+
<Text
|
|
136
|
+
typescale="bodyLarge"
|
|
137
|
+
style={datePickerYearItemStyles.yearLabel}
|
|
138
|
+
selectable={false}>
|
|
139
|
+
{year}
|
|
140
|
+
</Text>
|
|
141
|
+
</View>
|
|
163
142
|
</List.Item>
|
|
164
143
|
);
|
|
165
144
|
}
|
|
@@ -186,10 +165,10 @@ function YearPickerList() {
|
|
|
186
165
|
}, [selectedYear, years]);
|
|
187
166
|
|
|
188
167
|
const handleOnChange = useCallback(
|
|
189
|
-
(
|
|
190
|
-
if (
|
|
168
|
+
(value: ListItemId | null) => {
|
|
169
|
+
if (typeof value !== 'number') return;
|
|
191
170
|
setStore(prev => ({
|
|
192
|
-
localDate: setYear(prev.localDate,
|
|
171
|
+
localDate: setYear(prev.localDate, value),
|
|
193
172
|
pickerType: undefined,
|
|
194
173
|
}));
|
|
195
174
|
},
|
|
@@ -205,34 +184,19 @@ function YearPickerList() {
|
|
|
205
184
|
[],
|
|
206
185
|
);
|
|
207
186
|
|
|
208
|
-
const processFlatListProps = useCallback(
|
|
209
|
-
({
|
|
210
|
-
props,
|
|
211
|
-
items,
|
|
212
|
-
}: ListContentProcessPropsArgs<
|
|
213
|
-
YearListItem,
|
|
214
|
-
Omit<FlatListProps<YearListItem>, 'children' | 'ref'>
|
|
215
|
-
>): FlatListProps<YearListItem> => ({
|
|
216
|
-
...props,
|
|
217
|
-
data: items,
|
|
218
|
-
renderItem: ({ item }) => <YearRow year={item.id} />,
|
|
219
|
-
keyExtractor: item => `${item.id}`,
|
|
220
|
-
initialScrollIndex,
|
|
221
|
-
getItemLayout,
|
|
222
|
-
}),
|
|
223
|
-
[getItemLayout, initialScrollIndex],
|
|
224
|
-
);
|
|
225
|
-
|
|
226
187
|
if (!selectingYear) return null;
|
|
227
188
|
|
|
228
189
|
return (
|
|
229
|
-
<List
|
|
190
|
+
<List multiple={false} value={selectedYear} onChange={handleOnChange}>
|
|
230
191
|
<View style={[StyleSheet.absoluteFill, listStyles.root]} pointerEvents="auto">
|
|
231
192
|
<Divider />
|
|
232
|
-
<
|
|
233
|
-
ContainerComponent={FlatList<YearListItem>}
|
|
193
|
+
<FlatList<YearListItem>
|
|
234
194
|
style={listStyles.list}
|
|
235
|
-
|
|
195
|
+
data={yearItems}
|
|
196
|
+
renderItem={({ item }) => <YearRow year={item.id} />}
|
|
197
|
+
keyExtractor={item => `${item.id}`}
|
|
198
|
+
initialScrollIndex={initialScrollIndex}
|
|
199
|
+
getItemLayout={getItemLayout}
|
|
236
200
|
/>
|
|
237
201
|
</View>
|
|
238
202
|
</List>
|
|
@@ -255,16 +219,16 @@ function YearRowPure({ year }: { year: number }) {
|
|
|
255
219
|
accessibilityRole="button"
|
|
256
220
|
accessibilityLabel={String(year)}
|
|
257
221
|
style={datePickerMonthItemStyles.monthButton}
|
|
258
|
-
testID={`pick-year-${year}`}
|
|
259
|
-
|
|
260
|
-
isSelected ? (
|
|
222
|
+
testID={`pick-year-${year}`}>
|
|
223
|
+
<View style={listStyles.left}>
|
|
224
|
+
{isSelected ? (
|
|
261
225
|
<View style={listStyles.checkIconView}>
|
|
262
226
|
<Icon name="check" size={24} />
|
|
263
227
|
</View>
|
|
264
228
|
) : (
|
|
265
229
|
<View style={listStyles.spacer} />
|
|
266
|
-
)
|
|
267
|
-
|
|
230
|
+
)}
|
|
231
|
+
</View>
|
|
268
232
|
<View style={datePickerMonthItemStyles.monthInner}>
|
|
269
233
|
<Text style={datePickerMonthItemStyles.monthLabel} selectable={false}>
|
|
270
234
|
{year}
|
|
@@ -313,4 +277,5 @@ const listStyles = StyleSheet.create({
|
|
|
313
277
|
list: { flex: 1 },
|
|
314
278
|
checkIconView: { marginLeft: 16 },
|
|
315
279
|
spacer: { width: 44 },
|
|
280
|
+
left: { marginRight: 8 },
|
|
316
281
|
});
|