diginet-core-ui 1.3.70 → 1.3.71

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.
@@ -6,34 +6,33 @@ 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 } from '../../styles/general';
10
- import { color as colors } from '../../styles/colors';
11
- import { darken } from '../../styles/color-helper';
9
+ import { alignCenter, border, borderBox, flexRow, inlineFlex, justifyCenter, positionRelative, userSelectNone, whiteSpaceNoWrap, cursorNotAllowed, positionAbsolute, overflowHidden } from '../../styles/general';
10
+ import { hexToRGBA } from '../../styles/color-helper';
11
+ import { useTheme } from '../../theme';
12
12
  const {
13
- system: {
14
- active,
15
- rest,
16
- white
17
- },
18
- semantic: {
19
- danger
20
- },
21
- fill: {
22
- disabled: fillDisabled,
23
- hover: fillHover
24
- },
25
- line: {
26
- normal,
27
- disabled: lineDisabled
13
+ colors: {
14
+ danger,
15
+ info,
16
+ success,
17
+ warning,
18
+ system: {
19
+ active,
20
+ rest,
21
+ white,
22
+ disabled: disabledCl,
23
+ dark
24
+ }
28
25
  },
29
- text: {
30
- disabled: textDisabled
31
- }
32
- } = colors;
33
- const iconSizeMap = new Map([['small', '12px'], ['medium', '16px']]);
26
+ spacing
27
+ } = useTheme();
28
+ const colorMap = new Map([['default', active], ['primary', active], ['success', success], ['warning', warning], ['danger', danger], ['info', info]]);
29
+ const iconSizeMap = new Map([['small', `${spacing(4)}px`], ['medium', `${spacing(5)}px`], ['large', `${spacing(6)}px`]]);
30
+ const typographySizeMap = new Map([['small', 'p3'], ['medium', 'p2'], ['large', 'p1']]);
31
+ const paddingSizeMap = new Map([['small', `0px ${spacing(1.5)}px`], ['medium', `0px ${spacing(2)}px`], ['large', `0px ${spacing(2.5)}px`]]);
32
+ const minHeightSizeMap = new Map([['small', `${spacing(5)}px`], ['medium', `${spacing(6)}px`], ['large', `${spacing(7)}px`]]);
34
33
  const Chip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
35
34
  viewType,
36
- color,
35
+ color: colorProps,
37
36
  size,
38
37
  label,
39
38
  className,
@@ -41,24 +40,44 @@ const Chip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
41
40
  onClick,
42
41
  onDbClick,
43
42
  onDoubleClick,
44
- maxLength,
45
43
  startIcon,
46
44
  endIcon,
47
45
  clearAble,
48
46
  disabled,
49
47
  readOnly,
50
48
  children,
51
- style
49
+ style,
50
+ labelProps
52
51
  }, reference) => {
53
52
  const ref = useRef(null);
54
53
  const IconRef = useRef(null);
55
54
  if (!onDbClick && onDoubleClick) onDbClick = onDoubleClick;
55
+ const color = colorMap.get(colorProps) || colorProps;
56
+ const infoChip = {
57
+ color: colorMap.get(colorProps) || colorProps,
58
+ contentColor: viewType !== 'filled' ? color : white,
59
+ backgroundColor: viewType !== 'filled' ? white : color,
60
+ iconSize: iconSizeMap.get(size),
61
+ paddingSize: paddingSizeMap.get(size),
62
+ typographySize: typographySizeMap.get(size),
63
+ minHeightSize: minHeightSizeMap.get(size),
64
+ viewType
65
+ };
66
+ infoChip.border = viewType === 'ghost' ? 'transparent !important' : colorProps === 'default' ? rest : infoChip === null || infoChip === void 0 ? void 0 : infoChip.color;
67
+ infoChip.contentColor = colorProps === 'default' && viewType === 'outlined' ? rest : infoChip === null || infoChip === void 0 ? void 0 : infoChip.contentColor;
68
+ infoChip.backgroundColor = colorProps === 'default' && viewType === 'filled' ? rest : infoChip === null || infoChip === void 0 ? void 0 : infoChip.backgroundColor;
69
+ useImperativeHandle(reference, () => {
70
+ const currentRef = ref.current || {};
71
+ const _instance = {}; // methods
72
+
73
+ _instance.__proto__ = {}; // hidden methods
74
+
75
+ currentRef.instance = _instance;
76
+ return currentRef;
77
+ });
56
78
 
57
79
  const onRemoveHandler = () => {
58
- if (onRemove) onRemove(ref.current);
59
- setTimeout(() => {
60
- ref.current && ref.current.remove();
61
- }, 0);
80
+ if (onRemove || disabled) onRemove(ref.current);
62
81
  };
63
82
 
64
83
  const _onClick = event => {
@@ -71,213 +90,161 @@ const Chip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
71
90
  onDbClick && event.stopPropagation();
72
91
  if (disabled) return;
73
92
  onDbClick && onDbClick(event);
74
- };
93
+ }; // Start Icon
75
94
 
