diginet-core-ui 1.3.51 → 1.3.52

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.
@@ -12,18 +12,22 @@ import { getGlobal } from '../../global';
12
12
  import AvatarDefault from '../../assets/avatar/default.svg';
13
13
  import { alignCenter, borderNone, displayBlock, displayNone, flexCol, inlineFlex, overflowHidden, parseWidthHeight, pointerEventsNone, positionAbsolute, positionRelative, userSelectNone } from '../../styles/general';
14
14
  import isMobile from '../../utils/isMobile';
15
- import { color as colors } from '../../styles/colors';
15
+ import theme from '../../theme/settings';
16
16
  const {
17
- system: {
18
- white
19
- },
20
- fill: {
21
- tooltip: fillTooltip
17
+ colors: {
18
+ system: {
19
+ white
20
+ },
21
+ fill: {
22
+ tooltip: fillTooltip
23
+ },
24
+ text: {
25
+ tooltip: textTooltip
26
+ }
22
27
  },
23
- text: {
24
- tooltip: textTooltip
25
- }
26
- } = colors;
28
+ spacing,
29
+ zIndex: zIndexCORE
30
+ } = theme;
27
31
  const existed = {},
28
32
  urlAvatar = {},
29
33
  popupHandler = {};
@@ -34,6 +38,18 @@ const blurKeyframe = keyframes`
34
38
  75% { -webkit-filter: blur(1px);}
35
39
  100% { -webkit-filter: blur(0px);}
36
40
  `;
41
+
42
+ const checkFileType = (type, matchType) => {
43
+ if (typeof matchType === 'object' && matchType instanceof RegExp) {
44
+ return matchType.test(type);
45
+ } else if (typeof matchType === 'object' && Array.isArray(matchType)) {
46
+ const pattern = new RegExp('^image/(' + matchType.join('|') + ')', 'i');
47
+ return pattern.test(type);
48
+ } else {
49
+ return new RegExp(matchType).test(type);
50
+ }
51
+ };
52
+
37
53
  const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
38
54
  src,
39
55
  defaultSrc,
@@ -56,7 +72,9 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
56
72
  readOnly,
57
73
  disabled,
58
74
  lazyLoading,
59
- id
75
+ id,
76
+ allowEdit,
77
+ onClick
60
78
  }, reference) => {
61
79
  if (!defaultSrc) defaultSrc = AvatarDefault;
62
80
  const ref = useRef(null);
@@ -94,23 +112,12 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
94
112
  }
95
113
  };
96
114
 
97
- const checkFileType = type => {
98
- if (typeof matchType === 'object' && matchType instanceof RegExp) {
99
- return matchType.test(type);
100
- } else if (typeof matchType === 'object' && Array.isArray(matchType)) {
101
- const pattern = new RegExp('^image/(' + matchType.join('|') + ')', 'i');
102
- return pattern.test(type);
103
- } else {
104
- return new RegExp(matchType).test(type);
105
- }
106
- };
107
-
108
115
  const onChangeAvatar = input => {
109
116
  const [file] = input.target.files;
110
117
  if (!file) return;
111
118
  const reader = new FileReader();
112
119
 
113
- if (!checkFileType(file.type)) {
120
+ if (!checkFileType(file.type, matchType)) {
114
121
  input.target.value = '';
115
122
  popupHandler[unique].show(wrongTypeError);
116
123
  return;
@@ -194,12 +201,15 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
194
201
  if (hoverAble) setViewMoreInfo(false);
195
202
  };
196
203
 
197
- const _onClick = () => {
204
+ const _onClick = event => {
205
+ onClick && event.stopPropagation();
198
206
  if (disabled) return;
199
207
 
200
208
  if (readOnly) {
201
209
  if (_isMobile) showMoreInfo();
202
- } else triggerInput();
210
+ } else {
211
+ allowEdit ? triggerInput() : onClick === null || onClick === void 0 ? void 0 : onClick(event);
212
+ }
203
213
  };
204
214
 
205
215
  const _onMouseEnter = () => {
@@ -264,7 +274,7 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
264
274
  onMouseLeave: _onMouseLeave,
265
275
  tabIndex: "-1",
266
276
  onBlur: closeMoreInfo
267
- }, renderImage())), !readOnly && !disabled && jsx("span", {
277
+ }, renderImage())), allowEdit && !readOnly && !disabled && jsx("span", {
268
278
  css: _ActionIconCSS
269
279
  }, jsx(ButtonIcon, {
270
280
  viewType: 'ghost',
@@ -315,7 +325,7 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
315
325
  icon: 'danger',
316
326
  fullScreen: true
317
327
  }));
