@nutui/nutui-react 2.0.0-alpha.4 → 2.0.0-alpha.5

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.
@@ -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 = ["icon", "iconSize", "label", "className", "checkedIcon", "checked", "defaultChecked", "disabled", "onChange", "indeterminate", "iconClassPrefix", "iconFontClassName", "indeterminateIcon"], _excluded2 = ["textPosition"];
4
+ var _excluded = ["icon", "label", "className", "activeIcon", "checked", "value", "defaultChecked", "disabled", "onChange", "indeterminate", "indeterminateIcon"], _excluded2 = ["labelPosition"];
5
5
  function ownKeys(object, enumerableOnly) {
6
6
  var keys = Object.keys(object);
7
7
  if (Object.getOwnPropertySymbols) {
@@ -25,113 +25,100 @@ function _objectSpread(target) {
25
25
  }
26
26
  import React__default, { createContext, useContext, useState, useEffect } from "react";
27
27
  import { CheckNormal, CheckDisabled, Checked } from "@nutui/icons-react";
28
+ import classNames from "classnames";
28
29
  import CheckboxGroup from "./CheckboxGroup.js";
29
- import { c as cn } from "./bem.js";
30
30
  import { C as ComponentDefaults } from "./typings.js";
31
31
  import { u as usePropsValue } from "./use-props-value.js";
32
32
  var CheckboxGroupContext = createContext(null);
33
33
  var Context = CheckboxGroupContext;
34
34
  var defaultProps = _objectSpread(_objectSpread({}, ComponentDefaults), {}, {
35
35
  disabled: false,
36
- textPosition: "right",
37
- iconSize: 18,
38
- icon: "check-normal",
39
- checkedIcon: "checked",
40
- iconClassPrefix: "nut-icon",
41
- iconFontClassName: "nutui-iconfont",
42
- indeterminateIcon: "check-disabled",
43
- onChange: function onChange(state) {
36
+ labelPosition: "right",
37
+ icon: null,
38
+ activeIcon: null,
39
+ indeterminateIcon: null,
40
+ onChange: function onChange(value) {
44
41
  }
45
42
  });
43
+ var classPrefix = "nut-checkbox";
46
44
  var Checkbox = function Checkbox2(props) {
47
45
  var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props), children = _defaultProps$props.children;
48
- var b = cn("checkbox");
49
- var icon = props.icon, iconSize = props.iconSize, label = props.label, className = props.className, checkedIcon = props.checkedIcon, checked = props.checked, defaultChecked = props.defaultChecked, disabled = props.disabled, onChange2 = props.onChange, indeterminate = props.indeterminate, iconClassPrefix = props.iconClassPrefix, iconFontClassName = props.iconFontClassName, indeterminateIcon = props.indeterminateIcon, others = _objectWithoutProperties(props, _excluded);
50
- var textPosition = others.textPosition, rest = _objectWithoutProperties(others, _excluded2);
46
+ var icon = props.icon, label = props.label, className = props.className, activeIcon = props.activeIcon, checked = props.checked, value = props.value, defaultChecked = props.defaultChecked, disabled = props.disabled, onChange2 = props.onChange, indeterminate = props.indeterminate, indeterminateIcon = props.indeterminateIcon, others = _objectWithoutProperties(props, _excluded);
47
+ var labelPosition = others.labelPosition, rest = _objectWithoutProperties(others, _excluded2);
51
48
  var ctx = useContext(Context);
52
49
  var _usePropsValue = usePropsValue({
53
50
  value: props.checked,
54
51
  defaultValue: props.defaultChecked,
55
52
  finalValue: defaultChecked,
56
53
  onChange: onChange2
57
- }), _usePropsValue2 = _slicedToArray(_usePropsValue, 2), _checked = _usePropsValue2[0], setChecked = _usePropsValue2[1];
54
+ }), _usePropsValue2 = _slicedToArray(_usePropsValue, 2), innerChecked = _usePropsValue2[0], setChecked = _usePropsValue2[1];
58
55
  var _useState = useState(disabled), _useState2 = _slicedToArray(_useState, 2), innerDisabled = _useState2[0], setDisabled = _useState2[1];
59
- var _useState3 = useState(indeterminate), _useState4 = _slicedToArray(_useState3, 2), _indeterminate = _useState4[0], setIndeterminate = _useState4[1];
56
+ var _useState3 = useState(indeterminate), _useState4 = _slicedToArray(_useState3, 2), innerIndeterminate = _useState4[0], setIndeterminate = _useState4[1];
60
57
  useEffect(function() {
61
- !ctx && setChecked(checked);
62
58
  setDisabled(disabled);
59
+ }, [disabled]);
60
+ useEffect(function() {
63
61
  setIndeterminate(indeterminate);
64
- }, [disabled, indeterminate]);
62
+ }, [indeterminate]);
65
63
  if (ctx) {
66
- if (ctx.textPosition !== void 0) {
67
- textPosition = ctx.textPosition;
64
+ if (ctx.labelPosition !== void 0) {
65
+ labelPosition = ctx.labelPosition;
68
66
  }
69
- innerDisabled = ctx.disabled;
70
- _checked = ctx.checkedValue.includes(label);
67
+ innerDisabled = ctx.disabled !== void 0 ? ctx.disabled : innerDisabled;
68
+ innerChecked = ctx.value.includes(value);
71
69
  setChecked = function setChecked2(checked2) {
72
70
  if (ctx.disabled)
73
71
  return;
74
72
  if (checked2)
75
- ctx.check(label);
73
+ ctx.check(value);
76
74
  if (!checked2)
77
- ctx.uncheck(label);
75
+ ctx.uncheck(value);
78
76
  };
79
77
  }
80
78
  var renderIcon = function renderIcon2() {
81
- if (!_checked) {
79
+ if (!innerChecked) {
82
80
  return React__default.isValidElement(icon) ? icon : React__default.createElement(CheckNormal, {
83
- width: iconSize,
84
- height: iconSize,
85
81
  className: color()
86
82
  });
87
83
  }
88
- if (_indeterminate) {
84
+ if (innerIndeterminate) {
89
85
  return React__default.isValidElement(indeterminateIcon) ? indeterminateIcon : React__default.createElement(CheckDisabled, {
90
- width: iconSize,
91
- height: iconSize,
92
86
  className: color()
93
87
  });
94
88
  }
95
- return React__default.isValidElement(checkedIcon) ? checkedIcon : React__default.createElement(Checked, {
96
- width: iconSize,
97
- height: iconSize,
89
+ return React__default.isValidElement(activeIcon) ? activeIcon : React__default.createElement(Checked, {
98
90
  className: color()
99
91
  });
100
92
  };
101
93
  var color = function color2() {
102
94
  if (innerDisabled) {
103
- return "nut-checkbox__icon--disable";
95
+ return "".concat(classPrefix, "__icon--disable");
104
96
  }
105
- if (_checked) {
106
- if (_indeterminate) {
107
- return "nut-checkbox__icon--indeterminate";
97
+ if (innerChecked) {
98
+ if (innerIndeterminate) {
99
+ return "".concat(classPrefix, "__icon--indeterminate");
108
100
  }
109
- return "nut-checkbox__icon";
101
+ return "".concat(classPrefix, "__icon");
110
102
  }
111
- return "nut-checkbox__icon--unchecked";
103
+ return "".concat(classPrefix, "__icon--unchecked");
112
104
  };
113
105
  var renderLabel = function renderLabel2() {
114
106
  return React__default.createElement("span", {
115
- className: "".concat(b("label", {
116
- disabled: innerDisabled
117
- }), " ")
107
+ className: classNames("".concat(classPrefix, "__label "), _defineProperty({}, "".concat(classPrefix, "__label--disabled"), innerDisabled))
118
108
  }, children || label);
119
109
  };
120
110
  var handleClick = function handleClick2() {
121
111
  if (disabled)
122
112
  return;
123
- var latestChecked = !_checked;
113
+ var latestChecked = !innerChecked;
124
114
  if (ctx && ctx.max !== void 0) {
125
- if (latestChecked && ctx.checkedValue.length >= ctx.max)
115
+ if (latestChecked && ctx.value.length >= ctx.max)
126
116
  return;
127
117
  }
128
- onChange2 && onChange2(latestChecked, label || children);
129
118
  setChecked(latestChecked);
130
119
  };
131
120
  return React__default.createElement("div", _objectSpread(_objectSpread({
132
- className: "".concat(b({
133
- reverse: textPosition === "left"
134
- }), " ").concat(className || "")
121
+ className: classNames(classPrefix, className, _defineProperty({}, "".concat(classPrefix, "--reverse"), labelPosition === "left"))
135
122
  }, rest), {}, {
136
123
  onClick: handleClick
137
124
  }), renderIcon(), renderLabel());
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react v2.0.0-alpha.4 Fri May 05 2023 16:13:14 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.5 Wed May 10 2023 14:18:02 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.4 Fri May 05 2023 16:13:14 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.5 Wed May 10 2023 14:18:02 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.4 Fri May 05 2023 16:13:14 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.5 Wed May 10 2023 14:18:02 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.4 Fri May 05 2023 16:13:14 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.5 Wed May 10 2023 14:18:02 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.4 Fri May 05 2023 16:13:14 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.5 Wed May 10 2023 14:18:02 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.4 Fri May 05 2023 16:13:14 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react v2.0.0-alpha.5 Wed May 10 2023 14:18:02 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */