react-native-molecules 0.5.0-beta.3 → 0.5.0-beta.31
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/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 +211 -264
- package/components/Button/index.tsx +9 -3
- package/components/Button/types.ts +16 -2
- package/components/Button/utils.ts +230 -208
- package/components/Card/Card.tsx +1 -1
- package/components/Checkbox/Checkbox.tsx +125 -88
- package/components/Checkbox/CheckboxBase.ios.tsx +14 -23
- package/components/Checkbox/CheckboxBase.tsx +21 -137
- package/components/Checkbox/context.tsx +14 -0
- package/components/Checkbox/index.tsx +11 -4
- package/components/Checkbox/types.ts +63 -29
- package/components/Checkbox/utils.ts +25 -108
- package/components/Chip/Chip.tsx +41 -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} +19 -51
- package/components/DatePicker/DateCalendar.tsx +83 -0
- package/components/DatePicker/DatePickerActions.tsx +73 -0
- package/components/DatePicker/DatePickerModal.tsx +246 -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 +295 -0
- package/components/DatePickerInline/DatePickerDockedHeader.tsx +117 -0
- package/components/DatePickerInline/DatePickerInline.tsx +17 -16
- package/components/DatePickerInline/DatePickerInlineBase.tsx +11 -5
- package/components/DatePickerInline/DatePickerInlineHeader.tsx +50 -20
- 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 +44 -29
- package/components/DatePickerInline/Month.tsx +48 -67
- package/components/DatePickerInline/MonthPicker.tsx +80 -92
- package/components/DatePickerInline/Swiper.native.tsx +21 -4
- package/components/DatePickerInline/Swiper.tsx +169 -14
- package/components/DatePickerInline/SwiperUtils.ts +1 -1
- package/components/DatePickerInline/Week.tsx +6 -1
- package/components/DatePickerInline/YearPicker.tsx +220 -78
- package/components/DatePickerInline/dateUtils.tsx +18 -13
- package/components/DatePickerInline/store.tsx +27 -0
- package/components/DatePickerInline/types.ts +6 -2
- package/components/DatePickerInline/utils.ts +66 -29
- package/components/Divider/Divider.tsx +192 -0
- package/components/Divider/index.tsx +10 -0
- package/components/Drawer/Drawer.tsx +17 -6
- package/components/Drawer/DrawerItemGroup.tsx +3 -7
- package/components/ElementGroup/ElementGroup.tsx +1 -1
- 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 +5 -4
- package/components/Icon/index.tsx +1 -1
- package/components/Icon/types.ts +17 -6
- package/components/IconButton/IconButton.tsx +84 -84
- package/components/IconButton/index.tsx +1 -0
- package/components/IconButton/types.ts +10 -0
- package/components/IconButton/utils.ts +167 -33
- package/components/List/List.tsx +276 -0
- package/components/List/context.tsx +27 -0
- package/components/List/index.ts +8 -0
- package/components/List/types.ts +117 -0
- package/components/List/utils.ts +79 -0
- 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 +162 -39
- package/components/Menu/index.tsx +10 -7
- package/components/Menu/utils.ts +21 -70
- package/components/NavigationRail/NavigationRail.tsx +15 -9
- package/components/Popover/Popover.tsx +119 -145
- package/components/Popover/PopoverRoot.tsx +60 -0
- package/components/Popover/common.ts +54 -34
- package/components/Popover/index.ts +12 -1
- package/components/Popover/usePlatformMeasure.native.ts +90 -0
- package/components/Popover/usePlatformMeasure.ts +120 -0
- package/components/Popover/utils.ts +34 -0
- package/components/Portal/Portal.tsx +1 -2
- package/components/Radio/Radio.tsx +188 -0
- package/components/Radio/RadioBase.ios.tsx +69 -0
- package/components/Radio/RadioBase.tsx +136 -0
- package/components/Radio/context.tsx +23 -0
- package/components/Radio/index.tsx +20 -0
- package/components/Radio/types.ts +101 -0
- package/components/Radio/utils.ts +115 -0
- package/components/Rating/Rating.tsx +1 -1
- package/components/Select/Select.tsx +521 -785
- package/components/Select/context.tsx +81 -0
- package/components/Select/index.ts +26 -14
- package/components/Select/types.ts +65 -58
- package/components/Select/utils.ts +126 -0
- package/components/Slot/Slot.tsx +224 -0
- package/components/Slot/compose-refs.tsx +62 -0
- package/components/Slot/index.tsx +8 -0
- package/components/Surface/Surface.android.tsx +32 -7
- package/components/Surface/Surface.ios.tsx +34 -29
- package/components/Surface/Surface.tsx +31 -4
- package/components/Surface/utils.ts +44 -6
- package/components/Switch/Switch.ios.tsx +1 -1
- package/components/Switch/Switch.tsx +10 -3
- package/components/Tabs/TabItem.tsx +35 -58
- package/components/Tabs/TabLabel.tsx +5 -9
- package/components/Tabs/Tabs.tsx +156 -150
- package/components/Tabs/utils.ts +15 -2
- package/components/Text/textFactory.tsx +17 -5
- package/components/TextInput/TextInput.tsx +663 -579
- package/components/TextInput/index.tsx +19 -3
- package/components/TextInput/types.ts +77 -28
- package/components/TextInput/utils.ts +235 -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/AnalogClock.tsx +1 -1
- package/components/TimePicker/TimeInput.tsx +87 -42
- package/components/TimePicker/TimeInputs.tsx +138 -50
- package/components/TimePicker/TimePicker.tsx +74 -11
- 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 -4
- package/components/Tooltip/Tooltip.tsx +42 -67
- package/components/Tooltip/TooltipContent.tsx +32 -5
- package/components/Tooltip/TooltipTrigger.tsx +21 -24
- package/components/Tooltip/index.tsx +1 -1
- package/components/TouchableRipple/TouchableRipple.native.tsx +83 -16
- package/components/TouchableRipple/TouchableRipple.tsx +150 -102
- package/components/TouchableRipple/rippleFromForegroundColor.ts +21 -0
- package/hocs/index.tsx +1 -1
- package/hocs/withKeyboardAccessibility.tsx +2 -3
- package/hocs/withPortal.tsx +1 -1
- package/hooks/index.tsx +2 -12
- package/hooks/useActionState.tsx +19 -8
- package/hooks/useContrastColor.ts +1 -2
- package/hooks/useFilePicker.tsx +7 -17
- package/hooks/useHandleNumberFormat.tsx +2 -2
- package/hooks/useMediaQuery.tsx +1 -2
- package/package.json +95 -111
- package/shortcuts-manager/ShortcutsManager/ShortcutsManager.tsx +6 -3
- package/shortcuts-manager/ShortcutsManager/utils.tsx +1 -1
- package/shortcuts-manager/useSetScopes/useSetScopes.tsx +1 -1
- package/shortcuts-manager/useShortcut/useShortcut.tsx +1 -1
- 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/extractSubcomponents.ts +89 -0
- package/utils/extractTextStyles.ts +1 -2
- package/utils/formatNumberWithMask/formatNumberWithMask.ts +2 -1
- package/utils/index.ts +0 -3
- package/utils/normalizeToNumberString/normalizeToNumberString.ts +1 -1
- 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/DatePickerInline/DatePickerContext.tsx +0 -21
- 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/HorizontalDivider/HorizontalDivider.tsx +0 -103
- package/components/HorizontalDivider/index.tsx +0 -9
- package/components/ListItem/ListItem.tsx +0 -136
- 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/Popover/Popover.native.tsx +0 -185
- package/components/RadioButton/RadioButton.tsx +0 -138
- package/components/RadioButton/RadioButtonAndroid.tsx +0 -188
- package/components/RadioButton/RadioButtonGroup.tsx +0 -98
- package/components/RadioButton/RadioButtonIOS.tsx +0 -106
- package/components/RadioButton/RadioButtonItem.tsx +0 -232
- package/components/RadioButton/index.ts +0 -22
- package/components/RadioButton/utils.ts +0 -165
- 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/components/VerticalDivider/VerticalDivider.tsx +0 -100
- package/components/VerticalDivider/index.tsx +0 -9
- package/context-bridge/index.tsx +0 -87
- package/fast-context/index.tsx +0 -190
- package/hocs/typedMemo.tsx +0 -5
- package/hooks/useControlledValue.tsx +0 -68
- package/hooks/useLatest.tsx +0 -9
- package/hooks/useMergedRefs.ts +0 -14
- package/hooks/usePrevious.ts +0 -13
- package/hooks/useSearchable.tsx +0 -74
- package/hooks/useSubcomponents.tsx +0 -59
- package/hooks/useToggle.tsx +0 -24
- package/utils/color.ts +0 -22
- package/utils/compare/index.ts +0 -54
- package/utils/lodash.ts +0 -49
- package/utils/repository.ts +0 -53
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import { forwardRef, memo, useCallback, useContext, useMemo } from 'react';
|
|
2
|
-
import { type StyleProp, StyleSheet, type TextStyle, View, type ViewStyle } from 'react-native';
|
|
3
|
-
|
|
4
|
-
import { resolveStateVariant } from '../../utils';
|
|
5
|
-
import { Text } from '../Text';
|
|
6
|
-
import { TouchableRipple } from '../TouchableRipple';
|
|
7
|
-
import RadioButton from './RadioButton';
|
|
8
|
-
import { RadioButtonContext } from './RadioButtonGroup';
|
|
9
|
-
import { handlePress, isChecked, radioButtonItemStyles } from './utils';
|
|
10
|
-
|
|
11
|
-
export type Props = {
|
|
12
|
-
/**
|
|
13
|
-
* Value of the radio button.
|
|
14
|
-
*/
|
|
15
|
-
value: string;
|
|
16
|
-
/**
|
|
17
|
-
* Label to be displayed on the item.
|
|
18
|
-
*/
|
|
19
|
-
label: string;
|
|
20
|
-
/**
|
|
21
|
-
* Whether radio is disabled.
|
|
22
|
-
*/
|
|
23
|
-
disabled?: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* Function to execute on press.
|
|
26
|
-
*/
|
|
27
|
-
onPress?: () => void;
|
|
28
|
-
/**
|
|
29
|
-
* Accessibility label for the touchable. This is read by the screen reader when the user taps the touchable.
|
|
30
|
-
*/
|
|
31
|
-
accessibilityLabel?: string;
|
|
32
|
-
/**
|
|
33
|
-
* Custom color for unchecked radio.
|
|
34
|
-
*/
|
|
35
|
-
uncheckedColor?: string;
|
|
36
|
-
/**
|
|
37
|
-
* Custom color for radio.
|
|
38
|
-
*/
|
|
39
|
-
color?: string;
|
|
40
|
-
/**
|
|
41
|
-
* Status of radio button.
|
|
42
|
-
*/
|
|
43
|
-
status?: 'checked' | 'unchecked';
|
|
44
|
-
/**
|
|
45
|
-
* Additional styles for container View.
|
|
46
|
-
*/
|
|
47
|
-
style?: StyleProp<ViewStyle>;
|
|
48
|
-
/**
|
|
49
|
-
* TouchableRipple style
|
|
50
|
-
*/
|
|
51
|
-
rippleContainerStyle?: StyleProp<ViewStyle>;
|
|
52
|
-
/**
|
|
53
|
-
* Style that is passed to Label element.
|
|
54
|
-
*/
|
|
55
|
-
labelStyle?: StyleProp<TextStyle>;
|
|
56
|
-
/**
|
|
57
|
-
* Style that is passed to Container element.
|
|
58
|
-
*/
|
|
59
|
-
containerStyle?: StyleProp<ViewStyle>;
|
|
60
|
-
/**
|
|
61
|
-
* testID to be used on tests.
|
|
62
|
-
*/
|
|
63
|
-
testID?: string;
|
|
64
|
-
/**
|
|
65
|
-
* Radio button control position.
|
|
66
|
-
*/
|
|
67
|
-
position?: 'leading' | 'trailing';
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* RadioButton.Item allows you to press the whole row (item) instead of only the RadioButton.
|
|
72
|
-
*
|
|
73
|
-
* <div class="screenshots">
|
|
74
|
-
* <figure>
|
|
75
|
-
* <img class="medium" src="screenshots/radio-item.ios.png" />
|
|
76
|
-
* <figcaption>Pressed</figcaption>
|
|
77
|
-
* </figure>
|
|
78
|
-
* </div>
|
|
79
|
-
*
|
|
80
|
-
* ## Usage
|
|
81
|
-
* ```js
|
|
82
|
-
* import * as React from 'react';
|
|
83
|
-
* import { RadioButton } from 'react-native-paper';
|
|
84
|
-
*
|
|
85
|
-
* const MyComponent = () => {
|
|
86
|
-
* const [value, setValue] = React.useState('first');
|
|
87
|
-
*
|
|
88
|
-
* return (
|
|
89
|
-
* <RadioButton.Group onValueChange={value => setValue(value)} value={value}>
|
|
90
|
-
* <RadioButton.Item label="First item" value="first" />
|
|
91
|
-
* <RadioButton.Item label="Second item" value="second" />
|
|
92
|
-
* </RadioButton.Group>
|
|
93
|
-
* );
|
|
94
|
-
* };
|
|
95
|
-
*
|
|
96
|
-
* export default MyComponent;
|
|
97
|
-
*```
|
|
98
|
-
*/
|
|
99
|
-
const RadioButtonItem = (
|
|
100
|
-
{
|
|
101
|
-
value,
|
|
102
|
-
label,
|
|
103
|
-
style: styleProp,
|
|
104
|
-
labelStyle,
|
|
105
|
-
onPress,
|
|
106
|
-
disabled,
|
|
107
|
-
color,
|
|
108
|
-
uncheckedColor,
|
|
109
|
-
status,
|
|
110
|
-
accessibilityLabel = label,
|
|
111
|
-
testID,
|
|
112
|
-
position = 'trailing',
|
|
113
|
-
containerStyle,
|
|
114
|
-
rippleContainerStyle,
|
|
115
|
-
}: Props,
|
|
116
|
-
ref: any,
|
|
117
|
-
) => {
|
|
118
|
-
const context = useContext(RadioButtonContext);
|
|
119
|
-
|
|
120
|
-
const checked = useMemo(
|
|
121
|
-
() =>
|
|
122
|
-
isChecked({
|
|
123
|
-
contextValue: context?.value,
|
|
124
|
-
status,
|
|
125
|
-
value,
|
|
126
|
-
}) === 'checked',
|
|
127
|
-
[context?.value, status, value],
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
const state = resolveStateVariant({
|
|
131
|
-
disabled: !!disabled,
|
|
132
|
-
checked,
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
radioButtonItemStyles.useVariants({
|
|
136
|
-
state: state as any,
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
// const componentStyles = useComponentStyles('RadioButton_Item', styleProp, {
|
|
140
|
-
// state: resolveStateVariant({
|
|
141
|
-
// disabled: !!disabled,
|
|
142
|
-
// checked,
|
|
143
|
-
// }),
|
|
144
|
-
// });
|
|
145
|
-
|
|
146
|
-
const isLeading = position === 'leading';
|
|
147
|
-
|
|
148
|
-
const { containerStyles, labelStyles, accessibilityState, radioButtonProps } = useMemo(() => {
|
|
149
|
-
return {
|
|
150
|
-
containerStyles: [radioButtonItemStyles.root, styles.container, containerStyle],
|
|
151
|
-
labelStyles: [
|
|
152
|
-
styles.label,
|
|
153
|
-
radioButtonItemStyles.label,
|
|
154
|
-
{
|
|
155
|
-
textAlign: isLeading ? 'right' : 'left',
|
|
156
|
-
},
|
|
157
|
-
labelStyle,
|
|
158
|
-
] as StyleProp<TextStyle>,
|
|
159
|
-
accessibilityState: {
|
|
160
|
-
checked,
|
|
161
|
-
disabled,
|
|
162
|
-
},
|
|
163
|
-
radioButtonProps: {
|
|
164
|
-
value,
|
|
165
|
-
disabled,
|
|
166
|
-
status,
|
|
167
|
-
color,
|
|
168
|
-
uncheckedColor,
|
|
169
|
-
checked,
|
|
170
|
-
style: styleProp,
|
|
171
|
-
},
|
|
172
|
-
};
|
|
173
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
174
|
-
}, [
|
|
175
|
-
checked,
|
|
176
|
-
color,
|
|
177
|
-
containerStyle,
|
|
178
|
-
disabled,
|
|
179
|
-
isLeading,
|
|
180
|
-
labelStyle,
|
|
181
|
-
status,
|
|
182
|
-
styleProp,
|
|
183
|
-
uncheckedColor,
|
|
184
|
-
value,
|
|
185
|
-
state,
|
|
186
|
-
]);
|
|
187
|
-
|
|
188
|
-
const onRadioPress = useCallback(
|
|
189
|
-
() =>
|
|
190
|
-
handlePress({
|
|
191
|
-
onPress: onPress,
|
|
192
|
-
onValueChange: context?.onValueChange,
|
|
193
|
-
value,
|
|
194
|
-
}),
|
|
195
|
-
[onPress, context?.onValueChange, value],
|
|
196
|
-
);
|
|
197
|
-
|
|
198
|
-
return (
|
|
199
|
-
<TouchableRipple
|
|
200
|
-
ref={ref}
|
|
201
|
-
onPress={onRadioPress}
|
|
202
|
-
accessibilityLabel={accessibilityLabel}
|
|
203
|
-
accessibilityRole="radio"
|
|
204
|
-
accessibilityState={accessibilityState}
|
|
205
|
-
testID={testID}
|
|
206
|
-
disabled={disabled}
|
|
207
|
-
style={rippleContainerStyle}>
|
|
208
|
-
<View style={containerStyles} pointerEvents="none">
|
|
209
|
-
{isLeading && <RadioButton {...radioButtonProps} />}
|
|
210
|
-
<Text style={labelStyles}>{label}</Text>
|
|
211
|
-
{!isLeading && <RadioButton {...radioButtonProps} />}
|
|
212
|
-
</View>
|
|
213
|
-
</TouchableRipple>
|
|
214
|
-
);
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
const styles = StyleSheet.create({
|
|
218
|
-
container: {
|
|
219
|
-
flexDirection: 'row',
|
|
220
|
-
alignItems: 'center',
|
|
221
|
-
justifyContent: 'space-between',
|
|
222
|
-
},
|
|
223
|
-
label: {
|
|
224
|
-
flexShrink: 1,
|
|
225
|
-
flexGrow: 1,
|
|
226
|
-
fontSize: 16,
|
|
227
|
-
},
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
RadioButtonItem.displayName = 'RadioButton_Item';
|
|
231
|
-
|
|
232
|
-
export default memo(forwardRef(RadioButtonItem));
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { getRegisteredComponentWithFallback } from '../../core';
|
|
2
|
-
import RadioButtonComponent from './RadioButton';
|
|
3
|
-
import RadioButtonGroup from './RadioButtonGroup';
|
|
4
|
-
import RadioButtonItem from './RadioButtonItem';
|
|
5
|
-
|
|
6
|
-
const RadioButtonDefault = Object.assign(
|
|
7
|
-
// @component ./RadioButton.tsx
|
|
8
|
-
RadioButtonComponent,
|
|
9
|
-
{
|
|
10
|
-
// @component ./RadioButtonGroup.tsx
|
|
11
|
-
Group: RadioButtonGroup,
|
|
12
|
-
// @component ./RadioButtonItem.tsx
|
|
13
|
-
Item: RadioButtonItem,
|
|
14
|
-
},
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
export const RadioButton = getRegisteredComponentWithFallback('RadioButton', RadioButtonDefault);
|
|
18
|
-
|
|
19
|
-
export type { Props as RadioButtonProps } from './RadioButton';
|
|
20
|
-
export type { Props as RadioButtonGroupProps } from './RadioButtonGroup';
|
|
21
|
-
export type { Props as RadioButtonItemProps } from './RadioButtonItem';
|
|
22
|
-
export { radioButtonItemStyles, radioButtonStyles } from './utils';
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import { StyleSheet } from 'react-native-unistyles';
|
|
2
|
-
|
|
3
|
-
import { getRegisteredComponentStylesWithFallback } from '../../core';
|
|
4
|
-
|
|
5
|
-
// type States = 'disabled' | 'checked' | 'hovered' | 'checkedAndHovered';
|
|
6
|
-
|
|
7
|
-
export const DEFAULT_ICON_SIZE = 24;
|
|
8
|
-
export const ANIMATION_DURATION = 100;
|
|
9
|
-
|
|
10
|
-
const radioButtonStylesDefault = StyleSheet.create(theme => ({
|
|
11
|
-
root: {
|
|
12
|
-
// color: theme.colors.onSurfaceVariant,
|
|
13
|
-
// uncheckedColor: theme.colors.onSurfaceVariant,
|
|
14
|
-
// variants: {
|
|
15
|
-
// state: {
|
|
16
|
-
// checked: {
|
|
17
|
-
// color: theme.colors.primary,
|
|
18
|
-
// },
|
|
19
|
-
// disabled: {
|
|
20
|
-
// color: theme.colors.onSurfaceDisabled,
|
|
21
|
-
// uncheckedColor: theme.colors.onSurfaceDisabled,
|
|
22
|
-
// },
|
|
23
|
-
// },
|
|
24
|
-
// },
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
container: {
|
|
28
|
-
borderRadius: theme.shapes.corner.full as unknown as number,
|
|
29
|
-
},
|
|
30
|
-
radioContainer: {
|
|
31
|
-
alignItems: 'center',
|
|
32
|
-
justifyContent: 'center',
|
|
33
|
-
},
|
|
34
|
-
radio: {
|
|
35
|
-
height: 20,
|
|
36
|
-
width: 20,
|
|
37
|
-
borderRadius: 10,
|
|
38
|
-
margin: 8,
|
|
39
|
-
borderColor: theme.colors.onSurfaceVariant,
|
|
40
|
-
|
|
41
|
-
variants: {
|
|
42
|
-
state: {
|
|
43
|
-
checked: {
|
|
44
|
-
borderColor: theme.colors.primary,
|
|
45
|
-
},
|
|
46
|
-
disabled: {
|
|
47
|
-
borderColor: theme.colors.onSurfaceDisabled,
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
dot: {
|
|
53
|
-
height: 10,
|
|
54
|
-
width: 10,
|
|
55
|
-
borderRadius: 5,
|
|
56
|
-
backgroundColor: theme.colors.onSurfaceVariant,
|
|
57
|
-
|
|
58
|
-
variants: {
|
|
59
|
-
state: {
|
|
60
|
-
checked: {
|
|
61
|
-
backgroundColor: theme.colors.primary,
|
|
62
|
-
},
|
|
63
|
-
disabled: {
|
|
64
|
-
backgroundColor: theme.colors.onSurfaceDisabled,
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
icon: {
|
|
70
|
-
backgroundColor: theme.colors.onSurfaceVariant,
|
|
71
|
-
|
|
72
|
-
variants: {
|
|
73
|
-
state: {
|
|
74
|
-
checked: {
|
|
75
|
-
backgroundColor: theme.colors.primary,
|
|
76
|
-
},
|
|
77
|
-
disabled: {
|
|
78
|
-
backgroundColor: theme.colors.onSurfaceDisabled,
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
stateLayer: {
|
|
84
|
-
variants: {
|
|
85
|
-
state: {
|
|
86
|
-
hovered: {
|
|
87
|
-
backgroundColor: theme.colors.stateLayer.hover.onSurface,
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
checkedAndHovered: {
|
|
91
|
-
backgroundColor: theme.colors.stateLayer.hover.primary,
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
}));
|
|
97
|
-
|
|
98
|
-
const radioButtonItemStylesDefault = StyleSheet.create(theme => ({
|
|
99
|
-
root: {
|
|
100
|
-
paddingVertical: theme.spacings['2'],
|
|
101
|
-
paddingHorizontal: theme.spacings['4'],
|
|
102
|
-
|
|
103
|
-
variants: {
|
|
104
|
-
state: {
|
|
105
|
-
checked: {},
|
|
106
|
-
disabled: {},
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
label: {
|
|
111
|
-
color: theme.colors.onSurface,
|
|
112
|
-
|
|
113
|
-
variants: {
|
|
114
|
-
state: {
|
|
115
|
-
checked: {},
|
|
116
|
-
disabled: {
|
|
117
|
-
color: theme.colors.onSurfaceDisabled,
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
}));
|
|
123
|
-
|
|
124
|
-
export const radioButtonStyles = getRegisteredComponentStylesWithFallback(
|
|
125
|
-
'RadioButton',
|
|
126
|
-
radioButtonStylesDefault,
|
|
127
|
-
);
|
|
128
|
-
export const radioButtonItemStyles = getRegisteredComponentStylesWithFallback(
|
|
129
|
-
'RadioButton_Item',
|
|
130
|
-
radioButtonItemStylesDefault,
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
export const handlePress = ({
|
|
134
|
-
onPress,
|
|
135
|
-
value,
|
|
136
|
-
onValueChange,
|
|
137
|
-
}: {
|
|
138
|
-
onPress?: () => void;
|
|
139
|
-
value: string;
|
|
140
|
-
onValueChange?: (value: string) => void;
|
|
141
|
-
}) => {
|
|
142
|
-
if (onPress && onValueChange) {
|
|
143
|
-
console.warn(
|
|
144
|
-
`onPress in the scope of RadioButtonGroup will not be executed, use onValueChange instead`,
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
onValueChange ? onValueChange(value) : onPress?.();
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
export const isChecked = ({
|
|
152
|
-
value,
|
|
153
|
-
status,
|
|
154
|
-
contextValue,
|
|
155
|
-
}: {
|
|
156
|
-
value: string;
|
|
157
|
-
status?: 'checked' | 'unchecked';
|
|
158
|
-
contextValue?: string;
|
|
159
|
-
}) => {
|
|
160
|
-
if (contextValue !== undefined && contextValue !== null) {
|
|
161
|
-
return contextValue === value ? 'checked' : 'unchecked';
|
|
162
|
-
} else {
|
|
163
|
-
return status;
|
|
164
|
-
}
|
|
165
|
-
};
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { forwardRef, memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import type { BlurEvent, FocusEvent } from 'react-native';
|
|
3
|
-
|
|
4
|
-
import { useToggle } from '../../hooks';
|
|
5
|
-
import { IconButton, type IconButtonProps } from '../IconButton';
|
|
6
|
-
import { TextInput, type TextInputProps } from '../TextInput';
|
|
7
|
-
import type { TimePickerModalProps } from '../TimePickerModal';
|
|
8
|
-
import { TimePickerModal } from '../TimePickerModal/TimePickerModal';
|
|
9
|
-
import { sanitizeTime } from './sanitizeTime';
|
|
10
|
-
import { getFormattedTime, getOutputTime, styles, timeFormat } from './utils';
|
|
11
|
-
|
|
12
|
-
export type Props = TextInputProps & {
|
|
13
|
-
time: string;
|
|
14
|
-
onTimeChange: (time: string) => void;
|
|
15
|
-
is24Hour?: boolean;
|
|
16
|
-
withModal?: boolean;
|
|
17
|
-
modalProps?: Omit<TimePickerModalProps, 'time' | 'onConfirm' | 'isOpen' | 'onClose' | 'ref'>;
|
|
18
|
-
iconButtonProps?: Omit<Partial<IconButtonProps>, 'onPress' | 'ref'>;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const TimePickerField = (
|
|
22
|
-
{
|
|
23
|
-
time,
|
|
24
|
-
onTimeChange: onTimeChangeProp,
|
|
25
|
-
is24Hour = false,
|
|
26
|
-
withModal = true,
|
|
27
|
-
style,
|
|
28
|
-
onBlur: onBlurProp,
|
|
29
|
-
modalProps = {},
|
|
30
|
-
iconButtonProps = {},
|
|
31
|
-
disabled,
|
|
32
|
-
onFocus: onFocusProp,
|
|
33
|
-
...rest
|
|
34
|
-
}: Props,
|
|
35
|
-
ref: any,
|
|
36
|
-
) => {
|
|
37
|
-
const componentStyles = useMemo(() => [styles.root, style], [style]);
|
|
38
|
-
|
|
39
|
-
const [timeString, setTimeString] = useState(() => getFormattedTime({ time, is24Hour }));
|
|
40
|
-
const isBlurredRef = useRef(true);
|
|
41
|
-
|
|
42
|
-
const currentTimeFormat = useMemo(() => timeFormat[!is24Hour ? '12' : '24'], [is24Hour]);
|
|
43
|
-
|
|
44
|
-
const { state: isOpen, handleOpen: onOpenModal, handleClose: onCloseModal } = useToggle(false);
|
|
45
|
-
|
|
46
|
-
const onChangeText = useCallback(
|
|
47
|
-
(_text: string) => {
|
|
48
|
-
const text = sanitizeTime(_text, is24Hour);
|
|
49
|
-
setTimeString(_text);
|
|
50
|
-
|
|
51
|
-
if (disabled || !text) return;
|
|
52
|
-
|
|
53
|
-
const outputTime = getOutputTime({ time: text || time, is24Hour });
|
|
54
|
-
|
|
55
|
-
onTimeChangeProp(outputTime);
|
|
56
|
-
},
|
|
57
|
-
[disabled, is24Hour, onTimeChangeProp, time],
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
const onConfirmTime = useCallback(
|
|
61
|
-
(newTime: string) => {
|
|
62
|
-
onCloseModal();
|
|
63
|
-
|
|
64
|
-
onTimeChangeProp(newTime);
|
|
65
|
-
},
|
|
66
|
-
[onTimeChangeProp, onCloseModal],
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
const onBlur = useCallback(
|
|
70
|
-
(e: BlurEvent) => {
|
|
71
|
-
isBlurredRef.current = true;
|
|
72
|
-
onBlurProp?.(e);
|
|
73
|
-
|
|
74
|
-
if (disabled) return;
|
|
75
|
-
|
|
76
|
-
// const outputTime = getOutputTime({ time: timeString || time, is24Hour });
|
|
77
|
-
// onTimeChangeProp(outputTime);
|
|
78
|
-
|
|
79
|
-
// if (time === outputTime) {
|
|
80
|
-
setTimeString(sanitizeTime(getFormattedTime({ time, is24Hour }), is24Hour));
|
|
81
|
-
// }
|
|
82
|
-
},
|
|
83
|
-
[disabled, is24Hour, onBlurProp, time],
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
const onFocus = useCallback(
|
|
87
|
-
(e: FocusEvent) => {
|
|
88
|
-
isBlurredRef.current = false;
|
|
89
|
-
|
|
90
|
-
onFocusProp?.(e);
|
|
91
|
-
},
|
|
92
|
-
[onFocusProp],
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
const rightElement = useMemo(() => {
|
|
96
|
-
if (!withModal) return null;
|
|
97
|
-
|
|
98
|
-
return (
|
|
99
|
-
<>
|
|
100
|
-
<IconButton
|
|
101
|
-
name="clock-outline"
|
|
102
|
-
onPress={onOpenModal}
|
|
103
|
-
disabled={disabled}
|
|
104
|
-
{...iconButtonProps}
|
|
105
|
-
/>
|
|
106
|
-
<TimePickerModal
|
|
107
|
-
{...modalProps}
|
|
108
|
-
time={getFormattedTime({ time: time, is24Hour: true })}
|
|
109
|
-
isOpen={isOpen}
|
|
110
|
-
onClose={onCloseModal}
|
|
111
|
-
onConfirm={onConfirmTime}
|
|
112
|
-
is24Hour={is24Hour}
|
|
113
|
-
/>
|
|
114
|
-
</>
|
|
115
|
-
);
|
|
116
|
-
}, [
|
|
117
|
-
disabled,
|
|
118
|
-
iconButtonProps,
|
|
119
|
-
is24Hour,
|
|
120
|
-
isOpen,
|
|
121
|
-
modalProps,
|
|
122
|
-
onCloseModal,
|
|
123
|
-
onConfirmTime,
|
|
124
|
-
onOpenModal,
|
|
125
|
-
time,
|
|
126
|
-
withModal,
|
|
127
|
-
]);
|
|
128
|
-
|
|
129
|
-
// only change masked string when the input is not focus so as to not interrup the user
|
|
130
|
-
useEffect(() => {
|
|
131
|
-
if (!isBlurredRef.current) return;
|
|
132
|
-
|
|
133
|
-
setTimeString(getFormattedTime({ time, is24Hour }));
|
|
134
|
-
}, [is24Hour, time]);
|
|
135
|
-
|
|
136
|
-
return (
|
|
137
|
-
<TextInput
|
|
138
|
-
ref={ref}
|
|
139
|
-
placeholder={currentTimeFormat.format}
|
|
140
|
-
{...rest}
|
|
141
|
-
disabled={disabled}
|
|
142
|
-
value={timeString}
|
|
143
|
-
onFocus={onFocus}
|
|
144
|
-
onChangeText={onChangeText}
|
|
145
|
-
style={componentStyles}
|
|
146
|
-
onBlur={onBlur}
|
|
147
|
-
right={rightElement}
|
|
148
|
-
/>
|
|
149
|
-
);
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
export default memo(forwardRef(TimePickerField));
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { getRegisteredComponentWithFallback } from '../../core';
|
|
2
|
-
import TimePickerFieldDefault from './TimePickerField';
|
|
3
|
-
|
|
4
|
-
export const TimePickerField = getRegisteredComponentWithFallback(
|
|
5
|
-
'TimePickerField',
|
|
6
|
-
TimePickerFieldDefault,
|
|
7
|
-
);
|
|
8
|
-
|
|
9
|
-
export { type Props as TimePickerFieldProps } from './TimePickerField';
|
|
10
|
-
export { sanitizeTimeString, styles } from './utils';
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { format, parse, set } from 'date-fns';
|
|
2
|
-
import { StyleSheet } from 'react-native-unistyles';
|
|
3
|
-
|
|
4
|
-
export declare type MaskItem = string | RegExp | [RegExp];
|
|
5
|
-
export declare type MaskArray = Array<MaskItem>;
|
|
6
|
-
export declare type Mask = MaskArray | ((value?: string) => MaskArray);
|
|
7
|
-
|
|
8
|
-
import { getRegisteredComponentStylesWithFallback } from '../../core';
|
|
9
|
-
|
|
10
|
-
const timepickerFieldStylesDefault = StyleSheet.create({
|
|
11
|
-
root: {},
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
export const styles = getRegisteredComponentStylesWithFallback(
|
|
15
|
-
'TimePickerField',
|
|
16
|
-
timepickerFieldStylesDefault,
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
export const timeMask24Hour: Mask = (text: string = '') => {
|
|
20
|
-
const cleanTime = text.replace(/\D+/g, '');
|
|
21
|
-
|
|
22
|
-
const hourFirstDigit = /[012]/; // only 0,1 or 2
|
|
23
|
-
let hourSecondDigit = /\d/; // any number
|
|
24
|
-
|
|
25
|
-
if (cleanTime.charAt(0) === '2') {
|
|
26
|
-
hourSecondDigit = /[0123]/; // only 0,1,2 or 3
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const minuteFirstDigit = /[012345]/; // only 0,1,2,3,4 or 5
|
|
30
|
-
const minuteSecondDigit = /\d/; // any number
|
|
31
|
-
|
|
32
|
-
return [hourFirstDigit, hourSecondDigit, ':', minuteFirstDigit, minuteSecondDigit];
|
|
33
|
-
};
|
|
34
|
-
export const timeMask12Hour: Mask = (text: string = '') => {
|
|
35
|
-
const cleanTime = text.replace(/\D+/g, '');
|
|
36
|
-
|
|
37
|
-
const hourFirstDigit = /[01]/; // only 0,1 or 2
|
|
38
|
-
let hourSecondDigit = /\d/; // any number
|
|
39
|
-
|
|
40
|
-
if (cleanTime.charAt(0) === '1') {
|
|
41
|
-
hourSecondDigit = /[012]/; // only 0,1,2 or 3
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const minuteFirstDigit = /[012345]/; // only 0,1,2,3,4 or 5
|
|
45
|
-
const minuteSecondDigit = /\d/; // any number
|
|
46
|
-
|
|
47
|
-
return [hourFirstDigit, hourSecondDigit, ':', minuteFirstDigit, minuteSecondDigit, /[ap]/, 'm'];
|
|
48
|
-
};
|
|
49
|
-
export const timeFormat = {
|
|
50
|
-
'24': {
|
|
51
|
-
format: 'HH:mm',
|
|
52
|
-
mask: timeMask24Hour,
|
|
53
|
-
},
|
|
54
|
-
'12': {
|
|
55
|
-
format: 'hh:mmaaa',
|
|
56
|
-
mask: timeMask12Hour,
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const referenceDate = new Date('2022-01-01T00:00:00.000Z');
|
|
61
|
-
|
|
62
|
-
export const sanitizeTimeString = (time: string): string => time.replace(/[^\d:]/g, '');
|
|
63
|
-
|
|
64
|
-
export const getFormattedTime = ({ time, is24Hour }: { time: string; is24Hour: boolean }) => {
|
|
65
|
-
if (!time) {
|
|
66
|
-
return '';
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const [hour = '0', minute = '0'] = sanitizeTimeString(time).split(':');
|
|
70
|
-
|
|
71
|
-
const newHour = hour.padStart(2, '0');
|
|
72
|
-
const newMinute = minute.padStart(2, '0');
|
|
73
|
-
|
|
74
|
-
return format(
|
|
75
|
-
set(referenceDate, { hours: +newHour, minutes: +newMinute }),
|
|
76
|
-
timeFormat[is24Hour ? '24' : '12'].format,
|
|
77
|
-
);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export const getOutputTime = ({ time, is24Hour }: { time: string; is24Hour: boolean }) => {
|
|
81
|
-
if (!time) return '';
|
|
82
|
-
|
|
83
|
-
const formattedTime = sanitizeTimeString(getFormattedTime({ time, is24Hour }));
|
|
84
|
-
const isPM = time.replace(/[\d:]/g, '').includes('p');
|
|
85
|
-
|
|
86
|
-
return format(
|
|
87
|
-
parse(
|
|
88
|
-
formattedTime + (is24Hour ? '' : isPM ? 'pm' : 'am'),
|
|
89
|
-
timeFormat[is24Hour ? '24' : '12'].format,
|
|
90
|
-
referenceDate,
|
|
91
|
-
),
|
|
92
|
-
'HH:mm',
|
|
93
|
-
);
|
|
94
|
-
};
|