diginet-core-ui 1.4.14-beta.2 → 1.4.14-beta.4

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.
Files changed (128) hide show
  1. package/components/accordion/details.js +36 -25
  2. package/components/accordion/group.js +33 -18
  3. package/components/accordion/index.js +42 -28
  4. package/components/accordion/summary.js +60 -52
  5. package/components/alert/index.js +84 -75
  6. package/components/alert/notify.js +43 -31
  7. package/components/avatar/index.js +78 -75
  8. package/components/badge/index.js +62 -60
  9. package/components/breadcrumb/index.js +62 -44
  10. package/components/button/icon.js +69 -49
  11. package/components/button/index.js +97 -75
  12. package/components/button/more.js +60 -39
  13. package/components/button/ripple-effect.js +1 -1
  14. package/components/card/body.js +25 -15
  15. package/components/card/extra.js +25 -15
  16. package/components/card/footer.js +25 -15
  17. package/components/card/header.js +26 -15
  18. package/components/card/index.js +66 -57
  19. package/components/chart/bar/Labels.js +14 -8
  20. package/components/chart/bar-v2/Labels.js +14 -8
  21. package/components/chart/line/Labels.js +14 -8
  22. package/components/chart/line/Path.js +3 -3
  23. package/components/chart/line/Point.js +12 -11
  24. package/components/chart/line-v2/Labels.js +14 -8
  25. package/components/check-text/index.js +21 -16
  26. package/components/check-text/interview-confirmation.js +21 -15
  27. package/components/check-text/interview-status.js +21 -15
  28. package/components/chip/attach.js +6 -2
  29. package/components/chip/index.js +83 -82
  30. package/components/collapse/index.js +1 -1
  31. package/components/dialogs/colors.js +13 -11
  32. package/components/divider/index.js +40 -22
  33. package/components/form-control/attachment/index.js +73 -36
  34. package/components/form-control/calendar/function.js +42 -38
  35. package/components/form-control/calendar/index.js +32 -20
  36. package/components/form-control/calendar/range.js +38 -22
  37. package/components/form-control/checkbox/index.js +83 -59
  38. package/components/form-control/control/index.js +9 -10
  39. package/components/form-control/date-picker/index.js +81 -64
  40. package/components/form-control/date-range-picker/index.js +92 -75
  41. package/components/form-control/dropdown/index.js +243 -216
  42. package/components/form-control/dropdown-box/index.js +56 -43
  43. package/components/form-control/form-group/index.js +7 -6
  44. package/components/form-control/helper-text/index.js +45 -41
  45. package/components/form-control/input-base/index.js +165 -133
  46. package/components/form-control/label/index.js +48 -41
  47. package/components/form-control/money-input/index.js +76 -68
  48. package/components/form-control/number-input/index.js +579 -521
  49. package/components/form-control/number-input/index2.js +89 -69
  50. package/components/form-control/password-input/index.js +67 -59
  51. package/components/form-control/radio/index.js +85 -69
  52. package/components/form-control/text-input/index.js +79 -70
  53. package/components/form-control/time-picker/index.js +79 -56
  54. package/components/form-control/time-picker/v2/index.js +22 -16
  55. package/components/form-control/toggle/index.js +140 -129
  56. package/components/form-view/helper-text.js +2 -2
  57. package/components/form-view/index.js +34 -31
  58. package/components/form-view/input.js +70 -69
  59. package/components/form-view/label.js +14 -9
  60. package/components/grid/Col.js +48 -39
  61. package/components/grid/Container.js +31 -38
  62. package/components/grid/Row.js +28 -32
  63. package/components/grid/index.js +66 -54
  64. package/components/image/index.js +37 -27
  65. package/components/list/list-item-action.js +36 -26
  66. package/components/list/list-item-icon.js +34 -29
  67. package/components/list/list-item-text.js +27 -22
  68. package/components/list/list-item.js +42 -36
  69. package/components/list/list.js +46 -38
  70. package/components/list/sub-header.js +33 -26
  71. package/components/modal/body.js +24 -14
  72. package/components/modal/footer.js +23 -13
  73. package/components/modal/header.js +39 -28
  74. package/components/modal/index.js +3 -3
  75. package/components/modal/modal.js +60 -49
  76. package/components/others/extra/index.js +31 -30
  77. package/components/others/import/index.js +2 -2
  78. package/components/others/scrollbar/index.js +32 -26
  79. package/components/paging/page-info.js +33 -34
  80. package/components/paging/page-selector.js +15 -15
  81. package/components/paper/index.js +32 -28
  82. package/components/popover/body.js +14 -8
  83. package/components/popover/footer.js +13 -8
  84. package/components/popover/header.js +17 -15
  85. package/components/popover/index.js +71 -60
  86. package/components/popup/danger_popup.js +17 -16
  87. package/components/popup/index.js +16 -17
  88. package/components/popup/v2/index.js +28 -41
  89. package/components/progress/circular.js +65 -80
  90. package/components/progress/linear.js +73 -58
  91. package/components/rating/index.js +41 -55
  92. package/components/slider/slider-container.js +49 -57
  93. package/components/slider/slider-item.js +30 -29
  94. package/components/status/index.js +23 -34
  95. package/components/tab/tab-header.js +20 -11
  96. package/components/tab/tab-panel.js +12 -7
  97. package/components/tab/tab.js +35 -22
  98. package/components/tooltip/index.js +24 -35
  99. package/components/transfer/index.js +102 -103
  100. package/components/tree-view/index.js +99 -81
  101. package/components/typography/index.js +62 -45
  102. package/global/index.js +2 -17
  103. package/icons/basic.js +975 -972
  104. package/icons/effect.js +8 -7
  105. package/package.json +3 -1
  106. package/styles/color-helper.js +2 -2
  107. package/styles/colors.js +168 -30
  108. package/styles/general.js +73 -5
  109. package/styles/sx/index.js +7 -4
  110. package/styles/utils.js +6 -5
  111. package/theme/createSpacing.js +10 -0
  112. package/theme/createTheme.js +26 -0
  113. package/theme/createZIndex.js +9 -0
  114. package/theme/index.js +13 -2
  115. package/theme/make-styles.js +2 -1
  116. package/theme/settings.js +699 -8
  117. package/theme/theme-provider.js +32 -15
  118. package/theme/theme.js +57 -56
  119. package/theme/use-classes.js +15 -0
  120. package/theme/utils/getThemeProps.js +12 -0
  121. package/theme/utils/resolveProps.js +17 -0
  122. package/theme/utils/useThemeProps.js +14 -0
  123. package/utils/handleBreakpoints.js +2 -2
  124. package/utils/hexToRGBA/index.js +2 -2
  125. package/utils/object/deepmerge.js +104 -0
  126. package/utils/object/object.js +7 -12
  127. package/utils/render-portal.js +4 -3
  128. package/theme/set-theme.js +0 -38
