diginet-core-ui 1.3.80 → 1.3.81-beta.2

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
  }));
@@ -1,25 +1,28 @@
1
1
  /** @jsxRuntime classic */
2
2
  /** @jsx jsx */
3
- import { memo, useRef, forwardRef, useMemo, useImperativeHandle } from 'react';
4
- import PropTypes from 'prop-types';
5
- import { jsx, css } from '@emotion/core';
3
+ import { css, jsx } from '@emotion/core';
4
+ import { Icon } from "./..";
6
5
  import OptionWrapper from "../others/option-wrapper";
7
- import { color as colors } from "../../styles/colors";
8
- import { typography } from "../../styles/typography";
9
- import { alignCenter, borderBox, borderRadius4px, flexRow, flexWrap, inlineFlex, justifyCenter, pointerEventsNone, positionAbsolute, positionRelative } from "../../styles/general";
10
- import Icon from "../../icons";
11
- const {
12
- paragraph1,
13
- paragraph2,
14
- paragraph3
15
- } = typography;
6
+ import PropTypes from 'prop-types';
7
+ import { forwardRef, memo, useImperativeHandle, useMemo, useRef } from 'react';
8
+ import { alignCenter, borderBox, borderRadius4px, flexRow, flexWrap, inlineFlex, justifyCenter, parseMinWidthHeight, parseWidthHeight, pointerEventsNone, positionAbsolute, positionRelative } from "../../styles/general";
9
+ import { useColor as colors, useTheme } from "../../theme";
10
+ import { classNames, refType as ref } from "../../utils";
16
11
  const {
17
- system: {
18
- rest,
19
- white
20
- }
21
- } = colors;
22
- const colorMap = new Map([['default', rest]]);
12
+ colors: {
13
+ system: {
14
+ rest: systemRest,
15
+ white: systemWhite
16
+ }
17
+ },
18
+ typography: {
19
+ paragraph1,
20
+ paragraph2,
21
+ paragraph3
22
+ },
23
+ spacing
24
+ } = useTheme();
25
+ const colorMap = new Map([['default', systemRest]]);
23
26
  const iconSizeMap = new Map([['medium', 24], ['large', 32], ['giant', 40]]);
24
27
  const dotSizeMap = new Map([['medium', 8], ['large', 10], ['giant', 12]]);
25
28
  const dotIndentMap = new Map([['medium', 4], ['large', 2]]);
@@ -70,28 +73,30 @@ const calDotPos = (anchorOrigin, contentDirection, dotSize, hasContent, size) =>
70
73
  const Badge = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
71
74
  action = {},
72
75
  anchorOrigin,
73
- contentDirection,
76
+ children,
77
+ className,
78
+ color,
74
79
  content,
80
+ contentDirection,
81
+ iconProps,
82
+ id,
83
+ invisible,
75
84
  max,
76
85
  name,
77
- color,
86
+ showZero,
78
87
  size,
79
- className,
80
88
  style,
81
- showZero,
82
- invisible,
83
- children,
84
- iconProps,
85
89
  ...props
