@rescui/collapse 0.5.8 → 0.5.10-RUI-226-Update-card-cn-6e43cc89.60
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/lib/_virtual/index.css.js +12 -7
- package/lib/_virtual/plus.js +106 -0
- package/lib/_virtual/right.js +90 -21
- package/lib/accordion.js +35 -60
- package/lib/collapse.js +80 -111
- package/lib/collapse.p.module.css.js +32 -32
- package/lib/context.js +1 -1
- package/lib/index.css +123 -130
- package/lib/public-api.p.css +32 -20
- package/lib/public-api.pcss +32 -20
- package/lib/use-collapse-state.js +17 -29
- package/package.json +10 -10
- package/lib/_virtual/add-outline.js +0 -37
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
var styles = {
|
|
2
|
-
"icon": "
|
|
3
|
-
"sizeXS": "
|
|
4
|
-
"sizeS": "
|
|
5
|
-
"sizeM": "
|
|
6
|
-
"sizeL": "
|
|
7
|
-
"light": "
|
|
8
|
-
"dark": "
|
|
2
|
+
"icon": "_icon_15yklic_4",
|
|
3
|
+
"sizeXS": "_sizeXS_15yklic_14",
|
|
4
|
+
"sizeS": "_sizeS_15yklic_18",
|
|
5
|
+
"sizeM": "_sizeM_15yklic_22",
|
|
6
|
+
"sizeL": "_sizeL_15yklic_26",
|
|
7
|
+
"light": "_light_15yklic_30",
|
|
8
|
+
"dark": "_dark_15yklic_34",
|
|
9
|
+
"allVariants": "_allVariants_15yklic_48",
|
|
10
|
+
"variant16": "_variant16_15yklic_53",
|
|
11
|
+
"variant20": "_variant20_15yklic_54",
|
|
12
|
+
"variant24": "_variant24_15yklic_55",
|
|
13
|
+
"variant28": "_variant28_15yklic_58"
|
|
9
14
|
};
|
|
10
15
|
export { styles as default };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import _extends from '@babel/runtime-corejs3/helpers/esm/extends';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import cn from 'classnames';
|
|
5
|
+
import styles from './index.css.js';
|
|
6
|
+
const sizeStyles = {
|
|
7
|
+
"xs": styles.sizeXS,
|
|
8
|
+
"s": styles.sizeS,
|
|
9
|
+
"m": styles.sizeM,
|
|
10
|
+
"l": styles.sizeL
|
|
11
|
+
};
|
|
12
|
+
const Size = {
|
|
13
|
+
"xs": "xs",
|
|
14
|
+
"s": "s",
|
|
15
|
+
"m": "m",
|
|
16
|
+
"l": "l"
|
|
17
|
+
};
|
|
18
|
+
const PlusIcon16 = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React.createElement("svg", _extends({
|
|
19
|
+
viewBox: "0 0 16 16"
|
|
20
|
+
}, props, {
|
|
21
|
+
ref: ref
|
|
22
|
+
}), /*#__PURE__*/React.createElement("path", {
|
|
23
|
+
d: "M8 1.75a.75.75 0 0 1 .75.75v4.75h4.75a.75.75 0 0 1 0 1.5H8.75v4.75a.75.75 0 0 1-1.5 0V8.75H2.5a.75.75 0 0 1 0-1.5h4.75V2.5A.75.75 0 0 1 8 1.75"
|
|
24
|
+
})));
|
|
25
|
+
PlusIcon16.displayName = 'PlusIcon16';
|
|
26
|
+
const PlusIcon20 = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React.createElement("svg", _extends({
|
|
27
|
+
viewBox: "0 0 20 20"
|
|
28
|
+
}, props, {
|
|
29
|
+
ref: ref
|
|
30
|
+
}), /*#__PURE__*/React.createElement("path", {
|
|
31
|
+
d: "M10 3a1 1 0 0 1 1 1v5h5a1 1 0 1 1 0 2h-5v5a1 1 0 1 1-2 0v-5H4a1 1 0 1 1 0-2h5V4a1 1 0 0 1 1-1"
|
|
32
|
+
})));
|
|
33
|
+
PlusIcon20.displayName = 'PlusIcon20';
|
|
34
|
+
const PlusIcon24 = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React.createElement("svg", _extends({
|
|
35
|
+
viewBox: "0 0 24 24"
|
|
36
|
+
}, props, {
|
|
37
|
+
ref: ref
|
|
38
|
+
}), /*#__PURE__*/React.createElement("path", {
|
|
39
|
+
d: "M12.5 3A1.5 1.5 0 0 1 14 4.5V10h5.5a1.5 1.5 0 0 1 0 3H14v5.5a1.5 1.5 0 0 1-3 0V13H5.5a1.5 1.5 0 0 1 0-3H11V4.5A1.5 1.5 0 0 1 12.5 3"
|
|
40
|
+
})));
|
|
41
|
+
PlusIcon24.displayName = 'PlusIcon24';
|
|
42
|
+
const PlusIcon28 = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React.createElement("svg", _extends({
|
|
43
|
+
viewBox: "0 0 28 28"
|
|
44
|
+
}, props, {
|
|
45
|
+
ref: ref
|
|
46
|
+
}), /*#__PURE__*/React.createElement("path", {
|
|
47
|
+
d: "M14.5 4A1.5 1.5 0 0 1 16 5.5V12h6.5a1.5 1.5 0 0 1 0 3H16v6.5a1.5 1.5 0 0 1-3 0V15H6.5a1.5 1.5 0 0 1 0-3H13V5.5A1.5 1.5 0 0 1 14.5 4"
|
|
48
|
+
})));
|
|
49
|
+
PlusIcon28.displayName = 'PlusIcon28';
|
|
50
|
+
const PlusIcon = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
51
|
+
let {
|
|
52
|
+
theme,
|
|
53
|
+
size: sizeFromProps = "m",
|
|
54
|
+
className,
|
|
55
|
+
style,
|
|
56
|
+
['data-render-all-sizes']: renderAllSizes = false,
|
|
57
|
+
...props
|
|
58
|
+
} = _ref;
|
|
59
|
+
const size = sizeFromProps in Size ? sizeFromProps : "m";
|
|
60
|
+
const mainProps = { ...props,
|
|
61
|
+
className: cn(styles.icon, styles[theme], sizeStyles[size], renderAllSizes && styles.allVariants, className),
|
|
62
|
+
style: renderAllSizes ? {
|
|
63
|
+
'--rs-icon-ar-width': 28,
|
|
64
|
+
'--rs-icon-ar-height': 28,
|
|
65
|
+
...style
|
|
66
|
+
} : style,
|
|
67
|
+
ref
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
if (renderAllSizes) {
|
|
71
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
72
|
+
viewBox: "0 0 28 28"
|
|
73
|
+
}, mainProps), /*#__PURE__*/React.createElement(PlusIcon16, {
|
|
74
|
+
className: styles.variant16
|
|
75
|
+
}), /*#__PURE__*/React.createElement(PlusIcon20, {
|
|
76
|
+
className: styles.variant20
|
|
77
|
+
}), /*#__PURE__*/React.createElement(PlusIcon24, {
|
|
78
|
+
className: styles.variant24
|
|
79
|
+
}), /*#__PURE__*/React.createElement(PlusIcon28, {
|
|
80
|
+
className: styles.variant28
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (size === Size['xs']) {
|
|
85
|
+
return /*#__PURE__*/React.createElement(PlusIcon16, mainProps);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (size === Size['s']) {
|
|
89
|
+
return /*#__PURE__*/React.createElement(PlusIcon20, mainProps);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (size === Size['m']) {
|
|
93
|
+
return /*#__PURE__*/React.createElement(PlusIcon24, mainProps);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return /*#__PURE__*/React.createElement(PlusIcon28, mainProps);
|
|
97
|
+
});
|
|
98
|
+
PlusIcon.displayName = 'PlusIcon';
|
|
99
|
+
PlusIcon.propTypes = {
|
|
100
|
+
className: PropTypes.string,
|
|
101
|
+
theme: PropTypes.oneOf(["light", "dark"]),
|
|
102
|
+
size: PropTypes.oneOf(["xs", "s", "m", "l"]),
|
|
103
|
+
'data-render-all-sizes': PropTypes.bool,
|
|
104
|
+
style: PropTypes.object
|
|
105
|
+
};
|
|
106
|
+
export { Size, PlusIcon as default };
|
package/lib/_virtual/right.js
CHANGED
|
@@ -1,37 +1,106 @@
|
|
|
1
1
|
import _extends from '@babel/runtime-corejs3/helpers/esm/extends';
|
|
2
|
-
import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/esm/objectWithoutProperties';
|
|
3
2
|
import React from 'react';
|
|
4
3
|
import PropTypes from 'prop-types';
|
|
5
4
|
import cn from 'classnames';
|
|
6
5
|
import styles from './index.css.js';
|
|
7
|
-
|
|
8
|
-
var sizeStyles = {
|
|
6
|
+
const sizeStyles = {
|
|
9
7
|
"xs": styles.sizeXS,
|
|
10
8
|
"s": styles.sizeS,
|
|
11
9
|
"m": styles.sizeM,
|
|
12
10
|
"l": styles.sizeL
|
|
13
11
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
const Size = {
|
|
13
|
+
"xs": "xs",
|
|
14
|
+
"s": "s",
|
|
15
|
+
"m": "m",
|
|
16
|
+
"l": "l"
|
|
17
|
+
};
|
|
18
|
+
const RightIcon16 = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React.createElement("svg", _extends({
|
|
19
|
+
viewBox: "0 0 16 16"
|
|
20
|
+
}, props, {
|
|
21
|
+
ref: ref
|
|
22
|
+
}), /*#__PURE__*/React.createElement("path", {
|
|
23
|
+
d: "M5.97 4.47a.75.75 0 0 0 0 1.06L8.44 8l-2.47 2.47a.75.75 0 1 0 1.06 1.06l3-3a.75.75 0 0 0 0-1.06l-3-3a.75.75 0 0 0-1.06 0"
|
|
24
|
+
})));
|
|
25
|
+
RightIcon16.displayName = 'RightIcon16';
|
|
26
|
+
const RightIcon20 = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React.createElement("svg", _extends({
|
|
27
|
+
viewBox: "0 0 20 20"
|
|
28
|
+
}, props, {
|
|
29
|
+
ref: ref
|
|
30
|
+
}), /*#__PURE__*/React.createElement("path", {
|
|
31
|
+
d: "M7.293 5.293a1 1 0 0 0 0 1.414L10.586 10l-3.293 3.293a1 1 0 1 0 1.414 1.414l4-4a1 1 0 0 0 0-1.414l-4-4a1 1 0 0 0-1.414 0"
|
|
32
|
+
})));
|
|
33
|
+
RightIcon20.displayName = 'RightIcon20';
|
|
34
|
+
const RightIcon24 = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React.createElement("svg", _extends({
|
|
35
|
+
viewBox: "0 0 24 24"
|
|
36
|
+
}, props, {
|
|
37
|
+
ref: ref
|
|
38
|
+
}), /*#__PURE__*/React.createElement("path", {
|
|
39
|
+
d: "M7.94 4.94a1.5 1.5 0 0 0 0 2.12L12.878 12l-4.94 4.94a1.5 1.5 0 0 0 2.122 2.12l6-6a1.5 1.5 0 0 0 0-2.12l-6-6a1.5 1.5 0 0 0-2.122 0"
|
|
40
|
+
})));
|
|
41
|
+
RightIcon24.displayName = 'RightIcon24';
|
|
42
|
+
const RightIcon28 = /*#__PURE__*/React.forwardRef((props, ref) => /*#__PURE__*/React.createElement("svg", _extends({
|
|
43
|
+
viewBox: "0 0 28 28"
|
|
44
|
+
}, props, {
|
|
45
|
+
ref: ref
|
|
46
|
+
}), /*#__PURE__*/React.createElement("path", {
|
|
47
|
+
d: "M9.44 5.94a1.5 1.5 0 0 0 0 2.12L15.378 14l-5.94 5.94a1.5 1.5 0 0 0 2.122 2.12l7-7a1.5 1.5 0 0 0 0-2.12l-7-7a1.5 1.5 0 0 0-2.122 0"
|
|
48
|
+
})));
|
|
49
|
+
RightIcon28.displayName = 'RightIcon28';
|
|
50
|
+
const RightIcon = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
51
|
+
let {
|
|
52
|
+
theme,
|
|
53
|
+
size: sizeFromProps = "m",
|
|
54
|
+
className,
|
|
55
|
+
style,
|
|
56
|
+
['data-render-all-sizes']: renderAllSizes = false,
|
|
57
|
+
...props
|
|
58
|
+
} = _ref;
|
|
59
|
+
const size = sizeFromProps in Size ? sizeFromProps : "m";
|
|
60
|
+
const mainProps = { ...props,
|
|
61
|
+
className: cn(styles.icon, styles[theme], sizeStyles[size], renderAllSizes && styles.allVariants, className),
|
|
62
|
+
style: renderAllSizes ? {
|
|
63
|
+
'--rs-icon-ar-width': 28,
|
|
64
|
+
'--rs-icon-ar-height': 28,
|
|
65
|
+
...style
|
|
66
|
+
} : style,
|
|
67
|
+
ref
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
if (renderAllSizes) {
|
|
71
|
+
return /*#__PURE__*/React.createElement("svg", _extends({
|
|
72
|
+
viewBox: "0 0 28 28"
|
|
73
|
+
}, mainProps), /*#__PURE__*/React.createElement(RightIcon16, {
|
|
74
|
+
className: styles.variant16
|
|
75
|
+
}), /*#__PURE__*/React.createElement(RightIcon20, {
|
|
76
|
+
className: styles.variant20
|
|
77
|
+
}), /*#__PURE__*/React.createElement(RightIcon24, {
|
|
78
|
+
className: styles.variant24
|
|
79
|
+
}), /*#__PURE__*/React.createElement(RightIcon28, {
|
|
80
|
+
className: styles.variant28
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (size === Size['xs']) {
|
|
85
|
+
return /*#__PURE__*/React.createElement(RightIcon16, mainProps);
|
|
86
|
+
}
|
|
19
87
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
88
|
+
if (size === Size['s']) {
|
|
89
|
+
return /*#__PURE__*/React.createElement(RightIcon20, mainProps);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (size === Size['m']) {
|
|
93
|
+
return /*#__PURE__*/React.createElement(RightIcon24, mainProps);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return /*#__PURE__*/React.createElement(RightIcon28, mainProps);
|
|
28
97
|
});
|
|
98
|
+
RightIcon.displayName = 'RightIcon';
|
|
29
99
|
RightIcon.propTypes = {
|
|
30
100
|
className: PropTypes.string,
|
|
31
101
|
theme: PropTypes.oneOf(["light", "dark"]),
|
|
32
|
-
size: PropTypes.oneOf(["xs", "s", "m", "l"])
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
size: "m"
|
|
102
|
+
size: PropTypes.oneOf(["xs", "s", "m", "l"]),
|
|
103
|
+
'data-render-all-sizes': PropTypes.bool,
|
|
104
|
+
style: PropTypes.object
|
|
36
105
|
};
|
|
37
|
-
export { RightIcon as default };
|
|
106
|
+
export { Size, RightIcon as default };
|
package/lib/accordion.js
CHANGED
|
@@ -1,26 +1,10 @@
|
|
|
1
|
-
import "core-js/modules/es.object.to-string.js";
|
|
2
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
|
3
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
4
|
-
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
5
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
6
|
-
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
7
|
-
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
8
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
9
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
|
10
|
-
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
|
11
|
-
var _excluded = ["children", "className", "openedClassName", "size", "mode", "icon", "borderBottom", "disableLeftPadding", "gap", "theme", "value", "onChange"];
|
|
12
|
-
|
|
13
|
-
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
14
|
-
|
|
15
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? Object.defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
16
|
-
|
|
17
1
|
import React, { useState } from 'react';
|
|
18
2
|
import cn from 'classnames';
|
|
19
3
|
import PropTypes from 'prop-types';
|
|
20
4
|
import { useThemeWithUndefined, ThemeProvider } from '@rescui/ui-contexts';
|
|
21
5
|
import { collapseContext } from './context.js';
|
|
22
6
|
import styles from './collapse.p.module.css.js';
|
|
23
|
-
|
|
7
|
+
const GAP_STYLES = {
|
|
24
8
|
0: styles.accordionGap0,
|
|
25
9
|
8: styles.accordionGap8,
|
|
26
10
|
12: styles.accordionGap12,
|
|
@@ -28,38 +12,29 @@ var GAP_STYLES = {
|
|
|
28
12
|
24: styles.accordionGap24,
|
|
29
13
|
32: styles.accordionGap32
|
|
30
14
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
restProps = _objectWithoutProperties(_ref, _excluded);
|
|
52
|
-
|
|
53
|
-
var isControlled = typeof value !== 'undefined';
|
|
54
|
-
var theme = useThemeWithUndefined(themeFromProps);
|
|
55
|
-
|
|
56
|
-
var _useState = useState(isControlled ? value : null),
|
|
57
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
58
|
-
openKey = _useState2[0],
|
|
59
|
-
setActiveKey = _useState2[1];
|
|
15
|
+
const Accordion = /*#__PURE__*/React.forwardRef( // eslint-disable-next-line complexity
|
|
16
|
+
(_ref, ref) => {
|
|
17
|
+
let {
|
|
18
|
+
children,
|
|
19
|
+
className,
|
|
20
|
+
openedClassName,
|
|
21
|
+
size = 'm',
|
|
22
|
+
mode = 'classic',
|
|
23
|
+
icon = 'left-plus',
|
|
24
|
+
borderBottom = false,
|
|
25
|
+
disableLeftPadding = false,
|
|
26
|
+
gap = 0,
|
|
27
|
+
theme: themeFromProps,
|
|
28
|
+
value,
|
|
29
|
+
onChange,
|
|
30
|
+
...restProps
|
|
31
|
+
} = _ref;
|
|
32
|
+
const isControlled = typeof value !== 'undefined';
|
|
33
|
+
const theme = useThemeWithUndefined(themeFromProps);
|
|
34
|
+
const [openKey, setActiveKey] = useState(isControlled ? value : null);
|
|
60
35
|
|
|
61
|
-
|
|
62
|
-
|
|
36
|
+
const toggleActiveKey = key => {
|
|
37
|
+
const activatingKey = key !== openKey ? key : null;
|
|
63
38
|
|
|
64
39
|
if (onChange) {
|
|
65
40
|
onChange(activatingKey);
|
|
@@ -73,23 +48,23 @@ function (_ref, ref) {
|
|
|
73
48
|
openedKey: isControlled ? value : openKey,
|
|
74
49
|
isInAccordion: true,
|
|
75
50
|
isInControlledAccordion: isControlled,
|
|
76
|
-
toggleActiveKey
|
|
77
|
-
setActiveKey
|
|
78
|
-
size
|
|
79
|
-
mode
|
|
80
|
-
icon
|
|
81
|
-
borderBottom
|
|
82
|
-
disableLeftPadding
|
|
83
|
-
openedClassName
|
|
51
|
+
toggleActiveKey,
|
|
52
|
+
setActiveKey,
|
|
53
|
+
size,
|
|
54
|
+
mode,
|
|
55
|
+
icon,
|
|
56
|
+
borderBottom,
|
|
57
|
+
disableLeftPadding,
|
|
58
|
+
openedClassName
|
|
84
59
|
}
|
|
85
60
|
}, /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
86
61
|
theme: theme
|
|
87
|
-
}, /*#__PURE__*/React.createElement("div",
|
|
88
|
-
"data-test": 'accordion'
|
|
89
|
-
|
|
62
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
63
|
+
"data-test": 'accordion',
|
|
64
|
+
...restProps,
|
|
90
65
|
className: cn(styles.accordion, GAP_STYLES[gap], className),
|
|
91
66
|
ref: ref
|
|
92
|
-
}
|
|
67
|
+
}, children)));
|
|
93
68
|
});
|
|
94
69
|
Accordion.displayName = 'Accordion';
|
|
95
70
|
Accordion.propTypes = {
|
package/lib/collapse.js
CHANGED
|
@@ -1,27 +1,10 @@
|
|
|
1
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
2
|
-
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
3
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
4
|
-
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
5
|
-
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
6
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
7
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
|
8
|
-
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
|
9
|
-
var _excluded = ["children", "className", "openedClassName", "size", "mode", "icon", "borderBottom", "disableLeftPadding", "title", "isDefaultOpened", "theme", "itemKey"];
|
|
10
|
-
|
|
11
|
-
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
12
|
-
|
|
13
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? Object.defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
14
|
-
|
|
15
|
-
import "core-js/modules/es.object.to-string.js";
|
|
16
|
-
import "core-js/modules/es.regexp.to-string.js";
|
|
17
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
|
18
1
|
import React, { useRef, useContext, useState, useEffect } from 'react';
|
|
19
2
|
import cn from 'classnames';
|
|
20
3
|
import PropTypes from 'prop-types';
|
|
21
4
|
import { useThemeWithUndefined, ThemeProvider } from '@rescui/ui-contexts';
|
|
22
5
|
import { useResizeObserver } from '@rescui/use-resize-observer';
|
|
23
6
|
import RightIcon from './_virtual/right.js';
|
|
24
|
-
import
|
|
7
|
+
import PlusIcon from './_virtual/plus.js';
|
|
25
8
|
import { collapseContext } from './context.js';
|
|
26
9
|
import { useCollapseState, COLLAPSE_STATES, useStartedClosing } from './use-collapse-state.js';
|
|
27
10
|
import styles from './collapse.p.module.css.js';
|
|
@@ -30,112 +13,97 @@ function getRandId() {
|
|
|
30
13
|
return Math.random().toString(36).substring(7);
|
|
31
14
|
}
|
|
32
15
|
|
|
33
|
-
|
|
16
|
+
const THEME_STYLES = {
|
|
34
17
|
light: styles.themeLight,
|
|
35
18
|
dark: styles.themeDark
|
|
36
19
|
};
|
|
37
|
-
|
|
20
|
+
const SIZE_STYLES = {
|
|
38
21
|
s: styles.sizeS,
|
|
39
22
|
m: styles.sizeM,
|
|
40
23
|
l: styles.sizeL
|
|
41
24
|
};
|
|
42
|
-
|
|
25
|
+
const MODE_STYLES = {
|
|
43
26
|
classic: styles.classic,
|
|
44
27
|
rock: styles.rock,
|
|
45
28
|
clear: styles.clear
|
|
46
29
|
};
|
|
47
|
-
|
|
30
|
+
const ICON_STYLES = {
|
|
48
31
|
'left-plus': styles.iconPlus,
|
|
49
32
|
'right-plus': styles.iconPlus,
|
|
50
33
|
arrow: styles.iconArrow
|
|
51
34
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
restProps = _objectWithoutProperties(_ref, _excluded);
|
|
70
|
-
|
|
35
|
+
const Collapse = /*#__PURE__*/React.forwardRef( // eslint-disable-next-line complexity
|
|
36
|
+
(_ref, ref) => {
|
|
37
|
+
let {
|
|
38
|
+
children,
|
|
39
|
+
className,
|
|
40
|
+
openedClassName: openedClassnameFromProps,
|
|
41
|
+
size: sizeFromProps,
|
|
42
|
+
mode: modeFromProps,
|
|
43
|
+
icon: iconFromProps,
|
|
44
|
+
borderBottom: borderBottomFromProps,
|
|
45
|
+
disableLeftPadding: disableLeftPaddingFromProps,
|
|
46
|
+
title,
|
|
47
|
+
isDefaultOpened = false,
|
|
48
|
+
theme: themeFromProps,
|
|
49
|
+
itemKey,
|
|
50
|
+
...restProps
|
|
51
|
+
} = _ref;
|
|
71
52
|
// using the trick from https://github.com/Yaska/react-use-id-hook/
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
111
|
-
shouldBeOpenedLocal = _useState4[0],
|
|
112
|
-
setShouldBeOpenedLocal = _useState4[1]; // boolean state. ignores CLOSING and OPENING states
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
var shouldBeOpened = isInAccordion ? openedKey === key : shouldBeOpenedLocal; // add CLOSING and OPENING states.
|
|
116
|
-
|
|
117
|
-
var _useCollapseState = useCollapseState({
|
|
118
|
-
shouldBeOpened: shouldBeOpened,
|
|
53
|
+
const {
|
|
54
|
+
current: key
|
|
55
|
+
} = useRef(itemKey ?? getRandId());
|
|
56
|
+
const theme = useThemeWithUndefined(themeFromProps);
|
|
57
|
+
const {
|
|
58
|
+
openedKey,
|
|
59
|
+
isInAccordion,
|
|
60
|
+
isInControlledAccordion,
|
|
61
|
+
toggleActiveKey,
|
|
62
|
+
setActiveKey,
|
|
63
|
+
size: sizeFromContext,
|
|
64
|
+
mode: modeFromContext,
|
|
65
|
+
icon: iconFromContext,
|
|
66
|
+
borderBottom: borderBottomFromContext,
|
|
67
|
+
disableLeftPadding: disableLeftPaddingFromContext,
|
|
68
|
+
openedClassName: openedClassNameFromContext
|
|
69
|
+
} = useContext(collapseContext);
|
|
70
|
+
const size = sizeFromProps ?? sizeFromContext ?? 'm';
|
|
71
|
+
const mode = modeFromProps ?? modeFromContext ?? 'classic';
|
|
72
|
+
const icon = iconFromProps ?? iconFromContext ?? 'left-plus';
|
|
73
|
+
const borderBottom = borderBottomFromProps ?? borderBottomFromContext ?? false;
|
|
74
|
+
const disableLeftPadding = disableLeftPaddingFromProps ?? disableLeftPaddingFromContext ?? false;
|
|
75
|
+
const openedClassName = openedClassnameFromProps ?? openedClassNameFromContext; // height calculations
|
|
76
|
+
|
|
77
|
+
const resizeRef = useRef(null);
|
|
78
|
+
const [height, setHeight] = useState('initial');
|
|
79
|
+
useResizeObserver(resizeRef, entry => setHeight(entry.target.offsetHeight));
|
|
80
|
+
const isHeightCalculated = height !== 'initial'; // this state is ignored in accordion
|
|
81
|
+
|
|
82
|
+
const [shouldBeOpenedLocal, setShouldBeOpenedLocal] = useState(isDefaultOpened); // boolean state. ignores CLOSING and OPENING states
|
|
83
|
+
|
|
84
|
+
const shouldBeOpened = isInAccordion ? openedKey === key : shouldBeOpenedLocal; // add CLOSING and OPENING states.
|
|
85
|
+
|
|
86
|
+
const {
|
|
87
|
+
onAnimationEnd: handleTransitionEnd,
|
|
88
|
+
state: collapseState
|
|
89
|
+
} = useCollapseState({
|
|
90
|
+
shouldBeOpened,
|
|
119
91
|
// because how css transitions work, we shouldn't use OPENING and CLOSING states while height still calculating
|
|
120
92
|
// it also allows us to skip animation on the first renders
|
|
121
93
|
cancelAnimation: !isHeightCalculated
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
var isRightIcon = icon === 'right-plus';
|
|
136
|
-
var Icon = icon === 'arrow' ? RightIcon : AddOutlineIcon;
|
|
137
|
-
|
|
138
|
-
var toggleOpened = function toggleOpened() {
|
|
94
|
+
});
|
|
95
|
+
const isOpening = collapseState === COLLAPSE_STATES.OPENING;
|
|
96
|
+
const isOpened = collapseState === COLLAPSE_STATES.OPEN;
|
|
97
|
+
const isClosing = collapseState === COLLAPSE_STATES.CLOSING;
|
|
98
|
+
const isClosed = collapseState === COLLAPSE_STATES.CLOSE;
|
|
99
|
+
const {
|
|
100
|
+
isStartedClosing,
|
|
101
|
+
contentRef
|
|
102
|
+
} = useStartedClosing(collapseState);
|
|
103
|
+
const isRightIcon = icon === 'right-plus';
|
|
104
|
+
const Icon = icon === 'arrow' ? RightIcon : PlusIcon;
|
|
105
|
+
|
|
106
|
+
const toggleOpened = () => {
|
|
139
107
|
if (toggleActiveKey) {
|
|
140
108
|
toggleActiveKey(key);
|
|
141
109
|
} // this state update does nothing in accordion
|
|
@@ -144,7 +112,7 @@ function (_ref, ref) {
|
|
|
144
112
|
setShouldBeOpenedLocal(!shouldBeOpened);
|
|
145
113
|
};
|
|
146
114
|
|
|
147
|
-
useEffect(
|
|
115
|
+
useEffect(() => {
|
|
148
116
|
// for uncontrolled accordion, tell it that this collapse is opened by default
|
|
149
117
|
if (isInAccordion && !isInControlledAccordion && isDefaultOpened && setActiveKey) {
|
|
150
118
|
setActiveKey(key);
|
|
@@ -152,20 +120,21 @@ function (_ref, ref) {
|
|
|
152
120
|
}, []);
|
|
153
121
|
return /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
154
122
|
theme: theme
|
|
155
|
-
}, /*#__PURE__*/React.createElement("div",
|
|
156
|
-
"data-test": 'collapse'
|
|
157
|
-
|
|
123
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
124
|
+
"data-test": 'collapse',
|
|
125
|
+
...restProps,
|
|
158
126
|
className: cn(className, styles.main, isOpening && styles.opening, isOpened && styles.opened, isClosing && !isStartedClosing && styles.closingTransition, isClosing && styles.closing, isClosed && styles.closed, !isClosed && openedClassName, SIZE_STYLES[size], MODE_STYLES[mode], ICON_STYLES[icon], borderBottom && styles.hasBorderBottom, disableLeftPadding && styles.disableLeftPadding, isRightIcon ? styles.rightIcon : styles.leftIcon, THEME_STYLES[theme]),
|
|
159
127
|
"data-rs-internal": "collapse__collapse",
|
|
160
128
|
ref: ref
|
|
161
|
-
}
|
|
129
|
+
}, /*#__PURE__*/React.createElement("button", {
|
|
162
130
|
type: "button",
|
|
163
131
|
"data-test": 'collapse__button',
|
|
164
132
|
"data-rs-internal": "collapse__button",
|
|
165
133
|
className: styles.button,
|
|
166
134
|
onClick: toggleOpened
|
|
167
135
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
168
|
-
className: styles.icon
|
|
136
|
+
className: styles.icon,
|
|
137
|
+
"data-render-all-sizes": true
|
|
169
138
|
}), /*#__PURE__*/React.createElement("span", {
|
|
170
139
|
className: cn(styles.title),
|
|
171
140
|
"data-rs-internal": "collapse__title"
|