@@ -1,70 +1,64 @@
1
1
  /** @jsxRuntime classic */
2
2
  /** @jsx jsx */
3
- import { forwardRef, memo, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
3
+ import { css, jsx } from '@emotion/core';
4
+ import { ButtonIcon, Icon, LinearProgress } from "./..";
4
5
  import PropTypes from 'prop-types';
5
- import { jsx, css } from '@emotion/core';
6
- import LinearProgress from "../progress/linear";
7
- import ButtonIcon from "../button/icon";
8
- import Icon from "../../icons";
9
- import { hexToRGBA } from "../../styles/color-helper";
6
+ import { forwardRef, memo, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
10
7
  import { animations } from "../../styles/animation";
11
- import { classNames, useDelayUnmount } from "../../utils";
12
- import { itemsCenter, border, boxBorder, borderRadius4px, breakWord, displayBlock, flexRow, justifyStart, positionRelative, userSelectNone } from "../../styles/general";
13
- import { useTheme, useColor as colors } from "../../theme";
14
- const {
15
- colors: {
16
- system: {
17
- white: systemWhite
18
- }
19
- },
20
- typography: {
21
- heading3,
22
- heading4,
23
- heading5,
24
- paragraph1,
25
- paragraph2,
26
- paragraph3
27
- },
28
- spacing,
29
- zIndex: zIndexCORE
30
- } = useTheme();
8
+ import { bgColor, border, borderRadius4px, boxBorder, breakWord, displayBlock, flexRow, itemsCenter, justifyStart, positionRelative, textColor, userSelectNone } from "../../styles/general";
9
+ import { useTheme } from "../../theme";
10
+ import useThemeProps from "../../theme/utils/useThemeProps";
11
+ import { classNames, getProp, hexToRGBA, useDelayUnmount } from "../../utils";
31
12
  const iconMap = new Map([['info', 'Info'], ['success', 'ApprovalFilled'], ['warning', 'Warning'], ['danger', 'CancelFilled']]);
32
13
  const maxWidthMap = new Map([['tiny', 320], ['small', 400], ['medium', 480]]);
33
- const primaryTypoMap = new Map([['tiny', heading5], ['small', heading4], ['medium', heading3]]);
14
+ const primaryTypoMap = new Map([['tiny', 'typography.heading5'], ['small', 'typography.heading4'], ['medium', 'typography.heading3']]);
34
15
  const iconSizeMap = new Map([['tiny', 16], ['small', 20], ['medium', 24]]);
35
16
  const linearProgressSizeMap = new Map([['tiny', 2], ['small', 3], ['medium', 4]]);
36
17
  const transitionTime = 300;
37
- const Alert = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
38
- action = {},
39
- autoDisappear,
40
- children,
41
- className,
42
- clearAble,
43
- color,
44
- duration,
45
- onClose,
46
- progressing,
47
- secondary,
48
- size,
49
- text,
50
- type
51
- }, reference) => {
52
- type = type || color;
18
+ const Alert = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference) => {
19
+ if (!reference) reference = useRef(null);
20
+ const theme = useTheme();
21
+ const {
22
+ colors
23
+ } = theme;
24
+
25
+ // props priority: `inProps` > `themeDefaultProps`
26
+ const props = useThemeProps({
27
+ props: inProps,
28
+ name: 'Alert'
29
+ });
30
+ const {
31
+ action = {},
32
+ autoDisappear,
33
+ children,
34
+ className,
35
+ clearAble,
36
+ color,
37
+ duration,
38
+ onClose,
39
+ progressing,
40
+ secondary,
41
+ size,
42
+ text,
43
+ type: typeProp
44
+ } = props;
45
+ const type = typeProp || color;
53
46
  const ref = useRef(null);
54
47
  const clearIconRef = useRef(null);
55
48
  const [percentState, setPercentState] = useState(100);
56
49
  const [isClose, setIsClose] = useState(false);
57
50
  const showAlert = useDelayUnmount(!isClose, transitionTime);
58
- const mainColor = colors[type];
59
- const opacityColor = hexToRGBA(mainColor, 0.15);
51
+ const mainColor = getProp(colors, type, type);
52
+ const opacityColor = hexToRGBA(getProp(colors, mainColor, mainColor), 0.15);
60
53
  const iconName = iconMap.get(type);
61
54
  const iconSize = iconSizeMap.get(size);
62
- const _AlertContainerCSS = AlertContainerCSS(size);
63
- const _AlertInfoCSS = AlertInfoCSS(mainColor, opacityColor);
64
- const _AlertTextCSS = AlertTextCSS(clearAble);
65
- const _AlertPrimaryCSS = AlertPrimaryCSS(secondary, size);
66
- const _AlertSecondaryCSS = AlertSecondaryCSS(size);
67
- const _linearProgressCSS = linearProgressCSS(size);
55
+ const _AlertContainerCSS = AlertContainerCSS(size, theme);
56
+ const _AlertInfoCSS = AlertInfoCSS(mainColor, opacityColor, theme);
57
+ const _AlertIconCSS = AlertIconCSS(theme);
58
+ const _AlertTextCSS = AlertTextCSS(clearAble, theme);
59
+ const _AlertPrimaryCSS = AlertPrimaryCSS(secondary, size, theme);
60
+ const _AlertSecondaryCSS = AlertSecondaryCSS(size, theme);
61
+ const _linearProgressCSS = linearProgressCSS(size, theme);
68
62
  const _onClose = () => {
69
63
  setIsClose(true);
70
64
  onClose === null || onClose === void 0 ? void 0 : onClose();
@@ -107,7 +101,7 @@ const Alert = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
107
101
  css: _AlertInfoCSS,
108
102
  className: classNames('DGN-UI-Alert', className)
109
103
  }, jsx("span", {
110
- css: AlertIconCSS,
104
+ css: _AlertIconCSS,
111
105
  className: 'DGN-UI-Alert-Icon'
112
106
  }, node), jsx("span", {
113
107
  css: _AlertTextCSS,
@@ -130,7 +124,7 @@ const Alert = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
130
124
  color: type,
131
125
  name: 'Close'
132
126
  }) : null));
