@webority-technologies/mobile 0.0.22 → 0.0.24
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/lib/commonjs/components/Accordion/Accordion.js +9 -7
- package/lib/commonjs/components/AnimatePresence/AnimatePresence.js +69 -0
- package/lib/commonjs/components/AnimatePresence/index.js +13 -0
- package/lib/commonjs/components/AppBar/AppBar.js +9 -6
- package/lib/commonjs/components/Avatar/Avatar.js +4 -2
- package/lib/commonjs/components/Badge/Badge.js +5 -5
- package/lib/commonjs/components/Banner/Banner.js +20 -6
- package/lib/commonjs/components/BottomNavigation/BottomNavigation.js +6 -4
- package/lib/commonjs/components/BottomSheet/BottomSheet.js +8 -9
- package/lib/commonjs/components/Box/Box.js +162 -0
- package/lib/commonjs/components/Box/index.js +37 -0
- package/lib/commonjs/components/Button/Button.js +7 -7
- package/lib/commonjs/components/Card/Card.js +3 -3
- package/lib/commonjs/components/Carousel/Carousel.js +4 -2
- package/lib/commonjs/components/Checkbox/Checkbox.js +17 -7
- package/lib/commonjs/components/Chip/Chip.js +4 -2
- package/lib/commonjs/components/DatePicker/DatePicker.js +31 -24
- package/lib/commonjs/components/DateRangePicker/DateRangePicker.js +16 -11
- package/lib/commonjs/components/Dialog/Dialog.js +6 -4
- package/lib/commonjs/components/Drawer/Drawer.js +4 -2
- package/lib/commonjs/components/FieldBase/FieldBase.js +8 -4
- package/lib/commonjs/components/FloatingActionButton/FloatingActionButton.js +23 -13
- package/lib/commonjs/components/FormField/FormField.js +61 -25
- package/lib/commonjs/components/ImageGallery/ImageGallery.js +17 -15
- package/lib/commonjs/components/Input/Input.js +41 -29
- package/lib/commonjs/components/KeyboardAwareScrollView/KeyboardAwareScrollView.js +102 -0
- package/lib/commonjs/components/KeyboardAwareScrollView/index.js +13 -0
- package/lib/commonjs/components/KeyboardToolbar/KeyboardToolbar.js +130 -0
- package/lib/commonjs/components/KeyboardToolbar/index.js +13 -0
- package/lib/commonjs/components/ListItem/ListItem.js +4 -3
- package/lib/commonjs/components/Modal/Modal.js +21 -9
- package/lib/commonjs/components/NumberInput/NumberInput.js +38 -29
- package/lib/commonjs/components/OTPInput/OTPInput.js +37 -22
- package/lib/commonjs/components/Radio/Radio.js +9 -8
- package/lib/commonjs/components/Radio/RadioGroup.js +10 -3
- package/lib/commonjs/components/Rating/Rating.js +4 -3
- package/lib/commonjs/components/SearchBar/SearchBar.js +11 -6
- package/lib/commonjs/components/SegmentedControl/SegmentedControl.js +23 -12
- package/lib/commonjs/components/Select/Select.js +40 -36
- package/lib/commonjs/components/Skeleton/SkeletonContent.js +5 -2
- package/lib/commonjs/components/Slider/Slider.js +241 -225
- package/lib/commonjs/components/Spinner/Spinner.js +5 -5
- package/lib/commonjs/components/Stepper/Stepper.js +6 -5
- package/lib/commonjs/components/Swipeable/Swipeable.js +8 -9
- package/lib/commonjs/components/Switch/Switch.js +29 -16
- package/lib/commonjs/components/Tabs/Tabs.js +8 -5
- package/lib/commonjs/components/Text/Text.js +142 -0
- package/lib/commonjs/components/Text/index.js +13 -0
- package/lib/commonjs/components/TimePicker/TimePicker.js +23 -15
- package/lib/commonjs/components/Toast/Toast.js +22 -10
- package/lib/commonjs/components/Tooltip/Tooltip.js +6 -2
- package/lib/commonjs/components/index.js +156 -103
- package/lib/commonjs/form/FormContext.js +40 -0
- package/lib/commonjs/form/index.js +68 -0
- package/lib/commonjs/form/path.js +79 -0
- package/lib/commonjs/form/rules.js +67 -0
- package/lib/commonjs/form/types.js +2 -0
- package/lib/commonjs/form/useField.js +54 -0
- package/lib/commonjs/form/useForm.js +316 -0
- package/lib/commonjs/hooks/index.js +14 -0
- package/lib/commonjs/hooks/useControllableState.js +30 -0
- package/lib/commonjs/hooks/useReducedMotion.js +31 -0
- package/lib/commonjs/index.js +96 -11
- package/lib/commonjs/theme/ThemeContext.js +30 -2
- package/lib/commonjs/theme/tokens.js +12 -0
- package/lib/commonjs/utils/hapticUtils.js +11 -1
- package/lib/commonjs/utils/index.js +6 -0
- package/lib/module/components/Accordion/Accordion.js +10 -8
- package/lib/module/components/AnimatePresence/AnimatePresence.js +63 -0
- package/lib/module/components/AnimatePresence/index.js +4 -0
- package/lib/module/components/AppBar/AppBar.js +10 -7
- package/lib/module/components/Avatar/Avatar.js +4 -2
- package/lib/module/components/Badge/Badge.js +5 -5
- package/lib/module/components/Banner/Banner.js +20 -6
- package/lib/module/components/BottomNavigation/BottomNavigation.js +6 -4
- package/lib/module/components/BottomSheet/BottomSheet.js +8 -9
- package/lib/module/components/Box/Box.js +156 -0
- package/lib/module/components/Box/index.js +4 -0
- package/lib/module/components/Button/Button.js +7 -7
- package/lib/module/components/Card/Card.js +4 -4
- package/lib/module/components/Carousel/Carousel.js +4 -2
- package/lib/module/components/Checkbox/Checkbox.js +18 -8
- package/lib/module/components/Chip/Chip.js +5 -3
- package/lib/module/components/DatePicker/DatePicker.js +32 -25
- package/lib/module/components/DateRangePicker/DateRangePicker.js +17 -12
- package/lib/module/components/Dialog/Dialog.js +7 -5
- package/lib/module/components/Drawer/Drawer.js +5 -3
- package/lib/module/components/FieldBase/FieldBase.js +8 -4
- package/lib/module/components/FloatingActionButton/FloatingActionButton.js +24 -14
- package/lib/module/components/FormField/FormField.js +62 -26
- package/lib/module/components/ImageGallery/ImageGallery.js +18 -16
- package/lib/module/components/Input/Input.js +41 -29
- package/lib/module/components/KeyboardAwareScrollView/KeyboardAwareScrollView.js +98 -0
- package/lib/module/components/KeyboardAwareScrollView/index.js +4 -0
- package/lib/module/components/KeyboardToolbar/KeyboardToolbar.js +125 -0
- package/lib/module/components/KeyboardToolbar/index.js +4 -0
- package/lib/module/components/ListItem/ListItem.js +5 -4
- package/lib/module/components/Modal/Modal.js +22 -10
- package/lib/module/components/NumberInput/NumberInput.js +36 -27
- package/lib/module/components/OTPInput/OTPInput.js +37 -22
- package/lib/module/components/Radio/Radio.js +10 -9
- package/lib/module/components/Radio/RadioGroup.js +10 -3
- package/lib/module/components/Rating/Rating.js +5 -4
- package/lib/module/components/SearchBar/SearchBar.js +12 -7
- package/lib/module/components/SegmentedControl/SegmentedControl.js +24 -13
- package/lib/module/components/Select/Select.js +41 -37
- package/lib/module/components/Skeleton/SkeletonContent.js +5 -2
- package/lib/module/components/Slider/Slider.js +244 -228
- package/lib/module/components/Spinner/Spinner.js +5 -5
- package/lib/module/components/Stepper/Stepper.js +7 -6
- package/lib/module/components/Swipeable/Swipeable.js +9 -10
- package/lib/module/components/Switch/Switch.js +29 -16
- package/lib/module/components/Tabs/Tabs.js +9 -6
- package/lib/module/components/Text/Text.js +138 -0
- package/lib/module/components/Text/index.js +4 -0
- package/lib/module/components/TimePicker/TimePicker.js +24 -16
- package/lib/module/components/Toast/Toast.js +22 -10
- package/lib/module/components/Tooltip/Tooltip.js +6 -2
- package/lib/module/components/index.js +5 -0
- package/lib/module/form/FormContext.js +32 -0
- package/lib/module/form/index.js +12 -0
- package/lib/module/form/path.js +72 -0
- package/lib/module/form/rules.js +52 -0
- package/lib/module/form/types.js +2 -0
- package/lib/module/form/useField.js +49 -0
- package/lib/module/form/useForm.js +312 -0
- package/lib/module/hooks/index.js +2 -0
- package/lib/module/hooks/useControllableState.js +26 -0
- package/lib/module/hooks/useReducedMotion.js +27 -0
- package/lib/module/index.js +3 -1
- package/lib/module/theme/ThemeContext.js +30 -2
- package/lib/module/theme/tokens.js +12 -0
- package/lib/module/utils/hapticUtils.js +9 -0
- package/lib/module/utils/index.js +1 -1
- package/lib/typescript/commonjs/components/Accordion/Accordion.d.ts +3 -0
- package/lib/typescript/commonjs/components/AnimatePresence/AnimatePresence.d.ts +30 -0
- package/lib/typescript/commonjs/components/AnimatePresence/index.d.ts +3 -0
- package/lib/typescript/commonjs/components/AppBar/AppBar.d.ts +6 -0
- package/lib/typescript/commonjs/components/Banner/Banner.d.ts +3 -0
- package/lib/typescript/commonjs/components/BottomNavigation/BottomNavigation.d.ts +1 -1
- package/lib/typescript/commonjs/components/Box/Box.d.ts +60 -0
- package/lib/typescript/commonjs/components/Box/index.d.ts +3 -0
- package/lib/typescript/commonjs/components/Button/Button.d.ts +1 -1
- package/lib/typescript/commonjs/components/Card/Card.d.ts +3 -0
- package/lib/typescript/commonjs/components/Checkbox/Checkbox.d.ts +4 -2
- package/lib/typescript/commonjs/components/Chip/Chip.d.ts +3 -0
- package/lib/typescript/commonjs/components/DatePicker/DatePicker.d.ts +6 -3
- package/lib/typescript/commonjs/components/DateRangePicker/DateRangePicker.d.ts +6 -0
- package/lib/typescript/commonjs/components/Dialog/Dialog.d.ts +5 -2
- package/lib/typescript/commonjs/components/Drawer/Drawer.d.ts +3 -0
- package/lib/typescript/commonjs/components/FloatingActionButton/FloatingActionButton.d.ts +5 -0
- package/lib/typescript/commonjs/components/FormField/FormField.d.ts +13 -2
- package/lib/typescript/commonjs/components/ImageGallery/ImageGallery.d.ts +6 -0
- package/lib/typescript/commonjs/components/KeyboardAwareScrollView/KeyboardAwareScrollView.d.ts +20 -0
- package/lib/typescript/commonjs/components/KeyboardAwareScrollView/index.d.ts +3 -0
- package/lib/typescript/commonjs/components/KeyboardToolbar/KeyboardToolbar.d.ts +29 -0
- package/lib/typescript/commonjs/components/KeyboardToolbar/index.d.ts +3 -0
- package/lib/typescript/commonjs/components/ListItem/ListItem.d.ts +3 -0
- package/lib/typescript/commonjs/components/Modal/Modal.d.ts +6 -0
- package/lib/typescript/commonjs/components/NumberInput/NumberInput.d.ts +6 -2
- package/lib/typescript/commonjs/components/OTPInput/OTPInput.d.ts +9 -2
- package/lib/typescript/commonjs/components/Radio/Radio.d.ts +2 -2
- package/lib/typescript/commonjs/components/Radio/RadioGroup.d.ts +3 -2
- package/lib/typescript/commonjs/components/Rating/Rating.d.ts +6 -0
- package/lib/typescript/commonjs/components/SearchBar/SearchBar.d.ts +3 -0
- package/lib/typescript/commonjs/components/SegmentedControl/SegmentedControl.d.ts +6 -2
- package/lib/typescript/commonjs/components/Select/Select.d.ts +6 -0
- package/lib/typescript/commonjs/components/Slider/Slider.d.ts +9 -4
- package/lib/typescript/commonjs/components/Spinner/Spinner.d.ts +1 -1
- package/lib/typescript/commonjs/components/Stepper/Stepper.d.ts +6 -0
- package/lib/typescript/commonjs/components/Swipeable/Swipeable.d.ts +3 -0
- package/lib/typescript/commonjs/components/Switch/Switch.d.ts +3 -2
- package/lib/typescript/commonjs/components/Tabs/Tabs.d.ts +3 -0
- package/lib/typescript/commonjs/components/Text/Text.d.ts +25 -0
- package/lib/typescript/commonjs/components/Text/index.d.ts +3 -0
- package/lib/typescript/commonjs/components/TimePicker/TimePicker.d.ts +6 -3
- package/lib/typescript/commonjs/components/index.d.ts +10 -0
- package/lib/typescript/commonjs/form/FormContext.d.ts +17 -0
- package/lib/typescript/commonjs/form/index.d.ts +9 -0
- package/lib/typescript/commonjs/form/path.d.ts +10 -0
- package/lib/typescript/commonjs/form/rules.d.ts +31 -0
- package/lib/typescript/commonjs/form/types.d.ts +94 -0
- package/lib/typescript/commonjs/form/useField.d.ts +27 -0
- package/lib/typescript/commonjs/form/useForm.d.ts +10 -0
- package/lib/typescript/commonjs/hooks/index.d.ts +3 -0
- package/lib/typescript/commonjs/hooks/useControllableState.d.ts +17 -0
- package/lib/typescript/commonjs/hooks/useReducedMotion.d.ts +8 -0
- package/lib/typescript/commonjs/index.d.ts +4 -2
- package/lib/typescript/commonjs/theme/types.d.ts +17 -67
- package/lib/typescript/commonjs/utils/hapticUtils.d.ts +8 -0
- package/lib/typescript/commonjs/utils/index.d.ts +1 -1
- package/lib/typescript/module/components/Accordion/Accordion.d.ts +3 -0
- package/lib/typescript/module/components/AnimatePresence/AnimatePresence.d.ts +30 -0
- package/lib/typescript/module/components/AnimatePresence/index.d.ts +3 -0
- package/lib/typescript/module/components/AppBar/AppBar.d.ts +6 -0
- package/lib/typescript/module/components/Banner/Banner.d.ts +3 -0
- package/lib/typescript/module/components/BottomNavigation/BottomNavigation.d.ts +1 -1
- package/lib/typescript/module/components/Box/Box.d.ts +60 -0
- package/lib/typescript/module/components/Box/index.d.ts +3 -0
- package/lib/typescript/module/components/Button/Button.d.ts +1 -1
- package/lib/typescript/module/components/Card/Card.d.ts +3 -0
- package/lib/typescript/module/components/Checkbox/Checkbox.d.ts +4 -2
- package/lib/typescript/module/components/Chip/Chip.d.ts +3 -0
- package/lib/typescript/module/components/DatePicker/DatePicker.d.ts +6 -3
- package/lib/typescript/module/components/DateRangePicker/DateRangePicker.d.ts +6 -0
- package/lib/typescript/module/components/Dialog/Dialog.d.ts +5 -2
- package/lib/typescript/module/components/Drawer/Drawer.d.ts +3 -0
- package/lib/typescript/module/components/FloatingActionButton/FloatingActionButton.d.ts +5 -0
- package/lib/typescript/module/components/FormField/FormField.d.ts +13 -2
- package/lib/typescript/module/components/ImageGallery/ImageGallery.d.ts +6 -0
- package/lib/typescript/module/components/KeyboardAwareScrollView/KeyboardAwareScrollView.d.ts +20 -0
- package/lib/typescript/module/components/KeyboardAwareScrollView/index.d.ts +3 -0
- package/lib/typescript/module/components/KeyboardToolbar/KeyboardToolbar.d.ts +29 -0
- package/lib/typescript/module/components/KeyboardToolbar/index.d.ts +3 -0
- package/lib/typescript/module/components/ListItem/ListItem.d.ts +3 -0
- package/lib/typescript/module/components/Modal/Modal.d.ts +6 -0
- package/lib/typescript/module/components/NumberInput/NumberInput.d.ts +6 -2
- package/lib/typescript/module/components/OTPInput/OTPInput.d.ts +9 -2
- package/lib/typescript/module/components/Radio/Radio.d.ts +2 -2
- package/lib/typescript/module/components/Radio/RadioGroup.d.ts +3 -2
- package/lib/typescript/module/components/Rating/Rating.d.ts +6 -0
- package/lib/typescript/module/components/SearchBar/SearchBar.d.ts +3 -0
- package/lib/typescript/module/components/SegmentedControl/SegmentedControl.d.ts +6 -2
- package/lib/typescript/module/components/Select/Select.d.ts +6 -0
- package/lib/typescript/module/components/Slider/Slider.d.ts +9 -4
- package/lib/typescript/module/components/Spinner/Spinner.d.ts +1 -1
- package/lib/typescript/module/components/Stepper/Stepper.d.ts +6 -0
- package/lib/typescript/module/components/Swipeable/Swipeable.d.ts +3 -0
- package/lib/typescript/module/components/Switch/Switch.d.ts +3 -2
- package/lib/typescript/module/components/Tabs/Tabs.d.ts +3 -0
- package/lib/typescript/module/components/Text/Text.d.ts +25 -0
- package/lib/typescript/module/components/Text/index.d.ts +3 -0
- package/lib/typescript/module/components/TimePicker/TimePicker.d.ts +6 -3
- package/lib/typescript/module/components/index.d.ts +10 -0
- package/lib/typescript/module/form/FormContext.d.ts +17 -0
- package/lib/typescript/module/form/index.d.ts +9 -0
- package/lib/typescript/module/form/path.d.ts +10 -0
- package/lib/typescript/module/form/rules.d.ts +31 -0
- package/lib/typescript/module/form/types.d.ts +94 -0
- package/lib/typescript/module/form/useField.d.ts +27 -0
- package/lib/typescript/module/form/useForm.d.ts +10 -0
- package/lib/typescript/module/hooks/index.d.ts +3 -0
- package/lib/typescript/module/hooks/useControllableState.d.ts +17 -0
- package/lib/typescript/module/hooks/useReducedMotion.d.ts +8 -0
- package/lib/typescript/module/index.d.ts +4 -2
- package/lib/typescript/module/theme/types.d.ts +17 -67
- package/lib/typescript/module/utils/hapticUtils.d.ts +8 -0
- package/lib/typescript/module/utils/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.setPath = exports.getPath = exports.deletePath = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Immutable get/set/delete for dot- and bracket-notation field paths
|
|
9
|
+
* ("address.city", "phones[0]", "items[2].qty"). Lets a single flat `name`
|
|
10
|
+
* string address nested values and array items, so the form engine can treat
|
|
11
|
+
* every field uniformly regardless of how deep it lives in the value tree.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const tokenize = path => {
|
|
15
|
+
const tokens = [];
|
|
16
|
+
const re = /[^.[\]]+/g;
|
|
17
|
+
let m;
|
|
18
|
+
while ((m = re.exec(path)) !== null) {
|
|
19
|
+
const raw = m[0];
|
|
20
|
+
tokens.push(/^\d+$/.test(raw) ? Number(raw) : raw);
|
|
21
|
+
}
|
|
22
|
+
return tokens;
|
|
23
|
+
};
|
|
24
|
+
const getPath = (obj, path) => {
|
|
25
|
+
const tokens = tokenize(path);
|
|
26
|
+
let cur = obj;
|
|
27
|
+
for (const t of tokens) {
|
|
28
|
+
if (cur == null || typeof cur !== 'object') return undefined;
|
|
29
|
+
cur = cur[t];
|
|
30
|
+
}
|
|
31
|
+
return cur;
|
|
32
|
+
};
|
|
33
|
+
exports.getPath = getPath;
|
|
34
|
+
const setPath = (obj, path, value) => {
|
|
35
|
+
const tokens = tokenize(path);
|
|
36
|
+
if (tokens.length === 0) return obj;
|
|
37
|
+
const root = Array.isArray(obj) ? [...obj] : {
|
|
38
|
+
...obj
|
|
39
|
+
};
|
|
40
|
+
let cur = root;
|
|
41
|
+
for (let i = 0; i < tokens.length - 1; i++) {
|
|
42
|
+
const t = tokens[i];
|
|
43
|
+
const next = tokens[i + 1];
|
|
44
|
+
const child = cur[t];
|
|
45
|
+
// Clone the existing branch so we never mutate the previous value tree;
|
|
46
|
+
// create the right container shape when the branch is missing.
|
|
47
|
+
const cloned = child != null && typeof child === 'object' ? Array.isArray(child) ? [...child] : {
|
|
48
|
+
...child
|
|
49
|
+
} : typeof next === 'number' ? [] : {};
|
|
50
|
+
cur[t] = cloned;
|
|
51
|
+
cur = cloned;
|
|
52
|
+
}
|
|
53
|
+
cur[tokens[tokens.length - 1]] = value;
|
|
54
|
+
return root;
|
|
55
|
+
};
|
|
56
|
+
exports.setPath = setPath;
|
|
57
|
+
const deletePath = (obj, path) => {
|
|
58
|
+
const tokens = tokenize(path);
|
|
59
|
+
if (tokens.length === 0) return obj;
|
|
60
|
+
const root = Array.isArray(obj) ? [...obj] : {
|
|
61
|
+
...obj
|
|
62
|
+
};
|
|
63
|
+
let cur = root;
|
|
64
|
+
for (let i = 0; i < tokens.length - 1; i++) {
|
|
65
|
+
const t = tokens[i];
|
|
66
|
+
const child = cur[t];
|
|
67
|
+
if (child == null || typeof child !== 'object') return root;
|
|
68
|
+
const cloned = Array.isArray(child) ? [...child] : {
|
|
69
|
+
...child
|
|
70
|
+
};
|
|
71
|
+
cur[t] = cloned;
|
|
72
|
+
cur = cloned;
|
|
73
|
+
}
|
|
74
|
+
const last = tokens[tokens.length - 1];
|
|
75
|
+
if (Array.isArray(cur) && typeof last === 'number') cur.splice(last, 1);else delete cur[last];
|
|
76
|
+
return root;
|
|
77
|
+
};
|
|
78
|
+
exports.deletePath = deletePath;
|
|
79
|
+
//# sourceMappingURL=path.js.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.url = exports.strongPassword = exports.required = exports.pincode = exports.phone = exports.pattern = exports.pan = exports.oneOf = exports.numeric = exports.mobile = exports.minLength = exports.min = exports.maxLength = exports.max = exports.matches = exports.integer = exports.ifsc = exports.gstin = exports.email = exports.custom = exports.alphanumeric = exports.aadhaar = void 0;
|
|
7
|
+
var _index = require("../validators/index.js");
|
|
8
|
+
var _path = require("./path.js");
|
|
9
|
+
/**
|
|
10
|
+
* Validation rule presets — the dependency-free replacement for Yup chains.
|
|
11
|
+
* Each factory returns a {@link ValidationRule}. Rules built on the project's
|
|
12
|
+
* `validators` module skip empty values (so `required()` owns emptiness and you
|
|
13
|
+
* don't get duplicate errors), and accept an optional custom message.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const isEmptyValue = v => v == null || v === '' || Array.isArray(v) && v.length === 0;
|
|
17
|
+
const fromPredicate = (predicate, defaultMsg) => message => value => isEmptyValue(value) || predicate(value) ? undefined : message ?? defaultMsg;
|
|
18
|
+
const required = (message = 'This field is required') => value => {
|
|
19
|
+
// A required boolean (e.g. "accept terms" checkbox) must be true.
|
|
20
|
+
if (typeof value === 'boolean') return value ? undefined : message;
|
|
21
|
+
return isEmptyValue(value) ? message : undefined;
|
|
22
|
+
};
|
|
23
|
+
exports.required = required;
|
|
24
|
+
const email = exports.email = fromPredicate(_index.isEmail, 'Enter a valid email');
|
|
25
|
+
const mobile = exports.mobile = fromPredicate(_index.isIndianMobile, 'Enter a valid mobile number');
|
|
26
|
+
const phone = exports.phone = fromPredicate(_index.isPhone, 'Enter a valid phone number');
|
|
27
|
+
const url = exports.url = fromPredicate(_index.isUrl, 'Enter a valid URL');
|
|
28
|
+
const numeric = exports.numeric = fromPredicate(_index.isNumeric, 'Enter a valid number');
|
|
29
|
+
const integer = exports.integer = fromPredicate(_index.isInteger, 'Enter a whole number');
|
|
30
|
+
const alphanumeric = exports.alphanumeric = fromPredicate(_index.isAlphanumeric, 'Use letters and numbers only');
|
|
31
|
+
const pincode = exports.pincode = fromPredicate(_index.isIndianPincode, 'Enter a valid 6-digit PIN code');
|
|
32
|
+
const pan = exports.pan = fromPredicate(_index.isPan, 'Enter a valid PAN');
|
|
33
|
+
const gstin = exports.gstin = fromPredicate(_index.isGstin, 'Enter a valid GSTIN');
|
|
34
|
+
const aadhaar = exports.aadhaar = fromPredicate(_index.isAadhaar, 'Enter a valid Aadhaar number');
|
|
35
|
+
const ifsc = exports.ifsc = fromPredicate(_index.isIfsc, 'Enter a valid IFSC code');
|
|
36
|
+
const minLength = (length, message) => value => isEmptyValue(value) || String(value).length >= length ? undefined : message ?? `Must be at least ${length} characters`;
|
|
37
|
+
exports.minLength = minLength;
|
|
38
|
+
const maxLength = (length, message) => value => value == null || String(value).length <= length ? undefined : message ?? `Must be at most ${length} characters`;
|
|
39
|
+
exports.maxLength = maxLength;
|
|
40
|
+
const min = (n, message) => value => isEmptyValue(value) || Number(value) >= n ? undefined : message ?? `Must be at least ${n}`;
|
|
41
|
+
exports.min = min;
|
|
42
|
+
const max = (n, message) => value => isEmptyValue(value) || Number(value) <= n ? undefined : message ?? `Must be at most ${n}`;
|
|
43
|
+
exports.max = max;
|
|
44
|
+
const pattern = (regex, message = 'Invalid format') => value => isEmptyValue(value) || regex.test(String(value)) ? undefined : message;
|
|
45
|
+
exports.pattern = pattern;
|
|
46
|
+
const oneOf = (allowed, message = 'Invalid selection') => value => isEmptyValue(value) || allowed.includes(value) ? undefined : message;
|
|
47
|
+
|
|
48
|
+
/** Cross-field equality (e.g. confirm-password). `otherField` is a field path. */
|
|
49
|
+
exports.oneOf = oneOf;
|
|
50
|
+
const matches = (otherField, message = 'Values do not match') => (value, allValues) => value === (0, _path.getPath)(allValues, otherField) ? undefined : message;
|
|
51
|
+
exports.matches = matches;
|
|
52
|
+
const strongPassword = (rules, message = 'Password is too weak') => value => isEmptyValue(value) || (0, _index.isStrongPassword)(value, rules) ? undefined : message;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Wrap any custom check. Return `true` (valid), `false` (invalid → default
|
|
56
|
+
* message), or a string (invalid → that message). Async is supported — return
|
|
57
|
+
* a Promise of the same.
|
|
58
|
+
*/
|
|
59
|
+
exports.strongPassword = strongPassword;
|
|
60
|
+
const custom = (fn, message = 'Invalid value') => async (value, allValues) => {
|
|
61
|
+
const result = await fn(value, allValues);
|
|
62
|
+
if (result === true) return undefined;
|
|
63
|
+
if (result === false) return message;
|
|
64
|
+
return result;
|
|
65
|
+
};
|
|
66
|
+
exports.custom = custom;
|
|
67
|
+
//# sourceMappingURL=rules.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useField = useField;
|
|
7
|
+
exports.useFieldArray = useFieldArray;
|
|
8
|
+
var _path = require("./path.js");
|
|
9
|
+
var _FormContext = require("./FormContext.js");
|
|
10
|
+
/**
|
|
11
|
+
* Bind a single field by name. Returns everything an input needs; pick the
|
|
12
|
+
* handler your control uses:
|
|
13
|
+
* const email = useField('email');
|
|
14
|
+
* <Input value={email.value} onChangeText={email.onChangeText} onBlur={email.onBlur} error={email.error} />
|
|
15
|
+
* <Select value={country.value} onChange={country.onChange} error={country.error} />
|
|
16
|
+
* <Switch value={!!agree.value} onChange={agree.onChange} />
|
|
17
|
+
*/
|
|
18
|
+
function useField(name) {
|
|
19
|
+
const form = (0, _FormContext.useFormContext)();
|
|
20
|
+
return form.getFieldProps(name);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Manage a repeating list field (phone numbers, line items, etc.) by name.
|
|
24
|
+
* Each helper writes the whole array back through the form so validation and
|
|
25
|
+
* dirty-tracking stay correct.
|
|
26
|
+
*/
|
|
27
|
+
function useFieldArray(name) {
|
|
28
|
+
const form = (0, _FormContext.useFormContext)();
|
|
29
|
+
const fields = (0, _path.getPath)(form.values, name) ?? [];
|
|
30
|
+
const set = next => form.setFieldValue(name, next);
|
|
31
|
+
return {
|
|
32
|
+
fields,
|
|
33
|
+
length: fields.length,
|
|
34
|
+
push: item => set([...fields, item]),
|
|
35
|
+
remove: index => set(fields.filter((_, i) => i !== index)),
|
|
36
|
+
insert: (index, item) => {
|
|
37
|
+
const copy = [...fields];
|
|
38
|
+
copy.splice(index, 0, item);
|
|
39
|
+
set(copy);
|
|
40
|
+
},
|
|
41
|
+
move: (from, to) => {
|
|
42
|
+
const copy = [...fields];
|
|
43
|
+
const [moved] = copy.splice(from, 1);
|
|
44
|
+
copy.splice(to, 0, moved);
|
|
45
|
+
set(copy);
|
|
46
|
+
},
|
|
47
|
+
replace: (index, item) => {
|
|
48
|
+
const copy = [...fields];
|
|
49
|
+
copy[index] = item;
|
|
50
|
+
set(copy);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=useField.js.map
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useForm = useForm;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _path = require("./path.js");
|
|
9
|
+
// Loosely typed (Values -> any) so the generic schema from any useForm<Values>
|
|
10
|
+
// instance flows in without variance friction; callers re-apply Values at use.
|
|
11
|
+
const rulesFor = (validate, name) => {
|
|
12
|
+
if (!validate || typeof validate === 'function') return [];
|
|
13
|
+
const r = validate[name];
|
|
14
|
+
if (!r) return [];
|
|
15
|
+
return Array.isArray(r) ? r : [r];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Dependency-free form engine. Tracks values/errors/touched/dirty, runs
|
|
20
|
+
* synchronous and async validation (per-field rule maps or a form-level
|
|
21
|
+
* function), gates error display behind touched/submit, and on a failed submit
|
|
22
|
+
* focuses the first errored field. The returned object is rebuilt every render
|
|
23
|
+
* so `<Form>` consumers re-render on state changes.
|
|
24
|
+
*/
|
|
25
|
+
function useForm(config) {
|
|
26
|
+
const configRef = (0, _react.useRef)(config);
|
|
27
|
+
configRef.current = config;
|
|
28
|
+
const initialRef = (0, _react.useRef)(config.initialValues);
|
|
29
|
+
const [values, setValuesState] = (0, _react.useState)(config.initialValues);
|
|
30
|
+
const [errors, setErrorsState] = (0, _react.useState)({});
|
|
31
|
+
const [touched, setTouchedState] = (0, _react.useState)({});
|
|
32
|
+
const [isSubmitting, setSubmitting] = (0, _react.useState)(false);
|
|
33
|
+
const [isValidating, setValidating] = (0, _react.useState)(false);
|
|
34
|
+
const [submitCount, setSubmitCount] = (0, _react.useState)(0);
|
|
35
|
+
|
|
36
|
+
// Mirror of the latest state so handlers (incl. async) never read stale
|
|
37
|
+
// closures and sequential setFieldValue calls in one tick compound correctly.
|
|
38
|
+
const ref = (0, _react.useRef)({
|
|
39
|
+
values,
|
|
40
|
+
errors,
|
|
41
|
+
touched,
|
|
42
|
+
submitCount
|
|
43
|
+
});
|
|
44
|
+
ref.current = {
|
|
45
|
+
values,
|
|
46
|
+
errors,
|
|
47
|
+
touched,
|
|
48
|
+
submitCount
|
|
49
|
+
};
|
|
50
|
+
const fieldNodes = (0, _react.useRef)(new Map());
|
|
51
|
+
const fieldOrder = (0, _react.useRef)([]);
|
|
52
|
+
const focusedFieldRef = (0, _react.useRef)(null);
|
|
53
|
+
(0, _react.useEffect)(() => {
|
|
54
|
+
if (!configRef.current.enableReinitialize) return;
|
|
55
|
+
const next = configRef.current.initialValues;
|
|
56
|
+
initialRef.current = next;
|
|
57
|
+
ref.current.values = next;
|
|
58
|
+
ref.current.errors = {};
|
|
59
|
+
ref.current.touched = {};
|
|
60
|
+
setValuesState(next);
|
|
61
|
+
setErrorsState({});
|
|
62
|
+
setTouchedState({});
|
|
63
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
64
|
+
}, [JSON.stringify(config.initialValues)]);
|
|
65
|
+
const validateField = (0, _react.useCallback)(async name => {
|
|
66
|
+
const validate = configRef.current.validate;
|
|
67
|
+
const allValues = ref.current.values;
|
|
68
|
+
if (typeof validate === 'function') {
|
|
69
|
+
const map = (await validate(allValues)) ?? {};
|
|
70
|
+
return map[name] || undefined;
|
|
71
|
+
}
|
|
72
|
+
const value = (0, _path.getPath)(allValues, name);
|
|
73
|
+
for (const rule of rulesFor(validate, name)) {
|
|
74
|
+
const res = await rule(value, allValues);
|
|
75
|
+
if (res) return res;
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
}, []);
|
|
79
|
+
const runAll = (0, _react.useCallback)(async vals => {
|
|
80
|
+
const validate = configRef.current.validate;
|
|
81
|
+
if (!validate) return {};
|
|
82
|
+
if (typeof validate === 'function') return (await validate(vals)) ?? {};
|
|
83
|
+
const out = {};
|
|
84
|
+
await Promise.all(Object.keys(validate).map(async name => {
|
|
85
|
+
const value = (0, _path.getPath)(vals, name);
|
|
86
|
+
for (const rule of rulesFor(validate, name)) {
|
|
87
|
+
const res = await rule(value, vals);
|
|
88
|
+
if (res) {
|
|
89
|
+
out[name] = res;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}));
|
|
94
|
+
return out;
|
|
95
|
+
}, []);
|
|
96
|
+
const revalidateField = (0, _react.useCallback)(async name => {
|
|
97
|
+
const err = await validateField(name);
|
|
98
|
+
setErrorsState(prev => {
|
|
99
|
+
if (prev[name] === err) return prev;
|
|
100
|
+
const next = {
|
|
101
|
+
...prev
|
|
102
|
+
};
|
|
103
|
+
if (err) next[name] = err;else delete next[name];
|
|
104
|
+
ref.current.errors = next;
|
|
105
|
+
return next;
|
|
106
|
+
});
|
|
107
|
+
}, [validateField]);
|
|
108
|
+
const validate = (0, _react.useCallback)(async () => {
|
|
109
|
+
setValidating(true);
|
|
110
|
+
const errs = await runAll(ref.current.values);
|
|
111
|
+
setValidating(false);
|
|
112
|
+
ref.current.errors = errs;
|
|
113
|
+
setErrorsState(errs);
|
|
114
|
+
return errs;
|
|
115
|
+
}, [runAll]);
|
|
116
|
+
const setFieldValue = (0, _react.useCallback)((name, value, shouldValidate) => {
|
|
117
|
+
const next = (0, _path.setPath)(ref.current.values, name, value);
|
|
118
|
+
ref.current.values = next;
|
|
119
|
+
setValuesState(next);
|
|
120
|
+
const cfg = configRef.current;
|
|
121
|
+
const willValidate = shouldValidate ?? (ref.current.touched[name] || ref.current.submitCount > 0 || cfg.validateOn === 'change');
|
|
122
|
+
if (willValidate) void revalidateField(name);
|
|
123
|
+
}, [revalidateField]);
|
|
124
|
+
const handleBlur = (0, _react.useCallback)(name => {
|
|
125
|
+
setTouchedState(prev => {
|
|
126
|
+
if (prev[name]) return prev;
|
|
127
|
+
const next = {
|
|
128
|
+
...prev,
|
|
129
|
+
[name]: true
|
|
130
|
+
};
|
|
131
|
+
ref.current.touched = next;
|
|
132
|
+
return next;
|
|
133
|
+
});
|
|
134
|
+
// Blur is the natural moment to surface a field's error.
|
|
135
|
+
void revalidateField(name);
|
|
136
|
+
}, [revalidateField]);
|
|
137
|
+
const setFieldTouched = (0, _react.useCallback)((name, isTouched = true, shouldValidate) => {
|
|
138
|
+
const next = {
|
|
139
|
+
...ref.current.touched,
|
|
140
|
+
[name]: isTouched
|
|
141
|
+
};
|
|
142
|
+
ref.current.touched = next;
|
|
143
|
+
setTouchedState(next);
|
|
144
|
+
if (shouldValidate ?? isTouched) void revalidateField(name);
|
|
145
|
+
}, [revalidateField]);
|
|
146
|
+
const setFieldError = (0, _react.useCallback)((name, error) => {
|
|
147
|
+
setErrorsState(prev => {
|
|
148
|
+
const next = {
|
|
149
|
+
...prev
|
|
150
|
+
};
|
|
151
|
+
if (error) next[name] = error;else delete next[name];
|
|
152
|
+
ref.current.errors = next;
|
|
153
|
+
return next;
|
|
154
|
+
});
|
|
155
|
+
}, []);
|
|
156
|
+
const setErrors = (0, _react.useCallback)(errs => {
|
|
157
|
+
ref.current.errors = errs;
|
|
158
|
+
setErrorsState(errs);
|
|
159
|
+
}, []);
|
|
160
|
+
const setValues = (0, _react.useCallback)((next, shouldValidate) => {
|
|
161
|
+
const resolved = typeof next === 'function' ? next(ref.current.values) : {
|
|
162
|
+
...ref.current.values,
|
|
163
|
+
...next
|
|
164
|
+
};
|
|
165
|
+
ref.current.values = resolved;
|
|
166
|
+
setValuesState(resolved);
|
|
167
|
+
if (shouldValidate) void validate();
|
|
168
|
+
}, [validate]);
|
|
169
|
+
const reset = (0, _react.useCallback)(nextValues => {
|
|
170
|
+
const base = nextValues ? {
|
|
171
|
+
...initialRef.current,
|
|
172
|
+
...nextValues
|
|
173
|
+
} : initialRef.current;
|
|
174
|
+
initialRef.current = base;
|
|
175
|
+
ref.current.values = base;
|
|
176
|
+
ref.current.errors = {};
|
|
177
|
+
ref.current.touched = {};
|
|
178
|
+
ref.current.submitCount = 0;
|
|
179
|
+
setValuesState(base);
|
|
180
|
+
setErrorsState({});
|
|
181
|
+
setTouchedState({});
|
|
182
|
+
setSubmitCount(0);
|
|
183
|
+
}, []);
|
|
184
|
+
const registerField = (0, _react.useCallback)((name, node) => {
|
|
185
|
+
if (node) {
|
|
186
|
+
fieldNodes.current.set(name, node);
|
|
187
|
+
if (!fieldOrder.current.includes(name)) fieldOrder.current.push(name);
|
|
188
|
+
} else {
|
|
189
|
+
fieldNodes.current.delete(name);
|
|
190
|
+
fieldOrder.current = fieldOrder.current.filter(n => n !== name);
|
|
191
|
+
}
|
|
192
|
+
}, []);
|
|
193
|
+
const handleFocus = (0, _react.useCallback)(name => {
|
|
194
|
+
focusedFieldRef.current = name;
|
|
195
|
+
}, []);
|
|
196
|
+
const focusAdjacent = (0, _react.useCallback)(direction => {
|
|
197
|
+
const order = fieldOrder.current;
|
|
198
|
+
const current = focusedFieldRef.current;
|
|
199
|
+
const index = current ? order.indexOf(current) : -1;
|
|
200
|
+
const target = order[index + direction];
|
|
201
|
+
if (!target) return;
|
|
202
|
+
focusedFieldRef.current = target;
|
|
203
|
+
fieldNodes.current.get(target)?.focus?.();
|
|
204
|
+
}, []);
|
|
205
|
+
const focusNext = (0, _react.useCallback)(() => focusAdjacent(1), [focusAdjacent]);
|
|
206
|
+
const focusPrev = (0, _react.useCallback)(() => focusAdjacent(-1), [focusAdjacent]);
|
|
207
|
+
const helpers = (0, _react.useMemo)(() => ({
|
|
208
|
+
setErrors,
|
|
209
|
+
setFieldError,
|
|
210
|
+
reset,
|
|
211
|
+
setSubmitting
|
|
212
|
+
}), [setErrors, setFieldError, reset]);
|
|
213
|
+
const submit = (0, _react.useCallback)(() => {
|
|
214
|
+
void (async () => {
|
|
215
|
+
const cfg = configRef.current;
|
|
216
|
+
const currentValues = ref.current.values;
|
|
217
|
+
ref.current.submitCount += 1;
|
|
218
|
+
setSubmitCount(c => c + 1);
|
|
219
|
+
setValidating(true);
|
|
220
|
+
const errs = await runAll(currentValues);
|
|
221
|
+
setValidating(false);
|
|
222
|
+
const keys = new Set([...fieldOrder.current, ...Object.keys(errs)]);
|
|
223
|
+
const nextTouched = {
|
|
224
|
+
...ref.current.touched
|
|
225
|
+
};
|
|
226
|
+
keys.forEach(k => {
|
|
227
|
+
nextTouched[k] = true;
|
|
228
|
+
});
|
|
229
|
+
ref.current.touched = nextTouched;
|
|
230
|
+
ref.current.errors = errs;
|
|
231
|
+
setTouchedState(nextTouched);
|
|
232
|
+
setErrorsState(errs);
|
|
233
|
+
const firstError = fieldOrder.current.find(n => errs[n]) ?? Object.keys(errs).find(n => errs[n]);
|
|
234
|
+
if (firstError) {
|
|
235
|
+
fieldNodes.current.get(firstError)?.focus?.();
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
setSubmitting(true);
|
|
239
|
+
try {
|
|
240
|
+
await cfg.onSubmit(currentValues, helpers);
|
|
241
|
+
} finally {
|
|
242
|
+
setSubmitting(false);
|
|
243
|
+
}
|
|
244
|
+
})();
|
|
245
|
+
}, [runAll, helpers]);
|
|
246
|
+
const uiErrors = (0, _react.useMemo)(() => {
|
|
247
|
+
const gated = {};
|
|
248
|
+
for (const k of Object.keys(errors)) {
|
|
249
|
+
if (errors[k] && (touched[k] || submitCount > 0)) gated[k] = errors[k];
|
|
250
|
+
}
|
|
251
|
+
return gated;
|
|
252
|
+
}, [errors, touched, submitCount]);
|
|
253
|
+
const isValid = (0, _react.useMemo)(() => {
|
|
254
|
+
const validateCfg = configRef.current.validate;
|
|
255
|
+
if (!validateCfg) return true;
|
|
256
|
+
// Form-level async fn can't run synchronously — fall back to known errors.
|
|
257
|
+
if (typeof validateCfg === 'function') return Object.values(errors).every(e => !e);
|
|
258
|
+
for (const name of Object.keys(validateCfg)) {
|
|
259
|
+
const value = (0, _path.getPath)(values, name);
|
|
260
|
+
for (const rule of rulesFor(validateCfg, name)) {
|
|
261
|
+
const res = rule(value, values);
|
|
262
|
+
if (typeof res === 'string' && res) return false; // async rules (Promise) are skipped here
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return true;
|
|
266
|
+
}, [values, errors]);
|
|
267
|
+
const dirty = (0, _react.useMemo)(() => JSON.stringify(values) !== JSON.stringify(initialRef.current), [values]);
|
|
268
|
+
return {
|
|
269
|
+
values,
|
|
270
|
+
errors: uiErrors,
|
|
271
|
+
rawErrors: errors,
|
|
272
|
+
touched,
|
|
273
|
+
dirty,
|
|
274
|
+
isValid,
|
|
275
|
+
isSubmitting,
|
|
276
|
+
isValidating,
|
|
277
|
+
submitCount,
|
|
278
|
+
setFieldValue,
|
|
279
|
+
setFieldTouched,
|
|
280
|
+
setFieldError,
|
|
281
|
+
setValues,
|
|
282
|
+
setErrors,
|
|
283
|
+
reset,
|
|
284
|
+
validate,
|
|
285
|
+
validateField,
|
|
286
|
+
submit,
|
|
287
|
+
handleBlur,
|
|
288
|
+
focusNext,
|
|
289
|
+
focusPrev,
|
|
290
|
+
registerField,
|
|
291
|
+
getFieldState: name => {
|
|
292
|
+
const value = (0, _path.getPath)(values, name);
|
|
293
|
+
const rawError = errors[name];
|
|
294
|
+
const isTouched = !!touched[name];
|
|
295
|
+
return {
|
|
296
|
+
value,
|
|
297
|
+
error: isTouched || submitCount > 0 ? rawError : undefined,
|
|
298
|
+
rawError,
|
|
299
|
+
touched: isTouched,
|
|
300
|
+
dirty: JSON.stringify(value) !== JSON.stringify((0, _path.getPath)(initialRef.current, name))
|
|
301
|
+
};
|
|
302
|
+
},
|
|
303
|
+
getFieldProps: name => ({
|
|
304
|
+
name,
|
|
305
|
+
value: (0, _path.getPath)(values, name),
|
|
306
|
+
error: touched[name] || submitCount > 0 ? errors[name] : undefined,
|
|
307
|
+
touched: !!touched[name],
|
|
308
|
+
onChange: val => setFieldValue(name, val),
|
|
309
|
+
onChangeText: text => setFieldValue(name, text),
|
|
310
|
+
onBlur: () => handleBlur(name),
|
|
311
|
+
onFocus: () => handleFocus(name),
|
|
312
|
+
setValue: (val, sv) => setFieldValue(name, val, sv)
|
|
313
|
+
})
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
//# sourceMappingURL=useForm.js.map
|
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "useControllableState", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _useControllableState.useControllableState;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "useDebounce", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function () {
|
|
@@ -15,6 +21,12 @@ Object.defineProperty(exports, "usePressAnimation", {
|
|
|
15
21
|
return _usePressAnimation.usePressAnimation;
|
|
16
22
|
}
|
|
17
23
|
});
|
|
24
|
+
Object.defineProperty(exports, "useReducedMotion", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _useReducedMotion.useReducedMotion;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
18
30
|
Object.defineProperty(exports, "useToggle", {
|
|
19
31
|
enumerable: true,
|
|
20
32
|
get: function () {
|
|
@@ -24,4 +36,6 @@ Object.defineProperty(exports, "useToggle", {
|
|
|
24
36
|
var _useToggle = require("./useToggle.js");
|
|
25
37
|
var _useDebounce = require("./useDebounce.js");
|
|
26
38
|
var _usePressAnimation = require("./usePressAnimation.js");
|
|
39
|
+
var _useReducedMotion = require("./useReducedMotion.js");
|
|
40
|
+
var _useControllableState = require("./useControllableState.js");
|
|
27
41
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useControllableState = useControllableState;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
/**
|
|
9
|
+
* Bridges controlled and uncontrolled usage for a value+onChange pair. When
|
|
10
|
+
* `value` is provided the component is controlled (the hook just forwards it
|
|
11
|
+
* and calls `onChange`); otherwise the hook owns the state, seeded from
|
|
12
|
+
* `defaultValue`. The controlled/uncontrolled decision is locked on first
|
|
13
|
+
* render so a component never flips modes mid-life.
|
|
14
|
+
*/
|
|
15
|
+
function useControllableState({
|
|
16
|
+
value,
|
|
17
|
+
defaultValue,
|
|
18
|
+
onChange
|
|
19
|
+
}) {
|
|
20
|
+
const isControlledRef = (0, _react.useRef)(value !== undefined);
|
|
21
|
+
const isControlled = isControlledRef.current;
|
|
22
|
+
const [internal, setInternal] = (0, _react.useState)(defaultValue);
|
|
23
|
+
const current = isControlled ? value : internal;
|
|
24
|
+
const setValue = (0, _react.useCallback)(next => {
|
|
25
|
+
if (!isControlled) setInternal(next);
|
|
26
|
+
onChange?.(next);
|
|
27
|
+
}, [isControlled, onChange]);
|
|
28
|
+
return [current, setValue];
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=useControllableState.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useReducedMotion = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
/**
|
|
10
|
+
* Tracks the OS "Reduce Motion" accessibility setting. The library's
|
|
11
|
+
* ThemeProvider uses this to collapse `theme.motion` (durations → 0, springs →
|
|
12
|
+
* near-instant) so animations don't trigger vestibular discomfort; consumers
|
|
13
|
+
* can also read it directly to swap an animated path for a static one.
|
|
14
|
+
*/
|
|
15
|
+
const useReducedMotion = () => {
|
|
16
|
+
const [reduced, setReduced] = (0, _react.useState)(false);
|
|
17
|
+
(0, _react.useEffect)(() => {
|
|
18
|
+
let mounted = true;
|
|
19
|
+
_reactNative.AccessibilityInfo.isReduceMotionEnabled().then(value => {
|
|
20
|
+
if (mounted) setReduced(value);
|
|
21
|
+
});
|
|
22
|
+
const sub = _reactNative.AccessibilityInfo.addEventListener('reduceMotionChanged', value => setReduced(value));
|
|
23
|
+
return () => {
|
|
24
|
+
mounted = false;
|
|
25
|
+
sub.remove();
|
|
26
|
+
};
|
|
27
|
+
}, []);
|
|
28
|
+
return reduced;
|
|
29
|
+
};
|
|
30
|
+
exports.useReducedMotion = useReducedMotion;
|
|
31
|
+
//# sourceMappingURL=useReducedMotion.js.map
|