@hi-ui/table 4.10.0-alpha.0 → 4.11.0

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 (32) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/lib/cjs/Table.js +3 -2
  3. package/lib/cjs/TableBody.js +4 -2
  4. package/lib/cjs/TableRow.js +1 -0
  5. package/lib/cjs/hooks/use-col-width.js +24 -22
  6. package/lib/cjs/use-table.js +11 -1
  7. package/lib/cjs/utils/index.js +11 -4
  8. package/lib/esm/Table.js +1 -1
  9. package/lib/esm/TableBody.js +4 -2
  10. package/lib/esm/TableRow.js +1 -0
  11. package/lib/esm/hooks/use-col-width.js +22 -20
  12. package/lib/esm/use-table.js +11 -1
  13. package/lib/esm/utils/index.js +11 -4
  14. package/lib/types/types.d.ts +5 -1
  15. package/lib/types/utils/index.d.ts +4 -1
  16. package/package.json +2 -1
  17. package/lib/cjs/packages/ui/radio/lib/esm/Radio.js +0 -100
  18. package/lib/cjs/packages/ui/radio/lib/esm/RadioGroup.js +0 -104
  19. package/lib/cjs/packages/ui/radio/lib/esm/context.js +0 -37
  20. package/lib/cjs/packages/ui/radio/lib/esm/index.js +0 -33
  21. package/lib/cjs/packages/ui/radio/lib/esm/styles/index.scss.js +0 -35
  22. package/lib/cjs/packages/ui/radio/lib/esm/types.js +0 -34
  23. package/lib/cjs/packages/ui/radio/lib/esm/use-radio-group.js +0 -61
  24. package/lib/cjs/packages/ui/radio/lib/esm/use-radio.js +0 -88
  25. package/lib/esm/packages/ui/radio/lib/esm/Radio.js +0 -88
  26. package/lib/esm/packages/ui/radio/lib/esm/RadioGroup.js +0 -92
  27. package/lib/esm/packages/ui/radio/lib/esm/context.js +0 -31
  28. package/lib/esm/packages/ui/radio/lib/esm/index.js +0 -26
  29. package/lib/esm/packages/ui/radio/lib/esm/styles/index.scss.js +0 -23
  30. package/lib/esm/packages/ui/radio/lib/esm/types.js +0 -27
  31. package/lib/esm/packages/ui/radio/lib/esm/use-radio-group.js +0 -56
  32. package/lib/esm/packages/ui/radio/lib/esm/use-radio.js +0 -83