318
- }, [width, height, readOnly, disabled, clearAble, maxSize, matchType, hoverAble, outlined, actionIconWidth, actionIconHeight, lazyLoading, defaultSrc, direction, data, maxSizeError, srcState, isInView, onLoaded, viewAvatar, viewMoreInfo]);
328
+ }, [width, height, readOnly, disabled, clearAble, maxSize, matchType, hoverAble, outlined, actionIconWidth, actionIconHeight, lazyLoading, defaultSrc, direction, data, maxSizeError, allowEdit, srcState, isInView, onLoaded, viewAvatar, viewMoreInfo]);
319
329
  }));
320
330
 
321
331
  const ActionIconCSS = actionIconWidth => css`
@@ -325,7 +335,7 @@ const ActionIconCSS = actionIconWidth => css`
325
335
  min-width: ${actionIconWidth}px;
326
336
  transition: opacity 0.5s;
327
337
  opacity: 0;
328
- z-index: 9002;
338
+ z-index: ${zIndexCORE(2)};
329
339
  `;
330
340
 
331
341
  const AvatarPreviewCSS = readOnly => css`
@@ -380,12 +390,13 @@ const AvatarRootCSS = (width, height, outlined) => css`
380
390
  const MoreInfoCSS = css`
381
391
  ${displayBlock};
382
392
  ${positionRelative};
383
- padding: 8px;
393
+ padding: ${spacing([2])};
384
394
  `;
385
395
  const blurAnimationCSS = css`
386
396
  animation: ${blurKeyframe} 1s ease;
