diginet-core-ui 1.4.25-beta.4 → 1.4.26-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/button/index.js +39 -39
- package/package.json +1 -1
- package/readme.md +8 -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,10 +93,15 @@ 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);
|
|
@@ -106,7 +111,7 @@ const Button = /*#__PURE__*/memo( /*#__PURE__*/forwardRef((inProps, reference) =
|
|
|
106
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)};
|
|
@@ -288,29 +288,29 @@ const ButtonRootCSS = (color, isColorDefault, viewType, loading, disabled, {
|
|
|
288
288
|
}
|
|
289
289
|
`)}
|
|
290
290
|
${isColorDefault && css`
|
|
291
|
-
${border(1, getProp(colors, 'system
|
|
292
|
-
${textColor(getProp(colors, 'system
|
|
291
|
+
${border(1, getProp(colors, 'system/rest'))};
|
|
292
|
+
${textColor(getProp(colors, 'system/rest'))};
|
|
293
293
|
${loading && css`
|
|
294
|
-
${textColor(getProp(colors, 'system
|
|
295
|
-
${borderColor(getProp(colors, 'system
|
|
296
|
-
${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))};
|
|
297
297
|
`}
|
|
298
298
|
${Object.keys(alphaPseudo).map(key => css`
|
|
299
299
|
&: ${key} {
|
|
300
|
-
${textColor(getProp(colors, 'system
|
|
301
|
-
${borderColor(getProp(colors, 'system
|
|
302
|
-
${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]))};
|
|
303
303
|
}
|
|
304
304
|
`)} // &:hover | &:focus | &:active
|
|
305
305
|
`}
|
|
306
306
|
&.disabled {
|
|
307
|
-
${borderColor(getProp(colors, 'system
|
|
307
|
+
${borderColor(getProp(colors, 'system/disabled'))};
|
|
308
308
|
${bgColor('transparent')};
|
|
309
309
|
}
|
|
310
310
|
`}
|
|
311
311
|
${viewType === 'filled' && css`
|
|
312
312
|
${borderNone};
|
|
313
|
-
${textColor(getProp(colors, 'system
|
|
313
|
+
${textColor(getProp(colors, 'system/standard'))};
|
|
314
314
|
${bgColor(color)};
|
|
315
315
|
font-weight: bold;
|
|
316
316
|
${loading && css`
|
|
@@ -324,16 +324,16 @@ const ButtonRootCSS = (color, isColorDefault, viewType, loading, disabled, {
|
|
|
324
324
|
filter: brightness(0.7);
|
|
325
325
|
}
|
|
326
326
|
${isColorDefault && css`
|
|
327
|
-
${bgColor(getProp(colors, 'system
|
|
328
|
-
${loading && bgColor(getProp(colors, 'system
|
|
327
|
+
${bgColor(getProp(colors, 'system/rest'))};
|
|
328
|
+
${loading && bgColor(getProp(colors, 'system/active'))};
|
|
329
329
|
&:hover,
|
|
330
330
|
&:focus,
|
|
331
331
|
&:active {
|
|
332
|
-
${bgColor(getProp(colors, 'system
|
|
332
|
+
${bgColor(getProp(colors, 'system/active'))};
|
|
333
333
|
}
|
|
334
334
|
`}
|
|
335
335
|
&.disabled {
|
|
336
|
-
${bgColor(getProp(colors, 'fill
|
|
336
|
+
${bgColor(getProp(colors, 'fill/disabled'))};
|
|
337
337
|
}
|
|
338
338
|
`}
|
|
339
339
|
${viewType === 'text' && css`
|
|
@@ -347,15 +347,15 @@ const ButtonRootCSS = (color, isColorDefault, viewType, loading, disabled, {
|
|
|
347
347
|
}
|
|
348
348
|
`)}
|
|
349
349
|
${isColorDefault && css`
|
|
350
|
-
${textColor(getProp(colors, 'system
|
|
350
|
+
${textColor(getProp(colors, 'system/rest'))};
|
|
351
351
|
${loading && css`
|
|
352
|
-
${textColor(getProp(colors, 'system
|
|
353
|
-
${bgColor(hexToRGBA(getProp(colors, 'system
|
|
352
|
+
${textColor(getProp(colors, 'system/active'))};
|
|
353
|
+
${bgColor(hexToRGBA(getProp(colors, 'system/active'), alphaLoading))};
|
|
354
354
|
`}
|
|
355
355
|
${Object.keys(alphaPseudo).map(key => css`
|
|
356
356
|
&: ${key} {
|
|
357
|
-
${textColor(getProp(colors, 'system
|
|
358
|
-
${bgColor(hexToRGBA(getProp(colors, 'system
|
|
357
|
+
${textColor(getProp(colors, 'system/active'))};
|
|
358
|
+
${bgColor(hexToRGBA(getProp(colors, 'system/active'), alphaPseudo[key]))};
|
|
359
359
|
}
|
|
360
360
|
`)}
|
|
361
361
|
`}
|
|
@@ -365,7 +365,7 @@ const ButtonRootCSS = (color, isColorDefault, viewType, loading, disabled, {
|
|
|
365
365
|
`}
|
|
366
366
|
${viewType === 'link' && css`
|
|
367
367
|
${borderNone};
|
|
368
|
-
${textColor(isColorDefault ? getProp(colors, 'semantic
|
|
368
|
+
${textColor(isColorDefault ? getProp(colors, 'semantic/info') : color)};
|
|
369
369
|
${bgColor('transparent')};
|
|
370
370
|
${loading && css`
|
|
371
371
|
filter: brightness(0.85);
|
|
@@ -380,7 +380,7 @@ const ButtonRootCSS = (color, isColorDefault, viewType, loading, disabled, {
|
|
|
380
380
|
`}
|
|
381
381
|
&.disabled {
|
|
382
382
|
${cursorNotAllowed};
|
|
383
|
-
${textColor(getProp(colors, 'system
|
|
383
|
+
${textColor(getProp(colors, 'system/disabled'))};
|
|
384
384
|
filter: brightness(1);
|
|
385
385
|
}
|
|
386
386
|
`;
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -42,6 +42,14 @@ npm test
|
|
|
42
42
|
|
|
43
43
|
## Changelog
|
|
44
44
|
|
|
45
|
+
## 1.4.26
|
|
46
|
+
|
|
47
|
+
- \[Changed\]: Icon – Add theme components default props
|
|
48
|
+
- \[Fixed\]: Chip – Fix not lineClamp
|
|
49
|
+
- \[Fixed\]: Popover – Fix shifting popover
|
|
50
|
+
- \[Fixed\]: Label – Fix label missing margin in DatePicker
|
|
51
|
+
- \[Fixed\]: Attachment – Add prop allowDelete
|
|
52
|
+
|
|
45
53
|
## 1.4.25
|
|
46
54
|
|
|
47
55
|
- \[Added\]: DatePicker – Add DateInput
|