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
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { StyleProp, TextProps, TextStyle, ViewStyle } from 'react-native';
|
|
2
|
+
|
|
3
|
+
import type { TouchableRippleProps } from '../TouchableRipple';
|
|
4
|
+
|
|
5
|
+
export type Size = 'sm' | 'md' | 'lg';
|
|
6
|
+
export type States = 'disabled' | 'checked' | 'hovered' | 'checkedAndHovered';
|
|
7
|
+
|
|
8
|
+
export type CheckBoxBaseProps = Omit<TouchableRippleProps, 'children'> & {
|
|
9
|
+
/**
|
|
10
|
+
* value of checkbox.
|
|
11
|
+
*/
|
|
12
|
+
value?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* defaultValue of checkbox.
|
|
15
|
+
*/
|
|
16
|
+
defaultValue?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* function execute when the value change i.e checkbox is press
|
|
19
|
+
*/
|
|
20
|
+
onChange?: (newValue: boolean) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Whether or not if it's in the indeterminate state, if true, it will override the value
|
|
23
|
+
*/
|
|
24
|
+
indeterminate?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Whether checkbox is disabled.
|
|
27
|
+
*/
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Size of the icon.
|
|
31
|
+
* Should be a number or a Design Token
|
|
32
|
+
*/
|
|
33
|
+
size?: Size;
|
|
34
|
+
/**
|
|
35
|
+
* Custom color for unchecked checkbox.
|
|
36
|
+
*/
|
|
37
|
+
uncheckedColor?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Custom color for checkbox.
|
|
40
|
+
*/
|
|
41
|
+
color?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Accessibility label for the touchable. This is read by the screen reader when the user taps the touchable.
|
|
44
|
+
*/
|
|
45
|
+
accessibilityLabel?: string;
|
|
46
|
+
/**
|
|
47
|
+
* testID to be used on tests.
|
|
48
|
+
*/
|
|
49
|
+
testID?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Label to be displayed next to the checkbox.
|
|
52
|
+
*/
|
|
53
|
+
label?: string;
|
|
54
|
+
/**
|
|
55
|
+
* Style that is passed to Label element.
|
|
56
|
+
*/
|
|
57
|
+
labelStyle?: StyleProp<TextStyle>;
|
|
58
|
+
/**
|
|
59
|
+
* Style that is passed to Container element (when label is provided).
|
|
60
|
+
*/
|
|
61
|
+
containerStyle?: ViewStyle;
|
|
62
|
+
/**
|
|
63
|
+
* Props for the label text element.
|
|
64
|
+
*/
|
|
65
|
+
labelProps?: Omit<TextProps, 'children' | 'style'>;
|
|
66
|
+
/**
|
|
67
|
+
* Checkbox control position relative to label.
|
|
68
|
+
*/
|
|
69
|
+
position?: 'leading' | 'trailing';
|
|
70
|
+
|
|
71
|
+
style?: StyleProp<TextStyle>;
|
|
72
|
+
};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native-unistyles';
|
|
2
|
+
|
|
3
|
+
import { getRegisteredMoleculesComponentStyles, registerComponentsStyles } from '../../core';
|
|
4
|
+
|
|
5
|
+
const PADDING = 6;
|
|
6
|
+
|
|
7
|
+
export const iconSizeMap = {
|
|
8
|
+
sm: 20,
|
|
9
|
+
md: 24,
|
|
10
|
+
lg: 28,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const checkboxStylesDefault = StyleSheet.create(theme => ({
|
|
14
|
+
root: {
|
|
15
|
+
variants: {
|
|
16
|
+
size: {
|
|
17
|
+
sm: {
|
|
18
|
+
padding: PADDING,
|
|
19
|
+
borderRadius: 16,
|
|
20
|
+
// iconSize: iconSizeMap.sm,
|
|
21
|
+
},
|
|
22
|
+
md: {
|
|
23
|
+
padding: PADDING,
|
|
24
|
+
borderRadius: 18,
|
|
25
|
+
// iconSize: iconSizeMap.md,
|
|
26
|
+
},
|
|
27
|
+
lg: {
|
|
28
|
+
padding: PADDING,
|
|
29
|
+
borderRadius: 20,
|
|
30
|
+
// iconSize: iconSizeMap.lg,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
compoundVariants: [
|
|
36
|
+
{
|
|
37
|
+
variant: 'android',
|
|
38
|
+
size: 'sm',
|
|
39
|
+
styles: {
|
|
40
|
+
width: 32,
|
|
41
|
+
height: 32,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
variant: 'android',
|
|
46
|
+
size: 'md',
|
|
47
|
+
styles: {
|
|
48
|
+
width: 36,
|
|
49
|
+
height: 36,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
variant: 'android',
|
|
54
|
+
size: 'lg',
|
|
55
|
+
styles: {
|
|
56
|
+
width: 40,
|
|
57
|
+
height: 40,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
stateLayer: {
|
|
63
|
+
variants: {
|
|
64
|
+
state: {
|
|
65
|
+
hovered: {
|
|
66
|
+
backgroundColor: theme.colors.stateLayer.hover.onSurface,
|
|
67
|
+
},
|
|
68
|
+
checkedAndHovered: {
|
|
69
|
+
backgroundColor: theme.colors.stateLayer.hover.primary,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
variant: {
|
|
74
|
+
ios: {
|
|
75
|
+
backgroundColor: 'transparent',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
itemContainer: {
|
|
81
|
+
flexDirection: 'row',
|
|
82
|
+
alignItems: 'center',
|
|
83
|
+
justifyContent: 'space-between',
|
|
84
|
+
},
|
|
85
|
+
label: {
|
|
86
|
+
flexShrink: 1,
|
|
87
|
+
flexGrow: 1,
|
|
88
|
+
variants: {
|
|
89
|
+
variant: {
|
|
90
|
+
item: {
|
|
91
|
+
color: theme.colors.onSurface,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
isLeading: {
|
|
95
|
+
true: {
|
|
96
|
+
textAlign: 'right',
|
|
97
|
+
paddingLeft: 0,
|
|
98
|
+
paddingRight: theme.spacings['2'],
|
|
99
|
+
},
|
|
100
|
+
false: {
|
|
101
|
+
textAlign: 'left',
|
|
102
|
+
paddingLeft: theme.spacings['2'],
|
|
103
|
+
paddingRight: 0,
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
compoundVariants: [
|
|
108
|
+
{
|
|
109
|
+
variant: 'item',
|
|
110
|
+
size: 'sm',
|
|
111
|
+
styles: {
|
|
112
|
+
...theme.typescale.bodyMedium,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
variant: 'item',
|
|
117
|
+
size: 'md',
|
|
118
|
+
styles: {
|
|
119
|
+
...theme.typescale.bodyMedium,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
variant: 'item',
|
|
124
|
+
size: 'lg',
|
|
125
|
+
styles: {
|
|
126
|
+
...theme.typescale.bodyLarge,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
fillContainer: {
|
|
132
|
+
alignItems: 'center',
|
|
133
|
+
justifyContent: 'center',
|
|
134
|
+
},
|
|
135
|
+
animatedFill: {
|
|
136
|
+
width: 24 / 2 + (PADDING - 2),
|
|
137
|
+
height: 24 / 2 + (PADDING - 2),
|
|
138
|
+
|
|
139
|
+
variants: {
|
|
140
|
+
size: {
|
|
141
|
+
sm: {
|
|
142
|
+
width: iconSizeMap.sm / 2 + (PADDING - 2),
|
|
143
|
+
height: iconSizeMap.sm / 2 + (PADDING - 2),
|
|
144
|
+
},
|
|
145
|
+
md: {
|
|
146
|
+
width: iconSizeMap.md / 2 + (PADDING - 2),
|
|
147
|
+
height: iconSizeMap.md / 2 + (PADDING - 2),
|
|
148
|
+
},
|
|
149
|
+
lg: {
|
|
150
|
+
width: iconSizeMap.lg / 2 + (PADDING - 2),
|
|
151
|
+
height: iconSizeMap.lg / 2 + (PADDING - 2),
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
icon: {
|
|
157
|
+
color: theme.colors.onSurfaceVariant,
|
|
158
|
+
|
|
159
|
+
variants: {
|
|
160
|
+
state: {
|
|
161
|
+
checked: {
|
|
162
|
+
color: theme.colors.primary,
|
|
163
|
+
},
|
|
164
|
+
checkedAndHovered: {
|
|
165
|
+
color: theme.colors.primary,
|
|
166
|
+
},
|
|
167
|
+
disabled: {
|
|
168
|
+
color: theme.colors.onSurfaceDisabled,
|
|
169
|
+
},
|
|
170
|
+
hovered: {},
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
// compoundVariantStyles: (variant: 'android' | 'ios' | 'item', size: Size, state: States) => {
|
|
175
|
+
// if (variant === 'android') {
|
|
176
|
+
// return {
|
|
177
|
+
// root: {
|
|
178
|
+
// ...(size === 'sm' && { width: 32, height: 32 }),
|
|
179
|
+
// ...(size === 'md' && { width: 36, height: 36 }),
|
|
180
|
+
// ...(size === 'lg' && { width: 40, height: 40 }),
|
|
181
|
+
// },
|
|
182
|
+
// stateLayer: {
|
|
183
|
+
// ...(state === 'hovered' && {
|
|
184
|
+
// backgroundColor: theme.colors.stateLayer.hover.onSurface,
|
|
185
|
+
// }),
|
|
186
|
+
// ...(state === 'checkedAndHovered' && {
|
|
187
|
+
// backgroundColor: theme.colors.stateLayer.hover.primary,
|
|
188
|
+
// }),
|
|
189
|
+
// },
|
|
190
|
+
// } as any;
|
|
191
|
+
// }
|
|
192
|
+
|
|
193
|
+
// if (variant === 'item') {
|
|
194
|
+
// return {
|
|
195
|
+
// root: {
|
|
196
|
+
// labelColor: 'colors.onSurface',
|
|
197
|
+
// ...(size === 'sm' && { labelTypeScale: theme.typescale.bodyMedium }),
|
|
198
|
+
// ...(size === 'md' && { labelTypeScale: theme.typescale.bodyLarge }),
|
|
199
|
+
// ...(size === 'lg' && { labelTypeScale: theme.typescale.bodyLarge }),
|
|
200
|
+
// },
|
|
201
|
+
// };
|
|
202
|
+
// }
|
|
203
|
+
// },
|
|
204
|
+
}));
|
|
205
|
+
|
|
206
|
+
registerComponentsStyles({
|
|
207
|
+
Checkbox: checkboxStylesDefault,
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
export const styles = getRegisteredMoleculesComponentStyles('Checkbox') ?? checkboxStylesDefault;
|
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ComponentType,
|
|
3
|
+
forwardRef,
|
|
4
|
+
memo,
|
|
5
|
+
type PropsWithoutRef,
|
|
6
|
+
type ReactNode,
|
|
7
|
+
useContext,
|
|
8
|
+
useMemo,
|
|
9
|
+
} from 'react';
|
|
10
|
+
import {
|
|
11
|
+
type GestureResponderEvent,
|
|
12
|
+
type StyleProp,
|
|
13
|
+
type TextProps,
|
|
14
|
+
type TextStyle,
|
|
15
|
+
View,
|
|
16
|
+
type ViewProps,
|
|
17
|
+
type ViewStyle,
|
|
18
|
+
} from 'react-native';
|
|
19
|
+
|
|
20
|
+
import { useActionState } from '../../hooks';
|
|
21
|
+
import type { WithElements } from '../../types';
|
|
22
|
+
import type { MD3Elevation } from '../../types/theme';
|
|
23
|
+
import { BackgroundContext, resolveStateVariant } from '../../utils';
|
|
24
|
+
import { ActivityIndicator, type ActivityIndicatorProps } from '../ActivityIndicator';
|
|
25
|
+
import { Icon, type IconProps } from '../Icon';
|
|
26
|
+
import { IconButton, type IconButtonProps } from '../IconButton';
|
|
27
|
+
import { StateLayer } from '../StateLayer';
|
|
28
|
+
import { Surface } from '../Surface';
|
|
29
|
+
import { Text } from '../Text';
|
|
30
|
+
import { TouchableRipple, type TouchableRippleProps } from '../TouchableRipple';
|
|
31
|
+
import { type States, styles } from './utils';
|
|
32
|
+
|
|
33
|
+
export type Props = Omit<TouchableRippleProps, 'children'> &
|
|
34
|
+
WithElements<ReactNode> & {
|
|
35
|
+
/**
|
|
36
|
+
* label of the chip
|
|
37
|
+
* Will be truncated if it's longer than 20 characters
|
|
38
|
+
*/
|
|
39
|
+
label: string;
|
|
40
|
+
/**
|
|
41
|
+
* character limit of the label
|
|
42
|
+
*/
|
|
43
|
+
labelCharacterLimit?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Variant of the chip.
|
|
46
|
+
* - `elevated` - elevated chip with shadow and without outline.
|
|
47
|
+
* - `outlined` - chip with an outline. (outline will always have elevation 0 even if it's specified)
|
|
48
|
+
*/
|
|
49
|
+
variant?: 'elevated' | 'outlined';
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* */
|
|
53
|
+
size?: 'sm' | 'md';
|
|
54
|
+
/**
|
|
55
|
+
* callback event when the closeIcon is pressed
|
|
56
|
+
*/
|
|
57
|
+
onClose?: () => void;
|
|
58
|
+
/**
|
|
59
|
+
* elevation level of the elevated chip
|
|
60
|
+
*/
|
|
61
|
+
elevation?: MD3Elevation;
|
|
62
|
+
/**
|
|
63
|
+
* selected state
|
|
64
|
+
*/
|
|
65
|
+
selected?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* props for the close icon
|
|
68
|
+
* default is { name: 'close', onPress: onClose, disabled, accessibilityLabel: 'Close' }
|
|
69
|
+
*/
|
|
70
|
+
closeIconProps?: Partial<IconButtonProps>;
|
|
71
|
+
/**
|
|
72
|
+
* props for the ActivityIndicator
|
|
73
|
+
* default is { size: 18 }
|
|
74
|
+
*/
|
|
75
|
+
activityIndicatorProps?: Partial<ActivityIndicatorProps>;
|
|
76
|
+
/**
|
|
77
|
+
* Whether to style the chip color as selected.
|
|
78
|
+
*/
|
|
79
|
+
selectedColor?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Whether to display overlay on selected chip
|
|
82
|
+
*/
|
|
83
|
+
selectionBackgroundColor?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Accessibility label for the chip. This is read by the screen reader when the user taps the chip.
|
|
86
|
+
*/
|
|
87
|
+
accessibilityLabel?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Whether the chip is disabled. A disabled chip is greyed out and `onPress` is not called on touch.
|
|
90
|
+
*/
|
|
91
|
+
disabled?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Function to execute on press.
|
|
94
|
+
*/
|
|
95
|
+
onPress?: (e: GestureResponderEvent) => void;
|
|
96
|
+
/**
|
|
97
|
+
* Whether to show the ActivityIndicator or not
|
|
98
|
+
*/
|
|
99
|
+
loading?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* container style
|
|
102
|
+
*/
|
|
103
|
+
containerStyle?: ViewStyle;
|
|
104
|
+
/**
|
|
105
|
+
* left element container style
|
|
106
|
+
*/
|
|
107
|
+
leftElementContainerStyle?: ViewStyle;
|
|
108
|
+
/**
|
|
109
|
+
* right element container style
|
|
110
|
+
*/
|
|
111
|
+
rightElementContainerStyle?: ViewStyle;
|
|
112
|
+
/**
|
|
113
|
+
* label style
|
|
114
|
+
*/
|
|
115
|
+
labelStyle?: Partial<TextStyle>;
|
|
116
|
+
/**
|
|
117
|
+
* Pass down testID from chip props to touchable for Detox tests.
|
|
118
|
+
*/
|
|
119
|
+
/**
|
|
120
|
+
* props for the stateLayer
|
|
121
|
+
*/
|
|
122
|
+
stateLayerProps?: PropsWithoutRef<ViewProps>;
|
|
123
|
+
testID?: string;
|
|
124
|
+
containerProps?: Omit<PropsWithoutRef<ViewProps>, 'style'>;
|
|
125
|
+
leftElementIconProps?: IconProps;
|
|
126
|
+
rightElementIconProps?: IconProps;
|
|
127
|
+
backgroundColor?: string;
|
|
128
|
+
|
|
129
|
+
invertLabelColor?: boolean;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const Chip = (
|
|
133
|
+
{
|
|
134
|
+
style,
|
|
135
|
+
containerStyle: containerStyleProp,
|
|
136
|
+
label: _label,
|
|
137
|
+
labelCharacterLimit = 20,
|
|
138
|
+
variant = 'outlined',
|
|
139
|
+
size = 'md',
|
|
140
|
+
disabled,
|
|
141
|
+
elevation: elevationProp = 1,
|
|
142
|
+
left,
|
|
143
|
+
right,
|
|
144
|
+
loading = false,
|
|
145
|
+
onClose,
|
|
146
|
+
closeIconProps,
|
|
147
|
+
activityIndicatorProps,
|
|
148
|
+
selected = false,
|
|
149
|
+
leftElementContainerStyle,
|
|
150
|
+
rightElementContainerStyle,
|
|
151
|
+
labelStyle: labelStyleProp,
|
|
152
|
+
accessibilityLabel,
|
|
153
|
+
selectedColor,
|
|
154
|
+
selectionBackgroundColor,
|
|
155
|
+
stateLayerProps = {},
|
|
156
|
+
testID = 'chip',
|
|
157
|
+
containerProps,
|
|
158
|
+
leftElementIconProps,
|
|
159
|
+
invertLabelColor,
|
|
160
|
+
backgroundColor,
|
|
161
|
+
...rest
|
|
162
|
+
}: Props,
|
|
163
|
+
ref: any,
|
|
164
|
+
) => {
|
|
165
|
+
const { hovered, actionsRef } = useActionState({ ref, actionsToListen: ['hover'] });
|
|
166
|
+
|
|
167
|
+
const state = resolveStateVariant({
|
|
168
|
+
disabled: !!disabled,
|
|
169
|
+
selected,
|
|
170
|
+
selectedAndHovered: selected && hovered,
|
|
171
|
+
hovered,
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
styles.useVariants({
|
|
175
|
+
variant,
|
|
176
|
+
size,
|
|
177
|
+
state: state as States,
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
const iconSize = size === 'sm' ? 15 : 18;
|
|
181
|
+
// const componentStyles = useComponentStyles('Chip', [
|
|
182
|
+
// style,
|
|
183
|
+
// {
|
|
184
|
+
// container: containerStyleProp || {},
|
|
185
|
+
// leftElement: leftElementContainerStyleProp || {},
|
|
186
|
+
// rightElement: rightElementContainerStyleProp || {},
|
|
187
|
+
// label: labelStyleProp || {},
|
|
188
|
+
// },
|
|
189
|
+
// selectionBackgroundColorProp
|
|
190
|
+
// ? { selectionBackgroundColor: selectionBackgroundColorProp }
|
|
191
|
+
// : {},
|
|
192
|
+
// selectedColorProp ? { selectedColor: selectedColorProp } : {},
|
|
193
|
+
// ]);
|
|
194
|
+
|
|
195
|
+
const {
|
|
196
|
+
containerStyle,
|
|
197
|
+
touchableRippleStyle,
|
|
198
|
+
leftElementStyle,
|
|
199
|
+
rightElementStyle,
|
|
200
|
+
labelStyle,
|
|
201
|
+
stateLayerStyle,
|
|
202
|
+
} = useMemo(() => {
|
|
203
|
+
return {
|
|
204
|
+
containerStyle: [
|
|
205
|
+
styles.container,
|
|
206
|
+
selected && selectionBackgroundColor
|
|
207
|
+
? { backgroundColor: selectionBackgroundColor }
|
|
208
|
+
: {},
|
|
209
|
+
containerStyleProp,
|
|
210
|
+
],
|
|
211
|
+
touchableRippleStyle: [styles.touchableRippleContainer, style],
|
|
212
|
+
leftElementStyle: [styles.leftElement, leftElementContainerStyle],
|
|
213
|
+
rightElementStyle: [styles.rightElement, rightElementContainerStyle],
|
|
214
|
+
labelStyle: [
|
|
215
|
+
styles.label,
|
|
216
|
+
selected && selectedColor ? { color: selectedColor } : {},
|
|
217
|
+
labelStyleProp,
|
|
218
|
+
],
|
|
219
|
+
stateLayerStyle: [styles.stateLayer, stateLayerProps?.style],
|
|
220
|
+
};
|
|
221
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
222
|
+
}, [
|
|
223
|
+
leftElementContainerStyle,
|
|
224
|
+
rightElementContainerStyle,
|
|
225
|
+
selected,
|
|
226
|
+
selectedColor,
|
|
227
|
+
selectionBackgroundColor,
|
|
228
|
+
stateLayerProps?.style,
|
|
229
|
+
style,
|
|
230
|
+
containerStyleProp,
|
|
231
|
+
labelStyleProp,
|
|
232
|
+
state,
|
|
233
|
+
size,
|
|
234
|
+
variant,
|
|
235
|
+
]);
|
|
236
|
+
|
|
237
|
+
const { accessibilityState, elevation } = useMemo(
|
|
238
|
+
() => ({
|
|
239
|
+
accessibilityState: {
|
|
240
|
+
selected,
|
|
241
|
+
disabled,
|
|
242
|
+
},
|
|
243
|
+
elevation: variant === 'outlined' || disabled ? 0 : elevationProp,
|
|
244
|
+
}),
|
|
245
|
+
[disabled, elevationProp, selected, variant],
|
|
246
|
+
);
|
|
247
|
+
const label = `${_label}`.trim();
|
|
248
|
+
|
|
249
|
+
return (
|
|
250
|
+
<Surface
|
|
251
|
+
{...containerProps}
|
|
252
|
+
elevation={elevation}
|
|
253
|
+
style={containerStyle}
|
|
254
|
+
backgroundColor={backgroundColor}>
|
|
255
|
+
<TouchableRipple
|
|
256
|
+
borderless
|
|
257
|
+
{...rest}
|
|
258
|
+
disabled={disabled}
|
|
259
|
+
style={touchableRippleStyle}
|
|
260
|
+
accessibilityLabel={accessibilityLabel}
|
|
261
|
+
accessibilityRole="button"
|
|
262
|
+
accessibilityState={accessibilityState}
|
|
263
|
+
ref={actionsRef}
|
|
264
|
+
testID={testID}>
|
|
265
|
+
<>
|
|
266
|
+
<LeftElement
|
|
267
|
+
iconSize={iconSize}
|
|
268
|
+
leftElementStyle={leftElementStyle}
|
|
269
|
+
left={left}
|
|
270
|
+
activityIndicatorProps={activityIndicatorProps}
|
|
271
|
+
loading={loading}
|
|
272
|
+
selected={selected}
|
|
273
|
+
iconProps={leftElementIconProps}
|
|
274
|
+
invert={invertLabelColor}
|
|
275
|
+
/>
|
|
276
|
+
<Label
|
|
277
|
+
selectable={false}
|
|
278
|
+
style={labelStyle as TextProps['style']}
|
|
279
|
+
invert={invertLabelColor}>
|
|
280
|
+
{label.length < labelCharacterLimit
|
|
281
|
+
? label
|
|
282
|
+
: `${label.substring(0, labelCharacterLimit - 3)}...`}
|
|
283
|
+
</Label>
|
|
284
|
+
<RightElement
|
|
285
|
+
rightElementStyle={rightElementStyle}
|
|
286
|
+
accessibilityState={accessibilityState}
|
|
287
|
+
right={right}
|
|
288
|
+
disabled={disabled}
|
|
289
|
+
onClose={onClose}
|
|
290
|
+
closeIconProps={closeIconProps}
|
|
291
|
+
invert={invertLabelColor}
|
|
292
|
+
/>
|
|
293
|
+
|
|
294
|
+
<StateLayer
|
|
295
|
+
testID={testID ? `${testID}-stateLayer` : ''}
|
|
296
|
+
{...stateLayerProps}
|
|
297
|
+
style={stateLayerStyle}
|
|
298
|
+
/>
|
|
299
|
+
</>
|
|
300
|
+
</TouchableRipple>
|
|
301
|
+
</Surface>
|
|
302
|
+
);
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
type LeftElementProps = Pick<Props, 'activityIndicatorProps' | 'left' | 'loading' | 'selected'> & {
|
|
306
|
+
leftElementStyle: StyleProp<ViewStyle>;
|
|
307
|
+
iconSize: number;
|
|
308
|
+
iconProps?: IconProps;
|
|
309
|
+
invert?: boolean;
|
|
310
|
+
};
|
|
311
|
+
const LeftElement = memo(
|
|
312
|
+
({
|
|
313
|
+
iconSize,
|
|
314
|
+
loading,
|
|
315
|
+
left,
|
|
316
|
+
selected,
|
|
317
|
+
activityIndicatorProps,
|
|
318
|
+
leftElementStyle,
|
|
319
|
+
iconProps,
|
|
320
|
+
invert,
|
|
321
|
+
}: LeftElementProps) => {
|
|
322
|
+
return loading || left || selected ? (
|
|
323
|
+
<View style={leftElementStyle}>
|
|
324
|
+
{loading ? (
|
|
325
|
+
<ActivityIndicator size={iconSize} {...(activityIndicatorProps || {})} />
|
|
326
|
+
) : (
|
|
327
|
+
left || (
|
|
328
|
+
<IconWithContrastColor
|
|
329
|
+
name="check"
|
|
330
|
+
size={iconSize}
|
|
331
|
+
{...iconProps}
|
|
332
|
+
invert={invert}
|
|
333
|
+
/>
|
|
334
|
+
)
|
|
335
|
+
)}
|
|
336
|
+
</View>
|
|
337
|
+
) : (
|
|
338
|
+
<></>
|
|
339
|
+
);
|
|
340
|
+
},
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
type RightElementProps = Pick<
|
|
344
|
+
Props,
|
|
345
|
+
'onClose' | 'right' | 'closeIconProps' | 'disabled' | 'accessibilityState'
|
|
346
|
+
> & {
|
|
347
|
+
rightElementStyle: StyleProp<ViewStyle>;
|
|
348
|
+
invert?: boolean;
|
|
349
|
+
};
|
|
350
|
+
const RightElement = memo(
|
|
351
|
+
({
|
|
352
|
+
onClose,
|
|
353
|
+
right,
|
|
354
|
+
disabled,
|
|
355
|
+
closeIconProps,
|
|
356
|
+
rightElementStyle,
|
|
357
|
+
accessibilityState,
|
|
358
|
+
invert,
|
|
359
|
+
}: RightElementProps) => {
|
|
360
|
+
return onClose || right ? (
|
|
361
|
+
<View style={rightElementStyle}>
|
|
362
|
+
{onClose ? (
|
|
363
|
+
<IconButtonWithContrastColor
|
|
364
|
+
name="close"
|
|
365
|
+
size={18}
|
|
366
|
+
accessibilityLabel="Close"
|
|
367
|
+
disabled={disabled}
|
|
368
|
+
onPress={onClose}
|
|
369
|
+
accessibilityState={accessibilityState}
|
|
370
|
+
{...(closeIconProps || {})}
|
|
371
|
+
invert={invert}
|
|
372
|
+
/>
|
|
373
|
+
) : (
|
|
374
|
+
right
|
|
375
|
+
)}
|
|
376
|
+
</View>
|
|
377
|
+
) : (
|
|
378
|
+
<></>
|
|
379
|
+
);
|
|
380
|
+
},
|
|
381
|
+
);
|
|
382
|
+
|
|
383
|
+
const withInvertColorResolved =
|
|
384
|
+
<T extends { style?: TextProps['style'] } = {}>(
|
|
385
|
+
Component: ComponentType<T>,
|
|
386
|
+
prop: string = 'style',
|
|
387
|
+
) =>
|
|
388
|
+
({ invert, ...props }: T & { invert?: boolean }) => {
|
|
389
|
+
const { color: contrastColor } = useContext(BackgroundContext);
|
|
390
|
+
|
|
391
|
+
const componentStyle = useMemo(
|
|
392
|
+
() => (!invert ? props.style : [props.style, { color: contrastColor }]),
|
|
393
|
+
[invert, props.style, contrastColor],
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
const normalizedProps = {
|
|
397
|
+
...props,
|
|
398
|
+
[prop]: componentStyle,
|
|
399
|
+
} as unknown as T;
|
|
400
|
+
|
|
401
|
+
return <Component {...normalizedProps} />;
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
const Label = withInvertColorResolved((props: TextProps) => {
|
|
405
|
+
return <Text {...props} />;
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
const IconWithContrastColor = withInvertColorResolved((props: IconProps) => {
|
|
409
|
+
return <Icon {...props} />;
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
const IconButtonWithContrastColor = withInvertColorResolved((props: IconButtonProps) => {
|
|
413
|
+
return <IconButton {...props} />;
|
|
414
|
+
}, 'iconStyle');
|
|
415
|
+
|
|
416
|
+
export default memo(forwardRef(Chip));
|