react-native-molecules 0.5.0-beta.2 → 0.5.0-beta.20
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/README.md +1 -1
- package/components/Accordion/Accordion.tsx +2 -6
- package/components/Accordion/AccordionItem.tsx +16 -12
- package/components/Accordion/AccordionItemContent.tsx +6 -1
- package/components/Accordion/AccordionItemHeader.tsx +1 -1
- package/components/Accordion/utils.ts +6 -0
- package/components/ActivityIndicator/ActivityIndicator.tsx +6 -15
- package/components/Appbar/AppbarBase.tsx +18 -13
- package/components/Button/Button.tsx +209 -264
- package/components/Button/index.tsx +9 -3
- package/components/Button/types.ts +16 -2
- package/components/Button/utils.ts +230 -208
- package/components/Checkbox/CheckboxBase.tsx +23 -128
- package/components/Checkbox/utils.ts +0 -25
- package/components/Chip/Chip.tsx +40 -52
- package/components/Chip/utils.ts +3 -7
- package/components/DateField/DateField.tsx +110 -0
- package/components/DateField/index.tsx +6 -0
- package/components/{DatePickerInput/inputUtils.ts → DateField/useDateFieldState.ts} +17 -49
- package/components/DatePicker/DateCalendar.tsx +83 -0
- package/components/DatePicker/DatePickerActions.tsx +73 -0
- package/components/DatePicker/DatePickerModal.tsx +234 -0
- package/components/DatePicker/DatePickerPopover.tsx +79 -0
- package/components/DatePicker/DatePickerProvider.tsx +152 -0
- package/components/DatePicker/DatePickerTrigger.tsx +23 -0
- package/components/DatePicker/context.tsx +82 -0
- package/components/DatePicker/index.tsx +44 -0
- package/components/DatePicker/utils.ts +293 -0
- package/components/DatePickerInline/DatePickerContext.tsx +1 -0
- package/components/DatePickerInline/DatePickerDockedHeader.tsx +113 -0
- package/components/DatePickerInline/DatePickerInline.tsx +16 -15
- package/components/DatePickerInline/DatePickerInlineBase.tsx +7 -1
- package/components/DatePickerInline/Day.tsx +25 -1
- package/components/DatePickerInline/DayRange.tsx +2 -4
- package/components/DatePickerInline/HeaderItem.tsx +42 -27
- package/components/DatePickerInline/Month.tsx +45 -65
- package/components/DatePickerInline/MonthPicker.tsx +25 -41
- package/components/DatePickerInline/Swiper.native.tsx +21 -4
- package/components/DatePickerInline/Swiper.tsx +168 -13
- package/components/DatePickerInline/Week.tsx +6 -1
- package/components/DatePickerInline/YearPicker.tsx +206 -53
- package/components/DatePickerInline/dateUtils.tsx +17 -12
- package/components/DatePickerInline/types.ts +3 -0
- package/components/DatePickerInline/utils.ts +66 -29
- package/components/Drawer/Drawer.tsx +17 -6
- package/components/ElementGroup/ElementGroup.tsx +16 -14
- package/components/FilePicker/FilePicker.tsx +48 -78
- package/components/FilePicker/index.tsx +2 -1
- package/components/FilePicker/utils.ts +9 -0
- package/components/HelperText/HelperText.tsx +0 -35
- package/components/Icon/iconFactory.tsx +3 -3
- package/components/Icon/index.tsx +1 -1
- package/components/Icon/types.ts +17 -6
- package/components/IconButton/IconButton.tsx +42 -57
- package/components/IconButton/utils.ts +142 -33
- package/components/ListItem/ListItem.tsx +3 -1
- package/components/ListItem/utils.ts +1 -1
- package/components/LoadingIndicator/LoadingIndicator.tsx +253 -0
- package/components/LoadingIndicator/LoadingIndicator.web.tsx +136 -0
- package/components/LoadingIndicator/index.tsx +13 -0
- package/components/LoadingIndicator/utils.ts +117 -0
- package/components/Menu/Menu.tsx +3 -18
- package/components/NavigationRail/NavigationRail.tsx +15 -9
- package/components/Popover/Popover.tsx +122 -145
- package/components/Popover/PopoverRoot.tsx +74 -0
- package/components/Popover/common.ts +50 -34
- package/components/Popover/index.ts +18 -1
- package/components/Popover/usePlatformMeasure.native.ts +90 -0
- package/components/Popover/usePlatformMeasure.ts +118 -0
- package/components/Popover/utils.ts +34 -0
- package/components/Select/Select.tsx +368 -507
- package/components/Select/context.tsx +72 -0
- package/components/Select/index.ts +8 -14
- package/components/Select/types.ts +2 -4
- package/components/Select/utils.ts +144 -0
- package/components/Slot/Slot.tsx +244 -0
- package/components/Slot/compose-refs.tsx +62 -0
- package/components/Slot/index.tsx +8 -0
- package/components/Surface/Surface.android.tsx +34 -8
- package/components/Surface/Surface.ios.tsx +36 -29
- package/components/Surface/Surface.tsx +31 -4
- package/components/Surface/utils.ts +44 -30
- package/components/Switch/Switch.tsx +8 -2
- package/components/Tabs/TabItem.tsx +35 -58
- package/components/Tabs/TabLabel.tsx +5 -9
- package/components/Tabs/Tabs.tsx +154 -148
- package/components/Tabs/utils.ts +15 -2
- package/components/TextInput/TextInput.tsx +658 -575
- package/components/TextInput/index.tsx +19 -3
- package/components/TextInput/types.ts +76 -27
- package/components/TextInput/utils.ts +225 -145
- package/components/TimeField/TimeField.tsx +75 -0
- package/components/TimeField/index.tsx +6 -0
- package/components/TimeField/useTimeFieldState.ts +70 -0
- package/components/{TimePickerField/sanitizeTime.ts → TimeField/utils.ts} +77 -10
- package/components/TimePicker/TimeInput.tsx +87 -37
- package/components/TimePicker/TimeInputs.tsx +137 -49
- package/components/TimePicker/TimePicker.tsx +73 -10
- package/components/TimePicker/TimePickerModal.tsx +186 -0
- package/components/TimePicker/context.tsx +17 -0
- package/components/TimePicker/index.tsx +15 -3
- package/components/TimePicker/utils.ts +93 -0
- package/components/Tooltip/Tooltip.tsx +42 -67
- package/components/Tooltip/TooltipContent.tsx +32 -5
- package/components/Tooltip/TooltipTrigger.tsx +20 -20
- package/components/Tooltip/index.tsx +1 -1
- package/components/TouchableRipple/TouchableRipple.native.tsx +50 -14
- package/components/TouchableRipple/TouchableRipple.tsx +137 -47
- package/hocs/withPortal.tsx +1 -1
- package/hooks/index.tsx +0 -6
- package/hooks/useActionState.tsx +19 -8
- package/hooks/useControlledValue.tsx +20 -4
- package/hooks/useFilePicker.tsx +6 -16
- package/hooks/useWhatHasUpdated.tsx +48 -0
- package/package.json +17 -13
- package/shortcuts-manager/ShortcutsManager/ShortcutsManager.tsx +5 -2
- package/styles/shadow.ts +2 -1
- package/styles/themes/LightTheme.tsx +1 -1
- package/utils/DocumentPicker/documentPicker.ts +78 -27
- package/utils/DocumentPicker/types.ts +0 -1
- package/utils/extractPropertiesFromStyles.ts +25 -0
- package/utils/extractSubcomponents.ts +89 -0
- package/utils/lodash.ts +77 -5
- package/components/DatePickerDocked/DatePickerDocked.tsx +0 -30
- package/components/DatePickerDocked/DatePickerDockedHeader.tsx +0 -129
- package/components/DatePickerDocked/index.tsx +0 -17
- package/components/DatePickerDocked/types.ts +0 -11
- package/components/DatePickerDocked/utils.ts +0 -157
- package/components/DatePickerInput/DatePickerInput.tsx +0 -139
- package/components/DatePickerInput/DatePickerInputModal.tsx +0 -48
- package/components/DatePickerInput/DatePickerInputWithoutModal.tsx +0 -77
- package/components/DatePickerInput/DateRangeInput.tsx +0 -88
- package/components/DatePickerInput/index.tsx +0 -10
- package/components/DatePickerInput/types.ts +0 -28
- package/components/DatePickerInput/utils.ts +0 -15
- package/components/DatePickerModal/AnimatedCrossView.tsx +0 -94
- package/components/DatePickerModal/CalendarEdit.tsx +0 -139
- package/components/DatePickerModal/DatePickerModal.tsx +0 -85
- package/components/DatePickerModal/DatePickerModalContent.tsx +0 -155
- package/components/DatePickerModal/DatePickerModalContentHeader.tsx +0 -213
- package/components/DatePickerModal/DatePickerModalHeader.tsx +0 -74
- package/components/DatePickerModal/DatePickerModalHeaderBackground.tsx +0 -13
- package/components/DatePickerModal/index.tsx +0 -16
- package/components/DatePickerModal/types.ts +0 -92
- package/components/DatePickerModal/utils.ts +0 -122
- package/components/DateTimePicker/DateTimePicker.tsx +0 -172
- package/components/DateTimePicker/index.tsx +0 -10
- package/components/DateTimePicker/utils.ts +0 -12
- package/components/Popover/Popover.native.tsx +0 -185
- package/components/TimePickerField/TimePickerField.tsx +0 -152
- package/components/TimePickerField/index.tsx +0 -10
- package/components/TimePickerField/utils.ts +0 -94
- package/components/TimePickerModal/TimePickerModal.tsx +0 -115
- package/components/TimePickerModal/index.tsx +0 -10
- package/components/TimePickerModal/utils.ts +0 -47
- package/hooks/useSearchable.tsx +0 -74
- package/hooks/useSubcomponents.tsx +0 -59
|
@@ -1,32 +1,109 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createContext } from 'react';
|
|
2
2
|
import { StyleSheet } from 'react-native-unistyles';
|
|
3
3
|
|
|
4
4
|
import { getRegisteredComponentStylesWithFallback } from '../../core';
|
|
5
|
+
import type { ButtonContextType } from './types';
|
|
5
6
|
|
|
6
7
|
export const sizeToIconSizeMap = {
|
|
7
|
-
xs:
|
|
8
|
-
sm:
|
|
8
|
+
xs: 20,
|
|
9
|
+
sm: 20,
|
|
9
10
|
md: 24,
|
|
10
|
-
lg:
|
|
11
|
+
lg: 32,
|
|
12
|
+
xl: 40,
|
|
11
13
|
};
|
|
12
14
|
|
|
13
|
-
const
|
|
15
|
+
export const sizeToHeightMap = {
|
|
16
|
+
xs: 32,
|
|
17
|
+
sm: 40,
|
|
18
|
+
md: 56,
|
|
19
|
+
lg: 96,
|
|
20
|
+
xl: 136,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const sizeToPaddingMap = {
|
|
24
|
+
xs: 12,
|
|
25
|
+
sm: 16,
|
|
26
|
+
md: 24,
|
|
27
|
+
lg: 48,
|
|
28
|
+
xl: 64,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const sizeToIconGapMap = {
|
|
32
|
+
xs: 4,
|
|
33
|
+
sm: 8,
|
|
34
|
+
md: 8,
|
|
35
|
+
lg: 12,
|
|
36
|
+
xl: 16,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const elevationMap: Record<string, Record<string, number>> = {
|
|
40
|
+
true: {
|
|
41
|
+
contained: 1,
|
|
42
|
+
'contained-tonal': 1,
|
|
43
|
+
elevated: 2,
|
|
44
|
+
},
|
|
45
|
+
false: {
|
|
46
|
+
elevated: 1,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const ButtonContext = createContext<ButtonContextType>({
|
|
51
|
+
variant: 'text',
|
|
52
|
+
size: 'sm',
|
|
53
|
+
state: 'default',
|
|
54
|
+
disabled: false,
|
|
55
|
+
labelColor: undefined,
|
|
56
|
+
iconSize: undefined,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const buttonStylesDefault = StyleSheet.create(theme => {
|
|
14
60
|
return {
|
|
15
61
|
root: {
|
|
62
|
+
flexDirection: 'row',
|
|
63
|
+
alignItems: 'center',
|
|
64
|
+
justifyContent: 'center',
|
|
65
|
+
borderStyle: 'solid',
|
|
16
66
|
variants: {
|
|
17
67
|
size: {
|
|
68
|
+
xs: {
|
|
69
|
+
minWidth: 64,
|
|
70
|
+
height: 32,
|
|
71
|
+
paddingHorizontal: 12,
|
|
72
|
+
gap: 4,
|
|
73
|
+
},
|
|
18
74
|
sm: {
|
|
19
75
|
minWidth: 64,
|
|
20
|
-
|
|
76
|
+
height: 40,
|
|
77
|
+
paddingHorizontal: 16,
|
|
78
|
+
gap: 8,
|
|
21
79
|
},
|
|
22
80
|
md: {
|
|
23
81
|
minWidth: 64,
|
|
24
|
-
|
|
82
|
+
height: 56,
|
|
83
|
+
paddingHorizontal: 24,
|
|
84
|
+
gap: 8,
|
|
25
85
|
},
|
|
26
86
|
lg: {
|
|
27
|
-
minWidth:
|
|
87
|
+
minWidth: 96,
|
|
88
|
+
height: 96,
|
|
89
|
+
paddingHorizontal: 48,
|
|
90
|
+
gap: 12,
|
|
91
|
+
},
|
|
92
|
+
xl: {
|
|
93
|
+
minWidth: 136,
|
|
94
|
+
height: 136,
|
|
95
|
+
paddingHorizontal: 64,
|
|
96
|
+
gap: 16,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
shape: {
|
|
100
|
+
rounded: {
|
|
28
101
|
borderRadius: theme.shapes.corner.full,
|
|
29
102
|
},
|
|
103
|
+
square: {
|
|
104
|
+
// Base - will be overridden by compoundVariants for size-specific radii
|
|
105
|
+
borderRadius: 12,
|
|
106
|
+
},
|
|
30
107
|
},
|
|
31
108
|
|
|
32
109
|
state: {
|
|
@@ -128,6 +205,42 @@ const defaultStylesDefault = StyleSheet.create(theme => {
|
|
|
128
205
|
// elevationLevel: theme.elevations.level1,
|
|
129
206
|
},
|
|
130
207
|
},
|
|
208
|
+
// Square shape + size compound variants for border radius
|
|
209
|
+
{
|
|
210
|
+
shape: 'square',
|
|
211
|
+
size: 'xs',
|
|
212
|
+
styles: {
|
|
213
|
+
borderRadius: theme.shapes.corner.medium,
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
shape: 'square',
|
|
218
|
+
size: 'sm',
|
|
219
|
+
styles: {
|
|
220
|
+
borderRadius: theme.shapes.corner.medium,
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
shape: 'square',
|
|
225
|
+
size: 'md',
|
|
226
|
+
styles: {
|
|
227
|
+
borderRadius: theme.shapes.corner.large,
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
shape: 'square',
|
|
232
|
+
size: 'lg',
|
|
233
|
+
styles: {
|
|
234
|
+
borderRadius: theme.shapes.corner.extraLarge,
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
shape: 'square',
|
|
239
|
+
size: 'xl',
|
|
240
|
+
styles: {
|
|
241
|
+
borderRadius: theme.shapes.corner.extraLarge,
|
|
242
|
+
},
|
|
243
|
+
},
|
|
131
244
|
],
|
|
132
245
|
},
|
|
133
246
|
stateLayer: {
|
|
@@ -184,230 +297,139 @@ const defaultStylesDefault = StyleSheet.create(theme => {
|
|
|
184
297
|
},
|
|
185
298
|
],
|
|
186
299
|
},
|
|
300
|
+
};
|
|
301
|
+
});
|
|
187
302
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
? { marginLeft: theme.spacings['4'], marginRight: theme.spacings._4 }
|
|
205
|
-
: {}),
|
|
206
|
-
variants: {
|
|
207
|
-
state: {
|
|
208
|
-
disabled: {
|
|
209
|
-
color: theme.colors.onSurfaceDisabled,
|
|
210
|
-
},
|
|
211
|
-
hovered: {},
|
|
212
|
-
default: {},
|
|
303
|
+
/**
|
|
304
|
+
* Styles for Button.Icon component
|
|
305
|
+
*/
|
|
306
|
+
const buttonIconStylesDefault = StyleSheet.create(theme => ({
|
|
307
|
+
root: {
|
|
308
|
+
variants: {
|
|
309
|
+
state: {
|
|
310
|
+
disabled: {
|
|
311
|
+
color: theme.colors.onSurfaceDisabled,
|
|
312
|
+
},
|
|
313
|
+
hovered: {},
|
|
314
|
+
default: {},
|
|
315
|
+
},
|
|
316
|
+
variant: {
|
|
317
|
+
outlined: {
|
|
318
|
+
color: theme.colors.primary,
|
|
213
319
|
},
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
color: theme.colors.primary,
|
|
217
|
-
},
|
|
218
|
-
text: {
|
|
219
|
-
color: theme.colors.primary,
|
|
220
|
-
},
|
|
221
|
-
contained: {
|
|
222
|
-
color: theme.colors.onPrimary,
|
|
223
|
-
},
|
|
224
|
-
elevated: {
|
|
225
|
-
color: theme.colors.primary,
|
|
226
|
-
},
|
|
227
|
-
'contained-tonal': {
|
|
228
|
-
color: theme.colors.onSecondaryContainer,
|
|
229
|
-
},
|
|
320
|
+
text: {
|
|
321
|
+
color: theme.colors.primary,
|
|
230
322
|
},
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
iconTextMode: {
|
|
234
|
-
marginLeft: theme.spacings['3'],
|
|
235
|
-
marginRight: theme.spacings._2,
|
|
236
|
-
},
|
|
237
|
-
label: {
|
|
238
|
-
display: 'flex',
|
|
239
|
-
alignItems: 'center',
|
|
240
|
-
textAlign: 'center',
|
|
241
|
-
marginVertical: theme.spacings['2l'],
|
|
242
|
-
marginHorizontal: theme.spacings['6'],
|
|
243
|
-
...theme.typescale.labelLarge,
|
|
244
|
-
|
|
245
|
-
variants: {
|
|
246
|
-
size: {
|
|
247
|
-
sm: {
|
|
248
|
-
...theme.typescale.labelMedium,
|
|
249
|
-
},
|
|
250
|
-
md: {
|
|
251
|
-
...theme.typescale.labelLarge,
|
|
252
|
-
},
|
|
253
|
-
lg: {
|
|
254
|
-
...theme.typescale.labelLarge,
|
|
255
|
-
fontSize: theme.typescale.bodyLarge.fontSize,
|
|
256
|
-
},
|
|
323
|
+
contained: {
|
|
324
|
+
color: theme.colors.onPrimary,
|
|
257
325
|
},
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
color: theme.colors.primary,
|
|
261
|
-
},
|
|
262
|
-
text: {
|
|
263
|
-
color: theme.colors.primary,
|
|
264
|
-
},
|
|
265
|
-
contained: {
|
|
266
|
-
color: theme.colors.onPrimary,
|
|
267
|
-
},
|
|
268
|
-
elevated: {
|
|
269
|
-
color: theme.colors.primary,
|
|
270
|
-
},
|
|
271
|
-
'contained-tonal': {
|
|
272
|
-
color: theme.colors.onSecondaryContainer,
|
|
273
|
-
},
|
|
326
|
+
elevated: {
|
|
327
|
+
color: theme.colors.primary,
|
|
274
328
|
},
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
color: theme.colors.onSurfaceDisabled,
|
|
278
|
-
},
|
|
279
|
-
hovered: {},
|
|
280
|
-
default: {},
|
|
329
|
+
'contained-tonal': {
|
|
330
|
+
color: theme.colors.onSecondaryContainer,
|
|
281
331
|
},
|
|
282
332
|
},
|
|
333
|
+
},
|
|
334
|
+
},
|
|
335
|
+
}));
|
|
283
336
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
337
|
+
/**
|
|
338
|
+
* Styles for Button.Text component
|
|
339
|
+
*/
|
|
340
|
+
const buttonTextStylesDefault = StyleSheet.create(theme => ({
|
|
341
|
+
root: {
|
|
342
|
+
...theme.typescale.labelLarge,
|
|
343
|
+
variants: {
|
|
344
|
+
size: {
|
|
345
|
+
xs: {
|
|
346
|
+
...theme.typescale.labelLarge,
|
|
291
347
|
},
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
variant: 'text',
|
|
295
|
-
state: 'disabled',
|
|
296
|
-
styles: {
|
|
297
|
-
color: theme.colors.stateLayer.disabled.onSurface_Level4,
|
|
298
|
-
},
|
|
348
|
+
sm: {
|
|
349
|
+
...theme.typescale.labelLarge,
|
|
299
350
|
},
|
|
300
|
-
{
|
|
301
|
-
|
|
302
|
-
state: 'disabled',
|
|
303
|
-
styles: {
|
|
304
|
-
color: theme.colors.stateLayer.disabled.onSurface_Level4,
|
|
305
|
-
},
|
|
351
|
+
md: {
|
|
352
|
+
...theme.typescale.titleMedium,
|
|
306
353
|
},
|
|
307
|
-
{
|
|
308
|
-
|
|
309
|
-
state: 'disabled',
|
|
310
|
-
styles: {
|
|
311
|
-
color: theme.colors.stateLayer.disabled.onSurface_Level4,
|
|
312
|
-
},
|
|
354
|
+
lg: {
|
|
355
|
+
...theme.typescale.headlineSmall,
|
|
313
356
|
},
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
variant: 'contained-tonal',
|
|
317
|
-
state: 'disabled',
|
|
318
|
-
styles: {
|
|
319
|
-
color: theme.colors.stateLayer.disabled.onSurface_Level4,
|
|
320
|
-
},
|
|
357
|
+
xl: {
|
|
358
|
+
...theme.typescale.headlineLarge,
|
|
321
359
|
},
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
marginHorizontal: theme.spacings['3'],
|
|
327
|
-
...theme.typescale.labelLarge,
|
|
328
|
-
|
|
329
|
-
variants: {
|
|
330
|
-
variant: {
|
|
331
|
-
text: {
|
|
332
|
-
color: theme.colors.primary,
|
|
333
|
-
},
|
|
360
|
+
},
|
|
361
|
+
variant: {
|
|
362
|
+
text: {
|
|
363
|
+
color: theme.colors.primary,
|
|
334
364
|
},
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
color: theme.colors.onSurfaceDisabled,
|
|
338
|
-
},
|
|
339
|
-
hovered: {},
|
|
340
|
-
default: {},
|
|
365
|
+
outlined: {
|
|
366
|
+
color: theme.colors.primary,
|
|
341
367
|
},
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
...theme.typescale.labelLarge,
|
|
351
|
-
fontSize: theme.typescale.bodyLarge.fontSize,
|
|
352
|
-
},
|
|
368
|
+
contained: {
|
|
369
|
+
color: theme.colors.onPrimary,
|
|
370
|
+
},
|
|
371
|
+
elevated: {
|
|
372
|
+
color: theme.colors.primary,
|
|
373
|
+
},
|
|
374
|
+
'contained-tonal': {
|
|
375
|
+
color: theme.colors.onSecondaryContainer,
|
|
353
376
|
},
|
|
354
377
|
},
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
variant: 'text',
|
|
359
|
-
state: 'disabled',
|
|
360
|
-
styles: {
|
|
361
|
-
color: theme.colors.stateLayer.disabled.onSurface_Level4,
|
|
362
|
-
},
|
|
378
|
+
state: {
|
|
379
|
+
disabled: {
|
|
380
|
+
color: theme.colors.onSurfaceDisabled,
|
|
363
381
|
},
|
|
364
|
-
|
|
382
|
+
hovered: {},
|
|
383
|
+
default: {},
|
|
384
|
+
},
|
|
365
385
|
},
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
marginHorizontal: theme.spacings['4'],
|
|
386
|
+
},
|
|
387
|
+
}));
|
|
369
388
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
389
|
+
const buttonActivityIndicatorStylesDefault = StyleSheet.create(theme => ({
|
|
390
|
+
root: {
|
|
391
|
+
variants: {
|
|
392
|
+
state: {
|
|
393
|
+
disabled: {
|
|
394
|
+
color: theme.colors.onSurfaceDisabled,
|
|
395
|
+
},
|
|
396
|
+
hovered: {},
|
|
397
|
+
default: {},
|
|
398
|
+
},
|
|
399
|
+
variant: {
|
|
400
|
+
outlined: {
|
|
401
|
+
color: theme.colors.primary,
|
|
375
402
|
},
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
color: theme.colors.onSurfaceDisabled,
|
|
379
|
-
},
|
|
380
|
-
hovered: {},
|
|
381
|
-
default: {},
|
|
403
|
+
text: {
|
|
404
|
+
color: theme.colors.primary,
|
|
382
405
|
},
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
...theme.typescale.labelMedium,
|
|
386
|
-
},
|
|
387
|
-
md: {
|
|
388
|
-
...theme.typescale.labelLarge,
|
|
389
|
-
},
|
|
390
|
-
lg: {
|
|
391
|
-
...theme.typescale.labelLarge,
|
|
392
|
-
fontSize: theme.typescale.bodyLarge.fontSize,
|
|
393
|
-
},
|
|
406
|
+
contained: {
|
|
407
|
+
color: theme.colors.onPrimary,
|
|
394
408
|
},
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
compoundVariants: [
|
|
398
|
-
{
|
|
399
|
-
variant: 'text',
|
|
400
|
-
state: 'disabled',
|
|
401
|
-
styles: {
|
|
402
|
-
color: theme.colors.stateLayer.disabled.onSurface_Level4,
|
|
403
|
-
},
|
|
409
|
+
elevated: {
|
|
410
|
+
color: theme.colors.primary,
|
|
404
411
|
},
|
|
405
|
-
|
|
412
|
+
'contained-tonal': {
|
|
413
|
+
color: theme.colors.onSecondaryContainer,
|
|
414
|
+
},
|
|
415
|
+
},
|
|
406
416
|
},
|
|
407
|
-
}
|
|
408
|
-
});
|
|
417
|
+
},
|
|
418
|
+
}));
|
|
419
|
+
|
|
420
|
+
export const buttonStyles = getRegisteredComponentStylesWithFallback('Button', buttonStylesDefault);
|
|
421
|
+
|
|
422
|
+
export const buttonIconStyles = getRegisteredComponentStylesWithFallback(
|
|
423
|
+
'ButtonIcon',
|
|
424
|
+
buttonIconStylesDefault,
|
|
425
|
+
);
|
|
426
|
+
|
|
427
|
+
export const buttonTextStyles = getRegisteredComponentStylesWithFallback(
|
|
428
|
+
'ButtonText',
|
|
429
|
+
buttonTextStylesDefault,
|
|
430
|
+
);
|
|
409
431
|
|
|
410
|
-
export const
|
|
411
|
-
'
|
|
412
|
-
|
|
432
|
+
export const buttonActivityIndicatorStyles = getRegisteredComponentStylesWithFallback(
|
|
433
|
+
'ButtonActivityIndicator',
|
|
434
|
+
buttonActivityIndicatorStylesDefault,
|
|
413
435
|
);
|
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
import setColor from 'color';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
memo,
|
|
5
|
-
type PropsWithoutRef,
|
|
6
|
-
useCallback,
|
|
7
|
-
useEffect,
|
|
8
|
-
useMemo,
|
|
9
|
-
useRef,
|
|
10
|
-
} from 'react';
|
|
11
|
-
import { Animated, Platform, View, type ViewProps } from 'react-native';
|
|
12
|
-
import { StyleSheet } from 'react-native-unistyles';
|
|
2
|
+
import { forwardRef, memo, type PropsWithoutRef, useCallback, useMemo } from 'react';
|
|
3
|
+
import { Platform, type ViewProps } from 'react-native';
|
|
13
4
|
|
|
14
5
|
import { useActionState } from '../../hooks';
|
|
15
6
|
import { resolveStateVariant } from '../../utils';
|
|
@@ -44,9 +35,6 @@ const CheckboxAndroid = (
|
|
|
44
35
|
}: Props,
|
|
45
36
|
ref: any,
|
|
46
37
|
) => {
|
|
47
|
-
const { current: scaleAnim } = useRef<Animated.Value>(new Animated.Value(1));
|
|
48
|
-
const isFirstRendering = useRef<boolean>(true);
|
|
49
|
-
|
|
50
38
|
const { actionsRef, hovered } = useActionState({ ref, actionsToListen: ['hover'] });
|
|
51
39
|
|
|
52
40
|
const state = resolveStateVariant({
|
|
@@ -63,101 +51,20 @@ const CheckboxAndroid = (
|
|
|
63
51
|
size,
|
|
64
52
|
});
|
|
65
53
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
const {
|
|
83
|
-
iconSize,
|
|
84
|
-
rippleColor,
|
|
85
|
-
scale,
|
|
86
|
-
animationDuration,
|
|
87
|
-
rippleContainerStyles,
|
|
88
|
-
filledContainerStyles,
|
|
89
|
-
animatedContainerStyles,
|
|
90
|
-
animatedFillStyles,
|
|
91
|
-
stateLayerStyle,
|
|
92
|
-
iconStyle,
|
|
93
|
-
} = useMemo(() => {
|
|
94
|
-
// const {
|
|
95
|
-
// color: checkedColor,
|
|
96
|
-
// uncheckedColor,
|
|
97
|
-
// animationScale: _scale,
|
|
98
|
-
// animationDuration: _animationDuration,
|
|
99
|
-
// iconSize: _iconSize,
|
|
100
|
-
// padding,
|
|
101
|
-
// width,
|
|
102
|
-
// height,
|
|
103
|
-
// borderRadius,
|
|
104
|
-
// ...checkboxStyles
|
|
105
|
-
// // @ts-ignore
|
|
106
|
-
// } = styles.root;
|
|
107
|
-
|
|
108
|
-
const _color = tokenStylesParser.getColor(checked ? colorProp : uncheckedColorProp);
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
iconStyle: [styles.icon, _color],
|
|
112
|
-
iconSize: iconSizeMap[size],
|
|
113
|
-
// TODO - fix this on web
|
|
114
|
-
rippleColor:
|
|
115
|
-
Platform.OS === 'web' ? undefined : setColor(_color).fade(0.32).rgb().string(),
|
|
116
|
-
checkboxStyle: [styles.root, style],
|
|
117
|
-
scale: 1,
|
|
118
|
-
animationDuration: 100,
|
|
119
|
-
rippleContainerStyles: [styles.root],
|
|
120
|
-
animatedContainerStyles: { transform: [{ scale: scaleAnim }] },
|
|
121
|
-
filledContainerStyles: [StyleSheet.absoluteFill, styles.fillContainer],
|
|
122
|
-
// for toggle animation // This needs to be computed because it's opinionated animation
|
|
123
|
-
animatedFillStyles: [
|
|
124
|
-
styles.animatedFill, // 4 because padding - border(which is 1px each side)
|
|
125
|
-
tokenStylesParser.getColor(checked ? colorProp : uncheckedColorProp, 'borderColor'),
|
|
126
|
-
{ borderWidth },
|
|
127
|
-
],
|
|
128
|
-
stateLayerStyle: [styles.stateLayer, stateLayerProps?.style],
|
|
129
|
-
};
|
|
130
|
-
}, [
|
|
131
|
-
borderWidth,
|
|
132
|
-
checked,
|
|
133
|
-
colorProp,
|
|
134
|
-
scaleAnim,
|
|
135
|
-
stateLayerProps?.style,
|
|
136
|
-
style,
|
|
137
|
-
uncheckedColorProp,
|
|
138
|
-
size,
|
|
139
|
-
]);
|
|
140
|
-
|
|
141
|
-
useEffect(() => {
|
|
142
|
-
// Do not run animation on very first rendering
|
|
143
|
-
if (isFirstRendering.current) {
|
|
144
|
-
isFirstRendering.current = false;
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
Animated.sequence([
|
|
149
|
-
Animated.timing(scaleAnim, {
|
|
150
|
-
toValue: 0.85,
|
|
151
|
-
duration: checked ? animationDuration * scale : 0,
|
|
152
|
-
useNativeDriver: false,
|
|
153
|
-
}),
|
|
154
|
-
Animated.timing(scaleAnim, {
|
|
155
|
-
toValue: 1,
|
|
156
|
-
duration: checked ? animationDuration * scale : animationDuration * scale * 1.75,
|
|
157
|
-
useNativeDriver: false,
|
|
158
|
-
}),
|
|
159
|
-
]).start();
|
|
160
|
-
}, [checked, scaleAnim, scale, animationDuration]);
|
|
54
|
+
const { iconSize, rippleColor, rippleContainerStyles, stateLayerStyle, iconStyle } =
|
|
55
|
+
useMemo(() => {
|
|
56
|
+
const _color = tokenStylesParser.getColor(checked ? colorProp : uncheckedColorProp);
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
iconStyle: [styles.icon, _color],
|
|
60
|
+
iconSize: iconSizeMap[size],
|
|
61
|
+
// TODO - fix this on web
|
|
62
|
+
rippleColor:
|
|
63
|
+
Platform.OS === 'web' ? undefined : setColor(_color).fade(0.32).rgb().string(),
|
|
64
|
+
rippleContainerStyles: [styles.root, style],
|
|
65
|
+
stateLayerStyle: [styles.stateLayer, stateLayerProps?.style],
|
|
66
|
+
};
|
|
67
|
+
}, [checked, colorProp, uncheckedColorProp, size, style, stateLayerProps?.style]);
|
|
161
68
|
|
|
162
69
|
const onChange = useCallback(() => {
|
|
163
70
|
onChangeProp?.(!checked);
|
|
@@ -185,18 +92,13 @@ const CheckboxAndroid = (
|
|
|
185
92
|
testID={testID}
|
|
186
93
|
ref={actionsRef}>
|
|
187
94
|
<>
|
|
188
|
-
<
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
/>
|
|
196
|
-
<View style={filledContainerStyles}>
|
|
197
|
-
<Animated.View style={animatedFillStyles} />
|
|
198
|
-
</View>
|
|
199
|
-
</Animated.View>
|
|
95
|
+
<Icon
|
|
96
|
+
allowFontScaling={false}
|
|
97
|
+
type="material-community"
|
|
98
|
+
name={icon}
|
|
99
|
+
size={iconSize}
|
|
100
|
+
style={iconStyle}
|
|
101
|
+
/>
|
|
200
102
|
<StateLayer
|
|
201
103
|
testID={testID ? `${testID}-stateLayer` : ''}
|
|
202
104
|
{...stateLayerProps}
|
|
@@ -207,11 +109,4 @@ const CheckboxAndroid = (
|
|
|
207
109
|
);
|
|
208
110
|
};
|
|
209
111
|
|
|
210
|
-
// const styles = StyleSheet.create({
|
|
211
|
-
// fillContainer: {
|
|
212
|
-
// alignItems: 'center',
|
|
213
|
-
// justifyContent: 'center',
|
|
214
|
-
// },
|
|
215
|
-
// });
|
|
216
|
-
|
|
217
112
|
export default memo(forwardRef(CheckboxAndroid));
|