76
- const renderLabel = () => {
77
- if (maxLength && label && label.length > maxLength) {
78
- label = label.slice(0, maxLength) + '...';
79
- }
80
-
81
- return label;
82
- };
83
95
 
84
- useImperativeHandle(reference, () => {
85
- const currentRef = ref.current || {};
86
- const _instance = {}; // methods
87
-
88
- _instance.__proto__ = {}; // hidden methods
89
-
90
- currentRef.instance = _instance;
91
- return currentRef;
92
- });
93
96
  const startIconView = useMemo(() => {
94
- let node = startIcon;
95
-
96
- if (typeof node === 'string') {
97
- node = jsx(Icon, {
98
- name: node,
99
- width: iconSizeMap.get(size),
100
- height: iconSizeMap.get(size),
101
- color: 'currentColor',
102
- viewBox: false
97
+ if (typeof startIcon === 'string') {
98
+ return jsx(Icon, {
99
+ name: startIcon,
100
+ width: infoChip.iconSize,
101
+ height: infoChip.iconSize,
102
+ color: 'currentColor'
103
103
  });
104
- }
104
+ } else return jsx("div", {
105
+ css: ChipIconCSS(infoChip)
106
+ }, startIcon);
107
+ }, [startIcon, size]); // Label
105
108
 
106
- return startIcon && jsx("div", {
107
- css: ChipIconCSS,
108
- className: size
109
- }, node);
110
- }, [startIcon, size]);
111
109
  const labelView = useMemo(() => {
112
- return jsx("div", {
113
- css: ChipLabelCSS(startIcon, endIcon, clearAble),
114
- className: size
115
- }, jsx(Typography, {
116
- type: size === 'small' ? 'p2' : 'p1',
110
+ return jsx(Typography, {
111
+ css: ChipLabelCSS,
112
+ type: infoChip.typographySize,
117
113
  color: 'inherit',
118
- lineClamp: 1
119
- }, renderLabel()));
120
- }, [label, size, startIcon, endIcon, clearAble]);
114
+ lineClamp: 1,
115
+ ...labelProps
116
+ }, label);
117
+ }, [label, size, startIcon, endIcon, clearAble]); // End Icon
118
+
121
119
  const endIconView = useMemo(() => {
122
120
  let node = endIcon;
123
121
 
124
122
  if (typeof node === 'string') {
125
- node = jsx(Icon, {
123
+ return jsx(Icon, {
126
124
  name: node,
127
- width: iconSizeMap.get(size),
128
- height: iconSizeMap.get(size),
129
- color: 'currentColor',
130
- viewBox: false
125
+ width: infoChip.iconSize,
126
+ height: infoChip.iconSize,
127
+ color: infoChip.contentColor,
128
+ viewBox: true
131
129
  });
132
130
  }
133
131
 
134
- return clearAble ? jsx("div", {
135
- css: ChipIconCSS,
136
- className: 'end-icon ' + size,
137
- ref: IconRef
138
- }, jsx(ButtonIcon, {
132
+ return clearAble ? jsx(ButtonIcon, {
133
+ ref: IconRef,
134
+ className: 'end-icon',
139
135
  viewType: 'ghost',
140
136
  name: 'Close',
141
- color: viewType === 'outlined' && color ? 'inherit' : undefined,
137
+ width: infoChip.iconSize,
138
+ height: infoChip.iconSize,
139
+ color: infoChip.contentColor,
142
140
  disabled: disabled,
141
+ viewBox: true,
143
142
  onClick: onRemoveHandler
144
- })) : endIcon && jsx("div", {
145
- css: ChipIconCSS,
143
+ }) : node && jsx("div", {
144
+ css: ChipIconCSS(infoChip),
146
145
  className: 'end-icon ' + size,
147
146
  ref: IconRef
148
147
  }, node);
149
- }, [clearAble, viewType, color, endIcon, size, disabled]);
148
+ }, [clearAble, viewType, color, endIcon, size, disabled, onRemove]);
150
149
  return jsx("div", {
151
- css: ChipRootCSS(onClick, onDbClick, color),
150
+ css: ChipRootCSS(onClick, onDbClick, colorProps, infoChip),
152
151
  ref: ref,
153
- className: ['DGN-UI-Chip', size, className, color && color !== 'default' && color, color && color !== 'default' && viewType, disabled && 'chip--disabled', readOnly && 'chip--readOnly'].join(' ').trim().replace(/\s+/g, ' '),
152
+ className: ['DGN-UI-Chip', className, disabled && 'chip--disabled', readOnly && 'chip--readOnly', viewType === 'filled' && 'chip--filled'].join(' '),
154
153
  style: style,
155
154
  onClick: _onClick,
156
155
  onDoubleClick: _onDbClick
157
- }, startIconView, labelView, endIconView, children);
156
+ }, !!startIcon && startIconView, !!label && labelView, (!!endIcon || !!clearAble) && endIconView, children);
158
157
  }));
