diginet-core-ui 1.3.33-beta.1 → 1.3.33

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,3 +1,3 @@
1
- <svg width="24" height="24" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
2
- <path fill-rule="evenodd" clip-rule="evenodd" d="M10 0C4.47998 0 0 4.48 0 10C0 15.52 4.47998 20 10 20C15.52 20 20 15.52 20 10C20 4.48 15.52 0 10 0ZM10 3C11.66 3 13 4.34 13 6C13 7.66 11.66 9 10 9C8.34003 9 7 7.66 7 6C7 4.34 8.34003 3 10 3ZM4 13.98C5.28998 15.92 7.5 17.2 10 17.2C12.5 17.2 14.71 15.92 16 13.98C15.97 11.99 11.99 10.9 10 10.9C8 10.9 4.03003 11.99 4 13.98Z" fill="#7F828E"/>
1
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M12 2C6.48 2 2 6.48 2 12C2 17.52 6.48 22 12 22C17.52 22 22 17.52 22 12C22 6.48 17.52 2 12 2ZM12 5C13.66 5 15 6.34 15 8C15 9.66 13.66 11 12 11C10.34 11 9 9.66 9 8C9 6.34 10.34 5 12 5ZM6 15.98C7.29 17.92 9.5 19.2 12 19.2C14.5 19.2 16.71 17.92 18 15.98C17.97 13.99 13.99 12.9 12 12.9C10 12.9 6.03 13.99 6 15.98Z" fill="#7F828E"/>
3
3
  </svg>
@@ -1,27 +1,13 @@
1
1
  /** @jsxRuntime classic */
2
2
 
3
3
  /** @jsx jsx */
4
- import { Fragment, memo, useRef, forwardRef, useState, useEffect, useMemo, useImperativeHandle } from 'react';
4
+ import { Fragment, memo, useRef, forwardRef, useState, useEffect, useMemo } from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { jsx, css } from '@emotion/core';
7
- import OptionWrapper from '../others/option-wrapper';
7
+ import { Account } from '../../icons';
8
8
  import { ButtonIcon, ModalSample, Popover, Popup, Typography } from '../';
9
9
  import { randomString } from '../../utils';
10
10
  import { getGlobal } from '../../global';
11
- import { alignCenter, borderNone, displayBlock, inlineFlex, overflowHidden, pointerEventsNone, positionAbsolute, positionRelative, userSelectNone } from '../../styles/general';
12
- import isMobile from '../../utils/isMobile';
13
- import { color as colors } from '../../styles/colors';
14
- const {
15
- system: {
16
- white
17
- },
18
- fill: {
19
- tooltip: fillTooltip
20
- },
21
- text: {
22
- tooltip: textTooltip
23
- }
24
- } = colors;
25
11
  const existed = {},
26
12
  urlAvatar = {},
27
13
  popupHandler = {};
@@ -78,6 +64,26 @@ const getDirection = direction => {
78
64
  }
79
65
  };
80
66
 
67
+ const isMobile = {
68
+ iOS: function () {
69
+ return navigator.userAgent.match(/iPhone|iPad|iPod/i);
70
+ },
71
+ Android: function () {
72
+ return navigator.userAgent.match(/Android/i);
73
+ },
74
+ BlackBerry: function () {
75
+ return navigator.userAgent.match(/BlackBerry/i);
76
+ },
77
+ Opera: function () {
78
+ return navigator.userAgent.match(/Opera Mini/i);
79
+ },
80
+ Windows: function () {
81
+ return navigator.userAgent.match(/IEMobile/i) || navigator.userAgent.match(/WPDesktop/i);
82
+ },
83
+ any: function () {
84
+ return isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows();
85
+ }
86
+ };
81
87
  const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
82
88
  refs,
83
89
  src,
@@ -101,8 +107,11 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
101
107
  readOnly,
102
108
  disabled,
103
109
  ...props
