@nutui/nutui-react 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/Audio.js +5 -5
- package/dist/esm/Elevator.js +6 -5
- package/dist/esm/Image.js +2 -5
- package/dist/esm/ImagePreview.js +9 -9
- package/dist/esm/Indicator.js +4 -4
- package/dist/esm/Notify.js +35 -46
- package/dist/esm/NumberKeyboard.js +137 -195
- package/dist/esm/Price.js +22 -23
- package/dist/esm/PullToRefresh.js +8 -8
- package/dist/esm/Radio.js +2 -0
- package/dist/esm/RadioGroup.js +31 -51
- package/dist/esm/Swiper.js +100 -111
- package/dist/esm/SwiperItem.js +1 -1
- package/dist/esm/radio2.js +52 -54
- 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 +718 -742
- package/dist/nutui.react.umd.js +717 -741
- 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 +64 -80
- package/package.json +1 -1
- /package/dist/esm/{UserContext3.js → context2.js} +0 -0
package/dist/esm/Swiper.js
CHANGED
|
@@ -2,7 +2,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
4
|
import _typeof from "@babel/runtime/helpers/typeof";
|
|
5
|
-
var _excluded = ["children", "direction", "className", "
|
|
5
|
+
var _excluded = ["children", "direction", "className", "onChange", "defaultValue", "indicator", "touchable", "preventDefault", "stopPropagation", "autoPlay", "center"];
|
|
6
6
|
function ownKeys(object, enumerableOnly) {
|
|
7
7
|
var keys = Object.keys(object);
|
|
8
8
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -26,35 +26,32 @@ function _objectSpread(target) {
|
|
|
26
26
|
}
|
|
27
27
|
import React__default, { useRef, useState, useMemo, useEffect } from "react";
|
|
28
28
|
import classNames from "classnames";
|
|
29
|
-
import { D as DataContext } from "./
|
|
30
|
-
import { c as cn } from "./bem.js";
|
|
29
|
+
import { D as DataContext } from "./context2.js";
|
|
31
30
|
import { g as getRect } from "./use-client-rect.js";
|
|
32
|
-
import "
|
|
31
|
+
import Indicator from "./Indicator.js";
|
|
33
32
|
var defaultProps = {
|
|
34
33
|
width: (typeof window === "undefined" ? "undefined" : _typeof(window)) === "object" ? window.innerWidth : 375,
|
|
35
34
|
height: 0,
|
|
36
35
|
duration: 500,
|
|
37
|
-
|
|
36
|
+
defaultValue: 0,
|
|
38
37
|
autoPlay: 0,
|
|
39
38
|
direction: "horizontal",
|
|
40
|
-
|
|
41
|
-
paginationBgColor: "#ddd",
|
|
42
|
-
paginationVisible: false,
|
|
39
|
+
indicator: false,
|
|
43
40
|
loop: true,
|
|
44
41
|
touchable: true,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
preventDefault: true,
|
|
43
|
+
stopPropagation: true,
|
|
44
|
+
center: false,
|
|
48
45
|
className: ""
|
|
49
46
|
};
|
|
50
47
|
var DISTANCE = 5;
|
|
51
48
|
var Swiper = React__default.forwardRef(function(props, ref) {
|
|
52
|
-
var _classNames
|
|
49
|
+
var _classNames;
|
|
53
50
|
var propSwiper = _objectSpread(_objectSpread({}, defaultProps), props);
|
|
54
|
-
var children = propSwiper.children, direction = propSwiper.direction, className = propSwiper.className,
|
|
51
|
+
var children = propSwiper.children, direction = propSwiper.direction, className = propSwiper.className, onChange = propSwiper.onChange, defaultValue = propSwiper.defaultValue, indicator = propSwiper.indicator, touchable = propSwiper.touchable, preventDefault = propSwiper.preventDefault, stopPropagation = propSwiper.stopPropagation, autoPlay = propSwiper.autoPlay, center = propSwiper.center, rest = _objectWithoutProperties(propSwiper, _excluded);
|
|
55
52
|
var container = useRef(null);
|
|
56
53
|
var innerRef = useRef(null);
|
|
57
|
-
var
|
|
54
|
+
var swiperRef = useRef({
|
|
58
55
|
moving: false,
|
|
59
56
|
autoplayTimer: null,
|
|
60
57
|
width: 0,
|
|
@@ -81,7 +78,7 @@ var Swiper = React__default.forwardRef(function(props, ref) {
|
|
|
81
78
|
stateDirection: "",
|
|
82
79
|
delta: 0,
|
|
83
80
|
touchTime: 0
|
|
84
|
-
}), _useState16 = _slicedToArray(_useState15,
|
|
81
|
+
}), _useState16 = _slicedToArray(_useState15, 1), touch = _useState16[0];
|
|
85
82
|
var _useMemo = useMemo(function() {
|
|
86
83
|
var childCount2 = 0;
|
|
87
84
|
var childs2 = React__default.Children.map(props.children, function(child) {
|
|
@@ -108,20 +105,20 @@ var Swiper = React__default.forwardRef(function(props, ref) {
|
|
|
108
105
|
return 0;
|
|
109
106
|
}();
|
|
110
107
|
var stopAutoPlay = function stopAutoPlay2() {
|
|
111
|
-
clearTimeout(
|
|
112
|
-
|
|
108
|
+
clearTimeout(swiperRef.current.autoplayTimer);
|
|
109
|
+
swiperRef.current.autoplayTimer = null;
|
|
113
110
|
};
|
|
114
|
-
var
|
|
111
|
+
var startPlay = function startPlay2() {
|
|
115
112
|
if (propSwiper.autoPlay <= 0 || childCount <= 1)
|
|
116
113
|
return;
|
|
117
114
|
stopAutoPlay();
|
|
118
|
-
|
|
115
|
+
swiperRef.current.autoplayTimer = setTimeout(function() {
|
|
119
116
|
next();
|
|
120
|
-
|
|
117
|
+
startPlay2();
|
|
121
118
|
}, Number(propSwiper.autoPlay));
|
|
122
119
|
};
|
|
123
|
-
var
|
|
124
|
-
|
|
120
|
+
var resetPosition = function resetPosition2() {
|
|
121
|
+
swiperRef.current.moving = true;
|
|
125
122
|
if (active <= -1) {
|
|
126
123
|
move({
|
|
127
124
|
pace: childCount
|
|
@@ -134,47 +131,41 @@ var Swiper = React__default.forwardRef(function(props, ref) {
|
|
|
134
131
|
}
|
|
135
132
|
};
|
|
136
133
|
var prev = function prev2() {
|
|
137
|
-
|
|
138
|
-
|
|
134
|
+
resetPosition();
|
|
135
|
+
resetTouchDetails();
|
|
139
136
|
requestFrame(function() {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
isEmit: true
|
|
145
|
-
});
|
|
137
|
+
swiperRef.current.moving = false;
|
|
138
|
+
move({
|
|
139
|
+
pace: -1,
|
|
140
|
+
isEmit: true
|
|
146
141
|
});
|
|
147
142
|
});
|
|
148
143
|
};
|
|
149
144
|
var next = function next2() {
|
|
150
|
-
|
|
151
|
-
|
|
145
|
+
resetPosition();
|
|
146
|
+
resetTouchDetails();
|
|
152
147
|
requestFrame(function() {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
isEmit: true
|
|
158
|
-
});
|
|
148
|
+
swiperRef.current.moving = false;
|
|
149
|
+
move({
|
|
150
|
+
pace: 1,
|
|
151
|
+
isEmit: true
|
|
159
152
|
});
|
|
160
153
|
});
|
|
161
154
|
};
|
|
162
155
|
var to = function to2(index) {
|
|
163
|
-
|
|
164
|
-
|
|
156
|
+
resetPosition();
|
|
157
|
+
resetTouchDetails();
|
|
165
158
|
requestFrame(function() {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
isEmit: true
|
|
177
|
-
});
|
|
159
|
+
swiperRef.current.moving = false;
|
|
160
|
+
var targetIndex;
|
|
161
|
+
if (props.loop && childCount === index) {
|
|
162
|
+
targetIndex = active === 0 ? 0 : index;
|
|
163
|
+
} else {
|
|
164
|
+
targetIndex = index % childCount;
|
|
165
|
+
}
|
|
166
|
+
move({
|
|
167
|
+
pace: targetIndex - active,
|
|
168
|
+
isEmit: true
|
|
178
169
|
});
|
|
179
170
|
});
|
|
180
171
|
};
|
|
@@ -241,7 +232,7 @@ var Swiper = React__default.forwardRef(function(props, ref) {
|
|
|
241
232
|
return "vertical";
|
|
242
233
|
return "";
|
|
243
234
|
};
|
|
244
|
-
var
|
|
235
|
+
var resetTouchDetails = function resetTouchDetails2() {
|
|
245
236
|
touch.startX = 0;
|
|
246
237
|
touch.startY = 0;
|
|
247
238
|
touch.deltaX = 0;
|
|
@@ -253,11 +244,11 @@ var Swiper = React__default.forwardRef(function(props, ref) {
|
|
|
253
244
|
touch.touchTime = 0;
|
|
254
245
|
};
|
|
255
246
|
var touchStart = function touchStart2(e) {
|
|
256
|
-
|
|
247
|
+
resetTouchDetails();
|
|
257
248
|
touch.startX = e.touches[0].clientX;
|
|
258
249
|
touch.startY = e.touches[0].clientY;
|
|
259
250
|
};
|
|
260
|
-
var
|
|
251
|
+
var handleTouchMove = function handleTouchMove2(e) {
|
|
261
252
|
touch.deltaX = e.touches[0].clientX - touch.startX;
|
|
262
253
|
touch.deltaY = e.touches[0].clientY - touch.startY;
|
|
263
254
|
touch.offsetX = Math.abs(touch.deltaX);
|
|
@@ -267,40 +258,39 @@ var Swiper = React__default.forwardRef(function(props, ref) {
|
|
|
267
258
|
touch.stateDirection = getDirection(touch.offsetX, touch.offsetY);
|
|
268
259
|
}
|
|
269
260
|
};
|
|
270
|
-
var
|
|
271
|
-
var
|
|
272
|
-
var contentClass = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(b("inner")), true), _defineProperty(_classNames, "".concat(b("vertical")), isVertical), _classNames));
|
|
261
|
+
var classPrefix = "nut-swiper";
|
|
262
|
+
var contentClass = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(classPrefix, "__inner"), true), _defineProperty(_classNames, "".concat(classPrefix, "__vertical"), isVertical), _classNames));
|
|
273
263
|
var getStyle = function getStyle2() {
|
|
274
264
|
var moveOffset = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : offset;
|
|
275
265
|
var target = innerRef.current;
|
|
276
266
|
var _offset = 0;
|
|
277
|
-
if (!
|
|
267
|
+
if (!center) {
|
|
278
268
|
_offset = moveOffset;
|
|
279
269
|
} else {
|
|
280
270
|
var _size = isVertical ? height : width;
|
|
281
271
|
var val = isVertical ? rect.height - _size : rect.width - _size;
|
|
282
272
|
_offset = moveOffset + (active === childCount - 1 && !props.loop ? -val / 2 : val / 2);
|
|
283
273
|
}
|
|
284
|
-
target.style.transitionDuration = "".concat(
|
|
274
|
+
target.style.transitionDuration = "".concat(swiperRef.current.moving ? 0 : props.duration, "ms");
|
|
285
275
|
target.style[isVertical ? "height" : "width"] = "".concat(Number(size) * childCount, "px");
|
|
286
276
|
target.style[isVertical ? "width" : "height"] = "".concat(isVertical ? width : height, "px");
|
|
287
277
|
target.style.transform = "translate3D".concat(!isVertical ? "(".concat(_offset, "px,0,0)") : "(0,".concat(_offset, "px,0)"));
|
|
288
278
|
};
|
|
289
279
|
var onTouchStart = function onTouchStart2(e) {
|
|
290
|
-
if (props.
|
|
280
|
+
if (props.preventDefault)
|
|
291
281
|
e.preventDefault();
|
|
292
|
-
if (props.
|
|
282
|
+
if (props.stopPropagation)
|
|
293
283
|
e.stopPropagation();
|
|
294
284
|
if (!props.touchable)
|
|
295
285
|
return;
|
|
296
286
|
touchStart(e);
|
|
297
287
|
touch.touchTime = Date.now();
|
|
298
288
|
stopAutoPlay();
|
|
299
|
-
|
|
289
|
+
resetPosition();
|
|
300
290
|
};
|
|
301
291
|
var onTouchMove = function onTouchMove2(e) {
|
|
302
|
-
if (props.touchable &&
|
|
303
|
-
|
|
292
|
+
if (props.touchable && swiperRef.current.moving) {
|
|
293
|
+
handleTouchMove(e);
|
|
304
294
|
if (touch.stateDirection === props.direction) {
|
|
305
295
|
move({
|
|
306
296
|
offset: touch.delta
|
|
@@ -309,12 +299,12 @@ var Swiper = React__default.forwardRef(function(props, ref) {
|
|
|
309
299
|
}
|
|
310
300
|
};
|
|
311
301
|
var onTouchEnd = function onTouchEnd2(e) {
|
|
312
|
-
if (!props.touchable || !
|
|
302
|
+
if (!props.touchable || !swiperRef.current.moving)
|
|
313
303
|
return;
|
|
314
304
|
var speed = touch.delta / (Date.now() - touch.touchTime);
|
|
315
|
-
var isShouldMove = Math.abs(speed) > 0.3 || Math.abs(touch.delta) >
|
|
305
|
+
var isShouldMove = Math.abs(speed) > 0.3 || Math.abs(touch.delta) > Number((size / 2).toFixed(2));
|
|
316
306
|
var pace = 0;
|
|
317
|
-
|
|
307
|
+
swiperRef.current.moving = false;
|
|
318
308
|
if (isShouldMove && touch.stateDirection === props.direction) {
|
|
319
309
|
var offset2 = isVertical ? touch.offsetY : touch.offsetX;
|
|
320
310
|
if (props.loop) {
|
|
@@ -337,28 +327,28 @@ var Swiper = React__default.forwardRef(function(props, ref) {
|
|
|
337
327
|
} else {
|
|
338
328
|
getStyle();
|
|
339
329
|
}
|
|
340
|
-
|
|
330
|
+
startPlay();
|
|
341
331
|
};
|
|
342
332
|
useEffect(function() {
|
|
343
|
-
|
|
333
|
+
swiperRef.current.activePagination = (active + childCount) % childCount;
|
|
344
334
|
}, [active]);
|
|
345
335
|
var init = function init2() {
|
|
346
|
-
var active2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : +propSwiper.
|
|
336
|
+
var active2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : +propSwiper.defaultValue;
|
|
347
337
|
var rect2 = getRect(container === null || container === void 0 ? void 0 : container.current);
|
|
348
|
-
var
|
|
349
|
-
var
|
|
350
|
-
var
|
|
351
|
-
size = isVertical ?
|
|
338
|
+
var currentIndex = Math.max(Math.min(childCount - 1, active2), 0);
|
|
339
|
+
var width2 = +propSwiper.width || rect2.width;
|
|
340
|
+
var height2 = +propSwiper.height || rect2.height;
|
|
341
|
+
size = isVertical ? height2 : width2;
|
|
352
342
|
trackSize = childCount * Number(size);
|
|
353
|
-
var targetOffset = getOffset(
|
|
354
|
-
|
|
343
|
+
var targetOffset = getOffset(currentIndex);
|
|
344
|
+
swiperRef.current.moving = true;
|
|
355
345
|
if (ready) {
|
|
356
|
-
|
|
346
|
+
swiperRef.current.moving = false;
|
|
357
347
|
}
|
|
358
348
|
setRect(rect2);
|
|
359
|
-
setActive(
|
|
360
|
-
setWidth(
|
|
361
|
-
setHeight(
|
|
349
|
+
setActive(currentIndex);
|
|
350
|
+
setWidth(width2);
|
|
351
|
+
setHeight(height2);
|
|
362
352
|
setOffset(targetOffset);
|
|
363
353
|
setReady(true);
|
|
364
354
|
};
|
|
@@ -370,19 +360,19 @@ var Swiper = React__default.forwardRef(function(props, ref) {
|
|
|
370
360
|
useEffect(function() {
|
|
371
361
|
if (ready) {
|
|
372
362
|
stopAutoPlay();
|
|
373
|
-
|
|
363
|
+
startPlay();
|
|
374
364
|
}
|
|
375
365
|
return function() {
|
|
376
|
-
setReady(false);
|
|
366
|
+
return setReady(false);
|
|
377
367
|
};
|
|
378
368
|
}, [ready]);
|
|
379
369
|
useEffect(function() {
|
|
380
370
|
stopAutoPlay();
|
|
381
|
-
|
|
371
|
+
startPlay();
|
|
382
372
|
}, [children]);
|
|
383
373
|
useEffect(function() {
|
|
384
|
-
init();
|
|
385
|
-
}, [propSwiper.
|
|
374
|
+
return init();
|
|
375
|
+
}, [propSwiper.defaultValue]);
|
|
386
376
|
useEffect(function() {
|
|
387
377
|
var target = container.current;
|
|
388
378
|
target.addEventListener("touchstart", onTouchStart, false);
|
|
@@ -396,19 +386,17 @@ var Swiper = React__default.forwardRef(function(props, ref) {
|
|
|
396
386
|
});
|
|
397
387
|
useEffect(function() {
|
|
398
388
|
return function() {
|
|
399
|
-
stopAutoPlay();
|
|
389
|
+
return stopAutoPlay();
|
|
400
390
|
};
|
|
401
391
|
}, []);
|
|
402
|
-
var
|
|
392
|
+
var getItemStyle = function getItemStyle2(index) {
|
|
403
393
|
var style = {};
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
if (_size) {
|
|
407
|
-
style[_direction === "horizontal" ? "width" : "height"] = "".concat(_size, "px");
|
|
394
|
+
if (size) {
|
|
395
|
+
style[direction === "horizontal" ? "width" : "height"] = "".concat(size, "px");
|
|
408
396
|
}
|
|
409
397
|
var offset2 = childOffset[index];
|
|
410
398
|
if (offset2) {
|
|
411
|
-
style.transform = "translate3D".concat(
|
|
399
|
+
style.transform = "translate3D".concat(direction === "horizontal" ? "(".concat(offset2, "px,0,0)") : "(0,".concat(offset2, "px,0)"));
|
|
412
400
|
}
|
|
413
401
|
return style;
|
|
414
402
|
};
|
|
@@ -420,35 +408,36 @@ var Swiper = React__default.forwardRef(function(props, ref) {
|
|
|
420
408
|
resize
|
|
421
409
|
};
|
|
422
410
|
});
|
|
411
|
+
var renderIndicator = function renderIndicator2() {
|
|
412
|
+
if (React__default.isValidElement(indicator))
|
|
413
|
+
return indicator;
|
|
414
|
+
if (indicator === true) {
|
|
415
|
+
var _classNames2;
|
|
416
|
+
return React__default.createElement("div", {
|
|
417
|
+
className: classNames((_classNames2 = {}, _defineProperty(_classNames2, "".concat(classPrefix, "__pagination"), true), _defineProperty(_classNames2, "".concat(classPrefix, "__pagination-vertical"), isVertical), _classNames2))
|
|
418
|
+
}, React__default.createElement(Indicator, {
|
|
419
|
+
current: (active + childCount) % childCount,
|
|
420
|
+
total: childs === null || childs === void 0 ? void 0 : childs.length,
|
|
421
|
+
direction
|
|
422
|
+
}));
|
|
423
|
+
}
|
|
424
|
+
return null;
|
|
425
|
+
};
|
|
423
426
|
return React__default.createElement(DataContext.Provider, {
|
|
424
427
|
value: parent
|
|
425
428
|
}, React__default.createElement("div", _objectSpread({
|
|
426
|
-
className:
|
|
429
|
+
className: classNames(classPrefix, className),
|
|
427
430
|
ref: container
|
|
428
431
|
}, rest), React__default.createElement("div", {
|
|
429
432
|
className: contentClass,
|
|
430
433
|
ref: innerRef
|
|
431
434
|
}, React__default.Children.map(childs, function(child, index) {
|
|
432
435
|
return React__default.createElement("div", {
|
|
433
|
-
className:
|
|
434
|
-
style:
|
|
436
|
+
className: "".concat(classPrefix, "__item-wrapper"),
|
|
437
|
+
style: getItemStyle(index),
|
|
435
438
|
key: index
|
|
436
439
|
}, child);
|
|
437
|
-
})),
|
|
438
|
-
className: classNames((_classNames2 = {}, _defineProperty(_classNames2, "".concat(b("pagination")), true), _defineProperty(_classNames2, "".concat(b("pagination-vertical")), isVertical), _classNames2))
|
|
439
|
-
}, React__default.Children.map(childs, function(item, index) {
|
|
440
|
-
return React__default.createElement("i", {
|
|
441
|
-
style: (active + childCount) % childCount === index ? {
|
|
442
|
-
backgroundColor: propSwiper.paginationColor
|
|
443
|
-
} : {
|
|
444
|
-
backgroundColor: propSwiper.paginationBgColor
|
|
445
|
-
},
|
|
446
|
-
className: classNames({
|
|
447
|
-
active: (active + childCount) % childCount === index
|
|
448
|
-
}),
|
|
449
|
-
key: index
|
|
450
|
-
});
|
|
451
|
-
})) : React__default.createElement("div", null, pageContent)));
|
|
440
|
+
})), renderIndicator()));
|
|
452
441
|
});
|
|
453
442
|
Swiper.defaultProps = defaultProps;
|
|
454
443
|
Swiper.displayName = "NutSwiper";
|
package/dist/esm/SwiperItem.js
CHANGED
|
@@ -22,7 +22,7 @@ function _objectSpread(target) {
|
|
|
22
22
|
}
|
|
23
23
|
import React__default, { useContext } from "react";
|
|
24
24
|
import classNames from "classnames";
|
|
25
|
-
import { D as DataContext } from "./
|
|
25
|
+
import { D as DataContext } from "./context2.js";
|
|
26
26
|
import { c as cn } from "./bem.js";
|
|
27
27
|
import "@bem-react/classname";
|
|
28
28
|
var defaultProps = {
|
package/dist/esm/radio2.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
-
var _excluded = ["className", "
|
|
4
|
+
var _excluded = ["children", "className", "style", "checked", "defaultChecked", "shape", "value", "icon", "activeIcon", "onChange"], _excluded2 = ["labelPosition", "disabled"];
|
|
5
5
|
function ownKeys(object, enumerableOnly) {
|
|
6
6
|
var keys = Object.keys(object);
|
|
7
7
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -23,106 +23,104 @@ function _objectSpread(target) {
|
|
|
23
23
|
}
|
|
24
24
|
return target;
|
|
25
25
|
}
|
|
26
|
-
import React__default, {
|
|
26
|
+
import React__default, { useContext } from "react";
|
|
27
27
|
import { CheckChecked, CheckNormal } from "@nutui/icons-react";
|
|
28
|
+
import classNames from "classnames";
|
|
28
29
|
import RadioGroup from "./RadioGroup.js";
|
|
29
30
|
import { C as ComponentDefaults } from "./typings.js";
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var RadioContext = React__default.createContext(radioContext);
|
|
31
|
+
import { u as usePropsValue } from "./use-props-value.js";
|
|
32
|
+
var RadioContext = React__default.createContext(null);
|
|
35
33
|
var defaultProps = _objectSpread(_objectSpread({}, ComponentDefaults), {}, {
|
|
36
|
-
className: "",
|
|
37
|
-
style: {},
|
|
38
34
|
disabled: false,
|
|
39
|
-
checked: false,
|
|
40
35
|
shape: "round",
|
|
41
36
|
value: "",
|
|
42
|
-
|
|
43
|
-
icon:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
onChange: function onChange2(e) {
|
|
37
|
+
labelPosition: "right",
|
|
38
|
+
icon: null,
|
|
39
|
+
activeIcon: null,
|
|
40
|
+
onChange: function onChange(checked) {
|
|
47
41
|
}
|
|
48
42
|
});
|
|
49
43
|
var Radio = function Radio2(props) {
|
|
50
|
-
var
|
|
51
|
-
var className = props.className,
|
|
52
|
-
var
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
|
|
44
|
+
var classPrefix = "nut-radio";
|
|
45
|
+
var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props), children = _defaultProps$props.children, className = _defaultProps$props.className, style = _defaultProps$props.style, checked = _defaultProps$props.checked, defaultChecked = _defaultProps$props.defaultChecked, shape = _defaultProps$props.shape, value = _defaultProps$props.value, icon = _defaultProps$props.icon, activeIcon = _defaultProps$props.activeIcon, onChange2 = _defaultProps$props.onChange, others = _objectWithoutProperties(_defaultProps$props, _excluded);
|
|
46
|
+
var labelPosition = others.labelPosition, disabled = others.disabled, rest = _objectWithoutProperties(others, _excluded2);
|
|
47
|
+
var _usePropsValue = usePropsValue({
|
|
48
|
+
value: checked,
|
|
49
|
+
defaultValue: defaultChecked,
|
|
50
|
+
finalValue: false,
|
|
51
|
+
onChange: onChange2
|
|
52
|
+
}), _usePropsValue2 = _slicedToArray(_usePropsValue, 2), checkedStatement = _usePropsValue2[0], setCheckedStatement = _usePropsValue2[1];
|
|
56
53
|
var context = useContext(RadioContext);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
if (context) {
|
|
55
|
+
checkedStatement = context.value === value;
|
|
56
|
+
if (context.labelPosition !== void 0) {
|
|
57
|
+
labelPosition = context.labelPosition;
|
|
58
|
+
}
|
|
59
|
+
if (context.disabled !== void 0) {
|
|
60
|
+
disabled = context.disabled;
|
|
61
|
+
}
|
|
62
|
+
setCheckedStatement = function setCheckedStatement2(value2) {
|
|
63
|
+
if (value2) {
|
|
64
|
+
context.check(props.value === void 0 ? "" : props.value);
|
|
65
|
+
} else {
|
|
66
|
+
context.uncheck();
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
62
70
|
var renderLabel = function renderLabel2() {
|
|
63
71
|
return React__default.createElement("div", {
|
|
64
|
-
className: "".concat(
|
|
72
|
+
className: classNames("".concat(classPrefix, "__label"), _defineProperty({}, "".concat(classPrefix, "__label--disabled"), disabled))
|
|
65
73
|
}, children);
|
|
66
74
|
};
|
|
67
75
|
var renderButton = function renderButton2() {
|
|
76
|
+
var _classNames2;
|
|
68
77
|
return React__default.createElement("div", {
|
|
69
|
-
className: "".concat(
|
|
78
|
+
className: classNames("".concat(classPrefix, "__button"), (_classNames2 = {}, _defineProperty(_classNames2, "".concat(classPrefix, "__button--active"), checkedStatement), _defineProperty(_classNames2, "".concat(classPrefix, "__button--disabled"), disabled), _classNames2))
|
|
70
79
|
}, children);
|
|
71
80
|
};
|
|
72
81
|
var color = function color2() {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
if (checkedStatement) {
|
|
77
|
-
return "nut-radio__icon";
|
|
78
|
-
}
|
|
79
|
-
return "nut-radio__icon--unchecked";
|
|
82
|
+
var _ref;
|
|
83
|
+
return _ref = {}, _defineProperty(_ref, "".concat(classPrefix, "__icon--disable"), disabled), _defineProperty(_ref, "".concat(classPrefix, "__icon"), checkedStatement), _defineProperty(_ref, "".concat(classPrefix, "__icon--unchecked"), !checkedStatement), _ref;
|
|
80
84
|
};
|
|
81
85
|
var renderIcon = function renderIcon2() {
|
|
82
|
-
var icon2 = props.icon,
|
|
83
|
-
if (
|
|
84
|
-
return React__default.isValidElement(
|
|
85
|
-
className: color()
|
|
86
|
+
var icon2 = props.icon, activeIcon2 = props.activeIcon;
|
|
87
|
+
if (checkedStatement) {
|
|
88
|
+
return React__default.isValidElement(activeIcon2) ? React__default.cloneElement(activeIcon2, _objectSpread(_objectSpread({}, activeIcon2.props), {}, {
|
|
89
|
+
className: classNames(color())
|
|
86
90
|
})) : React__default.createElement(CheckChecked, {
|
|
87
|
-
|
|
88
|
-
height: iconSize2,
|
|
89
|
-
className: color()
|
|
91
|
+
className: classNames(color())
|
|
90
92
|
});
|
|
91
93
|
}
|
|
92
94
|
return React__default.isValidElement(icon2) ? React__default.cloneElement(icon2, _objectSpread(_objectSpread({}, icon2.props), {}, {
|
|
93
|
-
|
|
94
|
-
className: color()
|
|
95
|
+
className: classNames(color())
|
|
95
96
|
})) : React__default.createElement(CheckNormal, {
|
|
96
|
-
|
|
97
|
-
height: iconSize2,
|
|
98
|
-
className: color()
|
|
97
|
+
className: classNames(color())
|
|
99
98
|
});
|
|
100
99
|
};
|
|
101
|
-
var
|
|
100
|
+
var reverse = labelPosition === "left";
|
|
102
101
|
var renderRadioItem = function renderRadioItem2() {
|
|
103
102
|
if (shape === "button") {
|
|
104
103
|
return renderButton();
|
|
105
104
|
}
|
|
106
|
-
if (
|
|
105
|
+
if (reverse) {
|
|
107
106
|
return React__default.createElement(React__default.Fragment, null, renderLabel(), renderIcon());
|
|
108
107
|
}
|
|
109
108
|
return React__default.createElement(React__default.Fragment, null, renderIcon(), renderLabel());
|
|
110
109
|
};
|
|
111
110
|
var handleClick = function handleClick2(e) {
|
|
112
|
-
if (
|
|
111
|
+
if (disabled || checkedStatement)
|
|
113
112
|
return;
|
|
114
113
|
setCheckedStatement(!checkedStatement);
|
|
115
|
-
onChange3 && onChange3(e);
|
|
116
|
-
context && context.onChange(valueStatement);
|
|
117
114
|
};
|
|
118
115
|
return React__default.createElement("div", _objectSpread({
|
|
119
|
-
className: "
|
|
116
|
+
className: "".concat(classPrefix, " ").concat(className, " ").concat(reverse ? "".concat(classPrefix, "--reverse") : ""),
|
|
117
|
+
style,
|
|
120
118
|
onClick: handleClick
|
|
121
119
|
}, rest), renderRadioItem());
|
|
122
120
|
};
|
|
123
121
|
Radio.defaultProps = defaultProps;
|
|
124
122
|
Radio.displayName = "NutRadio";
|
|
125
|
-
Radio.
|
|
123
|
+
Radio.Group = RadioGroup;
|
|
126
124
|
export {
|
|
127
125
|
Radio as R,
|
|
128
126
|
RadioContext as a
|
package/dist/locales/base.js
CHANGED
package/dist/locales/en-US.js
CHANGED
package/dist/locales/id-ID.js
CHANGED
package/dist/locales/zh-CN.js
CHANGED
package/dist/locales/zh-TW.js
CHANGED
package/dist/locales/zh-UG.js
CHANGED