159
- const ChipIconCSS = css`
160
- ${flexRow};
161
- ${justifyCenter};
162
- ${alignCenter};
163
- ${positionRelative};
164
- ${borderBox};
165
- padding: 0 2px;
166
- color: inherit;
167
- img {
168
- border-radius: 50%;
169
- }
170
- &.small {
171
- width: 24px;
172
- height: 24px;
173
- img {
174
- width: 20px;
175
- height: 20px;
176
- }
177
- }
178
- &.medium {
179
- max-width: 32px;
180
- max-height: 32px;
181
- img {
182
- min-width: 24px;
183
- min-height: 24px;
184
- }
185
- &:not(.end-icon) {
186
- margin-right: 4px;
187
- }
188
- &.end-icon {
189
- width: 32px;
190
- height: 26px;
191
- }
192
- }
193
- `;
194
-
195
- const ChipLabelCSS = (startIcon, endIcon, clearAble) => css`
158
+ const ChipLabelCSS = css`
196
159
  ${flexRow};
197
160
  ${alignCenter};
198
161
  ${positionRelative};
199
162
  ${userSelectNone};
200
163
  ${whiteSpaceNoWrap};
201
- padding-right: ${endIcon || clearAble ? 2 : 10}px;
202
- padding-left: ${startIcon ? 2 : 10}px;
203
- &.small {
204
- max-height: 24px;
205
- }
206
- &.medium {
207
- max-height: 32px;
208
- }
209
164
  `;
210
165
 
211
- const ChipRootCSS = (onClick, onDbClick, color) => css`
166
+ const ChipRootCSS = (onClick, onDbClick, colorProps, info) => css`
212
167
  ${inlineFlex};
213
168
  ${alignCenter};
214
169
  ${positionRelative};
215
170
  ${borderBox};
216
- ${border(1, normal)};
171
+ ${border('1px', info.border)};
217
172
  width: max-content;
218
- margin-right: 15px;
219
- padding: 0 6px;
220
- color: ${rest};
221
- background: ${white};
222
- border-radius: 20px;
173
+ padding: ${info === null || info === void 0 ? void 0 : info.paddingSize};
174
+ color: ${info === null || info === void 0 ? void 0 : info.contentColor};
175
+ background: ${info === null || info === void 0 ? void 0 : info.backgroundColor};
176
+ border-radius: ${spacing(4)}px;
223
177
  cursor: ${onClick || onDbClick ? 'pointer' : 'unset'};
224
- &.small {
225
- height: 24px;
226
- }
227
- &.medium {
228
- min-height: 32px;
229
- padding-top: 2px;
230
- padding-bottom: 2px;
231
- }
232
- &:hover {
233
- background: ${fillHover};
234
- border-color: ${active};
235
- }
236
- &.chip--disabled {
237
- color: ${textDisabled} !important;
238
- background-color: ${fillDisabled} !important;
239
- border-color: ${lineDisabled} !important;
240
- pointer-events: none !important;
241
- .css-${ChipIconCSS.name} {
242
- path {
243
- fill: ${textDisabled} !important;
178
+ height: ${info === null || info === void 0 ? void 0 : info.minHeightSize};
179
+ min-height: ${info === null || info === void 0 ? void 0 : info.minHeightSize};
180
+ gap: ${spacing()}px;
181
+ &.chip--filled {
182
+ &:not(.chip--disabled):not(.chip--readOnly) {
183
+ &::after {
184
+ border-radius: ${spacing(4)}px;
185
+ ${positionAbsolute};
186
+ top: 0;
187
+ left: 0;
188
+ content: '';
189
+ width: 100%;
190
+ height: 100%;
191
+ }
192
+ &:hover::after,
193
+ &:focus::after {
194
+ background: ${hexToRGBA(dark, 0.15)};
195
+ }
196
+ &:active::after {
197
+ background: ${hexToRGBA(dark, 0.3)};
244
198
  }
245
199
  }
246
200
  }
247
- &.chip--readOnly {
248
- cursor: unset !important;
249
- .css-${ChipIconCSS.name} {
250
- pointer-events: none !important;
201
+ &:not(.chip--filled) {
202
+ &:not(.chip--disabled):not(.chip--readOnly):hover {
203
+ ${border('1px', info === null || info === void 0 ? void 0 : info.color)};
204
+ background: ${hexToRGBA(info === null || info === void 0 ? void 0 : info.color, 0.1)};
205
+ color: ${info === null || info === void 0 ? void 0 : info.color};
251
206
  }
252
- }
253
- &.outlined {
254
- &.${color} {
255
- color: ${colors[color] || color};
256
- border-color: ${colors[color] || color};
207
+ &:not(.chip--disabled):not(.chip--readOnly):active {
208
+ ${border('1px', info === null || info === void 0 ? void 0 : info.color)};
209
+ background: ${hexToRGBA(info === null || info === void 0 ? void 0 : info.color, 0.3)};
210
+ color: ${info === null || info === void 0 ? void 0 : info.color};
257
211
  }
258
- }
259
- &.filled {
260
- color: ${white};
261
- .clear-icon {
262
- color: ${white};
263
- &:hover {
264
- color: ${danger};
265
- }
266
- }
267
- &.${color} {
268
- background-color: ${colors[color] || color};
269
- border-color: ${darken(colors[color] || color, 0.22)};
212
+ &:not(.chip--disabled):not(.chip--readOnly):focus {
213
+ ${border('1px', info === null || info === void 0 ? void 0 : info.color)};
214
+ background: ${hexToRGBA(info === null || info === void 0 ? void 0 : info.color, 0.2)};
215
+ color: ${info === null || info === void 0 ? void 0 : info.color};
270
216
  }
271
217
  }
218
+ &.chip--disabled {
219
+ color: ${disabledCl} !important;
220
+ background-color: ${white} !important;
221
+ ${border('1px', disabledCl)};
222
+ }
223
+ &.chip--readOnly,
224
+ &.chip--disabled {
225
+ ${cursorNotAllowed}
226
+ }
227
+ `;
228
+
229
+ const ChipIconCSS = info => css`
230
+ ${flexRow};
231
+ ${justifyCenter};
232
+ ${alignCenter};
233
+ ${positionRelative};
234
+ ${borderBox};
235
+ ${overflowHidden};
236
+ width: ${info === null || info === void 0 ? void 0 : info.iconSize};
237
+ min-width: ${info === null || info === void 0 ? void 0 : info.iconSize};
238
+ max-width: ${info === null || info === void 0 ? void 0 : info.iconSize};
239
+ height: ${info === null || info === void 0 ? void 0 : info.iconSize};
240
+ min-height: ${info === null || info === void 0 ? void 0 : info.iconSize};
241
+ max-height: ${info === null || info === void 0 ? void 0 : info.iconSize};
272
242
  `;