104
- }, reference) => {
105
- const ref = useRef(null);
110
+ }, ref) => {
111
+ if (!ref) {
112
+ ref = useRef(null);
113
+ }
114
+
106
115
  const inputRef = useRef(null);
107
116
  const avatarRef = useRef(null);
108
117
  const [unique] = useState(randomString(6, {
@@ -111,11 +120,6 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
111
120
  }));
112
121
  const [viewAvatar, setViewAvatar] = useState(false);
113
122
  const [viewMoreInfo, setViewMoreInfo] = useState(false);
114
- const [srcState, setSrcState] = useState(src);
115
-
116
- const _isMobile = isMobile.any();
117
-
118
- if (!defaultSrc) defaultSrc = require('../../assets/avatar/default.svg');
119
123
 
120
124
  if (width && !height) {
121
125
  height = width;
@@ -125,31 +129,34 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
125
129
  width = height;
126
130
  }
127
131
 
132
+ const iconDefault = `<svg width="${width}" height="${height}" viewBox="0 0 24 24" fill="none">
133
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M12 2C6.47998 2 2 6.48 2 12C2 17.52 6.47998 22 12 22C17.52 22 22 17.52 22 12C22 6.48 17.52 2 12 2ZM12 5C13.66 5 15 6.34 15 8C15 9.66 13.66 11 12 11C10.34 11 9 9.66 9 8C9 6.34 10.34 5 12 5ZM6 15.98C7.28998 17.92 9.5 19.2 12 19.2C14.5 19.2 16.71 17.92 18 15.98C17.97 13.99 13.99 12.9 12 12.9C10 12.9 6.03003 13.99 6 15.98Z" fill="#7F828E"></path>
134
+ </svg>`;
128
135
  const ActionIcon = css`
129
- ${positionAbsolute}
136
+ position: absolute;
130
137
  right: -36px;
131
138
  transition: opacity 0.5s;
132
139
  opacity: 0;
133
140
  .icon-delete {
134
- display: flex;
141
+ display: none;
135
142
  }
136
143
  `;
137
144
  const AvatarPreview = css`
138
- ${displayBlock}
139
- ${positionRelative}
140
- ${overflowHidden}
145
+ display: block;
146
+ position: relative;
141
147
  width: 100%;
142
148
  height: 100%;
143
149
  border-radius: 50%;
150
+ overflow: hidden;
144
151
  cursor: ${readOnly ? 'initial' : 'pointer'};
145
152
  `;
146
153
  const AvatarContainer = css`
147
- ${inlineFlex}
148
- ${positionRelative}
149
- ${alignCenter}
154
+ display: inline-flex;
155
+ position: relative;
156
+ align-items: center;
150
157
  &.disabled {
151
158
  .css-${AvatarPreview.name} {
152
- ${pointerEventsNone}
159
+ pointer-events: none;
153
160
  cursor: inherit;
154
161
  }
155
162
  .css-${ActionIcon.name} {
@@ -163,33 +170,34 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
163
170
  }
164
171
  `;
165
172
  const AvatarRoot = css`
166
- ${displayBlock}
167
- ${positionRelative}
168
- ${overflowHidden}
169
- ${userSelectNone}
170
- ${borderNone}
173
+ display: block;
174
+ position: relative;
171
175
  border-radius: 50%;
172
176
  width: ${isNaN(width) ? width : width + 'px'};
173
177
  height: ${isNaN(height) ? height : height + 'px'};
178
+ overflow: hidden;
174
179
  box-sizing: content-box;
175
- border: ${typeof outlined === 'boolean' && outlined ? `1px solid ${white}` : outlined};
180
+ user-select: none;
181
+ border: none;
176
182
  input {
177
183
  display: none;
178
184
  }
179
185
  img {
186
+ background-image: url(${require('../../assets/avatar/default.svg')});
187
+ background-size: cover;
180
188
  width: 100%;
181
189
  height: 100%;
182
190
  }
183
191
  `;
184
192
  const MoreInfo = css`
185
- ${displayBlock}
186
- ${positionRelative}
193
+ display: block;
194
+ position: relative;
187
195
  padding: 8px;
188
196
  `;
189
197
 
190
198
  const triggerInput = e => {
191
- if (e || !existed[unique]) {
192
- inputRef.current.click();
199
+ if (!e || !existed[unique]) {
200
+ ref.current.querySelector('input').click();
193
201
  } else {
194
202
  // on View
195
203
  setViewAvatar(true);
@@ -225,8 +233,18 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
225
233
  }
226
234
 
227
235
  reader.onload = e => {
236
+ const img = document.createElement('img');
228
237
  urlAvatar[unique] = e.target.result;
229
- setSrcState(urlAvatar[unique]);
238
+ img.src = urlAvatar[unique];
239
+ img.alt = '';
240
+ img.style.cssText = 'object-fit: cover';
241
+ ref.current.querySelector(`.css-${AvatarPreview.name}`).innerHTML = '';
242
+ ref.current.querySelector(`.css-${AvatarPreview.name}`).appendChild(img);
243
+
244
+ if (!readOnly && clearAble) {
245
+ ref.current.querySelector(`.icon-delete`).style.display = 'flex';
246
+ }
247
+
230
248
  existed[unique] = true;
231
249
  };
232
250
 
@@ -235,29 +253,39 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
235
253
  };
236
254
 
237
255
  const onRemoveAvatar = () => {
238
- setSrcState(null);
256
+ if (defaultSrc) {
257
+ ref.current.querySelector('img').src = defaultSrc;
258
+ } else {
259
+ ref.current.querySelector(`.css-${AvatarPreview.name}`).innerHTML = iconDefault;
260
+ }
261
+
239
262
  existed[unique] = false;
240
263
  inputRef.current.value = '';
264
+
265
+ if (!readOnly && clearAble) {
266
+ ref.current.querySelector(`.icon-delete`).style.display = null;
267
+ }
268
+
241
269
  !!onRemove && onRemove();
242
270
  };
243
271
 
244
272
  const renderData = () => {
245
- const info = Object.keys(data || {});
273
+ const info = Object.keys(data);
246
274
 
247
275
  if (info.length) {
248
276
  return info.map((key, index) => {
249
277
  return jsx(Typography, {
250
278
  key: index,
251
- color: textTooltip,
279
+ color: 'white',
252
280
  type: 'p1'
253
281
  }, key + ': ' + data[key]);
254
282
  });
255
283
  }
256
284
 
257
285
  return jsx(Typography, {
258
- color: textTooltip,
286
+ color: 'white',
259
287
  type: 'p1'
260
- }, getGlobal('noDataText'));
288
+ }, "Kh\xF4ng c\xF3 d\u1EEF li\u1EC7u");
261
289
  };
