diginet-core-ui 1.3.73-beta.3 → 1.3.73-beta.5

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.
@@ -4,7 +4,8 @@
4
4
  import { memo, forwardRef, useRef, useMemo, useImperativeHandle } from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { jsx, css } from '@emotion/core';
7
- import { borderBox, displayBlock, overflowHidden, pointerEventsNone, positionRelative, userSelectNone } from '../../styles/general';
7
+ import { borderBox, displayBlock, overflowHidden, parseHeight, pointerEventsNone, positionRelative, userSelectNone } from '../../styles/general';
8
+ import { classNames } from '../../utils';
8
9
  import theme from '../../theme/settings';
9
10
  const {
10
11
  colors: {
@@ -18,16 +19,24 @@ const {
18
19
  spacing
19
20
  } = theme;
20
21
  const AccordionDetails = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
22
+ action = {},
21
23
  children,
22
24
  className,
23
25
  id,
24
26
  style
25
27
  }, reference) => {
26
28
  const ref = useRef(null);
27
- useImperativeHandle(reference, () => ({
28
- element: ref.current,
29
- instance: {}
30
- }));
29
+ useImperativeHandle(reference, () => {
30
+ const currentRef = ref.current || {};
31
+ currentRef.element = ref.current;
32
+ const _instance = { ...action
33
+ }; // methods
34
+
35
+ _instance.__proto__ = {}; // hidden methods
36
+
37
+ currentRef.instance = _instance;
38
+ return currentRef;
39
+ });
31
40
  return useMemo(() => {
32
41
  return jsx("div", {
33
42
  css: DetailsRootCSS,
@@ -36,15 +45,15 @@ const AccordionDetails = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
36
45
  id: id
37
46
  }, jsx("div", {
38
47
  style: style,
39
- className: ['DGN-UI-Accordion-Details-Content', className].join(' ').trim().replace(/\s+/g, ' ')
48
+ className: classNames('DGN-UI-Accordion-Details-Content', className)
40
49
  }, children));
41
- }, [style, className, children, id]);
50
+ }, [children, className, id, style]);
42
51
  }));
43
52
  const DetailsRootCSS = css`
44
53
  ${displayBlock};
45
54
  ${positionRelative};
46
55
  ${overflowHidden};
47
- height: 0;
56
+ ${parseHeight(0)};
48
57
  transition: height 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
49
58
  .DGN-UI-Accordion-Details-Content {
50
59
  ${borderBox};
@@ -52,8 +61,8 @@ const DetailsRootCSS = css`
52
61
  padding: ${spacing([0, 6, 4, 6])};
53
62
  color: ${main};
54
63
  &.disabled {
55
- ${pointerEventsNone}
56
- ${userSelectNone}
64
+ ${pointerEventsNone};
65
+ ${userSelectNone};
57
66
  }
58
67
  }
59
68
  `;
@@ -5,11 +5,13 @@ import { memo, useRef, forwardRef, Children, cloneElement, useMemo, useImperativ
5
5
  import PropTypes from 'prop-types';
6
6
  import { jsx, css } from '@emotion/core';
7
7
  import { borderRadius4px } from '../../styles/general';
8
+ import classNames from '../../utils/classNames';
8
9
  import theme from '../../theme/settings';
9
10
  const {
10
11
  spacing
11
12
  } = theme;
12
13
  const AccordionGroup = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
14
+ action = {},
13
15
  children,
14
16
  className,
15
17
  collapseOther,
@@ -30,20 +32,27 @@ const AccordionGroup = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
30
32
  }
31
33
  };
32
34
 
33
- useImperativeHandle(reference, () => ({
34
- element: ref.current,
35
- instance: {}
36
- }));
35
+ useImperativeHandle(reference, () => {
36
+ const currentRef = ref.current || {};
37
+ currentRef.element = ref.current;
38
+ const _instance = { ...action
39
+ }; // methods
40
+
41
+ _instance.__proto__ = {}; // hidden methods
42
+
43
+ currentRef.instance = _instance;
44
+ return currentRef;
45
+ });
37
46
  return useMemo(() => {
38
47
  return jsx("div", {
39
48
  css: AccordionGroupRootCSS,
40
49
  ref: ref,
41
50
  style: style,
42
- className: ['DGN-UI-Accordion-Group', className].join(' ').trim().replace(/\s+/g, ' ')
51
+ className: classNames('DGN-UI-Accordion-Group', className)
43
52
  }, Children.map(children, child => child && /*#__PURE__*/cloneElement(child, {
44
53
  onExpand: e => onCollapseOther(e, child.props.onExpand)
45
54
  })));
46
- }, [style, className, children]);
55
+ }, [children, className, collapseOther, style]);
47
56
  }));
48
57
  const AccordionGroupRootCSS = css`
