diginet-core-ui 1.3.80 → 1.3.81

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.
@@ -27,8 +27,7 @@ const {
27
27
  zIndex: zIndexCORE
28
28
  } = useTheme();
29
29
  const existed = {},
30
- urlAvatar = {},
31
- popupHandler = {};
30
+ urlAvatar = {};
32
31
  const blurKeyframe = keyframes`
33
32
  0% { -webkit-filter: blur(4px);}
34
33
  25% { -webkit-filter: blur(3px);}
@@ -78,6 +77,7 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
78
77
  const ref = useRef(null);
79
78
  const inputRef = useRef(null);
80
79
  const avatarRef = useRef(null);
80
+ const popupRef = useRef(null);
81
81
  const [unique] = useState(randomString(6, {
82
82
  allowNumber: false,
83
83
  allowSymbol: false
@@ -109,12 +109,16 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
109
109
  const reader = new FileReader();
110
110
  if (!checkFileType(file.type, matchType)) {
111
111
  input.target.value = '';
112
- popupHandler[unique].show(wrongTypeError);
112
+ popupRef.current.instance.show({
113
+ description: wrongTypeError
114
+ });
113
115
  return;
114
116
  }
115
117
  if (+maxSize && file.size > maxSize * 1024 ** 2) {
116
118
  input.target.value = '';
117
- popupHandler[unique].show(maxSizeError);
119
+ popupRef.current.instance.show({
120
+ description: maxSizeError
121
+ });
118
122
  return;
119
123
  }
120
124
  reader.onload = e => {
@@ -295,11 +299,8 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
295
299
  }, jsx("div", {
296
300
  css: MoreInfoCSS
297
301
  }, typeof data === 'function' ? data() : renderData())), !disabled && !readOnly && jsx(Popup, {
298
- getPopup: func => popupHandler[unique] = func,
299
- type: 'info',
300
- title: maxSizeError,
301
- icon: 'danger',
302
- fullScreen: true
302
+ ref: popupRef,
303
+ type: 'danger'
303
304
  }));
304
305
  }, [actionIconHeight, actionIconWidth, allowEdit, clearAble, data, defaultSrc, direction, disabled, height, hoverAble, lazyLoading, matchType, maxSize, maxSizeError, outlined, readOnly, width, isInView, onLoaded, srcState, viewAvatar, viewMoreInfo]);
305
306
  }));
@@ -11,7 +11,7 @@ import Icon from "../../icons";
11
11
  import Ripple from "./ripple-effect";
12
12
  import { getClassNameFromColor, getRippleColor } from '.';
13
13
  import CircularProgress from "../progress/circular";
14
- import { alignCenter, backgroundTransparent, border, borderBox, borderNone, borderRadius4px, borderRadius50, cursorPointer, flexRow, inlineFlex, justifyCenter, noBorder, outlineNone, parseMinWidthHeight, parseWidthHeight, pointerEventsNone, positionRelative, userSelectNone } from "../../styles/general";
14
+ import { alignCenter, backgroundTransparent, border, borderBox, borderNone, borderRadius4px, borderRadius50, cursorPointer, flexRow, inlineFlex, justifyCenter, outlineNone, parseMinWidthHeight, parseWidthHeight, pointerEventsNone, positionRelative, userSelectNone } from "../../styles/general";
15
15
  import { useColor as colors, useTheme } from "../../theme";
16
16
  const {
17
17
  colors: {
@@ -47,6 +47,9 @@ const sizeMap = new Map([['tiny', {
47
47
  }], ['giant', {
48
48
  buttonSize: '56px',
49
49
  iconSize: '40px'
50
+ }], ['extraGiant', {
51
+ buttonSize: '96px',
52
+ iconSize: '56px'
50
53
  }]]);
51
54
  const iconColorMap = new Map([['Close', semanticDanger], ['Cancel', semanticDanger], ['Approval', semanticSuccess], ['Delete', semanticWarning], ['Trash', semanticWarning], ['Edit', semanticInfo], ['EditV2', semanticInfo], ['View', semanticInfo]]);
52
55
  const alphaArr = {
@@ -239,7 +242,7 @@ const ButtonRootCSS = (circular, colorHover, color, name) => css`
239
242
  }
