@via-profit/ui-kit 0.10.1 → 0.12.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 +23 -0
- package/Popper/Popper.js +17 -12
- 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/Tooltip/index.d.ts +6 -0
- package/Tooltip/index.js +9 -6
- 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/Popper/Popper.js +17 -12
- 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/Tooltip/index.js +9 -6
- package/package.json +6 -1
package/Popper/Popper.js
CHANGED
|
@@ -81,19 +81,24 @@ const Popper = (props, ref) => {
|
|
|
81
81
|
}
|
|
82
82
|
}, [actualPlacement]);
|
|
83
83
|
const childrenMemo = react_1.default.useMemo(() => children, [children]);
|
|
84
|
-
const renderNode = react_1.default.useCallback(() =>
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
84
|
+
const renderNode = react_1.default.useCallback(() => {
|
|
85
|
+
var _a, _b;
|
|
86
|
+
return (react_1.default.createElement(overridesMap.Container, Object.assign({}, nativeProps, { style: Object.assign(Object.assign(Object.assign(Object.assign({}, style), nativeProps.style), { opacity: isVisible ? 1 : 0,
|
|
87
|
+
// A hidden popper never intercepts the pointer; a visible one lets the caller opt out
|
|
88
|
+
pointerEvents: !isVisible ? 'none' : ((_b = (_a = nativeProps.style) === null || _a === void 0 ? void 0 : _a.pointerEvents) !== null && _b !== void 0 ? _b : 'auto') }), (positionStrategy === 'fixed' && {
|
|
89
|
+
position: 'fixed',
|
|
90
|
+
})), zIndex: zIndex, positionStrategy: positionStrategy, "data-popper-placement": actualPlacement, "data-popper-strategy": positionStrategy, ref: el => {
|
|
91
|
+
popperRef.current = el;
|
|
92
|
+
if (ref) {
|
|
93
|
+
if (typeof ref === 'function') {
|
|
94
|
+
ref(el);
|
|
95
|
+
}
|
|
96
|
+
if (typeof ref === 'object') {
|
|
97
|
+
ref.current = el;
|
|
98
|
+
}
|
|
91
99
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
} }), childrenMemo)), [
|
|
100
|
+
} }), childrenMemo));
|
|
101
|
+
}, [
|
|
97
102
|
overridesMap,
|
|
98
103
|
nativeProps,
|
|
99
104
|
style,
|
|
@@ -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/Tooltip/index.d.ts
CHANGED
|
@@ -49,6 +49,12 @@ export type TooltipProps = {
|
|
|
49
49
|
* Default: false
|
|
50
50
|
*/
|
|
51
51
|
readonly describeChild?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Lets the pointer move onto the tooltip, e.g. to select its text or click a link inside.
|
|
54
|
+
* When `false`, the tooltip does not receive pointer events and cannot block the elements under it
|
|
55
|
+
* Default: false
|
|
56
|
+
*/
|
|
57
|
+
readonly interactive?: boolean;
|
|
52
58
|
/**
|
|
53
59
|
* Default: 8
|
|
54
60
|
*/
|
package/Tooltip/index.js
CHANGED
|
@@ -45,7 +45,7 @@ const setRef = (ref, value) => {
|
|
|
45
45
|
const isEmptyTitle = (title) => title === null || typeof title === 'undefined' || title === false || title === '';
|
|
46
46
|
const Tooltip = props => {
|
|
47
47
|
var _a;
|
|
48
|
-
const { title, children, placement = 'top', arrow = false, enterDelay = 400, leaveDelay = 100, isOpen, onOpenChange, describeChild = false, offset = 8, zIndex, id, overrides, } = props;
|
|
48
|
+
const { title, children, placement = 'top', arrow = false, enterDelay = 400, leaveDelay = 100, isOpen, onOpenChange, describeChild = false, interactive = false, offset = 8, zIndex, id, overrides, } = props;
|
|
49
49
|
const theme = (0, react_2.useTheme)();
|
|
50
50
|
const generatedId = `tooltip-${react_1.default.useId().replace(/:/g, '')}`;
|
|
51
51
|
const tooltipId = id || generatedId;
|
|
@@ -182,12 +182,15 @@ const Tooltip = props => {
|
|
|
182
182
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
183
183
|
anchor,
|
|
184
184
|
react_1.default.createElement(Popper_1.default, { isOpen: open, anchorElement: anchorElement, anchorPos: placement, autoFlip: true, offset: offset, viewportMargin: 8, zIndex: zIndex !== null && zIndex !== void 0 ? zIndex : theme.zIndex.modal + 1, onAnchorPosChanged: setActualPlacement, id: tooltipId, role: "tooltip",
|
|
185
|
-
//
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
185
|
+
// Without `interactive` the tooltip must not intercept the pointer: otherwise it
|
|
186
|
+
// blocks the elements under it and sticks under the cursor that moves across it
|
|
187
|
+
style: interactive ? undefined : { pointerEvents: 'none' }, onPointerEnter: interactive ? clearTimer : undefined, onPointerLeave: interactive
|
|
188
|
+
? event => {
|
|
189
|
+
if (isHoverPointer(event)) {
|
|
190
|
+
hide(leaveDelay);
|
|
191
|
+
}
|
|
189
192
|
}
|
|
190
|
-
|
|
193
|
+
: undefined },
|
|
191
194
|
react_1.default.createElement(overridesMap.Container, null,
|
|
192
195
|
title,
|
|
193
196
|
arrow && react_1.default.createElement(overridesMap.Arrow, { placement: actualPlacement })))));
|
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);
|