49
58
  ${borderRadius4px};
@@ -6,7 +6,8 @@ import PropTypes from 'prop-types';
6
6
  import { jsx, css } from '@emotion/core';
7
7
  import AccordionContext from './context';
8
8
  import Divider from '../divider';
9
- import { borderRadius4px, displayBlock, positionRelative } from '../../styles/general';
9
+ import { borderRadius4px, displayBlock, parseWidth, positionRelative } from '../../styles/general';
10
+ import classNames from '../../utils/classNames';
10
11
  import theme from '../../theme/settings';
11
12
  const {
12
13
  colors: {
@@ -16,6 +17,7 @@ const {
16
17
  }
17
18
  } = theme;
18
19
  const Accordion = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
20
+ action = {},
19
21
  boxShadow,
20
22
  children,
21
23
  className,
@@ -49,17 +51,24 @@ const Accordion = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
49
51
  });
50
52
  };
51
53
 
52
- useImperativeHandle(reference, () => ({
53
- element: ref.current,
54
- instance: {}
55
- }));
54
+ useImperativeHandle(reference, () => {
55
+ const currentRef = ref.current || {};
56
+ currentRef.element = ref.current;
57
+ const _instance = { ...action
58
+ }; // methods
59
+
60
+ _instance.__proto__ = {}; // hidden methods
61
+
62
+ currentRef.instance = _instance;
63
+ return currentRef;
64
+ });
56
65
  return useMemo(() => {
57
66
  return jsx("div", {
58
67
  id: id,
59
68
  css: AccordionRootCSS,
60
69
  ref: ref,
61
70
  style: style,
62
- className: ['DGN-UI-Accordion', disabled ? 'disabled' : '', boxShadow === true ? 'boxShadow' : '', expandState ? 'expanding' : '', className].join(' ').trim().replace(/\s+/g, ' ')
71
+ className: classNames('DGN-UI-Accordion', disabled && 'disabled', boxShadow === true && 'boxShadow', expandState && 'expanding', className)
63
72
  }, jsx(AccordionContext.Provider, {
64
73
  value: {
65
74
  expanded,
@@ -77,13 +86,13 @@ const Accordion = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
77
86
  display: 'none'
78
87
  }
79
88
  })));
80
- }, [id, disabled, className, style, boxShadow, onClick, children, expanded, onExpand, onCollapse, expandState]);
89
+ }, [boxShadow, children, className, disabled, expanded, id, onClick, onCollapse, onExpand, style, expandState]);
81
90
  }));
82
91
  const AccordionRootCSS = css`
83
92
  ${displayBlock};
84
93
  ${positionRelative};
85
94
  ${borderRadius4px};
86
- width: 100%;
95
+ ${parseWidth('100%')};
87
96
  transition: margin 300ms ease;
88
97
  &.boxShadow {
89
98
  box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.25);
@@ -94,10 +103,10 @@ const AccordionRootCSS = css`
94
103
  }
