react-native-system-ui 1.0.0 → 1.0.1
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/dist/cjs/components/action-sheet/ActionSheet.js +45 -51
- package/dist/cjs/components/area/Area.js +22 -22
- package/dist/cjs/components/avatar/Avatar.js +23 -23
- package/dist/cjs/components/badge/Badge.js +56 -61
- package/dist/cjs/components/button/Button.js +87 -92
- package/dist/cjs/components/button/ButtonGroup.js +4 -4
- package/dist/cjs/components/calendar/Calendar.js +28 -28
- package/dist/cjs/components/cascader/Cascader.js +205 -212
- package/dist/cjs/components/cell/Cell.js +54 -51
- package/dist/cjs/components/cell/CellGroup.js +26 -25
- package/dist/cjs/components/checkbox/Checkbox.js +1 -0
- package/dist/cjs/components/checkbox/CheckboxGroup.js +20 -19
- package/dist/cjs/components/circle/Circle.js +66 -54
- package/dist/cjs/components/collapse/Collapse.js +18 -18
- package/dist/cjs/components/config-provider/ConfigProvider.js +5 -5
- package/dist/cjs/components/count-down/CountDown.js +17 -17
- package/dist/cjs/components/datetime-picker/DatetimePicker.js +34 -35
- package/dist/cjs/components/dialog/Dialog.js +16 -10
- package/dist/cjs/components/dialog/imperative.js +8 -14
- package/dist/cjs/components/dialog/tokens.js +1 -0
- package/dist/cjs/components/divider/Divider.js +48 -51
- package/dist/cjs/components/empty/Empty.js +30 -25
- package/dist/cjs/components/error-boundary/ErrorBoundary.js +3 -2
- package/dist/cjs/components/flex/Flex.js +27 -27
- package/dist/cjs/components/flex/FlexItem.js +1 -0
- package/dist/cjs/components/form/Form.js +93 -92
- package/dist/cjs/components/form/FormItem.js +60 -54
- package/dist/cjs/components/form/FormList.js +35 -35
- package/dist/cjs/components/grid/Grid.js +48 -48
- package/dist/cjs/components/grid/GridItem.js +9 -2
- package/dist/cjs/components/image/Image.js +25 -24
- package/dist/cjs/components/image/tokens.js +3 -1
- package/dist/cjs/components/image-preview/ImagePreview.js +19 -19
- package/dist/cjs/components/image-preview/tokens.js +3 -1
- package/dist/cjs/components/input/Input.js +16 -19
- package/dist/cjs/components/loading/Loading.js +27 -27
- package/dist/cjs/components/nav-bar/NavBar.js +21 -18
- package/dist/cjs/components/nav-bar/tokens.js +3 -1
- package/dist/cjs/components/notice-bar/NoticeBar.js +7 -3
- package/dist/cjs/components/notice-bar/tokens.js +3 -1
- package/dist/cjs/components/notify/Notify.js +2 -1
- package/dist/cjs/components/notify/imperative.js +17 -17
- package/dist/cjs/components/notify/tokens.js +1 -0
- package/dist/cjs/components/number-keyboard/NumberKeyboard.js +217 -201
- package/dist/cjs/components/number-keyboard/tokens.js +7 -1
- package/dist/cjs/components/overlay/Overlay.js +15 -15
- package/dist/cjs/components/password-input/PasswordInput.js +49 -49
- package/dist/cjs/components/picker/Picker.js +50 -58
- package/dist/cjs/components/popup/Popup.js +10 -10
- package/dist/cjs/components/popup/tokens.js +1 -0
- package/dist/cjs/components/portal/Portal.js +3 -4
- package/dist/cjs/components/progress/Progress.js +94 -95
- package/dist/cjs/components/progress/tokens.js +1 -0
- package/dist/cjs/components/radio/Radio.js +67 -63
- package/dist/cjs/components/radio/RadioGroup.js +6 -6
- package/dist/cjs/components/safe-area-view/SafeAreaView.js +7 -7
- package/dist/cjs/components/search/Search.js +28 -28
- package/dist/cjs/components/selector/Selector.js +19 -26
- package/dist/cjs/components/share-sheet/ShareSheet.js +6 -1
- package/dist/cjs/components/share-sheet/tokens.js +3 -1
- package/dist/cjs/components/sidebar/Sidebar.js +22 -16
- package/dist/cjs/components/sidebar/SidebarItem.js +9 -8
- package/dist/cjs/components/sidebar/tokens.js +3 -1
- package/dist/cjs/components/skeleton/Skeleton.js +43 -42
- package/dist/cjs/components/space/Space.js +45 -41
- package/dist/cjs/components/space/tokens.js +7 -1
- package/dist/cjs/components/stepper/Stepper.js +17 -15
- package/dist/cjs/components/stepper/tokens.js +1 -0
- package/dist/cjs/components/swiper/Swiper.js +10 -7
- package/dist/cjs/components/swiper/SwiperPagIndicator.js +3 -2
- package/dist/cjs/components/switch/Switch.js +23 -23
- package/dist/cjs/components/tabbar/Tabbar.js +26 -26
- package/dist/cjs/components/tabs/Tabs.js +143 -153
- package/dist/cjs/components/tabs/tokens.js +3 -1
- package/dist/cjs/components/tag/Tag.js +38 -38
- package/dist/cjs/components/toast/Toast.js +3 -2
- package/dist/cjs/components/toast/tokens.js +1 -0
- package/dist/cjs/components/typography/Typography.js +23 -21
- package/dist/cjs/components/water-mark/WaterMark.js +65 -65
- package/dist/cjs/design-system/Text.js +38 -0
- package/dist/cjs/design-system/createComponentTokensHook.js +2 -2
- package/dist/cjs/design-system/index.js +7 -0
- package/dist/cjs/design-system/mergeTokensOverride.js +1 -4
- package/dist/cjs/hooks/useControllableValue.js +11 -11
- package/dist/cjs/hooks/useCountDown.js +18 -18
- package/dist/cjs/platform/measure.js +4 -2
- package/dist/cjs/utils/color.js +2 -7
- package/dist/cjs/utils/compare.js +3 -3
- package/dist/cjs/utils/date.js +2 -2
- package/dist/cjs/utils/deepMerge.js +5 -5
- package/dist/cjs/utils/hairline.js +1 -0
- package/dist/cjs/utils/render.js +2 -8
- package/dist/cjs/utils/validate.js +2 -4
- package/dist/es/components/action-sheet/ActionSheet.js +45 -51
- package/dist/es/components/area/Area.js +22 -22
- package/dist/es/components/avatar/Avatar.js +23 -23
- package/dist/es/components/badge/Badge.js +56 -61
- package/dist/es/components/button/Button.js +87 -92
- package/dist/es/components/button/ButtonGroup.js +4 -4
- package/dist/es/components/calendar/Calendar.js +28 -28
- package/dist/es/components/cascader/Cascader.js +205 -212
- package/dist/es/components/cell/Cell.js +55 -52
- package/dist/es/components/cell/CellGroup.js +26 -25
- package/dist/es/components/checkbox/Checkbox.js +1 -0
- package/dist/es/components/checkbox/CheckboxGroup.js +20 -19
- package/dist/es/components/circle/Circle.js +66 -54
- package/dist/es/components/collapse/Collapse.js +18 -18
- package/dist/es/components/config-provider/ConfigProvider.js +5 -5
- package/dist/es/components/count-down/CountDown.js +17 -17
- package/dist/es/components/datetime-picker/DatetimePicker.js +34 -35
- package/dist/es/components/dialog/Dialog.js +16 -10
- package/dist/es/components/dialog/imperative.js +8 -14
- package/dist/es/components/dialog/tokens.js +1 -0
- package/dist/es/components/divider/Divider.js +48 -51
- package/dist/es/components/empty/Empty.js +30 -25
- package/dist/es/components/error-boundary/ErrorBoundary.js +3 -2
- package/dist/es/components/flex/Flex.js +27 -27
- package/dist/es/components/flex/FlexItem.js +1 -0
- package/dist/es/components/form/Form.js +93 -92
- package/dist/es/components/form/FormItem.js +60 -54
- package/dist/es/components/form/FormList.js +35 -35
- package/dist/es/components/grid/Grid.js +48 -48
- package/dist/es/components/grid/GridItem.js +10 -3
- package/dist/es/components/image/Image.js +25 -24
- package/dist/es/components/image/tokens.js +3 -1
- package/dist/es/components/image-preview/ImagePreview.js +19 -19
- package/dist/es/components/image-preview/tokens.js +3 -1
- package/dist/es/components/input/Input.js +16 -19
- package/dist/es/components/loading/Loading.js +27 -27
- package/dist/es/components/nav-bar/NavBar.js +21 -18
- package/dist/es/components/nav-bar/tokens.js +3 -1
- package/dist/es/components/notice-bar/NoticeBar.js +7 -3
- package/dist/es/components/notice-bar/tokens.js +3 -1
- package/dist/es/components/notify/Notify.js +2 -1
- package/dist/es/components/notify/imperative.js +17 -17
- package/dist/es/components/notify/tokens.js +1 -0
- package/dist/es/components/number-keyboard/NumberKeyboard.js +217 -201
- package/dist/es/components/number-keyboard/tokens.js +7 -1
- package/dist/es/components/overlay/Overlay.js +15 -15
- package/dist/es/components/password-input/PasswordInput.js +49 -49
- package/dist/es/components/picker/Picker.js +50 -58
- package/dist/es/components/popup/Popup.js +10 -10
- package/dist/es/components/popup/tokens.js +1 -0
- package/dist/es/components/portal/Portal.js +3 -4
- package/dist/es/components/progress/Progress.js +94 -95
- package/dist/es/components/progress/tokens.js +1 -0
- package/dist/es/components/radio/Radio.js +67 -63
- package/dist/es/components/radio/RadioGroup.js +6 -6
- package/dist/es/components/safe-area-view/SafeAreaView.js +7 -7
- package/dist/es/components/search/Search.js +28 -28
- package/dist/es/components/selector/Selector.js +19 -26
- package/dist/es/components/share-sheet/ShareSheet.js +6 -1
- package/dist/es/components/share-sheet/tokens.js +3 -1
- package/dist/es/components/sidebar/Sidebar.js +22 -16
- package/dist/es/components/sidebar/SidebarItem.js +9 -8
- package/dist/es/components/sidebar/tokens.js +3 -1
- package/dist/es/components/skeleton/Skeleton.js +43 -42
- package/dist/es/components/space/Space.js +45 -41
- package/dist/es/components/space/tokens.js +7 -1
- package/dist/es/components/stepper/Stepper.js +17 -15
- package/dist/es/components/stepper/tokens.js +1 -0
- package/dist/es/components/swiper/Swiper.js +11 -8
- package/dist/es/components/swiper/SwiperPagIndicator.js +3 -2
- package/dist/es/components/switch/Switch.js +23 -23
- package/dist/es/components/tabbar/Tabbar.js +26 -26
- package/dist/es/components/tabs/Tabs.js +144 -154
- package/dist/es/components/tabs/tokens.js +3 -1
- package/dist/es/components/tag/Tag.js +38 -38
- package/dist/es/components/toast/Toast.js +3 -2
- package/dist/es/components/toast/tokens.js +1 -0
- package/dist/es/components/typography/Typography.js +23 -21
- package/dist/es/components/water-mark/WaterMark.js +65 -65
- package/dist/es/design-system/Text.js +19 -0
- package/dist/es/design-system/createComponentTokensHook.js +2 -2
- package/dist/es/design-system/index.js +1 -0
- package/dist/es/design-system/mergeTokensOverride.js +1 -4
- package/dist/es/hooks/useControllableValue.js +11 -11
- package/dist/es/hooks/useCountDown.js +18 -18
- package/dist/es/platform/measure.js +4 -2
- package/dist/es/utils/color.js +1 -4
- package/dist/es/utils/compare.js +3 -3
- package/dist/es/utils/date.js +2 -2
- package/dist/es/utils/deepMerge.js +5 -5
- package/dist/es/utils/hairline.js +1 -0
- package/dist/es/utils/render.js +1 -1
- package/dist/es/utils/validate.js +1 -2
- package/dist/types/components/dialog/tokens.d.ts +1 -0
- package/dist/types/components/image-preview/tokens.d.ts +1 -0
- package/dist/types/components/nav-bar/tokens.d.ts +1 -1
- package/dist/types/components/notice-bar/tokens.d.ts +1 -0
- package/dist/types/components/number-keyboard/tokens.d.ts +5 -0
- package/dist/types/components/picker/Picker.d.ts +1 -1
- package/dist/types/components/popup/tokens.d.ts +1 -0
- package/dist/types/components/share-sheet/tokens.d.ts +1 -0
- package/dist/types/components/stepper/tokens.d.ts +1 -0
- package/dist/types/components/tabs/tokens.d.ts +1 -0
- package/dist/types/components/toast/tokens.d.ts +1 -0
- package/dist/types/design-system/Text.d.ts +3 -0
- package/dist/types/design-system/index.d.ts +1 -0
- package/dist/types/hooks/useCountDown.d.ts +1 -1
- package/dist/types/utils/color.d.ts +0 -2
- package/dist/types/utils/date.d.ts +1 -1
- package/dist/types/utils/render.d.ts +1 -1
- package/dist/types/utils/validate.d.ts +0 -1
- package/package.json +17 -3
|
@@ -23,42 +23,45 @@ const FormItemImpl = ({
|
|
|
23
23
|
}) => {
|
|
24
24
|
const renderProps = typeof children === 'function';
|
|
25
25
|
const ctx = useContext(FormContext);
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
26
|
+
const normRules = rules ?? EMPTY_RULES;
|
|
27
|
+
const nKey = name ? serializeNamePath(name) : undefined;
|
|
28
|
+
const shouldAlwaysUp = renderProps && !nKey && !shouldUpdate;
|
|
29
|
+
const prevValsRef = useRef(EMPTY_VALUES);
|
|
30
30
|
const [, forceUpdate] = useState(0);
|
|
31
31
|
useEffect(() => {
|
|
32
32
|
if (!ctx?.subscribe) return undefined;
|
|
33
|
-
return ctx.subscribe((
|
|
34
|
-
if (FORM_ALL_FIELDS_KEY in
|
|
33
|
+
return ctx.subscribe((ch, all) => {
|
|
34
|
+
if (FORM_ALL_FIELDS_KEY in ch) {
|
|
35
35
|
forceUpdate(v => v + 1);
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
;
|
|
39
|
+
if (shouldAlwaysUp) {
|
|
39
40
|
forceUpdate(v => v + 1);
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
43
|
+
;
|
|
42
44
|
if (shouldUpdate) {
|
|
43
|
-
if (shouldUpdate(
|
|
45
|
+
if (shouldUpdate(prevValsRef.current, all)) forceUpdate(v => v + 1);
|
|
44
46
|
return;
|
|
45
47
|
}
|
|
46
|
-
|
|
48
|
+
;
|
|
49
|
+
if (nKey && nKey in ch) forceUpdate(v => v + 1);
|
|
47
50
|
});
|
|
48
|
-
}, [ctx,
|
|
49
|
-
const
|
|
51
|
+
}, [ctx, nKey, shouldUpdate, shouldAlwaysUp]);
|
|
52
|
+
const curVals = ctx?.getFieldsValue() ?? EMPTY_VALUES;
|
|
50
53
|
useEffect(() => {
|
|
51
|
-
|
|
52
|
-
}, [
|
|
54
|
+
prevValsRef.current = curVals;
|
|
55
|
+
}, [curVals]);
|
|
53
56
|
useEffect(() => {
|
|
54
57
|
if (!name || !ctx) return undefined;
|
|
55
58
|
return ctx.registerField(name, {
|
|
56
|
-
rules:
|
|
59
|
+
rules: normRules,
|
|
57
60
|
dependencies,
|
|
58
61
|
initialValue,
|
|
59
62
|
validateTrigger: validateTrigger ?? trigger
|
|
60
63
|
});
|
|
61
|
-
}, [ctx, name,
|
|
64
|
+
}, [ctx, name, normRules, dependencies, initialValue, validateTrigger, trigger]);
|
|
62
65
|
if (!ctx) {
|
|
63
66
|
if (renderProps) return /*#__PURE__*/React.createElement(React.Fragment, null, children({
|
|
64
67
|
getFieldValue: () => undefined,
|
|
@@ -67,13 +70,14 @@ const FormItemImpl = ({
|
|
|
67
70
|
}));
|
|
68
71
|
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
69
72
|
}
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
const
|
|
73
|
+
;
|
|
74
|
+
const shouldRender = !shouldUpdate || shouldUpdate(prevValsRef.current, curVals);
|
|
75
|
+
const modelVal = name ? ctx.getFieldValue(name) : undefined;
|
|
76
|
+
const rShowMsg = showValidateMessage ?? ctx.showValidateMessage ?? true;
|
|
77
|
+
const fieldErrs = name ? ctx.getFieldError(name) : undefined;
|
|
78
|
+
const fieldErr = rShowMsg ? fieldErrs?.[0] : undefined;
|
|
79
|
+
const rRequired = required ?? normRules.some(r => r.required);
|
|
80
|
+
const rValidateTrigger = normalizeTrigger(validateTrigger ?? trigger);
|
|
77
81
|
if (renderProps) {
|
|
78
82
|
if (!shouldRender) return null;
|
|
79
83
|
return /*#__PURE__*/React.createElement(React.Fragment, null, children({
|
|
@@ -82,50 +86,52 @@ const FormItemImpl = ({
|
|
|
82
86
|
form: ctx.form || null
|
|
83
87
|
}));
|
|
84
88
|
}
|
|
89
|
+
;
|
|
85
90
|
if (!name) return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
86
91
|
if (!shouldRender) return null;
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
89
|
-
const child =
|
|
92
|
+
const chArr = React.Children.toArray(children);
|
|
93
|
+
if (chArr.length !== 1) return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
94
|
+
const child = chArr[0];
|
|
90
95
|
const handleChange = next => {
|
|
91
96
|
ctx.setFieldValue(name, next, trigger);
|
|
92
|
-
const
|
|
93
|
-
if (isFunction(
|
|
97
|
+
const orig = child.props[trigger];
|
|
98
|
+
if (isFunction(orig)) orig(next);
|
|
94
99
|
};
|
|
95
|
-
const
|
|
96
|
-
const isFieldLike = isString(
|
|
97
|
-
const
|
|
98
|
-
const
|
|
99
|
-
if (
|
|
100
|
-
if (
|
|
100
|
+
const dispName = child.type.displayName;
|
|
101
|
+
const isFieldLike = isString(dispName) && (dispName.includes('Field') || dispName.includes('Input'));
|
|
102
|
+
const rValue = () => {
|
|
103
|
+
const cv = child.props[valuePropName];
|
|
104
|
+
if (cv !== undefined) return cv;
|
|
105
|
+
if (modelVal !== undefined) return modelVal;
|
|
101
106
|
if (isFieldLike && valuePropName === 'value') return '';
|
|
102
|
-
return
|
|
107
|
+
return modelVal;
|
|
103
108
|
};
|
|
104
|
-
const
|
|
105
|
-
[valuePropName]:
|
|
109
|
+
const injected = {
|
|
110
|
+
[valuePropName]: rValue(),
|
|
106
111
|
[trigger]: handleChange
|
|
107
112
|
};
|
|
108
|
-
|
|
109
|
-
if (!
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
if (isFunction(
|
|
113
|
-
ctx.validateField(name,
|
|
113
|
+
rValidateTrigger.forEach(ev => {
|
|
114
|
+
if (!ev || ev === trigger) return;
|
|
115
|
+
const orig = child.props[ev];
|
|
116
|
+
injected[ev] = (...args) => {
|
|
117
|
+
if (isFunction(orig)) orig(...args);
|
|
118
|
+
ctx.validateField(name, ev);
|
|
114
119
|
};
|
|
115
120
|
});
|
|
116
|
-
const
|
|
117
|
-
if (label !== undefined &&
|
|
118
|
-
if (ctx.colon !== undefined &&
|
|
119
|
-
if (ctx.labelWidth !== undefined &&
|
|
120
|
-
if (description &&
|
|
121
|
-
if (intro &&
|
|
122
|
-
if (tooltip &&
|
|
123
|
-
if (
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
|
|
121
|
+
const cp = child.props;
|
|
122
|
+
if (label !== undefined && cp.label === undefined) injected.label = label;
|
|
123
|
+
if (ctx.colon !== undefined && injected.label !== undefined && cp.colon === undefined) injected.colon = ctx.colon;
|
|
124
|
+
if (ctx.labelWidth !== undefined && cp.labelWidth === undefined) injected.labelWidth = ctx.labelWidth;
|
|
125
|
+
if (description && cp.description === undefined) injected.description = description;
|
|
126
|
+
if (intro && cp.intro === undefined) injected.intro = intro;
|
|
127
|
+
if (tooltip && cp.tooltip === undefined) injected.tooltip = tooltip;
|
|
128
|
+
if (rRequired && cp.required === undefined) injected.required = true;
|
|
129
|
+
if (fieldErr && cp.errorMessage === undefined) {
|
|
130
|
+
injected.error = true;
|
|
131
|
+
injected.errorMessage = fieldErr;
|
|
127
132
|
}
|
|
128
|
-
|
|
133
|
+
;
|
|
134
|
+
return /*#__PURE__*/React.cloneElement(child, injected);
|
|
129
135
|
};
|
|
130
136
|
FormItemImpl.displayName = 'FormItem';
|
|
131
137
|
export const FormItem = /*#__PURE__*/React.memo(FormItemImpl);
|
|
@@ -10,62 +10,62 @@ export const FormList = ({
|
|
|
10
10
|
initialValue,
|
|
11
11
|
children
|
|
12
12
|
}) => {
|
|
13
|
-
const
|
|
14
|
-
const keyCounterRef = useRef(0)
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const [listValue, setListValue] = useState(() =>
|
|
18
|
-
const syncKeys = useCallback(
|
|
19
|
-
const
|
|
20
|
-
while (
|
|
21
|
-
if (
|
|
13
|
+
const ctx = useContext(FormContext);
|
|
14
|
+
const keyCounterRef = useRef(0);
|
|
15
|
+
const keysRef = useRef([]);
|
|
16
|
+
const nKey = serializeNamePath(name);
|
|
17
|
+
const [listValue, setListValue] = useState(() => ctx ? getList(ctx, name) : []);
|
|
18
|
+
const syncKeys = useCallback(len => {
|
|
19
|
+
const k = keysRef.current;
|
|
20
|
+
while (k.length < len) k.push(keyCounterRef.current++);
|
|
21
|
+
if (k.length > len) keysRef.current = k.slice(0, len);
|
|
22
22
|
}, []);
|
|
23
23
|
const ensureInitial = useCallback(() => {
|
|
24
|
-
if (!
|
|
25
|
-
if (getValueByName(
|
|
26
|
-
}, [
|
|
24
|
+
if (!ctx) return;
|
|
25
|
+
if (getValueByName(ctx.getFieldsValue(), name) === undefined && initialValue !== undefined) ctx.setFieldValue(name, initialValue);
|
|
26
|
+
}, [ctx, initialValue, name]);
|
|
27
27
|
useEffect(() => {
|
|
28
28
|
ensureInitial();
|
|
29
29
|
}, [ensureInitial]);
|
|
30
30
|
useEffect(() => {
|
|
31
|
-
if (!
|
|
32
|
-
return
|
|
33
|
-
if (FORM_ALL_FIELDS_KEY in
|
|
31
|
+
if (!ctx?.subscribe) return undefined;
|
|
32
|
+
return ctx.subscribe((ch, all) => {
|
|
33
|
+
if (FORM_ALL_FIELDS_KEY in ch || nKey in ch) {
|
|
34
34
|
const next = getValueByName(all, name);
|
|
35
35
|
const nl = Array.isArray(next) ? next : [];
|
|
36
36
|
syncKeys(nl.length);
|
|
37
37
|
setListValue(nl);
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
|
-
}, [
|
|
40
|
+
}, [ctx, name, nKey, syncKeys]);
|
|
41
41
|
const add = useCallback((defaultValue, index) => {
|
|
42
|
-
if (!
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
if (!ctx) return;
|
|
43
|
+
const a = getList(ctx, name);
|
|
44
|
+
const i = typeof index === 'number' ? index : a.length;
|
|
45
|
+
const next = [...a];
|
|
46
46
|
next.splice(i, 0, defaultValue);
|
|
47
47
|
keysRef.current.splice(i, 0, keyCounterRef.current++);
|
|
48
|
-
|
|
49
|
-
}, [
|
|
48
|
+
ctx.setFieldValue(name, next);
|
|
49
|
+
}, [ctx, name]);
|
|
50
50
|
const remove = useCallback(index => {
|
|
51
|
-
if (!
|
|
52
|
-
const
|
|
53
|
-
if (index < 0 || index >=
|
|
51
|
+
if (!ctx) return;
|
|
52
|
+
const a = getList(ctx, name);
|
|
53
|
+
if (index < 0 || index >= a.length) return;
|
|
54
54
|
keysRef.current.splice(index, 1);
|
|
55
|
-
|
|
56
|
-
}, [
|
|
55
|
+
ctx.setFieldValue(name, a.slice(0, index).concat(a.slice(index + 1)));
|
|
56
|
+
}, [ctx, name]);
|
|
57
57
|
const move = useCallback((from, to) => {
|
|
58
|
-
if (!
|
|
59
|
-
const
|
|
60
|
-
if (from === to || from < 0 || to < 0 || from >=
|
|
61
|
-
const next = [...
|
|
62
|
-
|
|
58
|
+
if (!ctx) return;
|
|
59
|
+
const a = getList(ctx, name);
|
|
60
|
+
if (from === to || from < 0 || to < 0 || from >= a.length || to >= a.length) return;
|
|
61
|
+
const next = [...a];
|
|
62
|
+
const item = next.splice(from, 1)[0];
|
|
63
63
|
next.splice(to, 0, item);
|
|
64
64
|
const [movedKey] = keysRef.current.splice(from, 1);
|
|
65
65
|
keysRef.current.splice(to, 0, movedKey);
|
|
66
|
-
|
|
67
|
-
}, [
|
|
68
|
-
if (!
|
|
66
|
+
ctx.setFieldValue(name, next);
|
|
67
|
+
}, [ctx, name]);
|
|
68
|
+
if (!ctx) return null;
|
|
69
69
|
syncKeys(listValue.length);
|
|
70
70
|
const fields = listValue.map((_, i) => ({
|
|
71
71
|
name: i,
|
|
@@ -8,72 +8,72 @@ const GridImpl = props => {
|
|
|
8
8
|
const {
|
|
9
9
|
tokensOverride,
|
|
10
10
|
children,
|
|
11
|
-
columnNum:
|
|
12
|
-
gutter:
|
|
13
|
-
border:
|
|
14
|
-
center:
|
|
15
|
-
square:
|
|
16
|
-
direction:
|
|
17
|
-
reverse:
|
|
18
|
-
clickable:
|
|
19
|
-
iconSize:
|
|
11
|
+
columnNum: colNumP,
|
|
12
|
+
gutter: gutP,
|
|
13
|
+
border: borderP,
|
|
14
|
+
center: centerP,
|
|
15
|
+
square: sqP,
|
|
16
|
+
direction: dirP,
|
|
17
|
+
reverse: revP,
|
|
18
|
+
clickable: clkP,
|
|
19
|
+
iconSize: iconSzP,
|
|
20
20
|
iconColor,
|
|
21
21
|
style,
|
|
22
22
|
...rest
|
|
23
23
|
} = props;
|
|
24
24
|
const tokens = useGridTokens(tokensOverride);
|
|
25
25
|
const columnNum = useMemo(() => {
|
|
26
|
-
const
|
|
27
|
-
return Number.isFinite(
|
|
28
|
-
}, [
|
|
26
|
+
const v = colNumP ?? tokens.defaults.columnNum;
|
|
27
|
+
return Number.isFinite(v) && v > 0 ? Math.floor(v) : tokens.defaults.columnNum;
|
|
28
|
+
}, [colNumP, tokens.defaults.columnNum]);
|
|
29
29
|
const gutter = useMemo(() => {
|
|
30
|
-
const
|
|
31
|
-
return Number.isFinite(
|
|
32
|
-
}, [
|
|
33
|
-
const border =
|
|
34
|
-
const center =
|
|
35
|
-
const square =
|
|
36
|
-
const direction =
|
|
37
|
-
const reverse =
|
|
38
|
-
const clickable =
|
|
30
|
+
const v = gutP ?? tokens.defaults.gutter;
|
|
31
|
+
return Number.isFinite(v) && v > 0 ? v : 0;
|
|
32
|
+
}, [gutP, tokens.defaults.gutter]);
|
|
33
|
+
const border = borderP ?? tokens.defaults.border;
|
|
34
|
+
const center = centerP ?? tokens.defaults.center;
|
|
35
|
+
const square = sqP ?? tokens.defaults.square;
|
|
36
|
+
const direction = dirP ?? tokens.defaults.direction;
|
|
37
|
+
const reverse = revP ?? tokens.defaults.reverse;
|
|
38
|
+
const clickable = clkP ?? tokens.defaults.clickable;
|
|
39
39
|
const iconSize = useMemo(() => {
|
|
40
|
-
const
|
|
41
|
-
return Number.isFinite(
|
|
42
|
-
}, [
|
|
43
|
-
const childrenArray = useMemo(() => React.Children.toArray(children).filter(
|
|
40
|
+
const v = iconSzP ?? tokens.defaults.iconSize;
|
|
41
|
+
return Number.isFinite(v) && v > 0 ? v : tokens.defaults.iconSize;
|
|
42
|
+
}, [iconSzP, tokens.defaults.iconSize]);
|
|
43
|
+
const childrenArray = useMemo(() => React.Children.toArray(children).filter(c => /*#__PURE__*/React.isValidElement(c)), [children]);
|
|
44
44
|
const showBorder = border && !gutter;
|
|
45
|
-
const
|
|
45
|
+
const borderClr = tokens.colors.border;
|
|
46
46
|
const topBorder = useMemo(() => showBorder ? /*#__PURE__*/React.createElement(View, {
|
|
47
47
|
style: [tokens.layout.border, tokens.layout.borderTop, createHairlineView({
|
|
48
48
|
position: 'top',
|
|
49
|
-
color:
|
|
49
|
+
color: borderClr,
|
|
50
50
|
left: 0,
|
|
51
51
|
right: 0,
|
|
52
52
|
top: 0
|
|
53
53
|
})]
|
|
54
|
-
}) : null, [
|
|
54
|
+
}) : null, [borderClr, showBorder, tokens.layout.border, tokens.layout.borderTop]);
|
|
55
55
|
const bottomBorder = useMemo(() => showBorder ? /*#__PURE__*/React.createElement(View, {
|
|
56
56
|
style: [tokens.layout.border, tokens.layout.borderBottom, createHairlineView({
|
|
57
57
|
position: 'bottom',
|
|
58
|
-
color:
|
|
58
|
+
color: borderClr,
|
|
59
59
|
left: 0,
|
|
60
60
|
right: 0,
|
|
61
61
|
bottom: 0
|
|
62
62
|
})]
|
|
63
|
-
}) : null, [
|
|
64
|
-
const
|
|
65
|
-
columnNum
|
|
66
|
-
gutter
|
|
67
|
-
border
|
|
68
|
-
center
|
|
69
|
-
square
|
|
70
|
-
direction
|
|
71
|
-
reverse
|
|
72
|
-
clickable
|
|
73
|
-
iconSize
|
|
63
|
+
}) : null, [borderClr, showBorder, tokens.layout.border, tokens.layout.borderBottom]);
|
|
64
|
+
const ctxVal = useMemo(() => ({
|
|
65
|
+
columnNum,
|
|
66
|
+
gutter,
|
|
67
|
+
border,
|
|
68
|
+
center,
|
|
69
|
+
square,
|
|
70
|
+
direction,
|
|
71
|
+
reverse,
|
|
72
|
+
clickable,
|
|
73
|
+
iconSize,
|
|
74
74
|
iconColor,
|
|
75
75
|
count: childrenArray.length,
|
|
76
|
-
tokens
|
|
76
|
+
tokens
|
|
77
77
|
}), [border, center, childrenArray.length, clickable, columnNum, direction, gutter, iconColor, iconSize, reverse, square, tokens]);
|
|
78
78
|
const webGridStyle = useMemo(() => Platform.OS === 'web' ? {
|
|
79
79
|
display: 'grid',
|
|
@@ -81,19 +81,19 @@ const GridImpl = props => {
|
|
|
81
81
|
columnGap: gutter,
|
|
82
82
|
rowGap: gutter
|
|
83
83
|
} : undefined, [columnNum, gutter]);
|
|
84
|
-
const
|
|
84
|
+
const ctrStyle = useMemo(() => [tokens.layout.container, Platform.OS === 'web' ? webGridStyle : gutter ? {
|
|
85
85
|
paddingLeft: gutter
|
|
86
86
|
} : undefined, style], [gutter, style, tokens.layout.container, webGridStyle]);
|
|
87
|
-
const
|
|
88
|
-
gridItemIndex:
|
|
89
|
-
key: child.key ??
|
|
87
|
+
const rendered = useMemo(() => childrenArray.map((child, i) => /*#__PURE__*/React.cloneElement(child, {
|
|
88
|
+
gridItemIndex: i,
|
|
89
|
+
key: child.key ?? i
|
|
90
90
|
})), [childrenArray]);
|
|
91
91
|
return /*#__PURE__*/React.createElement(GridContext.Provider, {
|
|
92
|
-
value:
|
|
92
|
+
value: ctxVal
|
|
93
93
|
}, /*#__PURE__*/React.createElement(View, _extends({
|
|
94
94
|
accessibilityRole: 'grid',
|
|
95
|
-
style:
|
|
96
|
-
}, rest), topBorder,
|
|
95
|
+
style: ctrStyle
|
|
96
|
+
}, rest), topBorder, rendered, bottomBorder));
|
|
97
97
|
};
|
|
98
98
|
export const Grid = /*#__PURE__*/React.memo(GridImpl);
|
|
99
99
|
Grid.displayName = 'Grid';
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
2
|
import React, { useContext, useMemo } from 'react';
|
|
3
|
-
import { Platform, Pressable,
|
|
3
|
+
import { Platform, Pressable, View } from 'react-native';
|
|
4
|
+
import { Text } from '../../design-system';
|
|
4
5
|
import Badge from '../badge';
|
|
5
|
-
import { createHairlineView, isFunction, isRenderable, isText } from '../../utils';
|
|
6
|
+
import { createHairlineView, isFunction, isRenderable, isText, renderTextOrNode } from '../../utils';
|
|
6
7
|
import { GridContext } from './GridContext';
|
|
7
8
|
const GridItemImpl = p => {
|
|
8
9
|
const ctx = useContext(GridContext);
|
|
@@ -47,7 +48,13 @@ const GridItemImpl = p => {
|
|
|
47
48
|
const ht = isRenderable(text);
|
|
48
49
|
const ric = icp ?? ic ?? t.colors.text;
|
|
49
50
|
const icn = useMemo(() => {
|
|
50
|
-
if (children) return children
|
|
51
|
+
if (children) return isText(children) ? renderTextOrNode(children, [t.layout.text, {
|
|
52
|
+
color: t.colors.text,
|
|
53
|
+
fontSize: t.typography.fontSize,
|
|
54
|
+
lineHeight: t.typography.lineHeight,
|
|
55
|
+
fontFamily: t.typography.fontFamily,
|
|
56
|
+
fontWeight: t.typography.fontWeight
|
|
57
|
+
}, textStyle]) : children;
|
|
51
58
|
let ie = null;
|
|
52
59
|
if (icon || badge || dot) {
|
|
53
60
|
const {
|
|
@@ -72,15 +72,15 @@ const ImageImpl = (props, ref) => {
|
|
|
72
72
|
height,
|
|
73
73
|
radius,
|
|
74
74
|
round,
|
|
75
|
-
fit:
|
|
76
|
-
showLoading:
|
|
77
|
-
showError:
|
|
78
|
-
loadingText:
|
|
75
|
+
fit: fitP,
|
|
76
|
+
showLoading: showLoadP,
|
|
77
|
+
showError: showErrP,
|
|
78
|
+
loadingText: loadTxtP,
|
|
79
79
|
loadingIcon,
|
|
80
80
|
errorIcon,
|
|
81
|
-
iconSize:
|
|
81
|
+
iconSize: iconSzP,
|
|
82
82
|
loadingSize,
|
|
83
|
-
errorText:
|
|
83
|
+
errorText: errTxtP,
|
|
84
84
|
fallback,
|
|
85
85
|
onPress,
|
|
86
86
|
alt,
|
|
@@ -96,11 +96,11 @@ const ImageImpl = (props, ref) => {
|
|
|
96
96
|
} = props;
|
|
97
97
|
const locale = useLocale();
|
|
98
98
|
const tokens = useImageTokens(tokensOverride);
|
|
99
|
-
const fit =
|
|
100
|
-
const showLoading =
|
|
101
|
-
const showError =
|
|
102
|
-
const loadingText =
|
|
103
|
-
const errorText =
|
|
99
|
+
const fit = fitP ?? tokens.defaults.fit;
|
|
100
|
+
const showLoading = showLoadP ?? tokens.defaults.showLoading;
|
|
101
|
+
const showError = showErrP ?? tokens.defaults.showError;
|
|
102
|
+
const loadingText = loadTxtP !== undefined ? loadTxtP : locale?.vanImage?.loading ?? tokens.defaults.loadingText;
|
|
103
|
+
const errorText = errTxtP !== undefined ? errTxtP : locale?.vanImage?.error ?? tokens.defaults.errorText;
|
|
104
104
|
const {
|
|
105
105
|
container: containerLayoutStyle,
|
|
106
106
|
image: imageStyleWithLayout
|
|
@@ -111,14 +111,15 @@ const ImageImpl = (props, ref) => {
|
|
|
111
111
|
const sourceKey = useMemo(() => {
|
|
112
112
|
if (source) {
|
|
113
113
|
if (typeof source === 'number') return `res:${source}`;
|
|
114
|
-
const
|
|
115
|
-
if (
|
|
114
|
+
const u = resolveSourceUri(source);
|
|
115
|
+
if (u) return `uri:${u}`;
|
|
116
116
|
return 'source:unknown';
|
|
117
117
|
}
|
|
118
|
+
;
|
|
118
119
|
if (src) return `src:${src}`;
|
|
119
120
|
return 'none';
|
|
120
121
|
}, [source, src]);
|
|
121
|
-
const
|
|
122
|
+
const accLabel = alt ?? accessibilityLabel ?? ariaLabel;
|
|
122
123
|
const [state, setState] = useState(() => actualSource ? 'loading' : 'idle');
|
|
123
124
|
useEffect(() => {
|
|
124
125
|
setState(actualSource ? 'loading' : 'idle');
|
|
@@ -150,8 +151,8 @@ const ImageImpl = (props, ref) => {
|
|
|
150
151
|
const uri = useMemo(() => resolveSourceUri(actualSource), [actualSource]);
|
|
151
152
|
const normalizedUri = isString(uri) ? uri.toLowerCase() : undefined;
|
|
152
153
|
const isSvg = !!normalizedUri && (normalizedUri.endsWith('.svg') || normalizedUri.includes('.svg?') || normalizedUri.includes('/svg?'));
|
|
153
|
-
const
|
|
154
|
-
const
|
|
154
|
+
const rLoadSz = isNumber(loadingSize) ? loadingSize : tokens.defaults.loadingIndicatorBaseSize;
|
|
155
|
+
const rErrIconSz = iconSzP ?? tokens.defaults.iconSize;
|
|
155
156
|
const clickableRole = onPress ? 'button' : undefined;
|
|
156
157
|
const pressableProps = onPress ? {
|
|
157
158
|
onPress
|
|
@@ -178,14 +179,14 @@ const ImageImpl = (props, ref) => {
|
|
|
178
179
|
} : isNumber(radius) ? {
|
|
179
180
|
borderRadius: radius
|
|
180
181
|
} : undefined, containerStyle, containerLayoutStyle], [containerLayoutStyle, containerStyle, height, radius, round, tokens.colors.background, tokens.defaults.roundRadius, tokens.layout.container, width]);
|
|
181
|
-
const
|
|
182
|
+
const imgAccLabel = !onPress ? accLabel : undefined;
|
|
182
183
|
const imageNode = actualSource ? isSvg && Platform.OS !== 'web' && uri ? /*#__PURE__*/React.createElement(SvgUri, _extends({
|
|
183
184
|
width: "100%",
|
|
184
185
|
height: "100%",
|
|
185
186
|
uri: uri,
|
|
186
187
|
preserveAspectRatio: resolvePreserveAspectRatio(fit),
|
|
187
188
|
accessible: !onPress,
|
|
188
|
-
accessibilityLabel:
|
|
189
|
+
accessibilityLabel: imgAccLabel
|
|
189
190
|
}, rest, {
|
|
190
191
|
style: [tokens.layout.absoluteFill, imageStyleWithLayout],
|
|
191
192
|
onLoad: handleSvgLoad,
|
|
@@ -193,7 +194,7 @@ const ImageImpl = (props, ref) => {
|
|
|
193
194
|
})) : /*#__PURE__*/React.createElement(RNImage, _extends({
|
|
194
195
|
ref: ref,
|
|
195
196
|
accessible: !onPress,
|
|
196
|
-
accessibilityLabel:
|
|
197
|
+
accessibilityLabel: imgAccLabel
|
|
197
198
|
}, rest, {
|
|
198
199
|
source: actualSource,
|
|
199
200
|
style: [tokens.layout.absoluteFill, imageStyleWithLayout, WEB_IMAGE_STYLE],
|
|
@@ -210,7 +211,7 @@ const ImageImpl = (props, ref) => {
|
|
|
210
211
|
size: isString(loadingSize) ? loadingSize : 'small',
|
|
211
212
|
style: {
|
|
212
213
|
transform: [{
|
|
213
|
-
scale:
|
|
214
|
+
scale: rLoadSz / tokens.defaults.loadingIndicatorBaseSize
|
|
214
215
|
}]
|
|
215
216
|
}
|
|
216
217
|
}), renderLabel(loadingText, tokens.colors.text, tokens.defaults.loadingLabelMarginTop)), imageNode, state === 'error' && showError && /*#__PURE__*/React.createElement(View, {
|
|
@@ -219,16 +220,16 @@ const ImageImpl = (props, ref) => {
|
|
|
219
220
|
testID: "rv-image-error"
|
|
220
221
|
}, errorIcon && /*#__PURE__*/React.createElement(View, {
|
|
221
222
|
style: [tokens.layout.iconContainer, {
|
|
222
|
-
width:
|
|
223
|
-
height:
|
|
223
|
+
width: rErrIconSz,
|
|
224
|
+
height: rErrIconSz
|
|
224
225
|
}]
|
|
225
226
|
}, errorIcon), isRenderable(fallback) ? renderLabel(fallback, tokens.colors.error) : renderLabel(errorText, tokens.colors.error)), children);
|
|
226
227
|
return pressableProps ? /*#__PURE__*/React.createElement(Pressable, _extends({}, pressableProps, {
|
|
227
228
|
accessibilityRole: clickableRole,
|
|
228
|
-
accessibilityLabel:
|
|
229
|
+
accessibilityLabel: accLabel,
|
|
229
230
|
style: computedContainerStyle
|
|
230
231
|
}), content) : /*#__PURE__*/React.createElement(View, {
|
|
231
|
-
accessibilityLabel:
|
|
232
|
+
accessibilityLabel: accLabel,
|
|
232
233
|
style: computedContainerStyle
|
|
233
234
|
}, content);
|
|
234
235
|
};
|
|
@@ -4,7 +4,8 @@ const createTokens = foundations => {
|
|
|
4
4
|
palette,
|
|
5
5
|
spacing,
|
|
6
6
|
fontSize,
|
|
7
|
-
radii
|
|
7
|
+
radii,
|
|
8
|
+
typography
|
|
8
9
|
} = foundations;
|
|
9
10
|
return {
|
|
10
11
|
defaults: {
|
|
@@ -34,6 +35,7 @@ const createTokens = foundations => {
|
|
|
34
35
|
justifyContent: 'center'
|
|
35
36
|
},
|
|
36
37
|
label: {
|
|
38
|
+
fontFamily: typography.fontFamily,
|
|
37
39
|
fontSize: fontSize.xs
|
|
38
40
|
},
|
|
39
41
|
iconContainer: {
|