diginet-core-ui 1.3.61-beta.2 → 1.3.61-beta.3

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;
@@ -123,6 +123,7 @@ const MoneyInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
123
123
  convertToWords,
124
124
  prefix,
125
125
  suffix,
126
+ labelProps,
126
127
  ...props
127
128
  }, reference) => {
128
129
  const ref = useRef(null);
@@ -418,7 +419,7 @@ const MoneyInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
418
419
  css: MoneyInputRoot,
419
420
  className: ['DGN-UI-Money-Input', className].join(' ').trim().replace(/\s+/g, ' '),
420
421
  ...props
421
- }, !!label && jsx(Label, {
422
+ }, !!label && jsx(Label, { ...labelProps,
422
423
  required: required,
423
424
  disabled: disabled
424
425
  }, label), jsx(InputBase, {
@@ -548,10 +549,10 @@ MoneyInput.propTypes = {
548
549
  /** style inline of input in MoneyInput component */
549
550
  inputStyle: PropTypes.object,
550
551
 
551
- /** validation value, argument can:<br/>
552
- * * string: the validation rule. Example required.<br/>
553
- * * object: the validation rule insist name, property, message. Example {name: 'min', compareValue: 9, message: 'Error'} or {max: 99}<br/>
554
- * * array: the validation rule list, insist object/string
552
+ /** validation value, argument can:<br/>
553
+ * * string: the validation rule. Example required.<br/>
554
+ * * object: the validation rule insist name, property, message. Example {name: 'min', compareValue: 9, message: 'Error'} or {max: 99}<br/>
555
+ * * array: the validation rule list, insist object/string
555
556
  */
556
557
  validates: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.array, PropTypes.func]),
557
558
 
@@ -564,13 +565,13 @@ MoneyInput.propTypes = {
564
565
  /** on input function */
565
566
  onInput: PropTypes.func,
566
567
 
567
- /**
568
- * on change function, return an object:<br/>
569
- * {<br/>
570
- * &nbsp;&nbsp;&nbsp;&nbsp;value: is a number or null value<br/>
571
- * &nbsp;&nbsp;&nbsp;&nbsp;target.value: value of input<br/>
572
- * &nbsp;&nbsp;&nbsp;&nbsp;...element<br/>
573
- * }
568
+ /**
569
+ * on change function, return an object:<br/>
570
+ * {<br/>
571
+ * &nbsp;&nbsp;&nbsp;&nbsp;value: is a number or null value<br/>
572
+ * &nbsp;&nbsp;&nbsp;&nbsp;target.value: value of input<br/>
573
+ * &nbsp;&nbsp;&nbsp;&nbsp;...element<br/>
574
+ * }
574
575
  */
575
576
  onChange: PropTypes.func,
576
577
 
@@ -581,6 +582,9 @@ MoneyInput.propTypes = {
581
582
  onFocus: PropTypes.func,
582
583
 
583
584
  /** inputRef of MoneyInput component */
584
- inputRef: PropTypes.any
585
+ inputRef: PropTypes.any,
586
+
587
+ /** [Props](https://core.diginet.com.vn/ui/?path=/docs/form-control-text-label) of label. */
588
+ labelProps: PropTypes.object
585
589
  };
586
590
  export default MoneyInput;
@@ -51,7 +51,8 @@ const NumberInput = /*#__PURE__*/forwardRef(({
51
51
  delayOnChange,
52
52
  fixedDecimalDigit,
53
53
  className,
54
- maxDigit
54
+ maxDigit,
55
+ labelProps
55
56
  }, reference) => {
56
57
  inputRef = inputRef || useRef(null);
57
58
  const pos = useRef(null);
@@ -77,13 +78,13 @@ const NumberInput = /*#__PURE__*/forwardRef(({
77
78
  const clamp = (num, min, max) => Math.min(Math.max(num, min), max);
78
79
 
79
80
  if (valueProps || valueProps === 0) valueProps = clamp(valueProps, min, max);
80
- /**
81
- * Convert number to format money
82
- * @param vl {number} - value
83
- * @type {function(*): number}
84
- * @return {string}
85
- * @example 1200300.123 => 1,200,300.123
86
- * @example 1200300,123 => 1.200.300,123
81
+ /**
82
+ * Convert number to format money
83
+ * @param vl {number} - value
84
+ * @type {function(*): number}
85
+ * @return {string}
86
+ * @example 1200300.123 => 1,200,300.123
87
+ * @example 1200300,123 => 1.200.300,123
87
88
  */
88
89
 
89
90
  const parseNumberToMoney = useCallback((vl, isNumber) => {
@@ -117,13 +118,13 @@ const NumberInput = /*#__PURE__*/forwardRef(({
117
118
 
118
119
  return number;
119
120
  }, [decimalSymbol, max, value]);
120
- /**
121
- * Convert money to format number
122
- * @param vl {string} - value
123
- * @type {function(*): number}
124
- * @return {number}
125
- * @example 1,200,300.123 => 1200300.123
126
- * @example 1.200.300,123 => 1200300.123
121
+ /**
122
+ * Convert money to format number
123
+ * @param vl {string} - value
124
+ * @type {function(*): number}
125
+ * @return {number}
126
+ * @example 1,200,300.123 => 1200300.123
127
+ * @example 1.200.300,123 => 1200300.123
127
128
  */
128
129
 
129
130
  const convertMoneyToNumber = useCallback((vl, isNumber) => {
@@ -269,7 +270,7 @@ const NumberInput = /*#__PURE__*/forwardRef(({
269
270
  ref: ref,
270
271
  css: NumberInputRoot,
271
272
  className: ['DGN-UI-NumberInput', className].join(' ').trim().replace(/\s+/g, ' ')
272
- }, !!label && jsx(Label, {
273
+ }, !!label && jsx(Label, { ...labelProps,
273
274
  required: required,
274
275
  disabled: disabled
275
276
  }, label), jsx(InputBase, {
@@ -394,10 +395,10 @@ NumberInput.propTypes = {
394
395
  /** style inline of input in NumberInput component */
395
396
  inputStyle: PropTypes.object,
396
397
 
397
- /** validation value, argument can:<br/>
398
- * * string: the validation rule. Example required.<br/>
399
- * * object: the validation rule insist name, property, message. Example {name: 'min', compareValue: 9, message: 'Error'} or {max: 99}<br/>
400
- * * array: the validation rule list, insist object/string
398
+ /** validation value, argument can:<br/>
399
+ * * string: the validation rule. Example required.<br/>
400
+ * * object: the validation rule insist name, property, message. Example {name: 'min', compareValue: 9, message: 'Error'} or {max: 99}<br/>
401
+ * * array: the validation rule list, insist object/string
401
402
  */
402
403
  validates: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.array, PropTypes.func]),
403
404
 
@@ -435,6 +436,9 @@ NumberInput.propTypes = {
435
436
  className: PropTypes.string,
436
437
 
437
438
  /** max character is number of NumberInput component */
438
- maxDigit: PropTypes.number
439
+ maxDigit: PropTypes.number,
440
+
441
+ /** [Props](https://core.diginet.com.vn/ui/?path=/docs/form-control-text-label) of label. */
442
+ labelProps: PropTypes.object
439
443
  };
440
444
  export default NumberInput;
@@ -35,6 +35,7 @@ const PhoneInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
35
35
  inputRef,
36
36
  inputProps,
37
37
  inputStyle,
38
+ labelProps,
38
39
  error,
39
40
  onChange,
40
41
  onBlur,
@@ -295,7 +296,7 @@ const PhoneInput = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
295
296
  marginBottom: '20px'
296
297
  },
297
298
  ...props
298
- }, jsx(Label, {
299
+ }, jsx(Label, { ...labelProps,
299
300
  required: required,
300
301
  disabled: disabled
301
302
  }, label), jsx(InputBase, {
@@ -396,13 +397,13 @@ PhoneInput.propTypes = {
396
397
  /** on input function */
397
398
  onInput: PropTypes.func,
398
399
 
399
- /**
400
- * on change function. Return a object, example:<br/>
401
- * {<br/>
402
- * &nbsp;&nbsp;&nbsp;&nbsp;target: {value: "(+84) 123 456 789", ...}<br/>
403
- * &nbsp;&nbsp;&nbsp;&nbsp;value: 0123456789<br/>
404
- * &nbsp;&nbsp;&nbsp;&nbsp;countryCode: 84<br/>
405
- * }
400
+ /**
401
+ * on change function. Return a object, example:<br/>
402
+ * {<br/>
403
+ * &nbsp;&nbsp;&nbsp;&nbsp;target: {value: "(+84) 123 456 789", ...}<br/>
404
+ * &nbsp;&nbsp;&nbsp;&nbsp;value: 0123456789<br/>
405
+ * &nbsp;&nbsp;&nbsp;&nbsp;countryCode: 84<br/>
406
+ * }
406
407
  */
407
408
  onChange: PropTypes.func,
408
409
 
@@ -413,6 +414,9 @@ PhoneInput.propTypes = {
413
414
  onFocus: PropTypes.func,
414
415
 
415
416
  /** inputRef of PhoneInput component */
416
- inputRef: PropTypes.any
417
+ inputRef: PropTypes.any,
418
+
419
+ /** [Props](https://core.diginet.com.vn/ui/?path=/docs/form-control-text-label) of label. */
420
+ labelProps: PropTypes.object
417
421
  };
418
422
  export default PhoneInput;
@@ -488,9 +488,9 @@ Popover.propTypes = {
488
488
  /** An HTML element, or a function that returns one. It's used to set the position of the popover. */
489
489
  anchor: PropTypes.oneOfType([PropTypes.instanceOf(Element), PropTypes.func, PropTypes.object, PropTypes.node]),
490
490
 
491
- /**
492
- * This is the point on the anchor where the popover's anchor will attach to.
493
- * Options: vertical: [top, center, bottom]; horizontal: [left, center, right].
491
+ /**
492
+ * This is the point on the anchor where the popover's anchor will attach to.
493
+ * Options: vertical: [top, center, bottom]; horizontal: [left, center, right].
494
494
  */
495
495
  anchorOrigin: PropTypes.shape({
496
496
  horizontal: PropTypes.oneOf(['center', 'left', 'right']),
@@ -509,14 +509,14 @@ Popover.propTypes = {
509
509
  /** If `true`, click outside will close component. */
510
510
  clickOutsideToClose: PropTypes.bool,
511
511
 
512
- /**
513
- * Direction when Popover shown.
514
- * Note: This prop will overwrite anchorOrigin & transformOrigin.
515
- *
516
- * * top: anchorOrigin: { vertical: 'top', horizontal: 'center' }, transformOrigin: { vertical: 'bottom', horizontal: 'center' }
517
- * * left: anchorOrigin: { vertical: 'center', horizontal: 'left' }, transformOrigin: { vertical: 'center', horizontal: 'right' }
518
- * * right: anchorOrigin: { vertical: 'center', horizontal: 'right' }, transformOrigin: { vertical: 'center', horizontal: 'left' }
519
- * * right: anchorOrigin: { vertical: 'bottom', horizontal: 'center' }, transformOrigin: { vertical: 'top', horizontal: 'center' }
512
+ /**
513
+ * Direction when Popover shown.
514
+ * Note: This prop will overwrite anchorOrigin & transformOrigin.
515
+ *
516
+ * * top: anchorOrigin: { vertical: 'top', horizontal: 'center' }, transformOrigin: { vertical: 'bottom', horizontal: 'center' }
517
+ * * left: anchorOrigin: { vertical: 'center', horizontal: 'left' }, transformOrigin: { vertical: 'center', horizontal: 'right' }
518
+ * * right: anchorOrigin: { vertical: 'center', horizontal: 'right' }, transformOrigin: { vertical: 'center', horizontal: 'left' }
519
+ * * right: anchorOrigin: { vertical: 'bottom', horizontal: 'center' }, transformOrigin: { vertical: 'top', horizontal: 'center' }
520
520
  */
521
521
  direction: PropTypes.oneOf(['top', 'left', 'right', 'bottom']),
522
522
 
@@ -532,9 +532,9 @@ Popover.propTypes = {
532
532
  /** Style inline of component. */
533
533
  style: PropTypes.object,
534
534
 
535
- /**
536
- * This is the point on the popover which will attach to the anchor's origin.
537
- * Options: vertical: [top, center, bottom]; horizontal: [left, center, right].
535
+ /**
536
+ * This is the point on the popover which will attach to the anchor's origin.
537
+ * Options: vertical: [top, center, bottom]; horizontal: [left, center, right].
538
538
  */
539
539
  transformOrigin: PropTypes.shape({
540
540
  horizontal: PropTypes.oneOf(['center', 'left', 'right']),
@@ -547,13 +547,13 @@ Popover.propTypes = {
547
547
  /** Config z-index of the component. */
548
548
  zIndex: PropTypes.number,
549
549
 
550
- /**
551
- * ref methods (ref.current.instance.*method*)
552
- *
553
- * * show: Show popover
554
- * * close: Close popover
555
- * * setPosition(element): Set position of popover
556
- * * @param {element} - element
550
+ /**
551
+ * ref methods (ref.current.instance.*method*)
552
+ *
553
+ * * show: Show popover
554
+ * * close: Close popover
555
+ * * setPosition(element): Set position of popover
556
+ * * @param {element} - element
557
557
  */
558
558
  reference: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
559
559
  current: PropTypes.instanceOf(Element)
@@ -70,6 +70,7 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
70
70
  tooltipMaxWidth,
71
71
  viewportPadding,
72
72
  className,
73
+ disabled,
73
74
  ...props
74
75
  }, reference) => {
75
76
  const Id = randomString(6, {
@@ -439,6 +440,7 @@ const Tooltip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
439
440
  };
440
441
 
441
442
  const setOpenTrue = () => {
443
+ if (disabled) return;
442
444
  setOpen(true);
443
445
  };
444
446
 
@@ -540,7 +542,8 @@ Tooltip.defaultProps = {
540
542
  textAlign: 'center',
541
543
  viewportPadding: defaultViewPadding,
542
544
  className: '',
543
- style: {}
545
+ style: {},
546
+ disabled: false
544
547
  };
545
548
  Tooltip.propTypes = {
546
549
  /** alignMode use to set align-items of the tooltip*/
@@ -564,6 +567,9 @@ Tooltip.propTypes = {
564
567
  /** initialize direction of the tooltip */
565
568
  direction: PropTypes.oneOf(['down', 'left', 'right', 'up']),
566
569
 
570
+ /** If `true`, the component is disabled. */
571
+ disabled: PropTypes.bool,
572
+
567
573
  /** distance between the tooltip and the children */
568
574
  distance: PropTypes.number,
569
575
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diginet-core-ui",
3
- "version": "1.3.61-beta.2",
3
+ "version": "1.3.61-beta.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "license": "UNLICENSED",