133
- }, [color, text, clearAble, secondary, size, children, className, type, onClose, mainColor, opacityColor, isClose]);
127
+ }, [children, className, clearAble, color, onClose, secondary, size, text, typeProp, isClose, mainColor, opacityColor, theme]);
134
128
  const LinearView = useMemo(() => {
135
129
  return progressing ? jsx("span", {
136
130
  css: _linearProgressCSS,
@@ -146,7 +140,7 @@ const Alert = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
146
140
  boxShadow: 'none'
147
141
  }
148
142
  })) : null;
149
- }, [progressing, size, duration, percentState]);
143
+ }, [duration, size, progressing, percentState, theme]);
150
144
  return showAlert ? jsx("div", {
151
145
  css: _AlertContainerCSS,
152
146
  className: 'DGN-UI-Container-Alert',
@@ -154,73 +148,88 @@ const Alert = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
154
148
  }, AlertView, LinearView) : null;
155
149
  }));
156
150
  const fadeIn = animations.fadeIn;
157
- const AlertContainerCSS = size => css`
151
+ const AlertContainerCSS = (size, {
152
+ zIndex
153
+ }) => css`
158
154
  ${positionRelative};
159
155
  ${displayBlock};
160
156
  max-width: ${maxWidthMap.get(size)}px;
