@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.
Files changed (38) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/esm/Audio.js +5 -5
  3. package/dist/esm/Elevator.js +6 -5
  4. package/dist/esm/Image.js +2 -5
  5. package/dist/esm/ImagePreview.js +9 -9
  6. package/dist/esm/Indicator.js +4 -4
  7. package/dist/esm/Notify.js +35 -46
  8. package/dist/esm/NumberKeyboard.js +137 -195
  9. package/dist/esm/Price.js +22 -23
  10. package/dist/esm/PullToRefresh.js +8 -8
  11. package/dist/esm/Radio.js +2 -0
  12. package/dist/esm/RadioGroup.js +31 -51
  13. package/dist/esm/Swiper.js +100 -111
  14. package/dist/esm/SwiperItem.js +1 -1
  15. package/dist/esm/radio2.js +52 -54
  16. package/dist/locales/base.js +1 -1
  17. package/dist/locales/en-US.js +1 -1
  18. package/dist/locales/id-ID.js +1 -1
  19. package/dist/locales/zh-CN.js +1 -1
  20. package/dist/locales/zh-TW.js +1 -1
  21. package/dist/locales/zh-UG.js +1 -1
  22. package/dist/nutui.react.mjs +718 -742
  23. package/dist/nutui.react.umd.js +717 -741
  24. package/dist/packages/imagepreview/imagepreview.scss +5 -0
  25. package/dist/packages/notify/notify.scss +1 -1
  26. package/dist/packages/numberkeyboard/numberkeyboard.scss +29 -77
  27. package/dist/packages/price/price.scss +8 -0
  28. package/dist/packages/pulltorefresh/pulltorefresh.scss +0 -8
  29. package/dist/packages/radio/radio.scss +13 -32
  30. package/dist/packages/radiogroup/radiogroup.scss +17 -51
  31. package/dist/packages/swiper/swiper.scss +0 -15
  32. package/dist/style.css +1 -1
  33. package/dist/style.mjs +1 -1
  34. package/dist/styles/variables-jmapp.scss +50 -44
  35. package/dist/styles/variables.scss +50 -46
  36. package/dist/types/index.d.ts +64 -80
  37. package/package.json +1 -1
  38. /package/dist/esm/{UserContext3.js → context2.js} +0 -0
@@ -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", "pageContent", "onChange", "initPage", "paginationColor", "paginationVisible", "touchable", "isPreventDefault", "isStopPropagation", "autoPlay", "isCenter", "paginationBgColor"];
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 "./UserContext3.js";
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 "@bem-react/classname";
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
- initPage: 0,
36
+ defaultValue: 0,
38
37
  autoPlay: 0,
39
38
  direction: "horizontal",
40
- paginationColor: "#fff",
41
- paginationBgColor: "#ddd",
42
- paginationVisible: false,
39
+ indicator: false,
43
40
  loop: true,
44
41
  touchable: true,
45
- isPreventDefault: true,
46
- isStopPropagation: true,
47
- isCenter: false,
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, _classNames2;
49
+ var _classNames;
53
50
  var propSwiper = _objectSpread(_objectSpread({}, defaultProps), props);
54
- var children = propSwiper.children, direction = propSwiper.direction, className = propSwiper.className, pageContent = propSwiper.pageContent, onChange = propSwiper.onChange, initPage = propSwiper.initPage, paginationColor = propSwiper.paginationColor, paginationVisible = propSwiper.paginationVisible, touchable = propSwiper.touchable, isPreventDefault = propSwiper.isPreventDefault, isStopPropagation = propSwiper.isStopPropagation, autoPlay = propSwiper.autoPlay, isCenter = propSwiper.isCenter, paginationBgColor = propSwiper.paginationBgColor, rest = _objectWithoutProperties(propSwiper, _excluded);
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 _swiper = useRef({
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, 2), touch = _useState16[0], setTouch = _useState16[1];
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(_swiper.current.autoplayTimer);
112
- _swiper.current.autoplayTimer = null;
108
+ clearTimeout(swiperRef.current.autoplayTimer);
109
+ swiperRef.current.autoplayTimer = null;
113
110
  };
