@nutui/nutui-react-taro 2.0.0-alpha.8 → 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 +20 -0
- package/dist/esm/Address.js +2 -2
- package/dist/esm/Card.js +5 -5
- 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/Step.js +1 -1
- package/dist/esm/Steps.js +1 -1
- package/dist/esm/Sticky.js +1 -2
- package/dist/esm/Swiper.js +3 -5
- package/dist/esm/SwiperItem.js +1 -5
- package/dist/esm/{address.taro-1c534feb.js → address.taro-1a8ab3f1.js} +1 -1
- package/dist/esm/{card.taro-a46fdf25.js → card.taro-2080f4d2.js} +1 -1
- 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 +16 -21
- 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/step.taro-3bc01c0c.js +1 -1
- package/dist/esm/steps.taro-77e301ab.js +1 -1
- 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/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 +1162 -6119
- package/dist/nutui.react.umd.js +1546 -6519
- 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/swiper/swiper.scss +0 -15
- package/dist/style.css +1 -1
- package/dist/style.mjs +1 -1
- package/dist/styles/variables-jmapp.scss +50 -44
- package/dist/styles/variables.scss +50 -46
- package/dist/types/index.d.ts +63 -92
- 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/supports-passive-aaaf0eff.js +0 -17
- package/dist/esm/swiper.taro-74cf9306.js +0 -430
- package/dist/esm/swiperitem-80df464a.js +0 -29
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import React, { useState, useEffect } from "react";
|
|
2
|
-
import classNames from "classnames";
|
|
3
|
-
import { c as cn } from "./bem-cdccae08.js";
|
|
4
|
-
import { P as Popup } from "./popup.taro-e756f3fc.js";
|
|
5
|
-
import { u as useConfig } from "./configprovider.taro-25758d9f.js";
|
|
6
|
-
const defaultProps = {
|
|
7
|
-
confirmText: "",
|
|
8
|
-
title: "",
|
|
9
|
-
visible: false,
|
|
10
|
-
overlay: false,
|
|
11
|
-
type: "default",
|
|
12
|
-
customKey: [],
|
|
13
|
-
className: "",
|
|
14
|
-
randomKeys: false,
|
|
15
|
-
popClass: "",
|
|
16
|
-
onClose: () => {
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
const NumberKeyboard = (props) => {
|
|
20
|
-
const { locale } = useConfig();
|
|
21
|
-
const { title, confirmText, visible, overlay, type, customKey, randomKeys, popClass, style, className, onChange, onDelete, onClose } = props;
|
|
22
|
-
const b = cn("numberkeyboard");
|
|
23
|
-
const [show, setShow] = useState(visible);
|
|
24
|
-
const [clickKeyIndex, setClickKeyIndex] = useState(void 0);
|
|
25
|
-
const [keysList, setKeysList] = useState([]);
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
setShow(visible);
|
|
28
|
-
}, [visible]);
|
|
29
|
-
const defaultKey = () => {
|
|
30
|
-
let leftBottomKey = {
|
|
31
|
-
id: "lock",
|
|
32
|
-
type: "lock"
|
|
33
|
-
};
|
|
34
|
-
if (customKey) {
|
|
35
|
-
const customKeys = Array.isArray(customKey) ? customKey : [customKey];
|
|
36
|
-
if (customKeys.length > 0) {
|
|
37
|
-
const newCustomKey = customKeys[0];
|
|
38
|
-
leftBottomKey = {
|
|
39
|
-
id: newCustomKey,
|
|
40
|
-
type: "custom"
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return [
|
|
45
|
-
...getBasicKeys(),
|
|
46
|
-
leftBottomKey,
|
|
47
|
-
{ id: 0, type: "number" },
|
|
48
|
-
{ id: "delete", type: "delete" }
|
|
49
|
-
];
|
|
50
|
-
};
|
|
51
|
-
const getBasicKeys = () => {
|
|
52
|
-
const keys = [];
|
|
53
|
-
for (let i = 1; i <= 9; i++) {
|
|
54
|
-
keys.push({ id: i, type: "number" });
|
|
55
|
-
}
|
|
56
|
-
if (randomKeys) {
|
|
57
|
-
return keys.sort(() => Math.random() > 0.5 ? 1 : -1);
|
|
58
|
-
}
|
|
59
|
-
return keys;
|
|
60
|
-
};
|
|
61
|
-
const genCustomKeys = () => {
|
|
62
|
-
const keys = getBasicKeys();
|
|
63
|
-
if (!customKey)
|
|
64
|
-
return [];
|
|
65
|
-
let customKeys = Array.isArray(customKey) ? customKey : [customKey];
|
|
66
|
-
if (customKeys.length > 2) {
|
|
67
|
-
customKeys = [customKeys[0], customKeys[1]];
|
|
68
|
-
}
|
|
69
|
-
if (customKeys.length === 2 && props.title && props.type !== "rightColumn") {
|
|
70
|
-
customKeys = [customKeys[0]];
|
|
71
|
-
}
|
|
72
|
-
if (customKeys.length === 1) {
|
|
73
|
-
if (props.title && props.type !== "rightColumn") {
|
|
74
|
-
keys.push({ id: customKeys[0], type: "custom" }, { id: 0, type: "number" }, { id: "delete", type: "delete" });
|
|
75
|
-
} else {
|
|
76
|
-
keys.push({ id: 0, type: "number" }, { id: customKeys[0], type: "custom" });
|
|
77
|
-
}
|
|
78
|
-
} else if (customKeys.length === 2) {
|
|
79
|
-
keys.push({ id: customKeys[0], type: "custom" }, { id: 0, type: "number" }, { id: customKeys[1], type: "custom" });
|
|
80
|
-
}
|
|
81
|
-
return keys;
|
|
82
|
-
};
|
|
83
|
-
useEffect(() => {
|
|
84
|
-
if (props.type === "rightColumn" || props.title !== "") {
|
|
85
|
-
setKeysList(genCustomKeys());
|
|
86
|
-
} else {
|
|
87
|
-
setKeysList(defaultKey());
|
|
88
|
-
}
|
|
89
|
-
}, []);
|
|
90
|
-
const onTouchstart = (item, event) => {
|
|
91
|
-
event.stopPropagation();
|
|
92
|
-
setClickKeyIndex(item.id);
|
|
93
|
-
if (item.type === "number" || item.type === "custom") {
|
|
94
|
-
onChange && onChange(item.id);
|
|
95
|
-
}
|
|
96
|
-
if (item.type === "lock") {
|
|
97
|
-
onClose && onClose();
|
|
98
|
-
}
|
|
99
|
-
if (item.type === "delete") {
|
|
100
|
-
onDelete && onDelete();
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
const onTouchMove = (event) => {
|
|
104
|
-
event.stopPropagation();
|
|
105
|
-
};
|
|
106
|
-
const onTouchEnd = (event) => {
|
|
107
|
-
event.preventDefault();
|
|
108
|
-
setClickKeyIndex(void 0);
|
|
109
|
-
};
|
|
110
|
-
return React.createElement(
|
|
111
|
-
"div",
|
|
112
|
-
null,
|
|
113
|
-
React.createElement(
|
|
114
|
-
Popup,
|
|
115
|
-
{ visible: show, overlay, position: "bottom", className: popClass, onClickOverlay: onClose, onClickCloseIcon: onClose, overlayStyle: { backgroundColor: "rgba(0, 0, 0, 0)" } },
|
|
116
|
-
React.createElement(
|
|
117
|
-
"div",
|
|
118
|
-
{ className: `${b()} ${className}`, style: { ...style } },
|
|
119
|
-
title ? React.createElement(
|
|
120
|
-
"div",
|
|
121
|
-
{ className: b("header") },
|
|
122
|
-
React.createElement("h3", { className: b("header__tit") }, title),
|
|
123
|
-
type === "default" ? React.createElement("span", { className: b("header__close"), onClick: onClose }, locale.done) : null
|
|
124
|
-
) : null,
|
|
125
|
-
React.createElement(
|
|
126
|
-
"div",
|
|
127
|
-
{ className: b("body") },
|
|
128
|
-
React.createElement("div", { className: b("body__keys") }, keysList == null ? void 0 : keysList.map((item, index) => {
|
|
129
|
-
return React.createElement(
|
|
130
|
-
"div",
|
|
131
|
-
{ key: index, className: classNames({
|
|
132
|
-
"key-board-wrapper": true,
|
|
133
|
-
"key-board-wrapper-large": item.id === 0 && type === "rightColumn" && Array.isArray(customKey) && customKey.length === 1
|
|
134
|
-
}) },
|
|
135
|
-
React.createElement(
|
|
136
|
-
"div",
|
|
137
|
-
{ className: classNames({
|
|
138
|
-
key: true,
|
|
139
|
-
active: item.id === clickKeyIndex,
|
|
140
|
-
lock: item.type === "lock",
|
|
141
|
-
delete: item.type === "delete"
|
|
142
|
-
}), onTouchStart: (event) => onTouchstart(item, event), onTouchMove, onTouchEnd },
|
|
143
|
-
item.type === "number" || item.type === "custom" ? React.createElement("div", null, item.id) : null,
|
|
144
|
-
item.type === "lock" ? React.createElement("img", { src: "https://img11.360buyimg.com/imagetools/jfs/t1/146371/38/8485/738/5f606425Eca239740/14f4b4f5f20d8a68.png", alt: "" }) : null,
|
|
145
|
-
item.type === "delete" ? React.createElement("img", { src: "https://img11.360buyimg.com/imagetools/jfs/t1/129395/8/12735/2030/5f61ac37E70cab338/fb477dc11f46056c.png", alt: "" }) : null
|
|
146
|
-
)
|
|
147
|
-
);
|
|
148
|
-
})),
|
|
149
|
-
type === "rightColumn" ? React.createElement(
|
|
150
|
-
"div",
|
|
151
|
-
{ className: b("sidebar") },
|
|
152
|
-
React.createElement(
|
|
153
|
-
"div",
|
|
154
|
-
{ className: "key-board-wrapper" },
|
|
155
|
-
React.createElement(
|
|
156
|
-
"div",
|
|
157
|
-
{ className: classNames({
|
|
158
|
-
key: true,
|
|
159
|
-
active: clickKeyIndex === "delete"
|
|
160
|
-
}), onTouchStart: (event) => onTouchstart({ id: "delete", type: "delete" }, event), onTouchMove, onTouchEnd },
|
|
161
|
-
React.createElement("img", { src: "https://img11.360buyimg.com/imagetools/jfs/t1/129395/8/12735/2030/5f61ac37E70cab338/fb477dc11f46056c.png", alt: "" })
|
|
162
|
-
)
|
|
163
|
-
),
|
|
164
|
-
React.createElement(
|
|
165
|
-
"div",
|
|
166
|
-
{ className: "key-board-wrapper key-board-finish", onClick: onClose },
|
|
167
|
-
React.createElement("div", { className: classNames({
|
|
168
|
-
key: true,
|
|
169
|
-
finish: true,
|
|
170
|
-
activeFinsh: clickKeyIndex === "finish"
|
|
171
|
-
}) }, confirmText || locale.done)
|
|
172
|
-
)
|
|
173
|
-
) : null
|
|
174
|
-
)
|
|
175
|
-
)
|
|
176
|
-
)
|
|
177
|
-
);
|
|
178
|
-
};
|
|
179
|
-
NumberKeyboard.defaultProps = defaultProps;
|
|
180
|
-
NumberKeyboard.displayName = "NutNumberKeyboard";
|
|
181
|
-
export {
|
|
182
|
-
NumberKeyboard as N
|
|
183
|
-
};
|
|
@@ -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,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
|
-
};
|