86
90
  }, reference) => {
91
+ if (!reference) reference = useRef(null);
87
92
  const ref = useRef(null);
88
93
  const typographySize = typographySizeMap.get(size);
89
94
  const iconSize = iconSizeMap.get(size);
90
95
  const dotSize = content || content === 0 && showZero ? dotSizeMap.get(size) + 8 : dotSizeMap.get(size);
91
96
  const dotColor = colors[color] || colorMap.get(color) || color;
92
97
  const dotPos = calDotPos(anchorOrigin, !children && name ? 'right' : contentDirection, dotSize, content || content === 0, size);
93
- const _BadgeNumberCSS = BadgeNumberCSS(typographySize, children, name, dotSize, dotColor, invisible);
94
- const _BadgeRootCSS = BadgeRootCSS(children, name, dotPos, _BadgeNumberCSS);
98
+ const _BadgeNumberCSS = BadgeNumberCSS(typographySize, children, name, dotSize, dotColor);
99
+ const _BadgeRootCSS = BadgeRootCSS(children, name, dotPos, _BadgeNumberCSS.name);
95
100
  useImperativeHandle(reference, () => {
96
101
  const currentRef = ref.current || {};
97
102
  currentRef.element = ref.current;
@@ -106,28 +111,30 @@ const Badge = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
106
111
  let node = children;
107
112
  if (!node && name) {
108
113
  node = jsx(Icon, {
114
+ viewBox: true,
109
115
  name: name,
110
116
  width: iconSize,
111
117
  height: iconSize,
112
- viewBox: true,
118
+ color: 'currentColor',
113
119
  ...iconProps
114
120
  });
115
121
  }
116
122
  return jsx("div", {
117
123
  css: _BadgeRootCSS,
118
124
  ref: ref,
119
- className: ['DGN-UI-Badge', className].join(' ').trim().replace(/\s+/g, ' '),
125
+ id: id,
126
+ className: classNames('DGN-UI-Badge', className),
120
127
  style: style,
121
128
  ...props
122
129
  }, jsx("span", {
123
130
  className: 'DGN-UI-Badge-Children'
124
- }, node), content !== undefined && jsx("span", {
131
+ }, node), content !== undefined && !invisible ? jsx("span", {
125
132
  css: _BadgeNumberCSS,
126
133
  className: 'DGN-UI-Badge-Dot'
127
- }, max && content > max ? max + '+' : content === 0 && !showZero ? null : content));
128
- }, [anchorOrigin, contentDirection, content, name, size, children, max, showZero, invisible, color, style, className, iconProps]);
134
+ }, max && content > max ? max + '+' : content === 0 && !showZero ? null : content) : null);
135
+ }, [anchorOrigin, children, className, color, content, contentDirection, iconProps, id, invisible, max, name, showZero, size, style, props]);
129
136
  }));
130
- const BadgeNumberCSS = (typographySize, children, name, dotSize, dotColor, invisible) => css`
137
+ const BadgeNumberCSS = (typographySize, children, name, dotSize, dotColor) => css`
131
138
  ${typographySize};
132
139
  ${flexRow};
133
140
  ${alignCenter};
@@ -136,84 +143,88 @@ const BadgeNumberCSS = (typographySize, children, name, dotSize, dotColor, invis
136
143
  ${borderBox};
137
144
  ${pointerEventsNone};
138
145
  ${children || name ? positionAbsolute : positionRelative};
139
- color: ${white};
140
- min-height: ${dotSize}px;
141
- min-width: ${dotSize}px;
146
+ color: ${systemWhite};
147
+ ${parseMinWidthHeight(dotSize)};
142
148
  background-color: ${dotColor};
143
149
  border-radius: ${dotSize / 2}px;
144
- padding: 0 4px;
145
- transition: transform 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
146
- ${invisible && 'transform: scale(0) translate(50%, -50%);'};
150
+ padding: ${spacing([0, 1])};
147
151
  `;
148
- const BadgeRootCSS = (children, name, dotPos, _BadgeNumberCSS) => css`
152
+ const BadgeRootCSS = (children, name, dotPos, BadgeNumberCSSName) => css`
149
153
  ${inlineFlex};
150
154
  ${alignCenter};
151
155
  ${justifyCenter};
152
156
  ${positionRelative};
153
157
  ${borderBox};
154
158
  ${borderRadius4px};
155
- color: ${white};
156
- height: max-content;
157
- min-height: max-content;
158
- width: max-content;
159
- min-width: max-content;
160
- .css-${_BadgeNumberCSS.name} {
161
- ${(children || name) && dotPos}
159
+ ${parseWidthHeight('max-content')};
160
+ ${parseMinWidthHeight('max-content')};
161
+ .css-${BadgeNumberCSSName} {
162
+ ${(children || name) && dotPos};
162
163
  }
163
164
  `;
164
165
  Badge.defaultProps = {
165
- color: 'default',
166
- size: 'medium',
167
166
  anchorOrigin: {
168
167
  vertical: 'top',
169
168
  horizontal: 'right'
170
169
  },
170
+ className: '',
171
+ color: 'default',
171
172
  content: null,
172
- max: 99,
173
173
  contentDirection: 'left',
174
- showZero: false,
175
174
  invisible: false,
176
- className: '',
175
+ max: 99,
176
+ showZero: false,
177
+ size: 'medium',
177
178
  style: {}
178
179
  };
179
180
  Badge.propTypes = {
181
+ /** The anchor of the badge. */
180
182
  anchorOrigin: PropTypes.shape({
181
183
  horizontal: PropTypes.oneOf(['left', 'right']),
182
184
  vertical: PropTypes.oneOf(['top', 'bottom'])
183
185
  }),
184
- /** the quantity is shown on the badge */
186
+ /** The badge will be added relative to this node. */
187
+ children: PropTypes.node,
188
+ /** Class for component. */
189
+ className: PropTypes.string,
190
+ /** The color of the component. */
191
+ color: PropTypes.oneOfType([PropTypes.oneOf(['default', 'primary', 'info', 'success', 'warning', 'danger']), PropTypes.string]),
192
+ /** The content rendered within the badge. */
185
193
  content: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
186
- /** the largest number is displayed on the badge */
187
- max: PropTypes.number,
188
- /** used to fill background for button */
194
+ /** Direction of content within the badge */
189
195
  contentDirection: PropTypes.oneOf(['left', 'right']),
190
- /** background color of badge */
191
- color: PropTypes.oneOfType([PropTypes.oneOf(['default', 'primary', 'info', 'success', 'warning', 'danger']), PropTypes.string]),
192
- /** use name will replace children with ButtonIcon */
196
+ /** If `true`, the badge is invisible */
197
+ invisible: PropTypes.bool,
198
+ /** Max count to show. */
199
+ max: PropTypes.number,
200
+ /** Prop name of [ButtonIcon](https://core.diginet.com.vn/ui/?path=/docs/buttonicon) components. */
193
201
  name: PropTypes.string,
194
- /** other icon props when use prop name */
195
- iconProps: PropTypes.object,
196
- /** size of Badge
202
+ /** Controls whether the badge is hidden when `content` is zero. */
203
+ showZero: PropTypes.bool,
204
+ /** Size of the components.
197
205
  *
198
206
  * * medium (dot 8px, typography p3)
199
207
  * * large (button 10px, typography p2)
200
208
  * * giant (button 12px, typography p1)
201
209
  * */
202
210
  size: PropTypes.oneOf(['medium', 'large', 'giant']),
203
- /** Controls whether the badge is hidden when content is zero */
204
- showZero: PropTypes.bool,
205
- /** If true, the badge is invisible */
206
- invisible: PropTypes.bool,
207
- /** className of component */
208
- className: PropTypes.string,
209
- /** style inline of component */
211
+ /** Style inline of component. */
210
212
  style: PropTypes.object,
211
- /** the function get ref */
212
- refs: PropTypes.func,
213
- /** the content displayed under the number of the badge */
214
- children: PropTypes.node,
215
- /** any props else */
216
- props: PropTypes.any
213
+ /**
214
+ * ref methods (ref.current.instance.*method*)
215
+ *
216
+ * * option(): Gets all UI component properties
217
+ * * Returns value - object
218
+ * * option(optionName): Gets the value of a single property
219
+ * * @param {optionName} - string
220
+ * * Returns value - any
221
+ * * option(optionName, optionValue): Updates the value of a single property
222
+ * * @param {optionName} - string
223
+ * * @param {optionValue} - any
224
+ * * option(options): Updates the values of several properties
225
+ * * @param {options} - object
226
+ */
227
+ reference: ref
217
228
  };
218
229
  export { Badge };
219
230
  export default OptionWrapper(Badge);
@@ -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;