diginet-core-ui 1.3.61 → 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.
@@ -1,66 +1,106 @@
1
1
  /** @jsxRuntime classic */
2
2
 
3
3
  /** @jsx jsx */
4
- import { memo, useEffect, useRef, forwardRef } from 'react';
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 { jsx, css } from '@emotion/core';
7
+ import { displayBlock, parseWidthHeight, positionRelative } from '../../styles/general';
7
8
  const Collapse = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
8
- open,
9
9
  children,
10
- ...props
11
- }, ref) => {
12
- if (!ref) {
13
- ref = useRef(null);
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 = 'auto';
48
+ ref.current.style.height = null;
33
49
  }
34
- }, duration);
35
- return () => {
36
- if (ref.current) {
37
- ref.current.style.height = scrollHeight + 'px';
38
- setTimeout(() => {
39
- if (ref.current) {
40
- ref.current.style.height = null;
41
- }
42
- }, 0);
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
- return jsx("div", {
63
+ useImperativeHandle(reference, () => ({
64
+ element: ref.current,
65
+ instance: {}
66
+ }));
67
+ return useMemo(() => jsx("div", {
48
68
  css: CollapseRoot,
49
69
  ref: ref,
50
- ...props
51
- }, children);
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
- open: false
83
+ className: '',
84
+ open: false,
85
+ style: {}
55
86
  };
56
87
  Collapse.propTypes = {
57
- /** expand content if true */
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
- /** any props else */
64
- props: PropTypes.any
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;
@@ -58,7 +58,8 @@ const Radio = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
58
58
  e = {
59
59
  value: value,
60
60
  target: { ...inputRef.current,
61
- checked: true
61
+ checked: true,
62
+ value: value
62
63
  }
63
64
  };
64
65
  if (onChange) onChange(e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diginet-core-ui",
3
- "version": "1.3.61",
3
+ "version": "1.3.63",
4
4
  "description": "The DigiNet core ui",
5
5
  "homepage": "https://diginet.com.vn",
6
6
  "main": "index.js",
package/readme.md CHANGED
@@ -38,7 +38,13 @@ npm test
38
38
  ```
39
39
 
40
40
  ## Changelog
41
- ## 1.3.60
41
+ ## 1.3.63
42
+ - \[Changed\]: Collapse – Add props onClosed, onOpened
43
+
44
+ ## 1.3.62
45
+ - \[Changed\]: Radio – Add value to event target
46
+
47
+ ## 1.3.61
42
48
  - \[Added\]: MenuIcon – MHRM09N1035
43
49
  - \[Fixed\]: Dropdown – Fix bug not support Firefox browser
44
50