161
157
  transition: opacity ${transitionTime}ms ease;
162
158
  margin-bottom: 1rem;
163
159
  pointer-events: auto;
164
- z-index: ${zIndexCORE(1)};
160
+ z-index: ${zIndex(1)};
165
161
  animation: ${fadeIn} ${transitionTime}ms ease;
166
162
  `;
167
- const AlertInfoCSS = (mainColor, opacityColor) => css`
163
+ const AlertInfoCSS = (mainColor, opacityColor, {
164
+ colors,
165
+ spacing
166
+ }) => css`
168
167
  ${flexRow};
169
168
  ${positionRelative};
170
169
  ${boxBorder};
171
170
  ${borderRadius4px};
172
171
  ${breakWord};
173
172
  ${border(1, mainColor)};
174
- color: ${mainColor};
173
+ ${textColor(mainColor)};
175
174
  background-image: linear-gradient(${opacityColor}, ${opacityColor});
176
- background-color: ${systemWhite};
175
+ ${bgColor(getProp(colors, 'system/standard'))};
177
176
  width: 100%;
178
177
  min-width: 320px;
179
178
  padding: ${spacing([0, 1, 0, 4])};
180
179
  opacity: 1;
181
180
  `;
182
- const AlertIconCSS = css`
181
+ const AlertIconCSS = ({
182
+ spacing
183
+ }) => css`
183
184
  display: inherit;
184
185
  margin-right: ${spacing([2.5])};
185
186
  padding: ${spacing([2, 0])};
186
187
  `;
187
- const AlertTextCSS = clearAble => css`
188
+ const AlertTextCSS = (clearAble, {
189
+ spacing
190
+ }) => css`
188
191
  ${displayBlock};
189
192
  margin-right: ${spacing([clearAble ? 2.5 : 0])};
190
193
  padding: ${spacing([2, 0])};
191
194
  align-self: center;
192
195
  `;
193
- const AlertPrimaryCSS = (secondary, size) => css`
196
+ const AlertPrimaryCSS = (secondary, size, theme) => css`
194
197
  ${flexRow};
195
198
  ${positionRelative};
196
199
  ${itemsCenter};