95
104
  `;
96
105
  Accordion.defaultProps = {
97
- expand: false,
98
- disabled: false,
99
- className: '',
100
106
  boxShadow: true,
107
+ className: '',
108
+ disabled: false,
109
+ expand: false,
101
110
  style: {}
102
111
  };
103
112
  Accordion.propTypes = {
@@ -7,6 +7,7 @@ import { jsx } from '@emotion/core';
7
7
  import { SummaryRootCSS } from './css';
8
8
  import AccordionContext from './context';
9
9
  import { ButtonIcon, Typography } from '..';
10
+ import { classNames } from '../../utils';
10
11
  import theme from '../../theme/settings';
11
12
  const {
12
13
  colors: {
@@ -18,6 +19,7 @@ const {
18
19
  spacing
19
20
  } = theme;
20
21
  const AccordionSummary = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
22
+ action = {},
21
23
  background,
22
24
  children,
23
25
  className,
@@ -113,10 +115,17 @@ const AccordionSummary = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
113
115
  showHideDetailHandler('hide');
114
116
  }
115
117
  }, [expandState]);
116
- useImperativeHandle(reference, () => ({
117
- element: ref.current,
118
- instance: {}
119
- }));
118
+ useImperativeHandle(reference, () => {
119
+ const currentRef = ref.current || {};
120
+ currentRef.element = ref.current;
121
+ const _instance = { ...action
122
+ }; // methods
123
+
124
+ _instance.__proto__ = {}; // hidden methods
125
+
126
+ currentRef.instance = _instance;
127
+ return currentRef;
128
+ });
120
129
  return useMemo(() => {
121
130
  return jsx("div", {
122
131
  id: id,
@@ -125,7 +134,7 @@ const AccordionSummary = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
125
134
  tabIndex: "-1",
126
135
  onClick: _onClick,
127
136
  style: style,
128
- className: ['DGN-UI-Accordion-Summary', disabled ? 'disabled' : '', expandIcon ? expandIconAt : '', expandState ? 'expanding' : '', className].join(' ').trim().replace(/\s+/g, ' ')
137
+ className: classNames('DGN-UI-Accordion-Summary', disabled && 'disabled', expandIcon && expandIconAt, expandState && 'expanding', className)
129
138
  }, jsx("div", {
130
139
  className: 'DGN-UI-Accordion-Summary-Content'
131
140
  }, jsx(Typography, {
@@ -139,7 +148,7 @@ const AccordionSummary = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
139
148
  className: 'Accordion-Icon-Root'
140
149
  }, jsx("div", { ...expandIconProps,
141
150
  ref: expandIconRef,
142
- className: ['Accordion-Icon', collapseIcon ? '' : 'rotate-able', expandIconProps.className ? expandIconProps.className : ''].join(' ').trim().replace(/\s+/g, ' ')
151
+ className: classNames('Accordion-Icon', !collapseIcon && 'rotate-able', expandIconProps === null || expandIconProps === void 0 ? void 0 : expandIconProps.className)
143
152
  }, typeof expandIcon === 'string' ? jsx(ButtonIcon, {
144
153
  viewType: 'ghost',
145
154
  name: expandIcon,
@@ -153,7 +162,7 @@ const AccordionSummary = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
153
162
  }) : jsx("span", {
154
163
  className: 'Accordion-Collapse-Icon effect'
155
164
  }, collapseIcon)))));
156
- }, [id, expandIcon, expandIconAt, className, background, children, collapseIcon, expandIconProps, style, expandState, disabled]);
165
+ }, [background, children, className, collapseIcon, expandIcon, expandIconAt, expandIconProps, id, onClick, style, title, disabled, expanded, expandState, onClickAccordion, onCollapse, onExpand]);
157
166
  }));
158
167
  AccordionSummary.defaultProps = {
159
168
  className: '',
@@ -232,7 +232,7 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
232
232
  img.alt = '';
233
233
 
234
234
  img.onerror = () => {
235
- setSrcState(null);
235
+ setSrcState(defaultSrc);
236
236
  existed[unique] = false;
237
237
  };
238
238
 
@@ -6,9 +6,9 @@ import PropTypes from 'prop-types';
6
6
  import { jsx, css } from '@emotion/core';
7
7
  import { ButtonIcon, Typography } from '../';
8
8
  import Icon from '../../icons';
9
- import { alignCenter, border, borderBox, flexRow, inlineFlex, justifyCenter, positionRelative, userSelectNone, whiteSpaceNoWrap, cursorNotAllowed, positionAbsolute, overflowHidden } from '../../styles/general';
9
+ import { alignCenter, border, borderBox, flexRow, inlineFlex, justifyCenter, positionRelative, userSelectNone, cursorNotAllowed, positionAbsolute, overflowHidden } from '../../styles/general';
10
10
  import { hexToRGBA } from '../../styles/color-helper';
11
- import { useTheme } from '../../theme';
11
+ import { useTheme, useColor as colors } from '../../theme';
12
12
  const {
13
13
  colors: {
14
14
  danger,
@@ -52,9 +52,10 @@ const Chip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
52
52
  const ref = useRef(null);
53
53
  const IconRef = useRef(null);
54
54
  if (!onDbClick && onDoubleClick) onDbClick = onDoubleClick;
55
- const color = colorMap.get(colorProps) || colorProps;
55
+ let color = colorMap.get(colorProps) || colorProps;
56
+ if (colors[color]) color = colors[color];
56
57
  const infoChip = {
57
- color: colorMap.get(colorProps) || colorProps,
58
+ color: color,
58
59
  contentColor: viewType !== 'filled' ? color : white,
59
60
  backgroundColor: viewType !== 'filled' ? white : color,
60
61
  iconSize: iconSizeMap.get(size),
@@ -160,7 +161,6 @@ const ChipLabelCSS = css`
160
161
  ${alignCenter};
