rn-custom-ui 1.0.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/LICENSE +20 -0
- package/README.md +477 -0
- package/lib/module/assets/images/close.png +0 -0
- package/lib/module/components/CustomCheckbox/index.js +99 -0
- package/lib/module/components/CustomCheckbox/index.js.map +1 -0
- package/lib/module/components/CustomCheckbox/styles.js +213 -0
- package/lib/module/components/CustomCheckbox/styles.js.map +1 -0
- package/lib/module/components/CustomCheckbox/types.js +4 -0
- package/lib/module/components/CustomCheckbox/types.js.map +1 -0
- package/lib/module/components/closeButton/index.js +45 -0
- package/lib/module/components/closeButton/index.js.map +1 -0
- package/lib/module/components/closeButton/types.js +4 -0
- package/lib/module/components/closeButton/types.js.map +1 -0
- package/lib/module/components/customButton/index.js +176 -0
- package/lib/module/components/customButton/index.js.map +1 -0
- package/lib/module/components/customButton/styles.js +282 -0
- package/lib/module/components/customButton/styles.js.map +1 -0
- package/lib/module/components/customButton/types.js +4 -0
- package/lib/module/components/customButton/types.js.map +1 -0
- package/lib/module/components/customDropDown/DropDownBottomSheet.js +57 -0
- package/lib/module/components/customDropDown/DropDownBottomSheet.js.map +1 -0
- package/lib/module/components/customDropDown/DropDownList.js +51 -0
- package/lib/module/components/customDropDown/DropDownList.js.map +1 -0
- package/lib/module/components/customDropDown/DropDownListItem.js +38 -0
- package/lib/module/components/customDropDown/DropDownListItem.js.map +1 -0
- package/lib/module/components/customDropDown/DropDownListModal.js +63 -0
- package/lib/module/components/customDropDown/DropDownListModal.js.map +1 -0
- package/lib/module/components/customDropDown/index.js +143 -0
- package/lib/module/components/customDropDown/index.js.map +1 -0
- package/lib/module/components/customDropDown/styles.js +189 -0
- package/lib/module/components/customDropDown/styles.js.map +1 -0
- package/lib/module/components/customDropDown/types.js +4 -0
- package/lib/module/components/customDropDown/types.js.map +1 -0
- package/lib/module/components/customDropDown/utils.js +17 -0
- package/lib/module/components/customDropDown/utils.js.map +1 -0
- package/lib/module/components/customList/ListEmpty.js +33 -0
- package/lib/module/components/customList/ListEmpty.js.map +1 -0
- package/lib/module/components/customList/ListFooterLoader.js +14 -0
- package/lib/module/components/customList/ListFooterLoader.js.map +1 -0
- package/lib/module/components/customList/defaultKeyExtractor.js +9 -0
- package/lib/module/components/customList/defaultKeyExtractor.js.map +1 -0
- package/lib/module/components/customList/getFlashList.js +19 -0
- package/lib/module/components/customList/getFlashList.js.map +1 -0
- package/lib/module/components/customList/index.js +117 -0
- package/lib/module/components/customList/index.js.map +1 -0
- package/lib/module/components/customList/styles.js +45 -0
- package/lib/module/components/customList/styles.js.map +1 -0
- package/lib/module/components/customList/types.js +4 -0
- package/lib/module/components/customList/types.js.map +1 -0
- package/lib/module/components/customModal/ModalFooter.js +44 -0
- package/lib/module/components/customModal/ModalFooter.js.map +1 -0
- package/lib/module/components/customModal/index.js +132 -0
- package/lib/module/components/customModal/index.js.map +1 -0
- package/lib/module/components/customModal/styles.js +123 -0
- package/lib/module/components/customModal/styles.js.map +1 -0
- package/lib/module/components/customModal/types.js +4 -0
- package/lib/module/components/customModal/types.js.map +1 -0
- package/lib/module/components/customModal/useCustomModal.js +23 -0
- package/lib/module/components/customModal/useCustomModal.js.map +1 -0
- package/lib/module/components/customNumberPad/NumberPadKey.js +39 -0
- package/lib/module/components/customNumberPad/NumberPadKey.js.map +1 -0
- package/lib/module/components/customNumberPad/index.js +156 -0
- package/lib/module/components/customNumberPad/index.js.map +1 -0
- package/lib/module/components/customNumberPad/styles.js +131 -0
- package/lib/module/components/customNumberPad/styles.js.map +1 -0
- package/lib/module/components/customNumberPad/types.js +4 -0
- package/lib/module/components/customNumberPad/types.js.map +1 -0
- package/lib/module/components/customNumberPad/useNumberPadInput.js +44 -0
- package/lib/module/components/customNumberPad/useNumberPadInput.js.map +1 -0
- package/lib/module/components/customNumberPad/utils.js +38 -0
- package/lib/module/components/customNumberPad/utils.js.map +1 -0
- package/lib/module/components/customSlideTabs/AnimatedTabIndicator.js +66 -0
- package/lib/module/components/customSlideTabs/AnimatedTabIndicator.js.map +1 -0
- package/lib/module/components/customSlideTabs/TabBarItem.js +61 -0
- package/lib/module/components/customSlideTabs/TabBarItem.js.map +1 -0
- package/lib/module/components/customSlideTabs/TabScene.js +88 -0
- package/lib/module/components/customSlideTabs/TabScene.js.map +1 -0
- package/lib/module/components/customSlideTabs/index.js +277 -0
- package/lib/module/components/customSlideTabs/index.js.map +1 -0
- package/lib/module/components/customSlideTabs/styles.js +132 -0
- package/lib/module/components/customSlideTabs/styles.js.map +1 -0
- package/lib/module/components/customSlideTabs/tabBarScroll.js +65 -0
- package/lib/module/components/customSlideTabs/tabBarScroll.js.map +1 -0
- package/lib/module/components/customSlideTabs/types.js +4 -0
- package/lib/module/components/customSlideTabs/types.js.map +1 -0
- package/lib/module/components/loading/index.js +34 -0
- package/lib/module/components/loading/index.js.map +1 -0
- package/lib/module/customFunctions/array.js +61 -0
- package/lib/module/customFunctions/array.js.map +1 -0
- package/lib/module/customFunctions/async.js +62 -0
- package/lib/module/customFunctions/async.js.map +1 -0
- package/lib/module/customFunctions/date.js +109 -0
- package/lib/module/customFunctions/date.js.map +1 -0
- package/lib/module/customFunctions/general.js +29 -0
- package/lib/module/customFunctions/general.js.map +1 -0
- package/lib/module/customFunctions/id.js +20 -0
- package/lib/module/customFunctions/id.js.map +1 -0
- package/lib/module/customFunctions/index.js +29 -0
- package/lib/module/customFunctions/index.js.map +1 -0
- package/lib/module/customFunctions/number.js +94 -0
- package/lib/module/customFunctions/number.js.map +1 -0
- package/lib/module/customFunctions/object.js +39 -0
- package/lib/module/customFunctions/object.js.map +1 -0
- package/lib/module/customFunctions/string.js +63 -0
- package/lib/module/customFunctions/string.js.map +1 -0
- package/lib/module/customFunctions/types.js +2 -0
- package/lib/module/customFunctions/types.js.map +1 -0
- package/lib/module/customFunctions/validation.js +34 -0
- package/lib/module/customFunctions/validation.js.map +1 -0
- package/lib/module/customHooks/errors.js +61 -0
- package/lib/module/customHooks/errors.js.map +1 -0
- package/lib/module/customHooks/fetchJson.js +36 -0
- package/lib/module/customHooks/fetchJson.js.map +1 -0
- package/lib/module/customHooks/index.js +10 -0
- package/lib/module/customHooks/index.js.map +1 -0
- package/lib/module/customHooks/internal.js +49 -0
- package/lib/module/customHooks/internal.js.map +1 -0
- package/lib/module/customHooks/types.js +2 -0
- package/lib/module/customHooks/types.js.map +1 -0
- package/lib/module/customHooks/useApi.js +91 -0
- package/lib/module/customHooks/useApi.js.map +1 -0
- package/lib/module/customHooks/useLazyApi.js +80 -0
- package/lib/module/customHooks/useLazyApi.js.map +1 -0
- package/lib/module/customHooks/useMutation.js +69 -0
- package/lib/module/customHooks/useMutation.js.map +1 -0
- package/lib/module/customHooks/usePaginatedApi.js +127 -0
- package/lib/module/customHooks/usePaginatedApi.js.map +1 -0
- package/lib/module/customHooks/usePollingApi.js +37 -0
- package/lib/module/customHooks/usePollingApi.js.map +1 -0
- package/lib/module/index.js +13 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/multiply.js +6 -0
- package/lib/module/multiply.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/components/CustomCheckbox/index.d.ts +5 -0
- package/lib/typescript/src/components/CustomCheckbox/index.d.ts.map +1 -0
- package/lib/typescript/src/components/CustomCheckbox/styles.d.ts +67 -0
- package/lib/typescript/src/components/CustomCheckbox/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/CustomCheckbox/types.d.ts +28 -0
- package/lib/typescript/src/components/CustomCheckbox/types.d.ts.map +1 -0
- package/lib/typescript/src/components/closeButton/index.d.ts +4 -0
- package/lib/typescript/src/components/closeButton/index.d.ts.map +1 -0
- package/lib/typescript/src/components/closeButton/types.d.ts +8 -0
- package/lib/typescript/src/components/closeButton/types.d.ts.map +1 -0
- package/lib/typescript/src/components/customButton/index.d.ts +5 -0
- package/lib/typescript/src/components/customButton/index.d.ts.map +1 -0
- package/lib/typescript/src/components/customButton/styles.d.ts +231 -0
- package/lib/typescript/src/components/customButton/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/customButton/types.d.ts +46 -0
- package/lib/typescript/src/components/customButton/types.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/DropDownBottomSheet.d.ts +18 -0
- package/lib/typescript/src/components/customDropDown/DropDownBottomSheet.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/DropDownList.d.ts +17 -0
- package/lib/typescript/src/components/customDropDown/DropDownList.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/DropDownListItem.d.ts +15 -0
- package/lib/typescript/src/components/customDropDown/DropDownListItem.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/DropDownListModal.d.ts +19 -0
- package/lib/typescript/src/components/customDropDown/DropDownListModal.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/index.d.ts +5 -0
- package/lib/typescript/src/components/customDropDown/index.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/styles.d.ts +190 -0
- package/lib/typescript/src/components/customDropDown/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/types.d.ts +37 -0
- package/lib/typescript/src/components/customDropDown/types.d.ts.map +1 -0
- package/lib/typescript/src/components/customDropDown/utils.d.ts +4 -0
- package/lib/typescript/src/components/customDropDown/utils.d.ts.map +1 -0
- package/lib/typescript/src/components/customList/ListEmpty.d.ts +10 -0
- package/lib/typescript/src/components/customList/ListEmpty.d.ts.map +1 -0
- package/lib/typescript/src/components/customList/ListFooterLoader.d.ts +3 -0
- package/lib/typescript/src/components/customList/ListFooterLoader.d.ts.map +1 -0
- package/lib/typescript/src/components/customList/defaultKeyExtractor.d.ts +2 -0
- package/lib/typescript/src/components/customList/defaultKeyExtractor.d.ts.map +1 -0
- package/lib/typescript/src/components/customList/getFlashList.d.ts +6 -0
- package/lib/typescript/src/components/customList/getFlashList.d.ts.map +1 -0
- package/lib/typescript/src/components/customList/index.d.ts +11 -0
- package/lib/typescript/src/components/customList/index.d.ts.map +1 -0
- package/lib/typescript/src/components/customList/styles.d.ts +42 -0
- package/lib/typescript/src/components/customList/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/customList/types.d.ts +33 -0
- package/lib/typescript/src/components/customList/types.d.ts.map +1 -0
- package/lib/typescript/src/components/customModal/ModalFooter.d.ts +12 -0
- package/lib/typescript/src/components/customModal/ModalFooter.d.ts.map +1 -0
- package/lib/typescript/src/components/customModal/index.d.ts +6 -0
- package/lib/typescript/src/components/customModal/index.d.ts.map +1 -0
- package/lib/typescript/src/components/customModal/styles.d.ts +83 -0
- package/lib/typescript/src/components/customModal/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/customModal/types.d.ts +36 -0
- package/lib/typescript/src/components/customModal/types.d.ts.map +1 -0
- package/lib/typescript/src/components/customModal/useCustomModal.d.ts +8 -0
- package/lib/typescript/src/components/customModal/useCustomModal.d.ts.map +1 -0
- package/lib/typescript/src/components/customNumberPad/NumberPadKey.d.ts +23 -0
- package/lib/typescript/src/components/customNumberPad/NumberPadKey.d.ts.map +1 -0
- package/lib/typescript/src/components/customNumberPad/index.d.ts +7 -0
- package/lib/typescript/src/components/customNumberPad/index.d.ts.map +1 -0
- package/lib/typescript/src/components/customNumberPad/styles.d.ts +37 -0
- package/lib/typescript/src/components/customNumberPad/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/customNumberPad/types.d.ts +47 -0
- package/lib/typescript/src/components/customNumberPad/types.d.ts.map +1 -0
- package/lib/typescript/src/components/customNumberPad/useNumberPadInput.d.ts +16 -0
- package/lib/typescript/src/components/customNumberPad/useNumberPadInput.d.ts.map +1 -0
- package/lib/typescript/src/components/customNumberPad/utils.d.ts +4 -0
- package/lib/typescript/src/components/customNumberPad/utils.d.ts.map +1 -0
- package/lib/typescript/src/components/customSlideTabs/AnimatedTabIndicator.d.ts +16 -0
- package/lib/typescript/src/components/customSlideTabs/AnimatedTabIndicator.d.ts.map +1 -0
- package/lib/typescript/src/components/customSlideTabs/TabBarItem.d.ts +23 -0
- package/lib/typescript/src/components/customSlideTabs/TabBarItem.d.ts.map +1 -0
- package/lib/typescript/src/components/customSlideTabs/TabScene.d.ts +21 -0
- package/lib/typescript/src/components/customSlideTabs/TabScene.d.ts.map +1 -0
- package/lib/typescript/src/components/customSlideTabs/index.d.ts +5 -0
- package/lib/typescript/src/components/customSlideTabs/index.d.ts.map +1 -0
- package/lib/typescript/src/components/customSlideTabs/styles.d.ts +130 -0
- package/lib/typescript/src/components/customSlideTabs/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/customSlideTabs/tabBarScroll.d.ts +15 -0
- package/lib/typescript/src/components/customSlideTabs/tabBarScroll.d.ts.map +1 -0
- package/lib/typescript/src/components/customSlideTabs/types.d.ts +68 -0
- package/lib/typescript/src/components/customSlideTabs/types.d.ts.map +1 -0
- package/lib/typescript/src/components/loading/index.d.ts +7 -0
- package/lib/typescript/src/components/loading/index.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/array.d.ts +7 -0
- package/lib/typescript/src/customFunctions/array.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/async.d.ts +9 -0
- package/lib/typescript/src/customFunctions/async.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/date.d.ts +18 -0
- package/lib/typescript/src/customFunctions/date.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/general.d.ts +7 -0
- package/lib/typescript/src/customFunctions/general.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/id.d.ts +4 -0
- package/lib/typescript/src/customFunctions/id.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/index.d.ts +26 -0
- package/lib/typescript/src/customFunctions/index.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/number.d.ts +15 -0
- package/lib/typescript/src/customFunctions/number.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/object.d.ts +6 -0
- package/lib/typescript/src/customFunctions/object.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/string.d.ts +20 -0
- package/lib/typescript/src/customFunctions/string.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/types.d.ts +22 -0
- package/lib/typescript/src/customFunctions/types.d.ts.map +1 -0
- package/lib/typescript/src/customFunctions/validation.d.ts +11 -0
- package/lib/typescript/src/customFunctions/validation.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/errors.d.ts +16 -0
- package/lib/typescript/src/customHooks/errors.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/fetchJson.d.ts +5 -0
- package/lib/typescript/src/customHooks/fetchJson.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/index.d.ts +9 -0
- package/lib/typescript/src/customHooks/index.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/internal.d.ts +12 -0
- package/lib/typescript/src/customHooks/internal.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/types.d.ts +49 -0
- package/lib/typescript/src/customHooks/types.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/useApi.d.ts +13 -0
- package/lib/typescript/src/customHooks/useApi.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/useLazyApi.d.ts +14 -0
- package/lib/typescript/src/customHooks/useLazyApi.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/useMutation.d.ts +15 -0
- package/lib/typescript/src/customHooks/useMutation.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/usePaginatedApi.d.ts +19 -0
- package/lib/typescript/src/customHooks/usePaginatedApi.d.ts.map +1 -0
- package/lib/typescript/src/customHooks/usePollingApi.d.ts +13 -0
- package/lib/typescript/src/customHooks/usePollingApi.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +11 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/multiply.d.ts +2 -0
- package/lib/typescript/src/multiply.d.ts.map +1 -0
- package/package.json +181 -0
- package/src/assets/images/close.png +0 -0
- package/src/components/CustomCheckbox/index.tsx +143 -0
- package/src/components/CustomCheckbox/styles.ts +146 -0
- package/src/components/CustomCheckbox/types.ts +33 -0
- package/src/components/closeButton/index.tsx +40 -0
- package/src/components/closeButton/types.ts +13 -0
- package/src/components/customButton/index.tsx +288 -0
- package/src/components/customButton/styles.ts +247 -0
- package/src/components/customButton/types.ts +71 -0
- package/src/components/customDropDown/DropDownBottomSheet.tsx +70 -0
- package/src/components/customDropDown/DropDownList.tsx +88 -0
- package/src/components/customDropDown/DropDownListItem.tsx +74 -0
- package/src/components/customDropDown/DropDownListModal.tsx +86 -0
- package/src/components/customDropDown/index.tsx +213 -0
- package/src/components/customDropDown/styles.ts +184 -0
- package/src/components/customDropDown/types.ts +48 -0
- package/src/components/customDropDown/utils.ts +24 -0
- package/src/components/customList/ListEmpty.tsx +36 -0
- package/src/components/customList/ListFooterLoader.tsx +11 -0
- package/src/components/customList/defaultKeyExtractor.ts +7 -0
- package/src/components/customList/getFlashList.ts +26 -0
- package/src/components/customList/index.tsx +142 -0
- package/src/components/customList/styles.ts +43 -0
- package/src/components/customList/types.ts +60 -0
- package/src/components/customModal/ModalFooter.tsx +57 -0
- package/src/components/customModal/index.tsx +166 -0
- package/src/components/customModal/styles.ts +131 -0
- package/src/components/customModal/types.ts +48 -0
- package/src/components/customModal/useCustomModal.ts +25 -0
- package/src/components/customNumberPad/NumberPadKey.tsx +81 -0
- package/src/components/customNumberPad/index.tsx +204 -0
- package/src/components/customNumberPad/styles.ts +146 -0
- package/src/components/customNumberPad/types.ts +53 -0
- package/src/components/customNumberPad/useNumberPadInput.ts +56 -0
- package/src/components/customNumberPad/utils.ts +54 -0
- package/src/components/customSlideTabs/AnimatedTabIndicator.tsx +103 -0
- package/src/components/customSlideTabs/TabBarItem.tsx +118 -0
- package/src/components/customSlideTabs/TabScene.tsx +136 -0
- package/src/components/customSlideTabs/index.tsx +385 -0
- package/src/components/customSlideTabs/styles.ts +136 -0
- package/src/components/customSlideTabs/tabBarScroll.ts +92 -0
- package/src/components/customSlideTabs/types.ts +87 -0
- package/src/components/loading/index.tsx +34 -0
- package/src/customFunctions/array.ts +83 -0
- package/src/customFunctions/async.ts +85 -0
- package/src/customFunctions/date.ts +158 -0
- package/src/customFunctions/general.ts +35 -0
- package/src/customFunctions/id.ts +25 -0
- package/src/customFunctions/index.ts +91 -0
- package/src/customFunctions/number.ts +139 -0
- package/src/customFunctions/object.ts +59 -0
- package/src/customFunctions/string.ts +119 -0
- package/src/customFunctions/types.ts +25 -0
- package/src/customFunctions/validation.ts +49 -0
- package/src/customHooks/errors.ts +87 -0
- package/src/customHooks/fetchJson.ts +49 -0
- package/src/customHooks/index.ts +20 -0
- package/src/customHooks/internal.ts +67 -0
- package/src/customHooks/types.ts +71 -0
- package/src/customHooks/useApi.ts +107 -0
- package/src/customHooks/useLazyApi.ts +92 -0
- package/src/customHooks/useMutation.ts +97 -0
- package/src/customHooks/usePaginatedApi.ts +168 -0
- package/src/customHooks/usePollingApi.ts +48 -0
- package/src/index.tsx +63 -0
- package/src/multiply.tsx +3 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
ImageSourcePropType,
|
|
4
|
+
ModalProps,
|
|
5
|
+
StyleProp,
|
|
6
|
+
TextStyle,
|
|
7
|
+
ViewStyle,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
|
|
10
|
+
import type { ButtonVariant } from '../customButton/types';
|
|
11
|
+
|
|
12
|
+
export type ModalPresentation = 'center' | 'bottom' | 'fullscreen';
|
|
13
|
+
|
|
14
|
+
export type ModalAction = {
|
|
15
|
+
label: string;
|
|
16
|
+
onPress: () => void;
|
|
17
|
+
variant?: ButtonVariant;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
isLoading?: boolean;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type CustomModalProps = Pick<
|
|
23
|
+
ModalProps,
|
|
24
|
+
'supportedOrientations' | 'statusBarTranslucent' | 'testID'
|
|
25
|
+
> & {
|
|
26
|
+
visible: boolean;
|
|
27
|
+
onClose: () => void;
|
|
28
|
+
title?: string;
|
|
29
|
+
description?: string;
|
|
30
|
+
children?: ReactNode;
|
|
31
|
+
presentation?: ModalPresentation;
|
|
32
|
+
showCloseButton?: boolean;
|
|
33
|
+
closeOnBackdropPress?: boolean;
|
|
34
|
+
animationType?: ModalProps['animationType'];
|
|
35
|
+
scrollable?: boolean;
|
|
36
|
+
containerStyle?: StyleProp<ViewStyle>;
|
|
37
|
+
backdropStyle?: StyleProp<ViewStyle>;
|
|
38
|
+
contentStyle?: StyleProp<ViewStyle>;
|
|
39
|
+
headerStyle?: StyleProp<ViewStyle>;
|
|
40
|
+
titleStyle?: StyleProp<TextStyle>;
|
|
41
|
+
descriptionStyle?: StyleProp<TextStyle>;
|
|
42
|
+
bodyStyle?: StyleProp<ViewStyle>;
|
|
43
|
+
footerStyle?: StyleProp<ViewStyle>;
|
|
44
|
+
footer?: ReactNode;
|
|
45
|
+
primaryAction?: ModalAction;
|
|
46
|
+
secondaryAction?: ModalAction;
|
|
47
|
+
closeImage?: ImageSourcePropType;
|
|
48
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export const useCustomModal = (initialVisible = false) => {
|
|
4
|
+
const [visible, setVisible] = useState(initialVisible);
|
|
5
|
+
|
|
6
|
+
const open = useCallback(() => {
|
|
7
|
+
setVisible(true);
|
|
8
|
+
}, []);
|
|
9
|
+
|
|
10
|
+
const close = useCallback(() => {
|
|
11
|
+
setVisible(false);
|
|
12
|
+
}, []);
|
|
13
|
+
|
|
14
|
+
const toggle = useCallback(() => {
|
|
15
|
+
setVisible((current) => !current);
|
|
16
|
+
}, []);
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
visible,
|
|
20
|
+
setVisible,
|
|
21
|
+
open,
|
|
22
|
+
close,
|
|
23
|
+
toggle,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Pressable,
|
|
4
|
+
Text,
|
|
5
|
+
type StyleProp,
|
|
6
|
+
type TextStyle,
|
|
7
|
+
type ViewStyle,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
|
|
10
|
+
import { styles } from './styles';
|
|
11
|
+
import type { NumberPadKeyConfig } from './types';
|
|
12
|
+
|
|
13
|
+
type NumberPadKeyProps = {
|
|
14
|
+
config: NumberPadKeyConfig;
|
|
15
|
+
onPress: () => void;
|
|
16
|
+
keyStyle?: StyleProp<ViewStyle>;
|
|
17
|
+
keyTextStyle?: StyleProp<TextStyle>;
|
|
18
|
+
theme: {
|
|
19
|
+
key: ViewStyle;
|
|
20
|
+
keyPressed: ViewStyle;
|
|
21
|
+
keyText: TextStyle;
|
|
22
|
+
keyTextMuted: TextStyle;
|
|
23
|
+
keyDisabled: ViewStyle;
|
|
24
|
+
};
|
|
25
|
+
sizeStyle: {
|
|
26
|
+
key: ViewStyle;
|
|
27
|
+
keyText: TextStyle;
|
|
28
|
+
};
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const NumberPadKey = ({
|
|
33
|
+
config,
|
|
34
|
+
onPress,
|
|
35
|
+
keyStyle,
|
|
36
|
+
keyTextStyle,
|
|
37
|
+
theme,
|
|
38
|
+
sizeStyle,
|
|
39
|
+
disabled = false,
|
|
40
|
+
}: NumberPadKeyProps) => {
|
|
41
|
+
const [pressed, setPressed] = useState(false);
|
|
42
|
+
const isDisabled = disabled || config.disabled;
|
|
43
|
+
const isMuted = config.type === 'backspace' || config.type === 'decimal';
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Pressable
|
|
47
|
+
accessibilityRole="keyboardkey"
|
|
48
|
+
accessibilityLabel={
|
|
49
|
+
config.accessibilityLabel ??
|
|
50
|
+
(typeof config.label === 'string' ? config.label : config.id)
|
|
51
|
+
}
|
|
52
|
+
accessibilityState={{ disabled: isDisabled }}
|
|
53
|
+
disabled={isDisabled}
|
|
54
|
+
onPress={onPress}
|
|
55
|
+
onPressIn={() => setPressed(true)}
|
|
56
|
+
onPressOut={() => setPressed(false)}
|
|
57
|
+
style={[
|
|
58
|
+
styles.key,
|
|
59
|
+
sizeStyle.key,
|
|
60
|
+
theme.key,
|
|
61
|
+
{ flex: config.flex ?? 1 },
|
|
62
|
+
pressed && !isDisabled && theme.keyPressed,
|
|
63
|
+
isDisabled && theme.keyDisabled,
|
|
64
|
+
keyStyle,
|
|
65
|
+
]}
|
|
66
|
+
>
|
|
67
|
+
<Text
|
|
68
|
+
style={[
|
|
69
|
+
styles.keyText,
|
|
70
|
+
sizeStyle.keyText,
|
|
71
|
+
isMuted ? theme.keyTextMuted : theme.keyText,
|
|
72
|
+
keyTextStyle,
|
|
73
|
+
]}
|
|
74
|
+
>
|
|
75
|
+
{config.label}
|
|
76
|
+
</Text>
|
|
77
|
+
</Pressable>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export default NumberPadKey;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import NumberPadKey from './NumberPadKey';
|
|
5
|
+
import { sizeStyles, styles, variantTheme } from './styles';
|
|
6
|
+
import type { CustomNumberPadProps, NumberPadKeyConfig } from './types';
|
|
7
|
+
import { applyNumberPadKey, NUMBER_PAD_ROWS } from './utils';
|
|
8
|
+
|
|
9
|
+
const CustomNumberPad = ({
|
|
10
|
+
onKeyPress,
|
|
11
|
+
onBackspace,
|
|
12
|
+
value,
|
|
13
|
+
onChange,
|
|
14
|
+
maxLength,
|
|
15
|
+
allowDecimal = false,
|
|
16
|
+
decimalPlaces,
|
|
17
|
+
variant = 'default',
|
|
18
|
+
size = 'md',
|
|
19
|
+
disabled = false,
|
|
20
|
+
containerStyle,
|
|
21
|
+
rowStyle,
|
|
22
|
+
keyStyle,
|
|
23
|
+
keyTextStyle,
|
|
24
|
+
backspaceLabel = '⌫',
|
|
25
|
+
bottomLeftKey,
|
|
26
|
+
renderKey,
|
|
27
|
+
}: CustomNumberPadProps) => {
|
|
28
|
+
const theme = variantTheme[variant];
|
|
29
|
+
const sizing = sizeStyles[size];
|
|
30
|
+
|
|
31
|
+
const inputRules = useMemo(
|
|
32
|
+
() => ({ maxLength, allowDecimal, decimalPlaces }),
|
|
33
|
+
[allowDecimal, decimalPlaces, maxLength]
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const handleKey = useCallback(
|
|
37
|
+
(key: string, customPress?: () => void) => {
|
|
38
|
+
if (disabled) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (customPress) {
|
|
43
|
+
customPress();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (key === 'backspace') {
|
|
48
|
+
onBackspace?.();
|
|
49
|
+
|
|
50
|
+
if (onChange) {
|
|
51
|
+
onChange(
|
|
52
|
+
applyNumberPadKey(value ?? '', 'backspace', inputRules) ?? ''
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
onKeyPress?.('backspace');
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
onKeyPress?.(key);
|
|
61
|
+
|
|
62
|
+
if (onChange) {
|
|
63
|
+
const next = applyNumberPadKey(value ?? '', key, inputRules);
|
|
64
|
+
if (next != null) {
|
|
65
|
+
onChange(next);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
[disabled, inputRules, onBackspace, onChange, onKeyPress, value]
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const digitRows: NumberPadKeyConfig[][] = useMemo(
|
|
73
|
+
() =>
|
|
74
|
+
NUMBER_PAD_ROWS.map((row) =>
|
|
75
|
+
row.map((digit) => ({
|
|
76
|
+
id: digit,
|
|
77
|
+
label: digit,
|
|
78
|
+
value: digit,
|
|
79
|
+
type: 'digit' as const,
|
|
80
|
+
accessibilityLabel: `Number ${digit}`,
|
|
81
|
+
}))
|
|
82
|
+
),
|
|
83
|
+
[]
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const bottomRow = useMemo<NumberPadKeyConfig[]>(() => {
|
|
87
|
+
const keys: NumberPadKeyConfig[] = [];
|
|
88
|
+
|
|
89
|
+
if (bottomLeftKey) {
|
|
90
|
+
keys.push({
|
|
91
|
+
id: 'custom-bottom-left',
|
|
92
|
+
label: bottomLeftKey.label,
|
|
93
|
+
type: 'custom',
|
|
94
|
+
onPress: bottomLeftKey.onPress,
|
|
95
|
+
disabled: bottomLeftKey.disabled,
|
|
96
|
+
accessibilityLabel: bottomLeftKey.accessibilityLabel,
|
|
97
|
+
});
|
|
98
|
+
} else if (allowDecimal) {
|
|
99
|
+
keys.push({
|
|
100
|
+
id: 'decimal',
|
|
101
|
+
label: '.',
|
|
102
|
+
value: '.',
|
|
103
|
+
type: 'decimal',
|
|
104
|
+
accessibilityLabel: 'Decimal point',
|
|
105
|
+
});
|
|
106
|
+
} else {
|
|
107
|
+
keys.push({
|
|
108
|
+
id: 'spacer',
|
|
109
|
+
label: '',
|
|
110
|
+
type: 'custom',
|
|
111
|
+
flex: 1,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
keys.push({
|
|
116
|
+
id: '0',
|
|
117
|
+
label: '0',
|
|
118
|
+
value: '0',
|
|
119
|
+
type: 'digit',
|
|
120
|
+
accessibilityLabel: 'Number 0',
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
keys.push({
|
|
124
|
+
id: 'backspace',
|
|
125
|
+
label: backspaceLabel,
|
|
126
|
+
value: 'backspace',
|
|
127
|
+
type: 'backspace',
|
|
128
|
+
accessibilityLabel: 'Backspace',
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
return keys;
|
|
132
|
+
}, [allowDecimal, backspaceLabel, bottomLeftKey]);
|
|
133
|
+
|
|
134
|
+
const rows = [...digitRows, bottomRow];
|
|
135
|
+
|
|
136
|
+
const renderPadKey = (config: NumberPadKeyConfig) => {
|
|
137
|
+
if (config.id === 'spacer') {
|
|
138
|
+
return <View key={config.id} style={styles.spacer} />;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const onPress = () => {
|
|
142
|
+
if (config.type === 'custom') {
|
|
143
|
+
handleKey('', config.onPress);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
handleKey(config.value ?? '');
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
if (renderKey) {
|
|
151
|
+
return (
|
|
152
|
+
<View key={config.id} style={{ flex: config.flex ?? 1 }}>
|
|
153
|
+
{renderKey(config, onPress)}
|
|
154
|
+
</View>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<NumberPadKey
|
|
160
|
+
key={config.id}
|
|
161
|
+
config={config}
|
|
162
|
+
disabled={disabled}
|
|
163
|
+
keyStyle={keyStyle}
|
|
164
|
+
keyTextStyle={keyTextStyle}
|
|
165
|
+
onPress={onPress}
|
|
166
|
+
sizeStyle={sizing}
|
|
167
|
+
theme={theme}
|
|
168
|
+
/>
|
|
169
|
+
);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
return (
|
|
173
|
+
<View
|
|
174
|
+
style={[
|
|
175
|
+
styles.container,
|
|
176
|
+
theme.container,
|
|
177
|
+
{ gap: sizing.gap },
|
|
178
|
+
containerStyle,
|
|
179
|
+
]}
|
|
180
|
+
>
|
|
181
|
+
{rows.map((row, rowIndex) => (
|
|
182
|
+
<View
|
|
183
|
+
key={`row-${rowIndex}`}
|
|
184
|
+
style={[styles.row, { gap: sizing.gap }, rowStyle]}
|
|
185
|
+
>
|
|
186
|
+
{row.map(renderPadKey)}
|
|
187
|
+
</View>
|
|
188
|
+
))}
|
|
189
|
+
</View>
|
|
190
|
+
);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
export default CustomNumberPad;
|
|
194
|
+
export { applyNumberPadKey, NUMBER_PAD_ROWS } from './utils';
|
|
195
|
+
export { useNumberPadInput } from './useNumberPadInput';
|
|
196
|
+
export type {
|
|
197
|
+
CustomNumberPadProps,
|
|
198
|
+
NumberPadBottomLeftKey,
|
|
199
|
+
NumberPadKeyConfig,
|
|
200
|
+
NumberPadKeyType,
|
|
201
|
+
NumberPadSize,
|
|
202
|
+
NumberPadVariant,
|
|
203
|
+
UseNumberPadInputOptions,
|
|
204
|
+
} from './types';
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { StyleSheet, type TextStyle, type ViewStyle } from 'react-native';
|
|
2
|
+
|
|
3
|
+
import type { NumberPadSize, NumberPadVariant } from './types';
|
|
4
|
+
|
|
5
|
+
export const sizeStyles: Record<
|
|
6
|
+
NumberPadSize,
|
|
7
|
+
{ key: ViewStyle; keyText: TextStyle; gap: number }
|
|
8
|
+
> = {
|
|
9
|
+
sm: {
|
|
10
|
+
key: {
|
|
11
|
+
minHeight: 44,
|
|
12
|
+
borderRadius: 8,
|
|
13
|
+
},
|
|
14
|
+
keyText: {
|
|
15
|
+
fontSize: 20,
|
|
16
|
+
},
|
|
17
|
+
gap: 8,
|
|
18
|
+
},
|
|
19
|
+
md: {
|
|
20
|
+
key: {
|
|
21
|
+
minHeight: 52,
|
|
22
|
+
borderRadius: 10,
|
|
23
|
+
},
|
|
24
|
+
keyText: {
|
|
25
|
+
fontSize: 24,
|
|
26
|
+
},
|
|
27
|
+
gap: 10,
|
|
28
|
+
},
|
|
29
|
+
lg: {
|
|
30
|
+
key: {
|
|
31
|
+
minHeight: 60,
|
|
32
|
+
borderRadius: 12,
|
|
33
|
+
},
|
|
34
|
+
keyText: {
|
|
35
|
+
fontSize: 28,
|
|
36
|
+
},
|
|
37
|
+
gap: 12,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const variantTheme: Record<
|
|
42
|
+
NumberPadVariant,
|
|
43
|
+
{
|
|
44
|
+
container: ViewStyle;
|
|
45
|
+
key: ViewStyle;
|
|
46
|
+
keyPressed: ViewStyle;
|
|
47
|
+
keyText: TextStyle;
|
|
48
|
+
keyTextMuted: TextStyle;
|
|
49
|
+
keyDisabled: ViewStyle;
|
|
50
|
+
}
|
|
51
|
+
> = {
|
|
52
|
+
default: {
|
|
53
|
+
container: {
|
|
54
|
+
backgroundColor: '#F8F9FA',
|
|
55
|
+
},
|
|
56
|
+
key: {
|
|
57
|
+
backgroundColor: '#FFFFFF',
|
|
58
|
+
borderWidth: 1,
|
|
59
|
+
borderColor: '#E9ECEF',
|
|
60
|
+
},
|
|
61
|
+
keyPressed: {
|
|
62
|
+
backgroundColor: '#E9ECEF',
|
|
63
|
+
},
|
|
64
|
+
keyText: {
|
|
65
|
+
color: '#212529',
|
|
66
|
+
fontWeight: '600',
|
|
67
|
+
},
|
|
68
|
+
keyTextMuted: {
|
|
69
|
+
color: '#6C757D',
|
|
70
|
+
fontWeight: '600',
|
|
71
|
+
},
|
|
72
|
+
keyDisabled: {
|
|
73
|
+
opacity: 0.45,
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
primary: {
|
|
77
|
+
container: {
|
|
78
|
+
backgroundColor: '#E7F1FF',
|
|
79
|
+
},
|
|
80
|
+
key: {
|
|
81
|
+
backgroundColor: '#FFFFFF',
|
|
82
|
+
borderWidth: 1,
|
|
83
|
+
borderColor: '#B6D4FE',
|
|
84
|
+
},
|
|
85
|
+
keyPressed: {
|
|
86
|
+
backgroundColor: '#CFE2FF',
|
|
87
|
+
},
|
|
88
|
+
keyText: {
|
|
89
|
+
color: '#0D6EFD',
|
|
90
|
+
fontWeight: '700',
|
|
91
|
+
},
|
|
92
|
+
keyTextMuted: {
|
|
93
|
+
color: '#6EA8FE',
|
|
94
|
+
fontWeight: '700',
|
|
95
|
+
},
|
|
96
|
+
keyDisabled: {
|
|
97
|
+
opacity: 0.45,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
dark: {
|
|
101
|
+
container: {
|
|
102
|
+
backgroundColor: '#212529',
|
|
103
|
+
},
|
|
104
|
+
key: {
|
|
105
|
+
backgroundColor: '#343A40',
|
|
106
|
+
borderWidth: 1,
|
|
107
|
+
borderColor: '#495057',
|
|
108
|
+
},
|
|
109
|
+
keyPressed: {
|
|
110
|
+
backgroundColor: '#495057',
|
|
111
|
+
},
|
|
112
|
+
keyText: {
|
|
113
|
+
color: '#F8F9FA',
|
|
114
|
+
fontWeight: '600',
|
|
115
|
+
},
|
|
116
|
+
keyTextMuted: {
|
|
117
|
+
color: '#ADB5BD',
|
|
118
|
+
fontWeight: '600',
|
|
119
|
+
},
|
|
120
|
+
keyDisabled: {
|
|
121
|
+
opacity: 0.45,
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export const styles = StyleSheet.create({
|
|
127
|
+
container: {
|
|
128
|
+
padding: 12,
|
|
129
|
+
borderRadius: 16,
|
|
130
|
+
},
|
|
131
|
+
row: {
|
|
132
|
+
flexDirection: 'row',
|
|
133
|
+
alignItems: 'stretch',
|
|
134
|
+
},
|
|
135
|
+
key: {
|
|
136
|
+
flex: 1,
|
|
137
|
+
alignItems: 'center',
|
|
138
|
+
justifyContent: 'center',
|
|
139
|
+
},
|
|
140
|
+
keyText: {
|
|
141
|
+
textAlign: 'center',
|
|
142
|
+
},
|
|
143
|
+
spacer: {
|
|
144
|
+
flex: 1,
|
|
145
|
+
},
|
|
146
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { StyleProp, TextStyle, ViewStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export type NumberPadVariant = 'default' | 'primary' | 'dark';
|
|
5
|
+
|
|
6
|
+
export type NumberPadSize = 'sm' | 'md' | 'lg';
|
|
7
|
+
|
|
8
|
+
export type NumberPadKeyType = 'digit' | 'decimal' | 'backspace' | 'custom';
|
|
9
|
+
|
|
10
|
+
export type NumberPadKeyConfig = {
|
|
11
|
+
id: string;
|
|
12
|
+
label: ReactNode;
|
|
13
|
+
value?: string;
|
|
14
|
+
type: NumberPadKeyType;
|
|
15
|
+
flex?: number;
|
|
16
|
+
onPress?: () => void;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
accessibilityLabel?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type NumberPadBottomLeftKey = {
|
|
22
|
+
label: ReactNode;
|
|
23
|
+
onPress: () => void;
|
|
24
|
+
accessibilityLabel?: string;
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type CustomNumberPadProps = {
|
|
29
|
+
onKeyPress?: (key: string) => void;
|
|
30
|
+
onBackspace?: () => void;
|
|
31
|
+
value?: string;
|
|
32
|
+
onChange?: (value: string) => void;
|
|
33
|
+
maxLength?: number;
|
|
34
|
+
allowDecimal?: boolean;
|
|
35
|
+
decimalPlaces?: number;
|
|
36
|
+
variant?: NumberPadVariant;
|
|
37
|
+
size?: NumberPadSize;
|
|
38
|
+
disabled?: boolean;
|
|
39
|
+
containerStyle?: StyleProp<ViewStyle>;
|
|
40
|
+
rowStyle?: StyleProp<ViewStyle>;
|
|
41
|
+
keyStyle?: StyleProp<ViewStyle>;
|
|
42
|
+
keyTextStyle?: StyleProp<TextStyle>;
|
|
43
|
+
backspaceLabel?: ReactNode;
|
|
44
|
+
bottomLeftKey?: NumberPadBottomLeftKey;
|
|
45
|
+
renderKey?: (key: NumberPadKeyConfig, onPress: () => void) => ReactNode;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type UseNumberPadInputOptions = {
|
|
49
|
+
initialValue?: string;
|
|
50
|
+
maxLength?: number;
|
|
51
|
+
allowDecimal?: boolean;
|
|
52
|
+
decimalPlaces?: number;
|
|
53
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { applyNumberPadKey } from './utils';
|
|
4
|
+
import type { UseNumberPadInputOptions } from './types';
|
|
5
|
+
|
|
6
|
+
export const useNumberPadInput = ({
|
|
7
|
+
initialValue = '',
|
|
8
|
+
maxLength,
|
|
9
|
+
allowDecimal = false,
|
|
10
|
+
decimalPlaces,
|
|
11
|
+
}: UseNumberPadInputOptions = {}) => {
|
|
12
|
+
const [value, setValue] = useState(initialValue);
|
|
13
|
+
|
|
14
|
+
const handleChange = useCallback((nextValue: string) => {
|
|
15
|
+
setValue(nextValue);
|
|
16
|
+
}, []);
|
|
17
|
+
|
|
18
|
+
const handleKeyPress = useCallback(
|
|
19
|
+
(key: string) => {
|
|
20
|
+
setValue((current) => {
|
|
21
|
+
const next = applyNumberPadKey(current, key, {
|
|
22
|
+
maxLength,
|
|
23
|
+
allowDecimal,
|
|
24
|
+
decimalPlaces,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return next ?? current;
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
[allowDecimal, decimalPlaces, maxLength]
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const clear = useCallback(() => {
|
|
34
|
+
setValue('');
|
|
35
|
+
}, []);
|
|
36
|
+
|
|
37
|
+
const numberPadProps = useMemo(
|
|
38
|
+
() => ({
|
|
39
|
+
value,
|
|
40
|
+
onChange: handleChange,
|
|
41
|
+
maxLength,
|
|
42
|
+
allowDecimal,
|
|
43
|
+
decimalPlaces,
|
|
44
|
+
}),
|
|
45
|
+
[allowDecimal, decimalPlaces, handleChange, maxLength, value]
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
value,
|
|
50
|
+
setValue,
|
|
51
|
+
clear,
|
|
52
|
+
handleChange,
|
|
53
|
+
handleKeyPress,
|
|
54
|
+
numberPadProps,
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { UseNumberPadInputOptions } from './types';
|
|
2
|
+
|
|
3
|
+
export const NUMBER_PAD_ROWS = [
|
|
4
|
+
['1', '2', '3'],
|
|
5
|
+
['4', '5', '6'],
|
|
6
|
+
['7', '8', '9'],
|
|
7
|
+
] as const;
|
|
8
|
+
|
|
9
|
+
export const applyNumberPadKey = (
|
|
10
|
+
value: string,
|
|
11
|
+
key: string,
|
|
12
|
+
options: Pick<
|
|
13
|
+
UseNumberPadInputOptions,
|
|
14
|
+
'maxLength' | 'allowDecimal' | 'decimalPlaces'
|
|
15
|
+
> = {}
|
|
16
|
+
): string | null => {
|
|
17
|
+
const { maxLength, allowDecimal = false, decimalPlaces } = options;
|
|
18
|
+
|
|
19
|
+
if (key === 'backspace') {
|
|
20
|
+
return value.slice(0, -1);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (key === '.') {
|
|
24
|
+
if (!allowDecimal || value.includes('.')) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const next = value ? `${value}.` : '0.';
|
|
29
|
+
return maxLength && next.length > maxLength ? null : next;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!/^\d$/.test(key)) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const next = `${value}${key}`;
|
|
37
|
+
|
|
38
|
+
if (maxLength && next.length > maxLength) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (allowDecimal && decimalPlaces != null && value.includes('.')) {
|
|
43
|
+
const [, decimalPart = ''] = value.split('.');
|
|
44
|
+
if (decimalPart.length >= decimalPlaces) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (value === '0' && key !== '.') {
|
|
50
|
+
return key;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return next;
|
|
54
|
+
};
|