262
290
 
263
291
  const showMoreInfo = () => {
@@ -268,58 +296,95 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
268
296
  if (hoverAble) setViewMoreInfo(false);
269
297
  };
270
298
 
271
- const _onClick = () => {
272
- if (disabled) return;
273
-
274
- if (readOnly) {
275
- if (_isMobile) showMoreInfo();
276
- } else triggerInput();
277
- };
278
-
279
- const _onMouseEnter = () => {
280
- if (!_isMobile) showMoreInfo();
281
- };
282
-
283
- const _onMouseLeave = () => {
284
- if (!_isMobile) closeMoreInfo();
285
- };
286
-
287
299
  useEffect(() => {
288
300
  if (refs) refs(ref);
289
301
  }, []);
302
+ useEffect(() => {
303
+ if (outlined) {
304
+ ref.current.querySelector(`.css-${AvatarRoot.name}`).style.border = typeof outlined === 'boolean' ? '1px solid #FFF' : outlined;
305
+ return () => {
306
+ if (ref.current) {
307
+ ref.current.querySelector(`.css-${AvatarRoot.name}`).style.border = null;
308
+ }
309
+ };
310
+ }
311
+ }, [outlined]);
312
+ useEffect(() => {
313
+ if (!readOnly && clearAble && src) {
314
+ ref.current.querySelector(`.icon-delete`).style.display = 'flex';
315
+ }
316
+ }, [clearAble]); // useEffect(() => {
317
+ // if (hoverAble) {
318
+ // avatarRef.current.addEventListener('mouseenter', showMoreInfo);
319
+ // avatarRef.current.addEventListener('mouseleave', closeMoreInfo);
320
+ // }
321
+ // return () => {
322
+ // if (hoverAble && avatarRef.current) {
323
+ // avatarRef.current.removeEventListener('mouseenter', showMoreInfo);
324
+ // avatarRef.current.removeEventListener('mouseleave', closeMoreInfo);
325
+ // }
326
+ // };
327
+ // }, [hoverAble])
328
+
290
329
  useEffect(() => {
291
330
  if (src) {
331
+ existed[unique] = true;
292
332
  inputRef.current.value = '';
293
333
  const img = document.createElement('img');
294
334
  urlAvatar[unique] = src;
295
335
  img.src = src;
296
336
  img.alt = '';
297
- setSrcState(src);
298
- existed[unique] = true;
299
337
 
300
338
  img.onerror = e => {
301
- setSrcState(null);
339
+ if (defaultSrc) {
340
+ e.target.src = defaultSrc;
341
+ } else {
342
+ if (ref.current) ref.current.querySelector(`.css-${AvatarPreview.name}`).innerHTML = iconDefault;
343
+ }
344
+ };
345
+
346
+ img.style.cssText = 'object-fit: cover';
347
+ ref.current.querySelector(`.css-${AvatarPreview.name}`).innerHTML = '';
348
+ ref.current.querySelector(`.css-${AvatarPreview.name}`).appendChild(img);
349
+
350
+ if (!readOnly && clearAble) {
351
+ ref.current.querySelector(`.icon-delete`).style.display = 'flex';
352
+ }
353
+
354
+ return () => {
302
355
  existed[unique] = false;
356
+
357
+ if (ref.current) {
358
+ if (defaultSrc) {
359
+ ref.current.querySelector('img').src = defaultSrc;
360
+ } else {
361
+ ref.current.querySelector(`.css-${AvatarPreview.name}`).innerHTML = iconDefault;
362
+ }
363
+
364
+ if (!readOnly && clearAble && ref.current.querySelector(`.icon-delete`)) {
365
+ ref.current.querySelector(`.icon-delete`).style.display = null;
366
+ }
367
+ }
303
368
  };
304
369
  }
305
370
  }, [src]);