387
397
  `;
388
398
  Avatar.defaultProps = {
399
+ allowEdit: false,
389
400
  disabled: false,
390
401
  readOnly: false,
391
402
  clearAble: true,
@@ -404,6 +415,9 @@ Avatar.defaultProps = {
404
415
  lazyLoading: false
405
416
  };
406
417
  Avatar.propTypes = {
418
+ /** If `true`, allow to edit avatar. */
419
+ allowEdit: PropTypes.bool,
420
+
407
421
  /** prevent all events, only view */
408
422
  disabled: PropTypes.bool,
409
423
 
@@ -470,12 +484,12 @@ Avatar.propTypes = {
470
484
  /** will run after change avatar */
471
485
  onChange: PropTypes.func,
472
486
 
487
+ /** Callback fired when the component is clicked. */
488
+ onClick: PropTypes.func,
489
+
473
490
  /** lazy loading */
474
491
  lazyLoading: PropTypes.bool,
475
492
 
476
- /** any props else */
477
- props: PropTypes.any,
478
-
479
493
  /**
480
494
  * ref methods
481
495
  *
@@ -6,36 +6,38 @@ import PropTypes from 'prop-types';
6
6
  import { jsx, css } from '@emotion/core';
7
7
  import { renderHTML } from '../../utils';
8
8
  import { Popover } from '..';
9
- import { typography } from '../../styles/typography';
10
9
  import { breakWord, displayBlock, displayInlineBlock, overflowHidden, positionRelative, textCapitalize, textCenter, textUppercase } from '../../styles/general';
11
10
  import { color as colors } from '../../styles/colors';
11
+ import theme from '../../theme/settings';
12
12
  const {
13
- title1,
14
- title2,
15
- title3,
16
- title4,
17
- heading1,
18
- heading2,
19
- heading3,
20
- heading4,
21
- heading5,
22
- heading6,
23
- paragraph1,
24
- paragraph2,
25
- paragraph3
26
- } = typography;
27
- const {
28
- system: {
29
- rest
30
- },
31
- text: {
32
- main,
33
- tooltip: textTooltip
13
+ colors: {
14
+ system: {
15
+ rest
16
+ },
17
+ text: {
18
+ main,
19
+ tooltip: textTooltip
20
+ },
21
+ fill: {
22
+ tooltip: fillTooltip
23
+ }
34
24
  },
35
- fill: {
36
- tooltip: fillTooltip
25
+ typography: {
26
+ title1,
27
+ title2,
28
+ title3,
29
+ title4,
30
+ heading1,
31
+ heading2,
32
+ heading3,
33
+ heading4,
34
+ heading5,
35
+ heading6,
36
+ paragraph1,
37
+ paragraph2,
38
+ paragraph3
37
39
  }
38
- } = colors;
40
+ } = theme;
39
41
  const typographyMap = new Map([['t1', title1], ['t2', title2], ['t3', title3], ['t4', title4], ['h1', heading1], ['h2', heading2], ['h3', heading3], ['h4', heading4], ['h5', heading5], ['h6', heading6], ['p1', paragraph1], ['p2', paragraph2], ['p3', paragraph3]]);
40
42
  const colorMap = new Map([['default', main], ['secondary', rest]]);
41
43
 
@@ -85,27 +87,31 @@ const Typography = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
85
87
  return Array.isArray(children) && !children.some(node => node && String(node.$$typeof) === 'Symbol(react.element)') ? children.join('') : children;
86
88
  };
87
89
 
88
- const renderTooltip = useMemo(() => jsx(Popover, {
89
- open: openTooltip,
90
- pressESCToClose: false,
91
- bgColor: fillTooltip,
92
- anchor: ref,
93
- fullScreen: false,
94
- width: 'max-content',
95
- style: {
96
- color: textTooltip
97
- },
98
- onMouseEnter: () => setHoverTooltip(true, true),
99
- onMouseLeave: () => setHoverTooltip(false, true),
100
- direction: tooltipDirection
101
- }, renderHTML(renderChildren(), mapping, {
102
- css: _TextRootCSS,
103
- className: classNames(true),
104
- style: {
105
- color: textTooltip,
106
- padding: '4px 6px'
107
- }
108
- })), [openTooltip, tooltipDirection, children, mapping, color, type, lineClamp]);
90
+ const renderTooltip = useMemo(() => {
91
+ var _ref$current;
92
+
93
+ return jsx(Popover, {
94
+ open: openTooltip,
95
+ pressESCToClose: false,
96
+ bgColor: fillTooltip,
97
+ anchor: ref,
98
+ fullScreen: false,
99
+ width: ((_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.clientWidth) || 'max-content',
100
+ style: {
101
+ color: textTooltip
102
+ },
103
+ onMouseEnter: () => setHoverTooltip(true, true),
104
+ onMouseLeave: () => setHoverTooltip(false, true),
105
+ direction: tooltipDirection
106
+ }, renderHTML(renderChildren(), mapping, {
107
+ css: _TextRootCSS,
108
+ className: classNames(true),
109
+ style: {
110
+ color: textTooltip,
111
+ padding: '4px 6px'
112
+ }
113
+ }));
114
+ }, [openTooltip, tooltipDirection, children, mapping, color, type, lineClamp]);
109
115
  return jsx(Fragment, null, renderHTML(renderChildren(), mapping, {
110
116
  ref: ref,
111
117
  css: _TextRootCSS,
@@ -172,42 +178,43 @@ Typography.defaultProps = {
172
178
 
173
179
  export const arrTypeTypography = ['t1', 't2', 't3', 't4', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p1', 'p2', 'p3', 'title1', 'title2', 'title3', 'title4', 'heading1', 'heading2', 'heading3', 'heading4', 'heading5', 'heading6', 'paragraph1', 'paragraph2', 'paragraph3'];
174
180
  Typography.propTypes = {
175
- type: PropTypes.oneOf(arrTypeTypography),
181
+ /** If `true`, text-transform is capitalized. It overrides the value of the `uppercase` prop. */
182
+ capitalize: PropTypes.bool,
176
183
 
177
- /** color of text ['primary', 'secondary', 'success', 'warning', 'danger', 'info', '#hex', rgb(#,#,#)] */
178
- color: PropTypes.string,
184
+ /** If `true`, text-align is center. */
185
+ center: PropTypes.bool,
179
186
 
180
- /** mapping with the html tag */
181
- mapping: PropTypes.string,
187
+ /** The content of the component. */
188
+ children: PropTypes.node,
182
189
 
183
- /** class of Typography component */
190
+ /** Class for component. */
184
191
  className: PropTypes.string,
185
192
 
186
- /** text-align is center if true */
187
- center: PropTypes.bool,
193
+ /** Color of text ['primary', 'secondary', 'success', 'warning', 'danger', 'info', '#hex', rgb(#,#,#)]. */
194
+ color: PropTypes.string,
188
195
 
189
- /** text-transform is uppercase if true */
190
- uppercase: PropTypes.bool,
196
+ /** If true, the component will take up the full width of its container. */
197
+ fullWidth: PropTypes.bool,
191
198
 
192
- /** text-transform is capitalized if true (and uppercase is false) */
193
- capitalize: PropTypes.bool,
199
+ /** If `true`, hover will show tooltip when text clamped. */
200
+ hoverTooltip: PropTypes.bool,
194
201
 
195
202
  /** The line-clamp property truncates text at a specific number of lines. */
196
203
  lineClamp: PropTypes.number,
197
204
 
198
- /** If true, hover will show tooltip when text clamped. */
199
- hoverTooltip: PropTypes.bool,
205
+ /** The component used for the root node. Either a string to use a HTML element or a component. */
206
+ mapping: PropTypes.string,
200
207
 
201
- /** Tooltip direction */
202
- tooltipDirection: PropTypes.oneOf(['top', 'bottom', 'left', 'right']),
208
+ /** Accepts all props which `mapping` tag support. */
209
+ props: PropTypes.object,
203
210
 
204
- /** allows maximum screen width if true */
205
- fullWidth: PropTypes.bool,
211
+ /** Tooltip direction. */
212
+ tooltipDirection: PropTypes.oneOf(['top', 'bottom', 'left', 'right']),
206
213
 
207
- /** content to display (like text) */
208
- children: PropTypes.node,
214
+ /** Applies the theme typography styles. */
215
+ type: PropTypes.oneOf(arrTypeTypography),
209
216
 
210
- /** any props else */
211
- props: PropTypes.object
217
+ /** If `true`, text-transform is uppercase. */
218
+ uppercase: PropTypes.bool
212
219
  };
213
220
  export default Typography;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diginet-core-ui",
3
- "version": "1.3.51",
3
+ "version": "1.3.52",
4
4
  "description": "The DigiNet core ui",
5
5
  "homepage": "https://diginet.com.vn",
6
6
  "main": "index.js",
package/readme.md CHANGED
@@ -38,6 +38,10 @@ npm test
38
38
  ```
39
39
 
40
40
  ## Changelog
41
+ ## 1.3.52
42
+ - \[Fixed\]: Avatar – Add props onClick, allowEdit
43
+ - \[Fixed\]: Typography – Fix tooltip width fit Typography
44
+
41
45
  ## 1.3.51
42
46
  - \[Fixed\]: THEME – Fix bug makeStyles add duplicate style tag into head tag
43
47
  - \[Fixed\]: Accordion – Change css AccordionSummary; Fix when children of AccordionGroup null