diginet-core-ui 1.3.33 → 1.3.34

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.
@@ -1,11 +1,36 @@
1
1
  /** @jsxRuntime classic */
2
2
 
3
3
  /** @jsx jsx */
4
- import { memo, useRef, forwardRef, useEffect, useMemo } from 'react';
4
+ import { memo, useRef, forwardRef, useEffect, useMemo, useImperativeHandle } from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { jsx, css } from '@emotion/core';
7
7
  import { ButtonIcon, Typography } from '../';
8
- import theme from '../../theme/settings';
8
+ import Icon from '../../icons';
9
+ import { alignCenter, borderBox, flexRow, inlineFlex, justifyCenter, positionRelative, userSelectNone } from '../../styles/general';
10
+ import { color as colors } from '../../styles/colors';
11
+ import { darken } from '../../styles/color-helper';
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
28
+ },
29
+ text: {
30
+ disabled: textDisabled
31
+ }
32
+ } = colors;
33
+ const iconSizeMap = new Map([['small', '12px'], ['medium', '16px']]);
9
34
  const Chip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
10
35
  viewType,
11
36
  color,
@@ -25,20 +50,17 @@ const Chip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
25
50
  readOnly,
26
51
  children,
27
52
  ...props
28
- }, ref) => {
29
- if (!ref) {
30
- ref = useRef(null);
31
- }
32
-
53
+ }, reference) => {
54
+ const ref = useRef(null);
33
55
  const IconRef = useRef(null);
34
56
  const ChipIcon = css`
35
- display: flex;
36
- position: relative;
37
- justify-content: center;
38
- align-items: center;
57
+ ${flexRow}
58
+ ${justifyCenter}
59
+ ${alignCenter}
60
+ ${positionRelative}
61
+ ${borderBox}
39
62
  padding: 0 2px;
40
63
  color: inherit;
41
- box-sizing: border-box;
42
64
  img {
43
65
  border-radius: 50%;
44
66
  }
@@ -65,17 +87,14 @@ const Chip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
65
87
  height: 26px;
66
88
  }
67
89
  }
68
- .clear-icon svg {
69
- padding: 0 !important;
70
- }
71
90
  `;
72
91
  const ChipLabel = css`
73
- display: flex;
74
- position: relative;
75
- align-items: center;
92
+ ${flexRow}
93
+ ${alignCenter}
94
+ ${positionRelative}
95
+ ${userSelectNone}
76
96
  padding-right: ${endIcon || clearAble ? 2 : 10}px;
77
97
  padding-left: ${startIcon ? 2 : 10}px;
78
- user-select: none;
79
98
  white-space: nowrap;
80
99
  &.small {
81
100
  max-height: 24px;
@@ -85,16 +104,16 @@ const Chip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
85
104
  }
86
105
  `;
87
106
  const ChipRoot = css`
88
- display: inline-flex;
89
- position: relative;
90
- align-items: center;
107
+ ${inlineFlex}
108
+ ${alignCenter}
109
+ ${positionRelative}
110
+ ${borderBox}
91
111
  width: max-content;
92
112
  margin-right: 15px;
93
113
  padding: 0 6px;
94
- color: ${theme.colors.secondary};
95
- background: #FFFFFF;
96
- border: 1px solid ${theme.colors.dark6};
97
- box-sizing: border-box;
114
+ color: ${rest};
115
+ background: ${white};
116
+ border: 1px solid ${normal};
98
117
  border-radius: 20px;
99
118
  cursor: ${onClick || onDbClick ? 'pointer' : 'unset'};
100
119
  &.small {
@@ -106,74 +125,43 @@ const Chip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
106
125
  padding-bottom: 2px;
107
126
  }
108
127
  &:hover {
109
- background: ${theme.colors.hover};
110
- border-color: ${theme.colors.brand};
128
+ background: ${fillHover};
129
+ border-color: ${active};
111
130
  }
112
- &.disabled {
113
- color: ${theme.colors.disabled} !important;
114
- background-color: ${theme.colors.dark12} !important;
131
+ &.chip--disabled {
132
+ color: ${textDisabled} !important;
133
+ background-color: ${fillDisabled} !important;
134
+ border-color: ${lineDisabled} !important;
115
135
  pointer-events: none !important;
116
136
  .css-${ChipIcon.name} {
117
137
  path {
118
- fill: ${theme.colors.disabled} !important;
138
+ fill: ${textDisabled} !important;
119
139
  }
120
140
  }
121
141
  }
122
- &.readOnly {
142
+ &.chip--readOnly {
123
143
  cursor: unset !important;
124
144
  .css-${ChipIcon.name} {
125
145
  pointer-events: none !important;
126
146
  }
127
147
  }
128
148
  &.outlined {
129
- &.primary {
130
- color: ${theme.colors.primary};
131
- border-color: ${theme.colors.brand};
132
- }
133
- &.info {
134
- color: ${theme.colors.info};
135
- border-color: ${theme.colors.info5};
136
- }
137
- &.success {
138
- color: ${theme.colors.success};
139
- border-color: ${theme.colors.success};
140
- }
141
- &.warning {
142
- color: ${theme.colors.warning};
143
- border-color: ${theme.colors.warning};
144
- }
145
- &.danger {
146
- color: ${theme.colors.danger};
147
- border-color: ${theme.colors.danger};
149
+ &.${color} {
150
+ color: ${colors[color] || color};
151
+ border-color: ${colors[color] || color};
148
152
  }
149
153
  }
150
154
  &.filled {
151
- color: #FFF;
155
+ color: ${white};
152
156
  .clear-icon {
153
- color: #FFF;
157
+ color: ${white};
154
158
  &:hover {
155
- color: ${theme.colors.danger};
159
+ color: ${danger};
156
160
  }
157
161
  }
158
- &.primary {
159
- background-color: ${theme.colors.primary};
160
- border-color: #3D4D9E;
161
- }
162
- &.info {
163
- background-color: ${theme.colors.info5};
164
- border-color: ${theme.colors.info5};
165
- }
166
- &.success {
167
- background-color: ${theme.colors.success};
168
- border-color: ${theme.colors.success6};
169
- }
170
- &.warning {
171
- background-color: ${theme.colors.warning};
172
- border-color: ${theme.colors.warning6};
173
- }
174
- &.danger {
175
- background-color: ${theme.colors.danger};
176
- border-color: ${theme.colors.danger6};
162
+ &.${color} {
163
+ background-color: ${colors[color] || color};
164
+ border-color: ${darken(colors[color] || color, 0.22)};
177
165
  }
178
166
  }
179
167
  `;
@@ -185,9 +173,20 @@ const Chip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
185
173
  }, 0);
