diginet-core-ui 1.3.86 → 1.3.87-beta.1
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.
- package/components/avatar/index.js +56 -135
- package/components/form-control/attachment/index.js +2 -1
- package/components/form-control/input-base/index.js +25 -19
- package/components/form-control/number-input/index2.js +19 -17
- package/components/image/index.js +13 -15
- package/components/popover/index.js +22 -16
- package/components/popup/v2/index.js +41 -36
- package/components/tab/tab.js +1 -1
- package/components/tree-view/index.js +103 -107
- package/components/typography/index.js +21 -13
- package/global/index.js +2 -2
- package/icons/basic.js +76 -0
- package/package.json +62 -31
- package/readme.md +4 -0
- package/styles/general.js +16 -1
- package/utils/index.js +1 -0
- package/utils/intersectionObserver.js +3 -2
- package/components/tree-view/css.js +0 -107
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
2
|
/** @jsx jsx */
|
|
3
|
-
import {
|
|
3
|
+
import { css, jsx } from '@emotion/core';
|
|
4
4
|
import AvatarDefault from "../../assets/avatar/default.svg";
|
|
5
|
-
import { ButtonIcon, ModalSample,
|
|
5
|
+
import { ButtonIcon, Image, ModalSample, Notify, Popover, Typography } from "./..";
|
|
6
|
+
import OptionWrapper from "../others/option-wrapper";
|
|
6
7
|
import { getGlobal } from "../../global";
|
|
7
8
|
import PropTypes from 'prop-types';
|
|
8
9
|
import { forwardRef, Fragment, isValidElement, memo, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
9
|
-
import {
|
|
10
|
+
import { borderNone, borderRadius, boxContent, cursorInherit, cursorPointer, displayBlock, displayFlex, displayInlineFlex, displayNone, flexCol, itemsCenter, overflowHidden, parseMinWidth, parseWidthHeight, pd, positionAbsolute, positionRelative, userSelectNone, z } from "../../styles/general";
|
|
10
11
|
import { useTheme } from "../../theme";
|
|
11
|
-
import { classNames, isMobile
|
|
12
|
-
import { useIntersection } from "../../utils/intersectionObserver";
|
|
13
|
-
import OptionWrapper from "../others/option-wrapper";
|
|
12
|
+
import { classNames, isMobile } from "../../utils";
|
|
14
13
|
const {
|
|
15
14
|
colors: {
|
|
16
15
|
system: {
|
|
17
|
-
white
|
|
16
|
+
white: systemWhite
|
|
18
17
|
},
|
|
19
18
|
fill: {
|
|
20
19
|
tooltip: fillTooltip
|
|
@@ -22,19 +21,8 @@ const {
|
|
|
22
21
|
text: {
|
|
23
22
|
tooltip: textTooltip
|
|
24
23
|
}
|
|
25
|
-
}
|
|
26
|
-
spacing,
|
|
27
|
-
zIndex: zIndexCORE
|
|
24
|
+
}
|
|
28
25
|
} = useTheme();
|
|
29
|
-
const existed = {},
|
|
30
|
-
urlAvatar = {};
|
|
31
|
-
const blurKeyframe = keyframes`
|
|
32
|
-
0% { -webkit-filter: blur(4px);}
|
|
33
|
-
25% { -webkit-filter: blur(3px);}
|
|
34
|
-
50% { -webkit-filter: blur(2px);}
|
|
35
|
-
75% { -webkit-filter: blur(1px);}
|
|
36
|
-
100% { -webkit-filter: blur(0px);}
|
|
37
|
-
`;
|
|
38
26
|
const checkFileType = (type, matchType) => {
|
|
39
27
|
if (typeof matchType === 'object' && matchType instanceof RegExp) {
|
|
40
28
|
return matchType.test(type);
|
|
@@ -73,30 +61,22 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
73
61
|
width,
|
|
74
62
|
wrongTypeError
|
|
75
63
|
}, reference) => {
|
|
64
|
+
if (!reference) reference = useRef(null);
|
|
76
65
|
if (!defaultSrc) defaultSrc = AvatarDefault;
|
|
77
66
|
const ref = useRef(null);
|
|
78
67
|
const inputRef = useRef(null);
|
|
79
68
|
const avatarRef = useRef(null);
|
|
80
|
-
const
|
|
81
|
-
const [unique] = useState(randomString(6, {
|
|
82
|
-
allowNumber: false,
|
|
83
|
-
allowSymbol: false
|
|
84
|
-
}));
|
|
69
|
+
const notifyRef = useRef(null);
|
|
85
70
|
const [viewAvatar, setViewAvatar] = useState(false);
|
|
86
71
|
const [viewMoreInfo, setViewMoreInfo] = useState(false);
|
|
87
72
|
const [srcState, setSrcState] = useState(src);
|
|
88
|
-
const [isInView, setIsInView] = useState(false);
|
|
89
|
-
const [onLoaded, setOnLoaded] = useState(false);
|
|
90
|
-
useIntersection(ref, () => {
|
|
91
|
-
setIsInView(true);
|
|
92
|
-
});
|
|
93
73
|
const _ActionIconCSS = ActionIconCSS(actionIconWidth);
|
|
94
|
-
const _AvatarPreviewCSS = AvatarPreviewCSS(readOnly);
|
|
95
|
-
const _AvatarContainerCSS = AvatarContainerCSS(
|
|
74
|
+
const _AvatarPreviewCSS = AvatarPreviewCSS(readOnly || disabled);
|
|
75
|
+
const _AvatarContainerCSS = AvatarContainerCSS(_ActionIconCSS.name);
|
|
96
76
|
const _AvatarRootCSS = AvatarRootCSS(width, height, outlined);
|
|
97
77
|
const _isMobile = isMobile.any();
|
|
98
78
|
const triggerInput = e => {
|
|
99
|
-
if (e || !
|
|
79
|
+
if (e || !srcState) {
|
|
100
80
|
inputRef.current.click();
|
|
101
81
|
} else {
|
|
102
82
|
// on View
|
|
@@ -109,29 +89,22 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
109
89
|
const reader = new FileReader();
|
|
110
90
|
if (!checkFileType(file.type, matchType)) {
|
|
111
91
|
input.target.value = '';
|
|
112
|
-
|
|
113
|
-
description: wrongTypeError
|
|
114
|
-
});
|
|
92
|
+
notifyRef.current.instance.show(wrongTypeError);
|
|
115
93
|
return;
|
|
116
94
|
}
|
|
117
95
|
if (+maxSize && file.size > maxSize * 1024 ** 2) {
|
|
118
96
|
input.target.value = '';
|
|
119
|
-
|
|
120
|
-
description: maxSizeError
|
|
121
|
-
});
|
|
97
|
+
notifyRef.current.instance.show(maxSizeError);
|
|
122
98
|
return;
|
|
123
99
|
}
|
|
124
100
|
reader.onload = e => {
|
|
125
|
-
|
|
126
|
-
setSrcState(urlAvatar[unique]);
|
|
127
|
-
existed[unique] = true;
|
|
101
|
+
setSrcState(e.target.result);
|
|
128
102
|
};
|
|
129
103
|
reader.readAsDataURL(file);
|
|
130
104
|
!!onChange && onChange(input);
|
|
131
105
|
};
|
|
132
106
|
const onRemoveAvatar = () => {
|
|
133
107
|
setSrcState(null);
|
|
134
|
-
existed[unique] = false;
|
|
135
108
|
inputRef.current.value = '';
|
|
136
109
|
!!onRemove && onRemove();
|
|
137
110
|
};
|
|
@@ -152,32 +125,6 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
152
125
|
type: 'p1'
|
|
153
126
|
}, getGlobal('noDataText'));
|
|
154
127
|
};
|
|
155
|
-
const renderImage = () => {
|
|
156
|
-
const _image = jsx(Fragment, null, !onLoaded && jsx("img", {
|
|
157
|
-
src: defaultSrc,
|
|
158
|
-
alt: '',
|
|
159
|
-
style: {
|
|
160
|
-
objectFit: 'cover'
|
|
161
|
-
}
|
|
162
|
-
}), jsx("img", {
|
|
163
|
-
css: blurAnimationCSS,
|
|
164
|
-
src: srcState,
|
|
165
|
-
alt: srcState,
|
|
166
|
-
style: {
|
|
167
|
-
objectFit: 'cover'
|
|
168
|
-
},
|
|
169
|
-
onLoad: () => setOnLoaded(true)
|
|
170
|
-
}));
|
|
171
|
-
if (lazyLoading) {
|
|
172
|
-
return isInView ? _image : jsx("img", {
|
|
173
|
-
src: defaultSrc,
|
|
174
|
-
alt: '',
|
|
175
|
-
style: {
|
|
176
|
-
objectFit: 'cover'
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
} else return _image;
|
|
180
|
-
};
|
|
181
128
|
const showMoreInfo = () => {
|
|
182
129
|
if (hoverAble) setViewMoreInfo(true);
|
|
183
130
|
};
|
|
@@ -201,22 +148,11 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
201
148
|
};
|
|
202
149
|
useEffect(() => {
|
|
203
150
|
if (src) {
|
|
204
|
-
|
|
205
|
-
inputRef.current.value = '';
|
|
206
|
-
const img = document.createElement('img');
|
|
207
|
-
urlAvatar[unique] = src;
|
|
208
|
-
img.src = src;
|
|
209
|
-
img.alt = '';
|
|
210
|
-
img.onerror = () => {
|
|
211
|
-
setSrcState(defaultSrc);
|
|
212
|
-
existed[unique] = false;
|
|
213
|
-
};
|
|
214
|
-
img.onload = () => {
|
|
215
|
-
setSrcState(src);
|
|
216
|
-
existed[unique] = true;
|
|
217
|
-
};
|
|
218
|
-
}
|
|
151
|
+
setSrcState(src);
|
|
219
152
|
}
|
|
153
|
+
return () => {
|
|
154
|
+
setSrcState(defaultSrc);
|
|
155
|
+
};
|
|
220
156
|
}, [src]);
|
|
221
157
|
useImperativeHandle(reference, () => {
|
|
222
158
|
const currentRef = ref.current || {};
|
|
@@ -230,11 +166,9 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
230
166
|
});
|
|
231
167
|
return useMemo(() => {
|
|
232
168
|
return jsx(Fragment, null, jsx("div", {
|
|
233
|
-
css: _AvatarContainerCSS
|
|
234
|
-
ref: ref,
|
|
235
|
-
id: unique,
|
|
236
|
-
className: classNames(disabled && 'disabled')
|
|
169
|
+
css: _AvatarContainerCSS
|
|
237
170
|
}, jsx("div", {
|
|
171
|
+
ref: ref,
|
|
238
172
|
css: _AvatarRootCSS,
|
|
239
173
|
className: classNames('DGN-UI-Avatar', className),
|
|
240
174
|
style: style,
|
|
@@ -247,14 +181,21 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
247
181
|
onChange: onChangeAvatar,
|
|
248
182
|
disabled: disabled
|
|
249
183
|
}), jsx("div", {
|
|
184
|
+
ref: avatarRef,
|
|
250
185
|
css: _AvatarPreviewCSS,
|
|
251
186
|
onClick: _onClick,
|
|
252
|
-
ref: avatarRef,
|
|
253
187
|
onMouseEnter: _onMouseEnter,
|
|
254
188
|
onMouseLeave: _onMouseLeave,
|
|
255
189
|
tabIndex: "-1",
|
|
256
190
|
onBlur: closeMoreInfo
|
|
257
|
-
},
|
|
191
|
+
}, jsx(Image, {
|
|
192
|
+
circular: true,
|
|
193
|
+
defaultSrc: defaultSrc,
|
|
194
|
+
src: srcState,
|
|
195
|
+
width: '100%',
|
|
196
|
+
height: '100%',
|
|
197
|
+
lazyLoading: lazyLoading
|
|
198
|
+
}))), allowEdit && !readOnly && !disabled ? jsx("span", {
|
|
258
199
|
css: _ActionIconCSS
|
|
259
200
|
}, jsx(ButtonIcon, {
|
|
260
201
|
viewType: 'ghost',
|
|
@@ -263,7 +204,7 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
263
204
|
height: actionIconHeight,
|
|
264
205
|
className: 'icon-edit',
|
|
265
206
|
onClick: triggerInput
|
|
266
|
-
}), clearAble && srcState
|
|
207
|
+
}), clearAble && srcState ? jsx(ButtonIcon, {
|
|
267
208
|
viewType: 'ghost',
|
|
268
209
|
name: 'Delete',
|
|
269
210
|
width: actionIconWidth,
|
|
@@ -273,68 +214,55 @@ const Avatar = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
273
214
|
style: {
|
|
274
215
|
marginTop: '8px'
|
|
275
216
|
}
|
|
276
|
-
}))), jsx(ModalSample, {
|
|
217
|
+
}) : null) : null), jsx(ModalSample, {
|
|
277
218
|
open: viewAvatar,
|
|
278
219
|
onClose: () => setViewAvatar(false),
|
|
279
220
|
width: 'max-content'
|
|
280
|
-
}, jsx(
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
maxWidth: '100%',
|
|
287
|
-
margin: 'auto',
|
|
288
|
-
display: 'block'
|
|
289
|
-
}
|
|
290
|
-
})), hoverAble && jsx(Popover, {
|
|
221
|
+
}, jsx(Image, {
|
|
222
|
+
defaultSrc: defaultSrc,
|
|
223
|
+
src: srcState,
|
|
224
|
+
width: '100%',
|
|
225
|
+
height: '100%'
|
|
226
|
+
})), hoverAble ? jsx(Popover, {
|
|
291
227
|
arrow: true,
|
|
292
228
|
open: viewMoreInfo,
|
|
293
229
|
pressESCToClose: false,
|
|
294
230
|
bgColor: fillTooltip,
|
|
295
231
|
anchor: avatarRef,
|
|
296
232
|
fullScreen: false,
|
|
297
|
-
width: 'max-content',
|
|
298
233
|
direction: direction
|
|
299
234
|
}, jsx("div", {
|
|
300
235
|
css: MoreInfoCSS
|
|
301
|
-
}, typeof data === 'function' ? data() : renderData()))
|
|
302
|
-
ref:
|
|
303
|
-
|
|
236
|
+
}, typeof data === 'function' ? data() : renderData())) : null, jsx(Notify, {
|
|
237
|
+
ref: notifyRef,
|
|
238
|
+
progressing: true,
|
|
239
|
+
autoDisappear: true,
|
|
240
|
+
color: 'danger'
|
|
304
241
|
}));
|
|
305
|
-
}, [actionIconHeight, actionIconWidth, allowEdit, clearAble, data, defaultSrc, direction, disabled, height, hoverAble, lazyLoading, matchType, maxSize, maxSizeError, outlined, readOnly, width,
|
|
242
|
+
}, [actionIconHeight, actionIconWidth, allowEdit, clearAble, data, defaultSrc, direction, disabled, height, hoverAble, lazyLoading, matchType, maxSize, maxSizeError, outlined, readOnly, width, srcState, viewAvatar, viewMoreInfo]);
|
|
306
243
|
}));
|
|
307
244
|
const ActionIconCSS = actionIconWidth => css`
|
|
245
|
+
${displayFlex};
|
|
308
246
|
${flexCol};
|
|
309
247
|
${positionAbsolute};
|
|
248
|
+
${parseMinWidth(actionIconWidth)};
|
|
310
249
|
right: ${-actionIconWidth}px;
|
|
311
|
-
min-width: ${actionIconWidth}px;
|
|
312
250
|
transition: opacity 0.5s;
|
|
313
251
|
opacity: 0;
|
|
314
|
-
|
|
252
|
+
${z(2)};
|
|
315
253
|
`;
|
|
316
|
-
const AvatarPreviewCSS =
|
|
254
|
+
const AvatarPreviewCSS = isDisabled => css`
|
|
317
255
|
${displayBlock};
|
|
318
256
|
${positionRelative};
|
|
319
257
|
${overflowHidden};
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
cursor: ${readOnly ? 'initial' : 'pointer'};
|
|
258
|
+
${parseWidthHeight('100%')};
|
|
259
|
+
${borderRadius('50%')};
|
|
260
|
+
${isDisabled ? cursorInherit : cursorPointer};
|
|
324
261
|
`;
|
|
325
|
-
const AvatarContainerCSS =
|
|
262
|
+
const AvatarContainerCSS = ActionIconCSSName => css`
|
|
326
263
|
${displayInlineFlex};
|
|
327
264
|
${positionRelative};
|
|
328
265
|
${itemsCenter};
|
|
329
|
-
&.disabled {
|
|
330
|
-
.css-${AvatarPreviewCSSName} {
|
|
331
|
-
${pointerEventsNone}
|
|
332
|
-
cursor: inherit;
|
|
333
|
-
}
|
|
334
|
-
.css-${ActionIconCSSName} {
|
|
335
|
-
display: none !important;
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
266
|
&:hover {
|
|
339
267
|
.css-${ActionIconCSSName} {
|
|
340
268
|
opacity: 1;
|
|
@@ -347,25 +275,18 @@ const AvatarRootCSS = (width, height, outlined) => css`
|
|
|
347
275
|
${overflowHidden};
|
|
348
276
|
${userSelectNone};
|
|
349
277
|
${borderNone};
|
|
278
|
+
${boxContent};
|
|
350
279
|
${parseWidthHeight(width, height)};
|
|
351
|
-
|
|
352
|
-
border
|
|
353
|
-
box-sizing: content-box;
|
|
280
|
+
${borderRadius('50%')};
|
|
281
|
+
border: ${typeof outlined === 'boolean' && outlined ? `1px solid ${systemWhite}` : outlined};
|
|
354
282
|
input {
|
|
355
283
|
${displayNone};
|
|
356
284
|
}
|
|
357
|
-
img {
|
|
358
|
-
width: 100%;
|
|
359
|
-
height: 100%;
|
|
360
|
-
}
|
|
361
285
|
`;
|
|
362
286
|
const MoreInfoCSS = css`
|
|
363
287
|
${displayBlock};
|
|
364
288
|
${positionRelative};
|
|
365
|
-
|
|
366
|
-
`;
|
|
367
|
-
const blurAnimationCSS = css`
|
|
368
|
-
animation: ${blurKeyframe} 1s ease;
|
|
289
|
+
${pd([2])};
|
|
369
290
|
`;
|
|
370
291
|
Avatar.defaultProps = {
|
|
371
292
|
actionIconHeight: 24,
|
|
@@ -1301,7 +1301,8 @@ Attachment.defaultProps = {
|
|
|
1301
1301
|
maxSize: getGlobal(['errorDefault', 'maxSize']),
|
|
1302
1302
|
fileType: getGlobal(['errorDefault', 'fileType']),
|
|
1303
1303
|
existingFile: getGlobal(['errorDefault', 'existingFile'])
|
|
1304
|
-
}
|
|
1304
|
+
},
|
|
1305
|
+
viewType: 'detail'
|
|
1305
1306
|
};
|
|
1306
1307
|
Attachment.propTypes = {
|
|
1307
1308
|
/** File types that can be accepted. */
|
|
@@ -51,7 +51,7 @@ const InputBase = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
51
51
|
hoverTooltip,
|
|
52
52
|
iconStyle,
|
|
53
53
|
inputProps,
|
|
54
|
-
inputRef:
|
|
54
|
+
inputRef: inputRefProp,
|
|
55
55
|
inputStyle,
|
|
56
56
|
maxRows,
|
|
57
57
|
multiline,
|
|
@@ -84,7 +84,8 @@ const InputBase = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
84
84
|
bind,
|
|
85
85
|
value
|
|
86
86
|
} = useInput(defaultValue, valueProp, _onChange, onInput, delayOnChange);
|
|
87
|
-
if (!
|
|
87
|
+
if (!inputRefProp) inputRefProp = useRef(null);
|
|
88
|
+
const inputRef = useRef(null);
|
|
88
89
|
const ref = useRef(null);
|
|
89
90
|
const valueArray = useRef([]);
|
|
90
91
|
const canvas = document.createElement('canvas');
|
|
@@ -115,28 +116,28 @@ const InputBase = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
115
116
|
};
|
|
116
117
|
useEffect(() => {
|
|
117
118
|
if (defaultValue !== undefined && defaultValue !== '') {
|
|
118
|
-
if (multiline && !/\d+/.test(rows)) {
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
if (multiline && !/\d+/.test(rows) && inputRef.current) {
|
|
120
|
+
inputRef.current.style.height = 0;
|
|
121
|
+
inputRef.current.style.height = Math.max(24, inputRef.current.scrollHeight) + 'px';
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
}, []);
|
|
124
125
|
useEffect(() => {
|
|
125
|
-
if (multiline && !/\d+/.test(rows) && !(
|
|
126
|
-
|
|
126
|
+
if (multiline && !/\d+/.test(rows) && inputRef.current && !(inputRef.current.value || inputRef.current.value === 0)) {
|
|
127
|
+
inputRef.current.style.height = '24px';
|
|
127
128
|
}
|
|
128
129
|
if (autoFocus) {
|
|
129
|
-
|
|
130
|
+
inputRef.current.focus();
|
|
130
131
|
}
|
|
131
132
|
}, [multiline]);
|
|
132
133
|
useEffect(() => {
|
|
133
134
|
const defaultHeight = 24;
|
|
134
135
|
if (valueProp !== undefined) {
|
|
135
136
|
valueArray.current.push(valueProp);
|
|
136
|
-
|
|
137
|
+
inputRef.current.value = valueProp;
|
|
137
138
|
if (multiline && !/\d+/.test(rows)) {
|
|
138
|
-
|
|
139
|
-
|
|
139
|
+
inputRef.current.style.height = 0;
|
|
140
|
+
inputRef.current.style.height = Math.max(defaultHeight, inputRef.current.scrollHeight) + 'px';
|
|
140
141
|
} else {
|
|
141
142
|
dynamicWidth({
|
|
142
143
|
target: {
|
|
@@ -146,15 +147,15 @@ const InputBase = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
146
147
|
}
|
|
147
148
|
}
|
|
148
149
|
return () => {
|
|
149
|
-
if (valueProp !== undefined && multiline && !/\d+/.test(rows) &&
|
|
150
|
-
|
|
150
|
+
if (valueProp !== undefined && multiline && !/\d+/.test(rows) && inputRef.current) {
|
|
151
|
+
inputRef.current.style.height = defaultHeight + 'px';
|
|
151
152
|
}
|
|
152
153
|
};
|
|
153
154
|
}, [valueProp]);
|
|
154
155
|
/* End handler */
|
|
155
156
|
|
|
156
157
|
useImperativeHandle(reference, () => {
|
|
157
|
-
const currentRef =
|
|
158
|
+
const currentRef = inputRef.current || {};
|
|
158
159
|
const _instance = {
|
|
159
160
|
...action
|
|
160
161
|
}; // methods
|
|
@@ -169,14 +170,14 @@ const InputBase = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
169
170
|
styleInputBase.current = style;
|
|
170
171
|
};
|
|
171
172
|
const dynamicWidth = e => {
|
|
172
|
-
if (!autoWidth || !
|
|
173
|
-
if (!canvas || !styleInputBase.current || !
|
|
173
|
+
if (!autoWidth || !inputRef.current) return;
|
|
174
|
+
if (!canvas || !styleInputBase.current || !inputRef.current) return;
|
|
174
175
|
const context = canvas.getContext('2d');
|
|
175
176
|
context.font = styleInputBase.current.font;
|
|
176
177
|
const {
|
|
177
178
|
width
|
|
178
179
|
} = context.measureText(e.target.value);
|
|
179
|
-
|
|
180
|
+
inputRef.current.style.width = `${Math.max(width, widthInit.current)}px`;
|
|
180
181
|
};
|
|
181
182
|
|
|
182
183
|
/* Start component */
|
|
@@ -224,7 +225,11 @@ const InputBase = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
224
225
|
readOnly: readOnly,
|
|
225
226
|
style: inputStyle || (inputProps === null || inputProps === void 0 ? void 0 : inputProps.style),
|
|
226
227
|
className: classNames('DGN-UI-InputBase-Textarea', inputProps.className),
|
|
227
|
-
ref:
|
|
228
|
+
ref: refs => {
|
|
229
|
+
if (!refs) return;
|
|
230
|
+
inputRef.current = refs;
|
|
231
|
+
typeof inputRefProp === 'function' ? inputRefProp(refs) : inputRefProp.current = refs;
|
|
232
|
+
},
|
|
228
233
|
onKeyDown: onKeyDown,
|
|
229
234
|
onKeyUp: onKeyUp,
|
|
230
235
|
onInput: onInputTextArea,
|
|
@@ -249,7 +254,8 @@ const InputBase = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
249
254
|
className: classNames('DGN-UI-InputBase-Input', newClass, inputProps === null || inputProps === void 0 ? void 0 : inputProps.className),
|
|
250
255
|
ref: refs => {
|
|
251
256
|
if (!refs) return;
|
|
252
|
-
|
|
257
|
+
inputRef.current = refs;
|
|
258
|
+
typeof inputRefProp === 'function' ? inputRefProp(refs) : inputRefProp.current = refs;
|
|
253
259
|
saveInitInfo(refs);
|
|
254
260
|
},
|
|
255
261
|
css: _InputCSS,
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
2
|
/** @jsx jsx */
|
|
3
3
|
import { css, jsx } from '@emotion/core';
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
5
|
-
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
6
4
|
import { HelperText, InputBase, Label } from "../..";
|
|
7
5
|
import locale from "../../../locale";
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
8
|
+
import { cursorNotAllowed, displayBlock, mgb, positionRelative } from "../../../styles/general";
|
|
10
9
|
import { classNames, onValidate, refType as ref } from "../../../utils";
|
|
11
|
-
const {
|
|
12
|
-
spacing
|
|
13
|
-
} = useTheme();
|
|
14
10
|
const regexValidNumber = /[^0-9.,-]/g;
|
|
15
11
|
const regexNumber = /[^0-9]/g;
|
|
16
12
|
const regexThousandNumber = /(\d)(?=(\d{3})+\b)/g;
|
|
@@ -33,7 +29,7 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
33
29
|
fixedDecimalDigit,
|
|
34
30
|
helperTextProps,
|
|
35
31
|
inputProps,
|
|
36
|
-
inputRef,
|
|
32
|
+
inputRef: inputRefProp,
|
|
37
33
|
inputStyle,
|
|
38
34
|
label,
|
|
39
35
|
labelProps,
|
|
@@ -58,10 +54,12 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
58
54
|
value: valueProps,
|
|
59
55
|
viewType
|
|
60
56
|
}, reference) => {
|
|
61
|
-
|
|
57
|
+
if (!reference) reference = useRef(null);
|
|
58
|
+
if (!inputRefProp) inputRefProp = useRef(null);
|
|
62
59
|
const pos = useRef(null);
|
|
63
60
|
const ref = useRef(null);
|
|
64
61
|
const globalRef = useRef({});
|
|
62
|
+
const inputRef = useRef(null);
|
|
65
63
|
const [value, setValue] = useState(defaultValue);
|
|
66
64
|
const isError = !!error;
|
|
67
65
|
|
|
@@ -77,7 +75,6 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
77
75
|
} else {
|
|
78
76
|
thousandSymbol = '';
|
|
79
77
|
}
|
|
80
|
-
const validateResult = validates && onValidate(value, validates, true);
|
|
81
78
|
if (valueProps || valueProps === 0) valueProps = clamp(valueProps, min, max);
|
|
82
79
|
|
|
83
80
|
/**
|
|
@@ -238,6 +235,7 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
238
235
|
}
|
|
239
236
|
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(e);
|
|
240
237
|
};
|
|
238
|
+
const validateResult = validates && onValidate(Number(convertMoneyToNumber(value) || 0), validates, true);
|
|
241
239
|
useEffect(() => {
|
|
242
240
|
inputRef.current.value = value !== null && value !== void 0 ? value : null;
|
|
243
241
|
|
|
@@ -270,12 +268,16 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
270
268
|
css: NumberInputRoot,
|
|
271
269
|
className: classNames('DGN-UI-NumberInput', className, disabled && 'disabled'),
|
|
272
270
|
style: style
|
|
273
|
-
},
|
|
271
|
+
}, label ? jsx(Label, {
|
|
274
272
|
required: required,
|
|
275
273
|
disabled: disabled,
|
|
276
274
|
...labelProps
|
|
277
|
-
}, label), jsx(InputBase, {
|
|
278
|
-
inputRef:
|
|
275
|
+
}, label) : null, jsx(InputBase, {
|
|
276
|
+
inputRef: refs => {
|
|
277
|
+
if (!refs) return;
|
|
278
|
+
inputRef.current = refs;
|
|
279
|
+
typeof inputRefProp === 'function' ? inputRefProp(refs) : inputRefProp.current = refs;
|
|
280
|
+
},
|
|
279
281
|
viewType: viewType,
|
|
280
282
|
defaultValue: defaultValue,
|
|
281
283
|
value: value,
|
|
@@ -306,18 +308,18 @@ const NumberInput = /*#__PURE__*/forwardRef(({
|
|
|
306
308
|
target
|
|
307
309
|
});
|
|
308
310
|
}
|
|
309
|
-
}), isError
|
|
311
|
+
}), isError ? jsx(HelperText, {
|
|
310
312
|
...helperTextProps,
|
|
311
313
|
disabled: disabled
|
|
312
|
-
}, error), !isError && validateResult
|
|
314
|
+
}, error) : null, !isError && validateResult ? jsx(HelperText, {
|
|
313
315
|
...helperTextProps,
|
|
314
316
|
disabled: disabled
|
|
315
|
-
}, validateResult));
|
|
317
|
+
}, validateResult) : null);
|
|
316
318
|
});
|
|
317
319
|
const NumberInputRoot = css`
|
|
318
320
|
${displayBlock};
|
|
319
321
|
${positionRelative};
|
|
320
|
-
|
|
322
|
+
${mgb([5])};
|
|
321
323
|
&.disabled {
|
|
322
324
|
${cursorNotAllowed};
|
|
323
325
|
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/** @jsxRuntime classic */
|
|
2
2
|
/** @jsx jsx */
|
|
3
|
-
import {
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
5
|
-
import { jsx, css, keyframes } from '@emotion/core';
|
|
6
|
-
import OptionWrapper from "../others/option-wrapper";
|
|
7
|
-
import { useIntersection } from "../../utils/intersectionObserver";
|
|
8
|
-
import { classNames } from "../../utils";
|
|
3
|
+
import { css, jsx, keyframes } from '@emotion/core';
|
|
9
4
|
import AvatarDefault from "../../assets/avatar/default.svg";
|
|
10
|
-
import
|
|
5
|
+
import OptionWrapper from "../others/option-wrapper";
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
import { forwardRef, Fragment, memo, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
8
|
+
import { borderRadius, displayInlineFlex, itemsCenter, objectCover, overflowHidden, parseWidthHeight, positionRelative } from "../../styles/general";
|
|
9
|
+
import { classNames, useIntersection } from "../../utils";
|
|
11
10
|
const blurKeyframe = keyframes`
|
|
12
11
|
0% { -webkit-filter: blur(4px);}
|
|
13
12
|
25% { -webkit-filter: blur(3px);}
|
|
@@ -29,6 +28,7 @@ const Image = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
29
28
|
style,
|
|
30
29
|
width
|
|
31
30
|
}, reference) => {
|
|
31
|
+
if (!reference) reference = useRef(null);
|
|
32
32
|
if (!defaultSrc) defaultSrc = AvatarDefault;
|
|
33
33
|
const ref = useRef(null);
|
|
34
34
|
const [srcState, setSrcState] = useState(src);
|
|
@@ -53,6 +53,9 @@ const Image = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
+
return () => {
|
|
57
|
+
setSrcState(defaultSrc);
|
|
58
|
+
};
|
|
56
59
|
}, [src]);
|
|
57
60
|
useImperativeHandle(reference, () => {
|
|
58
61
|
const currentRef = ref.current || {};
|
|
@@ -66,21 +69,16 @@ const Image = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
|
66
69
|
});
|
|
67
70
|
const renderImage = () => {
|
|
68
71
|
const defaultImage = jsx("img", {
|
|
72
|
+
css: objectCover,
|
|
69
73
|
src: defaultSrc,
|
|
70
74
|
alt: '',
|
|
71
|
-
style: {
|
|
72
|
-
objectFit: 'cover'
|
|
73
|
-
},
|
|
74
75
|
width: width,
|
|
75
76
|
height: height
|
|
76
77
|
});
|
|
77
78
|
const image = jsx(Fragment, null, !onLoaded && defaultImage, jsx("img", {
|
|
78
|
-
css: blurAnimationCSS,
|
|
79
|
+
css: [blurAnimationCSS, objectCover],
|
|
79
80
|
src: srcState,
|
|
80
81
|
alt: alt || srcState,
|
|
81
|
-
style: {
|
|
82
|
-
objectFit: 'cover'
|
|
83
|
-
},
|
|
84
82
|
onLoad: () => setOnLoaded(true),
|
|
85
83
|
width: width,
|
|
86
84
|
height: height
|
|
@@ -105,7 +103,7 @@ const ImageCSS = (width, height, circular) => css`
|
|
|
105
103
|
${itemsCenter};
|
|
106
104
|
${overflowHidden};
|
|
107
105
|
${parseWidthHeight(width, height)};
|
|
108
|
-
${circular &&
|
|
106
|
+
${circular && borderRadius('50%')};
|
|
109
107
|
`;
|
|
110
108
|
const blurAnimationCSS = css`
|
|
111
109
|
animation: ${blurKeyframe} 1s ease;
|