diginet-core-ui 1.3.62 → 1.3.63
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/components/collapse/index.js +83 -43
- package/package.json +1 -1
- package/readme.md +3 -0
|
@@ -1,66 +1,106 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
2
|
|
|
3
3
|
/** @jsx jsx */
|
|
4
|
-
import { memo, useEffect,
|
|
4
|
+
import { forwardRef, memo, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
|
|
5
|
+
import { css, jsx } from '@emotion/core';
|
|
5
6
|
import PropTypes from 'prop-types';
|
|
6
|
-
import {
|
|
7
|
+
import { displayBlock, parseWidthHeight, positionRelative } from '../../styles/general';
|
|
7
8
|
const Collapse = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
8
|
-
open,
|
|
9
9
|
children,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
className,
|
|
11
|
+
id,
|
|
12
|
+
onClosed,
|
|
13
|
+
onOpened,
|
|
14
|
+
open,
|
|
15
|
+
style
|
|
16
|
+
}, reference) => {
|
|
17
|
+
const ref = useRef(null);
|
|
18
|
+
const timer = useRef(null);
|
|
19
|
+
|
|
20
|
+
const _onOpen = () => {
|
|
21
|
+
if (timer.current) {
|
|
22
|
+
clearTimeout(timer.current);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const scrollHeight = ref.current.scrollHeight;
|
|
26
|
+
const duration = Math.min(scrollHeight, 1500);
|
|
27
|
+
ref.current.style.transitionDuration = duration + 'ms';
|
|
28
|
+
ref.current.style.height = scrollHeight + 'px';
|
|
29
|
+
timer.current = setTimeout(() => {
|
|
30
|
+
if (ref.current) {
|
|
31
|
+
ref.current.style.height = 'auto';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
onOpened && onOpened(ref.current);
|
|
35
|
+
}, duration);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const _onClose = () => {
|
|
39
|
+
if (ref.current) {
|
|
40
|
+
if (timer.current) {
|
|
41
|
+
clearTimeout(timer.current);
|
|
42
|
+
}
|
|
15
43
|
|
|
16
|
-
const CollapseRoot = css`
|
|
17
|
-
display: block;
|
|
18
|
-
position: relative;
|
|
19
|
-
width: 100%;
|
|
20
|
-
height: 0;
|
|
21
|
-
transition: height 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
|
|
22
|
-
overflow-y: clip;
|
|
23
|
-
`;
|
|
24
|
-
useEffect(() => {
|
|
25
|
-
if (open) {
|
|
26
44
|
const scrollHeight = ref.current.scrollHeight;
|
|
27
|
-
const duration = Math.min(scrollHeight, 1500);
|
|
28
|
-
ref.current.style.transitionDuration = duration + 'ms';
|
|
29
45
|
ref.current.style.height = scrollHeight + 'px';
|
|
30
|
-
setTimeout(() => {
|
|
46
|
+
timer.current = setTimeout(() => {
|
|
31
47
|
if (ref.current) {
|
|
32
|
-
ref.current.style.height =
|
|
48
|
+
ref.current.style.height = null;
|
|
33
49
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
|
|
51
|
+
onClosed && onClosed(ref.current);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (open) {
|
|
58
|
+
_onOpen();
|
|
59
|
+
} else {
|
|
60
|
+
_onClose();
|
|
45
61
|
}
|
|
46
62
|
}, [open]);
|
|
47
|
-
|
|
63
|
+
useImperativeHandle(reference, () => ({
|
|
64
|
+
element: ref.current,
|
|
65
|
+
instance: {}
|
|
66
|
+
}));
|
|
67
|
+
return useMemo(() => jsx("div", {
|
|
48
68
|
css: CollapseRoot,
|
|
49
69
|
ref: ref,
|
|
50
|
-
|
|
51
|
-
|
|
70
|
+
id: id,
|
|
71
|
+
style: style,
|
|
72
|
+
className: ['DGN-UI-Collapse', className].join(' ').trim().replace(/\s+/g, ' ')
|
|
73
|
+
}, children), [children, className, id, onClosed, onOpened, open, style]);
|
|
52
74
|
}));
|
|
75
|
+
const CollapseRoot = css`
|
|
76
|
+
${displayBlock};
|
|
77
|
+
${positionRelative};
|
|
78
|
+
${parseWidthHeight('100%', 0)};
|
|
79
|
+
transition: height 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
|
|
80
|
+
overflow-y: clip;
|
|
81
|
+
`;
|
|
53
82
|
Collapse.defaultProps = {
|
|
54
|
-
|
|
83
|
+
className: '',
|
|
84
|
+
open: false,
|
|
85
|
+
style: {}
|
|
55
86
|
};
|
|
56
87
|
Collapse.propTypes = {
|
|
57
|
-
/**
|
|
58
|
-
open: PropTypes.bool,
|
|
59
|
-
|
|
60
|
-
/** The element to display in alert like text props (priority) */
|
|
88
|
+
/** The content of the component. */
|
|
61
89
|
children: PropTypes.node,
|
|
62
90
|
|
|
63
|
-
/**
|
|
64
|
-
|
|
91
|
+
/** Class for component. */
|
|
92
|
+
className: PropTypes.string,
|
|
93
|
+
|
|
94
|
+
/** Callback fired when the component closed. */
|
|
95
|
+
onClosed: PropTypes.func,
|
|
96
|
+
|
|
97
|
+
/** Callback fired when the component opened. */
|
|
98
|
+
onOpened: PropTypes.func,
|
|
99
|
+
|
|
100
|
+
/** If `true`, the content is shown. */
|
|
101
|
+
open: PropTypes.bool,
|
|
102
|
+
|
|
103
|
+
/** Style inline of component. */
|
|
104
|
+
style: PropTypes.object
|
|
65
105
|
};
|
|
66
106
|
export default Collapse;
|
package/package.json
CHANGED