197
200
  ${justifyStart};
198
201
  ${userSelectNone};
199
- ${secondary ? primaryTypoMap.get(size) : paragraph1};
202
+ ${secondary ? getProp(theme, primaryTypoMap.get(size)) : getProp(theme, 'typography.paragraph1')};
200
203
  `;
201
- const AlertSecondaryCSS = size => css`
204
+ const AlertSecondaryCSS = (size, {
205
+ typography
206
+ }) => css`
202
207
  ${displayBlock};
203
208
  ${userSelectNone};
204
- ${size === 'tiny' ? paragraph3 : paragraph2};
209
+ ${size === 'tiny' ? typography.paragraph3 : typography.paragraph2};
205
210
  `;
206
211
  const AlertClearIconCSS = css`
207
212
  margin-left: auto;
208
213
  `;
209
- const linearProgressCSS = size => css`
214
+ const linearProgressCSS = (size, {
215
+ spacing
216
+ }) => css`
210
217
  ${displayBlock};
211
218
  ${positionRelative};
212
219
  margin-top: ${spacing([size === 'medium' ? 1 : 0.5])};
213
220
  padding: ${spacing([0, 1.25])};
214
221
  `;
215
- Alert.defaultProps = {
216
- autoDisappear: false,
217
- className: '',
218
- clearAble: true,
219
- color: 'info',
220
- duration: 2000,
221
- progressing: false,
222
- size: 'medium'
223
- };
222
+
223
+ // Alert.defaultProps = {
224
+ // autoDisappear: false,
225
+ // className: '',
226
+ // clearAble: true,
227
+ // color: 'semantic/info',
228
+ // duration: 2000,
229
+ // progressing: false,
230
+ // size: 'medium',
231
+ // };
232
+
224
233
  Alert.propTypes = {
225
234
  /** Automatically remove the Alert component after the timer ends (milliseconds). */
226
235
  autoDisappear: PropTypes.bool,
@@ -1,16 +1,14 @@
1
1
  /** @jsxRuntime classic */
2
2
  /** @jsx jsx */
3
- import { memo, useEffect, forwardRef, useImperativeHandle, useRef, useState } from 'react';
4
- import ReactDOM, { createPortal } from 'react-dom';
3
+ import { css, jsx } from '@emotion/core';
5
4
  import PropTypes from 'prop-types';
6
- import { jsx, css } from '@emotion/core';
7
- import Alert from "./";
8
- import theme from "../../theme/settings";
9
- import { classNames } from "../../utils";
5
+ import { forwardRef, memo, useEffect, useImperativeHandle, useRef, useState } from 'react';
6
+ import ReactDOM, { createPortal } from 'react-dom';
10
7
  import { bgTransparent, pointerEventsNone, positionFixed } from "../../styles/general";
11
- const {
12
- zIndex: zIndexCORE
13
- } = theme;
8
+ import { useTheme } from "../../theme";
9
+ import useThemeProps from "../../theme/utils/useThemeProps";
10
+ import { classNames } from "../../utils";
11
+ import Alert from "./";
14
12
  const positionVerticalMap = new Map([['top', css`
15
13
  top: 15px;
16
14
  `], ['center', css`
@@ -29,17 +27,27 @@ const positionHorizontalMap = new Map([['left', css`
29
27
  `], ['right', css`
30
28
  right: 15px;
31
29
  `]]);
32
- const Notify = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
33
- action = {},
34
- className,
35
- getAddNotify,
36
- id,
37
- position,
38
- style,
39
- ...props
40
- }, reference) => {
30
+ const Notify = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference) => {
31
+ if (!reference) reference = useRef(null);
32
+ const theme = useTheme();
33
+
34
+ // props priority: `inProps` > `themeDefaultProps`
35
+ const props = useThemeProps({
36
+ props: inProps,
37
+ name: 'Notify'
38
+ });
39
+ const {
40
+ action = {},
41
+ className,
42
+ getAddNotify,
43
+ id,
44
+ position,
45
+ style,
46
+ ...other
47
+ } = props;
41
48
  const ref = useRef(null);
42
49
  const [positionState, setPositionState] = useState(position);
50
+ const _AlertCSS = AlertCSS(theme);
43
51
  const PositionVerticalCSS = positionVerticalMap.get((positionState === null || positionState === void 0 ? void 0 : positionState.vertical) || 'bottom');
44
52
  const PositionHorizontalCSS = positionHorizontalMap.get((positionState === null || positionState === void 0 ? void 0 : positionState.horizontal) || 'center');
45
53
  const showNotify = (message, {
@@ -56,13 +64,13 @@ const Notify = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
56
64
  // onClose={() => el.remove()}
57
65
  , {
58
66
  secondary: message,
59
- ...props,
67
+ ...other,
60
68
  ...options
61
69
  }), ref.current.appendChild(el));
62
70
  };
