@nutui/nutui-react-taro 2.0.0-alpha.7 → 2.0.0-alpha.9
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/CHANGELOG.md +26 -0
- package/dist/esm/Address.js +2 -2
- package/dist/esm/Audio.js +7 -6
- package/dist/esm/Card.js +5 -5
- package/dist/esm/Cascader.js +2 -2
- package/dist/esm/DatePicker.js +2 -3
- package/dist/esm/Elevator.js +1 -1
- package/dist/esm/ImagePreview.js +4 -7
- package/dist/esm/Indicator.js +1 -1
- package/dist/esm/InputNumber.js +1 -1
- package/dist/esm/Notify.js +2 -3
- package/dist/esm/NumberKeyboard.js +3 -5
- package/dist/esm/Picker.js +1 -2
- package/dist/esm/Price.js +2 -3
- package/dist/esm/PullToRefresh.js +4 -6
- package/dist/esm/Radio.js +3 -3
- package/dist/esm/RadioGroup.js +3 -3
- package/dist/esm/Range/style/index.js +1 -1
- package/dist/esm/Range.js +5 -7
- package/dist/esm/Sticky.js +1 -2
- package/dist/esm/Swiper.js +3 -5
- package/dist/esm/SwiperItem.js +1 -5
- package/dist/esm/Tabs.js +1 -1
- package/dist/esm/{address.taro-1c534feb.js → address.taro-1a8ab3f1.js} +1 -1
- package/dist/esm/{audio.taro-ec96ef80.js → audio.taro-bbd39f93.js} +2 -2
- package/dist/esm/{card.taro-a46fdf25.js → card.taro-2080f4d2.js} +1 -1
- package/dist/esm/{cascader.taro-0a2694ed.js → cascader.taro-fb7a0230.js} +21 -13
- package/dist/esm/{datepicker.taro-3f718964.js → datepicker.taro-65dbeceb.js} +1 -1
- package/dist/esm/{elevator.taro-bc162e4f.js → elevator.taro-df8fde9d.js} +20 -15
- package/dist/esm/{imagepreview.taro-8832dc01.js → imagepreview.taro-2508d412.js} +8 -5
- package/dist/esm/{indicator.taro-f2bd212f.js → indicator.taro-edbc71df.js} +3 -3
- package/dist/esm/{inputnumber.taro-877dc947.js → inputnumber.taro-6657d2c1.js} +1 -1
- package/dist/esm/{notify.taro-6b6eb6bf.js → notify.taro-5768403d.js} +11 -18
- package/dist/esm/numberkeyboard.taro-ad8afaf9.js +136 -0
- package/dist/esm/nutui-react.es.js +20 -25
- package/dist/esm/{picker.taro-a5603921.js → picker.taro-0570ec32.js} +14 -1
- package/dist/esm/{price.taro-c4f45310.js → price.taro-479f1b82.js} +17 -17
- package/dist/esm/pulltorefresh.taro-6afe4805.js +138 -0
- package/dist/esm/radio.taro-5d6ca4ad.js +153 -0
- package/dist/esm/range.taro-615e193a.js +259 -0
- package/dist/esm/{sticky.taro-3c03eb0a.js → sticky.taro-f8ae8d5e.js} +21 -1
- package/dist/esm/swiper.taro-53a36427.js +83 -0
- package/dist/esm/swiperitem.taro-ef7342e8.js +14 -0
- package/dist/esm/{tabs.taro-b75f20ff.js → tabs.taro-66164782.js} +8 -1
- package/dist/locales/base.js +1 -1
- package/dist/locales/en-US.js +1 -1
- package/dist/locales/id-ID.js +1 -1
- package/dist/locales/zh-CN.js +1 -1
- package/dist/locales/zh-TW.js +1 -1
- package/dist/locales/zh-UG.js +1 -1
- package/dist/nutui.react.mjs +1634 -6666
- package/dist/nutui.react.umd.js +2047 -7095
- package/dist/packages/imagepreview/imagepreview.scss +5 -0
- package/dist/packages/notify/notify.scss +1 -1
- package/dist/packages/numberkeyboard/numberkeyboard.scss +29 -77
- package/dist/packages/price/price.scss +8 -0
- package/dist/packages/pulltorefresh/pulltorefresh.scss +0 -8
- package/dist/packages/radio/radio.scss +13 -32
- package/dist/packages/radiogroup/radiogroup.scss +17 -51
- package/dist/packages/range/range.scss +24 -49
- package/dist/packages/swiper/swiper.scss +0 -15
- package/dist/style.css +1 -1
- package/dist/style.mjs +1 -1
- package/dist/styles/variables-jmapp.scss +61 -61
- package/dist/styles/variables.scss +61 -60
- package/dist/types/index.d.ts +83 -118
- package/package.json +1 -1
- package/dist/esm/UserContext-735db09f.js +0 -5
- package/dist/esm/get-scroll-parent-8da04f2e.js +0 -24
- package/dist/esm/numberkeyboard.taro-0a0e866a.js +0 -183
- package/dist/esm/pulltorefresh.taro-c611fd92.js +0 -179
- package/dist/esm/radio.taro-3a54f4c8.js +0 -152
- package/dist/esm/range.taro-52cda918.js +0 -325
- package/dist/esm/supports-passive-aaaf0eff.js +0 -17
- package/dist/esm/swiper.taro-74cf9306.js +0 -430
- package/dist/esm/swiperitem-80df464a.js +0 -29
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import React, { useState, useRef, useEffect } from "react";
|
|
2
|
-
import { useDrag } from "@use-gesture/react";
|
|
3
|
-
import { useSpring, animated } from "@react-spring/web";
|
|
4
|
-
import { u as useConfig } from "./configprovider.taro-25758d9f.js";
|
|
5
|
-
import { g as getScrollParent } from "./get-scroll-parent-8da04f2e.js";
|
|
6
|
-
import { p as passiveSupported } from "./supports-passive-aaaf0eff.js";
|
|
7
|
-
function bound(position, min, max) {
|
|
8
|
-
let ret = position;
|
|
9
|
-
if (min !== void 0) {
|
|
10
|
-
ret = Math.max(position, min);
|
|
11
|
-
}
|
|
12
|
-
if (max !== void 0) {
|
|
13
|
-
ret = Math.min(ret, max);
|
|
14
|
-
}
|
|
15
|
-
return ret;
|
|
16
|
-
}
|
|
17
|
-
function rubberband(distance, dimension, constant) {
|
|
18
|
-
return distance * dimension * constant / (dimension + constant * distance);
|
|
19
|
-
}
|
|
20
|
-
function rubberbandIfOutOfBounds(position, min, max, dimension, constant = 0.15) {
|
|
21
|
-
if (constant === 0)
|
|
22
|
-
return bound(position, min, max);
|
|
23
|
-
if (position < min)
|
|
24
|
-
return -rubberband(min - position, dimension, constant) + min;
|
|
25
|
-
if (position > max)
|
|
26
|
-
return +rubberband(position - max, dimension, constant) + max;
|
|
27
|
-
return position;
|
|
28
|
-
}
|
|
29
|
-
const sleep = (time) => new Promise((resolve) => setTimeout(resolve, time));
|
|
30
|
-
const defaultProps = {
|
|
31
|
-
pullingText: "",
|
|
32
|
-
canReleaseText: "",
|
|
33
|
-
refreshingText: "",
|
|
34
|
-
completeText: "",
|
|
35
|
-
completeDelay: 500,
|
|
36
|
-
disabled: false,
|
|
37
|
-
headHeight: 40,
|
|
38
|
-
threshold: 60,
|
|
39
|
-
onRefresh: () => {
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const PullToRefresh = (p) => {
|
|
43
|
-
const { locale } = useConfig();
|
|
44
|
-
const props = {
|
|
45
|
-
...defaultProps,
|
|
46
|
-
...p,
|
|
47
|
-
...{
|
|
48
|
-
pullingText: p.pullingText || locale.pullToRefresh.pullingText,
|
|
49
|
-
canReleaseText: p.canReleaseText || locale.pullToRefresh.canReleaseText,
|
|
50
|
-
refreshingText: p.refreshingText || locale.pullToRefresh.refreshingText,
|
|
51
|
-
completeText: p.completeText || locale.pullToRefresh.completeText
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
const headHeight = props.headHeight;
|
|
55
|
-
const threshold = props.threshold;
|
|
56
|
-
const [status, setStatus] = useState("pulling");
|
|
57
|
-
const [springStyles, api] = useSpring(() => ({
|
|
58
|
-
from: { height: 0 },
|
|
59
|
-
config: {
|
|
60
|
-
tension: 300,
|
|
61
|
-
friction: 30,
|
|
62
|
-
clamp: true
|
|
63
|
-
}
|
|
64
|
-
}));
|
|
65
|
-
const elementRef = useRef(null);
|
|
66
|
-
const pullingRef = useRef(false);
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
var _a;
|
|
69
|
-
(_a = elementRef.current) == null ? void 0 : _a.addEventListener("touchmove", () => {
|
|
70
|
-
});
|
|
71
|
-
}, []);
|
|
72
|
-
async function doRefresh() {
|
|
73
|
-
api.start({ height: headHeight });
|
|
74
|
-
setStatus("refreshing");
|
|
75
|
-
try {
|
|
76
|
-
await props.onRefresh();
|
|
77
|
-
setStatus("complete");
|
|
78
|
-
} catch (e) {
|
|
79
|
-
api.start({
|
|
80
|
-
to: async (next) => {
|
|
81
|
-
await next({ height: 0 });
|
|
82
|
-
setStatus("pulling");
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
throw e;
|
|
86
|
-
}
|
|
87
|
-
if (props.completeDelay > 0) {
|
|
88
|
-
await sleep(props.completeDelay);
|
|
89
|
-
}
|
|
90
|
-
api.start({
|
|
91
|
-
to: async (next) => {
|
|
92
|
-
await next({ height: 0 });
|
|
93
|
-
setStatus("pulling");
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
useDrag((state) => {
|
|
98
|
-
if (status === "refreshing" || status === "complete")
|
|
99
|
-
return;
|
|
100
|
-
const { event } = state;
|
|
101
|
-
if (state.last) {
|
|
102
|
-
pullingRef.current = false;
|
|
103
|
-
if (status === "canRelease") {
|
|
104
|
-
doRefresh();
|
|
105
|
-
} else {
|
|
106
|
-
api.start({ height: 0 });
|
|
107
|
-
}
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
function getScrollTop(element) {
|
|
111
|
-
return "scrollTop" in element ? element.scrollTop : element.scrollY;
|
|
112
|
-
}
|
|
113
|
-
const [, y] = state.movement;
|
|
114
|
-
if (state.first && y > 0) {
|
|
115
|
-
const target = state.event.target;
|
|
116
|
-
if (!target || !(target instanceof Element))
|
|
117
|
-
return;
|
|
118
|
-
let scrollParent = getScrollParent(target);
|
|
119
|
-
while (true) {
|
|
120
|
-
if (!scrollParent)
|
|
121
|
-
return;
|
|
122
|
-
const scrollTop = getScrollTop(scrollParent);
|
|
123
|
-
if (scrollTop > 0) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
if (scrollParent instanceof Window) {
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
scrollParent = getScrollParent(scrollParent.parentNode);
|
|
130
|
-
}
|
|
131
|
-
pullingRef.current = true;
|
|
132
|
-
}
|
|
133
|
-
if (!pullingRef.current)
|
|
134
|
-
return;
|
|
135
|
-
if (event.cancelable) {
|
|
136
|
-
event.preventDefault();
|
|
137
|
-
}
|
|
138
|
-
event.stopPropagation();
|
|
139
|
-
const height = Math.max(rubberbandIfOutOfBounds(y, 0, 0, headHeight * 5, 0.5), 0);
|
|
140
|
-
api.start({ height });
|
|
141
|
-
setStatus(height > threshold ? "canRelease" : "pulling");
|
|
142
|
-
}, {
|
|
143
|
-
pointer: { touch: true },
|
|
144
|
-
axis: "y",
|
|
145
|
-
target: elementRef,
|
|
146
|
-
enabled: !props.disabled,
|
|
147
|
-
eventOptions: passiveSupported ? { passive: false } : false
|
|
148
|
-
});
|
|
149
|
-
const renderStatusText = () => {
|
|
150
|
-
var _a;
|
|
151
|
-
if (props.renderText) {
|
|
152
|
-
return (_a = props.renderText) == null ? void 0 : _a.call(props, status);
|
|
153
|
-
}
|
|
154
|
-
if (status === "pulling")
|
|
155
|
-
return props.pullingText;
|
|
156
|
-
if (status === "canRelease")
|
|
157
|
-
return props.canReleaseText;
|
|
158
|
-
if (status === "refreshing")
|
|
159
|
-
return props.refreshingText;
|
|
160
|
-
if (status === "complete")
|
|
161
|
-
return props.completeText;
|
|
162
|
-
return "";
|
|
163
|
-
};
|
|
164
|
-
return React.createElement(
|
|
165
|
-
animated.div,
|
|
166
|
-
{ ref: elementRef, className: "nut-pulltorefresh" },
|
|
167
|
-
React.createElement(
|
|
168
|
-
animated.div,
|
|
169
|
-
{ style: springStyles, className: "nut-pulltorefresh-head" },
|
|
170
|
-
React.createElement("div", { className: "nut-pulltorefresh-head-content", style: { height: headHeight } }, renderStatusText())
|
|
171
|
-
),
|
|
172
|
-
React.createElement("div", { className: "nut-pulltorefresh-content" }, props.children)
|
|
173
|
-
);
|
|
174
|
-
};
|
|
175
|
-
PullToRefresh.defaultProps = defaultProps;
|
|
176
|
-
PullToRefresh.displayName = "NutPullToRefresh";
|
|
177
|
-
export {
|
|
178
|
-
PullToRefresh as P
|
|
179
|
-
};
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import React, { useState, useEffect, useCallback, useContext } from "react";
|
|
2
|
-
import { CheckChecked, CheckNormal } from "@nutui/icons-react-taro";
|
|
3
|
-
import { C as ComponentDefaults } from "./typings-11d83a22.js";
|
|
4
|
-
import { c as cn } from "./bem-cdccae08.js";
|
|
5
|
-
const radioContext = {
|
|
6
|
-
onChange: (val) => {
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
const RadioContext = React.createContext(radioContext);
|
|
10
|
-
const defaultProps$1 = {
|
|
11
|
-
value: null,
|
|
12
|
-
textPosition: "right",
|
|
13
|
-
onChange: (value) => {
|
|
14
|
-
},
|
|
15
|
-
direction: "vertical",
|
|
16
|
-
options: []
|
|
17
|
-
};
|
|
18
|
-
const RadioGroup = React.forwardRef((props, ref) => {
|
|
19
|
-
const { children } = { ...defaultProps$1, ...props };
|
|
20
|
-
cn("RadioGroup");
|
|
21
|
-
const { className, value, onChange, textPosition, direction, options, ...rest } = props;
|
|
22
|
-
const [val2State, setVal2State] = useState(value);
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
setVal2State(value);
|
|
25
|
-
}, [value]);
|
|
26
|
-
function validateChildChecked(child) {
|
|
27
|
-
if (val2State === null)
|
|
28
|
-
return false;
|
|
29
|
-
return val2State === child.props.value;
|
|
30
|
-
}
|
|
31
|
-
function validateChecked(value2) {
|
|
32
|
-
if (val2State === null)
|
|
33
|
-
return false;
|
|
34
|
-
return val2State === value2;
|
|
35
|
-
}
|
|
36
|
-
function cloneChildren() {
|
|
37
|
-
return React.Children.map(children, (child, index) => {
|
|
38
|
-
const childChecked = validateChildChecked(child);
|
|
39
|
-
if (child.type.displayName !== "NutRadio") {
|
|
40
|
-
return React.cloneElement(child);
|
|
41
|
-
}
|
|
42
|
-
return React.cloneElement(child, {
|
|
43
|
-
textPosition,
|
|
44
|
-
checked: childChecked
|
|
45
|
-
// onChange: handleChildChange,
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
const renderOptionsChildren = useCallback(() => {
|
|
50
|
-
return options == null ? void 0 : options.map(({ label, value: value2, disabled, onChange: onChange2, ...rest2 }) => {
|
|
51
|
-
const childChecked = validateChecked(value2);
|
|
52
|
-
return React.createElement(Radio, { key: value2 == null ? void 0 : value2.toString(), children: label, value: value2, disabled, onChange: onChange2, ...rest2, textPosition, checked: childChecked });
|
|
53
|
-
});
|
|
54
|
-
}, [val2State, options]);
|
|
55
|
-
return React.createElement(
|
|
56
|
-
RadioContext.Provider,
|
|
57
|
-
{ value: {
|
|
58
|
-
onChange: (val) => {
|
|
59
|
-
setVal2State(val);
|
|
60
|
-
onChange && onChange(val);
|
|
61
|
-
}
|
|
62
|
-
} },
|
|
63
|
-
React.createElement("div", { className: `nut-radiogroup nut-radiogroup--${props.direction} ${className || ""}`, ...rest }, (options == null ? void 0 : options.length) ? renderOptionsChildren() : cloneChildren())
|
|
64
|
-
);
|
|
65
|
-
});
|
|
66
|
-
RadioGroup.defaultProps = defaultProps$1;
|
|
67
|
-
RadioGroup.displayName = "NutRadioGroup";
|
|
68
|
-
const defaultProps = {
|
|
69
|
-
...ComponentDefaults,
|
|
70
|
-
className: "",
|
|
71
|
-
style: {},
|
|
72
|
-
disabled: false,
|
|
73
|
-
checked: false,
|
|
74
|
-
shape: "round",
|
|
75
|
-
value: "",
|
|
76
|
-
textPosition: "right",
|
|
77
|
-
icon: null,
|
|
78
|
-
checkedIcon: null,
|
|
79
|
-
iconSize: 18,
|
|
80
|
-
onChange: (e) => {
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
const Radio = (props) => {
|
|
84
|
-
const { children } = {
|
|
85
|
-
...defaultProps,
|
|
86
|
-
...props
|
|
87
|
-
};
|
|
88
|
-
const { className, disabled, checked, shape, textPosition, value, icon, checkedIcon, iconSize, onChange, ...rest } = props;
|
|
89
|
-
const componentName = "nut-radio";
|
|
90
|
-
const [checkedStatement, setCheckedStatement] = useState(checked);
|
|
91
|
-
const [valueStatement, setValueStatement] = useState(value);
|
|
92
|
-
const [disabledStatement, setDisabledStatement] = useState(disabled);
|
|
93
|
-
const context = useContext(RadioContext);
|
|
94
|
-
useEffect(() => {
|
|
95
|
-
setDisabledStatement(disabled);
|
|
96
|
-
setValueStatement(value);
|
|
97
|
-
setCheckedStatement(checked);
|
|
98
|
-
}, [disabled, value, checked]);
|
|
99
|
-
const renderLabel = () => {
|
|
100
|
-
return React.createElement("div", { className: `${componentName}__label ${disabledStatement ? `${componentName}__label--disabled` : ""}` }, children);
|
|
101
|
-
};
|
|
102
|
-
const renderButton = () => {
|
|
103
|
-
return React.createElement("div", { className: `${componentName}__button ${!disabledStatement && checkedStatement && `${componentName}__button--active`} ${disabledStatement ? `${componentName}__button--disabled` : ""}` }, children);
|
|
104
|
-
};
|
|
105
|
-
const color = () => {
|
|
106
|
-
if (disabledStatement) {
|
|
107
|
-
return "nut-radio__icon--disable";
|
|
108
|
-
}
|
|
109
|
-
if (checkedStatement) {
|
|
110
|
-
return "nut-radio__icon";
|
|
111
|
-
}
|
|
112
|
-
return "nut-radio__icon--unchecked";
|
|
113
|
-
};
|
|
114
|
-
const renderIcon = () => {
|
|
115
|
-
const { icon: icon2, iconSize: iconSize2, checkedIcon: checkedIcon2 } = props;
|
|
116
|
-
if (!disabledStatement && checkedStatement) {
|
|
117
|
-
return React.isValidElement(checkedIcon2) ? React.cloneElement(checkedIcon2, {
|
|
118
|
-
...checkedIcon2.props,
|
|
119
|
-
className: color()
|
|
120
|
-
}) : React.createElement(CheckChecked, { size: iconSize2, className: color() });
|
|
121
|
-
}
|
|
122
|
-
return React.isValidElement(icon2) ? React.cloneElement(icon2, {
|
|
123
|
-
...icon2.props,
|
|
124
|
-
className: color()
|
|
125
|
-
}) : React.createElement(CheckNormal, { size: iconSize2, className: color() });
|
|
126
|
-
};
|
|
127
|
-
const reverseState = textPosition === "left";
|
|
128
|
-
const renderRadioItem = () => {
|
|
129
|
-
if (shape === "button") {
|
|
130
|
-
return renderButton();
|
|
131
|
-
}
|
|
132
|
-
if (reverseState) {
|
|
133
|
-
return [renderLabel(), renderIcon()];
|
|
134
|
-
}
|
|
135
|
-
return [renderIcon(), renderLabel()];
|
|
136
|
-
};
|
|
137
|
-
const handleClick = (e) => {
|
|
138
|
-
if (disabledStatement || checkedStatement)
|
|
139
|
-
return;
|
|
140
|
-
setCheckedStatement(!checkedStatement);
|
|
141
|
-
onChange && onChange(e);
|
|
142
|
-
context && context.onChange(valueStatement);
|
|
143
|
-
};
|
|
144
|
-
return React.createElement("div", { className: `nut-radio ${className} ${reverseState ? `${componentName}--reverse` : ""}`, onClick: handleClick, ...rest }, renderRadioItem());
|
|
145
|
-
};
|
|
146
|
-
Radio.defaultProps = defaultProps;
|
|
147
|
-
Radio.displayName = "NutRadio";
|
|
148
|
-
Radio.RadioGroup = RadioGroup;
|
|
149
|
-
export {
|
|
150
|
-
Radio as R,
|
|
151
|
-
RadioGroup as a
|
|
152
|
-
};
|
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
import React, { useState, useRef, useEffect, useCallback } from "react";
|
|
2
|
-
import { u as useTouch } from "./use-touch-ff43512c.js";
|
|
3
|
-
import { g as getRectByTaro } from "./use-client-rect-f317804e.js";
|
|
4
|
-
import { T as Toast } from "./toast.taro-92c10e1d.js";
|
|
5
|
-
import { u as useConfig } from "./configprovider.taro-25758d9f.js";
|
|
6
|
-
const defaultProps = {
|
|
7
|
-
range: false,
|
|
8
|
-
hiddenRange: false,
|
|
9
|
-
hiddenTag: false,
|
|
10
|
-
min: 0,
|
|
11
|
-
max: 100,
|
|
12
|
-
step: 1,
|
|
13
|
-
modelValue: 0,
|
|
14
|
-
vertical: false,
|
|
15
|
-
marks: {}
|
|
16
|
-
};
|
|
17
|
-
let startValue;
|
|
18
|
-
let currentValue;
|
|
19
|
-
const Range = (props) => {
|
|
20
|
-
const { locale } = useConfig();
|
|
21
|
-
const { className, range, disabled, activeColor, inactiveColor, buttonColor, hiddenRange, hiddenTag, modelValue, button, vertical, marks, dragStart, dragEnd, onChange, onDragStart, onDragEnd, minDesc, maxDesc, curValueDesc } = { ...defaultProps, ...props };
|
|
22
|
-
let { min, max, step } = { ...defaultProps, ...props };
|
|
23
|
-
min = Number(min);
|
|
24
|
-
max = Number(max);
|
|
25
|
-
step = Number(step);
|
|
26
|
-
const [buttonIndex, SetButtonIndex] = useState(0);
|
|
27
|
-
const [initValue, SetInitValue] = useState();
|
|
28
|
-
const [dragStatus, SetDragStatus] = useState("start");
|
|
29
|
-
const touch = useTouch();
|
|
30
|
-
const root = useRef(null);
|
|
31
|
-
const [marksList, SetMarksList] = useState([]);
|
|
32
|
-
const [show, SetShow] = useState(false);
|
|
33
|
-
const [toastMsg, SetToastMsg] = useState("");
|
|
34
|
-
const toastShow = (msg) => {
|
|
35
|
-
SetToastMsg(msg);
|
|
36
|
-
SetShow(true);
|
|
37
|
-
};
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
if (typeof modelValue === "number") {
|
|
40
|
-
if (!range && (modelValue < min || modelValue > max)) {
|
|
41
|
-
SetInitValue(0);
|
|
42
|
-
toastShow(`${modelValue} ${locale.range.rangeText}`);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
SetInitValue(modelValue);
|
|
46
|
-
}
|
|
47
|
-
}, [modelValue]);
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
if (marks) {
|
|
50
|
-
const marksKeys = Object.keys(marks);
|
|
51
|
-
const list = marksKeys.map(parseFloat).sort((a, b) => a - b).filter((point) => point >= min && point <= max);
|
|
52
|
-
SetMarksList(list);
|
|
53
|
-
}
|
|
54
|
-
}, [marks]);
|
|
55
|
-
const scope = () => {
|
|
56
|
-
return Number(max) - Number(min);
|
|
57
|
-
};
|
|
58
|
-
const classes = useCallback(() => {
|
|
59
|
-
const prefixCls = "nut-range";
|
|
60
|
-
return [
|
|
61
|
-
prefixCls,
|
|
62
|
-
`${disabled ? `${prefixCls}-disabled` : ""}`,
|
|
63
|
-
`${vertical ? `${prefixCls}-vertical` : ""}`,
|
|
64
|
-
`${!hiddenRange ? `${prefixCls}-show-number` : ""}`
|
|
65
|
-
].filter(Boolean).join(" ");
|
|
66
|
-
}, [disabled, vertical, hiddenRange]);
|
|
67
|
-
const containerClasses = useCallback(() => {
|
|
68
|
-
const prefixCls = "nut-range-container";
|
|
69
|
-
return [prefixCls, `${vertical ? `${prefixCls}-vertical` : ""}`, className].filter(Boolean).join(" ");
|
|
70
|
-
}, [vertical, className]);
|
|
71
|
-
const markClassName = useCallback((mark) => {
|
|
72
|
-
const classPrefix = "nut-range-mark";
|
|
73
|
-
let lowerBound = Number(min);
|
|
74
|
-
let upperBound = Number(max);
|
|
75
|
-
if (range) {
|
|
76
|
-
const [left, right] = modelValue;
|
|
77
|
-
lowerBound = left;
|
|
78
|
-
upperBound = right;
|
|
79
|
-
} else {
|
|
80
|
-
upperBound = modelValue;
|
|
81
|
-
}
|
|
82
|
-
const isActive = mark <= upperBound && mark >= lowerBound;
|
|
83
|
-
return [
|
|
84
|
-
`${classPrefix}-text`,
|
|
85
|
-
`${isActive ? `${classPrefix}-text-active` : ""}`
|
|
86
|
-
].filter(Boolean).join(" ");
|
|
87
|
-
}, [range, modelValue, min, max]);
|
|
88
|
-
const [rangeName, setRangeName] = useState(classes());
|
|
89
|
-
const [containerName, setContainerName] = useState(containerClasses());
|
|
90
|
-
useEffect(() => {
|
|
91
|
-
setRangeName(classes());
|
|
92
|
-
setContainerName(containerClasses());
|
|
93
|
-
}, [classes, containerClasses]);
|
|
94
|
-
const wrapperStyle = () => {
|
|
95
|
-
return {
|
|
96
|
-
background: inactiveColor
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
const buttonStyle = () => {
|
|
100
|
-
return {
|
|
101
|
-
borderColor: buttonColor
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
const isRange = (val) => {
|
|
105
|
-
return !!range && Array.isArray(val);
|
|
106
|
-
};
|
|
107
|
-
const calcMainAxis = () => {
|
|
108
|
-
const modelVal = initValue || initValue === 0 ? initValue : modelValue;
|
|
109
|
-
if (isRange(modelVal)) {
|
|
110
|
-
return `${(modelVal[1] - modelVal[0]) * 100 / scope()}%`;
|
|
111
|
-
}
|
|
112
|
-
return `${(modelVal - Number(min)) * 100 / scope()}%`;
|
|
113
|
-
};
|
|
114
|
-
const calcOffset = () => {
|
|
115
|
-
const modelVal = initValue || initValue === 0 ? initValue : modelValue;
|
|
116
|
-
if (isRange(modelVal)) {
|
|
117
|
-
return `${(modelVal[0] - Number(min)) * 100 / scope()}%`;
|
|
118
|
-
}
|
|
119
|
-
return `0%`;
|
|
120
|
-
};
|
|
121
|
-
const barStyle = () => {
|
|
122
|
-
if (vertical) {
|
|
123
|
-
return {
|
|
124
|
-
height: calcMainAxis(),
|
|
125
|
-
top: calcOffset(),
|
|
126
|
-
background: activeColor,
|
|
127
|
-
transition: dragStatus ? "none" : void 0
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
return {
|
|
131
|
-
width: calcMainAxis(),
|
|
132
|
-
left: calcOffset(),
|
|
133
|
-
background: activeColor,
|
|
134
|
-
transition: dragStatus ? "none" : void 0
|
|
135
|
-
};
|
|
136
|
-
};
|
|
137
|
-
const marksStyle = (mark) => {
|
|
138
|
-
let style = {
|
|
139
|
-
left: `${(mark - Number(min)) / scope() * 100}%`
|
|
140
|
-
};
|
|
141
|
-
if (vertical) {
|
|
142
|
-
style = {
|
|
143
|
-
top: `${(mark - Number(min)) / scope() * 100}%`
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
return style;
|
|
147
|
-
};
|
|
148
|
-
const tickStyle = (mark) => {
|
|
149
|
-
let lowerBound = Number(min);
|
|
150
|
-
let upperBound = Number(max);
|
|
151
|
-
if (range) {
|
|
152
|
-
const [left, right] = modelValue;
|
|
153
|
-
lowerBound = left;
|
|
154
|
-
upperBound = right;
|
|
155
|
-
}
|
|
156
|
-
const isActive = mark <= upperBound && mark >= lowerBound;
|
|
157
|
-
const style = {
|
|
158
|
-
background: !isActive ? inactiveColor : activeColor
|
|
159
|
-
};
|
|
160
|
-
return style;
|
|
161
|
-
};
|
|
162
|
-
const format = (value) => {
|
|
163
|
-
value = Math.max(+min, Math.min(value, +max));
|
|
164
|
-
return Math.round(value / +step) * +step;
|
|
165
|
-
};
|
|
166
|
-
const isSameValue = (newValue, oldValue) => {
|
|
167
|
-
return JSON.stringify(newValue) === JSON.stringify(oldValue);
|
|
168
|
-
};
|
|
169
|
-
const handleOverlap = (value) => {
|
|
170
|
-
if (value[0] > value[1]) {
|
|
171
|
-
return value.slice(0).reverse();
|
|
172
|
-
}
|
|
173
|
-
return value;
|
|
174
|
-
};
|
|
175
|
-
const updateValue = (value, end) => {
|
|
176
|
-
if (isRange(value)) {
|
|
177
|
-
value = handleOverlap(value).map(format);
|
|
178
|
-
} else {
|
|
179
|
-
value = format(value);
|
|
180
|
-
}
|
|
181
|
-
const modelVal = initValue || initValue === 0 ? initValue : modelValue;
|
|
182
|
-
if (!isSameValue(value, modelVal)) {
|
|
183
|
-
SetInitValue(value);
|
|
184
|
-
}
|
|
185
|
-
if ((marks || end) && !isSameValue(value, startValue)) {
|
|
186
|
-
onChange && onChange(value);
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
const click = async (event) => {
|
|
190
|
-
if (disabled || !root.current) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
SetDragStatus("");
|
|
194
|
-
const rect = await getRectByTaro(root.current);
|
|
195
|
-
let delta = (event.detail.x ? event.detail.x : event.clientX) - rect.left;
|
|
196
|
-
let total = rect.width;
|
|
197
|
-
if (vertical) {
|
|
198
|
-
delta = (event.detail.y ? event.detail.y : event.clientY) - rect.top;
|
|
199
|
-
total = rect.height;
|
|
200
|
-
}
|
|
201
|
-
const value = Number(min) + delta / total * scope();
|
|
202
|
-
currentValue = initValue || initValue === 0 ? initValue : modelValue;
|
|
203
|
-
if (isRange(currentValue)) {
|
|
204
|
-
const [left, right] = currentValue;
|
|
205
|
-
const middle = (left + right) / 2;
|
|
206
|
-
if (value <= middle) {
|
|
207
|
-
updateValue([value, right], true);
|
|
208
|
-
} else {
|
|
209
|
-
updateValue([left, value], true);
|
|
210
|
-
}
|
|
211
|
-
} else {
|
|
212
|
-
updateValue(value, true);
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
const onTouchStart = (event) => {
|
|
216
|
-
if (disabled) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
touch.start(event);
|
|
220
|
-
currentValue = initValue || initValue === 0 ? initValue : modelValue;
|
|
221
|
-
if (isRange(currentValue)) {
|
|
222
|
-
startValue = currentValue.map(format);
|
|
223
|
-
} else {
|
|
224
|
-
startValue = format(currentValue);
|
|
225
|
-
}
|
|
226
|
-
SetDragStatus("start");
|
|
227
|
-
};
|
|
228
|
-
const onTouchMove = async (event) => {
|
|
229
|
-
if (disabled || !root.current) {
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
if (dragStatus === "start") {
|
|
233
|
-
dragStart && dragStart();
|
|
234
|
-
onDragStart && onDragStart();
|
|
235
|
-
}
|
|
236
|
-
touch.move(event);
|
|
237
|
-
SetDragStatus("draging");
|
|
238
|
-
const rect = await getRectByTaro(root.current);
|
|
239
|
-
let delta = touch.deltaX;
|
|
240
|
-
let total = rect.width;
|
|
241
|
-
let diff = delta / total * scope();
|
|
242
|
-
if (vertical) {
|
|
243
|
-
delta = touch.deltaY;
|
|
244
|
-
total = rect.height;
|
|
245
|
-
diff = delta / total * scope();
|
|
246
|
-
}
|
|
247
|
-
if (isRange(startValue)) {
|
|
248
|
-
currentValue[buttonIndex] = startValue[buttonIndex] + diff;
|
|
249
|
-
} else {
|
|
250
|
-
currentValue = startValue + diff;
|
|
251
|
-
}
|
|
252
|
-
updateValue(currentValue);
|
|
253
|
-
};
|
|
254
|
-
const onTouchEnd = (event) => {
|
|
255
|
-
if (disabled) {
|
|
256
|
-
return;
|
|
257
|
-
}
|
|
258
|
-
if (dragStatus === "draging") {
|
|
259
|
-
updateValue(currentValue, true);
|
|
260
|
-
dragEnd && dragEnd();
|
|
261
|
-
onDragEnd && onDragEnd();
|
|
262
|
-
}
|
|
263
|
-
SetDragStatus("");
|
|
264
|
-
};
|
|
265
|
-
const curValue = (idx) => {
|
|
266
|
-
const modelVal = initValue || initValue === 0 ? initValue : modelValue;
|
|
267
|
-
const value = typeof idx === "number" ? modelVal[idx] : modelVal;
|
|
268
|
-
return value;
|
|
269
|
-
};
|
|
270
|
-
return React.createElement(
|
|
271
|
-
"div",
|
|
272
|
-
{ className: `${containerName}` },
|
|
273
|
-
!hiddenRange ? React.createElement("div", { className: "min" }, minDesc || +min) : null,
|
|
274
|
-
React.createElement(
|
|
275
|
-
"div",
|
|
276
|
-
{ ref: root, style: wrapperStyle(), className: `${rangeName}`, onClick: (e) => {
|
|
277
|
-
click(e);
|
|
278
|
-
} },
|
|
279
|
-
marksList.length > 0 ? React.createElement("div", { className: "nut-range-mark" }, marksList.map((marks2) => {
|
|
280
|
-
return React.createElement(
|
|
281
|
-
"span",
|
|
282
|
-
{ key: marks2, className: markClassName(marks2), style: marksStyle(marks2) },
|
|
283
|
-
marks2,
|
|
284
|
-
React.createElement("span", { className: "nut-range-tick", style: tickStyle(marks2) })
|
|
285
|
-
);
|
|
286
|
-
})) : null,
|
|
287
|
-
React.createElement("div", { className: "nut-range-bar", style: barStyle() }, range ? [0, 1].map((item, index) => {
|
|
288
|
-
return React.createElement("div", { role: "slider", key: index, className: `${index === 0 ? "nut-range-button-wrapper-left" : ""}
|
|
289
|
-
${index === 1 ? "nut-range-button-wrapper-right" : ""}`, tabIndex: disabled ? -1 : 0, "aria-valuemin": +min, "aria-valuenow": curValue(index), "aria-valuemax": +max, "aria-orientation": vertical ? "vertical" : "horizontal", onTouchStart: (e) => {
|
|
290
|
-
if (typeof index === "number") {
|
|
291
|
-
SetButtonIndex(index);
|
|
292
|
-
}
|
|
293
|
-
onTouchStart(e);
|
|
294
|
-
}, onTouchMove: (e) => {
|
|
295
|
-
onTouchMove(e);
|
|
296
|
-
}, onTouchEnd: (e) => {
|
|
297
|
-
onTouchEnd();
|
|
298
|
-
}, onTouchCancel: (e) => {
|
|
299
|
-
onTouchEnd();
|
|
300
|
-
}, onClick: (e) => {
|
|
301
|
-
e.stopPropagation();
|
|
302
|
-
} }, button || React.createElement("div", { className: "nut-range-button", style: buttonStyle() }, !hiddenTag ? React.createElement("div", { className: "number" }, curValueDesc || curValue(index)) : null));
|
|
303
|
-
}) : React.createElement("div", { role: "slider", className: "nut-range-button-wrapper", tabIndex: disabled ? -1 : 0, "aria-valuemin": +min, "aria-valuenow": curValue(), "aria-valuemax": +max, "aria-orientation": vertical ? "vertical" : "horizontal", onTouchStart: (e) => {
|
|
304
|
-
onTouchStart(e);
|
|
305
|
-
}, onTouchMove: (e) => {
|
|
306
|
-
onTouchMove(e);
|
|
307
|
-
}, onTouchEnd: (e) => {
|
|
308
|
-
onTouchEnd();
|
|
309
|
-
}, onTouchCancel: (e) => {
|
|
310
|
-
onTouchEnd();
|
|
311
|
-
}, onClick: (e) => {
|
|
312
|
-
e.stopPropagation();
|
|
313
|
-
} }, button || React.createElement("div", { className: "nut-range-button", style: buttonStyle() }, !hiddenTag ? React.createElement("div", { className: "number" }, curValueDesc || curValue()) : null)))
|
|
314
|
-
),
|
|
315
|
-
!hiddenRange ? React.createElement("div", { className: "max" }, maxDesc || +max) : null,
|
|
316
|
-
React.createElement(Toast, { type: "text", visible: show, msg: toastMsg, onClose: () => {
|
|
317
|
-
SetShow(false);
|
|
318
|
-
} })
|
|
319
|
-
);
|
|
320
|
-
};
|
|
321
|
-
Range.defaultProps = defaultProps;
|
|
322
|
-
Range.displayName = "NutRange";
|
|
323
|
-
export {
|
|
324
|
-
Range as R
|
|
325
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { c as canUseDom } from "./can-use-dom-0e539bd3.js";
|
|
2
|
-
let passiveSupported = false;
|
|
3
|
-
if (canUseDom) {
|
|
4
|
-
try {
|
|
5
|
-
const opts = Object.defineProperty({}, "passive", {
|
|
6
|
-
get() {
|
|
7
|
-
passiveSupported = true;
|
|
8
|
-
}
|
|
9
|
-
});
|
|
10
|
-
window.addEventListener("test-passive-supported", null, opts);
|
|
11
|
-
} catch (e) {
|
|
12
|
-
console.log(e);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export {
|
|
16
|
-
passiveSupported as p
|
|
17
|
-
};
|