react-native-system-ui 1.0.0 → 1.0.2
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/README.md +3 -3
- package/dist/cjs/components/action-sheet/ActionSheet.js +51 -53
- 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 +206 -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 +94 -93
- 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 +38 -28
- 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 +8 -2
- 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/slider/Slider.js +1 -1
- 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/tabbar/TabbarItem.js +6 -0
- 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 +7 -3
- 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 +51 -53
- 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 +206 -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 +95 -94
- 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 +39 -29
- 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 +8 -2
- 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/slider/Slider.js +3 -3
- 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/tabbar/TabbarItem.js +6 -0
- 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 +7 -3
- 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
|
@@ -10,23 +10,23 @@ import Tabs from "../tabs";
|
|
|
10
10
|
import { useLocale } from "../config-provider/useLocale";
|
|
11
11
|
import { useCascaderTokens } from "./tokens";
|
|
12
12
|
import { useCascaderExtend } from "./useCascaderExtend";
|
|
13
|
-
const getFieldKeys =
|
|
14
|
-
textKey:
|
|
15
|
-
valueKey:
|
|
16
|
-
childrenKey:
|
|
13
|
+
const getFieldKeys = fn => ({
|
|
14
|
+
textKey: fn?.text ?? "text",
|
|
15
|
+
valueKey: fn?.value ?? "value",
|
|
16
|
+
childrenKey: fn?.children ?? "children"
|
|
17
17
|
});
|
|
18
|
-
const resolveRows = (
|
|
19
|
-
const
|
|
20
|
-
let
|
|
21
|
-
|
|
22
|
-
if (!
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
const resolveRows = (opts = [], k, vals) => {
|
|
19
|
+
const sel = [];
|
|
20
|
+
let cur = opts;
|
|
21
|
+
vals.forEach(val => {
|
|
22
|
+
if (!cur?.length) return;
|
|
23
|
+
const m = cur.find(o => o[k.valueKey] === val);
|
|
24
|
+
if (m) {
|
|
25
|
+
sel.push(m);
|
|
26
|
+
cur = m[k.childrenKey] ?? [];
|
|
27
27
|
}
|
|
28
28
|
});
|
|
29
|
-
return
|
|
29
|
+
return sel;
|
|
30
30
|
};
|
|
31
31
|
const CascaderImpl = props => {
|
|
32
32
|
const {
|
|
@@ -50,9 +50,9 @@ const CascaderImpl = props => {
|
|
|
50
50
|
testID,
|
|
51
51
|
children,
|
|
52
52
|
poppable,
|
|
53
|
-
visible:
|
|
54
|
-
defaultVisible:
|
|
55
|
-
onVisibleChange:
|
|
53
|
+
visible: _v,
|
|
54
|
+
defaultVisible: _dv,
|
|
55
|
+
onVisibleChange: _ov,
|
|
56
56
|
closeOnClickOverlay,
|
|
57
57
|
closeOnFinish,
|
|
58
58
|
popupPlacement,
|
|
@@ -63,146 +63,142 @@ const CascaderImpl = props => {
|
|
|
63
63
|
} = props;
|
|
64
64
|
const locale = useLocale();
|
|
65
65
|
const tokens = useCascaderTokens(tokensOverride);
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
const
|
|
66
|
+
const rT = title ?? locale?.vanCascader?.placeholder ?? tokens.defaults.title;
|
|
67
|
+
const rP = placeholder ?? locale?.vanCascader?.placeholder ?? tokens.defaults.placeholder;
|
|
68
|
+
const rAc = activeColor ?? tokens.colors.tabActive;
|
|
69
|
+
const rSH = showHeader ?? tokens.defaults.showHeader;
|
|
70
|
+
const rSw = swipeable ?? tokens.defaults.swipeable;
|
|
71
|
+
const rPop = poppable ?? tokens.defaults.poppable;
|
|
72
|
+
const rCO = closeOnClickOverlay ?? tokens.defaults.closeOnClickOverlay;
|
|
73
|
+
const rCF = closeOnFinish ?? tokens.defaults.closeOnFinish;
|
|
74
|
+
const rPP = popupPlacement ?? tokens.defaults.popupPlacement;
|
|
75
|
+
const rPR = popupRound ?? tokens.defaults.popupRound;
|
|
76
|
+
const rLT = loadingText ?? tokens.defaults.loadingText;
|
|
77
77
|
const [value, setValue] = useControllableValue(props, {
|
|
78
78
|
defaultValue: [],
|
|
79
79
|
trigger: "onChange"
|
|
80
80
|
});
|
|
81
81
|
const keys = getFieldKeys(fieldNames);
|
|
82
|
-
const
|
|
83
|
-
const [
|
|
84
|
-
const
|
|
85
|
-
const [
|
|
82
|
+
const curVal = Array.isArray(value) ? value : [];
|
|
83
|
+
const [pending, setPending] = useState(curVal);
|
|
84
|
+
const showCl = closeable ?? tokens.defaults.closeable;
|
|
85
|
+
const [popVis, setPopVis] = useControllableValue(props, {
|
|
86
86
|
defaultValue: false,
|
|
87
87
|
valuePropName: "visible",
|
|
88
88
|
defaultValuePropName: "defaultVisible",
|
|
89
89
|
trigger: "onVisibleChange"
|
|
90
90
|
});
|
|
91
|
-
const
|
|
91
|
+
const cur = rPop ? pending : curVal;
|
|
92
92
|
const {
|
|
93
93
|
tabs,
|
|
94
94
|
items,
|
|
95
95
|
depth
|
|
96
|
-
} = useCascaderExtend(options, keys,
|
|
96
|
+
} = useCascaderExtend(options, keys, cur);
|
|
97
97
|
const {
|
|
98
|
-
width:
|
|
98
|
+
width: winW
|
|
99
99
|
} = useWindowDimensions();
|
|
100
|
-
const [
|
|
101
|
-
const
|
|
102
|
-
const
|
|
103
|
-
if (
|
|
104
|
-
setMeasuredWidth(prev => prev === width ? prev : width);
|
|
100
|
+
const [measW, setMeasW] = useState(0);
|
|
101
|
+
const onTabsLayout = useCallback(e => {
|
|
102
|
+
const w = e.nativeEvent.layout.width;
|
|
103
|
+
if (w) setMeasW(prev => prev === w ? prev : w);
|
|
105
104
|
}, []);
|
|
106
|
-
const
|
|
107
|
-
const [
|
|
105
|
+
const curRows = resolveRows(options, keys, curVal);
|
|
106
|
+
const [actTab, setActTab] = useState(0);
|
|
108
107
|
useEffect(() => {
|
|
109
|
-
const
|
|
110
|
-
let
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
}, [
|
|
108
|
+
const len = Array.isArray(cur) ? cur.length : 0;
|
|
109
|
+
let ti = len;
|
|
110
|
+
if (ti >= depth) ti = Math.max(depth - 1, 0);
|
|
111
|
+
setActTab(prev => prev === ti ? prev : ti);
|
|
112
|
+
}, [cur.length, depth]);
|
|
114
113
|
useEffect(() => {
|
|
115
|
-
if (!
|
|
116
|
-
}, [
|
|
117
|
-
const
|
|
118
|
-
if (!
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}, [
|
|
122
|
-
const onCloseRef = useRef(onClose)
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
114
|
+
if (!rPop || !popVis) setPending(prev => shallowEqualArray(prev, curVal) ? prev : curVal);
|
|
115
|
+
}, [curVal, rPop, popVis]);
|
|
116
|
+
const openPop = useCallback(() => {
|
|
117
|
+
if (!rPop || popVis) return;
|
|
118
|
+
setPending(prev => shallowEqualArray(prev, curVal) ? prev : curVal);
|
|
119
|
+
setPopVis(true);
|
|
120
|
+
}, [curVal, rPop, popVis, setPopVis]);
|
|
121
|
+
const onCloseRef = useRef(onClose);
|
|
122
|
+
const onChangeRef = useRef(onChange);
|
|
123
|
+
const onFinRef = useRef(onFinish);
|
|
124
|
+
const onClickTabRef = useRef(onClickTab);
|
|
125
|
+
const onTabChgRef = useRef(onTabChange);
|
|
127
126
|
onCloseRef.current = onClose;
|
|
128
127
|
onChangeRef.current = onChange;
|
|
129
|
-
|
|
128
|
+
onFinRef.current = onFinish;
|
|
130
129
|
onClickTabRef.current = onClickTab;
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
if (!
|
|
134
|
-
|
|
130
|
+
onTabChgRef.current = onTabChange;
|
|
131
|
+
const closePop = useCallback(notify => {
|
|
132
|
+
if (!rPop || !popVis) return;
|
|
133
|
+
setPopVis(false);
|
|
135
134
|
if (notify) onCloseRef.current?.();
|
|
136
|
-
}, [
|
|
137
|
-
const
|
|
138
|
-
if (!
|
|
139
|
-
|
|
140
|
-
}, [
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
const
|
|
145
|
-
if (Number.isNaN(
|
|
146
|
-
const tabName = items[
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
onTabChangeRef.current?.(index);
|
|
135
|
+
}, [rPop, popVis, setPopVis]);
|
|
136
|
+
const togglePop = useCallback(() => {
|
|
137
|
+
if (!rPop) return;
|
|
138
|
+
popVis ? closePop(true) : openPop();
|
|
139
|
+
}, [closePop, openPop, rPop, popVis]);
|
|
140
|
+
const isRP = isFunction(children);
|
|
141
|
+
const rp = isRP ? children : null;
|
|
142
|
+
const onClkTab = useCallback(e => {
|
|
143
|
+
const i = isNumber(e.index) ? e.index : Number(e.name);
|
|
144
|
+
if (Number.isNaN(i)) return;
|
|
145
|
+
const tabName = items[i]?.[keys.textKey];
|
|
146
|
+
onClickTabRef.current?.(i, isText(tabName) ? String(tabName) : rP);
|
|
147
|
+
}, [items, keys.textKey, rP]);
|
|
148
|
+
const onTabChg = useCallback((tv, iEx) => {
|
|
149
|
+
const i = isNumber(iEx) ? iEx : Number(tv);
|
|
150
|
+
if (Number.isNaN(i)) return;
|
|
151
|
+
setActTab(i);
|
|
152
|
+
onTabChgRef.current?.(i);
|
|
155
153
|
}, []);
|
|
156
|
-
const
|
|
157
|
-
if (
|
|
158
|
-
const
|
|
159
|
-
if (
|
|
160
|
-
const base = (
|
|
161
|
-
const
|
|
162
|
-
const rows = resolveRows(options, keys,
|
|
163
|
-
const
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
const
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if (resolvedCloseOnFinish) closePopup(true);
|
|
154
|
+
const onSelect = useCallback((opt, ti) => {
|
|
155
|
+
if (opt.disabled) return;
|
|
156
|
+
const ov = opt[keys.valueKey];
|
|
157
|
+
if (ov == null) return;
|
|
158
|
+
const base = (rPop ? pending : curVal).slice(0, ti);
|
|
159
|
+
const next = [...base, ov];
|
|
160
|
+
const rows = resolveRows(options, keys, next);
|
|
161
|
+
const ch = opt[keys.childrenKey] ?? [];
|
|
162
|
+
const hasCh = Object.prototype.hasOwnProperty.call(opt, keys.childrenKey);
|
|
163
|
+
const isAsync = hasCh && !ch.length;
|
|
164
|
+
const atDepth = next.length >= depth;
|
|
165
|
+
const isLeaf = !ch.length && !isAsync;
|
|
166
|
+
if (rPop) {
|
|
167
|
+
setPending(next);
|
|
168
|
+
onChangeRef.current?.(next, rows);
|
|
169
|
+
} else setValue(next, rows);
|
|
170
|
+
if (isLeaf || atDepth) {
|
|
171
|
+
if (rPop) {
|
|
172
|
+
setValue(next, rows);
|
|
173
|
+
if (rCF) closePop(true);
|
|
177
174
|
}
|
|
178
|
-
|
|
175
|
+
onFinRef.current?.(next, rows);
|
|
179
176
|
}
|
|
180
|
-
}, [
|
|
181
|
-
const
|
|
182
|
-
if (
|
|
183
|
-
const
|
|
184
|
-
if (!
|
|
185
|
-
const
|
|
186
|
-
if (!
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}, [current.length, items, keys.childrenKey, resolvedLoadingText, resolvedPlaceholder]);
|
|
177
|
+
}, [curVal, rCF, closePop, depth, keys, options, pending, rPop, setValue]);
|
|
178
|
+
const getEmpty = useCallback(ti => {
|
|
179
|
+
if (ti <= 0) return rP;
|
|
180
|
+
const p = items[ti - 1];
|
|
181
|
+
if (!p) return rP;
|
|
182
|
+
const hasCh = Object.prototype.hasOwnProperty.call(p, keys.childrenKey);
|
|
183
|
+
if (!hasCh) return rP;
|
|
184
|
+
const ch = p[keys.childrenKey] ?? [];
|
|
185
|
+
return ch.length === 0 && cur.length === ti ? rLT : rP;
|
|
186
|
+
}, [cur.length, items, keys.childrenKey, rLT, rP]);
|
|
191
187
|
const renderTabs = () => {
|
|
192
188
|
if (!tabs.length) return /*#__PURE__*/React.createElement(CascaderOptionList, {
|
|
193
189
|
optionList: [],
|
|
194
190
|
tabIndex: 0,
|
|
195
|
-
selectedValue:
|
|
196
|
-
activeColor:
|
|
191
|
+
selectedValue: cur[0],
|
|
192
|
+
activeColor: rAc,
|
|
197
193
|
keys: keys,
|
|
198
194
|
optionRender: optionRender,
|
|
199
|
-
onSelect:
|
|
195
|
+
onSelect: onSelect,
|
|
200
196
|
tokens: tokens,
|
|
201
|
-
emptyText:
|
|
197
|
+
emptyText: getEmpty(0)
|
|
202
198
|
});
|
|
203
|
-
const
|
|
204
|
-
const
|
|
205
|
-
const
|
|
199
|
+
const swEn = !!rSw;
|
|
200
|
+
const tabsW = measW || winW || undefined;
|
|
201
|
+
const tbStyle = {
|
|
206
202
|
height: tokens.sizing.headerHeight,
|
|
207
203
|
paddingHorizontal: tokens.spacing.tabNavPaddingHorizontal,
|
|
208
204
|
paddingVertical: tokens.spacing.tabNavPaddingVertical,
|
|
@@ -210,79 +206,78 @@ const CascaderImpl = props => {
|
|
|
210
206
|
};
|
|
211
207
|
return /*#__PURE__*/React.createElement(View, {
|
|
212
208
|
style: tokens.layout.tabsWrapper,
|
|
213
|
-
onLayout:
|
|
209
|
+
onLayout: onTabsLayout
|
|
214
210
|
}, /*#__PURE__*/React.createElement(Tabs, {
|
|
215
|
-
style:
|
|
216
|
-
width:
|
|
211
|
+
style: tabsW ? {
|
|
212
|
+
width: tabsW
|
|
217
213
|
} : undefined,
|
|
218
|
-
active:
|
|
219
|
-
onChange:
|
|
220
|
-
onClickTab:
|
|
214
|
+
active: actTab,
|
|
215
|
+
onChange: onTabChg,
|
|
216
|
+
onClickTab: onClkTab,
|
|
221
217
|
align: "center",
|
|
222
|
-
swipeable:
|
|
218
|
+
swipeable: swEn,
|
|
223
219
|
swipeThreshold: 0,
|
|
224
220
|
scrollable: true,
|
|
225
221
|
animated: true,
|
|
226
222
|
duration: 300,
|
|
227
|
-
color:
|
|
223
|
+
color: rAc,
|
|
228
224
|
lineHeight: tokens.sizing.indicatorHeight,
|
|
229
225
|
titleActiveColor: tokens.colors.tabText,
|
|
230
226
|
titleInactiveColor: tokens.colors.tabInactive,
|
|
231
|
-
tabBarStyle:
|
|
227
|
+
tabBarStyle: tbStyle,
|
|
232
228
|
tabStyle: [tokens.layout.tabsItem, {
|
|
233
229
|
paddingHorizontal: tokens.spacing.tabPaddingHorizontal
|
|
234
230
|
}],
|
|
235
231
|
titleStyle: [tokens.layout.tabsTitle, {
|
|
236
232
|
fontSize: tokens.typography.tabsTitleSize
|
|
237
233
|
}],
|
|
238
|
-
contentStyle: !
|
|
239
|
-
}, tabs.map((
|
|
240
|
-
const
|
|
241
|
-
const
|
|
242
|
-
const
|
|
243
|
-
const usePlaceholder = !label;
|
|
234
|
+
contentStyle: !swEn ? tokens.layout.tabsContentStatic : undefined
|
|
235
|
+
}, tabs.map((optList, i) => {
|
|
236
|
+
const sel = items[i];
|
|
237
|
+
const lbl = isText(sel?.[keys.textKey]) ? String(sel?.[keys.textKey]) : "";
|
|
238
|
+
const usePh = !lbl;
|
|
244
239
|
const titleNode = _ => /*#__PURE__*/React.createElement(Text, {
|
|
245
240
|
style: [tokens.layout.tabTitleNode, {
|
|
246
|
-
color:
|
|
247
|
-
fontWeight:
|
|
241
|
+
color: usePh ? tokens.colors.tabInactive : tokens.colors.tabText,
|
|
242
|
+
fontWeight: usePh ? tokens.typography.tabTitlePlaceholderWeight : tokens.typography.tabTitleWeight
|
|
248
243
|
}]
|
|
249
|
-
},
|
|
244
|
+
}, usePh ? rP : lbl);
|
|
250
245
|
return /*#__PURE__*/React.createElement(Tabs.TabPane, {
|
|
251
246
|
key: i,
|
|
252
247
|
name: i,
|
|
253
248
|
title: titleNode
|
|
254
249
|
}, /*#__PURE__*/React.createElement(CascaderOptionList, {
|
|
255
|
-
optionList:
|
|
250
|
+
optionList: optList,
|
|
256
251
|
tabIndex: i,
|
|
257
|
-
selectedValue:
|
|
258
|
-
activeColor:
|
|
252
|
+
selectedValue: cur[i],
|
|
253
|
+
activeColor: rAc,
|
|
259
254
|
keys: keys,
|
|
260
255
|
optionRender: optionRender,
|
|
261
|
-
onSelect:
|
|
256
|
+
onSelect: onSelect,
|
|
262
257
|
tokens: tokens,
|
|
263
|
-
emptyText:
|
|
258
|
+
emptyText: getEmpty(i)
|
|
264
259
|
}));
|
|
265
260
|
})));
|
|
266
261
|
};
|
|
267
|
-
const
|
|
262
|
+
const inlineCh = !rPop && !isRP ? children : null;
|
|
268
263
|
const content = /*#__PURE__*/React.createElement(View, _extends({
|
|
269
264
|
testID: testID,
|
|
270
265
|
style: [tokens.layout.container, {
|
|
271
266
|
backgroundColor: tokens.colors.background
|
|
272
267
|
}, style]
|
|
273
|
-
}, rest),
|
|
268
|
+
}, rest), rSH ? /*#__PURE__*/React.createElement(View, {
|
|
274
269
|
style: [tokens.layout.header, {
|
|
275
270
|
height: tokens.sizing.headerHeight,
|
|
276
271
|
paddingHorizontal: tokens.spacing.headerPaddingHorizontal
|
|
277
272
|
}]
|
|
278
|
-
}, renderTextOrNode(
|
|
273
|
+
}, renderTextOrNode(rT, [tokens.layout.title, {
|
|
279
274
|
color: tokens.colors.headerText,
|
|
280
275
|
fontSize: tokens.typography.titleSize,
|
|
281
276
|
fontWeight: tokens.typography.titleWeight
|
|
282
|
-
}]),
|
|
277
|
+
}]), showCl ? /*#__PURE__*/React.createElement(Pressable, {
|
|
283
278
|
hitSlop: 8,
|
|
284
279
|
onPress: () => {
|
|
285
|
-
|
|
280
|
+
rPop ? closePop(true) : onCloseRef.current?.();
|
|
286
281
|
},
|
|
287
282
|
style: [tokens.layout.closeButton, {
|
|
288
283
|
marginLeft: tokens.spacing.closeButtonMarginLeft
|
|
@@ -293,63 +288,61 @@ const CascaderImpl = props => {
|
|
|
293
288
|
size: tokens.sizing.closeIconSize,
|
|
294
289
|
fill: state.pressed ? tokens.colors.closeIconActive : tokens.colors.closeIcon,
|
|
295
290
|
color: state.pressed ? tokens.colors.closeIconActive : tokens.colors.closeIcon
|
|
296
|
-
}))) : null) : null, renderTabs(),
|
|
291
|
+
}))) : null) : null, renderTabs(), inlineCh ? /*#__PURE__*/React.createElement(View, {
|
|
297
292
|
style: [tokens.layout.inlineChildren, {
|
|
298
293
|
paddingVertical: tokens.spacing.inlineChildrenPaddingVertical,
|
|
299
294
|
paddingHorizontal: tokens.spacing.headerPaddingHorizontal
|
|
300
295
|
}]
|
|
301
|
-
},
|
|
302
|
-
if (!
|
|
296
|
+
}, inlineCh) : null);
|
|
297
|
+
if (!rPop) return content;
|
|
303
298
|
const {
|
|
304
|
-
closeOnOverlayPress:
|
|
305
|
-
overlay:
|
|
306
|
-
onOpen:
|
|
307
|
-
onOpened:
|
|
308
|
-
onClose:
|
|
309
|
-
onClosed:
|
|
310
|
-
...
|
|
299
|
+
closeOnOverlayPress: ovClose,
|
|
300
|
+
overlay: popOv,
|
|
301
|
+
onOpen: popOnOpen,
|
|
302
|
+
onOpened: popOnOpened,
|
|
303
|
+
onClose: popOnClose,
|
|
304
|
+
onClosed: popOnClosed,
|
|
305
|
+
...popRest
|
|
311
306
|
} = popupProps ?? {};
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
close: () => closePopup(true),
|
|
323
|
-
toggle: togglePopup
|
|
307
|
+
const popOnCloseRef = useRef(popOnClose);
|
|
308
|
+
popOnCloseRef.current = popOnClose;
|
|
309
|
+
const onPopupClose = useCallback(() => {
|
|
310
|
+
popOnCloseRef.current?.();
|
|
311
|
+
closePop(true);
|
|
312
|
+
}, [closePop]);
|
|
313
|
+
const actions = {
|
|
314
|
+
open: openPop,
|
|
315
|
+
close: () => closePop(true),
|
|
316
|
+
toggle: togglePop
|
|
324
317
|
};
|
|
325
|
-
const
|
|
318
|
+
const enhanceTrigger = useCallback(node => {
|
|
326
319
|
if (! /*#__PURE__*/React.isValidElement(node)) return node;
|
|
327
|
-
const
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
320
|
+
const p = node.props;
|
|
321
|
+
const onP = () => {
|
|
322
|
+
p.onPress?.();
|
|
323
|
+
p.onClick?.();
|
|
324
|
+
openPop();
|
|
332
325
|
};
|
|
333
326
|
return /*#__PURE__*/React.cloneElement(node, {
|
|
334
|
-
onPress:
|
|
335
|
-
onClick:
|
|
327
|
+
onPress: onP,
|
|
328
|
+
onClick: onP
|
|
336
329
|
});
|
|
337
|
-
}, [
|
|
338
|
-
const triggerNode =
|
|
339
|
-
const
|
|
340
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null,
|
|
341
|
-
visible:
|
|
342
|
-
placement:
|
|
343
|
-
round:
|
|
344
|
-
closeOnOverlayPress:
|
|
345
|
-
overlay:
|
|
346
|
-
safeAreaInsetTop:
|
|
347
|
-
safeAreaInsetBottom:
|
|
348
|
-
onOpen:
|
|
349
|
-
onOpened:
|
|
350
|
-
onClose:
|
|
351
|
-
onClosed:
|
|
352
|
-
},
|
|
330
|
+
}, [openPop]);
|
|
331
|
+
const triggerNode = rp ? rp(curVal, curRows, actions) : isRP ? null : children || null;
|
|
332
|
+
const renderTrigger = enhanceTrigger(triggerNode);
|
|
333
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, renderTrigger, /*#__PURE__*/React.createElement(Popup, _extends({
|
|
334
|
+
visible: popVis,
|
|
335
|
+
placement: rPP,
|
|
336
|
+
round: rPR,
|
|
337
|
+
closeOnOverlayPress: ovClose ?? rCO,
|
|
338
|
+
overlay: popOv ?? true,
|
|
339
|
+
safeAreaInsetTop: popRest?.safeAreaInsetTop != null ? popRest.safeAreaInsetTop : rSH && showCl,
|
|
340
|
+
safeAreaInsetBottom: popRest?.safeAreaInsetBottom != null ? popRest.safeAreaInsetBottom : rPP === 'bottom',
|
|
341
|
+
onOpen: popOnOpen,
|
|
342
|
+
onOpened: popOnOpened,
|
|
343
|
+
onClose: onPopupClose,
|
|
344
|
+
onClosed: popOnClosed
|
|
345
|
+
}, popRest, {
|
|
353
346
|
style: {
|
|
354
347
|
paddingLeft: 0,
|
|
355
348
|
paddingRight: 0
|
|
@@ -366,41 +359,42 @@ const CascaderOptionItem = /*#__PURE__*/React.memo(({
|
|
|
366
359
|
onSelect,
|
|
367
360
|
tokens
|
|
368
361
|
}) => {
|
|
369
|
-
const
|
|
370
|
-
const
|
|
371
|
-
const
|
|
372
|
-
const
|
|
373
|
-
const
|
|
374
|
-
const
|
|
375
|
-
color:
|
|
362
|
+
const ov = option[keys.valueKey];
|
|
363
|
+
const lbl = option[keys.textKey];
|
|
364
|
+
const dis = !!option.disabled;
|
|
365
|
+
const baseCl = option.color ?? tokens.colors.optionText;
|
|
366
|
+
const txtCl = dis ? tokens.colors.optionDisabled : selected ? option.color ?? activeColor : baseCl;
|
|
367
|
+
const txtStyle = [tokens.layout.optionText, {
|
|
368
|
+
color: txtCl,
|
|
376
369
|
fontSize: tokens.typography.optionTextSize
|
|
377
370
|
}, selected ? {
|
|
378
371
|
fontWeight: tokens.typography.optionTextActiveWeight
|
|
379
372
|
} : null];
|
|
380
|
-
const
|
|
373
|
+
const rawCnt = optionRender ? optionRender({
|
|
381
374
|
option,
|
|
382
375
|
selected
|
|
383
|
-
}) : renderTextOrNode(
|
|
376
|
+
}) : renderTextOrNode(lbl, txtStyle);
|
|
377
|
+
const cnt = isText(rawCnt) ? renderTextOrNode(rawCnt, txtStyle) : rawCnt;
|
|
384
378
|
return /*#__PURE__*/React.createElement(Pressable, {
|
|
385
|
-
testID: `cascader-option-${tabIndex}-${String(
|
|
379
|
+
testID: `cascader-option-${tabIndex}-${String(ov)}`,
|
|
386
380
|
style: ({
|
|
387
381
|
pressed
|
|
388
382
|
}) => [tokens.layout.option, {
|
|
389
383
|
minHeight: tokens.sizing.optionMinHeight,
|
|
390
384
|
paddingVertical: tokens.spacing.optionPaddingVertical,
|
|
391
385
|
paddingHorizontal: tokens.spacing.optionPaddingHorizontal
|
|
392
|
-
}, pressed && !
|
|
386
|
+
}, pressed && !dis && {
|
|
393
387
|
backgroundColor: tokens.colors.optionActiveBackground
|
|
394
388
|
}],
|
|
395
389
|
onPress: () => onSelect(option, tabIndex),
|
|
396
|
-
disabled:
|
|
390
|
+
disabled: dis
|
|
397
391
|
}, /*#__PURE__*/React.createElement(View, {
|
|
398
392
|
style: tokens.layout.optionContent
|
|
399
393
|
}, /*#__PURE__*/React.createElement(View, {
|
|
400
394
|
style: [tokens.layout.optionLabel, {
|
|
401
395
|
marginRight: tokens.spacing.optionLabelMarginRight
|
|
402
396
|
}]
|
|
403
|
-
},
|
|
397
|
+
}, cnt), selected ? /*#__PURE__*/React.createElement(Checked, {
|
|
404
398
|
size: tokens.sizing.selectedIconSize,
|
|
405
399
|
fill: activeColor,
|
|
406
400
|
color: activeColor
|
|
@@ -429,7 +423,7 @@ const CascaderOptionList = /*#__PURE__*/React.memo(({
|
|
|
429
423
|
onSelect: onSelect,
|
|
430
424
|
tokens: tokens
|
|
431
425
|
}), [activeColor, keys, onSelect, optionRender, selectedValue, tabIndex, tokens]);
|
|
432
|
-
const
|
|
426
|
+
const keyExt = useCallback(item => String(item[keys.valueKey]), [keys.valueKey]);
|
|
433
427
|
if (!optionList.length) return /*#__PURE__*/React.createElement(View, {
|
|
434
428
|
style: [tokens.layout.optionList, {
|
|
435
429
|
height: tokens.sizing.optionListHeight
|
|
@@ -452,7 +446,7 @@ const CascaderOptionList = /*#__PURE__*/React.memo(({
|
|
|
452
446
|
},
|
|
453
447
|
showsVerticalScrollIndicator: false,
|
|
454
448
|
renderItem: renderItem,
|
|
455
|
-
keyExtractor:
|
|
449
|
+
keyExtractor: keyExt,
|
|
456
450
|
removeClippedSubviews: true,
|
|
457
451
|
initialNumToRender: 20,
|
|
458
452
|
windowSize: 5
|