161
162
  ${positionRelative};
162
163
  ${userSelectNone};
163
- ${whiteSpaceNoWrap};
164
164
  `;
165
165
 
166
166
  const ChipRootCSS = (onClick, onDbClick, colorProps, info) => css`
@@ -268,7 +268,7 @@ Chip.propTypes = {
268
268
  viewType: PropTypes.oneOf(['ghost', 'outlined', 'filled']),
269
269
 
270
270
  /** color for text or background of Chip */
271
- color: PropTypes.oneOf(['default', 'primary', 'info', 'success', 'warning', 'danger']),
271
+ color: PropTypes.oneOfType([PropTypes.oneOf(['default', 'primary', 'info', 'success', 'warning', 'danger']), PropTypes.string]),
272
272
 
273
273
  /** size of Chip */
274
274
  size: PropTypes.oneOf(['small', 'medium', 'large']),
@@ -1793,17 +1793,17 @@ Attachment.propTypes = {
1793
1793
  /** Class for component. */
1794
1794
  className: PropTypes.string,
1795
1795
 
1796
- /** List attachment:<br />
1797
- * [{<br />
1798
- * &nbsp;&nbsp;&nbsp;&nbsp;"AttachmentID": "ATT2U8O7YPTF1KSNCW3X",<br />
1799
- * &nbsp;&nbsp;&nbsp;&nbsp;"URL": "https://apricot.diginet.com.vn/cdn-dev/file/8a07bee1eeff17a14eee.jpg?path=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmaWxlUGF0aCI6Ii8yMDIwLzA4LzQ0YjNhYjQ4LTMwNGQtNDQ3NC05ZDk0LWNkNGVlMDQwOGNlMy5qcGciLCJmaWxlTmFtZSI6IjhhMDdiZWUxZWVmZjE3YTE0ZWVlLmpwZyIsImZpbGVTaXplIjoyNDg4MzcsImZpbGVUeXBlIjoiaW1hZ2UvanBlZyIsImlhdCI6MTU5ODI0NDMwMiwiZXhwIjo4Nzk5ODI0NDMwMn0.fow6O5fp2z3vieA9gom5RRwQ7xxwBx9_7X2Fe8T2YI0",<br />
1800
- * &nbsp;&nbsp;&nbsp;&nbsp;"FileName": "8a07bee1eeff17a14eee.jpg",<br />
1801
- * &nbsp;&nbsp;&nbsp;&nbsp;"FileSize": 248837,<br />
1802
- * &nbsp;&nbsp;&nbsp;&nbsp;"KeyID": "W39OAD3YGLCWAQKV1D6PGEKNW4RLGVTZTUWLYEVFQ2QG8AOCXW",<br />
1803
- * &nbsp;&nbsp;&nbsp;&nbsp;"CreateUserID": "LEMONADMIN",<br />
1804
- * &nbsp;&nbsp;&nbsp;&nbsp;"CreateDate": "2020-08-24T11:54:04.307Z",<br />
1805
- * &nbsp;&nbsp;&nbsp;&nbsp;"UserName": "Quản trị hệ thống"<br />
1806
- * }, ...]
1796
+ /** List attachment:<br />
1797
+ * [{<br />
1798
+ * &nbsp;&nbsp;&nbsp;&nbsp;"AttachmentID": "ATT2U8O7YPTF1KSNCW3X",<br />
1799
+ * &nbsp;&nbsp;&nbsp;&nbsp;"URL": "https://apricot.diginet.com.vn/cdn-dev/file/8a07bee1eeff17a14eee.jpg?path=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmaWxlUGF0aCI6Ii8yMDIwLzA4LzQ0YjNhYjQ4LTMwNGQtNDQ3NC05ZDk0LWNkNGVlMDQwOGNlMy5qcGciLCJmaWxlTmFtZSI6IjhhMDdiZWUxZWVmZjE3YTE0ZWVlLmpwZyIsImZpbGVTaXplIjoyNDg4MzcsImZpbGVUeXBlIjoiaW1hZ2UvanBlZyIsImlhdCI6MTU5ODI0NDMwMiwiZXhwIjo4Nzk5ODI0NDMwMn0.fow6O5fp2z3vieA9gom5RRwQ7xxwBx9_7X2Fe8T2YI0",<br />
1800
+ * &nbsp;&nbsp;&nbsp;&nbsp;"FileName": "8a07bee1eeff17a14eee.jpg",<br />
1801
+ * &nbsp;&nbsp;&nbsp;&nbsp;"FileSize": 248837,<br />
1802
+ * &nbsp;&nbsp;&nbsp;&nbsp;"KeyID": "W39OAD3YGLCWAQKV1D6PGEKNW4RLGVTZTUWLYEVFQ2QG8AOCXW",<br />
1803
+ * &nbsp;&nbsp;&nbsp;&nbsp;"CreateUserID": "LEMONADMIN",<br />
1804
+ * &nbsp;&nbsp;&nbsp;&nbsp;"CreateDate": "2020-08-24T11:54:04.307Z",<br />
1805
+ * &nbsp;&nbsp;&nbsp;&nbsp;"UserName": "Quản trị hệ thống"<br />
1806
+ * }, ...]
1807
1807
  */
1808
1808
  data: PropTypes.array,
1809
1809
 
@@ -1846,16 +1846,16 @@ Attachment.propTypes = {
1846
1846
  /** Download attached event, if not it will use default. */
1847
1847
  onDownload: PropTypes.func,
1848
1848
 
1849
- /**
1850
- * event when removed file(s)
1851
- *
1852
- * return data: {<br/>
1853
- * &nbsp;&nbsp;&nbsp;&nbsp;attached: [Files] (insist old and all new files )<br/>
1854
- * &nbsp;&nbsp;&nbsp;&nbsp;allNewAttached: [Files]<br/>
1855
- * &nbsp;&nbsp;&nbsp;&nbsp;oldAttached: [Files]<br/>
1856
- * &nbsp;&nbsp;&nbsp;&nbsp;removedAttached: [Files]<br/>
1857
- * &nbsp;&nbsp;&nbsp;&nbsp;element: [NodeList (just removed)]<br/>
1858
- * }
1849
+ /**
1850
+ * event when removed file(s)
1851
+ *
1852
+ * return data: {<br/>
1853
+ * &nbsp;&nbsp;&nbsp;&nbsp;attached: [Files] (insist old and all new files )<br/>
1854
+ * &nbsp;&nbsp;&nbsp;&nbsp;allNewAttached: [Files]<br/>
1855
+ * &nbsp;&nbsp;&nbsp;&nbsp;oldAttached: [Files]<br/>
1856
+ * &nbsp;&nbsp;&nbsp;&nbsp;removedAttached: [Files]<br/>
1857
+ * &nbsp;&nbsp;&nbsp;&nbsp;element: [NodeList (just removed)]<br/>
1858
+ * }
1859
1859
  */
1860
1860
  onRemove: PropTypes.func,
1861
1861
 
@@ -431,11 +431,11 @@ const DateRangePickerV2 = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
431
431
  }
432
432
  }
433
433
 
434
- const trueWidth = width > 320 ? width < 633 ? 633 : width : 320;
434
+ const pickerWidth = window.innerWidth <= 633 ? 300 : 633;
435
435
 
436
- if (left + trueWidth > innerWidth) {
437
- if (innerWidth > trueWidth) {
438
- style.left = (innerWidth - trueWidth) / 2;
436
+ if (left + pickerWidth > innerWidth) {
437
+ if (innerWidth > pickerWidth) {
438
+ style.left = (innerWidth - pickerWidth) / 2;
439
439
  }
440
440
  }
441
441
 
@@ -894,6 +894,9 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
894
894
  value,
895
895
  data
896
896
  });
897
+ } else {
898
+ // Fix lost icon when select same value
899
+ triggerBlur(false);
897
900
  }