273
243
 
274
244
  Chip.defaultProps = {
275
- label: '',
276
- className: '',
277
- style: {},
278
245
  viewType: 'outlined',
279
- size: 'small',
280
- clearAble: false
246
+ size: 'medium',
247
+ color: 'default'
281
248
  };
282
249
  Chip.propTypes = {
283
250
  /** content to display in Chip */
@@ -290,7 +257,6 @@ Chip.propTypes = {
290
257
 
291
258
  /** style inline of component */
292
259
  style: PropTypes.object,
293
- maxLength: PropTypes.number,
294
260
 
295
261
  /** the icon display at head of Chip */
296
262
  startIcon: PropTypes.any,
@@ -299,13 +265,13 @@ Chip.propTypes = {
299
265
  endIcon: PropTypes.any,
300
266
 
301
267
  /** type of chip */
302
- viewType: PropTypes.oneOf(['outlined', 'filled']),
268
+ viewType: PropTypes.oneOf(['ghost', 'outlined', 'filled']),
303
269
 
304
270
  /** color for text or background of Chip */
305
271
  color: PropTypes.oneOf(['default', 'primary', 'info', 'success', 'warning', 'danger']),
306
272
 
307
273
  /** size of Chip */
308
- size: PropTypes.oneOf(['small', 'medium']),
274
+ size: PropTypes.oneOf(['small', 'medium', 'large']),
309
275
 
310
276
  /** show clear icon if true */
311
277
  clearAble: PropTypes.bool,
@@ -332,6 +298,9 @@ Chip.propTypes = {
332
298
  onDoubleClick: PropTypes.func,
333
299
 
334
300
  /** content to display on Chip (the same to label) */
335
- children: PropTypes.node
301
+ children: PropTypes.node,
302
+
303
+ /** props for Typography of label */
304
+ labelProps: PropTypes.object
336
305
  };
337
306
  export default Chip;
@@ -3,7 +3,7 @@
3
3
  /** @jsx jsx */
4
4
  import { css, jsx } from '@emotion/core';
5
5
  import PropTypes from 'prop-types';
6
- import React, { forwardRef, memo, useEffect, useRef, useState, useImperativeHandle } from 'react';
6
+ import { forwardRef, memo, useEffect, useRef, useState, useImperativeHandle, Fragment } from 'react';
7
7
  import { Typography } from '../..';
8
8
  import { alignCenter, alignStart, borderBox, cursorPointer, displayBlock, flexRow, positionAbsolute, positionRelative, cursorNoDrop, parseWidthHeight } from '../../../styles/general';
9
9
  import { randomString } from '../../../utils';
@@ -154,7 +154,7 @@ const Checkbox = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
154
154
  },
155
155
  color: disabled ? clDisabled : '',
156
156
  ...labelProps
157
- }, jsx(React.Fragment, null, children || label, required && jsx("span", {
157
+ }, jsx(Fragment, null, children || label, required && jsx("span", {
158
158
  style: {
159
159
  color: disabled ? clDisabled : clDanger
160
160
  }