@@ -1,104 +0,0 @@
1
- /** @LICENSE
2
- * @hi-ui/table
3
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
4
- *
5
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */
10
- 'use strict';
11
-
12
- var _typeof = require("@babel/runtime/helpers/typeof");
13
- Object.defineProperty(exports, '__esModule', {
14
- value: true
15
- });
16
- var tslib = require('tslib');
17
- var React = require('react');
18
- var classname = require('@hi-ui/classname');
19
- var env = require('@hi-ui/env');
20
- var useRadioGroup = require('./use-radio-group.js');
21
- var context = require('./context.js');
22
- var types = require('./types.js');
23
- var typeAssertion = require('@hi-ui/type-assertion');
24
- var Radio = require('./Radio.js');
25
- function _interopDefaultCompat(e) {
26
- return e && _typeof(e) === 'object' && 'default' in e ? e : {
27
- 'default': e
28
- };
29
- }
30
- var React__default = /*#__PURE__*/_interopDefaultCompat(React);
31
-
32
- /** @LICENSE
33
- * @hi-ui/radio
34
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/radio#readme
35
- *
36
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
37
- *
38
- * This source code is licensed under the MIT license found in the
39
- * LICENSE file in the root directory of this source tree.
40
- */
41
- var RADIO_GROUP_PREFIX = classname.getPrefixCls('radio-group');
42
- /**
43
- * 单选组合器
44
- */
45
- var RadioGroup = /*#__PURE__*/React.forwardRef(function (_a, ref) {
46
- var _a$prefixCls = _a.prefixCls,
47
- prefixCls = _a$prefixCls === void 0 ? RADIO_GROUP_PREFIX : _a$prefixCls,
48
- className = _a.className,
49
- children = _a.children,
50
- data = _a.data,
51
- _a$type = _a.type,
52
- type = _a$type === void 0 ? types.RadioGroupTypeEnum.DEFAULT : _a$type,
53
- _a$placement = _a.placement,
54
- placement = _a$placement === void 0 ? types.RadioGroupPlacementEnum.HORIZONTAL : _a$placement,
55
- _a$autoWidth = _a.autoWidth,
56
- autoWidth = _a$autoWidth === void 0 ? false : _a$autoWidth,
57
- rest = tslib.__rest(_a, ["prefixCls", "className", "children", "data", "type", "placement", "autoWidth"]);
58
- var _useRadioGroup = useRadioGroup.useRadioGroup(rest),
59
- rootProps = _useRadioGroup.rootProps,
60
- name = _useRadioGroup.name,
61
- value = _useRadioGroup.value,
62
- onChange = _useRadioGroup.onChange,
63
- isChecked = _useRadioGroup.isChecked,
64
- disabled = _useRadioGroup.disabled;
65
- var providedValue = React.useMemo(function () {
66
- return {
67
- name: name,
68
- onChange: onChange,
69
- value: value,
70
- isChecked: isChecked,
71
- disabled: disabled,
72
- type: type,
73
- placement: placement
74
- };
75
- }, [name, onChange, value, isChecked, disabled, type, placement]);
76
- var hasData = typeAssertion.isArrayNonEmpty(data);
77
- // data 优先级大于内嵌式组合
78
- if (hasData) {
79
- children = data.map(function (_ref) {
80
- var id = _ref.id,
81
- disabled = _ref.disabled,
82
- title = _ref.title;
83
- return /*#__PURE__*/React__default["default"].createElement(Radio.Radio, {
84
- key: id,
85
- value: id,
86
- name: name,
87
- disabled: disabled,
88
- checked: isChecked(id),
89
- className: prefixCls + "__item"
90
- }, title);
91
- });
92
- }
93
- var cls = classname.cx(prefixCls, className, prefixCls + "--placement-" + placement, autoWidth && type === types.RadioGroupTypeEnum.BUTTON && prefixCls + "--auto-width", prefixCls + "--type-" + type, hasData && prefixCls + "--data-wrap");
94
- return /*#__PURE__*/React__default["default"].createElement(context.RadioGroupProvider, {
95
- value: providedValue
96
- }, /*#__PURE__*/React__default["default"].createElement("div", Object.assign({
97
- ref: ref,
98
- className: cls
99
- }, rootProps), children));
100
- });
101
- if (env.__DEV__) {
102
- RadioGroup.displayName = 'RadioGroup';
103
- }
104
- exports.RadioGroup = RadioGroup;
@@ -1,37 +0,0 @@
1
- /** @LICENSE
2
- * @hi-ui/table
3
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
4
- *
5
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */
10
- 'use strict';
11
-
12
- Object.defineProperty(exports, '__esModule', {
13
- value: true
14
- });
15
- var React = require('react');
16
-
17
- /** @LICENSE
18
- * @hi-ui/radio
19
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/radio#readme
20
- *
21
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
22
- *
23
- * This source code is licensed under the MIT license found in the
24
- * LICENSE file in the root directory of this source tree.
25
- */
26
- var RadioGroupContext = /*#__PURE__*/React.createContext(null);
27
- var RadioGroupProvider = RadioGroupContext.Provider;
28
- var useRadioGroupContext = function useRadioGroupContext() {
29
- var context = React.useContext(RadioGroupContext);
30
- // 允许 Radio 单独存在,不做检查
31
- // if (!context) {
32
- // throw new Error('The RadioGroupContext context should using in Radio.')
33
- // }
34
- return context;
35
- };
36
- exports.RadioGroupProvider = RadioGroupProvider;
37
- exports.useRadioGroupContext = useRadioGroupContext;
@@ -1,33 +0,0 @@
1
- /** @LICENSE
2
- * @hi-ui/table
3
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
4
- *
5
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */
10
- 'use strict';
11
-
12
- Object.defineProperty(exports, '__esModule', {
13
- value: true
14
- });
15
- require('./styles/index.scss.js');
16
- var Radio$1 = require('./Radio.js');
17
- var RadioGroup = require('./RadioGroup.js');
18
-
19
- /** @LICENSE
20
- * @hi-ui/radio
21
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/radio#readme
22
- *
23
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
24
- *
25
- * This source code is licensed under the MIT license found in the
26
- * LICENSE file in the root directory of this source tree.
27
- */
28
- var Radio = Object.assign(Radio$1.Radio, {
29
- Group: RadioGroup.RadioGroup
30
- });
31
- exports.Radio = Radio$1.Radio;
32
- exports.RadioGroup = RadioGroup.RadioGroup;
33
- exports["default"] = Radio;
@@ -1,35 +0,0 @@
1
- /** @LICENSE
2
- * @hi-ui/table
3
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
4
- *
5
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */
10
- 'use strict';
11
-
12
- var _typeof = require("@babel/runtime/helpers/typeof");
13
- Object.defineProperty(exports, '__esModule', {
14
- value: true
15
- });
16
- var __styleInject__ = require('@hi-ui/style-inject');
17
- function _interopDefaultCompat(e) {
18
- return e && _typeof(e) === 'object' && 'default' in e ? e : {
19
- 'default': e
20
- };
21
- }
22
- var __styleInject____default = /*#__PURE__*/_interopDefaultCompat(__styleInject__);
23
-
24
- /** @LICENSE
25
- * @hi-ui/radio
26
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/radio#readme
27
- *
28
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
29
- *
30
- * This source code is licensed under the MIT license found in the
31
- * LICENSE file in the root directory of this source tree.
32
- */
33
- var css_248z = ".hi-v4-radio {overflow-wrap: break-word;font-size: var(--hi-v4-text-size-md, 0.875rem);line-height: var(--hi-v4-text-lineheight-md, 1.375rem);position: relative;-webkit-box-sizing: border-box;box-sizing: border-box;cursor: pointer;display: -webkit-inline-box;display: -ms-inline-flexbox;display: inline-flex;-webkit-box-align: center;-ms-flex-align: center;align-items: center;vertical-align: middle;}.hi-v4-radio--type-button {height: 32px;padding: 0 12px;color: var(--hi-v4-color-gray-600, #5f6a7a);background: var(--hi-v4-color-gray-100, #f2f4f7);cursor: pointer;-webkit-transition: all var(--hi-v4-motion-duration-normal, 200ms);transition: all var(--hi-v4-motion-duration-normal, 200ms);}.hi-v4-radio--type-button .hi-v4-radio__input {display: none;}.hi-v4-radio--type-button .hi-v4-radio__input:focus + .hi-v4-radio__label {color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));}.hi-v4-radio--type-button .hi-v4-radio__controller {display: none;}.hi-v4-radio--type-button:hover, .hi-v4-radio--type-button[data-checked] {background: var(--hi-v4-color-primary-50, var(--hi-v4-color-brandblue-50, #e2f3fe));color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));}.hi-v4-radio--type-button[data-disabled] {cursor: not-allowed;background: var(--hi-v4-color-gray-200, #ebedf0);color: var(--hi-v4-color-gray-400, #b5bcc7);}.hi-v4-radio--type-button[data-checked].hi-v4-radio--type-button[data-disabled] {background: var(--hi-v4-color-primary-50, var(--hi-v4-color-brandblue-50, #e2f3fe));color: var(--hi-v4-color-primary-300, var(--hi-v4-color-brandblue-300, #70b8ff));}.hi-v4-radio--type-default .hi-v4-radio__input:focus + .hi-v4-radio__controller {border-color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));-webkit-box-shadow: 0 0 0 2px var(--hi-v4-color-primary-100, var(--hi-v4-color-brandblue-100, #bde2ff));box-shadow: 0 0 0 2px var(--hi-v4-color-primary-100, var(--hi-v4-color-brandblue-100, #bde2ff));}.hi-v4-radio--type-default .hi-v4-radio__controller {display: -webkit-box;display: -ms-flexbox;display: flex;-webkit-box-pack: center;-ms-flex-pack: center;justify-content: center;-webkit-box-align: center;-ms-flex-align: center;align-items: center;-webkit-box-orient: horizontal;-webkit-box-direction: normal;-ms-flex-direction: row;flex-direction: row;position: relative;-webkit-box-sizing: border-box;box-sizing: border-box;width: 16px;height: 16px;border: 1px solid var(--hi-v4-color-gray-300, #dfe2e8);border-radius: var(--hi-v4-border-radius-full, 9999px);-webkit-transition: all var(--hi-v4-motion-duration-normal, 200ms);transition: all var(--hi-v4-motion-duration-normal, 200ms);-webkit-box-flex: 0;-ms-flex: none;flex: none;}.hi-v4-radio--type-default .hi-v4-radio__controller::after {position: absolute;top: 0;left: 0;-webkit-box-sizing: border-box;box-sizing: border-box;display: inline-block;width: 14px;height: 14px;content: \"\";background: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));border-radius: var(--hi-v4-border-radius-full, 9999px);opacity: 0;-webkit-transition: all var(--hi-v4-motion-duration-normal, 200ms);transition: all var(--hi-v4-motion-duration-normal, 200ms);-webkit-transform: scale(0);transform: scale(0);}.hi-v4-radio--type-default .hi-v4-radio__label {-webkit-box-sizing: border-box;box-sizing: border-box;-webkit-margin-start: var(--hi-v4-spacing-4, 8px);margin-inline-start: var(--hi-v4-spacing-4, 8px);color: var(--hi-v4-color-gray-700, #1f2733);}.hi-v4-radio--type-default:hover .hi-v4-radio__controller {border-color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));}.hi-v4-radio--type-default[data-checked] .hi-v4-radio__controller {border-color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));background: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));}.hi-v4-radio--type-default[data-checked] .hi-v4-radio__controller::after {opacity: 1;-webkit-transform: scale(0.3);transform: scale(0.3);background-color: var(--hi-v4-color-static-white, #fff);}.hi-v4-radio--type-default[data-checked].hi-v4-radio--type-default[data-disabled] .hi-v4-radio__controller {border-color: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));background: var(--hi-v4-color-primary-500, var(--hi-v4-color-brandblue-500, #237ffa));opacity: 0.4;}.hi-v4-radio--type-default[data-checked].hi-v4-radio--type-default[data-disabled] .hi-v4-radio__controller::after {opacity: 1;-webkit-transform: scale(0.3);transform: scale(0.3);background-color: var(--hi-v4-color-static-white, #fff);}.hi-v4-radio--type-default[data-disabled] {cursor: not-allowed;}.hi-v4-radio--type-default[data-disabled] .hi-v4-radio__controller {border-color: var(--hi-v4-color-gray-300, #dfe2e8);background: var(--hi-v4-color-gray-100, #f2f4f7);}.hi-v4-radio--type-default[data-disabled] .hi-v4-radio__controller::after {background: var(--hi-v4-color-gray-300, #dfe2e8);}.hi-v4-radio--type-default[data-disabled] .hi-v4-radio__label {color: var(--hi-v4-color-gray-500, #929aa6);}.hi-v4-radio-group {position: relative;}.hi-v4-radio-group--data-wrap {display: -webkit-inline-box;display: -ms-inline-flexbox;display: inline-flex;z-index: var(--hi-v4-zindex-normal, 0);}.hi-v4-radio-group--type-button {border-radius: var(--hi-v4-border-radius-md, 4px);overflow: hidden;}.hi-v4-radio-group--type-default.hi-v4-radio-group--data-wrap {gap: var(--hi-v4-spacing-8, 16px);}.hi-v4-radio-group--placement-horizontal.hi-v4-radio-group--data-wrap {-webkit-box-align: center;-ms-flex-align: center;align-items: center;}.hi-v4-radio-group--placement-horizontal.hi-v4-radio-group--auto-width {display: -webkit-box;display: -ms-flexbox;display: flex;}.hi-v4-radio-group--placement-horizontal.hi-v4-radio-group--auto-width .hi-v4-radio--type-button {-webkit-box-flex: 1;-ms-flex: 1 1;flex: 1 1;-webkit-box-pack: center;-ms-flex-pack: center;justify-content: center;}.hi-v4-radio-group--placement-horizontal .hi-v4-radio--type-button::after {content: \"\";background: var(--hi-v4-color-gray-300, #dfe2e8);width: 1px;left: 100%;top: 8px;bottom: 8px;position: absolute;z-index: var(--hi-v4-zindex-absolute, 1);}.hi-v4-radio-group--placement-vertical {-webkit-box-orient: vertical;-webkit-box-direction: normal;-ms-flex-direction: column;flex-direction: column;}.hi-v4-radio-group--placement-vertical .hi-v4-radio--type-button::after {content: \"\";background: var(--hi-v4-color-gray-300, #dfe2e8);height: 1px;left: 8px;right: 8px;top: 100%;position: absolute;z-index: var(--hi-v4-zindex-absolute, 1);}";
34
- __styleInject____default["default"](css_248z);
35
- exports["default"] = css_248z;
@@ -1,34 +0,0 @@
1
- /** @LICENSE
2
- * @hi-ui/table
3
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
4
- *
5
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */
10
- 'use strict';
11
-
12
- Object.defineProperty(exports, '__esModule', {
13
- value: true
14
- });
15
-
16
- /** @LICENSE
17
- * @hi-ui/radio
18
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/radio#readme
19
- *
20
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
21
- *
22
- * This source code is licensed under the MIT license found in the
23
- * LICENSE file in the root directory of this source tree.
24
- */
25
- var RadioGroupPlacementEnum = {
26
- VERTICAL: 'vertical',
27
- HORIZONTAL: 'horizontal'
28
- };
29
- var RadioGroupTypeEnum = {
30
- DEFAULT: 'default',
31
- BUTTON: 'button'
32
- };
33
- exports.RadioGroupPlacementEnum = RadioGroupPlacementEnum;
34
- exports.RadioGroupTypeEnum = RadioGroupTypeEnum;
@@ -1,61 +0,0 @@
1
- /** @LICENSE
2
- * @hi-ui/table
3
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
4
- *
5
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */
10
- 'use strict';
11
-
12
- Object.defineProperty(exports, '__esModule', {
13
- value: true
14
- });
15
- var tslib = require('tslib');
16
- var React = require('react');
17
- var useUncontrolledState = require('@hi-ui/use-uncontrolled-state');
18
-
19
- /** @LICENSE
20
- * @hi-ui/radio
21
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/radio#readme
22
- *
23
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
24
- *
25
- * This source code is licensed under the MIT license found in the
26
- * LICENSE file in the root directory of this source tree.
27
- */
28
- var useRadioGroup = function useRadioGroup(_a) {
29
- var name = _a.name,
30
- valueProp = _a.value,
31
- onChange = _a.onChange,
32
- _a$defaultValue = _a.defaultValue,
33
- defaultValue = _a$defaultValue === void 0 ? '' : _a$defaultValue,
34
- _a$disabled = _a.disabled,
35
- disabled = _a$disabled === void 0 ? false : _a$disabled,
36
- rest = tslib.__rest(_a, ["name", "value", "onChange", "defaultValue", "disabled"]);
37
- var _useUncontrolledState = useUncontrolledState.useUncontrolledState(defaultValue, valueProp, onChange),
38
- value = _useUncontrolledState[0],
39
- tryChangeValue = _useUncontrolledState[1];
40
- var handleChange = React.useCallback(function (value) {
41
- if (disabled) {
42
- return;
43
- }
44
- tryChangeValue(value);
45
- }, [disabled, tryChangeValue]);
46
- var isChecked = React.useCallback(function (valueArg) {
47
- return valueArg === value;
48
- }, [value]);
49
- var rootProps = Object.assign(Object.assign({}, rest), {
50
- role: 'radiogroup'
51
- });
52
- return {
53
- rootProps: rootProps,
54
- value: value,
55
- onChange: handleChange,
56
- name: name,
57
- isChecked: isChecked,
58
- disabled: disabled
59
- };
60
- };
61
- exports.useRadioGroup = useRadioGroup;
@@ -1,88 +0,0 @@
1
- /** @LICENSE
2
- * @hi-ui/table
3
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
4
- *
5
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */
10
- 'use strict';
11
-
12
- Object.defineProperty(exports, '__esModule', {
13
- value: true
14
- });
15
- var tslib = require('tslib');
16
- var React = require('react');
17
- var useUncontrolledState = require('@hi-ui/use-uncontrolled-state');
18
- var domUtils = require('@hi-ui/dom-utils');
19
-
20
- /** @LICENSE
21
- * @hi-ui/radio
22
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/radio#readme
23
- *
24
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
25
- *
26
- * This source code is licensed under the MIT license found in the
27
- * LICENSE file in the root directory of this source tree.
28
- */
29
- var useRadio = function useRadio(_a) {
30
- var nameProp = _a.name,
31
- valueProp = _a.value,
32
- _a$autoFocus = _a.autoFocus,
33
- autoFocus = _a$autoFocus === void 0 ? false : _a$autoFocus,
34
- _a$defaultChecked = _a.defaultChecked,
35
- defaultChecked = _a$defaultChecked === void 0 ? false : _a$defaultChecked,
36
- onChange = _a.onChange,
37
- checkedProp = _a.checked,
38
- _a$readOnly = _a.readOnly,
39
- readOnly = _a$readOnly === void 0 ? false : _a$readOnly,
40
- _a$disabled = _a.disabled,
41
- disabled = _a$disabled === void 0 ? false : _a$disabled,
42
- rest = tslib.__rest(_a, ["name", "value", "autoFocus", "defaultChecked", "onChange", "checked", "readOnly", "disabled"]);
43
- var _useUncontrolledState = useUncontrolledState.useUncontrolledState(defaultChecked, checkedProp, function (_, evt) {
44
- onChange === null || onChange === void 0 ? void 0 : onChange(evt);
45
- }),
46
- checked = _useUncontrolledState[0],
47
- tryChangeChecked = _useUncontrolledState[1];
48
- var nonInteractive = disabled || readOnly;
49
- var handleChange = React.useCallback(function (evt) {
50
- if (nonInteractive) {
51
- // 不可交互,不触发事件的任何默认行为
52
- evt.preventDefault();
53
- return;
54
- }
55
- tryChangeChecked(evt.target.checked, evt);
56
- }, [nonInteractive, tryChangeChecked]);
57
- var getInputProps = React.useCallback(function () {
58
- return {
59
- style: domUtils.hiddenStyle,
60
- type: 'radio',
61
- checked: checked,
62
- disabled: disabled,
63
- readOnly: readOnly,
64
- onChange: handleChange,
65
- autoFocus: autoFocus,
66
- name: nameProp,
67
- value: valueProp
68
- };
69
- }, [nameProp, handleChange, checked, disabled, readOnly, autoFocus, valueProp]);
70
- var state = React.useMemo(function () {
71
- return {
72
- disabled: disabled,
73
- checked: checked,
74
- readOnly: readOnly
75
- };
76
- }, [disabled, checked, readOnly]);
77
- var rootProps = Object.assign(Object.assign({}, rest), {
78
- 'data-disabled': domUtils.setAttrStatus(disabled),
79
- 'data-checked': domUtils.setAttrStatus(checked),
80
- 'data-readonly': domUtils.setAttrStatus(readOnly)
81
- });
82
- return {
83
- state: state,
84
- rootProps: rootProps,
85
- getInputProps: getInputProps
86
- };
87
- };
88
- exports.useRadio = useRadio;
@@ -1,88 +0,0 @@
1
- /** @LICENSE
2
- * @hi-ui/table
3
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
4
- *
5
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */
10
- import { __rest } from 'tslib';
11
- import React__default, { forwardRef } from 'react';
12
- import { getPrefixCls, cx } from '@hi-ui/classname';
13
- import { __DEV__ } from '@hi-ui/env';
14
- import { useRadio } from './use-radio.js';
15
- import { useRadioGroupContext } from './context.js';
16
- import { isNullish } from '@hi-ui/type-assertion';
17
- import { callAllFuncs } from '@hi-ui/func-utils';
18
-
19
- /** @LICENSE
20
- * @hi-ui/radio
21
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/radio#readme
22
- *
23
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
24
- *
25
- * This source code is licensed under the MIT license found in the
26
- * LICENSE file in the root directory of this source tree.
27
- */
28
- var RADIO_PREFIX = getPrefixCls('radio');
29
- /**
30
- * 单选
31
- */
32
- var Radio = /*#__PURE__*/forwardRef(function (_a, ref) {
33
- var _a$prefixCls = _a.prefixCls,
34
- prefixCls = _a$prefixCls === void 0 ? RADIO_PREFIX : _a$prefixCls,
35
- _a$role = _a.role,
36
- role = _a$role === void 0 ? 'radio' : _a$role,
37
- className = _a.className,
38
- children = _a.children,
39
- rest = __rest(_a, ["prefixCls", "role", "className", "children"]);
40
- var groupContext = useRadioGroupContext();
41
- var _ref = groupContext || {},
42
- disabledContext = _ref.disabled,
43
- isCheckedContext = _ref.isChecked,
44
- nameContext = _ref.name,
45
- onChangeContext = _ref.onChange,
46
- _ref$type = _ref.type,
47
- type = _ref$type === void 0 ? 'default' : _ref$type;
48
- var checkedProp = rest.checked,
49
- valueProp = rest.value,
50
- _rest$disabled = rest.disabled,
51
- disabled = _rest$disabled === void 0 ? disabledContext : _rest$disabled,
52
- _rest$name = rest.name,
53
- name = _rest$name === void 0 ? nameContext : _rest$name,
54
- onChangeProp = rest.onChange;
55
- // Group's priority is higher than its own.
56
- var checked = isCheckedContext && !isNullish(valueProp) ? isCheckedContext(valueProp) : checkedProp;
57
- var onChange = onChangeContext && !isNullish(valueProp) ? callAllFuncs(function (evt) {
58
- if (evt.target.checked) {
59
- onChangeContext(valueProp);
60
- }
61
- }, onChangeProp) : onChangeProp;
62
- var _useRadio = useRadio(Object.assign(Object.assign({}, rest), {
63
- disabled: disabled,
64
- name: name,
65
- checked: checked,
66
- onChange: onChange
67
- })),
68
- rootProps = _useRadio.rootProps,
69
- getInputProps = _useRadio.getInputProps;
70
- var inputProps = getInputProps();
71
- var cls = cx(prefixCls, className, prefixCls + "--type-" + type);
72
- return /*#__PURE__*/React__default.createElement("label", Object.assign({
73
- ref: ref,
74
- role: role,
75
- className: cls
76
- }, rootProps), /*#__PURE__*/React__default.createElement("input", Object.assign({}, inputProps, {
77
- tabIndex: 0,
78
- className: prefixCls + "__input"
79
- })), /*#__PURE__*/React__default.createElement("span", {
80
- className: prefixCls + "__controller"
81
- }), children ? /*#__PURE__*/React__default.createElement("span", {
82
- className: prefixCls + "__label"
83
- }, children) : null);
84
- });
85
- if (__DEV__) {
86
- Radio.displayName = 'Radio';
87
- }
88
- export { Radio };
@@ -1,92 +0,0 @@
1
- /** @LICENSE
2
- * @hi-ui/table
3
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
4
- *
5
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */
10
- import { __rest } from 'tslib';
11
- import React__default, { forwardRef, useMemo } from 'react';
12
- import { getPrefixCls, cx } from '@hi-ui/classname';
13
- import { __DEV__ } from '@hi-ui/env';
14
- import { useRadioGroup } from './use-radio-group.js';
15
- import { RadioGroupProvider } from './context.js';
16
- import { RadioGroupTypeEnum, RadioGroupPlacementEnum } from './types.js';
17
- import { isArrayNonEmpty } from '@hi-ui/type-assertion';
18
- import { Radio } from './Radio.js';
19
-
20
- /** @LICENSE
21
- * @hi-ui/radio
22
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/radio#readme
23
- *
24
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
25
- *
26
- * This source code is licensed under the MIT license found in the
27
- * LICENSE file in the root directory of this source tree.
28
- */
29
- var RADIO_GROUP_PREFIX = getPrefixCls('radio-group');
30
- /**
31
- * 单选组合器
32
- */
33
- var RadioGroup = /*#__PURE__*/forwardRef(function (_a, ref) {
34
- var _a$prefixCls = _a.prefixCls,
35
- prefixCls = _a$prefixCls === void 0 ? RADIO_GROUP_PREFIX : _a$prefixCls,
36
- className = _a.className,
37
- children = _a.children,
38
- data = _a.data,
39
- _a$type = _a.type,
40
- type = _a$type === void 0 ? RadioGroupTypeEnum.DEFAULT : _a$type,
41
- _a$placement = _a.placement,
42
- placement = _a$placement === void 0 ? RadioGroupPlacementEnum.HORIZONTAL : _a$placement,
43
- _a$autoWidth = _a.autoWidth,
44
- autoWidth = _a$autoWidth === void 0 ? false : _a$autoWidth,
45
- rest = __rest(_a, ["prefixCls", "className", "children", "data", "type", "placement", "autoWidth"]);
46
- var _useRadioGroup = useRadioGroup(rest),
47
- rootProps = _useRadioGroup.rootProps,
48
- name = _useRadioGroup.name,
49
- value = _useRadioGroup.value,
50
- onChange = _useRadioGroup.onChange,
51
- isChecked = _useRadioGroup.isChecked,
52
- disabled = _useRadioGroup.disabled;
53
- var providedValue = useMemo(function () {
54
- return {
55
- name: name,
56
- onChange: onChange,
57
- value: value,
58
- isChecked: isChecked,
59
- disabled: disabled,
60
- type: type,
61
- placement: placement
62
- };
63
- }, [name, onChange, value, isChecked, disabled, type, placement]);
64
- var hasData = isArrayNonEmpty(data);
65
- // data 优先级大于内嵌式组合
66
- if (hasData) {
67
- children = data.map(function (_ref) {
68
- var id = _ref.id,
69
- disabled = _ref.disabled,
70
- title = _ref.title;
71
- return /*#__PURE__*/React__default.createElement(Radio, {
72
- key: id,
73
- value: id,
74
- name: name,
75
- disabled: disabled,
76
- checked: isChecked(id),
77
- className: prefixCls + "__item"
78
- }, title);
79
- });
80
- }
81
- var cls = cx(prefixCls, className, prefixCls + "--placement-" + placement, autoWidth && type === RadioGroupTypeEnum.BUTTON && prefixCls + "--auto-width", prefixCls + "--type-" + type, hasData && prefixCls + "--data-wrap");
82
- return /*#__PURE__*/React__default.createElement(RadioGroupProvider, {
83
- value: providedValue
84
- }, /*#__PURE__*/React__default.createElement("div", Object.assign({
85
- ref: ref,
86
- className: cls
87
- }, rootProps), children));
88
- });
89
- if (__DEV__) {
90
- RadioGroup.displayName = 'RadioGroup';
91
- }
92
- export { RadioGroup };
@@ -1,31 +0,0 @@
1
- /** @LICENSE
2
- * @hi-ui/table
3
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
4
- *
5
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */
10
- import { useContext, createContext } from 'react';
11
-
12
- /** @LICENSE
13
- * @hi-ui/radio
14
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/radio#readme
15
- *
16
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
17
- *
18
- * This source code is licensed under the MIT license found in the
19
- * LICENSE file in the root directory of this source tree.
20
- */
21
- var RadioGroupContext = /*#__PURE__*/createContext(null);
22
- var RadioGroupProvider = RadioGroupContext.Provider;
23
- var useRadioGroupContext = function useRadioGroupContext() {
24
- var context = useContext(RadioGroupContext);
25
- // 允许 Radio 单独存在,不做检查
26
- // if (!context) {
27
- // throw new Error('The RadioGroupContext context should using in Radio.')
28
- // }
29
- return context;
30
- };
31
- export { RadioGroupProvider, useRadioGroupContext };
@@ -1,26 +0,0 @@
1
- /** @LICENSE
2
- * @hi-ui/table
3
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
4
- *
5
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */
10
- import './styles/index.scss.js';
11
- import { Radio as Radio$1 } from './Radio.js';
12
- import { RadioGroup } from './RadioGroup.js';
13
-
14
- /** @LICENSE
15
- * @hi-ui/radio
16
- * https://github.com/XiaoMi/hiui/tree/master/packages/ui/radio#readme
17
- *
18
- * Copyright (c) HiUI <mi-hiui@xiaomi.com>.
19
- *
20
- * This source code is licensed under the MIT license found in the
21
- * LICENSE file in the root directory of this source tree.
22
- */
23
- var Radio = Object.assign(Radio$1, {
24
- Group: RadioGroup
25
- });
26
- export { Radio$1 as Radio, RadioGroup, Radio as default };