react-native-molecules 0.5.0-beta.2 → 0.5.0-beta.21
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.ios.tsx +10 -14
- package/components/Checkbox/CheckboxBase.tsx +14 -121
- 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 +111 -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 +245 -0
- package/components/DatePicker/DatePickerPopover.tsx +79 -0
- package/components/DatePicker/DatePickerProvider.tsx +158 -0
- package/components/DatePicker/DatePickerTrigger.tsx +23 -0
- package/components/DatePicker/context.tsx +83 -0
- package/components/DatePicker/index.tsx +45 -0
- package/components/DatePicker/utils.ts +293 -0
- package/components/DatePickerInline/DatePickerContext.tsx +1 -0
- package/components/DatePickerInline/DatePickerDockedHeader.tsx +117 -0
- package/components/DatePickerInline/DatePickerInline.tsx +16 -15
- package/components/DatePickerInline/DatePickerInlineBase.tsx +8 -2
- package/components/DatePickerInline/DatePickerInlineHeader.tsx +8 -4
- package/components/DatePickerInline/Day.tsx +25 -1
- package/components/DatePickerInline/DayNames.tsx +13 -10
- package/components/DatePickerInline/DayRange.tsx +2 -4
- package/components/DatePickerInline/HeaderItem.tsx +42 -27
- package/components/DatePickerInline/Month.tsx +48 -67
- package/components/DatePickerInline/MonthPicker.tsx +38 -44
- 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 +6 -2
- 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,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,18 @@ const CheckboxAndroid = (
|
|
|
63
51
|
size,
|
|
64
52
|
});
|
|
65
53
|
|
|
66
|
-
|
|
67
|
-
// variant: 'android',
|
|
68
|
-
// state: resolveStateVariant({
|
|
69
|
-
// disabled,
|
|
70
|
-
// checkedAndHovered: checked && !indeterminate && hovered,
|
|
71
|
-
// checked: checked && !indeterminate,
|
|
72
|
-
// hovered,
|
|
73
|
-
// }),
|
|
74
|
-
// size,
|
|
75
|
-
// });
|
|
76
|
-
|
|
77
|
-
const borderWidth = scaleAnim.interpolate({
|
|
78
|
-
inputRange: [0.8, 1],
|
|
79
|
-
outputRange: [7, 0],
|
|
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
|
-
|
|
54
|
+
const { rippleColor, rippleContainerStyles, iconStyle } = useMemo(() => {
|
|
108
55
|
const _color = tokenStylesParser.getColor(checked ? colorProp : uncheckedColorProp);
|
|
109
56
|
|
|
110
57
|
return {
|
|
111
58
|
iconStyle: [styles.icon, _color],
|
|
112
|
-
iconSize: iconSizeMap[size],
|
|
113
59
|
// TODO - fix this on web
|
|
114
60
|
rippleColor:
|
|
115
61
|
Platform.OS === 'web' ? undefined : setColor(_color).fade(0.32).rgb().string(),
|
|
116
|
-
|
|
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],
|
|
62
|
+
rippleContainerStyles: [styles.root, style],
|
|
129
63
|
};
|
|
130
|
-
|
|
131
|
-
|
|
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]);
|
|
64
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
65
|
+
}, [checked, colorProp, uncheckedColorProp, style, size, state]);
|
|
161
66
|
|
|
162
67
|
const onChange = useCallback(() => {
|
|
163
68
|
onChangeProp?.(!checked);
|
|
@@ -185,33 +90,21 @@ const CheckboxAndroid = (
|
|
|
185
90
|
testID={testID}
|
|
186
91
|
ref={actionsRef}>
|
|
187
92
|
<>
|
|
188
|
-
<
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
/>
|
|
196
|
-
<View style={filledContainerStyles}>
|
|
197
|
-
<Animated.View style={animatedFillStyles} />
|
|
198
|
-
</View>
|
|
199
|
-
</Animated.View>
|
|
93
|
+
<Icon
|
|
94
|
+
allowFontScaling={false}
|
|
95
|
+
type="material-community"
|
|
96
|
+
name={icon}
|
|
97
|
+
size={iconSizeMap[size]}
|
|
98
|
+
style={iconStyle}
|
|
99
|
+
/>
|
|
200
100
|
<StateLayer
|
|
201
101
|
testID={testID ? `${testID}-stateLayer` : ''}
|
|
202
102
|
{...stateLayerProps}
|
|
203
|
-
style={
|
|
103
|
+
style={[styles.stateLayer, stateLayerProps?.style]}
|
|
204
104
|
/>
|
|
205
105
|
</>
|
|
206
106
|
</TouchableRipple>
|
|
207
107
|
);
|
|
208
108
|
};
|
|
209
109
|
|
|
210
|
-
// const styles = StyleSheet.create({
|
|
211
|
-
// fillContainer: {
|
|
212
|
-
// alignItems: 'center',
|
|
213
|
-
// justifyContent: 'center',
|
|
214
|
-
// },
|
|
215
|
-
// });
|
|
216
|
-
|
|
217
110
|
export default memo(forwardRef(CheckboxAndroid));
|
|
@@ -132,31 +132,6 @@ const checkboxStylesDefault = StyleSheet.create(theme => ({
|
|
|
132
132
|
},
|
|
133
133
|
],
|
|
134
134
|
},
|
|
135
|
-
fillContainer: {
|
|
136
|
-
alignItems: 'center',
|
|
137
|
-
justifyContent: 'center',
|
|
138
|
-
},
|
|
139
|
-
animatedFill: {
|
|
140
|
-
width: 24 / 2 + (PADDING - 2),
|
|
141
|
-
height: 24 / 2 + (PADDING - 2),
|
|
142
|
-
|
|
143
|
-
variants: {
|
|
144
|
-
size: {
|
|
145
|
-
sm: {
|
|
146
|
-
width: iconSizeMap.sm / 2 + (PADDING - 2),
|
|
147
|
-
height: iconSizeMap.sm / 2 + (PADDING - 2),
|
|
148
|
-
},
|
|
149
|
-
md: {
|
|
150
|
-
width: iconSizeMap.md / 2 + (PADDING - 2),
|
|
151
|
-
height: iconSizeMap.md / 2 + (PADDING - 2),
|
|
152
|
-
},
|
|
153
|
-
lg: {
|
|
154
|
-
width: iconSizeMap.lg / 2 + (PADDING - 2),
|
|
155
|
-
height: iconSizeMap.lg / 2 + (PADDING - 2),
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
},
|
|
160
135
|
icon: {
|
|
161
136
|
color: theme.colors.onSurfaceVariant,
|
|
162
137
|
|
package/components/Chip/Chip.tsx
CHANGED
|
@@ -97,10 +97,6 @@ export type Props = Omit<TouchableRippleProps, 'children'> &
|
|
|
97
97
|
* Whether to show the ActivityIndicator or not
|
|
98
98
|
*/
|
|
99
99
|
loading?: boolean;
|
|
100
|
-
/**
|
|
101
|
-
* container style
|
|
102
|
-
*/
|
|
103
|
-
containerStyle?: ViewStyle;
|
|
104
100
|
/**
|
|
105
101
|
* left element container style
|
|
106
102
|
*/
|
|
@@ -132,7 +128,6 @@ export type Props = Omit<TouchableRippleProps, 'children'> &
|
|
|
132
128
|
const Chip = (
|
|
133
129
|
{
|
|
134
130
|
style,
|
|
135
|
-
containerStyle: containerStyleProp,
|
|
136
131
|
label: _label,
|
|
137
132
|
labelCharacterLimit = 20,
|
|
138
133
|
variant = 'outlined',
|
|
@@ -158,11 +153,13 @@ const Chip = (
|
|
|
158
153
|
leftElementIconProps,
|
|
159
154
|
invertLabelColor,
|
|
160
155
|
backgroundColor,
|
|
156
|
+
onPress,
|
|
161
157
|
...rest
|
|
162
158
|
}: Props,
|
|
163
159
|
ref: any,
|
|
164
160
|
) => {
|
|
165
161
|
const { hovered, actionsRef } = useActionState({ ref, actionsToListen: ['hover'] });
|
|
162
|
+
const Wrapper = onPress ? TouchableRipple : View;
|
|
166
163
|
|
|
167
164
|
const state = resolveStateVariant({
|
|
168
165
|
disabled: !!disabled,
|
|
@@ -192,47 +189,39 @@ const Chip = (
|
|
|
192
189
|
// selectedColorProp ? { selectedColor: selectedColorProp } : {},
|
|
193
190
|
// ]);
|
|
194
191
|
|
|
195
|
-
const {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
styles.
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
stateLayerProps?.style,
|
|
229
|
-
style,
|
|
230
|
-
containerStyleProp,
|
|
231
|
-
labelStyleProp,
|
|
232
|
-
state,
|
|
233
|
-
size,
|
|
234
|
-
variant,
|
|
235
|
-
]);
|
|
192
|
+
const { containerStyle, leftElementStyle, rightElementStyle, labelStyle, stateLayerStyle } =
|
|
193
|
+
useMemo(() => {
|
|
194
|
+
return {
|
|
195
|
+
containerStyle: [
|
|
196
|
+
styles.container,
|
|
197
|
+
selected && selectionBackgroundColor
|
|
198
|
+
? { backgroundColor: selectionBackgroundColor }
|
|
199
|
+
: {},
|
|
200
|
+
style,
|
|
201
|
+
],
|
|
202
|
+
leftElementStyle: [styles.leftElement, leftElementContainerStyle],
|
|
203
|
+
rightElementStyle: [styles.rightElement, rightElementContainerStyle],
|
|
204
|
+
labelStyle: [
|
|
205
|
+
styles.label,
|
|
206
|
+
selected && selectedColor ? { color: selectedColor } : {},
|
|
207
|
+
labelStyleProp,
|
|
208
|
+
],
|
|
209
|
+
stateLayerStyle: [styles.stateLayer, stateLayerProps?.style],
|
|
210
|
+
};
|
|
211
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
212
|
+
}, [
|
|
213
|
+
leftElementContainerStyle,
|
|
214
|
+
rightElementContainerStyle,
|
|
215
|
+
selected,
|
|
216
|
+
selectedColor,
|
|
217
|
+
selectionBackgroundColor,
|
|
218
|
+
stateLayerProps?.style,
|
|
219
|
+
style,
|
|
220
|
+
labelStyleProp,
|
|
221
|
+
state,
|
|
222
|
+
size,
|
|
223
|
+
variant,
|
|
224
|
+
]);
|
|
236
225
|
|
|
237
226
|
const { accessibilityState, elevation } = useMemo(
|
|
238
227
|
() => ({
|
|
@@ -251,14 +240,13 @@ const Chip = (
|
|
|
251
240
|
{...containerProps}
|
|
252
241
|
elevation={elevation}
|
|
253
242
|
style={containerStyle}
|
|
254
|
-
backgroundColor={backgroundColor}
|
|
255
|
-
|
|
243
|
+
backgroundColor={backgroundColor}
|
|
244
|
+
asChild>
|
|
245
|
+
<Wrapper
|
|
256
246
|
borderless
|
|
257
247
|
{...rest}
|
|
258
248
|
disabled={disabled}
|
|
259
|
-
style={touchableRippleStyle}
|
|
260
249
|
accessibilityLabel={accessibilityLabel}
|
|
261
|
-
accessibilityRole="button"
|
|
262
250
|
accessibilityState={accessibilityState}
|
|
263
251
|
ref={actionsRef}
|
|
264
252
|
testID={testID}>
|
|
@@ -297,7 +285,7 @@ const Chip = (
|
|
|
297
285
|
style={stateLayerStyle}
|
|
298
286
|
/>
|
|
299
287
|
</>
|
|
300
|
-
</
|
|
288
|
+
</Wrapper>
|
|
301
289
|
</Surface>
|
|
302
290
|
);
|
|
303
291
|
};
|
|
@@ -362,7 +350,7 @@ const RightElement = memo(
|
|
|
362
350
|
{onClose ? (
|
|
363
351
|
<IconButtonWithContrastColor
|
|
364
352
|
name="close"
|
|
365
|
-
size={
|
|
353
|
+
size={14}
|
|
366
354
|
accessibilityLabel="Close"
|
|
367
355
|
disabled={disabled}
|
|
368
356
|
onPress={onClose}
|
package/components/Chip/utils.ts
CHANGED
|
@@ -6,6 +6,9 @@ const chipStylesDefault = StyleSheet.create(theme => ({
|
|
|
6
6
|
container: {
|
|
7
7
|
borderRadius: theme.shapes.corner.small,
|
|
8
8
|
backgroundColor: theme.colors.surface,
|
|
9
|
+
paddingHorizontal: theme.spacings['2'],
|
|
10
|
+
flexDirection: 'row',
|
|
11
|
+
alignItems: 'center',
|
|
9
12
|
|
|
10
13
|
variants: {
|
|
11
14
|
variant: {
|
|
@@ -47,13 +50,6 @@ const chipStylesDefault = StyleSheet.create(theme => ({
|
|
|
47
50
|
},
|
|
48
51
|
},
|
|
49
52
|
},
|
|
50
|
-
touchableRippleContainer: {
|
|
51
|
-
flex: 1,
|
|
52
|
-
paddingHorizontal: theme.spacings['2'],
|
|
53
|
-
borderRadius: theme.shapes.corner.small,
|
|
54
|
-
flexDirection: 'row',
|
|
55
|
-
alignItems: 'center',
|
|
56
|
-
},
|
|
57
53
|
label: {
|
|
58
54
|
display: 'flex',
|
|
59
55
|
color: theme.colors.onSurfaceVariant,
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { memo, useCallback, useMemo, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { DatePickerValue, RangeValue } from '../DatePicker/context';
|
|
4
|
+
import { useDatePickerContext } from '../DatePicker/context';
|
|
5
|
+
import type { TextInputProps } from '../TextInput';
|
|
6
|
+
import { TextInputWithMask } from '../TextInputWithMask';
|
|
7
|
+
import { useDateFieldState } from './useDateFieldState';
|
|
8
|
+
|
|
9
|
+
export type DateFieldInputMode = 'start' | 'end';
|
|
10
|
+
|
|
11
|
+
export type DateFieldProps = Omit<
|
|
12
|
+
TextInputProps,
|
|
13
|
+
'value' | 'defaultValue' | 'onChangeText' | 'inputMode'
|
|
14
|
+
> & {
|
|
15
|
+
inputMode?: DateFieldInputMode;
|
|
16
|
+
dateFormat?: string;
|
|
17
|
+
mask?: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const DEFAULT_DATE_FORMAT = 'dd/MM/yyyy';
|
|
21
|
+
|
|
22
|
+
const isRange = (value: DatePickerValue): value is RangeValue =>
|
|
23
|
+
value !== null && typeof value === 'object' && 'start' in value && 'end' in value;
|
|
24
|
+
|
|
25
|
+
const preserveTime = (next: Date | null, prev: Date | null): Date | null => {
|
|
26
|
+
if (!next || !prev) return next;
|
|
27
|
+
|
|
28
|
+
const combined = new Date(next);
|
|
29
|
+
|
|
30
|
+
combined.setHours(
|
|
31
|
+
prev.getHours(),
|
|
32
|
+
prev.getMinutes(),
|
|
33
|
+
prev.getSeconds(),
|
|
34
|
+
prev.getMilliseconds(),
|
|
35
|
+
);
|
|
36
|
+
return combined;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
function DateField({
|
|
40
|
+
ref,
|
|
41
|
+
inputMode = 'start',
|
|
42
|
+
dateFormat = DEFAULT_DATE_FORMAT,
|
|
43
|
+
disabled: disabledProp,
|
|
44
|
+
onBlur,
|
|
45
|
+
onFocus,
|
|
46
|
+
...rest
|
|
47
|
+
}: DateFieldProps) {
|
|
48
|
+
const {
|
|
49
|
+
mode,
|
|
50
|
+
value,
|
|
51
|
+
commitValue,
|
|
52
|
+
validRange,
|
|
53
|
+
disabled: providerDisabled,
|
|
54
|
+
} = useDatePickerContext();
|
|
55
|
+
const isBlurredRef = useRef(true);
|
|
56
|
+
|
|
57
|
+
const disabled = disabledProp ?? providerDisabled;
|
|
58
|
+
|
|
59
|
+
const fieldValue = useMemo<Date | null>(() => {
|
|
60
|
+
if (mode === 'range') {
|
|
61
|
+
if (!isRange(value)) return null;
|
|
62
|
+
return inputMode === 'end' ? value.end : value.start;
|
|
63
|
+
}
|
|
64
|
+
return isRange(value) ? null : value;
|
|
65
|
+
}, [value, mode, inputMode]);
|
|
66
|
+
|
|
67
|
+
const onChange = useCallback(
|
|
68
|
+
(next: Date | null) => {
|
|
69
|
+
if (mode === 'range') {
|
|
70
|
+
const current: RangeValue = isRange(value) ? value : { start: null, end: null };
|
|
71
|
+
commitValue({ ...current, [inputMode]: next });
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
commitValue(preserveTime(next, isRange(value) ? null : value));
|
|
75
|
+
},
|
|
76
|
+
[mode, value, inputMode, commitValue],
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const {
|
|
80
|
+
formattedValue,
|
|
81
|
+
onChangeText,
|
|
82
|
+
onBlur: onInnerBlur,
|
|
83
|
+
onFocus: onInnerFocus,
|
|
84
|
+
} = useDateFieldState({
|
|
85
|
+
value: fieldValue,
|
|
86
|
+
validRange,
|
|
87
|
+
inputMode,
|
|
88
|
+
dateFormat,
|
|
89
|
+
onChange,
|
|
90
|
+
onBlur,
|
|
91
|
+
onFocus,
|
|
92
|
+
isBlurredRef,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<TextInputWithMask
|
|
97
|
+
placeholder={dateFormat}
|
|
98
|
+
keyboardType="number-pad"
|
|
99
|
+
mask={dateFormat}
|
|
100
|
+
{...rest}
|
|
101
|
+
ref={ref}
|
|
102
|
+
disabled={disabled}
|
|
103
|
+
value={formattedValue}
|
|
104
|
+
onChangeText={onChangeText}
|
|
105
|
+
onBlur={onInnerBlur}
|
|
106
|
+
onFocus={onInnerFocus}
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export default memo(DateField);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { getRegisteredComponentWithFallback } from '../../core';
|
|
2
|
+
import DateFieldDefault from './DateField';
|
|
3
|
+
|
|
4
|
+
export const DateField = getRegisteredComponentWithFallback('DateField', DateFieldDefault);
|
|
5
|
+
|
|
6
|
+
export type { DateFieldInputMode, DateFieldProps } from './DateField';
|
|
@@ -10,34 +10,31 @@ import { useRangeChecker } from '../DatePickerInline/dateUtils';
|
|
|
10
10
|
const formatValue = (value: Date | null | undefined, dateFormat: string) =>
|
|
11
11
|
!isNil(value) ? format(value, dateFormat) || '' : '';
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
// locale,
|
|
15
|
-
value,
|
|
16
|
-
validRange,
|
|
17
|
-
inputMode = 'start',
|
|
18
|
-
onChange,
|
|
19
|
-
dateFormat,
|
|
20
|
-
onBlur: onBlurProp,
|
|
21
|
-
onFocus: onFocusProp,
|
|
22
|
-
isBlurredRef,
|
|
23
|
-
}: {
|
|
24
|
-
onChange?: (d: Date | null) => void;
|
|
25
|
-
onBlur?: (e: BlurEvent) => void;
|
|
26
|
-
onFocus?: (e: FocusEvent) => void;
|
|
27
|
-
// locale: undefined | string;
|
|
13
|
+
type Props = {
|
|
28
14
|
value?: Date | null;
|
|
29
15
|
validRange?: ValidRangeType;
|
|
30
16
|
inputMode: 'start' | 'end';
|
|
31
17
|
dateFormat: string;
|
|
32
18
|
isBlurredRef: RefObject<boolean>;
|
|
33
|
-
|
|
34
|
-
|
|
19
|
+
onChange?: (value: Date | null) => void;
|
|
20
|
+
onBlur?: (e: BlurEvent) => void;
|
|
21
|
+
onFocus?: (e: FocusEvent) => void;
|
|
22
|
+
};
|
|
35
23
|
|
|
24
|
+
export function useDateFieldState({
|
|
25
|
+
value,
|
|
26
|
+
validRange,
|
|
27
|
+
inputMode,
|
|
28
|
+
dateFormat,
|
|
29
|
+
isBlurredRef,
|
|
30
|
+
onChange,
|
|
31
|
+
onBlur: onBlurProp,
|
|
32
|
+
onFocus: onFocusProp,
|
|
33
|
+
}: Props) {
|
|
34
|
+
const { isDisabled, isWithinValidRange } = useRangeChecker(validRange);
|
|
36
35
|
const [formattedValue, setFormattedValue] = useState(() => formatValue(value, dateFormat));
|
|
37
36
|
const formattedValueRef = useLatest(formattedValue);
|
|
38
37
|
|
|
39
|
-
// const [error, setError] = useState<null | string>(null);
|
|
40
|
-
|
|
41
38
|
const onChangeText = useCallback(
|
|
42
39
|
(date: string) => {
|
|
43
40
|
const parsedDate = parse(date, dateFormat, new Date());
|
|
@@ -51,45 +48,18 @@ export default function useDateInput({
|
|
|
51
48
|
);
|
|
52
49
|
|
|
53
50
|
if (!isValid(parsedDate)) {
|
|
54
|
-
// TODO: Translate
|
|
55
|
-
// setError(`Date format must be ${dateFormat}`);
|
|
56
51
|
onChange?.(date ? value ?? null : null);
|
|
57
|
-
|
|
58
52
|
return;
|
|
59
53
|
}
|
|
60
54
|
|
|
61
55
|
const finalDate = inputMode === 'end' ? endOfDay(parsedDate) : parsedDate;
|
|
62
56
|
|
|
63
|
-
if (isDisabled(finalDate)) {
|
|
64
|
-
// TODO: Translate
|
|
65
|
-
// setError('Day is not allowed');
|
|
57
|
+
if (isDisabled(finalDate) || !isWithinValidRange(finalDate)) {
|
|
66
58
|
onChange?.(null);
|
|
67
|
-
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (!isWithinValidRange(finalDate)) {
|
|
71
|
-
// TODO: Translate
|
|
72
|
-
// const errors =
|
|
73
|
-
// validStart && validEnd
|
|
74
|
-
// ? [
|
|
75
|
-
// `${`Must be between ${format(validStart, dateFormat)} - ${format(
|
|
76
|
-
// validEnd,
|
|
77
|
-
// dateFormat,
|
|
78
|
-
// )})`}`,
|
|
79
|
-
// ]
|
|
80
|
-
// : [
|
|
81
|
-
// validStart ? `Must be later then ${validStart}` : '',
|
|
82
|
-
// validEnd ? `Must be earlier then ${validEnd}` : '',
|
|
83
|
-
// ];
|
|
84
|
-
|
|
85
|
-
// setError(errors.filter(n => n).join(' '));
|
|
86
|
-
onChange?.(null);
|
|
87
|
-
|
|
88
59
|
return;
|
|
89
60
|
}
|
|
90
61
|
|
|
91
62
|
onChange?.(finalDate);
|
|
92
|
-
// setError(null);
|
|
93
63
|
},
|
|
94
64
|
[
|
|
95
65
|
dateFormat,
|
|
@@ -128,8 +98,6 @@ export default function useDateInput({
|
|
|
128
98
|
}, [value, dateFormat, isBlurredRef]);
|
|
129
99
|
|
|
130
100
|
return {
|
|
131
|
-
onChange,
|
|
132
|
-
// error,
|
|
133
101
|
formattedValue,
|
|
134
102
|
onChangeText,
|
|
135
103
|
onBlur,
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { memo } from 'react';
|
|
2
|
+
|
|
3
|
+
import { getRegisteredComponentWithFallback } from '../../core';
|
|
4
|
+
import {
|
|
5
|
+
DatePickerInline,
|
|
6
|
+
type DatePickerInlineProps,
|
|
7
|
+
type RangeChange,
|
|
8
|
+
type SingleChange,
|
|
9
|
+
} from '../DatePickerInline';
|
|
10
|
+
import { useOptionalDatePickerContext } from './context';
|
|
11
|
+
|
|
12
|
+
export type DateCalendarProps = DatePickerInlineProps;
|
|
13
|
+
|
|
14
|
+
const DateCalendarDefault = memo((props: DateCalendarProps) => {
|
|
15
|
+
const ctx = useOptionalDatePickerContext();
|
|
16
|
+
|
|
17
|
+
const hasExplicitState =
|
|
18
|
+
props.date !== undefined ||
|
|
19
|
+
props.startDate !== undefined ||
|
|
20
|
+
props.endDate !== undefined ||
|
|
21
|
+
props.dates !== undefined ||
|
|
22
|
+
props.onChange !== undefined;
|
|
23
|
+
|
|
24
|
+
const isRange = props.mode === 'range' || ctx?.mode === 'range';
|
|
25
|
+
const effectiveHeaderLayout = props.headerLayout ?? (ctx ? 'docked' : 'inline');
|
|
26
|
+
const showOutsideDays =
|
|
27
|
+
props.showOutsideDays ?? (effectiveHeaderLayout === 'docked' && !isRange);
|
|
28
|
+
|
|
29
|
+
if (!ctx || hasExplicitState) {
|
|
30
|
+
return <DatePickerInline {...props} showOutsideDays={showOutsideDays} />;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const locale = props.locale ?? ctx.locale;
|
|
34
|
+
const validRange = props.validRange ?? ctx.validRange;
|
|
35
|
+
|
|
36
|
+
if (ctx.mode === 'range') {
|
|
37
|
+
const range =
|
|
38
|
+
ctx.draftValue && typeof ctx.draftValue === 'object' && 'start' in ctx.draftValue
|
|
39
|
+
? ctx.draftValue
|
|
40
|
+
: { start: null, end: null };
|
|
41
|
+
const onChange: RangeChange = ({ startDate, endDate }) => {
|
|
42
|
+
ctx.setValue({ start: startDate ?? null, end: endDate ?? null });
|
|
43
|
+
};
|
|
44
|
+
return (
|
|
45
|
+
<DatePickerInline
|
|
46
|
+
{...props}
|
|
47
|
+
mode="range"
|
|
48
|
+
startDate={range.start ?? undefined}
|
|
49
|
+
endDate={range.end ?? undefined}
|
|
50
|
+
onChange={onChange}
|
|
51
|
+
locale={locale}
|
|
52
|
+
validRange={validRange}
|
|
53
|
+
headerLayout={props.headerLayout ?? 'docked'}
|
|
54
|
+
showOutsideDays={showOutsideDays}
|
|
55
|
+
/>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const single =
|
|
60
|
+
ctx.draftValue && typeof ctx.draftValue === 'object' && 'start' in ctx.draftValue
|
|
61
|
+
? null
|
|
62
|
+
: ctx.draftValue;
|
|
63
|
+
const onChange: SingleChange = ({ date }) => {
|
|
64
|
+
ctx.setValue(date ?? null);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<DatePickerInline
|
|
69
|
+
{...props}
|
|
70
|
+
mode="single"
|
|
71
|
+
date={single ?? undefined}
|
|
72
|
+
onChange={onChange}
|
|
73
|
+
locale={locale}
|
|
74
|
+
validRange={validRange}
|
|
75
|
+
headerLayout={props.headerLayout ?? 'docked'}
|
|
76
|
+
showOutsideDays={showOutsideDays}
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
DateCalendarDefault.displayName = 'DateCalendar';
|
|
82
|
+
|
|
83
|
+
export const DateCalendar = getRegisteredComponentWithFallback('DateCalendar', DateCalendarDefault);
|