63
71
  useEffect(() => {
64
72
  if (getAddNotify && typeof getAddNotify === 'function') getAddNotify(showNotify);
65
- }, [props]);
73
+ }, [other]);
66
74
  useEffect(() => {
67
75
  setPositionState(position);
68
76
  }, [position]);
@@ -80,27 +88,31 @@ const Notify = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
80
88
  });
81
89
  const NotifyContainerView = jsx("div", {
82
90
  ref: ref,
83
- css: [AlertCSS, PositionVerticalCSS, PositionHorizontalCSS],
91
+ css: [_AlertCSS, PositionVerticalCSS, PositionHorizontalCSS],
84
92
  id: id,
85
93
  style: style,
86
94
  className: classNames('DGN-UI-Notify-Alert', (position === null || position === void 0 ? void 0 : position.vertical) || 'center' + '-' + (position === null || position === void 0 ? void 0 : position.horizontal) || 'center', className)
87
95
  });
88
96
  return /*#__PURE__*/createPortal(NotifyContainerView, document.body);
89
97
  }));
90
- const AlertCSS = css`
98
+ const AlertCSS = ({
99
+ zIndex
100
+ }) => css`
91
101
  ${positionFixed};
92
102
  ${pointerEventsNone};
93
103
  ${bgTransparent};
