react-native-molecules 0.5.0-beta.21 → 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/Card/Card.tsx +1 -1
- package/components/Checkbox/CheckboxBase.ios.tsx +1 -4
- package/components/Checkbox/CheckboxBase.tsx +2 -7
- package/components/DatePicker/DateCalendar.tsx +4 -4
- package/components/DatePicker/DatePickerModal.tsx +2 -1
- package/components/DatePicker/utils.ts +2 -0
- package/components/DatePickerInline/DatePickerDockedHeader.tsx +3 -3
- package/components/DatePickerInline/DatePickerInline.tsx +1 -1
- package/components/DatePickerInline/DatePickerInlineBase.tsx +2 -2
- package/components/DatePickerInline/DatePickerInlineHeader.tsx +43 -17
- package/components/DatePickerInline/HeaderItem.tsx +2 -2
- package/components/DatePickerInline/MonthPicker.tsx +58 -64
- package/components/DatePickerInline/Swiper.native.tsx +2 -2
- package/components/DatePickerInline/Swiper.tsx +3 -3
- package/components/DatePickerInline/YearPicker.tsx +108 -119
- package/components/DatePickerInline/{DatePickerContext.tsx → store.tsx} +7 -3
- package/components/DatePickerInline/types.ts +1 -1
- package/components/Divider/Divider.tsx +192 -0
- package/components/Divider/index.tsx +11 -0
- package/components/Drawer/DrawerItemGroup.tsx +3 -7
- package/components/IconButton/IconButton.tsx +2 -12
- package/components/List/List.tsx +275 -0
- package/components/List/context.tsx +26 -0
- package/components/List/index.ts +8 -0
- package/components/List/types.ts +117 -0
- package/components/List/utils.ts +79 -0
- package/components/Menu/Menu.tsx +146 -19
- package/components/Menu/index.tsx +9 -7
- package/components/Menu/utils.ts +21 -70
- 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/RadioButton/RadioButtonAndroid.tsx +38 -54
- package/components/RadioButton/RadioButtonIOS.tsx +2 -16
- package/components/Select/Select.tsx +307 -501
- package/components/Select/context.tsx +39 -32
- package/components/Select/types.ts +63 -56
- package/components/Select/utils.ts +19 -44
- package/components/Text/textFactory.tsx +17 -5
- package/components/TimePicker/TimeInput.tsx +2 -7
- package/components/TimePicker/utils.ts +0 -4
- package/components/TouchableRipple/TouchableRipple.native.tsx +36 -5
- package/components/TouchableRipple/TouchableRipple.tsx +121 -163
- package/components/TouchableRipple/rippleFromForegroundColor.ts +21 -0
- package/package.json +6 -3
- package/components/HorizontalDivider/HorizontalDivider.tsx +0 -103
- package/components/HorizontalDivider/index.tsx +0 -9
- package/components/ListItem/ListItem.tsx +0 -138
- package/components/ListItem/ListItemDescription.tsx +0 -25
- package/components/ListItem/ListItemTitle.tsx +0 -25
- package/components/ListItem/index.tsx +0 -14
- package/components/ListItem/utils.ts +0 -115
- package/components/Menu/MenuDivider.tsx +0 -13
- package/components/Menu/MenuItem.tsx +0 -128
- package/components/VerticalDivider/VerticalDivider.tsx +0 -100
- package/components/VerticalDivider/index.tsx +0 -9
|
@@ -1,16 +1,18 @@
|
|
|
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
|
-
import {
|
|
7
|
+
import { Divider } from '../Divider';
|
|
8
8
|
import { Icon } from '../Icon';
|
|
9
|
-
import {
|
|
9
|
+
import { List, type ListItemId, useListContextValue } from '../List';
|
|
10
10
|
import { Text } from '../Text';
|
|
11
|
-
import {
|
|
11
|
+
import { useDatePickerInlineStore } from './store';
|
|
12
12
|
import { datePickerYearItemStyles, datePickerYearPickerStyles } from './utils';
|
|
13
13
|
|
|
14
|
+
type YearListItem = { id: number; label: string };
|
|
15
|
+
|
|
14
16
|
const GRID_ITEM_HEIGHT = 62;
|
|
15
17
|
const NUM_COLUMNS = 3;
|
|
16
18
|
const LIST_ITEM_HEIGHT = 46;
|
|
@@ -25,23 +27,19 @@ export default function YearPicker({ layout = 'grid' }: YearPickerProps) {
|
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
function YearPickerGrid() {
|
|
28
|
-
const [{ startDateYear, endDateYear, localDate, pickerType }, setStore] =
|
|
29
|
-
state => state
|
|
30
|
-
);
|
|
30
|
+
const [{ startDateYear, endDateYear, localDate, pickerType }, setStore] =
|
|
31
|
+
useDatePickerInlineStore(state => state);
|
|
31
32
|
const years = useMemo(
|
|
32
33
|
() => getYearRange(startDateYear, endDateYear),
|
|
33
34
|
[startDateYear, endDateYear],
|
|
34
35
|
);
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
return chunks;
|
|
41
|
-
}, [years]);
|
|
36
|
+
const yearItems = useMemo(
|
|
37
|
+
() => years.map(year => ({ id: year, label: String(year) })),
|
|
38
|
+
[years],
|
|
39
|
+
);
|
|
42
40
|
const selectingYear = pickerType === 'year';
|
|
43
41
|
const selectedYear = localDate.getFullYear();
|
|
44
|
-
const
|
|
42
|
+
const flatListRef = useRef<FlatList<YearListItem> | null>(null);
|
|
45
43
|
|
|
46
44
|
const initialScrollOffset = useMemo(() => {
|
|
47
45
|
if (years.length === 0) return 0;
|
|
@@ -53,7 +51,7 @@ function YearPickerGrid() {
|
|
|
53
51
|
|
|
54
52
|
useLayoutEffect(() => {
|
|
55
53
|
if (!selectingYear) return;
|
|
56
|
-
|
|
54
|
+
flatListRef.current?.scrollToOffset({ offset: initialScrollOffset, animated: false });
|
|
57
55
|
}, [selectingYear, initialScrollOffset]);
|
|
58
56
|
|
|
59
57
|
const { containerStyle, yearStyle } = useMemo(() => {
|
|
@@ -71,92 +69,92 @@ function YearPickerGrid() {
|
|
|
71
69
|
}, [selectingYear]);
|
|
72
70
|
|
|
73
71
|
const handleOnChange = useCallback(
|
|
74
|
-
(
|
|
72
|
+
(value: ListItemId | null) => {
|
|
73
|
+
if (typeof value !== 'number') return;
|
|
75
74
|
setStore(prev => ({
|
|
76
|
-
localDate: setYear(prev.localDate,
|
|
75
|
+
localDate: setYear(prev.localDate, value),
|
|
77
76
|
pickerType: undefined,
|
|
78
77
|
}));
|
|
79
78
|
},
|
|
80
79
|
[setStore],
|
|
81
80
|
);
|
|
82
81
|
|
|
82
|
+
const getRowLayout = useCallback(
|
|
83
|
+
(_data: ArrayLike<YearListItem> | null | undefined, index: number) => ({
|
|
84
|
+
length: GRID_ITEM_HEIGHT,
|
|
85
|
+
offset: GRID_ITEM_HEIGHT * index,
|
|
86
|
+
index,
|
|
87
|
+
}),
|
|
88
|
+
[],
|
|
89
|
+
);
|
|
90
|
+
|
|
83
91
|
return (
|
|
84
|
-
<
|
|
85
|
-
<
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
{
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
year={year}
|
|
98
|
-
selected={selectedYear === year}
|
|
99
|
-
onPressYear={handleOnChange}
|
|
100
|
-
yearStyles={yearStyle}
|
|
101
|
-
/>
|
|
102
|
-
</View>
|
|
103
|
-
))}
|
|
104
|
-
{row.length < NUM_COLUMNS &&
|
|
105
|
-
Array.from({ length: NUM_COLUMNS - row.length }).map((_, i) => (
|
|
106
|
-
<View key={`pad-${i}`} style={gridStyles.cell} />
|
|
107
|
-
))}
|
|
92
|
+
<List multiple={false} value={selectedYear} onChange={handleOnChange}>
|
|
93
|
+
<View style={containerStyle} pointerEvents={selectingYear ? 'auto' : 'none'}>
|
|
94
|
+
<Divider />
|
|
95
|
+
<FlatList<YearListItem>
|
|
96
|
+
ref={flatListRef}
|
|
97
|
+
style={gridStyles.list}
|
|
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} />
|
|
108
105
|
</View>
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
106
|
+
)}
|
|
107
|
+
keyExtractor={item => `${item.id}`}
|
|
108
|
+
getItemLayout={getRowLayout}
|
|
109
|
+
initialScrollIndex={Math.floor(initialScrollOffset / GRID_ITEM_HEIGHT)}
|
|
110
|
+
removeClippedSubviews
|
|
111
|
+
/>
|
|
112
|
+
</View>
|
|
113
|
+
</List>
|
|
113
114
|
);
|
|
114
115
|
}
|
|
115
116
|
|
|
116
|
-
function YearPillPure({
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
yearStyles,
|
|
121
|
-
}: {
|
|
122
|
-
year: number;
|
|
123
|
-
selected: boolean;
|
|
124
|
-
onPressYear: (newYear: number) => any;
|
|
125
|
-
yearStyles: Record<string, any>;
|
|
126
|
-
}) {
|
|
127
|
-
datePickerYearItemStyles.useVariants({
|
|
128
|
-
state: resolveStateVariant({ selected }) as any,
|
|
117
|
+
function YearPillPure({ year, yearStyles }: { year: number; yearStyles: Record<string, any> }) {
|
|
118
|
+
const isSelected = useListContextValue(state => {
|
|
119
|
+
const selectedValue = state.value as any;
|
|
120
|
+
return (selectedValue?.id ?? selectedValue) === year;
|
|
129
121
|
});
|
|
130
122
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
123
|
+
datePickerYearItemStyles.useVariants({
|
|
124
|
+
state: resolveStateVariant({ selected: isSelected }) as any,
|
|
125
|
+
});
|
|
134
126
|
|
|
135
127
|
return (
|
|
136
|
-
<
|
|
137
|
-
|
|
138
|
-
onPress={handlePressYear}
|
|
128
|
+
<List.Item
|
|
129
|
+
value={year}
|
|
139
130
|
accessibilityRole="button"
|
|
140
131
|
accessibilityLabel={String(year)}
|
|
141
132
|
style={[yearStyles, datePickerYearItemStyles.yearButton]}
|
|
142
133
|
testID={`pick-year-${year}`}>
|
|
143
|
-
<
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
134
|
+
<View style={datePickerYearItemStyles.content}>
|
|
135
|
+
<Text
|
|
136
|
+
typescale="bodyLarge"
|
|
137
|
+
style={datePickerYearItemStyles.yearLabel}
|
|
138
|
+
selectable={false}>
|
|
139
|
+
{year}
|
|
140
|
+
</Text>
|
|
141
|
+
</View>
|
|
142
|
+
</List.Item>
|
|
147
143
|
);
|
|
148
144
|
}
|
|
149
145
|
const YearPill = memo(YearPillPure);
|
|
150
146
|
|
|
151
147
|
function YearPickerList() {
|
|
152
|
-
const [{ startDateYear, endDateYear, localDate, pickerType }, setStore] =
|
|
153
|
-
state => state
|
|
154
|
-
);
|
|
155
|
-
const flatList = useRef<FlatList<number> | null>(null);
|
|
148
|
+
const [{ startDateYear, endDateYear, localDate, pickerType }, setStore] =
|
|
149
|
+
useDatePickerInlineStore(state => state);
|
|
156
150
|
const years = useMemo(
|
|
157
151
|
() => getYearRange(startDateYear, endDateYear),
|
|
158
152
|
[startDateYear, endDateYear],
|
|
159
153
|
);
|
|
154
|
+
const yearItems = useMemo<YearListItem[]>(
|
|
155
|
+
() => years.map(year => ({ id: year, label: String(year) })),
|
|
156
|
+
[years],
|
|
157
|
+
);
|
|
160
158
|
const selectingYear = pickerType === 'year';
|
|
161
159
|
const selectedYear = localDate.getFullYear();
|
|
162
160
|
|
|
@@ -167,24 +165,18 @@ function YearPickerList() {
|
|
|
167
165
|
}, [selectedYear, years]);
|
|
168
166
|
|
|
169
167
|
const handleOnChange = useCallback(
|
|
170
|
-
(
|
|
168
|
+
(value: ListItemId | null) => {
|
|
169
|
+
if (typeof value !== 'number') return;
|
|
171
170
|
setStore(prev => ({
|
|
172
|
-
localDate: setYear(prev.localDate,
|
|
171
|
+
localDate: setYear(prev.localDate, value),
|
|
173
172
|
pickerType: undefined,
|
|
174
173
|
}));
|
|
175
174
|
},
|
|
176
175
|
[setStore],
|
|
177
176
|
);
|
|
178
177
|
|
|
179
|
-
const renderItem = useCallback(
|
|
180
|
-
({ item }: { item: number }) => (
|
|
181
|
-
<YearRow year={item} selected={selectedYear === item} onPressYear={handleOnChange} />
|
|
182
|
-
),
|
|
183
|
-
[selectedYear, handleOnChange],
|
|
184
|
-
);
|
|
185
|
-
|
|
186
178
|
const getItemLayout = useCallback(
|
|
187
|
-
(_data:
|
|
179
|
+
(_data: ArrayLike<YearListItem> | null | undefined, index: number) => ({
|
|
188
180
|
length: LIST_ITEM_HEIGHT,
|
|
189
181
|
offset: LIST_ITEM_HEIGHT * index,
|
|
190
182
|
index,
|
|
@@ -195,61 +187,54 @@ function YearPickerList() {
|
|
|
195
187
|
if (!selectingYear) return null;
|
|
196
188
|
|
|
197
189
|
return (
|
|
198
|
-
<
|
|
199
|
-
<
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
190
|
+
<List multiple={false} value={selectedYear} onChange={handleOnChange}>
|
|
191
|
+
<View style={[StyleSheet.absoluteFill, listStyles.root]} pointerEvents="auto">
|
|
192
|
+
<Divider />
|
|
193
|
+
<FlatList<YearListItem>
|
|
194
|
+
style={listStyles.list}
|
|
195
|
+
data={yearItems}
|
|
196
|
+
renderItem={({ item }) => <YearRow year={item.id} />}
|
|
197
|
+
keyExtractor={item => `${item.id}`}
|
|
198
|
+
initialScrollIndex={initialScrollIndex}
|
|
199
|
+
getItemLayout={getItemLayout}
|
|
200
|
+
/>
|
|
201
|
+
</View>
|
|
202
|
+
</List>
|
|
210
203
|
);
|
|
211
204
|
}
|
|
212
205
|
|
|
213
|
-
function YearRowPure({
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}: {
|
|
218
|
-
year: number;
|
|
219
|
-
selected: boolean;
|
|
220
|
-
onPressYear: (newYear: number) => any;
|
|
221
|
-
}) {
|
|
222
|
-
datePickerMonthItemStyles.useVariants({
|
|
223
|
-
state: resolveStateVariant({ selected }) as any,
|
|
206
|
+
function YearRowPure({ year }: { year: number }) {
|
|
207
|
+
const isSelected = useListContextValue(state => {
|
|
208
|
+
const selectedValue = state.value as any;
|
|
209
|
+
return (selectedValue?.id ?? selectedValue) === year;
|
|
224
210
|
});
|
|
225
211
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
212
|
+
datePickerMonthItemStyles.useVariants({
|
|
213
|
+
state: resolveStateVariant({ selected: isSelected }) as any,
|
|
214
|
+
});
|
|
229
215
|
|
|
230
216
|
return (
|
|
231
|
-
<
|
|
232
|
-
|
|
217
|
+
<List.Item
|
|
218
|
+
value={year}
|
|
233
219
|
accessibilityRole="button"
|
|
234
220
|
accessibilityLabel={String(year)}
|
|
235
|
-
accessibilityState={{ selected }}
|
|
236
221
|
style={datePickerMonthItemStyles.monthButton}
|
|
237
|
-
testID={`pick-year-${year}`}
|
|
238
|
-
|
|
239
|
-
|
|
222
|
+
testID={`pick-year-${year}`}>
|
|
223
|
+
<View style={listStyles.left}>
|
|
224
|
+
{isSelected ? (
|
|
240
225
|
<View style={listStyles.checkIconView}>
|
|
241
226
|
<Icon name="check" size={24} />
|
|
242
227
|
</View>
|
|
243
228
|
) : (
|
|
244
229
|
<View style={listStyles.spacer} />
|
|
245
|
-
)
|
|
246
|
-
|
|
230
|
+
)}
|
|
231
|
+
</View>
|
|
247
232
|
<View style={datePickerMonthItemStyles.monthInner}>
|
|
248
233
|
<Text style={datePickerMonthItemStyles.monthLabel} selectable={false}>
|
|
249
234
|
{year}
|
|
250
235
|
</Text>
|
|
251
236
|
</View>
|
|
252
|
-
</
|
|
237
|
+
</List.Item>
|
|
253
238
|
);
|
|
254
239
|
}
|
|
255
240
|
const YearRow = memo(YearRowPure);
|
|
@@ -260,7 +245,10 @@ const gridStyles = StyleSheet.create({
|
|
|
260
245
|
top: 56,
|
|
261
246
|
zIndex: 100,
|
|
262
247
|
},
|
|
263
|
-
list: {
|
|
248
|
+
list: {
|
|
249
|
+
flex: 1,
|
|
250
|
+
width: '100%',
|
|
251
|
+
},
|
|
264
252
|
grid: { alignItems: 'center' },
|
|
265
253
|
row: {
|
|
266
254
|
flexDirection: 'row',
|
|
@@ -289,4 +277,5 @@ const listStyles = StyleSheet.create({
|
|
|
289
277
|
list: { flex: 1 },
|
|
290
278
|
checkIconView: { marginLeft: 16 },
|
|
291
279
|
spacer: { width: 44 },
|
|
280
|
+
left: { marginRight: 8 },
|
|
292
281
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createFastContext } from '../../fast-context';
|
|
2
|
+
import { registerPortalContext } from '../Portal/Portal';
|
|
2
3
|
|
|
3
4
|
export type Store = {
|
|
4
5
|
localDate: Date;
|
|
@@ -16,7 +17,10 @@ export const defaultValue = {
|
|
|
16
17
|
|
|
17
18
|
export const {
|
|
18
19
|
Provider,
|
|
19
|
-
useContext:
|
|
20
|
-
useContextValue:
|
|
21
|
-
useStoreRef:
|
|
20
|
+
useContext: useDatePickerInlineStore,
|
|
21
|
+
useContextValue: useDatePickerInlineStoreValue,
|
|
22
|
+
useStoreRef: useDatePickerInlineStoreRef,
|
|
23
|
+
Context: DatePickerInlineStoreContext,
|
|
22
24
|
} = createFastContext<Store>();
|
|
25
|
+
|
|
26
|
+
registerPortalContext(DatePickerInlineStoreContext);
|
|
@@ -54,7 +54,7 @@ export type BaseDatePickerProps = {
|
|
|
54
54
|
startYear?: number;
|
|
55
55
|
endYear?: number;
|
|
56
56
|
HeaderComponent?: MemoExoticComponent<CalendarHeaderProps | any>;
|
|
57
|
-
headerLayout?: '
|
|
57
|
+
headerLayout?: 'default' | 'docked';
|
|
58
58
|
monthStyle?: Record<string, any>;
|
|
59
59
|
showOutsideDays?: boolean;
|
|
60
60
|
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { memo } from 'react';
|
|
2
|
+
import { type StyleProp, View, type ViewProps, type ViewStyle } from 'react-native';
|
|
3
|
+
import { StyleSheet } from 'react-native-unistyles';
|
|
4
|
+
|
|
5
|
+
import { getRegisteredComponentStylesWithFallback } from '../../core';
|
|
6
|
+
|
|
7
|
+
export type DividerProps = Omit<ViewProps, 'children'> & {
|
|
8
|
+
/**
|
|
9
|
+
* Line orientation. Defaults to horizontal.
|
|
10
|
+
*/
|
|
11
|
+
mode?: 'horizontal' | 'vertical';
|
|
12
|
+
/**
|
|
13
|
+
* Left inset when `mode` is `"horizontal"`.
|
|
14
|
+
*/
|
|
15
|
+
leftInset?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Right inset when `mode` is `"horizontal"`.
|
|
18
|
+
*/
|
|
19
|
+
rightInset?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Top inset when `mode` is `"vertical"`.
|
|
22
|
+
*/
|
|
23
|
+
topInset?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Bottom inset when `mode` is `"vertical"`.
|
|
26
|
+
*/
|
|
27
|
+
bottomInset?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Whether the divider stroke should use the bold thickness.
|
|
30
|
+
*/
|
|
31
|
+
bold?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Margin added perpendicular to the divider line (`marginVertical` for horizontal,
|
|
34
|
+
* `marginHorizontal` for vertical).
|
|
35
|
+
*/
|
|
36
|
+
spacing?: number;
|
|
37
|
+
style?: StyleProp<ViewStyle>;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type Props = DividerProps;
|
|
41
|
+
|
|
42
|
+
const DividerHorizontalImpl = memo(function DividerHorizontalImpl({
|
|
43
|
+
leftInset = 0,
|
|
44
|
+
rightInset = 0,
|
|
45
|
+
style,
|
|
46
|
+
bold = false,
|
|
47
|
+
spacing = 8,
|
|
48
|
+
...rest
|
|
49
|
+
}: Omit<DividerProps, 'mode' | 'topInset' | 'bottomInset'>) {
|
|
50
|
+
horizontalDividerStyles.useVariants({
|
|
51
|
+
isBold: bold,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<View
|
|
56
|
+
{...rest}
|
|
57
|
+
style={
|
|
58
|
+
[
|
|
59
|
+
horizontalDividerStyles.root,
|
|
60
|
+
leftInset ? { marginLeft: leftInset } : undefined,
|
|
61
|
+
rightInset ? { marginRight: rightInset } : undefined,
|
|
62
|
+
spacing ? { marginVertical: spacing } : undefined,
|
|
63
|
+
style,
|
|
64
|
+
] as StyleProp<ViewStyle>
|
|
65
|
+
}
|
|
66
|
+
/>
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const DividerVerticalImpl = memo(function DividerVerticalImpl({
|
|
71
|
+
topInset = 0,
|
|
72
|
+
bottomInset = 0,
|
|
73
|
+
spacing = 0,
|
|
74
|
+
style,
|
|
75
|
+
bold = false,
|
|
76
|
+
...rest
|
|
77
|
+
}: Omit<DividerProps, 'mode' | 'leftInset' | 'rightInset'>) {
|
|
78
|
+
verticalDividerStyles.useVariants({
|
|
79
|
+
isBold: bold,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<View
|
|
84
|
+
{...rest}
|
|
85
|
+
style={
|
|
86
|
+
[
|
|
87
|
+
verticalDividerStyles.root,
|
|
88
|
+
style,
|
|
89
|
+
topInset ? { marginTop: topInset } : undefined,
|
|
90
|
+
bottomInset ? { marginBottom: bottomInset } : undefined,
|
|
91
|
+
spacing ? { marginHorizontal: spacing } : undefined,
|
|
92
|
+
] as StyleProp<ViewStyle>
|
|
93
|
+
}
|
|
94
|
+
/>
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
function DividerRoot(props: DividerProps) {
|
|
99
|
+
const mode = props.mode ?? 'horizontal';
|
|
100
|
+
|
|
101
|
+
if (mode === 'vertical') {
|
|
102
|
+
const {
|
|
103
|
+
mode: _m,
|
|
104
|
+
leftInset: _l,
|
|
105
|
+
rightInset: _r,
|
|
106
|
+
topInset,
|
|
107
|
+
bottomInset,
|
|
108
|
+
bold,
|
|
109
|
+
spacing,
|
|
110
|
+
style,
|
|
111
|
+
...viewRest
|
|
112
|
+
} = props;
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<DividerVerticalImpl
|
|
116
|
+
{...viewRest}
|
|
117
|
+
topInset={topInset}
|
|
118
|
+
bottomInset={bottomInset}
|
|
119
|
+
bold={bold}
|
|
120
|
+
spacing={spacing}
|
|
121
|
+
style={style}
|
|
122
|
+
/>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const {
|
|
127
|
+
mode: _m,
|
|
128
|
+
topInset: _t,
|
|
129
|
+
bottomInset: _b,
|
|
130
|
+
leftInset,
|
|
131
|
+
rightInset,
|
|
132
|
+
bold,
|
|
133
|
+
spacing,
|
|
134
|
+
style,
|
|
135
|
+
...viewRest
|
|
136
|
+
} = props;
|
|
137
|
+
|
|
138
|
+
return (
|
|
139
|
+
<DividerHorizontalImpl
|
|
140
|
+
{...viewRest}
|
|
141
|
+
leftInset={leftInset}
|
|
142
|
+
rightInset={rightInset}
|
|
143
|
+
bold={bold}
|
|
144
|
+
spacing={spacing}
|
|
145
|
+
style={style}
|
|
146
|
+
/>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export const Divider = memo(DividerRoot);
|
|
151
|
+
|
|
152
|
+
export const horizontalDividerStylesDefault = StyleSheet.create(theme => ({
|
|
153
|
+
root: {
|
|
154
|
+
height: StyleSheet.hairlineWidth,
|
|
155
|
+
background: theme.colors.outlineVariant,
|
|
156
|
+
|
|
157
|
+
variants: {
|
|
158
|
+
isBold: {
|
|
159
|
+
true: {
|
|
160
|
+
height: 1,
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
}));
|
|
166
|
+
|
|
167
|
+
export const verticalDividerStylesDefault = StyleSheet.create(theme => ({
|
|
168
|
+
root: {
|
|
169
|
+
width: StyleSheet.hairlineWidth,
|
|
170
|
+
background: theme.colors.outlineVariant,
|
|
171
|
+
|
|
172
|
+
variants: {
|
|
173
|
+
isBold: {
|
|
174
|
+
true: {
|
|
175
|
+
width: 1,
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
}));
|
|
181
|
+
|
|
182
|
+
export const horizontalDividerStyles = getRegisteredComponentStylesWithFallback(
|
|
183
|
+
'HorizontalDivider',
|
|
184
|
+
horizontalDividerStylesDefault,
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
export const verticalDividerStyles = getRegisteredComponentStylesWithFallback(
|
|
188
|
+
'VerticalDivider',
|
|
189
|
+
verticalDividerStylesDefault,
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
export default Divider;
|
|
@@ -3,13 +3,13 @@ import { type TextProps, View, type ViewProps } from 'react-native';
|
|
|
3
3
|
import { StyleSheet } from 'react-native-unistyles';
|
|
4
4
|
|
|
5
5
|
import { getRegisteredComponentStylesWithFallback } from '../../core';
|
|
6
|
-
import {
|
|
6
|
+
import { Divider, type DividerProps } from '../Divider';
|
|
7
7
|
import { Text } from '../Text';
|
|
8
8
|
|
|
9
9
|
export type Props = ViewProps & {
|
|
10
10
|
title?: ReactNode;
|
|
11
11
|
showDivider?: boolean;
|
|
12
|
-
dividerProps?:
|
|
12
|
+
dividerProps?: Omit<DividerProps, 'mode'>;
|
|
13
13
|
titleProps?: TextProps;
|
|
14
14
|
};
|
|
15
15
|
|
|
@@ -45,11 +45,7 @@ const DrawerItemGroup = memo(
|
|
|
45
45
|
)}
|
|
46
46
|
</>
|
|
47
47
|
{children}
|
|
48
|
-
<>
|
|
49
|
-
{showDivider && (
|
|
50
|
-
<HorizontalDivider style={dividerStyle} {...dividerRestProps} />
|
|
51
|
-
)}
|
|
52
|
-
</>
|
|
48
|
+
<>{showDivider && <Divider style={dividerStyle} {...dividerRestProps} />}</>
|
|
53
49
|
</View>
|
|
54
50
|
);
|
|
55
51
|
},
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import color from 'color';
|
|
2
1
|
import { forwardRef, memo, useMemo } from 'react';
|
|
3
2
|
import {
|
|
4
3
|
type GestureResponderEvent,
|
|
@@ -112,13 +111,13 @@ const IconButton = (
|
|
|
112
111
|
variant: variant as any,
|
|
113
112
|
// @ts-ignore // TODO - fix this
|
|
114
113
|
state,
|
|
114
|
+
// @ts-ignore // TODO - fix this
|
|
115
115
|
size: typeof size === 'string' && size ? size : undefined,
|
|
116
116
|
});
|
|
117
117
|
|
|
118
118
|
const {
|
|
119
119
|
iconColor,
|
|
120
120
|
iconSize,
|
|
121
|
-
rippleColor,
|
|
122
121
|
containerStyle,
|
|
123
122
|
accessibilityState,
|
|
124
123
|
// accessibilityTraits,
|
|
@@ -129,18 +128,9 @@ const IconButton = (
|
|
|
129
128
|
iconButtonSizeToIconSizeMap[size as keyof typeof iconButtonSizeToIconSizeMap] ??
|
|
130
129
|
(typeof size === 'number' && size ? (size as number) : undefined);
|
|
131
130
|
|
|
132
|
-
let _rippleColor: string | undefined;
|
|
133
|
-
|
|
134
|
-
try {
|
|
135
|
-
_rippleColor = color(_iconColor).alpha(0.12).rgb().string();
|
|
136
|
-
} catch (e) {
|
|
137
|
-
_rippleColor = undefined;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
131
|
return {
|
|
141
132
|
iconColor: _iconColor,
|
|
142
133
|
iconSize: iconSizeInNum,
|
|
143
|
-
rippleColor: _rippleColor,
|
|
144
134
|
containerStyle: [
|
|
145
135
|
iconSizeInNum
|
|
146
136
|
? {
|
|
@@ -164,7 +154,7 @@ const IconButton = (
|
|
|
164
154
|
borderless
|
|
165
155
|
centered
|
|
166
156
|
onPress={onPress}
|
|
167
|
-
|
|
157
|
+
rippleAlpha={0.12}
|
|
168
158
|
accessibilityLabel={accessibilityLabel}
|
|
169
159
|
style={containerStyle}
|
|
170
160
|
// accessibilityTraits={accessibilityTraits}
|