react-native-molecules 0.5.0-beta.0
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 +89 -0
- package/components/Accordion/AccordionItem.tsx +94 -0
- package/components/Accordion/AccordionItemContent.tsx +17 -0
- package/components/Accordion/AccordionItemHeader.tsx +122 -0
- package/components/Accordion/index.tsx +36 -0
- package/components/Accordion/utils.ts +62 -0
- package/components/ActivityIndicator/ActivityIndicator.ios.tsx +1 -0
- package/components/ActivityIndicator/ActivityIndicator.tsx +200 -0
- package/components/ActivityIndicator/AnimatedSpinner.tsx +121 -0
- package/components/ActivityIndicator/index.tsx +17 -0
- package/components/Appbar/AppbarActions.tsx +13 -0
- package/components/Appbar/AppbarBase.tsx +60 -0
- package/components/Appbar/AppbarCenterAligned.tsx +13 -0
- package/components/Appbar/AppbarLarge.tsx +13 -0
- package/components/Appbar/AppbarLeft.tsx +26 -0
- package/components/Appbar/AppbarMedium.tsx +13 -0
- package/components/Appbar/AppbarRight.tsx +40 -0
- package/components/Appbar/AppbarSmall.tsx +13 -0
- package/components/Appbar/AppbarTitle.tsx +49 -0
- package/components/Appbar/index.tsx +46 -0
- package/components/Appbar/types.ts +19 -0
- package/components/Appbar/utils.ts +127 -0
- package/components/Avatar/Avatar.tsx +189 -0
- package/components/Avatar/index.tsx +11 -0
- package/components/Avatar/utils.ts +35 -0
- package/components/Backdrop/Backdrop.tsx +18 -0
- package/components/Backdrop/index.tsx +11 -0
- package/components/Backdrop/types.ts +3 -0
- package/components/Backdrop/utils.ts +21 -0
- package/components/Badge/Badge.tsx +29 -0
- package/components/Badge/index.tsx +11 -0
- package/components/Badge/utils.ts +38 -0
- package/components/Button/Button.tsx +349 -0
- package/components/Button/index.tsx +11 -0
- package/components/Button/types.ts +5 -0
- package/components/Button/utils.ts +416 -0
- package/components/Card/Card.tsx +160 -0
- package/components/Card/CardActions.tsx +18 -0
- package/components/Card/CardContent.tsx +29 -0
- package/components/Card/CardHeader.tsx +31 -0
- package/components/Card/CardHeadline.tsx +15 -0
- package/components/Card/CardMedia.tsx +36 -0
- package/components/Card/CardSubhead.tsx +15 -0
- package/components/Card/CardText.tsx +13 -0
- package/components/Card/CardTypography.tsx +113 -0
- package/components/Card/index.tsx +38 -0
- package/components/Card/types.ts +1 -0
- package/components/Card/utils.ts +23 -0
- package/components/Checkbox/Checkbox.tsx +123 -0
- package/components/Checkbox/CheckboxBase.ios.tsx +86 -0
- package/components/Checkbox/CheckboxBase.tsx +216 -0
- package/components/Checkbox/index.tsx +11 -0
- package/components/Checkbox/types.ts +72 -0
- package/components/Checkbox/utils.ts +210 -0
- package/components/Chip/Chip.tsx +416 -0
- package/components/Chip/index.tsx +51 -0
- package/components/Chip/utils.ts +100 -0
- package/components/DatePickerDocked/DatePickerDocked.tsx +30 -0
- package/components/DatePickerDocked/DatePickerDockedHeader.tsx +129 -0
- package/components/DatePickerDocked/index.tsx +21 -0
- package/components/DatePickerDocked/types.ts +11 -0
- package/components/DatePickerDocked/utils.ts +155 -0
- package/components/DatePickerInline/AutoSizer.tsx +46 -0
- package/components/DatePickerInline/DatePickerContext.tsx +21 -0
- package/components/DatePickerInline/DatePickerInline.tsx +82 -0
- package/components/DatePickerInline/DatePickerInlineBase.tsx +181 -0
- package/components/DatePickerInline/DatePickerInlineHeader.tsx +108 -0
- package/components/DatePickerInline/Day.tsx +88 -0
- package/components/DatePickerInline/DayName.tsx +17 -0
- package/components/DatePickerInline/DayNames.tsx +32 -0
- package/components/DatePickerInline/DayRange.tsx +48 -0
- package/components/DatePickerInline/HeaderItem.tsx +111 -0
- package/components/DatePickerInline/Month.tsx +233 -0
- package/components/DatePickerInline/MonthPicker.tsx +174 -0
- package/components/DatePickerInline/Swiper.native.tsx +172 -0
- package/components/DatePickerInline/Swiper.tsx +172 -0
- package/components/DatePickerInline/SwiperUtils.ts +40 -0
- package/components/DatePickerInline/Week.tsx +67 -0
- package/components/DatePickerInline/YearPicker.tsx +139 -0
- package/components/DatePickerInline/dateUtils.tsx +334 -0
- package/components/DatePickerInline/index.tsx +41 -0
- package/components/DatePickerInline/types.ts +104 -0
- package/components/DatePickerInline/utils.ts +367 -0
- package/components/DatePickerInput/DatePickerInput.tsx +139 -0
- package/components/DatePickerInput/DatePickerInputModal.tsx +48 -0
- package/components/DatePickerInput/DatePickerInputWithoutModal.tsx +77 -0
- package/components/DatePickerInput/DateRangeInput.tsx +88 -0
- package/components/DatePickerInput/index.tsx +14 -0
- package/components/DatePickerInput/inputUtils.ts +138 -0
- package/components/DatePickerInput/types.ts +28 -0
- package/components/DatePickerInput/utils.ts +16 -0
- package/components/DatePickerModal/AnimatedCrossView.tsx +94 -0
- package/components/DatePickerModal/CalendarEdit.tsx +139 -0
- package/components/DatePickerModal/DatePickerModal.tsx +85 -0
- package/components/DatePickerModal/DatePickerModalContent.tsx +155 -0
- package/components/DatePickerModal/DatePickerModalContentHeader.tsx +213 -0
- package/components/DatePickerModal/DatePickerModalHeader.tsx +74 -0
- package/components/DatePickerModal/DatePickerModalHeaderBackground.tsx +13 -0
- package/components/DatePickerModal/index.tsx +20 -0
- package/components/DatePickerModal/types.ts +92 -0
- package/components/DatePickerModal/utils.ts +121 -0
- package/components/DateTimePicker/DateTimePicker.tsx +172 -0
- package/components/DateTimePicker/index.tsx +14 -0
- package/components/DateTimePicker/utils.ts +13 -0
- package/components/Dialog/Dialog.tsx +66 -0
- package/components/Dialog/DialogActions.tsx +89 -0
- package/components/Dialog/DialogContent.tsx +37 -0
- package/components/Dialog/DialogIcon.tsx +69 -0
- package/components/Dialog/DialogTitle.tsx +68 -0
- package/components/Dialog/index.tsx +37 -0
- package/components/Dialog/utils.ts +80 -0
- package/components/Drawer/Collapsible/DrawerCollapsible.tsx +22 -0
- package/components/Drawer/Collapsible/DrawerCollapsibleItem.tsx +38 -0
- package/components/Drawer/Collapsible/DrawerCollapsibleItemContent.tsx +16 -0
- package/components/Drawer/Collapsible/DrawerCollapsibleItemHeader.tsx +48 -0
- package/components/Drawer/Collapsible/index.tsx +23 -0
- package/components/Drawer/Collapsible/utils.ts +49 -0
- package/components/Drawer/Drawer.tsx +43 -0
- package/components/Drawer/DrawerContent.tsx +35 -0
- package/components/Drawer/DrawerFooter.tsx +27 -0
- package/components/Drawer/DrawerHeader.tsx +27 -0
- package/components/Drawer/DrawerItem.tsx +206 -0
- package/components/Drawer/DrawerItemGroup.tsx +82 -0
- package/components/Drawer/index.tsx +47 -0
- package/components/Drawer/types.ts +3 -0
- package/components/Drawer/utils.ts +8 -0
- package/components/ElementGroup/ElementGroup.tsx +139 -0
- package/components/ElementGroup/index.tsx +11 -0
- package/components/ElementGroup/utils.ts +25 -0
- package/components/FAB/FAB.tsx +176 -0
- package/components/FAB/index.tsx +12 -0
- package/components/FAB/types.ts +1 -0
- package/components/FAB/utils.ts +221 -0
- package/components/FilePicker/FilePicker.tsx +133 -0
- package/components/FilePicker/index.tsx +11 -0
- package/components/FilePicker/utils.ts +13 -0
- package/components/HelperText/HelperText.tsx +139 -0
- package/components/HelperText/index.tsx +11 -0
- package/components/HelperText/utils.ts +29 -0
- package/components/HorizontalDivider/HorizontalDivider.tsx +101 -0
- package/components/HorizontalDivider/index.tsx +13 -0
- package/components/Icon/CrossFadeIcon.tsx +116 -0
- package/components/Icon/Icon.tsx +41 -0
- package/components/Icon/iconFactory.tsx +23 -0
- package/components/Icon/index.tsx +11 -0
- package/components/Icon/types.ts +35 -0
- package/components/IconButton/IconButton.tsx +218 -0
- package/components/IconButton/index.tsx +11 -0
- package/components/IconButton/types.ts +1 -0
- package/components/IconButton/utils.ts +325 -0
- package/components/If/index.tsx +13 -0
- package/components/InputAddon/InputAddon.tsx +27 -0
- package/components/InputAddon/index.tsx +11 -0
- package/components/InputAddon/utils.ts +33 -0
- package/components/Link/Link.tsx +48 -0
- package/components/Link/index.tsx +11 -0
- package/components/Link/utils.ts +37 -0
- package/components/ListItem/ListItem.tsx +136 -0
- package/components/ListItem/ListItemDescription.tsx +25 -0
- package/components/ListItem/ListItemTitle.tsx +25 -0
- package/components/ListItem/index.tsx +18 -0
- package/components/ListItem/utils.ts +113 -0
- package/components/Menu/Menu.tsx +69 -0
- package/components/Menu/MenuDivider.tsx +13 -0
- package/components/Menu/MenuItem.tsx +128 -0
- package/components/Menu/index.tsx +19 -0
- package/components/Menu/utils.ts +92 -0
- package/components/Modal/Modal.tsx +261 -0
- package/components/Modal/index.tsx +11 -0
- package/components/Modal/utils.ts +45 -0
- package/components/NavigationRail/NavigationRail.tsx +32 -0
- package/components/NavigationRail/NavigationRailContent.tsx +25 -0
- package/components/NavigationRail/NavigationRailFooter.tsx +18 -0
- package/components/NavigationRail/NavigationRailHeader.tsx +18 -0
- package/components/NavigationRail/NavigationRailItem.tsx +226 -0
- package/components/NavigationRail/index.tsx +35 -0
- package/components/NavigationRail/utils.ts +170 -0
- package/components/NavigationStack/NavigationStack.tsx +85 -0
- package/components/NavigationStack/NavigationStackItem.tsx +60 -0
- package/components/NavigationStack/index.tsx +20 -0
- package/components/NavigationStack/utils.tsx +16 -0
- package/components/Popover/Popover.native.tsx +185 -0
- package/components/Popover/Popover.tsx +198 -0
- package/components/Popover/common.ts +459 -0
- package/components/Popover/index.ts +2 -0
- package/components/Portal/Portal.tsx +13 -0
- package/components/Portal/index.tsx +12 -0
- package/components/RadioButton/RadioButton.tsx +138 -0
- package/components/RadioButton/RadioButtonAndroid.tsx +188 -0
- package/components/RadioButton/RadioButtonGroup.tsx +98 -0
- package/components/RadioButton/RadioButtonIOS.tsx +106 -0
- package/components/RadioButton/RadioButtonItem.tsx +232 -0
- package/components/RadioButton/index.ts +27 -0
- package/components/RadioButton/utils.ts +164 -0
- package/components/Rating/Rating.tsx +149 -0
- package/components/Rating/RatingItem.tsx +125 -0
- package/components/Rating/index.tsx +13 -0
- package/components/Rating/utils.ts +38 -0
- package/components/Select/Select.tsx +1038 -0
- package/components/Select/index.ts +14 -0
- package/components/Select/types.ts +115 -0
- package/components/StateLayer/StateLayer.tsx +12 -0
- package/components/StateLayer/index.tsx +11 -0
- package/components/StateLayer/utils.ts +17 -0
- package/components/Surface/BackgroundContextWrapper.tsx +27 -0
- package/components/Surface/Surface.android.tsx +62 -0
- package/components/Surface/Surface.ios.tsx +123 -0
- package/components/Surface/Surface.tsx +48 -0
- package/components/Surface/index.tsx +12 -0
- package/components/Surface/utils.ts +106 -0
- package/components/Switch/Switch.ios.tsx +67 -0
- package/components/Switch/Switch.tsx +278 -0
- package/components/Switch/index.tsx +11 -0
- package/components/Switch/utils.ts +283 -0
- package/components/Tabs/TabItem.tsx +150 -0
- package/components/Tabs/TabLabel.tsx +84 -0
- package/components/Tabs/Tabs.tsx +398 -0
- package/components/Tabs/index.tsx +21 -0
- package/components/Tabs/utils.ts +126 -0
- package/components/Text/Text.tsx +23 -0
- package/components/Text/index.tsx +2 -0
- package/components/Text/textFactory.tsx +33 -0
- package/components/TextInput/InputLabel.tsx +181 -0
- package/components/TextInput/TextInput.tsx +693 -0
- package/components/TextInput/index.tsx +16 -0
- package/components/TextInput/types.ts +96 -0
- package/components/TextInput/utils.ts +544 -0
- package/components/TextInputWithMask/TextInputMask.tsx +57 -0
- package/components/TextInputWithMask/index.tsx +11 -0
- package/components/TextInputWithMask/utils.ts +56 -0
- package/components/TimePicker/AmPmSwitcher.tsx +99 -0
- package/components/TimePicker/AnalogClock.tsx +165 -0
- package/components/TimePicker/AnalogClockHours.tsx +163 -0
- package/components/TimePicker/AnalogClockMinutes.tsx +68 -0
- package/components/TimePicker/AnimatedClockSwitcher.tsx +72 -0
- package/components/TimePicker/DisplayModeContext.tsx +6 -0
- package/components/TimePicker/TimeInput.tsx +112 -0
- package/components/TimePicker/TimeInputs.tsx +148 -0
- package/components/TimePicker/TimePicker.tsx +130 -0
- package/components/TimePicker/index.tsx +19 -0
- package/components/TimePicker/timeUtils.ts +159 -0
- package/components/TimePicker/utils.ts +285 -0
- package/components/TimePickerField/TimePickerField.tsx +152 -0
- package/components/TimePickerField/index.tsx +14 -0
- package/components/TimePickerField/sanitizeTime.ts +85 -0
- package/components/TimePickerField/utils.ts +95 -0
- package/components/TimePickerModal/TimePickerModal.tsx +115 -0
- package/components/TimePickerModal/index.tsx +14 -0
- package/components/TimePickerModal/utils.ts +48 -0
- package/components/Tooltip/Tooltip.tsx +137 -0
- package/components/Tooltip/TooltipContent.tsx +12 -0
- package/components/Tooltip/TooltipTrigger.tsx +94 -0
- package/components/Tooltip/index.tsx +20 -0
- package/components/Tooltip/utils.ts +21 -0
- package/components/TouchableRipple/TouchableRipple.native.tsx +105 -0
- package/components/TouchableRipple/TouchableRipple.tsx +286 -0
- package/components/TouchableRipple/index.tsx +14 -0
- package/components/TouchableRipple/utils.ts +15 -0
- package/components/VerticalDivider/VerticalDivider.tsx +99 -0
- package/components/VerticalDivider/index.tsx +13 -0
- package/context-bridge/index.tsx +87 -0
- package/core/componentsRegistry.ts +164 -0
- package/core/index.tsx +2 -0
- package/fast-context/index.tsx +190 -0
- package/hocs/index.tsx +5 -0
- package/hocs/typedMemo.tsx +5 -0
- package/hocs/withKeyboardAccessibility.tsx +231 -0
- package/hocs/withPortal.tsx +16 -0
- package/hooks/createPsuedoHook.tsx +50 -0
- package/hooks/index.tsx +29 -0
- package/hooks/useActionState.native.tsx +22 -0
- package/hooks/useActionState.tsx +34 -0
- package/hooks/useActive.tsx +5 -0
- package/hooks/useBreakpoints.tsx +7 -0
- package/hooks/useColorMode.tsx +17 -0
- package/hooks/useContrastColor.ts +15 -0
- package/hooks/useControlledValue.tsx +68 -0
- package/hooks/useFilePicker.tsx +48 -0
- package/hooks/useFocus.tsx +5 -0
- package/hooks/useHandleNumberFormat.tsx +106 -0
- package/hooks/useHover.tsx +5 -0
- package/hooks/useKeyboardDismissable.ts +66 -0
- package/hooks/useLatest.tsx +9 -0
- package/hooks/useMediaQuery.tsx +64 -0
- package/hooks/useMergedRefs.ts +14 -0
- package/hooks/usePrevious.ts +13 -0
- package/hooks/useQueryFilter.tsx +35 -0
- package/hooks/useSearchable.tsx +74 -0
- package/hooks/useSubcomponents.tsx +59 -0
- package/hooks/useTheme.ts +3 -0
- package/hooks/useToggle.tsx +24 -0
- package/package.json +114 -0
- package/shortcuts-manager/EventsManager.tsx +121 -0
- package/shortcuts-manager/ShortcutsManager/ShortcutsManager.native.tsx +9 -0
- package/shortcuts-manager/ShortcutsManager/ShortcutsManager.tsx +58 -0
- package/shortcuts-manager/ShortcutsManager/index.tsx +2 -0
- package/shortcuts-manager/ShortcutsManager/utils.tsx +30 -0
- package/shortcuts-manager/index.tsx +6 -0
- package/shortcuts-manager/types.ts +24 -0
- package/shortcuts-manager/useIsKeyPressed/index.tsx +1 -0
- package/shortcuts-manager/useIsKeyPressed/useIsKeyPress.tsx +9 -0
- package/shortcuts-manager/useSetScopes/index.tsx +1 -0
- package/shortcuts-manager/useSetScopes/useSetScopes.native.tsx +9 -0
- package/shortcuts-manager/useSetScopes/useSetScopes.tsx +25 -0
- package/shortcuts-manager/useShortcut/index.tsx +2 -0
- package/shortcuts-manager/useShortcut/types.ts +3 -0
- package/shortcuts-manager/useShortcut/useShortcut.native.tsx +9 -0
- package/shortcuts-manager/useShortcut/useShortcut.tsx +61 -0
- package/shortcuts-manager/utils.ts +105 -0
- package/styles/index.ts +4 -0
- package/styles/overlay.ts +69 -0
- package/styles/shadow.ts +21 -0
- package/styles/themes/DarkTheme.tsx +98 -0
- package/styles/themes/LightTheme.tsx +212 -0
- package/styles/themes/tokens.ts +248 -0
- package/styles/utils.ts +11 -0
- package/types/index.ts +129 -0
- package/types/theme.ts +159 -0
- package/utils/DocumentPicker/documentPicker.native.ts +10 -0
- package/utils/DocumentPicker/documentPicker.ts +76 -0
- package/utils/DocumentPicker/index.ts +2 -0
- package/utils/DocumentPicker/types.ts +28 -0
- package/utils/addEventListener.tsx +51 -0
- package/utils/backgroundContext.ts +9 -0
- package/utils/color.ts +22 -0
- package/utils/compare/index.ts +54 -0
- package/utils/composeEventHandlers.ts +9 -0
- package/utils/createNumberMask/createNumberMask.ts +98 -0
- package/utils/createNumberMask/index.ts +5 -0
- package/utils/createSyntheticEvent.ts +31 -0
- package/utils/date-fns.ts +7 -0
- package/utils/dateTimePicker.ts +5 -0
- package/utils/escapeRegex.ts +9 -0
- package/utils/extractTextStyles.ts +52 -0
- package/utils/formatNumberWithMask/formatNumberWithMask.ts +26 -0
- package/utils/formatNumberWithMask/formatWithMask.ts +119 -0
- package/utils/formatNumberWithMask/index.ts +6 -0
- package/utils/getCursorStyle/getCursorStyle.native.ts +1 -0
- package/utils/getCursorStyle/getCursorStyle.ts +1 -0
- package/utils/getCursorStyle/index.ts +1 -0
- package/utils/getOS/getOS.native.ts +7 -0
- package/utils/getOS/getOS.ts +24 -0
- package/utils/getOS/index.ts +1 -0
- package/utils/getyearRange.ts +5 -0
- package/utils/index.ts +20 -0
- package/utils/lodash.ts +50 -0
- package/utils/mergeRefs.ts +13 -0
- package/utils/normalizeBorderRadiuses.ts +24 -0
- package/utils/normalizeSpacings.ts +110 -0
- package/utils/normalizeToNumberString/index.ts +4 -0
- package/utils/normalizeToNumberString/normalizeToNumberString.ts +48 -0
- package/utils/repository.ts +103 -0
- package/utils/resolveColorMode.ts +9 -0
- package/utils/resolveStateVariant.ts +26 -0
- package/utils/tokenStylesParser.ts +7 -0
package/types/index.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { ComponentPropsWithoutRef, ComponentType } from 'react';
|
|
2
|
+
import type { StyleProp } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export * from './theme';
|
|
5
|
+
|
|
6
|
+
export type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
7
|
+
|
|
8
|
+
export type DeepPartial<T> = T extends object
|
|
9
|
+
? {
|
|
10
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
11
|
+
}
|
|
12
|
+
: T;
|
|
13
|
+
|
|
14
|
+
export type $Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
15
|
+
|
|
16
|
+
export type $RemoveChildren<T extends ComponentType<any>> = $Omit<
|
|
17
|
+
ComponentPropsWithoutRef<T>,
|
|
18
|
+
'children'
|
|
19
|
+
>;
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
* T stands for ComponentStyle type eg. ViewStyl
|
|
23
|
+
* C stands for Customer Properties
|
|
24
|
+
* S stands for ComponentStates
|
|
25
|
+
* */
|
|
26
|
+
export type ComponentStyleProp<T, C = {}> = StyleProp<T> & C;
|
|
27
|
+
|
|
28
|
+
export type ComponentStylePropWithResolvers<
|
|
29
|
+
T,
|
|
30
|
+
S extends ComponentState,
|
|
31
|
+
C = {},
|
|
32
|
+
Z = {},
|
|
33
|
+
> = ComponentStyleProp<T, C> & {
|
|
34
|
+
states?: {
|
|
35
|
+
[key in S]?: ComponentStyleProp<T, C>;
|
|
36
|
+
};
|
|
37
|
+
sizes?: {
|
|
38
|
+
[key: string]: ComponentSize<Z>;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type ComponentStylePropWithVariants<
|
|
43
|
+
T,
|
|
44
|
+
S extends ComponentState = ComponentState,
|
|
45
|
+
C = {},
|
|
46
|
+
Z = {},
|
|
47
|
+
> = ComponentStylePropWithResolvers<T, S, C, Z> & {
|
|
48
|
+
variants?: {
|
|
49
|
+
[key: string]: ComponentStylePropWithResolvers<T, S, C, Z>;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type ComponentState =
|
|
54
|
+
| 'selected_disabled'
|
|
55
|
+
| 'selected'
|
|
56
|
+
| 'disabled'
|
|
57
|
+
| 'hovered'
|
|
58
|
+
| 'focused'
|
|
59
|
+
| 'pressed'
|
|
60
|
+
| string;
|
|
61
|
+
|
|
62
|
+
export type ComponentSize<Z = {}> = Z & {
|
|
63
|
+
margin?: number | string;
|
|
64
|
+
marginBottom?: number | string;
|
|
65
|
+
marginEnd?: number | string;
|
|
66
|
+
marginHorizontal?: number | string;
|
|
67
|
+
marginLeft?: number | string;
|
|
68
|
+
marginRight?: number | string;
|
|
69
|
+
marginStart?: number | string;
|
|
70
|
+
marginTop?: number | string;
|
|
71
|
+
marginVertical?: number | string;
|
|
72
|
+
|
|
73
|
+
padding?: number | string;
|
|
74
|
+
paddingBottom?: number | string;
|
|
75
|
+
paddingEnd?: number | string;
|
|
76
|
+
paddingHorizontal?: number | string;
|
|
77
|
+
paddingLeft?: number | string;
|
|
78
|
+
paddingRight?: number | string;
|
|
79
|
+
paddingStart?: number | string;
|
|
80
|
+
paddingTop?: number | string;
|
|
81
|
+
paddingVertical?: number | string;
|
|
82
|
+
|
|
83
|
+
maxHeight?: number | string;
|
|
84
|
+
maxWidth?: number | string;
|
|
85
|
+
minHeight?: number | string;
|
|
86
|
+
minWidth?: number | string;
|
|
87
|
+
height?: number | string;
|
|
88
|
+
width?: number | string;
|
|
89
|
+
|
|
90
|
+
borderBottomWidth?: number | string;
|
|
91
|
+
borderEndWidth?: number | string;
|
|
92
|
+
borderLeftWidth?: number | string;
|
|
93
|
+
borderRightWidth?: number | string;
|
|
94
|
+
borderStartWidth?: number | string;
|
|
95
|
+
borderTopWidth?: number | string;
|
|
96
|
+
borderWidth?: number | string;
|
|
97
|
+
|
|
98
|
+
borderBottomEndRadius?: number | string;
|
|
99
|
+
borderBottomLeftRadius?: number | string;
|
|
100
|
+
borderBottomRightRadius?: number | string;
|
|
101
|
+
borderBottomStartRadius?: number | string;
|
|
102
|
+
borderRadius?: number | string;
|
|
103
|
+
borderTopEndRadius?: number | string;
|
|
104
|
+
borderTopLeftRadius?: number | string;
|
|
105
|
+
borderTopRightRadius?: number | string;
|
|
106
|
+
borderTopStartRadius?: number | string;
|
|
107
|
+
|
|
108
|
+
fontSize?: number | string;
|
|
109
|
+
fontWeight?:
|
|
110
|
+
| 'normal'
|
|
111
|
+
| 'bold'
|
|
112
|
+
| '100'
|
|
113
|
+
| '200'
|
|
114
|
+
| '300'
|
|
115
|
+
| '400'
|
|
116
|
+
| '500'
|
|
117
|
+
| '600'
|
|
118
|
+
| '700'
|
|
119
|
+
| '800'
|
|
120
|
+
| '900'
|
|
121
|
+
| string;
|
|
122
|
+
letterSpacing?: number | string;
|
|
123
|
+
lineHeight?: number | string;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export type WithElements<T> = {
|
|
127
|
+
left?: T;
|
|
128
|
+
right?: T;
|
|
129
|
+
};
|
package/types/theme.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { StyleProp } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export type Breakpoints = {
|
|
4
|
+
xs: number;
|
|
5
|
+
sm: number;
|
|
6
|
+
md: number;
|
|
7
|
+
lg: number;
|
|
8
|
+
xl: number;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type ITheme = {
|
|
12
|
+
light: MD3Theme;
|
|
13
|
+
dark: MD3Theme;
|
|
14
|
+
grid: {
|
|
15
|
+
breakpoints: Partial<Breakpoints>;
|
|
16
|
+
numberOfColumns: number;
|
|
17
|
+
};
|
|
18
|
+
resolveComponentStyles: (args: ResolveComponentStylesArgs) => StyleProp<any>;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type MD3Theme = {
|
|
22
|
+
themeName: string;
|
|
23
|
+
dark: boolean;
|
|
24
|
+
animation: {
|
|
25
|
+
scale: number;
|
|
26
|
+
durations: Record<string, number>;
|
|
27
|
+
};
|
|
28
|
+
colors: MD3Colors;
|
|
29
|
+
typescale: MD3Typescale;
|
|
30
|
+
shapes: MD3Shapes;
|
|
31
|
+
spacings: Record<string, number>;
|
|
32
|
+
letterSpacings: Record<string, string | number>;
|
|
33
|
+
fontSizes: Record<string, string | number>;
|
|
34
|
+
fontWeights: Record<string, string | number>;
|
|
35
|
+
lineHeights: Record<string, string | number>;
|
|
36
|
+
elevations: Record<string, number>;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type ResolveComponentStylesArgs = {
|
|
40
|
+
componentTheme: StyleProp<any>;
|
|
41
|
+
style: StyleProp<any>;
|
|
42
|
+
variant?: string;
|
|
43
|
+
states?: { [key: string]: boolean };
|
|
44
|
+
size?: string;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type Font = {
|
|
48
|
+
fontFamily: string;
|
|
49
|
+
fontWeight?:
|
|
50
|
+
| 'normal'
|
|
51
|
+
| 'bold'
|
|
52
|
+
| '100'
|
|
53
|
+
| '200'
|
|
54
|
+
| '300'
|
|
55
|
+
| '400'
|
|
56
|
+
| '500'
|
|
57
|
+
| '600'
|
|
58
|
+
| '700'
|
|
59
|
+
| '800'
|
|
60
|
+
| '900';
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type MD3Colors = {
|
|
64
|
+
primary: string;
|
|
65
|
+
primaryContainer: string;
|
|
66
|
+
secondary: string;
|
|
67
|
+
secondaryContainer: string;
|
|
68
|
+
tertiary: string;
|
|
69
|
+
tertiaryContainer: string;
|
|
70
|
+
surface: string;
|
|
71
|
+
surfaceVariant: string;
|
|
72
|
+
surfaceDisabled: string;
|
|
73
|
+
background: string;
|
|
74
|
+
error: string;
|
|
75
|
+
errorContainer: string;
|
|
76
|
+
onPrimary: string;
|
|
77
|
+
onPrimaryContainer: string;
|
|
78
|
+
onSecondary: string;
|
|
79
|
+
onSecondaryContainer: string;
|
|
80
|
+
onTertiary: string;
|
|
81
|
+
onTertiaryContainer: string;
|
|
82
|
+
onSurface: string;
|
|
83
|
+
onSurfaceVariant: string;
|
|
84
|
+
onSurfaceDisabled: string;
|
|
85
|
+
onError: string;
|
|
86
|
+
onErrorContainer: string;
|
|
87
|
+
onBackground: string;
|
|
88
|
+
outline: string;
|
|
89
|
+
inverseSurface: string;
|
|
90
|
+
inverseOnSurface: string;
|
|
91
|
+
inversePrimary: string;
|
|
92
|
+
backdrop: string;
|
|
93
|
+
elevation: MD3ElevationColors;
|
|
94
|
+
lines: string;
|
|
95
|
+
palette: Record<string, string>;
|
|
96
|
+
opacity: Record<string, number>;
|
|
97
|
+
surfaceContainerHighest: string;
|
|
98
|
+
stateLayer: {};
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export type MD3Shapes = {
|
|
102
|
+
corner: {
|
|
103
|
+
none: number;
|
|
104
|
+
extraSmall: number;
|
|
105
|
+
small: number;
|
|
106
|
+
medium: number;
|
|
107
|
+
large: number;
|
|
108
|
+
extraLarge: number;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export enum MD3TypescaleKey {
|
|
113
|
+
displayLarge = 'displayLarge',
|
|
114
|
+
displayMedium = 'displayMedium',
|
|
115
|
+
displaySmall = 'displaySmall',
|
|
116
|
+
|
|
117
|
+
headlineLarge = 'headlineLarge',
|
|
118
|
+
headlineMedium = 'headlineMedium',
|
|
119
|
+
headlineSmall = 'headlineSmall',
|
|
120
|
+
|
|
121
|
+
titleLarge = 'titleLarge',
|
|
122
|
+
titleMedium = 'titleMedium',
|
|
123
|
+
titleSmall = 'titleSmall',
|
|
124
|
+
|
|
125
|
+
labelLarge = 'labelLarge',
|
|
126
|
+
labelMedium = 'labelMedium',
|
|
127
|
+
labelSmall = 'labelSmall',
|
|
128
|
+
|
|
129
|
+
bodyLarge = 'bodyLarge',
|
|
130
|
+
bodyMedium = 'bodyMedium',
|
|
131
|
+
bodySmall = 'bodySmall',
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export type MD3Type = {
|
|
135
|
+
fontFamily: string;
|
|
136
|
+
letterSpacing: number;
|
|
137
|
+
fontWeight: Font['fontWeight'];
|
|
138
|
+
lineHeight: number;
|
|
139
|
+
fontSize: number;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export type MD3Typescale = {
|
|
143
|
+
[key in MD3TypescaleKey]: MD3Type;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export type MD3Elevation = 0 | 1 | 2 | 3 | 4 | 5;
|
|
147
|
+
|
|
148
|
+
export enum ElevationLevels {
|
|
149
|
+
'level0',
|
|
150
|
+
'level1',
|
|
151
|
+
'level2',
|
|
152
|
+
'level3',
|
|
153
|
+
'level4',
|
|
154
|
+
'level5',
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export type MD3ElevationColors = {
|
|
158
|
+
[key in keyof typeof ElevationLevels]: string;
|
|
159
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type DocumentPickerOptions, pick } from '@react-native-documents/picker';
|
|
2
|
+
|
|
3
|
+
const pickMultiple = ({ allowMultiSelection = true, ...rest }: DocumentPickerOptions) =>
|
|
4
|
+
pick({ allowMultiSelection, ...rest });
|
|
5
|
+
|
|
6
|
+
// to make sure only these 2 functions are available for all three platforms
|
|
7
|
+
export default {
|
|
8
|
+
pickSingle: pick,
|
|
9
|
+
pickMultiple: pickMultiple,
|
|
10
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Platform } from 'react-native';
|
|
2
|
+
|
|
3
|
+
import type { DocumentPickerOptions, DocumentResult } from './types';
|
|
4
|
+
|
|
5
|
+
const resolveFileData = (file: File): Promise<DocumentResult> => {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const mimeType = file.type;
|
|
8
|
+
const reader = new FileReader();
|
|
9
|
+
|
|
10
|
+
reader.onerror = () => {
|
|
11
|
+
reject(new Error(`Failed to read the selected media because the operation failed.`));
|
|
12
|
+
};
|
|
13
|
+
reader.onload = ({ target }) => {
|
|
14
|
+
const uri = (target as any).result;
|
|
15
|
+
|
|
16
|
+
resolve({
|
|
17
|
+
type: 'success',
|
|
18
|
+
uri,
|
|
19
|
+
mimeType,
|
|
20
|
+
name: file.name,
|
|
21
|
+
file: file,
|
|
22
|
+
lastModified: file.lastModified,
|
|
23
|
+
size: file.size,
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
// Read in the image file as a binary string.
|
|
27
|
+
reader.readAsDataURL(file);
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const getDocumentAsyncWeb = async ({
|
|
32
|
+
type = '*/*',
|
|
33
|
+
multiple = false,
|
|
34
|
+
}: DocumentPickerOptions): Promise<DocumentResult | DocumentResult[]> => {
|
|
35
|
+
// SSR guard
|
|
36
|
+
if (Platform.OS !== 'web') {
|
|
37
|
+
return { type: 'cancel' };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const input = document.createElement('input');
|
|
41
|
+
input.style.display = 'none';
|
|
42
|
+
input.setAttribute('type', 'file');
|
|
43
|
+
// @ts-expect-error
|
|
44
|
+
input.setAttribute('accept', Array.isArray(type) ? type.join(',') : type);
|
|
45
|
+
|
|
46
|
+
if (multiple) {
|
|
47
|
+
input.setAttribute('multiple', 'multiple');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
document.body.appendChild(input);
|
|
51
|
+
|
|
52
|
+
return new Promise(resolve => {
|
|
53
|
+
input.addEventListener('change', () => {
|
|
54
|
+
if (input.files) {
|
|
55
|
+
const response: Promise<DocumentResult>[] = [];
|
|
56
|
+
|
|
57
|
+
Array.from(input.files).forEach(file => response.push(resolveFileData(file)));
|
|
58
|
+
|
|
59
|
+
return resolve(Promise.all(response));
|
|
60
|
+
} else {
|
|
61
|
+
resolve({ type: 'cancel' });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
document.body.removeChild(input);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const event = new MouseEvent('click');
|
|
68
|
+
input.dispatchEvent(event);
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export default {
|
|
73
|
+
pickSingle: ({ type }: DocumentPickerOptions) => getDocumentAsyncWeb({ type, multiple: false }),
|
|
74
|
+
pickMultiple: ({ type }: DocumentPickerOptions) =>
|
|
75
|
+
getDocumentAsyncWeb({ type, multiple: true }),
|
|
76
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DocumentPickerOptions as RNDocumentPickerOptions,
|
|
3
|
+
DocumentPickerResponse,
|
|
4
|
+
} from '@react-native-documents/picker/lib/typescript';
|
|
5
|
+
|
|
6
|
+
export type { types as documentTypes } from '@react-native-documents/picker';
|
|
7
|
+
export type DocumentPickerOptions = Omit<RNDocumentPickerOptions, 'allowMultiSelection'> & {
|
|
8
|
+
/**
|
|
9
|
+
* Allows multiple files to be selected from the system UI.
|
|
10
|
+
* @default false
|
|
11
|
+
*/
|
|
12
|
+
multiple?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* runs when the DocumentPicker is cancelled
|
|
15
|
+
* currently, only supported on IOS and Android
|
|
16
|
+
*/
|
|
17
|
+
onCancel?: () => void;
|
|
18
|
+
/**
|
|
19
|
+
* runs when the DocumentPicker is errored
|
|
20
|
+
*/
|
|
21
|
+
onError?: (e: any) => void;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type DocumentResult = Partial<DocumentPickerResponse> & {
|
|
25
|
+
mimeType?: string;
|
|
26
|
+
file?: File;
|
|
27
|
+
lastModified?: number;
|
|
28
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { EmitterSubscription, NativeEventSubscription } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export function addEventListener<
|
|
4
|
+
T extends {
|
|
5
|
+
addEventListener: (...args: any) => NativeEventSubscription | EmitterSubscription;
|
|
6
|
+
} & { removeEventListener?: (...args: any) => void } & {
|
|
7
|
+
remove?: (...args: any) => void;
|
|
8
|
+
},
|
|
9
|
+
>(Module: T, ...rest: Parameters<typeof Module.addEventListener>) {
|
|
10
|
+
const [eventName, handler] = rest;
|
|
11
|
+
|
|
12
|
+
let removed = false;
|
|
13
|
+
|
|
14
|
+
const subscription = Module.addEventListener(eventName, handler) ?? {
|
|
15
|
+
remove: () => {
|
|
16
|
+
if (removed) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
Module.removeEventListener?.(eventName, handler);
|
|
21
|
+
Module.remove?.(eventName, handler);
|
|
22
|
+
removed = true;
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
return subscription;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function addListener<
|
|
30
|
+
T extends {
|
|
31
|
+
addListener: (...args: any) => EmitterSubscription;
|
|
32
|
+
removeEventListener: (...args: any) => void;
|
|
33
|
+
},
|
|
34
|
+
>(Module: T, ...rest: Parameters<typeof Module.addListener>) {
|
|
35
|
+
const [eventName, handler] = rest;
|
|
36
|
+
|
|
37
|
+
let removed = false;
|
|
38
|
+
|
|
39
|
+
const subscription = Module.addListener(eventName, handler) ?? {
|
|
40
|
+
remove: () => {
|
|
41
|
+
if (removed) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
Module.removeEventListener(eventName, handler);
|
|
46
|
+
removed = true;
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return subscription;
|
|
51
|
+
}
|
package/utils/color.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import color from 'color';
|
|
2
|
+
|
|
3
|
+
import { weakMemoized } from './lodash';
|
|
4
|
+
|
|
5
|
+
export const resolveContrastColor = weakMemoized(
|
|
6
|
+
(
|
|
7
|
+
bgColor: string,
|
|
8
|
+
lightColor: string = '#fff',
|
|
9
|
+
darkColor: string = '#000',
|
|
10
|
+
isDarkMode?: boolean,
|
|
11
|
+
) => {
|
|
12
|
+
let isLightColor = !isDarkMode;
|
|
13
|
+
try {
|
|
14
|
+
// TODO: Account for transparency.
|
|
15
|
+
isLightColor = color(bgColor).isLight();
|
|
16
|
+
} finally {
|
|
17
|
+
return isLightColor ? darkColor : lightColor;
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export default color;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
|
5
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
|
6
|
+
*/
|
|
7
|
+
function is(x: any, y: any) {
|
|
8
|
+
// SameValue algorithm
|
|
9
|
+
if (x === y) {
|
|
10
|
+
// Steps 1-5, 7-10
|
|
11
|
+
// Steps 6.b-6.e: +0 != -0
|
|
12
|
+
return x !== 0 || 1 / x === 1 / y;
|
|
13
|
+
} else {
|
|
14
|
+
// Step 6.a: NaN == NaN
|
|
15
|
+
return x !== x && y !== y;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Performs equality by iterating through keys on an object and returning false
|
|
21
|
+
* when any key has values which are not strictly equal between the arguments.
|
|
22
|
+
* Returns true when the values of all keys are strictly equal.
|
|
23
|
+
*/
|
|
24
|
+
export function shallowCompare(objA?: unknown, objB?: unknown) {
|
|
25
|
+
if (is(objA, objB)) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const keysA = Object.keys(objA);
|
|
34
|
+
const keysB = Object.keys(objB);
|
|
35
|
+
|
|
36
|
+
if (keysA.length !== keysB.length) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Test for A's keys different from B.
|
|
41
|
+
for (let i = 0; i < keysA.length; i++) {
|
|
42
|
+
if (
|
|
43
|
+
!hasOwnProperty.call(objB, keysA[i]) ||
|
|
44
|
+
!is(
|
|
45
|
+
(objA as Record<string, unknown>)[keysA[i]],
|
|
46
|
+
(objB as Record<string, unknown>)[keysA[i]],
|
|
47
|
+
)
|
|
48
|
+
) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { escapeRegex } from '../escapeRegex';
|
|
2
|
+
|
|
3
|
+
export type Mask = MaskArray | ((value?: string) => MaskArray);
|
|
4
|
+
export type MaskArray = Array<MaskItem>;
|
|
5
|
+
export type MaskItem = string | RegExp | [RegExp];
|
|
6
|
+
|
|
7
|
+
export type Props = {
|
|
8
|
+
/** Character for thousands delimiter. Defaults to `"."` */
|
|
9
|
+
delimiter?: string;
|
|
10
|
+
/** Decimal precision. Defaults to `2` */
|
|
11
|
+
precision?: number;
|
|
12
|
+
/** Decimal separator character. Defaults to `","` */
|
|
13
|
+
separator?: string;
|
|
14
|
+
prefix?: string | string[];
|
|
15
|
+
suffix?: string | string[];
|
|
16
|
+
getDelimiterOffset?: (index: number) => number;
|
|
17
|
+
allowNegative?: boolean;
|
|
18
|
+
optionalPrefix?: string | string[];
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const joinIfStringArr = (value: string | string[]) =>
|
|
22
|
+
Array.isArray(value) ? value.join('') : value || '';
|
|
23
|
+
|
|
24
|
+
export default function createNumberMask(props?: Props): Mask {
|
|
25
|
+
const {
|
|
26
|
+
delimiter = ',',
|
|
27
|
+
precision = 2,
|
|
28
|
+
prefix = [],
|
|
29
|
+
separator = '.',
|
|
30
|
+
suffix = [],
|
|
31
|
+
getDelimiterOffset = (_index: number) => 3,
|
|
32
|
+
allowNegative = true,
|
|
33
|
+
} = props || {};
|
|
34
|
+
|
|
35
|
+
return (value: string | number = '') => {
|
|
36
|
+
value = String(value);
|
|
37
|
+
|
|
38
|
+
// the first prefix will allow plus sign, minus sign(if allowNegative is true), and the prefix from the args
|
|
39
|
+
let firstPrefix: string | RegExp = new RegExp(
|
|
40
|
+
`[+${allowNegative ? '\\-' : ''}${escapeRegex(joinIfStringArr(prefix))}]`,
|
|
41
|
+
'g',
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
// if the first value already included, plus or minus sign, the value that comes after it should be the prefix
|
|
45
|
+
// otherwise, it means the first value has the prefix (doesnt matter if it's an array)
|
|
46
|
+
let secondPrefix: string | string[] = ['+', '-'].includes(value[0]) ? prefix : [];
|
|
47
|
+
|
|
48
|
+
const hasMinusSign = allowNegative && value[0] === '-';
|
|
49
|
+
const hasMinusSignOrPlusSign = hasMinusSign || value[0] === '+';
|
|
50
|
+
const isFirstValueNumber = !Number.isNaN(value[0]);
|
|
51
|
+
|
|
52
|
+
// if the first value that has been entered is a number and not plus or minus sign, the prefix should be displayed before that value
|
|
53
|
+
if (isFirstValueNumber && !hasMinusSignOrPlusSign) {
|
|
54
|
+
firstPrefix = '';
|
|
55
|
+
secondPrefix = prefix;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const shouldAddSeparatorOnMask = !!value && precision > 0 && !!separator;
|
|
59
|
+
const [normalizedValue = '', ...mantissa] =
|
|
60
|
+
shouldAddSeparatorOnMask || precision === 0 ? value.split(separator) : [value];
|
|
61
|
+
const numericValue = normalizedValue.replace(/\D+/g, '') || '';
|
|
62
|
+
const decimalLength = Math.max(
|
|
63
|
+
0,
|
|
64
|
+
Math.min(mantissa.join('').replace(/\D+/g, '').length, precision),
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const mask: MaskArray = numericValue.split('').map(() => /\d/);
|
|
68
|
+
|
|
69
|
+
if (delimiter) {
|
|
70
|
+
let i = 0;
|
|
71
|
+
let elapsed = numericValue.length;
|
|
72
|
+
|
|
73
|
+
do {
|
|
74
|
+
const precisionOffset = 0;
|
|
75
|
+
const separatorOffset = 0;
|
|
76
|
+
const thousandOffset = getDelimiterOffset(i) + (delimiter ? 1 : 0);
|
|
77
|
+
elapsed -= getDelimiterOffset(i);
|
|
78
|
+
|
|
79
|
+
if (elapsed <= 0) {
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const delimiterPosition =
|
|
84
|
+
-precisionOffset - separatorOffset - i * thousandOffset - 3;
|
|
85
|
+
|
|
86
|
+
mask.splice(delimiterPosition, 0, delimiter);
|
|
87
|
+
i++;
|
|
88
|
+
} while (true);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const hasDecimalAlready = shouldAddSeparatorOnMask && value.includes(separator);
|
|
92
|
+
if (hasDecimalAlready) {
|
|
93
|
+
mask.push(separator, ...Array.from({ length: decimalLength }, () => /\d/));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return [firstPrefix, ...secondPrefix, ...mask, ...suffix];
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const createSyntheticEvent = <T extends Element, E extends Event>(
|
|
2
|
+
event: E,
|
|
3
|
+
): React.SyntheticEvent<T, E> => {
|
|
4
|
+
let isDefaultPrevented = false;
|
|
5
|
+
let isPropagationStopped = false;
|
|
6
|
+
const preventDefault = () => {
|
|
7
|
+
isDefaultPrevented = true;
|
|
8
|
+
event.preventDefault();
|
|
9
|
+
};
|
|
10
|
+
const stopPropagation = () => {
|
|
11
|
+
isPropagationStopped = true;
|
|
12
|
+
event.stopPropagation();
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
nativeEvent: event,
|
|
16
|
+
currentTarget: event.currentTarget as EventTarget & T,
|
|
17
|
+
target: event.target as EventTarget & T,
|
|
18
|
+
bubbles: event.bubbles,
|
|
19
|
+
cancelable: event.cancelable,
|
|
20
|
+
defaultPrevented: event.defaultPrevented,
|
|
21
|
+
eventPhase: event.eventPhase,
|
|
22
|
+
isTrusted: event.isTrusted,
|
|
23
|
+
preventDefault,
|
|
24
|
+
isDefaultPrevented: () => isDefaultPrevented,
|
|
25
|
+
stopPropagation,
|
|
26
|
+
isPropagationStopped: () => isPropagationStopped,
|
|
27
|
+
persist: () => {},
|
|
28
|
+
timeStamp: event.timeStamp,
|
|
29
|
+
type: event.type,
|
|
30
|
+
};
|
|
31
|
+
};
|