186
174
  };
187
175
 
188
- const handleClick = e => {
189
- if (!IconRef.current || !IconRef.current.contains(e.target)) {
190
- !!onClick && onClick();
176
+ const _onClick = event => {
177
+ onClick && event.stopPropagation();
178
+ if (disabled || loading) return;
179
+ onClick && onClick(event);
180
+ };
181
+
182
+ const _onDbClick = event => {
183
+ (onDbClick || onDoubleClick) && event.stopPropagation();
184
+ if (disabled || loading) return;
185
+
186
+ if (onDbClick) {
187
+ onDbClick && onDbClick(event);
188
+ } else if (onDoubleClick) {
189
+ onDoubleClick && onDoubleClick(event);
191
190
  }
192
191
  };
193
192
 
@@ -202,74 +201,77 @@ const Chip = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
202
201
  useEffect(() => {
203
202
  if (refs) refs(ref);
204
203
  }, []);
205
- useEffect(() => {
206
- if (color && color !== 'default') {
207
- ref.current.classList.add(viewType);
208
- ref.current.classList.add(color);
209
- }
204
+ useImperativeHandle(reference, () => {
205
+ const currentRef = ref.current || {};
206
+ const _instance = {}; // methods
210
207
 
211
- return () => {
212
- if (ref.current && color && color !== 'default') {
213
- ref.current.classList.remove(viewType);
214
- ref.current.classList.remove(color);
215
- }
216
- };
217
- }, [viewType, color]);
218
- useEffect(() => {
219
- if (disabled) {
220
- ref.current.classList.add('disabled');
208
+ _instance.__proto__ = {}; // hidden methods
209
+
210
+ currentRef.instance = _instance;
211
+ return currentRef;
212
+ });
213
+ const startIconView = useMemo(() => {
214
+ let node = startIcon;
215
+
216
+ if (typeof node === 'string') {
217
+ node = jsx(Icon, {
218
+ name: node,
219
+ width: iconSizeMap.get(size),
220
+ height: iconSizeMap.get(size),
221
+ color: 'currentColor',
222
+ viewBox: false
223
+ });
221
224
  }
222
225
 
223
- return () => {
224
- if (disabled && ref.current) {
225
- ref.current.classList.remove('disabled');
226
- }
227
- };
228
- }, [disabled]);
229
- useEffect(() => {
230
- if (readOnly) {
231
- ref.current.classList.add('readOnly');
226
+ return jsx("div", {
227
+ css: ChipIcon,
228
+ className: size
229
+ }, node);
230
+ }, [startIcon, size]);
231
+ const labelView = useMemo(() => {
232
+ return jsx("div", {
233
+ css: ChipLabel,
234
+ className: size
235
+ }, jsx(Typography, {
236
+ type: size === 'small' ? 'p2' : 'p1',
237
+ color: 'inherit'
238
+ }, renderLabel()));
239
+ }, [label]);
240
+ const endIconView = useMemo(() => {
241
+ let node = endIcon;
242
+
243
+ if (typeof node === 'string') {
244
+ node = jsx(Icon, {
245
+ name: node,
246
+ width: iconSizeMap.get(size),
247
+ height: iconSizeMap.get(size),
248
+ color: 'currentColor',
249
+ viewBox: false
250
+ });
232
251
  }
233
252
 
234
- return () => {
235
- if (readOnly && ref.current) {
236
- ref.current.classList.remove('readOnly');
237
- }
238
- };
239
- }, [readOnly]);
240
- const startIconView = useMemo(() => startIcon && jsx("div", {
241
- css: ChipIcon,
242
- className: size
243
- }, startIcon), [startIcon]);
244
- const labelView = useMemo(() => jsx("div", {
245
- css: ChipLabel,
246
- className: size
247
- }, jsx(Typography, {
248
- type: size === 'small' ? 'p2' : 'p1',
249
- color: 'inherit'
250
- }, renderLabel())), [label]);
251
- const endIconView = useMemo(() => clearAble ? jsx("div", {
252
- css: ChipIcon,
253
- className: 'end-icon ' + size,
254
- ref: IconRef
255
- }, jsx(ButtonIcon, {
256
- viewType: 'ghost',
257
- name: 'Close',
258
- className: 'clear-icon',
259
- color: viewType === 'outlined' && color ? 'inherit' : undefined,
260
- onClick: onRemoveHandler
261
- })) : endIcon && jsx("div", {
262
- css: ChipIcon,
263
- className: 'end-icon ' + size,
264
- ref: IconRef
265
- }, endIcon), [clearAble]);
253
+ return clearAble ? jsx("div", {
254
+ css: ChipIcon,
255
+ className: 'end-icon ' + size,
256
+ ref: IconRef
257
+ }, jsx(ButtonIcon, {
258
+ viewType: 'ghost',
259
+ name: 'Close',
260
+ color: viewType === 'outlined' && color ? 'inherit' : undefined,
261
+ onClick: onRemoveHandler
262
+ })) : endIcon && jsx("div", {
263
+ css: ChipIcon,
264
+ className: 'end-icon ' + size,
265
+ ref: IconRef
266
+ }, node);
267
+ }, [clearAble, endIcon, size]);
266
268
  return jsx("div", {
267
269
  css: ChipRoot,
268
270
  ref: ref,
269
- ...props,
270
- className: ['DGN-UI-Chip', size, className].join(' ').trim(),
271
- onClick: readOnly ? null : handleClick,
272
- onDoubleClick: onDbClick || onDoubleClick
271
+ 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, ' '),
272
+ onClick: _onClick,
273
+ onDoubleClick: _onDbClick,
274
+ ...props
273
275
  }, startIconView, labelView, endIconView, children);
274
276
  }));
275
277
  Chip.defaultProps = {