306
- useImperativeHandle(reference, () => {
307
- const currentRef = ref.current || {};
308
- const _instance = {}; // methods
309
-
310
- _instance.__proto__ = {}; // hidden methods
311
-
312
- currentRef.instance = _instance;
313
- return currentRef;
314
- });
371
+ useEffect(() => {
372
+ if (disabled) {
373
+ ref.current.classList.add('disabled');
374
+ return () => {
375
+ if (ref.current) {
376
+ ref.current.classList.remove('disabled');
377
+ }
378
+ };
379
+ }
380
+ }, [disabled]);
315
381
  const AvatarView = useMemo(() => jsx("div", {
316
382
  css: AvatarContainer,
317
383
  ref: ref,
318
- id: unique,
319
- className: disabled ? 'disabled' : ''
384
+ id: unique
320
385
  }, jsx("div", {
321
386
  css: AvatarRoot,
322
- className: ['DGN-UI-Avatar', className].join(' ').trim().replace(/\s+/g, ' '),
387
+ className: ['DGN-UI-Avatar', className].join(' ').trim(),
323
388
  ...props
324
389
  }, jsx("input", {
325
390
  ref: inputRef,
@@ -329,18 +394,22 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
329
394
  onChange: onChangeAvatar
330
395
  }), jsx("div", {
331
396
  css: AvatarPreview,
332
- onClick: _onClick,
397
+ onClick: readOnly ? isMobile.any() ? showMoreInfo : null : triggerInput,
333
398
  ref: avatarRef,
334
- onMouseEnter: _onMouseEnter,
335
- onMouseLeave: _onMouseLeave,
399
+ onMouseEnter: isMobile.any() ? null : showMoreInfo,
400
+ onMouseLeave: isMobile.any() ? null : closeMoreInfo,
336
401
  tabIndex: "-1",
337
402
  onBlur: closeMoreInfo
338
- }, jsx("img", {
339
- src: srcState || defaultSrc,
340
- alt: srcState || defaultSrc,
403
+ }, defaultSrc ? jsx("img", {
404
+ src: defaultSrc,
405
+ alt: defaultSrc,
341
406
  style: {
342
407
  objectFit: 'cover'
343
408
  }
409
+ }) : jsx(Account, {
410
+ width: width,
411
+ height: height,
412
+ viewBox: true
344
413
  }))), !readOnly && !disabled && jsx("span", {
345
414
  css: ActionIcon
346
415
  }, jsx(ButtonIcon, {
@@ -349,8 +418,8 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
349
418
  width: actionIconWidth,
350
419
  height: actionIconHeight,
351
420
  className: 'icon-edit',
352
- onClick: triggerInput
353
- }), clearAble && srcState && jsx(ButtonIcon, {
421
+ onClick: () => triggerInput()
422
+ }), clearAble && jsx(ButtonIcon, {
354
423
  viewType: 'ghost',
355
424
  name: 'Delete',
356
425
  width: actionIconWidth,
@@ -360,7 +429,7 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
360
429
  style: {
361
430
  marginTop: '8px'
362
431
  }
363
- }))), [width, height, readOnly, disabled, clearAble, maxSize, matchType, hoverAble, outlined, srcState]);
432
+ }))), [width, height, readOnly, disabled, clearAble, maxSize, matchType, hoverAble]);
364
433
  const ModalView = useMemo(() => jsx(ModalSample, {
365
434
  open: viewAvatar,
366
435
  onClose: () => setViewAvatar(false),
@@ -377,10 +446,9 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
377
446
  }
378
447
  })), [viewAvatar]);