94
- z-index: ${zIndexCORE(2)};
104
+ z-index: ${zIndex(2)};
95
105
  `;
96
- Notify.defaultProps = {
97
- className: '',
98
- position: {
99
- vertical: 'bottom',
100
- horizontal: 'center'
101
- },
102
- style: {}
103
- };
106
+
107
+ // Notify.defaultProps = {
108
+ // className: '',
109
+ // position: {
110
+ // vertical: 'bottom',
111
+ // horizontal: 'center',
112
+ // },
113
+ // style: {},
114
+ // };
115
+
104
116
  Notify.propTypes = {
105
117
  /** Class for component. */
106
118
  className: PropTypes.string,
@@ -6,23 +6,12 @@ import { ButtonIcon, Image, ModalSample, Notify, Popover, Typography } from "./.
6
6
  import OptionWrapper from "../others/option-wrapper";
7
7
  import { getGlobal } from "../../global";
8
8
  import PropTypes from 'prop-types';
9
- import { forwardRef, Fragment, isValidElement, memo, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
10
- import { borderNone, borderRadius, boxContent, cursorInherit, cursorPointer, displayBlock, displayFlex, displayInlineFlex, displayNone, flexCol, itemsCenter, overflowHidden, parseMinWidth, parseWidthHeight, pd, positionAbsolute, positionRelative, userSelectNone, z } from "../../styles/general";
9
+ import { Fragment, forwardRef, isValidElement, memo, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
10
+ import { borderNone, borderRadius, boxContent, cursorInherit, cursorPointer, displayBlock, displayFlex, displayInlineFlex, displayNone, flexCol, itemsCenter, overflowHidden, parseMinWidth, parseWidthHeight, positionAbsolute, positionRelative, userSelectNone, z } from "../../styles/general";
11
+ import { getColor } from "../../styles/utils";
11
12
  import { useTheme } from "../../theme";
12
- import { classNames, isMobile, refType as ref } from "../../utils";
13
- const {
14
- colors: {
15
- system: {
16
- white: systemWhite
17
- },
18
- fill: {
19
- tooltip: fillTooltip
20
- },
21
- text: {
22
- tooltip: textTooltip
23
- }
24
- }
25
- } = useTheme();
13
+ import useThemeProps from "../../theme/utils/useThemeProps";
14
+ import { classNames, getProp, isMobile, refType as ref } from "../../utils";
26
15
  const checkFileType = (type, matchType) => {
27
16
  if (typeof matchType === 'object' && matchType instanceof RegExp) {
28
17
  return matchType.test(type);
@@ -33,36 +22,44 @@ const checkFileType = (type, matchType) => {
33
22
  return new RegExp(matchType).test(type);
34
23
  }
35
24
  };
36
- const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
37
- action = {},
38
- actionIconHeight,
39
- actionIconWidth,
40
- allowEdit,
41
- className,
42
- clearAble,
43
- data,
44
- defaultSrc,
45
- direction,
46
- disabled,
47
- height,
48
- hoverAble,
49
- id,
50
- lazyLoading,
51
- matchType,
52
- maxSize,
53
- maxSizeError,
54
- onChange,
55
- onClick,
56
- onRemove,
57
- outlined,
58
- readOnly,
59
- src,
60
- style,
61
- width,
62
- wrongTypeError
63
- }, reference) => {
25
+ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference) => {
64
26
  if (!reference) reference = useRef(null);
65
- if (!defaultSrc) defaultSrc = AvatarDefault;
27
+ const theme = useTheme();
28
+
29
+ // props priority: `inProps` > `themeDefaultProps`
30
+ const props = useThemeProps({
31
+ props: inProps,
32
+ name: 'Avatar'
33
+ });
34
+ const {
35
+ action = {},
36
+ actionIconHeight,
37
+ actionIconWidth,
38
+ allowEdit,
39
+ className,
40
+ clearAble,
41
+ data,
42
+ defaultSrc: defaultSrcProp,
43
+ direction,
44
+ disabled,
45
+ height,
46
+ hoverAble,
47
+ id,
48
+ lazyLoading,
49
+ matchType,
50
+ maxSize,
51
+ maxSizeError,
52
+ onChange,
53
+ onClick,
54
+ onRemove,
55
+ outlined,
56
+ readOnly,
57
+ src,
58
+ style,
59
+ width,
60
+ wrongTypeError
61
+ } = props;
62
+ const defaultSrc = defaultSrcProp || AvatarDefault;
66
63
  const ref = useRef(null);
67
64
  const inputRef = useRef(null);
68
65
  const avatarRef = useRef(null);
@@ -73,7 +70,7 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
73
70
  const _ActionIconCSS = ActionIconCSS(actionIconWidth);
74
71
  const _AvatarPreviewCSS = AvatarPreviewCSS(readOnly || disabled);
75
72
  const _AvatarContainerCSS = AvatarContainerCSS(_ActionIconCSS.name);
76
- const _AvatarRootCSS = AvatarRootCSS(width, height, outlined);
73
+ const _AvatarRootCSS = AvatarRootCSS(width, height, outlined, theme);
77
74
  const _isMobile = isMobile.any();
78
75
  const triggerInput = e => {
79
76
  if (e || !srcState) {
@@ -115,13 +112,13 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
115
112
  return info.map((key, index) => {
116
113
  return jsx(Typography, {
117
114
  key: index,
118
- color: textTooltip,
115
+ color: 'text/tooltip',
119
116
  type: 'p1'
120
117
  }, key + ': ' + data[key]);
121
118
  });
122
119
  }
123
120
  return jsx(Typography, {
124
- color: textTooltip,
121
+ color: 'text/tooltip',
125
122
  type: 'p1'
126
123
  }, getGlobal('noDataText'));
127
124
  };
@@ -227,19 +224,19 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
227
224
  arrow: true,
228
225
  open: viewMoreInfo,
229
226
  pressESCToClose: false,
230
- bgColor: fillTooltip,
227
+ bgColor: 'fill/tooltip',
231
228
  anchor: avatarRef,
232
229
  fullScreen: false,
233
230
  direction: direction
234
231
  }, jsx("div", {
235
- css: MoreInfoCSS
232
+ css: MoreInfoCSS(theme)
236
233
  }, typeof data === 'function' ? data() : renderData())) : null, jsx(Notify, {
237
234
  ref: notifyRef,
238
235
  progressing: true,
239
236
  autoDisappear: true,
240
237
  color: 'danger'
241
238
  }));
242
- }, [actionIconHeight, actionIconWidth, allowEdit, clearAble, data, defaultSrc, direction, disabled, height, hoverAble, lazyLoading, matchType, maxSize, maxSizeError, outlined, readOnly, width, srcState, viewAvatar, viewMoreInfo]);
239
+ }, [actionIconHeight, actionIconWidth, allowEdit, clearAble, data, defaultSrcProp, direction, disabled, height, hoverAble, lazyLoading, matchType, maxSize, maxSizeError, outlined, readOnly, width, srcState, theme, viewAvatar, viewMoreInfo]);
243
240
  }));
244
241
  const ActionIconCSS = actionIconWidth => css`