240
243
  }
241
244
  &.text {
242
- ${noBorder};
245
+ ${borderNone};
243
246
  ${backgroundTransparent};
244
247
  color: ${color};
245
248
  &.button-icon--loading {
@@ -266,7 +269,7 @@ const ButtonRootCSS = (circular, colorHover, color, name) => css`
266
269
  }
267
270
  &.ghost {
268
271
  ${backgroundTransparent};
269
- ${noBorder};
272
+ ${borderNone};
270
273
  color: ${color};
271
274
  &.loading,
272
275
  &:hover,
@@ -326,7 +329,7 @@ ButtonIcon.propTypes = {
326
329
  * * large (button 48px, icon 32px)
327
330
  * * giant (button 56px, icon 40px)
328
331
  * */
329
- size: PropTypes.oneOf(['tiny', 'small', 'medium', 'large', 'giant']),
332
+ size: PropTypes.oneOf(['tiny', 'small', 'medium', 'large', 'giant', 'extraGiant']),
330
333
  /** Style inline of component. */
331
334
  style: PropTypes.object,
332
335
  /** If `true`, icon has view box. */
@@ -1,17 +1,15 @@
1
1
  /** @jsxRuntime classic */
2
2
  /** @jsx jsx */
3
3
  import { css, jsx } from '@emotion/core';
4
+ import { CircularProgress, Icon, Typography } from "./..";
5
+ import OptionWrapper from "../others/option-wrapper";
4
6
  import PropTypes from 'prop-types';
5
- import { forwardRef, memo, useImperativeHandle, useMemo, useRef } from 'react';
6
- import { Typography } from "../";
7
- import Icon from "../../icons";
7
+ import { forwardRef, memo, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
8
8
  import { detectColor, fade, hexToRGBA, hslToRgb, isColor, isColorName, rgbaToHexA, rgbToHex } from "../../styles/color-helper";
9
9
  import * as allColors from "../../styles/colors";
10
- import { alignCenter, backgroundTransparent, border, borderBox, borderNone, borderRadius4px, cursorPointer, flexRow, inlineFlex, justifyCenter, noBorder, noMargin, noPadding, outlineNone, overflowHidden, parseHeight, parseMinHeight, parseMinWidth, parseMinWidthHeight, parseWidthHeight, pointerEventsNone, positionRelative, userSelectNone } from "../../styles/general";
10
+ import { alignCenter, backgroundTransparent, border, borderBox, borderNone, borderRadius4px, cursorPointer, flexRow, inlineFlex, justifyCenter, outlineNone, overflowHidden, parseHeight, parseMinHeight, parseMinWidth, parseMinWidthHeight, parseWidthHeight, pointerEventsNone, positionRelative, userSelectNone } from "../../styles/general";
11
11
  import { useColor as colors, useTheme } from "../../theme";
12
12
  import { classNames, refType as ref } from "../../utils";
13
- import OptionWrapper from "../others/option-wrapper";
14
- import CircularProgress from "../progress/circular";
15
13
  import Ripple from "./ripple-effect";
16
14
  const {
17
15
  colors: {
@@ -89,6 +87,7 @@ const Button = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
89
87
  color: colorProp,
90
88
  disabled,
91
89
  endIcon,
90
+ href,
92
91
  id,
93
92
  label,
94
93
  labelProps,
@@ -99,12 +98,14 @@ const Button = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
99
98
  stopPropagation,
100
99
  text,
101
100
  type,
101
+ urlParams,
102
102
  viewType,
103
103
  ...props
104
104
  }, reference) => {
105
105
  label = label || text || '';
106
106
  const ref = useRef(null);
107
107
  const rippleRef = useRef(null);
108
+ const [urlState, setUrlState] = useState(href);
108
109
  const iconSize = iconSizeMap.get(size);
109
110
  const paddingSize = paddingSizeMap.get(size);
110
111
  const outlinedPaddingSize = outlinedPaddingSizeMap.get(size);
@@ -114,10 +115,25 @@ const Button = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
114
115
  const minHeightSizeLink = minHeightSizeLinkMap.get(size);
115
116
  const color = colors[colorProp] || colorProp;
116
117
  const isViewTypeLink = viewType === 'link';
118
+ const TagName = href ? 'a' : 'button';
117
119
  const _ButtonRootCSS = ButtonRootCSS(color);
118
120
  const _ButtonIcon = ButtonIconCSS(endIcon, label, startIcon, iconMarginSize, iconSize);
119
121
  const _ButtonTextCSS = ButtonTextCSS(loading, iconMarginSize);
120
122
  const _ButtonSizeCSS = ButtonSizeCSS(paddingSize, minHeightSize, minHeightSizeLink, outlinedPaddingSize, iconSize);
123
+ const _onClick = e => {
124
+ if (href) e.preventDefault(); //Prevent open link when click
125
+ onClick && stopPropagation && e.stopPropagation();
126
+ if (disabled || loading) return;
127
+ if (!isViewTypeLink) rippleRef.current.start(e);
128
+ onClick && onClick(e);
129
+ };
130
+ useEffect(() => {
131
+ if (href) {
132
+ const qs = urlParams ? '?' + new URLSearchParams(urlParams).toString() : '';
133
+ const url = href + qs;
134
+ setUrlState(url);
135
+ }
136
+ }, [href, urlParams]);
121
137
  useImperativeHandle(reference, () => {
122
138
  const currentRef = ref.current || {};
123
139
  currentRef.element = ref.current;
@@ -171,19 +187,11 @@ const Button = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
171
187
  const iconLoading = () => {
172
188
  return jsx(CircularProgress, {
173
189
  className: 'DGN-UI-Button-Loading',
174
- size: 'extraSmall',
175
190
  background: 'transparent',
176
191
  color: 'currentColor',
177
- strokeWidth: 3,
178
- width: parseInt(iconSize)
192
+ size: parseInt(iconSize)
179
193
  });
180
194
  };
181
- const _onClick = e => {
182
- onClick && stopPropagation && e.stopPropagation();
183
- if (disabled || loading) return;
184
- if (!isViewTypeLink) rippleRef.current.start(e);
185
- onClick && onClick(e);
186
- };
187
195
  return useMemo(() => {
188
196
  // 1. Có StartIcon => thay StartIcon
189
197
  // 2. Có EndIcon => thay EndIcon
@@ -203,7 +211,7 @@ const Button = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
203
211
  }
204
212
  if (!startIcon && !endIcon) start = iconLoading();
205
213
  }
206
- return jsx("button", {
214
+ return jsx(TagName, {
207
215
  css: [_ButtonRootCSS, _ButtonSizeCSS, disabled && ButtonDisabledCSS],
208
216
  ref: ref,
209
217
  onClick: _onClick,
@@ -211,17 +219,18 @@ const Button = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
211
219
  type: type,
212
220
  disabled: disabled,
213
221
  className: classNames('DGN-UI-Button', viewType, getClassNameFromColor(colorProp), size, loading && 'button--loading', className),
222
+ href: urlState || null,
214
223
  ...props
215
224
  }, start, jsx(Typography, {
216
225
  css: _ButtonTextCSS,
217
226
  type: typographySize,
218
227
  className: classNames('DGN-UI-Button-Label', 'button-text'),
219
228
  ...labelProps
220
- }, children || label), end && end, !disabled && !loading && !isViewTypeLink && jsx(Ripple, {
229
+ }, children || label), end ? end : null, !disabled && !loading && !isViewTypeLink ? jsx(Ripple, {
221
230
  ref: rippleRef,
222
231
  color: getRippleColor(colorProp, viewType, allColors)
223
- }));
224
- }, [children, className, colorProp, disabled, endIcon, id, label, loading, onClick, size, startIcon, stopPropagation, type, viewType]);
232
+ }) : null);
233
+ }, [children, className, colorProp, disabled, endIcon, href, id, label, loading, onClick, size, startIcon, stopPropagation, type, urlParams, viewType, urlState]);
225
234
  }));
226
235
  const ButtonIconCSS = (endIcon, label, startIcon, iconMarginSize, iconSize) => css`
227
236
  ${flexRow};
@@ -270,7 +279,7 @@ const ButtonSizeCSS = (paddingSize, minHeightSize, minHeightSizeLink, outlinedPa
270
279
  ${parseMinHeight(minHeightSizeLink)};
271
280
  }
272
281
  .no-icon {
273
- ${noMargin};
282
+ margin: 0;
274
283
  ${parseHeight(iconSize)};
275
284
  ${parseMinWidth(0)};
276
285
  }
@@ -288,6 +297,7 @@ const ButtonRootCSS = color => css`
288
297
  ${outlineNone};
289
298
  ${userSelectNone};
290
299
  ${parseHeight('max-content')};
300
+ text-decoration: none;
291
301
  transition: all 0.5s;
292
302
  &.button--loading {
293
303
  ${pointerEventsNone};
@@ -347,7 +357,7 @@ const ButtonRootCSS = color => css`
347
357
  }
348
358
  &.text {
349
359
  ${backgroundTransparent};
350
- ${noBorder};
360
+ ${borderNone};
351
361
  color: ${color};
352
362
  &.button--loading {
353
363
  background-color: ${hexToRGBA(color, alphaLoading)};
@@ -373,8 +383,8 @@ const ButtonRootCSS = color => css`
373
383
  }
374
384
  &.link {
375
385
  ${backgroundTransparent};
376
- ${noBorder};
377
- ${noPadding};
386
+ ${borderNone};
387
+ padding: 0;
378
388
  color: ${color};
379
389
  &.button--loading,
380
390
  &:hover,
@@ -410,6 +420,8 @@ Button.propTypes = {
410
420
  disabled: PropTypes.bool,
411
421
  /** [Icon](https://core.diginet.com.vn/ui/?path=/story/icon-basic--basic) or element placed after the children. */
412
422
  endIcon: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
423
+ /** The URL to link to when the button is clicked. If defined, an `a` element will be used as the root node. */
424
+ href: PropTypes.string,
413
425
  /** The content of the component. */
414
426
  label: PropTypes.string,
415
427
  /** [Props](https://core.diginet.com.vn/ui/?path=/docs/typography--title) applied to the `Typography` label. */
@@ -422,6 +434,8 @@ Button.propTypes = {
422
434
  size: PropTypes.oneOf(['tiny', 'small', 'medium', 'large', 'giant']),
423
435
  /** [Icon](https://core.diginet.com.vn/ui/?path=/story/icon-basic--basic) or element placed before the children. */
424
436
  startIcon: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
437
+ /** Query params pass to url. */
438
+ urlParams: PropTypes.object,
425
439
  /** The variant to use. */
426
440
  viewType: PropTypes.oneOf(['text', 'outlined', 'filled', 'link']),
427
441
  /**
@@ -1,78 +1,79 @@
1
1
  /** @jsxRuntime classic */
2
2
  /** @jsx jsx */
3
- import { memo, useMemo, useEffect, useRef, forwardRef } from 'react';
3
+ import { css, jsx } from '@emotion/core';
4
4
  import PropTypes from 'prop-types';
5
- import { jsx, css } from '@emotion/core';
6
- import { noBorder } from "../../styles/general";
7
- import { color as colors } from "../../styles/colors";
5
+ import { forwardRef, memo, useImperativeHandle, useMemo, useRef } from 'react';
6
+ import { noBorder, parseWidthHeight } from "../../styles/general";
7
+ import { useColor as colors, useTheme } from "../../theme";
8
+ import { classNames } from "../../utils";
8
9
  const {
9
- system: {
10
- disabled: systemDisabled
10
+ colors: {
11
+ system: {
12
+ disabled: systemDisabled
13
+ }
11
14
  }
12
- } = colors;
15
+ } = useTheme();
13
16
  const Divider = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
14
- width,
15
- height,
16
- direction,
17
- color,
17
+ action = {},
18
18
  className,
19
+ color,
20
+ direction,
21
+ height,
22
+ id,
19
23
  style,
20
- ...props
21
- }, ref) => {
22
- if (!ref) {
23
- ref = useRef(null);
24
- }
25
- if (typeof width === 'number') width = `${width}px`;
26
- if (typeof height === 'number') height = `${height}px`;
27
- const DividerRoot = css`
28
- ${noBorder}
29
- flex-shrink: 0;
30
- margin: 0;
31
- background-color: ${colors.semantic[color] || color};
32
- &.vertical {
33
- width: ${width || '1px'};
34
- height: ${height || '100%'};
35
- /* margin: auto 5px; */
36
- }
37
- &.horizontal {
38
- width: ${width || '100%'};
39
- height: ${height || '1px'};
40
- /* margin: 5px auto; */
41
- }
42
- `;
43
- useEffect(() => {
44
- if (direction === 'vertical' && !height && ref.current && ref.current.parentNode) {
45
- ref.current.style.height = ref.current.parentNode.offsetHeight + 'px';
46
- }
47
- }, []);
24
+ width
25
+ }, reference) => {
26
+ if (!reference) reference = useRef(null);
27
+ const ref = useRef(null);
28
+ const _DividerRoot = DividerRoot(color, width, height);
29
+ useImperativeHandle(reference, () => {
30
+ const currentRef = ref.current || {};
31
+ currentRef.element = ref.current;
32
+ const _instance = {
33
+ ...action
34
+ }; // methods
35
+ _instance.__proto__ = {}; // hidden methods
36
+ currentRef.instance = _instance;
37
+ return currentRef;
38
+ });
48
39
  return useMemo(() => jsx("hr", {
49
- css: DividerRoot,
40
+ css: _DividerRoot,
50
41
  ref: ref,
42
+ id: id,
51
43
  style: style,
52
- className: ['DGN-UI-Divider', direction, className].join(' ').trim(),
53
- ...props
54
- }), [width, height, color, style, className]);
44
+ className: classNames('DGN-UI-Divider', direction, className)
45
+ }), [className, color, direction, height, id, style, width]);
55
46
  }));
47
+ const DividerRoot = (color, width, height) => css`
48
+ ${noBorder}
49
+ flex-shrink: 0;
50
+ margin: 0;
51
+ background-color: ${colors[color] || color};
52
+ &.vertical {
53
+ ${parseWidthHeight(width || '1px', height || 'auto')};
54
+ }
55
+ &.horizontal {
56
+ ${parseWidthHeight(width || '100%', height || '1px')};
57
+ }
58
+ `;
56
59
  Divider.defaultProps = {
60
+ className: '',
57
61
  color: systemDisabled,
58
62
  direction: 'horizontal',
59
- style: {},
60
- className: ''
63
+ style: {}
61
64
  };
62
65
  Divider.propTypes = {
63
- /** width of divider */
64
- width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
65
- /** color of divider */
66
- height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
67
- /** color of divider */
66
+ /** Class for component. */
67
+ className: PropTypes.string,
68
+ /** The color of the component. */
68
69
  color: PropTypes.string,
69
70
  /** direction of divider */
70
71
  direction: PropTypes.oneOf(['vertical', 'horizontal']),
71
- /** style inline of divider */
72
+ /** Height oof the component. */
73
+ height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
74
+ /** Style inline of component. */
72
75
  style: PropTypes.object,
73
- /** className of divider */
74
- className: PropTypes.string,
75
- /** any props else */
76
- props: PropTypes.object
76
+ /** Width of the component. */
77
+ width: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
77
78
  };
78
79
  export default Divider;