@via-profit/ui-kit 0.10.0 → 0.11.0
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/Badge/BadgeBase.d.ts +8 -3
- package/Badge/BadgeBase.js +5 -6
- package/Badge/BadgeContainer.d.ts +8 -0
- package/Badge/BadgeContainer.js +148 -10
- package/Badge/BadgeDeleteButton.d.ts +4 -4
- package/Badge/BadgeDeleteButton.js +5 -4
- package/Badge/BadgeDeleteIcon.d.ts +4 -0
- package/Badge/BadgeDeleteIcon.js +9 -0
- package/Badge/BadgeOutlined.js +2 -2
- package/Badge/BadgeStandard.js +2 -2
- package/Badge/BadgeStyled.d.ts +2 -5
- package/Badge/BadgeStyled.js +4 -163
- package/Badge/index.d.ts +3 -4
- package/Badge/index.js +17 -3
- package/CHANGELOG.md +18 -0
- package/DatePicker/index.js +3 -1
- package/HintPopover/index.js +1 -1
- package/Menu/MenuContainer.js +5 -3
- package/Selectbox/SelectboxMenu.js +1 -1
- package/ThemeProvider/tokens.d.ts +1 -1
- package/ThemeProvider/tokens.js +1 -1
- package/Toast/ToastContainer.d.ts +5 -3
- package/Toast/ToastContainer.js +1 -1
- package/Toast/ToastItem.d.ts +2 -2
- package/Toast/ToastItem.js +11 -1
- package/Toast/index.d.ts +1 -1
- package/Toast/store.d.ts +15 -0
- package/Toast/store.js +5 -1
- package/esm/Badge/BadgeBase.js +5 -6
- package/esm/Badge/BadgeContainer.js +148 -10
- package/esm/Badge/BadgeDeleteButton.js +5 -4
- package/esm/Badge/BadgeDeleteIcon.js +4 -0
- package/esm/Badge/BadgeOutlined.js +2 -2
- package/esm/Badge/BadgeStandard.js +2 -2
- package/esm/Badge/BadgeStyled.js +2 -163
- package/esm/Badge/index.js +17 -3
- package/esm/DatePicker/index.js +3 -1
- package/esm/HintPopover/index.js +1 -1
- package/esm/Menu/MenuContainer.js +5 -3
- package/esm/Selectbox/SelectboxMenu.js +1 -1
- package/esm/ThemeProvider/tokens.js +1 -1
- package/esm/Toast/ToastContainer.js +2 -2
- package/esm/Toast/ToastItem.js +12 -2
- package/esm/Toast/store.js +4 -0
- package/esm/utils/TabManager.js +1 -1
- package/package.json +6 -1
- package/utils/TabManager.js +1 -1
package/Menu/MenuContainer.js
CHANGED
|
@@ -285,10 +285,11 @@ const MenuContainer = react_1.default.forwardRef((props, ref) => {
|
|
|
285
285
|
if (!isOpen) {
|
|
286
286
|
// The menu is already closed by the parent, so onRequestClose must not be called again
|
|
287
287
|
dispatch((0, context_1.actionSetmenuState)({ markedIndex: -1, hoveredIndex: -1 }));
|
|
288
|
-
// Otherwise the focus is lost together with the unmounted list
|
|
288
|
+
// Otherwise the focus is lost together with the unmounted list.
|
|
289
|
+
// Without the scroll: an anchor in a sticky header is scrolled to its place in the document
|
|
289
290
|
if (hasFocusRef.current) {
|
|
290
291
|
hasFocusRef.current = false;
|
|
291
|
-
(_a = lastAnchorRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
292
|
+
(_a = lastAnchorRef.current) === null || _a === void 0 ? void 0 : _a.focus({ preventScroll: true });
|
|
292
293
|
}
|
|
293
294
|
return;
|
|
294
295
|
}
|
|
@@ -303,7 +304,8 @@ const MenuContainer = react_1.default.forwardRef((props, ref) => {
|
|
|
303
304
|
var _a;
|
|
304
305
|
scrollToFirstSelected();
|
|
305
306
|
if (autofocus) {
|
|
306
|
-
|
|
307
|
+
// The list is already placed by the popper: focusing must not scroll the page
|
|
308
|
+
(_a = menuListRef.current) === null || _a === void 0 ? void 0 : _a.focus({ preventScroll: true });
|
|
307
309
|
}
|
|
308
310
|
}, 15);
|
|
309
311
|
}, [isOpen, autofocus, dispatch, scrollToFirstSelected]);
|
|
@@ -59,7 +59,7 @@ const SelectboxMenu = React.forwardRef((props, ref) => {
|
|
|
59
59
|
if (onRequestClose) {
|
|
60
60
|
onRequestClose(evt);
|
|
61
61
|
}
|
|
62
|
-
anchorElement === null || anchorElement === void 0 ? void 0 : anchorElement.focus();
|
|
62
|
+
anchorElement === null || anchorElement === void 0 ? void 0 : anchorElement.focus({ preventScroll: true });
|
|
63
63
|
}
|
|
64
64
|
}, [onRequestClose, anchorElement]);
|
|
65
65
|
return (React.createElement(Menu_1.default, Object.assign({ ref: ref, offset: 0, anchorPos: anchorPos, multiple: multiple, items: items, value: value, isOpen: isOpen && items.length > 0, autofocus: true, anchorElement: anchorElement, closeOutsideClick: false, getOptionSelected: getOptionSelected, onSelectItem: handleSelectItem, closeOnSelect: !multiple, onRequestClose: handleRequestClose }, restMenuProps), ({ index, item }, itemProps) => children({ index, item: item }, itemProps)));
|
|
@@ -31,7 +31,7 @@ export declare const CONTROL_LINE_HEIGHT = "1.2em";
|
|
|
31
31
|
*/
|
|
32
32
|
export declare const BORDER_WIDTH = "0.0625em";
|
|
33
33
|
/**
|
|
34
|
-
* The border of the buttons. The standard and
|
|
34
|
+
* The border of the buttons. The standard, plain and soft buttons have no border:
|
|
35
35
|
* their padding is larger by this width, so all the variants have the same size
|
|
36
36
|
*/
|
|
37
37
|
export declare const CONTROL_BORDER = "0.0625em";
|
package/ThemeProvider/tokens.js
CHANGED
|
@@ -53,7 +53,7 @@ exports.CONTROL_LINE_HEIGHT = '1.2em';
|
|
|
53
53
|
*/
|
|
54
54
|
exports.BORDER_WIDTH = '0.0625em';
|
|
55
55
|
/**
|
|
56
|
-
* The border of the buttons. The standard and
|
|
56
|
+
* The border of the buttons. The standard, plain and soft buttons have no border:
|
|
57
57
|
* their padding is larger by this width, so all the variants have the same size
|
|
58
58
|
*/
|
|
59
59
|
exports.CONTROL_BORDER = exports.BORDER_WIDTH;
|
|
@@ -3,7 +3,7 @@ import { ToastCardProps } from './ToastCard';
|
|
|
3
3
|
import { ToastIconProps } from './ToastIcon';
|
|
4
4
|
import { ToastCloseButtonProps } from './ToastCloseButton';
|
|
5
5
|
import { ToastActionProps } from './ToastAction';
|
|
6
|
-
import { ToastPosition } from './store';
|
|
6
|
+
import { ToastAutoClose, ToastPosition } from './store';
|
|
7
7
|
export interface ToastContainerProps {
|
|
8
8
|
/**
|
|
9
9
|
* The container shows only the toasts with the same `containerId`.
|
|
@@ -17,10 +17,12 @@ export interface ToastContainerProps {
|
|
|
17
17
|
*/
|
|
18
18
|
readonly position?: ToastPosition;
|
|
19
19
|
/**
|
|
20
|
-
* The time in ms before the toast closes, or `false` to keep the toasts until the user closes them
|
|
20
|
+
* The time in ms before the toast closes, or `false` to keep the toasts until the user closes them.
|
|
21
|
+
* The object sets the time for each type, e.g. `{ success: 2000, error: false }`;
|
|
22
|
+
* a type not listed uses `default` — then 5000
|
|
21
23
|
* Default: 5000
|
|
22
24
|
*/
|
|
23
|
-
readonly autoClose?:
|
|
25
|
+
readonly autoClose?: ToastAutoClose;
|
|
24
26
|
/**
|
|
25
27
|
* The maximum number of the toasts on the screen. The rest wait in the queue
|
|
26
28
|
* Default: undefined (no limit)
|
package/Toast/ToastContainer.js
CHANGED
|
@@ -89,7 +89,7 @@ const useWindowFocused = () => {
|
|
|
89
89
|
return isFocused;
|
|
90
90
|
};
|
|
91
91
|
const ToastContainer = props => {
|
|
92
|
-
const { containerId, position = 'top-right', autoClose =
|
|
92
|
+
const { containerId, position = 'top-right', autoClose = store_1.TOAST_DEFAULT_AUTO_CLOSE, limit, closeButton = true, closeButtonLabel = 'Close', closeOnClick = true, pauseOnHover = true, pauseOnFocusLoss = true, newestOnTop = false, hotkey = 'F8', label = 'Notifications', zIndex, overrides, } = props;
|
|
93
93
|
const theme = (0, react_2.useTheme)();
|
|
94
94
|
const allToasts = react_1.default.useSyncExternalStore(store_1.toastStore.subscribe, store_1.toastStore.getSnapshot, store_1.toastStore.getServerSnapshot);
|
|
95
95
|
const toasts = react_1.default.useMemo(() => allToasts.filter(item => item.containerId === containerId), [allToasts, containerId]);
|
package/Toast/ToastItem.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { ToastCardProps } from './ToastCard';
|
|
|
3
3
|
import { ToastIconProps } from './ToastIcon';
|
|
4
4
|
import { ToastCloseButtonProps } from './ToastCloseButton';
|
|
5
5
|
import { ToastActionProps } from './ToastAction';
|
|
6
|
-
import { ToastPosition, ToastState } from './store';
|
|
6
|
+
import { ToastAutoClose, ToastPosition, ToastState } from './store';
|
|
7
7
|
export interface ToastItemComponents {
|
|
8
8
|
readonly Toast: React.ComponentType<ToastCardProps & React.RefAttributes<HTMLDivElement>>;
|
|
9
9
|
readonly Icon: React.ComponentType<ToastIconProps & React.RefAttributes<HTMLSpanElement>>;
|
|
@@ -11,7 +11,7 @@ export interface ToastItemComponents {
|
|
|
11
11
|
readonly Action: React.ComponentType<ToastActionProps & React.RefAttributes<HTMLButtonElement>>;
|
|
12
12
|
}
|
|
13
13
|
export interface ToastDefaults {
|
|
14
|
-
readonly autoClose:
|
|
14
|
+
readonly autoClose: ToastAutoClose;
|
|
15
15
|
readonly closeButton: boolean;
|
|
16
16
|
readonly closeOnClick: boolean;
|
|
17
17
|
readonly pauseOnHover: boolean;
|
package/Toast/ToastItem.js
CHANGED
|
@@ -28,12 +28,22 @@ const Actions = styled_1.default.div `
|
|
|
28
28
|
* The clicks on these elements are actions, not the click on the toast
|
|
29
29
|
*/
|
|
30
30
|
const INTERACTIVE = 'a, button, input, select, textarea, label, summary, [role="button"], [contenteditable="true"]';
|
|
31
|
+
/**
|
|
32
|
+
* The `autoClose` of the toast type: the own value of the type, then `default`, then 5000
|
|
33
|
+
*/
|
|
34
|
+
const getAutoClose = (autoClose, type) => {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
if (typeof autoClose === 'number' || autoClose === false) {
|
|
37
|
+
return autoClose;
|
|
38
|
+
}
|
|
39
|
+
return (_b = (_a = autoClose[type]) !== null && _a !== void 0 ? _a : autoClose.default) !== null && _b !== void 0 ? _b : store_1.TOAST_DEFAULT_AUTO_CLOSE;
|
|
40
|
+
};
|
|
31
41
|
const ToastItem = props => {
|
|
32
42
|
var _a, _b, _c, _d, _e;
|
|
33
43
|
const { toast, position, defaults, components, isWindowFocused } = props;
|
|
34
44
|
const { toastId, content, type = 'default', isLoading = false, description, actions, icon, onClick, onOpen, isClosing, version, } = toast;
|
|
35
45
|
// The loading toast waits for `toast.update`: it can not be closed by the timer or by the click
|
|
36
|
-
const autoClose = isLoading ? false : ((_a = toast.autoClose) !== null && _a !== void 0 ? _a : defaults.autoClose);
|
|
46
|
+
const autoClose = isLoading ? false : ((_a = toast.autoClose) !== null && _a !== void 0 ? _a : getAutoClose(defaults.autoClose, type));
|
|
37
47
|
const closeButton = isLoading ? false : ((_b = toast.closeButton) !== null && _b !== void 0 ? _b : defaults.closeButton);
|
|
38
48
|
const closeOnClick = isLoading ? false : ((_c = toast.closeOnClick) !== null && _c !== void 0 ? _c : defaults.closeOnClick);
|
|
39
49
|
const pauseOnHover = (_d = toast.pauseOnHover) !== null && _d !== void 0 ? _d : defaults.pauseOnHover;
|
package/Toast/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ToastContainer from './ToastContainer';
|
|
2
2
|
export { toast } from './store';
|
|
3
|
-
export type { ToastId, ToastType, ToastPosition, ToastOptions, ToastUpdateOptions, ToastContent, ToastContentProps, ToastAction as ToastActionItem, ToastState, } from './store';
|
|
3
|
+
export type { ToastId, ToastType, ToastPosition, ToastAutoClose, ToastAutoCloseByType, ToastOptions, ToastUpdateOptions, ToastContent, ToastContentProps, ToastAction as ToastActionItem, ToastState, } from './store';
|
|
4
4
|
export { ToastContainer };
|
|
5
5
|
export type { ToastContainerProps, ToastOverrides } from './ToastContainer';
|
|
6
6
|
export default ToastContainer;
|
package/Toast/store.d.ts
CHANGED
|
@@ -2,6 +2,21 @@ import React from 'react';
|
|
|
2
2
|
export type ToastId = string | number;
|
|
3
3
|
export type ToastType = 'default' | 'info' | 'success' | 'warning' | 'error';
|
|
4
4
|
export type ToastPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
|
|
5
|
+
/**
|
|
6
|
+
* The time to close the toasts for each type. A type not listed uses `default`
|
|
7
|
+
*/
|
|
8
|
+
export type ToastAutoCloseByType = {
|
|
9
|
+
readonly [type in ToastType]?: number | false;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The time in ms before the toast closes, `false` to keep it until the user closes it,
|
|
13
|
+
* or the time for each type of the toast
|
|
14
|
+
*/
|
|
15
|
+
export type ToastAutoClose = number | false | ToastAutoCloseByType;
|
|
16
|
+
/**
|
|
17
|
+
* The time to close the toast when `autoClose` does not set one
|
|
18
|
+
*/
|
|
19
|
+
export declare const TOAST_DEFAULT_AUTO_CLOSE = 5000;
|
|
5
20
|
export interface ToastContentProps {
|
|
6
21
|
/**
|
|
7
22
|
* Closes this toast
|
package/Toast/store.js
CHANGED
|
@@ -11,7 +11,11 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.toast = exports.toastStore = void 0;
|
|
14
|
+
exports.toast = exports.toastStore = exports.TOAST_DEFAULT_AUTO_CLOSE = void 0;
|
|
15
|
+
/**
|
|
16
|
+
* The time to close the toast when `autoClose` does not set one
|
|
17
|
+
*/
|
|
18
|
+
exports.TOAST_DEFAULT_AUTO_CLOSE = 5000;
|
|
15
19
|
let toasts = [];
|
|
16
20
|
const listeners = new Set();
|
|
17
21
|
let idCounter = 0;
|
package/esm/Badge/BadgeBase.js
CHANGED
|
@@ -15,6 +15,7 @@ import TextWrapper from './BadgeTextWrapper';
|
|
|
15
15
|
import Container from './BadgeContainer';
|
|
16
16
|
import ButtonDelete from './BadgeDeleteButton';
|
|
17
17
|
import Dot from './BadgeDot';
|
|
18
|
+
import DeleteIcon from './BadgeDeleteIcon';
|
|
18
19
|
const BadgeBase = (props, ref) => {
|
|
19
20
|
const { children, startIcon, dot = false, color, variant, overrides, onDelete, deleteButtonLabel = 'Delete', onClick, onKeyDown } = props, nativeProps = __rest(props, ["children", "startIcon", "dot", "color", "variant", "overrides", "onDelete", "deleteButtonLabel", "onClick", "onKeyDown"]);
|
|
20
21
|
const clickable = typeof onClick === 'function';
|
|
@@ -23,6 +24,7 @@ const BadgeBase = (props, ref) => {
|
|
|
23
24
|
IconWrapper: (overrides === null || overrides === void 0 ? void 0 : overrides.IconWrapper) || IconWrapper,
|
|
24
25
|
Container: (overrides === null || overrides === void 0 ? void 0 : overrides.Container) || Container,
|
|
25
26
|
ButtonDelete: (overrides === null || overrides === void 0 ? void 0 : overrides.ButtonDelete) || ButtonDelete,
|
|
27
|
+
DeleteIcon: (overrides === null || overrides === void 0 ? void 0 : overrides.DeleteIcon) || DeleteIcon,
|
|
26
28
|
Dot: (overrides === null || overrides === void 0 ? void 0 : overrides.Dot) || Dot,
|
|
27
29
|
}), [overrides]);
|
|
28
30
|
// A clickable badge acts as a button, so it is activated by Enter and Space too
|
|
@@ -42,14 +44,11 @@ const BadgeBase = (props, ref) => {
|
|
|
42
44
|
event.stopPropagation();
|
|
43
45
|
onDelete === null || onDelete === void 0 ? void 0 : onDelete(event);
|
|
44
46
|
}, [onDelete]);
|
|
45
|
-
return (React.createElement(overridesMap.Container, Object.assign({ role: clickable ? 'button' : undefined, tabIndex: clickable ? 0 : undefined }, nativeProps, { onClick: onClick, onKeyDown: handleKeyDown, color: color, ref: ref }),
|
|
47
|
+
return (React.createElement(overridesMap.Container, Object.assign({ role: clickable ? 'button' : undefined, tabIndex: clickable ? 0 : undefined }, nativeProps, { onClick: onClick, onKeyDown: handleKeyDown, color: color, variant: variant, ref: ref }),
|
|
46
48
|
dot && React.createElement(overridesMap.Dot, null),
|
|
47
49
|
typeof startIcon !== 'undefined' && startIcon !== null && (React.createElement(overridesMap.IconWrapper, null, startIcon)),
|
|
48
50
|
React.createElement(overridesMap.TextWrapper, null, children),
|
|
49
|
-
typeof onDelete === 'function' && (React.createElement(overridesMap.ButtonDelete
|
|
50
|
-
|
|
51
|
-
, {
|
|
52
|
-
// the pale soft badge has the colored icon, as the outlined one
|
|
53
|
-
variant: variant === 'soft' ? 'outlined' : variant, onClick: handleDelete, color: color, "aria-label": deleteButtonLabel }))));
|
|
51
|
+
typeof onDelete === 'function' && (React.createElement(overridesMap.ButtonDelete, { variant: variant, onClick: handleDelete, color: color, "aria-label": deleteButtonLabel },
|
|
52
|
+
React.createElement(overridesMap.DeleteIcon, null)))));
|
|
54
53
|
};
|
|
55
54
|
export default React.forwardRef(BadgeBase);
|
|
@@ -11,6 +11,76 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import React from 'react';
|
|
13
13
|
import styled from '@emotion/styled';
|
|
14
|
+
import { useTheme, css } from '@emotion/react';
|
|
15
|
+
import Color from '../Color';
|
|
16
|
+
import { themeFocusRing, BORDER_WIDTH } from '../ThemeProvider/tokens';
|
|
17
|
+
const parseColor = (color, fallback) => {
|
|
18
|
+
try {
|
|
19
|
+
return Color.fromString(color);
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
console.error(`invalid color value «${color}»`);
|
|
23
|
+
return fallback;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const getStandardColors = (color, theme) => {
|
|
27
|
+
switch (true) {
|
|
28
|
+
case color === 'primary':
|
|
29
|
+
return { $color: theme.color.accentPrimaryContrast, $background: theme.color.accentPrimary };
|
|
30
|
+
case color === 'secondary':
|
|
31
|
+
return {
|
|
32
|
+
$color: theme.color.accentSecondaryContrast,
|
|
33
|
+
$background: theme.color.accentSecondary,
|
|
34
|
+
};
|
|
35
|
+
case typeof color === 'undefined':
|
|
36
|
+
case color === 'default':
|
|
37
|
+
return { $background: theme.color.surface.darken(10), $color: theme.color.textPrimary };
|
|
38
|
+
default: {
|
|
39
|
+
const $background = parseColor(String(color), theme.color.surface);
|
|
40
|
+
return {
|
|
41
|
+
$background,
|
|
42
|
+
$color: $background.getContrast(theme.color.textPrimary) > 5
|
|
43
|
+
? theme.color.textPrimary
|
|
44
|
+
: theme.color.surface,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const getOutlinedColors = (color, theme) => {
|
|
50
|
+
switch (true) {
|
|
51
|
+
case color === 'primary':
|
|
52
|
+
return { $color: theme.color.accentPrimary, $background: theme.color.accentPrimary };
|
|
53
|
+
case color === 'secondary':
|
|
54
|
+
return { $color: theme.color.accentSecondary, $background: theme.color.accentSecondary };
|
|
55
|
+
case typeof color === 'undefined':
|
|
56
|
+
case color === 'default':
|
|
57
|
+
return {
|
|
58
|
+
$color: Color.fromString(theme.color.textPrimary.toString()),
|
|
59
|
+
$background: theme.color.textPrimary.lighten(100),
|
|
60
|
+
};
|
|
61
|
+
default: {
|
|
62
|
+
const c = parseColor(String(color), theme.color.textPrimary);
|
|
63
|
+
return { $color: c, $background: c };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* The pale background of the color and the text of the same hue: dark on the light theme,
|
|
69
|
+
* light on the dark one. `$background` is the color itself
|
|
70
|
+
*/
|
|
71
|
+
const getSoftColors = (color, theme) => {
|
|
72
|
+
const base = color === 'primary'
|
|
73
|
+
? theme.color.accentPrimary
|
|
74
|
+
: color === 'secondary'
|
|
75
|
+
? theme.color.accentSecondary
|
|
76
|
+
: typeof color === 'undefined' || color === 'default'
|
|
77
|
+
? theme.color.textPrimary
|
|
78
|
+
: parseColor(String(color), theme.color.textPrimary);
|
|
79
|
+
return {
|
|
80
|
+
$background: base,
|
|
81
|
+
$color: theme.isDark ? base.lighten(60) : base.darken(60),
|
|
82
|
+
};
|
|
83
|
+
};
|
|
14
84
|
const StyledBadge = styled.span `
|
|
15
85
|
border-radius: ${({ theme }) => theme.shape.radiusFactor * 2}em;
|
|
16
86
|
font-size: 1em;
|
|
@@ -22,17 +92,85 @@ const StyledBadge = styled.span `
|
|
|
22
92
|
background: none;
|
|
23
93
|
display: inline-flex;
|
|
24
94
|
align-items: center;
|
|
25
|
-
color: ${({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
95
|
+
color: ${({ theme }) => theme.color.textPrimary.toString()};
|
|
96
|
+
|
|
97
|
+
/* One styled element for all variants: switching them must not lose focus */
|
|
98
|
+
${({ $variant, $color, $background, $clickable, theme }) => $variant &&
|
|
99
|
+
css `
|
|
100
|
+
border-style: solid;
|
|
101
|
+
border-width: ${BORDER_WIDTH};
|
|
102
|
+
border-color: ${$background.toString()};
|
|
103
|
+
--badge-dot-color: ${($variant === 'standard' ? $color : $background).toString()};
|
|
104
|
+
|
|
105
|
+
${$variant === 'soft' &&
|
|
106
|
+
css `
|
|
107
|
+
color: ${$color.toString()};
|
|
108
|
+
background-color: ${$background.alpha(0.18).toString()};
|
|
109
|
+
border-color: transparent;
|
|
110
|
+
|
|
111
|
+
&:focus-visible {
|
|
112
|
+
outline-style: solid;
|
|
113
|
+
outline-width: 0.14em;
|
|
114
|
+
outline-color: ${$background.alpha(0.6).toString()};
|
|
115
|
+
}
|
|
116
|
+
`}
|
|
117
|
+
|
|
118
|
+
${$variant === 'soft'
|
|
119
|
+
? ''
|
|
120
|
+
: $variant === 'outlined'
|
|
121
|
+
? css `
|
|
122
|
+
color: ${$color.darken(30).toString()};
|
|
123
|
+
background-color: transparent;
|
|
124
|
+
|
|
125
|
+
&:focus-visible {
|
|
126
|
+
outline-style: solid;
|
|
127
|
+
outline-width: 0.14em;
|
|
128
|
+
outline-color: ${$background.rgbString()};
|
|
129
|
+
}
|
|
130
|
+
`
|
|
131
|
+
: css `
|
|
132
|
+
color: ${$color.toString()};
|
|
133
|
+
background-color: ${$background.toString()};
|
|
134
|
+
|
|
135
|
+
&:focus-visible {
|
|
136
|
+
outline-color: ${$background.rgbString() === theme.color.accentPrimary.rgbString()
|
|
137
|
+
? theme.color.textPrimary.toString()
|
|
138
|
+
: theme.color.accentPrimary.toString()};
|
|
139
|
+
}
|
|
140
|
+
`}
|
|
141
|
+
|
|
142
|
+
${$clickable &&
|
|
143
|
+
css `
|
|
144
|
+
cursor: pointer;
|
|
145
|
+
|
|
146
|
+
&:hover {
|
|
147
|
+
${$variant === 'soft'
|
|
148
|
+
? css `
|
|
149
|
+
background-color: ${$background.alpha(0.3).toString()};
|
|
150
|
+
`
|
|
151
|
+
: $variant === 'outlined'
|
|
152
|
+
? css `
|
|
153
|
+
background-color: ${$background.darken(20).alpha(0.1).toString()};
|
|
154
|
+
`
|
|
155
|
+
: css `
|
|
156
|
+
background-color: ${$background.darken(30).toString()};
|
|
157
|
+
border-color: ${$background.darken(30).toString()};
|
|
158
|
+
`}
|
|
159
|
+
}
|
|
160
|
+
`}
|
|
161
|
+
${themeFocusRing(theme)}
|
|
162
|
+
`}
|
|
32
163
|
`;
|
|
33
164
|
const BadgeContainer = (props, ref) => {
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
165
|
+
const { children, color, variant, onClick } = props, nativeProps = __rest(props, ["children", "color", "variant", "onClick"]);
|
|
166
|
+
const theme = useTheme();
|
|
167
|
+
const { $background, $color } = React.useMemo(() => !variant
|
|
168
|
+
? { $background: theme.color.surface, $color: theme.color.textPrimary }
|
|
169
|
+
: variant === 'soft'
|
|
170
|
+
? getSoftColors(color, theme)
|
|
171
|
+
: variant === 'outlined'
|
|
172
|
+
? getOutlinedColors(color, theme)
|
|
173
|
+
: getStandardColors(color, theme), [color, variant, theme]);
|
|
174
|
+
return (React.createElement(StyledBadge, Object.assign({}, nativeProps, { "$variant": variant, "$clickable": typeof onClick === 'function', "$color": $color, "$background": $background, onClick: onClick, ref: ref }), children));
|
|
37
175
|
};
|
|
38
176
|
export default React.forwardRef(BadgeContainer);
|
|
@@ -14,6 +14,7 @@ import styled from '@emotion/styled';
|
|
|
14
14
|
import { useTheme } from '@emotion/react';
|
|
15
15
|
import ButtonBase from '../Button/ButtonBase';
|
|
16
16
|
import Color from '../Color';
|
|
17
|
+
import DeleteIcon from './BadgeDeleteIcon';
|
|
17
18
|
const StyledButton = styled(ButtonBase) `
|
|
18
19
|
display: flex;
|
|
19
20
|
padding: 0.3em;
|
|
@@ -27,7 +28,9 @@ const StyledButton = styled(ButtonBase) `
|
|
|
27
28
|
position: relative;
|
|
28
29
|
`;
|
|
29
30
|
const BadgeDeleteButton = (props, ref) => {
|
|
30
|
-
const { color = 'default', variant = 'standard' } = props, nativeProps = __rest(props, ["color", "variant"]);
|
|
31
|
+
const { children, color = 'default', variant: badgeVariant = 'standard' } = props, nativeProps = __rest(props, ["children", "color", "variant"]);
|
|
32
|
+
// The pale soft badge has the colored icon, as the outlined one
|
|
33
|
+
const variant = badgeVariant === 'soft' ? 'outlined' : badgeVariant;
|
|
31
34
|
const theme = useTheme();
|
|
32
35
|
const { $color, $background } = React.useMemo(() => {
|
|
33
36
|
switch (true) {
|
|
@@ -80,8 +83,6 @@ const BadgeDeleteButton = (props, ref) => {
|
|
|
80
83
|
};
|
|
81
84
|
}
|
|
82
85
|
}, [color, variant, theme.color]);
|
|
83
|
-
return (React.createElement(StyledButton, Object.assign({}, nativeProps, { "$color": $color, "$background": $background, ref: ref }),
|
|
84
|
-
React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", version: "1.1", width: "1em", height: "1em", viewBox: "0 0 512 512" },
|
|
85
|
-
React.createElement("path", { d: "m256 0c-141.11 0-256 114.89-256 256s114.89 256 256 256 256-114.89 256-256-114.89-256-256-256zm0 39.385c119.81 0 216.62 96.805 216.62 216.62s-96.805 216.62-216.62 216.62-216.62-96.805-216.62-216.62 96.805-216.62 216.62-216.62zm-78.769 118.15a19.692 19.692 0 0 0-5.0961 0.67068 19.692 19.692 0 0 0-8.8293 5.0961 19.692 19.692 0 0 0 0 27.851l64.844 64.844-64.844 64.844a19.692 19.692 0 0 0 0 27.851 19.692 19.692 0 0 0 27.851 0l64.844-64.844 64.844 64.844a19.692 19.692 0 0 0 27.851 0 19.692 19.692 0 0 0 0-27.851l-64.844-64.844 64.844-64.844a19.692 19.692 0 0 0 0-27.851 19.692 19.692 0 0 0-27.851 0l-64.844 64.844-64.844-64.844a19.692 19.692 0 0 0-13.925-5.7669z", fill: "currentColor" }))));
|
|
86
|
+
return (React.createElement(StyledButton, Object.assign({}, nativeProps, { "$color": $color, "$background": $background, ref: ref }), typeof children === 'undefined' ? React.createElement(DeleteIcon, null) : children));
|
|
86
87
|
};
|
|
87
88
|
export default React.forwardRef(BadgeDeleteButton);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
const BadgeDeleteIcon = (props, ref) => (React.createElement("svg", Object.assign({ xmlns: "http://www.w3.org/2000/svg", version: "1.1", width: "1em", height: "1em", viewBox: "0 0 512 512", "aria-hidden": true, focusable: "false" }, props, { ref: ref }),
|
|
3
|
+
React.createElement("path", { d: "m256 0c-141.11 0-256 114.89-256 256s114.89 256 256 256 256-114.89 256-256-114.89-256-256-256zm0 39.385c119.81 0 216.62 96.805 216.62 216.62s-96.805 216.62-216.62 216.62-216.62-96.805-216.62-216.62 96.805-216.62 216.62-216.62zm-78.769 118.15a19.692 19.692 0 0 0-5.0961 0.67068 19.692 19.692 0 0 0-8.8293 5.0961 19.692 19.692 0 0 0 0 27.851l64.844 64.844-64.844 64.844a19.692 19.692 0 0 0 0 27.851 19.692 19.692 0 0 0 27.851 0l64.844-64.844 64.844 64.844a19.692 19.692 0 0 0 27.851 0 19.692 19.692 0 0 0 0-27.851l-64.844-64.844 64.844-64.844a19.692 19.692 0 0 0 0-27.851 19.692 19.692 0 0 0-27.851 0l-64.844 64.844-64.844-64.844a19.692 19.692 0 0 0-13.925-5.7669z", fill: "currentColor" })));
|
|
4
|
+
export default React.forwardRef(BadgeDeleteIcon);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import Badge from './index';
|
|
3
3
|
/**
|
|
4
4
|
* The badge with the `outlined` variant. Prefer `<Badge variant="outlined">`
|
|
5
5
|
*/
|
|
6
|
-
const BadgeOutlined = (props, ref) => React.createElement(
|
|
6
|
+
const BadgeOutlined = (props, ref) => React.createElement(Badge, Object.assign({}, props, { variant: "outlined", ref: ref }));
|
|
7
7
|
export default React.forwardRef(BadgeOutlined);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import Badge from './index';
|
|
3
3
|
/**
|
|
4
4
|
* The badge with the `standard` variant. Prefer `<Badge variant="standard">`
|
|
5
5
|
*/
|
|
6
|
-
const BadgeStandard = (props, ref) => React.createElement(
|
|
6
|
+
const BadgeStandard = (props, ref) => React.createElement(Badge, Object.assign({}, props, { variant: "standard", ref: ref }));
|
|
7
7
|
export default React.forwardRef(BadgeStandard);
|
package/esm/Badge/BadgeStyled.js
CHANGED
|
@@ -1,163 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
-
t[p] = s[p];
|
|
5
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
-
t[p[i]] = s[p[i]];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
|
-
import React from 'react';
|
|
13
|
-
import styled from '@emotion/styled';
|
|
14
|
-
import { useTheme, css } from '@emotion/react';
|
|
15
|
-
import Color from '../Color';
|
|
16
|
-
import BadgeBase from './BadgeBase';
|
|
17
|
-
import { themeFocusRing, BORDER_WIDTH } from '../ThemeProvider/tokens';
|
|
18
|
-
const parseColor = (color, fallback) => {
|
|
19
|
-
try {
|
|
20
|
-
return Color.fromString(color);
|
|
21
|
-
}
|
|
22
|
-
catch (err) {
|
|
23
|
-
console.error(`invalid color value «${color}»`);
|
|
24
|
-
return fallback;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
const getStandardColors = (color, theme) => {
|
|
28
|
-
switch (true) {
|
|
29
|
-
case color === 'primary':
|
|
30
|
-
return { $color: theme.color.accentPrimaryContrast, $background: theme.color.accentPrimary };
|
|
31
|
-
case color === 'secondary':
|
|
32
|
-
return {
|
|
33
|
-
$color: theme.color.accentSecondaryContrast,
|
|
34
|
-
$background: theme.color.accentSecondary,
|
|
35
|
-
};
|
|
36
|
-
case typeof color === 'undefined':
|
|
37
|
-
case color === 'default':
|
|
38
|
-
return { $background: theme.color.surface.darken(10), $color: theme.color.textPrimary };
|
|
39
|
-
default: {
|
|
40
|
-
const $background = parseColor(String(color), theme.color.surface);
|
|
41
|
-
return {
|
|
42
|
-
$background,
|
|
43
|
-
$color: $background.getContrast(theme.color.textPrimary) > 5
|
|
44
|
-
? theme.color.textPrimary
|
|
45
|
-
: theme.color.surface,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
const getOutlinedColors = (color, theme) => {
|
|
51
|
-
switch (true) {
|
|
52
|
-
case color === 'primary':
|
|
53
|
-
return { $color: theme.color.accentPrimary, $background: theme.color.accentPrimary };
|
|
54
|
-
case color === 'secondary':
|
|
55
|
-
return { $color: theme.color.accentSecondary, $background: theme.color.accentSecondary };
|
|
56
|
-
case typeof color === 'undefined':
|
|
57
|
-
case color === 'default':
|
|
58
|
-
return {
|
|
59
|
-
$color: Color.fromString(theme.color.textPrimary.toString()),
|
|
60
|
-
$background: theme.color.textPrimary.lighten(100),
|
|
61
|
-
};
|
|
62
|
-
default: {
|
|
63
|
-
const c = parseColor(String(color), theme.color.textPrimary);
|
|
64
|
-
return { $color: c, $background: c };
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* The pale background of the color and the text of the same hue: dark on the light theme,
|
|
70
|
-
* light on the dark one. `$background` is the color itself
|
|
71
|
-
*/
|
|
72
|
-
const getSoftColors = (color, theme) => {
|
|
73
|
-
const base = color === 'primary'
|
|
74
|
-
? theme.color.accentPrimary
|
|
75
|
-
: color === 'secondary'
|
|
76
|
-
? theme.color.accentSecondary
|
|
77
|
-
: typeof color === 'undefined' || color === 'default'
|
|
78
|
-
? theme.color.textPrimary
|
|
79
|
-
: parseColor(String(color), theme.color.textPrimary);
|
|
80
|
-
return {
|
|
81
|
-
$background: base,
|
|
82
|
-
$color: theme.isDark ? base.lighten(60) : base.darken(60),
|
|
83
|
-
};
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Both variants are one styled component: switching the variant (e.g. a toggling filter badge)
|
|
87
|
-
* must not remount the element, otherwise the focused badge loses the focus
|
|
88
|
-
*/
|
|
89
|
-
const StyledBadge = styled(BadgeBase) `
|
|
90
|
-
border-style: solid;
|
|
91
|
-
border-width: ${BORDER_WIDTH};
|
|
92
|
-
border-color: ${({ $background }) => $background.toString()};
|
|
93
|
-
--badge-dot-color: ${({ $variant, $background, $color }) => ($variant === 'standard' ? $color : $background).toString()};
|
|
94
|
-
|
|
95
|
-
${({ $variant, $color, $background }) => $variant === 'soft' &&
|
|
96
|
-
css `
|
|
97
|
-
color: ${$color.toString()};
|
|
98
|
-
background-color: ${$background.alpha(0.18).toString()};
|
|
99
|
-
border-color: transparent;
|
|
100
|
-
|
|
101
|
-
&:focus-visible {
|
|
102
|
-
outline-style: solid;
|
|
103
|
-
outline-width: 0.14em;
|
|
104
|
-
outline-color: ${$background.alpha(0.6).toString()};
|
|
105
|
-
}
|
|
106
|
-
`}
|
|
107
|
-
|
|
108
|
-
${({ $variant, $color, $background, theme }) => $variant === 'soft'
|
|
109
|
-
? ''
|
|
110
|
-
: $variant === 'outlined'
|
|
111
|
-
? css `
|
|
112
|
-
color: ${$color.darken(30).toString()};
|
|
113
|
-
background-color: transparent;
|
|
114
|
-
|
|
115
|
-
&:focus-visible {
|
|
116
|
-
outline-style: solid;
|
|
117
|
-
outline-width: 0.14em;
|
|
118
|
-
outline-color: ${$background.rgbString()};
|
|
119
|
-
}
|
|
120
|
-
`
|
|
121
|
-
: css `
|
|
122
|
-
color: ${$color.toString()};
|
|
123
|
-
background-color: ${$background.toString()};
|
|
124
|
-
|
|
125
|
-
&:focus-visible {
|
|
126
|
-
outline-color: ${$background.rgbString() === theme.color.accentPrimary.rgbString()
|
|
127
|
-
? theme.color.textPrimary.toString()
|
|
128
|
-
: theme.color.accentPrimary.toString()};
|
|
129
|
-
}
|
|
130
|
-
`}
|
|
131
|
-
|
|
132
|
-
${({ $clickable, $variant, $background }) => $clickable &&
|
|
133
|
-
css `
|
|
134
|
-
cursor: pointer;
|
|
135
|
-
|
|
136
|
-
&:hover {
|
|
137
|
-
${$variant === 'soft'
|
|
138
|
-
? css `
|
|
139
|
-
background-color: ${$background.alpha(0.3).toString()};
|
|
140
|
-
`
|
|
141
|
-
: $variant === 'outlined'
|
|
142
|
-
? css `
|
|
143
|
-
background-color: ${$background.darken(20).alpha(0.1).toString()};
|
|
144
|
-
`
|
|
145
|
-
: css `
|
|
146
|
-
background-color: ${$background.darken(30).toString()};
|
|
147
|
-
border-color: ${$background.darken(30).toString()};
|
|
148
|
-
`}
|
|
149
|
-
}
|
|
150
|
-
`}
|
|
151
|
-
${({ theme }) => themeFocusRing(theme)}
|
|
152
|
-
`;
|
|
153
|
-
const BadgeStyled = (props, ref) => {
|
|
154
|
-
const { children, color, variant = 'standard', onClick } = props, restProps = __rest(props, ["children", "color", "variant", "onClick"]);
|
|
155
|
-
const theme = useTheme();
|
|
156
|
-
const { $background, $color } = React.useMemo(() => variant === 'soft'
|
|
157
|
-
? getSoftColors(color, theme)
|
|
158
|
-
: variant === 'outlined'
|
|
159
|
-
? getOutlinedColors(color, theme)
|
|
160
|
-
: getStandardColors(color, theme), [color, variant, theme]);
|
|
161
|
-
return (React.createElement(StyledBadge, Object.assign({ "$variant": variant, "$clickable": typeof onClick === 'function', "$color": $color, "$background": $background, color: color, variant: variant, onClick: onClick }, restProps, { ref: ref }), children));
|
|
162
|
-
};
|
|
163
|
-
export default React.forwardRef(BadgeStyled);
|
|
1
|
+
// Preserve the old import path without adding a wrapper around Badge
|
|
2
|
+
export { default } from './index';
|
package/esm/Badge/index.js
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
1
12
|
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
// One component for
|
|
4
|
-
const Badge = (
|
|
13
|
+
import BadgeBase from './BadgeBase';
|
|
14
|
+
// One component for all variants, so changing the variant does not remount the badge
|
|
15
|
+
const Badge = (_a, ref) => {
|
|
16
|
+
var { variant = 'standard' } = _a, props = __rest(_a, ["variant"]);
|
|
17
|
+
return React.createElement(BadgeBase, Object.assign({}, props, { variant: variant, ref: ref }));
|
|
18
|
+
};
|
|
5
19
|
export default React.forwardRef(Badge);
|
package/esm/DatePicker/index.js
CHANGED
|
@@ -111,7 +111,9 @@ const DatePicker = props => {
|
|
|
111
111
|
var _a, _b;
|
|
112
112
|
setOpenSate(false);
|
|
113
113
|
// Back to the field, so the keyboard user continues from the same place
|
|
114
|
-
(_b = (readOnly ? inputRef.current : ((_a = buttonRef.current) !== null && _a !== void 0 ? _a : inputRef.current))) === null || _b === void 0 ? void 0 : _b.focus(
|
|
114
|
+
(_b = (readOnly ? inputRef.current : ((_a = buttonRef.current) !== null && _a !== void 0 ? _a : inputRef.current))) === null || _b === void 0 ? void 0 : _b.focus({
|
|
115
|
+
preventScroll: true,
|
|
116
|
+
});
|
|
115
117
|
}, [readOnly]);
|
|
116
118
|
const handlePopperKeyDown = React.useCallback((event) => {
|
|
117
119
|
if (event.key === 'Escape') {
|