114
- var autoplay = function autoplay2() {
111
+ var startPlay = function startPlay2() {
115
112
  if (propSwiper.autoPlay <= 0 || childCount <= 1)
116
113
  return;
117
114
  stopAutoPlay();
118
- _swiper.current.autoplayTimer = setTimeout(function() {
115
+ swiperRef.current.autoplayTimer = setTimeout(function() {
119
116
  next();
120
- autoplay2();
117
+ startPlay2();
121
118
  }, Number(propSwiper.autoPlay));
122
119
  };
123
- var resettPosition = function resettPosition2() {
124
- _swiper.current.moving = true;
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
- resettPosition();
138
- touchReset();
134
+ resetPosition();
135
+ resetTouchDetails();
139
136
  requestFrame(function() {
140
- requestFrame(function() {
141
- _swiper.current.moving = false;
142
- move({
143
- pace: -1,
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
- resettPosition();
151
- touchReset();
145
+ resetPosition();
146
+ resetTouchDetails();
152
147
  requestFrame(function() {
153
- requestFrame(function() {
154
- _swiper.current.moving = false;
155
- move({
156
- pace: 1,
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
- resettPosition();
164
- touchReset();
156
+ resetPosition();
157
+ resetTouchDetails();
165
158
  requestFrame(function() {
166
- requestFrame(function() {
167
- _swiper.current.moving = false;
168
- var targetIndex;
169
- if (props.loop && childCount === index) {
170
- targetIndex = active === 0 ? 0 : index;
171
- } else {
172
- targetIndex = index % childCount;
173
- }
174
- move({
175
- pace: targetIndex - active,
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 touchReset = function touchReset2() {
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
- touchReset();
247
+ resetTouchDetails();
257
248
  touch.startX = e.touches[0].clientX;
258
249
  touch.startY = e.touches[0].clientY;
259
250
  };
260
- var touchMove = function touchMove2(e) {
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 b = cn("swiper");
271
- var classes = classNames(b(""));
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 (!isCenter) {
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(_swiper.current.moving ? 0 : props.duration, "ms");
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.isPreventDefault)
280
+ if (props.preventDefault)
291
281
  e.preventDefault();
292
- if (props.isStopPropagation)
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
- resettPosition();
289
+ resetPosition();
300
290
  };
301
291
  var onTouchMove = function onTouchMove2(e) {
302
- if (props.touchable && _swiper.current.moving) {
303
- touchMove(e);
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 || !_swiper.current.moving)
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) > +(size / 2).toFixed(2);
305
+ var isShouldMove = Math.abs(speed) > 0.3 || Math.abs(touch.delta) > Number((size / 2).toFixed(2));
316
306
  var pace = 0;
317
- _swiper.current.moving = false;
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
- autoplay();
330
+ startPlay();
341
331
  };
342
332
  useEffect(function() {
343
- _swiper.current.activePagination = (active + childCount) % childCount;
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.initPage;
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 _active = Math.max(Math.min(childCount - 1, active2), 0);
349
- var _width = propSwiper.width ? +propSwiper.width : rect2.width;
350
- var _height = propSwiper.height ? +propSwiper.height : rect2.height;
351
- size = isVertical ? _height : _width;
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(_active);
354
- _swiper.current.moving = true;
343
+ var targetOffset = getOffset(currentIndex);
344
+ swiperRef.current.moving = true;
355
345
  if (ready) {
356
- _swiper.current.moving = false;
346
+ swiperRef.current.moving = false;
357
347
  }
358
348
  setRect(rect2);
359
- setActive(_active);
360
- setWidth(_width);
361
- setHeight(_height);
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
- autoplay();
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
- autoplay();
371
+ startPlay();
382
372
  }, [children]);
383
373
  useEffect(function() {
384
- init();
385
- }, [propSwiper.initPage]);
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 itemStyle = function itemStyle2(index) {
392
+ var getItemStyle = function getItemStyle2(index) {
403
393
  var style = {};
404
- var _direction = propSwiper.direction || direction;
405
- var _size = size;
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(_direction === "horizontal" ? "(".concat(offset2, "px,0,0)") : "(0,".concat(offset2, "px,0)"));
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: "".concat(classes, " ").concat(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: b("item-wrapper"),
434
- style: itemStyle(index),
436
+ className: "".concat(classPrefix, "__item-wrapper"),
437
+ style: getItemStyle(index),
435
438
  key: index
436
439
  }, child);
437
- })), propSwiper.paginationVisible && !("pageContent" in propSwiper) ? React__default.createElement("div", {
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";
@@ -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 "./UserContext3.js";
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 = {
@@ -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", "disabled", "checked", "shape", "textPosition", "value", "icon", "checkedIcon", "iconSize", "onChange"];
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, { useState, useContext, useEffect } from "react";
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
- var radioContext = {
31
- onChange: function onChange(val) {
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
- textPosition: "right",
43
- icon: "check-normal",
44
- checkedIcon: "check-checked",
45
- iconSize: 18,
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 _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props), children = _defaultProps$props.children;
51
- var className = props.className, disabled = props.disabled, checked = props.checked, shape = props.shape, textPosition = props.textPosition, value = props.value, icon = props.icon, checkedIcon = props.checkedIcon, iconSize = props.iconSize, onChange3 = props.onChange, rest = _objectWithoutProperties(props, _excluded);
52
- var componentName = "nut-radio";
53
- var _useState = useState(checked), _useState2 = _slicedToArray(_useState, 2), checkedStatement = _useState2[0], setCheckedStatement = _useState2[1];
54
- var _useState3 = useState(value), _useState4 = _slicedToArray(_useState3, 2), valueStatement = _useState4[0], setValueStatement = _useState4[1];
55
- var _useState5 = useState(disabled), _useState6 = _slicedToArray(_useState5, 2), disabledStatement = _useState6[0], setDisabledStatement = _useState6[1];
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
- useEffect(function() {
58
- setDisabledStatement(disabled);
59
- setValueStatement(value);
60
- setCheckedStatement(checked);
61
- }, [disabled, value, checked]);
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(componentName, "__label ").concat(disabledStatement ? "".concat(componentName, "__label--disabled") : "")
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(componentName, "__button ").concat(!disabledStatement && checkedStatement && "".concat(componentName, "__button--active"), " ").concat(disabledStatement ? "".concat(componentName, "__button--disabled") : "")
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
- if (disabledStatement) {
74
- return "nut-radio__icon--disable";
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, iconSize2 = props.iconSize, checkedIcon2 = props.checkedIcon;
83
- if (!disabledStatement && checkedStatement) {
84
- return React__default.isValidElement(checkedIcon2) ? React__default.cloneElement(checkedIcon2, _objectSpread(_objectSpread({}, checkedIcon2.props), {}, {
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
- width: iconSize2,
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
- size: iconSize2,
94
- className: color()
95
+ className: classNames(color())
95
96
  })) : React__default.createElement(CheckNormal, {
96
- width: iconSize2,
97
- height: iconSize2,
98
- className: color()
97
+ className: classNames(color())
99
98
  });
100
99
  };
101
- var reverseState = textPosition === "left";
100
+ var reverse = labelPosition === "left";
102
101
  var renderRadioItem = function renderRadioItem2() {
103
102
  if (shape === "button") {
104
103
  return renderButton();
105
104
  }
106
- if (reverseState) {
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 (disabledStatement || checkedStatement)
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: "nut-radio ".concat(className, " ").concat(reverseState ? "".concat(componentName, "--reverse") : ""),
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.RadioGroup = RadioGroup;
123
+ Radio.Group = RadioGroup;
126
124
  export {
127
125
  Radio as R,
128
126
  RadioContext as a
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.0.0-alpha.8 Fri May 12 2023 19:08:16 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.9 Wed May 17 2023 18:23:27 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.0.0-alpha.8 Fri May 12 2023 19:08:16 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.9 Wed May 17 2023 18:23:27 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.0.0-alpha.8 Fri May 12 2023 19:08:16 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.9 Wed May 17 2023 18:23:27 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.0.0-alpha.8 Fri May 12 2023 19:08:16 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.9 Wed May 17 2023 18:23:27 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.0.0-alpha.8 Fri May 12 2023 19:08:16 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.9 Wed May 17 2023 18:23:27 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.0.0-alpha.8 Fri May 12 2023 19:08:16 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.9 Wed May 17 2023 18:23:27 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */