diginet-core-ui 1.4.23-beta.2 → 1.4.24

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,12 +4,11 @@ import { css, jsx } from '@emotion/core';
4
4
  import { ButtonIcon, Icon, Typography } from "./..";
5
5
  import PropTypes from 'prop-types';
6
6
  import { forwardRef, memo, useImperativeHandle, useMemo, useRef } from 'react';
7
- import { bgColor, border, boxBorder, cursorNotAllowed, displayInlineFlex, flexRow, itemsCenter, justifyCenter, overflowHidden, parseMaxWidthHeight, parseMinWidthHeight, parseWidthHeight, pointerEventsNone, positionAbsolute, positionRelative, textColor
8
- // userSelectNone,
9
- } from "../../styles/general";
7
+ import { hexToRGBA } from "../../styles/color-helper";
8
+ import { bgColor, border, boxBorder, cursorNotAllowed, displayInlineFlex, flexRow, itemsCenter, justifyCenter, overflowHidden, pointerEventsNone, positionAbsolute, positionRelative, textColor, userSelectNone } from "../../styles/general";
10
9
  import { useTheme } from "../../theme";
11
10
  import useThemeProps from "../../theme/utils/useThemeProps";
12
- import { classNames, getProp, hexToRGBA } from "../../utils";
11
+ import { classNames, getProp } from "../../utils";
13
12
  const colorMap = new Map([['default', 'system/active'], ['primary', 'system/active'], ['success', 'semantic/success'], ['warning', 'semantic/warning'], ['danger', 'semantic/danger'], ['info', 'semantic/info']]);
14
13
  const iconSizeMap = new Map([['small', `16px`], ['medium', `20px`], ['large', `24px`]]);
15
14
  const typographySizeMap = new Map([['small', 'p3'], ['medium', 'p2'], ['large', 'p1']]);
@@ -28,26 +27,27 @@ const Chip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference) =>
28
27
  name: 'Chip'
29
28
  });
30
29
  const {
31
- children,
32
- className,
33
- clearAble,
30
+ viewType,
34
31
  color: colorProps,
35
- disabled,
36
- endIcon,
32
+ size,
37
33
  label,
38
- labelProps,
34
+ className,
35
+ onRemove,
39
36
  onClick,
40
37
  onDbClick: onDbClickProp,
41
38
  onDoubleClick,
42
- onRemove,
43
- readOnly,
44
- size,
45
39
  startIcon,
40
+ endIcon,
41
+ clearAble,
42
+ disabled,
43
+ readOnly,
44
+ children,
46
45
  style,
47
- viewType
46
+ labelProps
48
47
  } = props;
49
48
  const onDbClick = !onDbClickProp && onDoubleClick ? onDoubleClick : onDbClickProp;
50
49
  const ref = useRef(null);
50
+ const IconRef = useRef(null);
51
51
  let color = colorMap.get(colorProps) || colorProps;
52
52
  color = getProp(colors, color, color);
53
53
  const infoChip = {
@@ -64,7 +64,6 @@ const Chip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference) =>
64
64
  infoChip.contentColor = colorProps === 'default' && viewType === 'outlined' ? getProp(colors, 'system/rest') : infoChip === null || infoChip === void 0 ? void 0 : infoChip.contentColor;
65
65
  infoChip.backgroundColor = colorProps === 'default' && viewType === 'filled' ? getProp(colors, 'system/rest') : infoChip === null || infoChip === void 0 ? void 0 : infoChip.backgroundColor;
66
66
  const _ChipRootCSS = ChipRootCSS(onClick, onDbClick, infoChip, theme);
67
- const _ChipIconCSS = ChipIconCSS(infoChip);
68
67
  const onRemoveHandler = () => {
69
68
  if (onRemove || disabled) onRemove(ref.current);
70
69
  };
@@ -96,20 +95,20 @@ const Chip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference) =>
96
95
  color: 'currentColor'
97
96
  });
98
97
  } else return jsx("div", {
99
- css: _ChipIconCSS
98
+ css: ChipIconCSS(infoChip)
100
99
  }, startIcon);
101
100
  }, [startIcon, size]);
102
101
 
103
102
  // Label
104
- const labelView = jsx(Typography
105
- // css={ChipLabelCSS}
106
- , {
107
- type: infoChip.typographySize,
108
- color: 'inherit',
109
- lineClamp: 1,
110
- hoverTooltip: true,
111
- ...labelProps
112
- }, label);
103
+ const labelView = useMemo(() => {
104
+ return jsx(Typography, {
105
+ css: ChipLabelCSS,
106
+ type: infoChip.typographySize,
107
+ color: 'inherit',
108
+ lineClamp: 1,
109
+ ...labelProps
110
+ }, label);
111
+ }, [label, size, startIcon, endIcon, clearAble]);
113
112
 
114
113
  // End Icon
115
114
  const endIconView = useMemo(() => {
@@ -119,10 +118,12 @@ const Chip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference) =>
119
118
  name: node,
120
119
  width: infoChip.iconSize,
121
120
  height: infoChip.iconSize,
122
- color: infoChip.contentColor
121
+ color: infoChip.contentColor,
122
+ viewBox: true
123
123
  });
124
124
  }
125
125
  return clearAble ? jsx(ButtonIcon, {
126
+ ref: IconRef,
126
127
  className: 'end-icon',
127
128
  viewType: 'ghost',
128
129
  name: 'Close',
@@ -130,29 +131,29 @@ const Chip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference) =>
130
131
  height: infoChip.iconSize,
131
132
  color: infoChip.contentColor,
132
133
  disabled: disabled,
134
+ viewBox: true,
133
135
  onClick: onRemoveHandler
134
136
  }) : node && jsx("div", {
135
- css: _ChipIconCSS,
136
- className: 'end-icon ' + size
137
+ css: ChipIconCSS(infoChip),
138
+ className: 'end-icon ' + size,
139
+ ref: IconRef
137
140
  }, node);
138
141
  }, [clearAble, viewType, color, endIcon, size, disabled, onRemove]);
139
142
  return jsx("div", {
140
143
  css: _ChipRootCSS,
141
144
  ref: ref,
142
- className: classNames('DGN-UI-Chip', className, disabled && 'chip--disabled', readOnly && 'chip--readOnly', viewType === 'filled' && 'chip--filled'),
145
+ className: classNames(['DGN-UI-Chip', className, disabled && 'chip--disabled', readOnly && 'chip--readOnly', viewType === 'filled' && 'chip--filled']),
143
146
  style: style,
144
147
  onClick: _onClick,
145
148
  onDoubleClick: _onDbClick
146
149
  }, !!startIcon && startIconView, !!label && labelView, (!!endIcon || !!clearAble) && endIconView, children);
147
150
  }));
148
-
149
- // const ChipLabelCSS = css`
150
- // ${flexRow};
151
- // ${itemsCenter};
152
- // ${positionRelative};
153
- // ${userSelectNone};
154
- // `;
155
-
151
+ const ChipLabelCSS = css`
152
+ ${flexRow};
153
+ ${itemsCenter};
154
+ ${positionRelative};
155
+ ${userSelectNone};
156
+ `;
156
157
  const ChipRootCSS = (onClick, onDbClick, info, {
157
158
  colors,
158
159
  spacing
@@ -166,20 +167,21 @@ const ChipRootCSS = (onClick, onDbClick, info, {
166
167
  padding: ${info === null || info === void 0 ? void 0 : info.paddingSize};
167
168
  ${textColor(info === null || info === void 0 ? void 0 : info.contentColor)};
168
169
  ${bgColor(info === null || info === void 0 ? void 0 : info.backgroundColor)};
169
- border-radius: ${spacing([4])};
170
+ border-radius: ${spacing(4)}px;
170
171
  cursor: ${onClick || onDbClick ? 'pointer' : 'unset'};
171
172
  height: ${info === null || info === void 0 ? void 0 : info.minHeightSize};
172
173
  min-height: ${info === null || info === void 0 ? void 0 : info.minHeightSize};
173
- gap: ${spacing([1])};
174
+ gap: ${spacing()}px;
174
175
  &.chip--filled {
175
176
  &:not(.chip--disabled):not(.chip--readOnly) {
176
177
  &::after {
177
- border-radius: ${spacing([4])};
178
+ border-radius: ${spacing(4)}px;
178
179
  ${positionAbsolute};
179
180
  top: 0;
180
181
  left: 0;
181
182
  content: '';
182
- ${parseWidthHeight('100%')};
183
+ width: 100%;
184
+ height: 100%;
183
185
  ${pointerEventsNone};
184
186
  }
185
187
  &:hover::after,
@@ -225,9 +227,12 @@ const ChipIconCSS = info => css`
225
227
  ${positionRelative};
226
228
  ${boxBorder};
227
229
  ${overflowHidden};
228
- ${parseWidthHeight(info === null || info === void 0 ? void 0 : info.iconSize)};
229
- ${parseMinWidthHeight(info === null || info === void 0 ? void 0 : info.iconSize)};
230
- ${parseMaxWidthHeight(info === null || info === void 0 ? void 0 : info.iconSize)};
230
+ width: ${info === null || info === void 0 ? void 0 : info.iconSize};
231
+ min-width: ${info === null || info === void 0 ? void 0 : info.iconSize};
232
+ max-width: ${info === null || info === void 0 ? void 0 : info.iconSize};
233
+ height: ${info === null || info === void 0 ? void 0 : info.iconSize};
234
+ min-height: ${info === null || info === void 0 ? void 0 : info.iconSize};
235
+ max-height: ${info === null || info === void 0 ? void 0 : info.iconSize};
231
236
  `;
232
237
 
233
238
  // Chip.defaultProps = {
@@ -237,39 +242,42 @@ const ChipIconCSS = info => css`
237
242
  // };
238
243
 
239
244
  Chip.propTypes = {
240
- /** Content to display in the component. */
245
+ /** content to display in Chip */
241
246
  label: PropTypes.string,
242
- /** The CSS class for the component. */
247
+ /** class of Chip element */
243
248
  className: PropTypes.string,
244
- /** Inline style for the component. */
249
+ /** max length content to display was allowed */
250
+ /** style inline of component */
245
251
  style: PropTypes.object,
246
- /** The icon displayed at the start of the component. */
252
+ /** the icon display at head of Chip */
247
253
  startIcon: PropTypes.any,
248
- /** The icon displayed at the end of the component. */
254
+ /** the icon display at last of Chip */
249
255
  endIcon: PropTypes.any,
250
- /** The variant to use. */
256
+ /** type of chip */
251
257
  viewType: PropTypes.oneOf(['ghost', 'outlined', 'filled']),
252
- /** Color for the text or background of the Chip. */
258
+ /** color for text or background of Chip */
253
259
  color: PropTypes.oneOfType([PropTypes.oneOf(['default', 'primary', 'info', 'success', 'warning', 'danger']), PropTypes.string]),
254
- /** Size of the component. */
260
+ /** size of Chip */
255
261
  size: PropTypes.oneOf(['small', 'medium', 'large']),
256
- /** If `true`, a clear icon will be shown. */
262
+ /** show clear icon if true */
257
263
  clearAble: PropTypes.bool,
258
- /** If `true`, all events will be disabled and the color will be changed. */
264
+ /** prevent all event and change color if true */
259
265
  disabled: PropTypes.bool,
260
- /** If `true`, all events will be disabled. */
266
+ /** prevent all event if true */
261
267
  readOnly: PropTypes.bool,
262
- /** Function to be called after removing the component. */
268
+ /** the function to get ref of Chip */
269
+ refs: PropTypes.func,
270
+ /** the function will run after remove chip */
263
271
  onRemove: PropTypes.func,
264
- /** Function to be called when the component is clicked. */
272
+ /** the function will run when click on chip */
265
273
  onClick: PropTypes.func,
266
- /** Function to be called when the component is double-clicked. */
274
+ /** the function will run when double click on chip */
267
275
  onDbClick: PropTypes.func,
268
- /** Function to be called when the component is double-clicked (priority over onDbClick). */
276
+ /** like onDbClick (priority onDbClick) */
269
277
  onDoubleClick: PropTypes.func,
270
- /** Content to display on the Chip (same as label). */
278
+ /** content to display on Chip (the same to label) */
271
279
  children: PropTypes.node,
272
- /** [Props](https://core.diginet.com.vn/ui/?path=/docs/components-typography--title) applied to the `Typography` label. */
280
+ /** props for Typography of label */
273
281
  labelProps: PropTypes.object
274
282
  };
275
283
  export default Chip;
@@ -655,7 +655,7 @@ const renderNavigator = (className, refs, dbLeftFn, leftFn, rightFn, dbRightFn,
655
655
  color: 'primary',
656
656
  type: 'h3',
657
657
  ref: refs.content,
658
- format: ['sentence']
658
+ format: ['lowercase']
659
659
  }))), jsx("div", {
660
660
  className: className.navigator.around
661
661
  }, jsx(ButtonIcon, {