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,232 @@
|
|
|
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));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getRegisteredComponentWithFallback, registerMoleculesComponents } 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
|
+
registerMoleculesComponents({
|
|
18
|
+
RadioButton: RadioButtonDefault,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export const RadioButton = getRegisteredComponentWithFallback('RadioButton', RadioButtonDefault);
|
|
22
|
+
|
|
23
|
+
export { Props as RadioButtonProps } from './RadioButton';
|
|
24
|
+
export { Props as RadioButtonGroupProps } from './RadioButtonGroup';
|
|
25
|
+
export { Props as RadioButtonItemProps } from './RadioButtonItem';
|
|
26
|
+
|
|
27
|
+
export { radioButtonStyles, radioButtonItemStyles } from './utils';
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native-unistyles';
|
|
2
|
+
|
|
3
|
+
import { getRegisteredMoleculesComponentStyles, registerComponentsStyles } 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
|
+
registerComponentsStyles({
|
|
125
|
+
RadioButton: radioButtonStylesDefault,
|
|
126
|
+
RadioButton_Item: radioButtonItemStylesDefault,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
export const radioButtonStyles = getRegisteredMoleculesComponentStyles('RadioButton');
|
|
130
|
+
export const radioButtonItemStyles = getRegisteredMoleculesComponentStyles('RadioButton_Item');
|
|
131
|
+
|
|
132
|
+
export const handlePress = ({
|
|
133
|
+
onPress,
|
|
134
|
+
value,
|
|
135
|
+
onValueChange,
|
|
136
|
+
}: {
|
|
137
|
+
onPress?: () => void;
|
|
138
|
+
value: string;
|
|
139
|
+
onValueChange?: (value: string) => void;
|
|
140
|
+
}) => {
|
|
141
|
+
if (onPress && onValueChange) {
|
|
142
|
+
console.warn(
|
|
143
|
+
`onPress in the scope of RadioButtonGroup will not be executed, use onValueChange instead`,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
onValueChange ? onValueChange(value) : onPress?.();
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export const isChecked = ({
|
|
151
|
+
value,
|
|
152
|
+
status,
|
|
153
|
+
contextValue,
|
|
154
|
+
}: {
|
|
155
|
+
value: string;
|
|
156
|
+
status?: 'checked' | 'unchecked';
|
|
157
|
+
contextValue?: string;
|
|
158
|
+
}) => {
|
|
159
|
+
if (contextValue !== undefined && contextValue !== null) {
|
|
160
|
+
return contextValue === value ? 'checked' : 'unchecked';
|
|
161
|
+
} else {
|
|
162
|
+
return status;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { forwardRef, memo, useMemo } from 'react';
|
|
2
|
+
import { View, type ViewProps, type ViewStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { useControlledValue } from '../../hooks';
|
|
5
|
+
import type { IconProps, IconType } from '../Icon';
|
|
6
|
+
import type { TooltipProps } from '../Tooltip';
|
|
7
|
+
import RatingItem from './RatingItem';
|
|
8
|
+
import { ratingStyles } from './utils';
|
|
9
|
+
|
|
10
|
+
export type Props = ViewProps & {
|
|
11
|
+
/**
|
|
12
|
+
* rating count
|
|
13
|
+
* @default 5
|
|
14
|
+
*/
|
|
15
|
+
count?: number;
|
|
16
|
+
/**
|
|
17
|
+
* The rating value.
|
|
18
|
+
*/
|
|
19
|
+
value?: number;
|
|
20
|
+
/**
|
|
21
|
+
* The default value for the uncontrolled state
|
|
22
|
+
* @default undefined
|
|
23
|
+
*/
|
|
24
|
+
defaultValue?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Callback function that is fired when the hover state changes.
|
|
27
|
+
* @param {number} value The new value.
|
|
28
|
+
*/
|
|
29
|
+
onChange?: (value: number) => void;
|
|
30
|
+
/** Removes all hover effects and pointer events.
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
readonly?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* If `true`, the component is disabled
|
|
36
|
+
* @default false
|
|
37
|
+
*/
|
|
38
|
+
disabled?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* name of the empty icon
|
|
41
|
+
*/
|
|
42
|
+
iconName?: string;
|
|
43
|
+
/**
|
|
44
|
+
* the type of the empty icon
|
|
45
|
+
*/
|
|
46
|
+
iconType?: IconType;
|
|
47
|
+
/**
|
|
48
|
+
* name of the active icon
|
|
49
|
+
*/
|
|
50
|
+
activeIconName?: string;
|
|
51
|
+
/**
|
|
52
|
+
* type of the active icon
|
|
53
|
+
*/
|
|
54
|
+
activeIconType?: IconType;
|
|
55
|
+
/**
|
|
56
|
+
* size of all the icons
|
|
57
|
+
* */
|
|
58
|
+
size?: number;
|
|
59
|
+
/**
|
|
60
|
+
* color of the empty icon
|
|
61
|
+
* */
|
|
62
|
+
color?: string;
|
|
63
|
+
/**
|
|
64
|
+
* color of the active icon
|
|
65
|
+
* */
|
|
66
|
+
activeColor?: string;
|
|
67
|
+
/**
|
|
68
|
+
* style of the icon container component
|
|
69
|
+
* */
|
|
70
|
+
iconContainerStyle?: ViewStyle;
|
|
71
|
+
/**
|
|
72
|
+
* props for to pass down to all the icons
|
|
73
|
+
* */
|
|
74
|
+
iconProps?: Omit<IconProps, 'name' | 'type' | 'color' | 'ref'>;
|
|
75
|
+
/**
|
|
76
|
+
* display tooltips
|
|
77
|
+
* */
|
|
78
|
+
showTooltips?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* for configuring tooltip
|
|
81
|
+
* won't be used if showTooltips is false
|
|
82
|
+
* */
|
|
83
|
+
tooltipProps?: TooltipProps;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const Rating = (
|
|
87
|
+
{
|
|
88
|
+
count = 5,
|
|
89
|
+
value: valueProp,
|
|
90
|
+
defaultValue,
|
|
91
|
+
onChange: onChangeProp,
|
|
92
|
+
size = 24,
|
|
93
|
+
disabled,
|
|
94
|
+
readonly,
|
|
95
|
+
iconContainerStyle,
|
|
96
|
+
iconName = 'star-outline',
|
|
97
|
+
iconType = 'material-community',
|
|
98
|
+
activeIconName = 'star',
|
|
99
|
+
activeIconType = 'material-community',
|
|
100
|
+
iconProps = {},
|
|
101
|
+
color,
|
|
102
|
+
activeColor,
|
|
103
|
+
style,
|
|
104
|
+
testID,
|
|
105
|
+
showTooltips,
|
|
106
|
+
tooltipProps,
|
|
107
|
+
...rest
|
|
108
|
+
}: Props,
|
|
109
|
+
ref: any,
|
|
110
|
+
) => {
|
|
111
|
+
const componentStyles = useMemo(() => [ratingStyles.root, style], [style]);
|
|
112
|
+
|
|
113
|
+
const [value, onChange] = useControlledValue({
|
|
114
|
+
value: valueProp,
|
|
115
|
+
defaultValue,
|
|
116
|
+
onChange: onChangeProp,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const arrayFromCount = useMemo(() => Array.from({ length: count }, (_, i) => i + 1), [count]);
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<View style={componentStyles} {...rest} testID={testID} ref={ref}>
|
|
123
|
+
{arrayFromCount.map(i => (
|
|
124
|
+
<RatingItem
|
|
125
|
+
key={i}
|
|
126
|
+
size={size}
|
|
127
|
+
disabled={disabled}
|
|
128
|
+
readonly={readonly}
|
|
129
|
+
iconContainerStyle={iconContainerStyle}
|
|
130
|
+
{...iconProps}
|
|
131
|
+
index={i}
|
|
132
|
+
name={iconName}
|
|
133
|
+
type={iconType}
|
|
134
|
+
activeIconName={activeIconName}
|
|
135
|
+
activeIconType={activeIconType}
|
|
136
|
+
value={value}
|
|
137
|
+
onChange={onChange}
|
|
138
|
+
color={color}
|
|
139
|
+
activeColor={activeColor}
|
|
140
|
+
testID={testID ? `${testID}-rating-item-${i}` : ''}
|
|
141
|
+
showTooltips={showTooltips}
|
|
142
|
+
tooltipProps={tooltipProps}
|
|
143
|
+
/>
|
|
144
|
+
))}
|
|
145
|
+
</View>
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export default memo(forwardRef(Rating));
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { forwardRef, memo, useCallback, useMemo } from 'react';
|
|
2
|
+
import { Pressable, type ViewStyle } from 'react-native';
|
|
3
|
+
import { Icon, type IconProps, type IconType } from '../Icon';
|
|
4
|
+
import { Tooltip, type TooltipProps } from '../Tooltip';
|
|
5
|
+
import { resolveStateVariant } from '../../utils';
|
|
6
|
+
import { ratingItemStyles } from './utils';
|
|
7
|
+
|
|
8
|
+
export type Props = Omit<IconProps, 'ref'> & {
|
|
9
|
+
index: number;
|
|
10
|
+
value: number;
|
|
11
|
+
onChange: (val: number) => void;
|
|
12
|
+
activeIconName: string;
|
|
13
|
+
activeIconType: IconType;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
readonly?: boolean;
|
|
16
|
+
iconContainerStyle?: ViewStyle;
|
|
17
|
+
activeColor?: string;
|
|
18
|
+
color?: string;
|
|
19
|
+
showTooltips?: boolean;
|
|
20
|
+
tooltipProps?: Omit<TooltipProps, 'children'>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const RatingItem = (
|
|
24
|
+
{
|
|
25
|
+
style,
|
|
26
|
+
disabled = false,
|
|
27
|
+
readonly = false,
|
|
28
|
+
iconContainerStyle,
|
|
29
|
+
value,
|
|
30
|
+
index,
|
|
31
|
+
onChange,
|
|
32
|
+
name,
|
|
33
|
+
type,
|
|
34
|
+
activeIconName,
|
|
35
|
+
activeIconType,
|
|
36
|
+
activeColor = 'rgb(250, 175, 0)',
|
|
37
|
+
color,
|
|
38
|
+
showTooltips = true,
|
|
39
|
+
tooltipProps = {},
|
|
40
|
+
...rest
|
|
41
|
+
}: Props,
|
|
42
|
+
ref: any,
|
|
43
|
+
) => {
|
|
44
|
+
const active = value >= index;
|
|
45
|
+
|
|
46
|
+
// const componentStyles = useComponentStyles(
|
|
47
|
+
// 'Rating_Item',
|
|
48
|
+
// [active ? { color: activeColor } : color ? { color } : {}, style],
|
|
49
|
+
// {
|
|
50
|
+
// state: resolveStateVariant({
|
|
51
|
+
// activeAndDisabled: active && disabled,
|
|
52
|
+
// activeAndReadonly: active && readonly,
|
|
53
|
+
// active,
|
|
54
|
+
// disabled,
|
|
55
|
+
// readonly,
|
|
56
|
+
// }),
|
|
57
|
+
// },
|
|
58
|
+
// );
|
|
59
|
+
const state = resolveStateVariant({
|
|
60
|
+
activeAndDisabled: active && disabled,
|
|
61
|
+
activeAndReadonly: active && readonly,
|
|
62
|
+
active,
|
|
63
|
+
disabled,
|
|
64
|
+
readonly,
|
|
65
|
+
});
|
|
66
|
+
ratingItemStyles.useVariants({
|
|
67
|
+
state: state as any,
|
|
68
|
+
});
|
|
69
|
+
const componentStyles = useMemo(
|
|
70
|
+
() => [
|
|
71
|
+
ratingItemStyles.root,
|
|
72
|
+
active ? { color: activeColor } : color ? { color } : {},
|
|
73
|
+
style,
|
|
74
|
+
],
|
|
75
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
76
|
+
[active, activeColor, color, style, state],
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const onPress = useCallback(() => {
|
|
80
|
+
onChange(value === index ? 0 : index);
|
|
81
|
+
}, [index, onChange, value]);
|
|
82
|
+
|
|
83
|
+
const IconComponent = useMemo(
|
|
84
|
+
() => (
|
|
85
|
+
<Pressable
|
|
86
|
+
ref={ref}
|
|
87
|
+
style={iconContainerStyle}
|
|
88
|
+
onPress={onPress}
|
|
89
|
+
disabled={disabled || readonly}>
|
|
90
|
+
<Icon
|
|
91
|
+
style={componentStyles}
|
|
92
|
+
{...rest}
|
|
93
|
+
name={value >= index ? activeIconName : name}
|
|
94
|
+
type={value >= index ? activeIconType : type}
|
|
95
|
+
/>
|
|
96
|
+
</Pressable>
|
|
97
|
+
),
|
|
98
|
+
[
|
|
99
|
+
activeIconName,
|
|
100
|
+
activeIconType,
|
|
101
|
+
componentStyles,
|
|
102
|
+
disabled,
|
|
103
|
+
iconContainerStyle,
|
|
104
|
+
index,
|
|
105
|
+
name,
|
|
106
|
+
onPress,
|
|
107
|
+
readonly,
|
|
108
|
+
ref,
|
|
109
|
+
rest,
|
|
110
|
+
type,
|
|
111
|
+
value,
|
|
112
|
+
],
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
return showTooltips ? (
|
|
116
|
+
<Tooltip {...tooltipProps}>
|
|
117
|
+
<Tooltip.Trigger>{IconComponent}</Tooltip.Trigger>
|
|
118
|
+
<Tooltip.Content>{index}</Tooltip.Content>
|
|
119
|
+
</Tooltip>
|
|
120
|
+
) : (
|
|
121
|
+
IconComponent
|
|
122
|
+
);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export default memo(forwardRef(RatingItem));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getRegisteredComponentWithFallback, registerMoleculesComponents } from '../../core';
|
|
2
|
+
import RatingDefault from './Rating';
|
|
3
|
+
|
|
4
|
+
registerMoleculesComponents({
|
|
5
|
+
Rating: RatingDefault,
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export const Rating = getRegisteredComponentWithFallback('Rating', RatingDefault);
|
|
9
|
+
|
|
10
|
+
export type { Props as RatingProps } from './Rating';
|
|
11
|
+
export type { Props as RatingItemProps } from './RatingItem';
|
|
12
|
+
export type { States } from './utils';
|
|
13
|
+
export { ratingItemStyles, ratingStyles } from './utils';
|