898
901
  }
899
902
 
@@ -1086,7 +1089,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
1086
1089
  };
1087
1090
 
1088
1091
  const setSingleValueHandler = (data, keyArr) => {
1089
- const text = keyArr ? renderData(data, keyArr) : typeof renderSelectedItem === 'string' ? data[renderSelectedItem] : data[displayExpr || valueExpr] || data;
1092
+ const text = keyArr ? renderData(data, keyArr) : typeof renderSelectedItem === 'string' ? data[renderSelectedItem] : data[displayExpr] || data[valueExpr] || data;
1090
1093
 
1091
1094
  if (typeof renderSelectedItem === 'function') {
1092
1095
  inputRef.current.innerHTML = '';
@@ -1157,8 +1160,8 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
1157
1160
  return currentRef;
1158
1161
  });
1159
1162
  useEffect(() => {
1160
- setShowClear(clearAble && checkHasValue(valueProp) && !disabled && !readOnly && !loading);
1161
- }, [clearAble, valueProp, disabled, readOnly, loading]);
1163
+ setShowClear(clearAble && checkHasValue(valueProp || defaultValue) && !disabled && !readOnly && !loading);
1164
+ }, [clearAble, valueProp, defaultValue, disabled, readOnly, loading]);
1162
1165
  useEffect(() => {
1163
1166
  if (valueObjectDefault) {
1164
1167
  if (Array.isArray(valueObjectDefault)) {
@@ -1369,7 +1372,7 @@ const Dropdown = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
1369
1372
  if (data) {
1370
1373
  var _displayExpr4;
1371
1374
 
1372
- const mask = (_displayExpr4 = displayExpr) === null || _displayExpr4 === void 0 ? void 0 : _displayExpr4.replace(regexBetween, _ => data[_]);
1375
+ const mask = (data === null || data === void 0 ? void 0 : data[displayExpr]) || ((_displayExpr4 = displayExpr) === null || _displayExpr4 === void 0 ? void 0 : _displayExpr4.replace(regexBetween, _ => data[_]));
1373
1376
  text = mask === null || mask === void 0 ? void 0 : mask.replace(regexInclude, '');
1374
1377
  }
1375
1378
 
@@ -0,0 +1,164 @@
1
+ /** @jsxRuntime classic */
2
+
3
+ /** @jsx jsx */
4
+ import { forwardRef, Fragment, memo, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
5
+ import PropTypes from 'prop-types';
6
+ import { jsx, css, keyframes } from '@emotion/core';
7
+ import OptionWrapper from '../others/option-wrapper';
8
+ import { useIntersection } from '../../utils/intersectionObserver';
9
+ import { classNames } from '../../utils';
10
+ import AvatarDefault from '../../assets/avatar/default.svg';
11
+ import { alignCenter, inlineFlex, overflowHidden, parseWidthHeight, positionRelative } from '../../styles/general';
12
+ const blurKeyframe = keyframes`
13
+ 0% { -webkit-filter: blur(4px);}
14
+ 25% { -webkit-filter: blur(3px);}
15
+ 50% { -webkit-filter: blur(2px);}
16
+ 75% { -webkit-filter: blur(1px);}
17
+ 100% { -webkit-filter: blur(0px);}
18
+ `;
19
+ const Image = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
20
+ action = {},
21
+ alt,
22
+ circular,
23
+ className,
24
+ defaultSrc,
25
+ height,
26
+ id,
27
+ lazyLoading,
28
+ onError,
29
+ src,
30
+ style,
31
+ width
32
+ }, reference) => {
33
+ if (!defaultSrc) defaultSrc = AvatarDefault;
34
+ const ref = useRef(null);
35
+ const [srcState, setSrcState] = useState(src);
36
+ const [isInView, setIsInView] = useState(false);
37
+ const [onLoaded, setOnLoaded] = useState(false);
38
+ useIntersection(ref, () => {
39
+ setIsInView(true);
40
+ });
41
+
42
+ const _ImageCSS = ImageCSS(width, height, circular);
43
+
44
+ useEffect(() => {
45
+ if (src) {
46
+ if (isInView || !lazyLoading) {
47
+ const img = document.createElement('img');
48
+ img.src = src;
49
+ img.alt = '';
50
+
51
+ img.onerror = () => {
52
+ setSrcState(defaultSrc);
53
+ onError === null || onError === void 0 ? void 0 : onError();
54
+ };
55
+
56
+ img.onload = () => {
57
+ setSrcState(src);
58
+ };
59
+ }
60
+ }
61
+ }, [src]);
62
+ useImperativeHandle(reference, () => {
63
+ const currentRef = ref.current || {};
64
+ currentRef.element = ref.current;
65
+ const _instance = { ...action
66
+ }; // methods
67
+
68
+ _instance.__proto__ = {}; // hidden methods
69
+
70
+ currentRef.instance = _instance;
71
+ return currentRef;
72
+ });
73
+
74
+ const renderImage = () => {
75
+ const defaultImage = jsx("img", {
76
+ src: defaultSrc,
77
+ alt: '',
78
+ style: {
79
+ objectFit: 'cover'
80
+ },
81
+ width: width,
82
+ height: height
83
+ });
84
+ const image = jsx(Fragment, null, !onLoaded && defaultImage, jsx("img", {
85
+ css: blurAnimationCSS,
86
+ src: srcState,
87
+ alt: alt || srcState,
88
+ style: {
89
+ objectFit: 'cover'
90
+ },
91
+ onLoad: () => setOnLoaded(true),
92
+ width: width,
93
+ height: height
94
+ }));
95
+
96
+ if (lazyLoading) {
97
+ return isInView ? image : defaultImage;
98
+ } else return image;
99
+ };
100
+
101
+ return useMemo(() => {
102
+ return jsx("div", {
103
+ ref: ref,
104
+ css: _ImageCSS,
105
+ id: id,
106
+ className: classNames('DGN-UI-Image', className),
107
+ style: style
108
+ }, renderImage());
109
+ }, [alt, circular, className, defaultSrc, height, id, lazyLoading, src, style, width, isInView, onLoaded, srcState]);
110
+ }));
111
+
112
+ const ImageCSS = (width, height, circular) => css`
113
+ ${inlineFlex};
114
+ ${positionRelative};
115
+ ${alignCenter};
116
+ ${overflowHidden};
117
+ ${parseWidthHeight(width, height)};
118
+ ${circular && `border-radius: 50%`};
119
+ `;
120
+
121
+ const blurAnimationCSS = css`
122
+ animation: ${blurKeyframe} 1s ease;
123
+ `;
124
+ Image.defaultProps = {
125
+ circular: false,
126
+ className: '',
127
+ height: 200,
128
+ lazyLoading: false,
129
+ style: {},
130
+ width: 200
131
+ };
132
+ Image.propTypes = {
133
+ /** Image description. */
134
+ alt: PropTypes.string,
135
+
136
+ /** If `true`, image is circular.*/
137
+ circular: PropTypes.bool,
138
+
139
+ /** Class for component. */
140
+ className: PropTypes.string,
141
+
142
+ /** Default img when src error. */
143
+ defaultSrc: PropTypes.string,
144
+
145
+ /** Height of component. */
146
+ height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
147
+
148
+ /** If `true`, lazy loading image.*/
149
+ lazyLoading: PropTypes.bool,
150
+
151
+ /** Callback fired when the src is error. */
152
+ onError: PropTypes.func,
153
+
154
+ /** Image path. */
155
+ src: PropTypes.string,
156
+
157
+ /** Style inline of component. */
158
+ style: PropTypes.object,
159
+
160
+ /** Width of component. */
161
+ width: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
162
+ };
163
+ export { Image };
164
+ export default OptionWrapper(Image);
@@ -64,7 +64,9 @@ export { default as Row } from './grid/Row';
64
64
  export { default as Col } from './grid/Col';
65
65
  export { default as Container } from './grid/Container'; //Icon
66
66
 
67
- export { default as Icon } from '../icons/index'; // List
67
+ export { default as Icon } from '../icons/index'; //Image
68
+
69
+ export { default as Image } from './image'; // List
68
70
 
69
71
  export { default as List } from './list/list';
70
72
  export { default as ListItem } from './list/list-item';
@@ -5,16 +5,16 @@ import { memo, useMemo, useRef, forwardRef, useImperativeHandle } from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { jsx, css } from '@emotion/core';
7
7
  import { border, borderBox, displayBlock, overflowAuto, parseWidthHeight, positionRelative } from '../../styles/general';
8
- import { classNames, handleBreakpoints } from '../../utils';
8
+ import { classNames } from '../../utils';
9
9
  import theme from '../../theme/settings';
10
+ import { responsivePaddingCSS } from './header';
10
11
  const {
11
12
  colors: {
12
13
  fill: {
13
14
  'scrollbar-rest': scrollbarRest,
14
15
  'scrollbar-active': scrollbarActive
15
16
  }
16
- },
17
- spacing
17
+ }
18
18
  } = theme;