245
242
  ${displayFlex};
@@ -269,7 +266,9 @@ const AvatarContainerCSS = ActionIconCSSName => css`
269
266
  }
270
267
  }
271
268
  `;
272
- const AvatarRootCSS = (width, height, outlined) => css`
269
+ const AvatarRootCSS = (width, height, outlined, {
270
+ colors
271
+ }) => css`
273
272
  ${displayBlock};
274
273
  ${positionRelative};
275
274
  ${overflowHidden};
@@ -278,36 +277,40 @@ const AvatarRootCSS = (width, height, outlined) => css`
278
277
  ${boxContent};
279
278
  ${parseWidthHeight(width, height)};
280
279
  ${borderRadius('50%')};
281
- border: ${typeof outlined === 'boolean' && outlined ? `1px solid ${systemWhite}` : outlined};
280
+ border: ${typeof outlined === 'boolean' && outlined ? `1px solid ${getColor(getProp(colors, 'system/standard'))}` : outlined};
282
281
  input {
283
282
  ${displayNone};
284
283
  }
285
284
  `;
286
- const MoreInfoCSS = css`
285
+ const MoreInfoCSS = ({
286
+ spacing
287
+ }) => css`
287
288
  ${displayBlock};
288
289
  ${positionRelative};
289
- ${pd([2])};
290
+ padding: ${spacing([2])};
290
291
  `;
291
- Avatar.defaultProps = {
292
- actionIconHeight: 24,
293
- actionIconWidth: 24,
294
- allowEdit: false,
295
- className: '',
296
- clearAble: true,
297
- data: {},
298
- direction: 'bottom',
299
- disabled: false,
300
- height: 48,
301
- hoverAble: false,
302
- lazyLoading: false,
303
- matchType: /^image\/(gif|jpe?g|tiff?|png|webp|bmp|svg(\+xml)?)$/i,
304
- maxSizeError: `File ${getGlobal(['errorDefault', 'maxSize'])}`,
305
- outlined: false,
306
- readOnly: false,
307
- style: {},
308
- width: 48,
309
- wrongTypeError: `File ${getGlobal(['errorDefault', 'fileType'])}`
310
- };
292
+
293
+ // Avatar.defaultProps = {
294
+ // actionIconHeight: 24,
295
+ // actionIconWidth: 24,
296
+ // allowEdit: false,
297
+ // className: '',
298
+ // clearAble: true,
299
+ // data: {},
300
+ // direction: 'bottom',
301
+ // disabled: false,
302
+ // height: 48,
303
+ // hoverAble: false,
304
+ // lazyLoading: false,
305
+ // matchType: /^image\/(gif|jpe?g|tiff?|png|webp|bmp|svg(\+xml)?)$/i,
306
+ // maxSizeError: `File ${getGlobal(['errorDefault', 'maxSize'])}`,
307
+ // outlined: false,
308
+ // readOnly: false,
309
+ // style: {},
310
+ // width: 48,
311
+ // wrongTypeError: `File ${getGlobal(['errorDefault', 'fileType'])}`,
312
+ // };
313
+
311
314
  Avatar.propTypes = {
312
315
  /** The height of action icon. */
313
316
  actionIconHeight: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),