diginet-core-ui 1.4.26 → 1.4.28
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/button/index.js +44 -42
- package/components/form-control/attachment/index.js +23 -22
- package/package.json +1 -1
- package/readme.md +9 -0
|
@@ -4,7 +4,7 @@ import { css, jsx } from '@emotion/core';
|
|
|
4
4
|
import { CircularProgress, Icon, Typography } from "./..";
|
|
5
5
|
import OptionWrapper from "../others/option-wrapper";
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
|
-
import { forwardRef, memo,
|
|
7
|
+
import { forwardRef, memo, useImperativeHandle, useMemo, useRef } from 'react';
|
|
8
8
|
import { detectColor, fade, hexToRGBA, hslToRgb, isColor, isColorName, rgbToHex, rgbaToHexA } from "../../styles/color-helper";
|
|
9
9
|
import * as allColors from "../../styles/colors";
|
|
10
10
|
import { alphaPseudo, bgColor, border, borderColor, borderNone, borderRadius4px, boxBorder, cursorNotAllowed, cursorPointer, displayFlex, displayInlineFlex, flexRow, itemsCenter, justifyCenter, outlineNone, overflowHidden, parseHeight, parseMinWidth, parseMinWidthHeight, parseWidthHeight, pointerEventsNone, positionRelative, textColor, userSelectNone, whiteSpaceNoWrap } from "../../styles/general";
|
|
@@ -12,9 +12,6 @@ import { useTheme } from "../../theme";
|
|
|
12
12
|
import { classNames, getProp } from "../../utils";
|
|
13
13
|
import Ripple from "./ripple-effect";
|
|
14
14
|
import useThemeProps from "../../theme/utils/useThemeProps";
|
|
15
|
-
const {
|
|
16
|
-
spacing
|
|
17
|
-
} = useTheme();
|
|
18
15
|
export const getRippleColor = (color, viewType, colors) => {
|
|
19
16
|
if (!isColor(color) && !isColorName(color)) {
|
|
20
17
|
let level = 3;
|
|
@@ -48,7 +45,9 @@ export const getRippleColor = (color, viewType, colors) => {
|
|
|
48
45
|
return rgbaToHexA(hslToRgb(fade(color, 0.5)));
|
|
49
46
|
}
|
|
50
47
|
};
|
|
51
|
-
const iconSizeMap =
|
|
48
|
+
const iconSizeMap = ({
|
|
49
|
+
spacing
|
|
50
|
+
}) => new Map([['tiny', spacing([4])], ['small', spacing([5])], ['medium', spacing([6])], ['large', spacing([8])], ['giant', spacing([10])]]);
|
|
52
51
|
const paddingSizeMap = new Map([['tiny', [1, 2]], ['small', [1.5, 3]], ['medium', [2, 4]], ['large', [2, 5]], ['giant', [2, 6]]]);
|
|
53
52
|
const outlinedPaddingSizeMap = new Map([['tiny', [0.75, 1.75]], ['small', [1.25, 2.75]], ['medium', [1.75, 3.75]], ['large', [1.75, 4.75]], ['giant', [1.75, 5.75]]]);
|
|
54
53
|
const iconMarginSizeMap = new Map([['tiny', [1]], ['small', [1]], ['medium', [1]], ['large', [1.5]], ['giant', [2]]]);
|
|
@@ -57,6 +56,7 @@ const minHeightSizeMap = new Map([['tiny', '24px'], ['small', '32px'], ['medium'
|
|
|
57
56
|
const minHeightSizeLinkMap = new Map([['tiny', '16px'], ['small', '20px'], ['medium', '24px'], ['large', '32px'], ['giant', '40px']]);
|
|
58
57
|
const alphaLoading = 0.2;
|
|
59
58
|
const Button = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference) => {
|
|
59
|
+
var _iconSizeMap;
|
|
60
60
|
if (!reference) reference = useRef(null);
|
|
61
61
|
const theme = useTheme();
|
|
62
62
|
const {
|
|
@@ -93,20 +93,25 @@ const Button = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference) =
|
|
|
93
93
|
const label = labelProp || text || '';
|
|
94
94
|
const ref = useRef(null);
|
|
95
95
|
const rippleRef = useRef(null);
|
|
96
|
-
const
|
|
96
|
+
const url = useMemo(() => {
|
|
97
|
+
if (href) {
|
|
98
|
+
const qs = urlParams ? '?' + new URLSearchParams(urlParams).toString() : '';
|
|
99
|
+
return href + qs;
|
|
100
|
+
}
|
|
101
|
+
}, [href, urlParams]);
|
|
97
102
|
const isColorDefault = colorProp === 'default';
|
|
98
103
|
const isViewTypeLink = viewType === 'link';
|
|
99
|
-
const iconSize = iconSizeMap.get(size);
|
|
104
|
+
const iconSize = (_iconSizeMap = iconSizeMap(theme)) === null || _iconSizeMap === void 0 ? void 0 : _iconSizeMap.get(size);
|
|
100
105
|
const paddingSize = isViewTypeLink ? 0 : viewType === 'outlined' ? outlinedPaddingSizeMap.get(size) : paddingSizeMap.get(size);
|
|
101
106
|
const typographySize = typographySizeMap.get(size);
|
|
102
107
|
const iconMarginSize = iconMarginSizeMap.get(size);
|
|
103
108
|
const minHeightSize = isViewTypeLink ? minHeightSizeLinkMap.get(size) : minHeightSizeMap.get(size);
|
|
104
109
|
const color = getProp(colors, colorProp, colorProp);
|
|
105
110
|
const TagName = href ? 'a' : 'button';
|
|
106
|
-
const _ButtonRootCSS = ButtonRootCSS(color, isColorDefault, viewType, loading, theme);
|
|
111
|
+
const _ButtonRootCSS = ButtonRootCSS(color, isColorDefault, viewType, loading, disabled, theme);
|
|
107
112
|
const _ButtonIconCSS = ButtonIconCSS(endIcon, label, startIcon, iconMarginSize, iconSize, theme);
|
|
108
113
|
const _NonStartIconCSS = NonStartIconCSS(iconSize, theme);
|
|
109
|
-
const _ButtonLabelCSS = ButtonLabelCSS(loading, iconMarginSize);
|
|
114
|
+
const _ButtonLabelCSS = ButtonLabelCSS(loading, iconMarginSize, theme);
|
|
110
115
|
const _ButtonSizeCSS = ButtonSizeCSS(paddingSize, minHeightSize, theme);
|
|
111
116
|
const _onClick = e => {
|
|
112
117
|
if (href) e.preventDefault(); //Prevent open link when click
|
|
@@ -115,13 +120,6 @@ const Button = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference) =
|
|
|
115
120
|
if (!isViewTypeLink) rippleRef.current.start(e);
|
|
116
121
|
onClick && onClick(e);
|
|
117
122
|
};
|
|
118
|
-
useEffect(() => {
|
|
119
|
-
if (href) {
|
|
120
|
-
const qs = urlParams ? '?' + new URLSearchParams(urlParams).toString() : '';
|
|
121
|
-
const url = href + qs;
|
|
122
|
-
setUrlState(url);
|
|
123
|
-
}
|
|
124
|
-
}, [href, urlParams]);
|
|
125
123
|
useImperativeHandle(reference, () => {
|
|
126
124
|
const currentRef = ref.current || {};
|
|
127
125
|
currentRef.element = ref.current;
|
|
@@ -206,7 +204,7 @@ const Button = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference) =
|
|
|
206
204
|
id: id,
|
|
207
205
|
type: type,
|
|
208
206
|
className: classNames('DGN-UI-Button', disabled && 'disabled', viewType, size, className),
|
|
209
|
-
href:
|
|
207
|
+
href: url || null,
|
|
210
208
|
...other
|
|
211
209
|
}, start, jsx(Typography, {
|
|
212
210
|
css: _ButtonLabelCSS,
|
|
@@ -218,7 +216,7 @@ const Button = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference) =
|
|
|
218
216
|
ref: rippleRef,
|
|
219
217
|
color: getRippleColor(colorProp, viewType, allColors)
|
|
220
218
|
}) : null);
|
|
221
|
-
}, [children, className, colorProp, disabled, endIcon, href, id, labelProp, labelProps, loading, onClick, size, startIcon, stopPropagation, type, urlParams, viewType,
|
|
219
|
+
}, [children, className, colorProp, disabled, endIcon, href, id, labelProp, labelProps, loading, onClick, size, startIcon, stopPropagation, type, urlParams, viewType, theme]);
|
|
222
220
|
}));
|
|
223
221
|
const NonStartIconCSS = (iconSize, {
|
|
224
222
|
spacing
|
|
@@ -247,7 +245,9 @@ const ButtonIconCSS = (endIcon, label, startIcon, iconMarginSize, iconSize, {
|
|
|
247
245
|
${parseWidthHeight(iconSize)};
|
|
248
246
|
}
|
|
249
247
|
`;
|
|
250
|
-
const ButtonLabelCSS = (loading, iconMarginSize
|
|
248
|
+
const ButtonLabelCSS = (loading, iconMarginSize, {
|
|
249
|
+
spacing
|
|
250
|
+
}) => css`
|
|
251
251
|
${whiteSpaceNoWrap};
|
|
252
252
|
${textColor('inherit')};
|
|
253
253
|
margin-left: ${spacing(loading ? iconMarginSize : 0)};
|
|
@@ -258,7 +258,7 @@ const ButtonSizeCSS = (paddingSize, minHeightSize, {
|
|
|
258
258
|
padding: ${spacing(paddingSize)};
|
|
259
259
|
${parseMinWidthHeight('max-content', minHeightSize)};
|
|
260
260
|
`;
|
|
261
|
-
const ButtonRootCSS = (color, isColorDefault, viewType, loading, {
|
|
261
|
+
const ButtonRootCSS = (color, isColorDefault, viewType, loading, disabled, {
|
|
262
262
|
colors
|
|
263
263
|
}) => css`
|
|
264
264
|
${displayInlineFlex};
|
|
@@ -273,7 +273,9 @@ const ButtonRootCSS = (color, isColorDefault, viewType, loading, {
|
|
|
273
273
|
${userSelectNone};
|
|
274
274
|
${parseHeight('max-content')};
|
|
275
275
|
text-decoration: none;
|
|
276
|
-
|
|
276
|
+
${disabled && css`
|
|
277
|
+
transition: all 0.5s;
|
|
278
|
+
`};
|
|
277
279
|
${loading && pointerEventsNone};
|
|
278
280
|
${viewType === 'outlined' && css`
|
|
279
281
|
${textColor(color)};
|
|
@@ -286,29 +288,29 @@ const ButtonRootCSS = (color, isColorDefault, viewType, loading, {
|
|
|
286
288
|
}
|
|
287
289
|
`)}
|
|
288
290
|
${isColorDefault && css`
|
|
289
|
-
${border(1, getProp(colors, 'system
|
|
290
|
-
${textColor(getProp(colors, 'system
|
|
291
|
+
${border(1, getProp(colors, 'system/rest'))};
|
|
292
|
+
${textColor(getProp(colors, 'system/rest'))};
|
|
291
293
|
${loading && css`
|
|
292
|
-
${textColor(getProp(colors, 'system
|
|
293
|
-
${borderColor(getProp(colors, 'system
|
|
294
|
-
${bgColor(hexToRGBA(getProp(colors, 'system
|
|
294
|
+
${textColor(getProp(colors, 'system/active'))};
|
|
295
|
+
${borderColor(getProp(colors, 'system/active'))};
|
|
296
|
+
${bgColor(hexToRGBA(getProp(colors, 'system/active'), alphaLoading))};
|
|
295
297
|
`}
|
|
296
298
|
${Object.keys(alphaPseudo).map(key => css`
|
|
297
299
|
&: ${key} {
|
|
298
|
-
${textColor(getProp(colors, 'system
|
|
299
|
-
${borderColor(getProp(colors, 'system
|
|
300
|
-
${bgColor(hexToRGBA(getProp(colors, 'system
|
|
300
|
+
${textColor(getProp(colors, 'system/active'))};
|
|
301
|
+
${borderColor(getProp(colors, 'system/active'))};
|
|
302
|
+
${bgColor(hexToRGBA(getProp(colors, 'system/active'), alphaPseudo[key]))};
|
|
301
303
|
}
|
|
302
304
|
`)} // &:hover | &:focus | &:active
|
|
303
305
|
`}
|
|
304
306
|
&.disabled {
|
|
305
|
-
${borderColor(getProp(colors, 'system
|
|
307
|
+
${borderColor(getProp(colors, 'system/disabled'))};
|
|
306
308
|
${bgColor('transparent')};
|
|
307
309
|
}
|
|
308
310
|
`}
|
|
309
311
|
${viewType === 'filled' && css`
|
|
310
312
|
${borderNone};
|
|
311
|
-
${textColor(getProp(colors, 'system
|
|
313
|
+
${textColor(getProp(colors, 'system/standard'))};
|
|
312
314
|
${bgColor(color)};
|
|
313
315
|
font-weight: bold;
|
|
314
316
|
${loading && css`
|
|
@@ -322,16 +324,16 @@ const ButtonRootCSS = (color, isColorDefault, viewType, loading, {
|
|
|
322
324
|
filter: brightness(0.7);
|
|
323
325
|
}
|
|
324
326
|
${isColorDefault && css`
|
|
325
|
-
${bgColor(getProp(colors, 'system
|
|
326
|
-
${loading && bgColor(getProp(colors, 'system
|
|
327
|
+
${bgColor(getProp(colors, 'system/rest'))};
|
|
328
|
+
${loading && bgColor(getProp(colors, 'system/active'))};
|
|
327
329
|
&:hover,
|
|
328
330
|
&:focus,
|
|
329
331
|
&:active {
|
|
330
|
-
${bgColor(getProp(colors, 'system
|
|
332
|
+
${bgColor(getProp(colors, 'system/active'))};
|
|
331
333
|
}
|
|
332
334
|
`}
|
|
333
335
|
&.disabled {
|
|
334
|
-
${bgColor(getProp(colors, 'fill
|
|
336
|
+
${bgColor(getProp(colors, 'fill/disabled'))};
|
|
335
337
|
}
|
|
336
338
|
`}
|
|
337
339
|
${viewType === 'text' && css`
|
|
@@ -345,15 +347,15 @@ const ButtonRootCSS = (color, isColorDefault, viewType, loading, {
|
|
|
345
347
|
}
|
|
346
348
|
`)}
|
|
347
349
|
${isColorDefault && css`
|
|
348
|
-
${textColor(getProp(colors, 'system
|
|
350
|
+
${textColor(getProp(colors, 'system/rest'))};
|
|
349
351
|
${loading && css`
|
|
350
|
-
${textColor(getProp(colors, 'system
|
|
351
|
-
${bgColor(hexToRGBA(getProp(colors, 'system
|
|
352
|
+
${textColor(getProp(colors, 'system/active'))};
|
|
353
|
+
${bgColor(hexToRGBA(getProp(colors, 'system/active'), alphaLoading))};
|
|
352
354
|
`}
|
|
353
355
|
${Object.keys(alphaPseudo).map(key => css`
|
|
354
356
|
&: ${key} {
|
|
355
|
-
${textColor(getProp(colors, 'system
|
|
356
|
-
${bgColor(hexToRGBA(getProp(colors, 'system
|
|
357
|
+
${textColor(getProp(colors, 'system/active'))};
|
|
358
|
+
${bgColor(hexToRGBA(getProp(colors, 'system/active'), alphaPseudo[key]))};
|
|
357
359
|
}
|
|
358
360
|
`)}
|
|
359
361
|
`}
|
|
@@ -363,7 +365,7 @@ const ButtonRootCSS = (color, isColorDefault, viewType, loading, {
|
|
|
363
365
|
`}
|
|
364
366
|
${viewType === 'link' && css`
|
|
365
367
|
${borderNone};
|
|
366
|
-
${textColor(isColorDefault ? getProp(colors, 'semantic
|
|
368
|
+
${textColor(isColorDefault ? getProp(colors, 'semantic/info') : color)};
|
|
367
369
|
${bgColor('transparent')};
|
|
368
370
|
${loading && css`
|
|
369
371
|
filter: brightness(0.85);
|
|
@@ -378,7 +380,7 @@ const ButtonRootCSS = (color, isColorDefault, viewType, loading, {
|
|
|
378
380
|
`}
|
|
379
381
|
&.disabled {
|
|
380
382
|
${cursorNotAllowed};
|
|
381
|
-
${textColor(getProp(colors, 'system
|
|
383
|
+
${textColor(getProp(colors, 'system/disabled'))};
|
|
382
384
|
filter: brightness(1);
|
|
383
385
|
}
|
|
384
386
|
`;
|
|
@@ -15,6 +15,7 @@ const allNewAttached = new FormData();
|
|
|
15
15
|
const attached = []; // attached = [...dataState, ...newDataState]
|
|
16
16
|
const chosenItems = [];
|
|
17
17
|
const getType = data => {
|
|
18
|
+
if (!data) return null;
|
|
18
19
|
if (data !== null && data !== void 0 && data.type) {
|
|
19
20
|
var _type$match;
|
|
20
21
|
const pattern = /word|sheet|presentation|pdf|image|compressed/i;
|
|
@@ -457,7 +458,7 @@ const Attachment = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, referenc
|
|
|
457
458
|
recentRemovedAttached,
|
|
458
459
|
removedAttached: removedAttachedRef.current,
|
|
459
460
|
oldAttached,
|
|
460
|
-
allNewAttached:
|
|
461
|
+
allNewAttached: tempNewDataState
|
|
461
462
|
});
|
|
462
463
|
!!onRemoveProp && onRemoveProp(recentRemovedAttached);
|
|
463
464
|
onClosePopup();
|
|
@@ -1467,17 +1468,17 @@ Attachment.propTypes = {
|
|
|
1467
1468
|
allowSort: PropTypes.bool,
|
|
1468
1469
|
/** Class for component. */
|
|
1469
1470
|
className: PropTypes.string,
|
|
1470
|
-
/** List attachment:<br />
|
|
1471
|
-
* [{<br />
|
|
1472
|
-
* "AttachmentID": "ATT2U8O7YPTF1KSNCW3X",<br />
|
|
1473
|
-
* "URL": "https://apricot.diginet.com.vn/cdn-dev/file/8a07bee1eeff17a14eee.jpg?path=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmaWxlUGF0aCI6Ii8yMDIwLzA4LzQ0YjNhYjQ4LTMwNGQtNDQ3NC05ZDk0LWNkNGVlMDQwOGNlMy5qcGciLCJmaWxlTmFtZSI6IjhhMDdiZWUxZWVmZjE3YTE0ZWVlLmpwZyIsImZpbGVTaXplIjoyNDg4MzcsImZpbGVUeXBlIjoiaW1hZ2UvanBlZyIsImlhdCI6MTU5ODI0NDMwMiwiZXhwIjo4Nzk5ODI0NDMwMn0.fow6O5fp2z3vieA9gom5RRwQ7xxwBx9_7X2Fe8T2YI0",<br />
|
|
1474
|
-
* "FileName": "8a07bee1eeff17a14eee.jpg",<br />
|
|
1475
|
-
* "FileSize": 248837,<br />
|
|
1476
|
-
* "KeyID": "W39OAD3YGLCWAQKV1D6PGEKNW4RLGVTZTUWLYEVFQ2QG8AOCXW",<br />
|
|
1477
|
-
* "CreateUserID": "LEMONADMIN",<br />
|
|
1478
|
-
* "CreateDate": "2020-08-24T11:54:04.307Z",<br />
|
|
1479
|
-
* "UserName": "Quản trị hệ thống"<br />
|
|
1480
|
-
* }, ...]
|
|
1471
|
+
/** List attachment:<br />
|
|
1472
|
+
* [{<br />
|
|
1473
|
+
* "AttachmentID": "ATT2U8O7YPTF1KSNCW3X",<br />
|
|
1474
|
+
* "URL": "https://apricot.diginet.com.vn/cdn-dev/file/8a07bee1eeff17a14eee.jpg?path=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmaWxlUGF0aCI6Ii8yMDIwLzA4LzQ0YjNhYjQ4LTMwNGQtNDQ3NC05ZDk0LWNkNGVlMDQwOGNlMy5qcGciLCJmaWxlTmFtZSI6IjhhMDdiZWUxZWVmZjE3YTE0ZWVlLmpwZyIsImZpbGVTaXplIjoyNDg4MzcsImZpbGVUeXBlIjoiaW1hZ2UvanBlZyIsImlhdCI6MTU5ODI0NDMwMiwiZXhwIjo4Nzk5ODI0NDMwMn0.fow6O5fp2z3vieA9gom5RRwQ7xxwBx9_7X2Fe8T2YI0",<br />
|
|
1475
|
+
* "FileName": "8a07bee1eeff17a14eee.jpg",<br />
|
|
1476
|
+
* "FileSize": 248837,<br />
|
|
1477
|
+
* "KeyID": "W39OAD3YGLCWAQKV1D6PGEKNW4RLGVTZTUWLYEVFQ2QG8AOCXW",<br />
|
|
1478
|
+
* "CreateUserID": "LEMONADMIN",<br />
|
|
1479
|
+
* "CreateDate": "2020-08-24T11:54:04.307Z",<br />
|
|
1480
|
+
* "UserName": "Quản trị hệ thống"<br />
|
|
1481
|
+
* }, ...]
|
|
1481
1482
|
*/
|
|
1482
1483
|
data: PropTypes.array,
|
|
1483
1484
|
/** The message to display when deleting files. */
|
|
@@ -1508,16 +1509,16 @@ Attachment.propTypes = {
|
|
|
1508
1509
|
onChange: PropTypes.func,
|
|
1509
1510
|
/** Download attached event, if not it will use default. */
|
|
1510
1511
|
onDownload: PropTypes.func,
|
|
1511
|
-
/**
|
|
1512
|
-
* event when removed file(s)
|
|
1513
|
-
*
|
|
1514
|
-
* return data: {<br/>
|
|
1515
|
-
* attached: [Files] (insist old and all new files )<br/>
|
|
1516
|
-
* allNewAttached: [Files]<br/>
|
|
1517
|
-
* oldAttached: [Files]<br/>
|
|
1518
|
-
* removedAttached: [Files]<br/>
|
|
1519
|
-
* element: [NodeList (just removed)]<br/>
|
|
1520
|
-
* }
|
|
1512
|
+
/**
|
|
1513
|
+
* event when removed file(s)
|
|
1514
|
+
*
|
|
1515
|
+
* return data: {<br/>
|
|
1516
|
+
* attached: [Files] (insist old and all new files )<br/>
|
|
1517
|
+
* allNewAttached: [Files]<br/>
|
|
1518
|
+
* oldAttached: [Files]<br/>
|
|
1519
|
+
* removedAttached: [Files]<br/>
|
|
1520
|
+
* element: [NodeList (just removed)]<br/>
|
|
1521
|
+
* }
|
|
1521
1522
|
*/
|
|
1522
1523
|
onRemove: PropTypes.func,
|
|
1523
1524
|
/** View attached event, if not it will use default. */
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -42,8 +42,17 @@ npm test
|
|
|
42
42
|
|
|
43
43
|
## Changelog
|
|
44
44
|
|
|
45
|
+
## 1.4.28
|
|
46
|
+
|
|
47
|
+
- \[Fixed\]: Attachment – Fix allNewAttached in onChange after delete
|
|
48
|
+
|
|
49
|
+
## 1.4.27
|
|
50
|
+
|
|
51
|
+
- \[Changed\]: Button – Remove transition when disabled
|
|
52
|
+
|
|
45
53
|
## 1.4.26
|
|
46
54
|
|
|
55
|
+
- \[Added\]: IconMenu – Add MHRP13N0005, MHRP13N0006
|
|
47
56
|
- \[Changed\]: Icon – Add theme components default props
|
|
48
57
|
- \[Fixed\]: Chip – Fix not lineClamp
|
|
49
58
|
- \[Fixed\]: Popover – Fix shifting popover
|