19
19
  const ModalBody = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
20
20
  action = {},
@@ -63,12 +63,7 @@ const ModalBodyCSS = css`
63
63
  background-color: ${scrollbarActive};
64
64
  }
65
65
  }
66
- ${handleBreakpoints({
67
- xs: 4,
68
- md: 6
69
- }, propValue => {
70
- return `padding: ${spacing([4, propValue])}`;
71
- })}
66
+ ${responsivePaddingCSS};
72
67
  `;
73
68
  ModalBody.defaultProps = {
74
69
  className: '',
@@ -5,11 +5,8 @@ import { memo, useMemo, useRef, forwardRef, useImperativeHandle } from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { jsx, css } from '@emotion/core';
7
7
  import { alignCenter, borderBox, flexRow, justifyEnd, positionRelative } from '../../styles/general';
8
- import theme from '../../theme/settings';
9
- import { classNames, handleBreakpoints } from '../../utils';
10
- const {
11
- spacing
12
- } = theme;
8
+ import { classNames } from '../../utils';
9
+ import { responsivePaddingCSS } from './header';
13
10
  const ModalFooter = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
14
11
  action = {},
15
12
  boxShadow,
@@ -53,12 +50,7 @@ const ModalFooterCSS = boxShadow => css`
53
50
  border-radius: 0px 0px 4px 4px;
54
51
  box-shadow: ${boxShadow};
55
52
  order: 3;
56
- ${handleBreakpoints({
57
- xs: 4,
58
- md: 6
59
- }, propValue => {
60
- return `padding: ${spacing([4, propValue])}`;
61
- })}
53
+ ${responsivePaddingCSS};
62
54
  `;
63
55
 
64
56
  ModalFooter.defaultProps = {