379
448
  const MoreInfoView = useMemo(() => jsx(Popover, {
380
- arrow: true,
381
449
  open: viewMoreInfo,
382
450
  pressESCToClose: false,
383
- bgColor: fillTooltip,
451
+ bgColor: '#000',
384
452
  anchor: avatarRef,
385
453
  fullScreen: false,
386
454
  width: 'max-content',
@@ -405,6 +473,8 @@ Avatar.defaultProps = {
405
473
  outlined: false,
406
474
  width: 48,
407
475
  height: 48,
476
+ actionIconWidth: '100%',
477
+ actionIconHeight: '100%',
408
478
  className: '',
409
479
  direction: 'down',
410
480
  maxSizeError: `File ${getGlobal(['errorDefault', 'maxSize'])}`,
@@ -483,25 +553,6 @@ Avatar.propTypes = {
483
553
  onChange: PropTypes.func,
484
554
 
485
555
  /** any props else */
486
- props: PropTypes.any,
487
-
488
- /**
489
- * ref methods
490
- *
491
- * * option(): Gets all UI component properties
492
- * * Returns value - object
493
- * * option(optionName): Gets the value of a single property
494
- * * @param {optionName} - string
495
- * * Returns value - any
496
- * * option(optionName, optionValue): Updates the value of a single property
497
- * * @param {optionName} - string
498
- * * @param {optionValue} - any
499
- * * option(options): Updates the values of several properties
500
- * * @param {options} - object
501
- */
502
- reference: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
503
- current: PropTypes.instanceOf(Element)
504
- })])
556
+ props: PropTypes.any
505
557
  };
506
- export { Avatar };
507
- export default OptionWrapper(Avatar);
558
+ export default Avatar;