@bigbluebutton/bbb-ui-components-react 0.8.0 → 0.10.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/README.md +3 -2
- package/dist/components/Accordion.js +1 -1
- package/dist/components/Avatar.js +1 -1
- package/dist/components/Button.js +41 -40
- package/dist/components/Checkbox.js +3 -3
- package/dist/components/Input.js +67 -66
- package/dist/components/Modal.js +87 -79
- package/dist/components/Search.js +3 -2
- package/dist/components/Select.js +9 -9
- package/dist/components/Slider.js +2 -2
- package/dist/components/Spinner.js +1 -0
- package/dist/components/TextAreaInput.js +1 -1
- package/dist/components/TextInput.js +10 -10
- package/dist/components/Toast.js +292 -0
- package/dist/components/Toggle.js +20 -13
- package/dist/components/colors.js +1 -1
- package/dist/components/index.js +410 -252
- package/dist/esm/components/Button/component.js +7 -7
- package/dist/esm/components/Button/constants.js +8 -1
- package/dist/esm/components/Button/styles.js +6 -5
- package/dist/esm/components/Checkbox/component.js +7 -3
- package/dist/esm/components/Modal/component.js +2 -4
- package/dist/esm/components/Modal/styles.js +12 -1
- package/dist/esm/components/Spinner/styles.js +1 -0
- package/dist/esm/components/Toast/component.js +144 -0
- package/dist/esm/components/Toast/constants.js +36 -0
- package/dist/esm/components/Toast/index.js +1 -0
- package/dist/esm/components/Toast/styles.js +180 -0
- package/dist/esm/components/Toast/types.js +1 -0
- package/dist/esm/components/Toggle/component.js +20 -5
- package/dist/esm/components/Toggle/styles.js +13 -2
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/stylesheets/palette.js +9 -3
- package/dist/types/components/Accordion/constants.d.ts +1 -1
- package/dist/types/components/Button/constants.d.ts +11 -4
- package/dist/types/components/Button/type.d.ts +9 -1
- package/dist/types/components/Checkbox/component.d.ts +1 -1
- package/dist/types/components/Checkbox/types.d.ts +1 -1
- package/dist/types/components/Modal/styles.d.ts +3 -1
- package/dist/types/components/Slider/styles.d.ts +1 -1
- package/dist/types/components/Toast/component.d.ts +14 -0
- package/dist/types/components/Toast/constants.d.ts +42 -0
- package/dist/types/components/Toast/index.d.ts +1 -0
- package/dist/types/components/Toast/styles.d.ts +14 -0
- package/dist/types/components/Toast/types.d.ts +68 -0
- package/dist/types/components/Toggle/component.d.ts +1 -1
- package/dist/types/components/Toggle/constants.d.ts +2 -2
- package/dist/types/components/Toggle/types.d.ts +4 -1
- package/dist/types/components/index.d.ts +1 -0
- package/dist/types/stylesheets/colors.d.ts +5 -5
- package/dist/types/stylesheets/palette.d.ts +7 -5
- package/package.json +13 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { useCallback, useEffect, useId, useRef, useState, } from 'react';
|
|
2
2
|
import { MdSettings, MdCheckCircle } from 'react-icons/md';
|
|
3
|
-
import { DEFAULT_VARIANT, DEFAULT_COLOR, DEFAULT_SIZE, DEFAULT_LAYOUT, LAYOUTS, DEFAULT_TOOLTIP_PLACEMENT, } from './constants';
|
|
3
|
+
import { DEFAULT_VARIANT, DEFAULT_COLOR, DEFAULT_SIZE, DEFAULT_LAYOUT, LAYOUTS, DEFAULT_TOOLTIP_PLACEMENT, DEFAULT_TYPE, } from './constants';
|
|
4
4
|
import * as Styled from './styles';
|
|
5
5
|
import Tippy from '@tippyjs/react';
|
|
6
6
|
import 'tippy.js/dist/tippy.css';
|
|
@@ -13,7 +13,7 @@ import 'tippy.js/dist/tippy.css';
|
|
|
13
13
|
*
|
|
14
14
|
*/
|
|
15
15
|
function Button(props) {
|
|
16
|
-
const { id = '', dataTest, label, tooltipLabel, tooltipPlacement = DEFAULT_TOOLTIP_PLACEMENT, onClick, onKeyDown, ariaLabel = '', ariaLabelledBy = '', ariaDescribedBy = '', color = DEFAULT_COLOR, variant = DEFAULT_VARIANT, size = DEFAULT_SIZE, layout = DEFAULT_LAYOUT, disabled = false, children, showFeedback = false, feedbackContent = React.createElement(MdCheckCircle, { fontSize: "small" }), feedbackDuration = 2000, } = props;
|
|
16
|
+
const { id = '', dataTest, label, tooltipLabel, tooltipPlacement = DEFAULT_TOOLTIP_PLACEMENT, onClick, onKeyDown, ariaLabel = '', ariaLabelledBy = '', ariaDescribedBy = '', color = DEFAULT_COLOR, variant = DEFAULT_VARIANT, size = DEFAULT_SIZE, layout = DEFAULT_LAYOUT, type = DEFAULT_TYPE, disabled = false, children, showFeedback = false, feedbackContent = React.createElement(MdCheckCircle, { fontSize: "small" }), feedbackDuration = 2000, className, } = props;
|
|
17
17
|
const feedbackTimeoutRef = useRef(null);
|
|
18
18
|
const [isFeedbackVisible, setFeedbackVisible] = useState(false);
|
|
19
19
|
useEffect(() => () => {
|
|
@@ -52,13 +52,13 @@ function Button(props) {
|
|
|
52
52
|
if (props.layout === LAYOUTS.CIRCLE || props.layout === LAYOUTS.SQUARED) {
|
|
53
53
|
const { icon } = props;
|
|
54
54
|
const testId = dataTest || `button-${id || 'default'}`;
|
|
55
|
-
return (React.createElement(Styled.Button, Object.assign({ id: id, "data-test": testId, onClick: handleClick, onKeyDown: onKeyDown }, accessibilityProps, { "$color": color, "$variant": variant, "$size": size, "$layout": layout, disabled: disabled }), isFeedbackVisible ? (React.createElement(Styled.FeedbackContent, { role: "status", "aria-live": "polite" }, feedbackContent)) : icon));
|
|
55
|
+
return (React.createElement(Styled.Button, Object.assign({ id: id, className: className, type: type, "data-test": testId, onClick: handleClick, onKeyDown: onKeyDown }, accessibilityProps, { "$color": color, "$variant": variant, "$size": size, "$layout": layout, disabled: disabled }), isFeedbackVisible ? (React.createElement(Styled.FeedbackContent, { role: "status", "aria-live": "polite" }, feedbackContent)) : icon));
|
|
56
56
|
}
|
|
57
57
|
if (props.layout === LAYOUTS.STACKED) {
|
|
58
58
|
const { icon, helperIcon = React.createElement(MdSettings, { fontSize: "small" }), hideHelperIcon = false, helperOnClick = null, } = props;
|
|
59
59
|
const testId = dataTest || `${LAYOUTS.STACKED}-button-${id || label || 'default'}`;
|
|
60
|
-
return (React.createElement(Styled.ButtonWrapper, { "data-test": testId, "$layout": layout },
|
|
61
|
-
React.createElement(Styled.Button, Object.assign({ id: id, onClick: handleClick, onKeyDown: onKeyDown }, accessibilityProps, { "$color": color, "$variant": variant, "$size": size, "$layout": layout, disabled: disabled }),
|
|
60
|
+
return (React.createElement(Styled.ButtonWrapper, { className: className, "data-test": testId, "$layout": layout },
|
|
61
|
+
React.createElement(Styled.Button, Object.assign({ id: id, type: type, onClick: handleClick, onKeyDown: onKeyDown }, accessibilityProps, { "$color": color, "$variant": variant, "$size": size, "$layout": layout, disabled: disabled }),
|
|
62
62
|
!hideHelperIcon && (React.createElement(Styled.HelperIconContainer
|
|
63
63
|
// Add this property only when there is a onClick function for the auxiliary icon.
|
|
64
64
|
// It controls whether the auxiliary button is going to have an independent hover state.
|
|
@@ -74,9 +74,9 @@ function Button(props) {
|
|
|
74
74
|
React.createElement(Styled.FeedbackContent, { role: "status", "aria-live": "polite" }, feedbackContent))) : (icon && React.createElement(Styled.IconWrapper, null, icon))),
|
|
75
75
|
React.createElement(Styled.ButtonText, { id: defaultLabelId }, label)));
|
|
76
76
|
}
|
|
77
|
-
const { iconStart, iconEnd } = props;
|
|
77
|
+
const { iconStart, iconEnd, fullWidth = false } = props;
|
|
78
78
|
const testId = dataTest || `button-${id || label || 'default'}`;
|
|
79
|
-
return (React.createElement(Styled.Button, Object.assign({ id: id, "data-test": testId, onClick: handleClick, onKeyDown: onKeyDown }, accessibilityProps, { "$color": color, "$variant": variant, "$size": size, "$layout": layout, disabled: disabled }), isFeedbackVisible ? (React.createElement(Styled.FeedbackContent, { id: defaultLabelId, role: "status", "aria-live": "polite" }, feedbackContent)) : (React.createElement(React.Fragment, null,
|
|
79
|
+
return (React.createElement(Styled.Button, Object.assign({ id: id, className: className, type: type, "data-test": testId, onClick: handleClick, onKeyDown: onKeyDown }, accessibilityProps, { "$color": color, "$variant": variant, "$size": size, "$layout": layout, "$fullWidth": fullWidth, disabled: disabled }), isFeedbackVisible ? (React.createElement(Styled.FeedbackContent, { id: defaultLabelId, role: "status", "aria-live": "polite" }, feedbackContent)) : (React.createElement(React.Fragment, null,
|
|
80
80
|
iconStart && iconStart,
|
|
81
81
|
label && React.createElement("span", { id: defaultLabelId }, label),
|
|
82
82
|
children,
|
|
@@ -37,6 +37,13 @@ const TOOLTIP_PLACEMENTS = {
|
|
|
37
37
|
};
|
|
38
38
|
const TOOLTIP_PLACEMENT_VALUES = Object.values(TOOLTIP_PLACEMENTS);
|
|
39
39
|
const DEFAULT_TOOLTIP_PLACEMENT = TOOLTIP_PLACEMENTS.TOP;
|
|
40
|
+
const TYPES = {
|
|
41
|
+
BUTTON: 'button',
|
|
42
|
+
SUBMIT: 'submit',
|
|
43
|
+
RESET: 'reset',
|
|
44
|
+
};
|
|
45
|
+
const TYPE_VALUES = Object.values(TYPES);
|
|
46
|
+
const DEFAULT_TYPE = TYPES.BUTTON;
|
|
40
47
|
const CSS_COLOR_PROPERTIES = {
|
|
41
48
|
primary: {
|
|
42
49
|
default: {
|
|
@@ -174,4 +181,4 @@ const CSS_SIZE_PROPERTIES = {
|
|
|
174
181
|
iconBoxSize: spacingXXLarge,
|
|
175
182
|
},
|
|
176
183
|
};
|
|
177
|
-
export { VARIANTS, VARIANT_VALUES, DEFAULT_VARIANT, COLORS, COLOR_VALUES, DEFAULT_COLOR, SIZES, SIZE_VALUES, DEFAULT_SIZE, LAYOUTS, LAYOUT_VALUES, DEFAULT_LAYOUT, TOOLTIP_PLACEMENTS, TOOLTIP_PLACEMENT_VALUES, DEFAULT_TOOLTIP_PLACEMENT, CSS_COLOR_PROPERTIES, CSS_COLOR_PROPERTIES_DISABLED, CSS_SIZE_PROPERTIES, };
|
|
184
|
+
export { VARIANTS, VARIANT_VALUES, DEFAULT_VARIANT, COLORS, COLOR_VALUES, DEFAULT_COLOR, SIZES, SIZE_VALUES, DEFAULT_SIZE, LAYOUTS, LAYOUT_VALUES, DEFAULT_LAYOUT, TOOLTIP_PLACEMENTS, TOOLTIP_PLACEMENT_VALUES, DEFAULT_TOOLTIP_PLACEMENT, TYPES, TYPE_VALUES, DEFAULT_TYPE, CSS_COLOR_PROPERTIES, CSS_COLOR_PROPERTIES_DISABLED, CSS_SIZE_PROPERTIES, };
|
|
@@ -61,14 +61,14 @@ const commonButtonStyles = css `
|
|
|
61
61
|
color: ${color};
|
|
62
62
|
}
|
|
63
63
|
color: ${color};
|
|
64
|
-
${background ? `background-color: ${background}` : `background-color:
|
|
65
|
-
border: ${border ? `1px solid ${border}` : '
|
|
64
|
+
${background ? `background-color: ${background}` : `background-color: transparent`};
|
|
65
|
+
border: ${border ? `1px solid ${border}` : '1px solid transparent'};
|
|
66
66
|
|
|
67
67
|
&&:hover,
|
|
68
68
|
&&:active {
|
|
69
69
|
color: ${color};
|
|
70
|
-
${background ? `background-color: ${background}` : `background-color:
|
|
71
|
-
border: ${border ? `1px solid ${border}` : '
|
|
70
|
+
${background ? `background-color: ${background}` : `background-color: transparent`};
|
|
71
|
+
border: ${border ? `1px solid ${border}` : '1px solid transparent'};
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
&&:focus {
|
|
@@ -114,7 +114,8 @@ const squaredLayoutStyles = css `
|
|
|
114
114
|
border-radius: ${borderRadiusSmall};
|
|
115
115
|
`;
|
|
116
116
|
const defaultLayoutStyles = css `
|
|
117
|
-
display: inline-flex;
|
|
117
|
+
display: ${({ $fullWidth }) => ($fullWidth ? 'flex' : 'inline-flex')};
|
|
118
|
+
${({ $fullWidth }) => $fullWidth && 'width: 100%;'}
|
|
118
119
|
justify-content: center;
|
|
119
120
|
align-items: center;
|
|
120
121
|
gap: ${spacingSmall};
|
|
@@ -22,11 +22,15 @@ import { RadioButtonUnchecked, RadioButtonChecked } from '@mui/icons-material';
|
|
|
22
22
|
*
|
|
23
23
|
*/
|
|
24
24
|
function Checkbox(_a) {
|
|
25
|
-
var { label, layout = DEFAULT_LAYOUT, round = false, ariaLabel, id, dataTest,
|
|
25
|
+
var { label, layout = DEFAULT_LAYOUT, round = false, ariaLabel, id, dataTest, slotProps } = _a, props = __rest(_a, ["label", "layout", "round", "ariaLabel", "id", "dataTest", "slotProps"]);
|
|
26
26
|
const generatedId = useId();
|
|
27
27
|
const checkboxId = id !== null && id !== void 0 ? id : generatedId;
|
|
28
|
-
const
|
|
29
|
-
const
|
|
28
|
+
const ownInputProps = { 'aria-label': ariaLabel, 'data-test': dataTest };
|
|
29
|
+
const _b = slotProps !== null && slotProps !== void 0 ? slotProps : {}, { input: consumerInputSlotProps } = _b, otherSlotProps = __rest(_b, ["input"]);
|
|
30
|
+
const inputSlotProps = typeof consumerInputSlotProps === 'function'
|
|
31
|
+
? (ownerState) => (Object.assign(Object.assign({}, ownInputProps), consumerInputSlotProps(ownerState)))
|
|
32
|
+
: Object.assign(Object.assign({}, ownInputProps), consumerInputSlotProps);
|
|
33
|
+
const checkbox = (React.createElement(Styled.StyledCheckbox, Object.assign({}, props, { id: checkboxId, icon: round ? React.createElement(RadioButtonUnchecked, null) : undefined, checkedIcon: round ? React.createElement(RadioButtonChecked, null) : undefined, slotProps: Object.assign(Object.assign({}, otherSlotProps), { input: inputSlotProps }) })));
|
|
30
34
|
if (!label) {
|
|
31
35
|
return checkbox;
|
|
32
36
|
}
|
|
@@ -10,9 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import React, { useCallback } from 'react';
|
|
13
|
-
import ReactModal from 'react-modal';
|
|
14
13
|
import * as Styled from './styles';
|
|
15
|
-
import { BBBTypography } from '../Typography';
|
|
16
14
|
import { MdClose } from 'react-icons/md';
|
|
17
15
|
import { BBBDivider } from '../Divider';
|
|
18
16
|
import { BBButton } from '../Button';
|
|
@@ -32,9 +30,9 @@ const Modal = (_a) => {
|
|
|
32
30
|
const renderFooter = useCallback((isSticky) => (React.createElement(React.Fragment, null,
|
|
33
31
|
showDividers && React.createElement(BBBDivider, null),
|
|
34
32
|
React.createElement(Styled.ModalFooter, { "$stickyFooter": isSticky }, footerContent))), [footerContent, showDividers]);
|
|
35
|
-
return (React.createElement(
|
|
33
|
+
return (React.createElement(Styled.Modal, Object.assign({}, rest, { isOpen: isOpen, onRequestClose: onRequestClose, contentLabel: contentLabel, style: Styled.modalStyles, shouldCloseOnOverlayClick: shouldCloseOnOverlayClick, shouldCloseOnEsc: shouldCloseOnEsc, appElement: appElement, testId: testId }),
|
|
36
34
|
React.createElement(Styled.ModalHeader, null,
|
|
37
|
-
React.createElement(
|
|
35
|
+
React.createElement(Styled.ModalTitle, { variant: "header" }, title),
|
|
38
36
|
!hideCloseButton && (React.createElement(BBButton, Object.assign({ layout: "circle", icon: React.createElement(MdClose, { size: "1.5rem" }), onClick: onRequestClose, variant: "subtle", ariaLabel: "close" }, (_closeButtonDataTest ? { dataTest: _closeButtonDataTest } : {}))))),
|
|
39
37
|
showDividers && React.createElement(BBBDivider, null),
|
|
40
38
|
React.createElement(Styled.ModalScrollArea, { "$allowScroll": allowScroll },
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import styled from 'styled-components';
|
|
2
|
+
import ReactModal from 'react-modal';
|
|
2
3
|
import { spacingLarge, spacingMedium, spacingSmallMedium, borderRadiusDefault } from '../../stylesheets/sizing';
|
|
3
4
|
import { colorWhite, colorOverlay } from '../../stylesheets/palette';
|
|
5
|
+
import { BBBTypography } from '../Typography';
|
|
4
6
|
export const modalStyles = {
|
|
5
7
|
overlay: {
|
|
6
8
|
position: 'fixed',
|
|
@@ -21,7 +23,6 @@ export const modalStyles = {
|
|
|
21
23
|
right: 'auto',
|
|
22
24
|
bottom: 'auto',
|
|
23
25
|
borderRadius: borderRadiusDefault,
|
|
24
|
-
background: colorWhite,
|
|
25
26
|
overflow: 'hidden',
|
|
26
27
|
WebkitOverflowScrolling: 'touch',
|
|
27
28
|
outline: 'none',
|
|
@@ -38,6 +39,12 @@ export const ModalHeader = styled.div `
|
|
|
38
39
|
display: flex;
|
|
39
40
|
justify-content: space-between;
|
|
40
41
|
align-items: center;
|
|
42
|
+
gap: ${spacingMedium};
|
|
43
|
+
`;
|
|
44
|
+
export const ModalTitle = styled(BBBTypography) `
|
|
45
|
+
flex: 1;
|
|
46
|
+
min-width: 0;
|
|
47
|
+
overflow-wrap: anywhere;
|
|
41
48
|
`;
|
|
42
49
|
export const ModalScrollArea = styled.div `
|
|
43
50
|
flex-grow: 1;
|
|
@@ -64,3 +71,7 @@ export const ModalFooter = styled.div `
|
|
|
64
71
|
background-color: ${colorWhite};
|
|
65
72
|
`}
|
|
66
73
|
`;
|
|
74
|
+
// Background lives in a class instead of the inline `style` so the BBB dark theme and consumers can override it.
|
|
75
|
+
export const Modal = styled(ReactModal) `
|
|
76
|
+
background: ${colorWhite};
|
|
77
|
+
`;
|
|
@@ -0,0 +1,144 @@
|
|
|
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
|
+
};
|
|
12
|
+
import React, { useEffect, useId, useRef, useState, } from 'react';
|
|
13
|
+
import { MdClose } from 'react-icons/md';
|
|
14
|
+
import * as Styled from './styles';
|
|
15
|
+
import { BBBDivider } from '../Divider';
|
|
16
|
+
import { BBButton } from '../Button';
|
|
17
|
+
import { DEFAULT_AUTO_CLOSE, DEFAULT_CLOSE_BUTTON_ARIA_LABEL, DEFAULT_ICONS, DEFAULT_MAX_HEIGHT, DEFAULT_TOAST_VARIANT, INTERACTIVE_SELECTOR, TOAST_VARIANTS, } from './constants';
|
|
18
|
+
/**
|
|
19
|
+
* A notification card for transient messages.
|
|
20
|
+
*
|
|
21
|
+
* This component renders the presentational part of a toast notification: an icon badge
|
|
22
|
+
* matched to `variant`, the message, optional secondary content and an optional action button.
|
|
23
|
+
*
|
|
24
|
+
* It never hides itself. Both the close button and the `autoClose` timer call `onRequestClose`,
|
|
25
|
+
* leaving removal to whoever owns the toast stack, so the card can live inside an external
|
|
26
|
+
* toast engine without leaving an empty slot behind.
|
|
27
|
+
*/
|
|
28
|
+
function Toast(_a) {
|
|
29
|
+
var { message, variant = DEFAULT_TOAST_VARIANT, icon, content, showSeparator = true, small = false, disablePointer, onClick, clickAriaLabel, actionLabel, onActionClick, autoClose = DEFAULT_AUTO_CLOSE, paused = false, hideProgressBar = false, hideCloseButton = false, closeButtonAriaLabel = DEFAULT_CLOSE_BUTTON_ARIA_LABEL, onRequestClose, maxHeight = DEFAULT_MAX_HEIGHT, dataTest, messageDataTest, closeButtonDataTest, actionButtonDataTest, onMouseEnter, onMouseLeave, onFocus, onBlur } = _a, rest = __rest(_a, ["message", "variant", "icon", "content", "showSeparator", "small", "disablePointer", "onClick", "clickAriaLabel", "actionLabel", "onActionClick", "autoClose", "paused", "hideProgressBar", "hideCloseButton", "closeButtonAriaLabel", "onRequestClose", "maxHeight", "dataTest", "messageDataTest", "closeButtonDataTest", "actionButtonDataTest", "onMouseEnter", "onMouseLeave", "onFocus", "onBlur"]);
|
|
30
|
+
// Without an explicit value BBButton derives its own from the label, which is
|
|
31
|
+
// translated at every call site — so the derived ids below are what keep test
|
|
32
|
+
// selectors stable across locales.
|
|
33
|
+
const derive = (explicit, suffix) => explicit !== null && explicit !== void 0 ? explicit : (dataTest ? `${dataTest}-${suffix}` : undefined);
|
|
34
|
+
const testIds = {
|
|
35
|
+
message: derive(messageDataTest, 'message'),
|
|
36
|
+
closeButton: derive(closeButtonDataTest, 'close-button'),
|
|
37
|
+
actionButton: derive(actionButtonDataTest, 'action-button'),
|
|
38
|
+
};
|
|
39
|
+
// Held in a ref so an inline `onRequestClose` doesn't restart the timer on every
|
|
40
|
+
// render, which would keep the toast alive forever.
|
|
41
|
+
const onRequestCloseRef = useRef(onRequestClose);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
onRequestCloseRef.current = onRequestClose;
|
|
44
|
+
}, [onRequestClose]);
|
|
45
|
+
// Paused while hovered or focused so the toast doesn't vanish under a user who is
|
|
46
|
+
// reading it or about to press one of its buttons (WCAG 2.2.1, Timing Adjustable).
|
|
47
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
48
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
49
|
+
const isPaused = paused || isHovered || isFocused;
|
|
50
|
+
const remainingRef = useRef(autoClose === false ? 0 : autoClose);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (autoClose !== false)
|
|
53
|
+
remainingRef.current = autoClose;
|
|
54
|
+
}, [autoClose]);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (autoClose === false || isPaused)
|
|
57
|
+
return undefined;
|
|
58
|
+
const startedAt = Date.now();
|
|
59
|
+
const delay = remainingRef.current;
|
|
60
|
+
const timeout = setTimeout(() => { var _a; return (_a = onRequestCloseRef.current) === null || _a === void 0 ? void 0 : _a.call(onRequestCloseRef); }, delay);
|
|
61
|
+
return () => {
|
|
62
|
+
clearTimeout(timeout);
|
|
63
|
+
remainingRef.current = Math.max(0, delay - (Date.now() - startedAt));
|
|
64
|
+
};
|
|
65
|
+
}, [autoClose, isPaused]);
|
|
66
|
+
const handleMouseEnter = (event) => {
|
|
67
|
+
setIsHovered(true);
|
|
68
|
+
onMouseEnter === null || onMouseEnter === void 0 ? void 0 : onMouseEnter(event);
|
|
69
|
+
};
|
|
70
|
+
const handleMouseLeave = (event) => {
|
|
71
|
+
setIsHovered(false);
|
|
72
|
+
onMouseLeave === null || onMouseLeave === void 0 ? void 0 : onMouseLeave(event);
|
|
73
|
+
};
|
|
74
|
+
const handleFocus = (event) => {
|
|
75
|
+
setIsFocused(true);
|
|
76
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
|
|
77
|
+
};
|
|
78
|
+
const handleBlur = (event) => {
|
|
79
|
+
if (!event.currentTarget.contains(event.relatedTarget))
|
|
80
|
+
setIsFocused(false);
|
|
81
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
|
|
82
|
+
};
|
|
83
|
+
const isAssertive = variant === TOAST_VARIANTS.WARNING || variant === TOAST_VARIANTS.ERROR;
|
|
84
|
+
const contentId = useId();
|
|
85
|
+
const cardActionRef = useRef(null);
|
|
86
|
+
// Every click on the card lands here, including the card action's own (keyboard
|
|
87
|
+
// activation of a button dispatches a click too). Clicks on other interactive
|
|
88
|
+
// elements passed through `message` or `content` belong to those elements.
|
|
89
|
+
const handleCardClick = (event) => {
|
|
90
|
+
if (!onClick)
|
|
91
|
+
return;
|
|
92
|
+
const interactive = event.target.closest(INTERACTIVE_SELECTOR);
|
|
93
|
+
const isOwnedElsewhere = interactive
|
|
94
|
+
&& interactive !== cardActionRef.current
|
|
95
|
+
&& event.currentTarget.contains(interactive);
|
|
96
|
+
if (isOwnedElsewhere)
|
|
97
|
+
return;
|
|
98
|
+
onClick(event);
|
|
99
|
+
};
|
|
100
|
+
const handleCloseClick = (event) => {
|
|
101
|
+
event.stopPropagation();
|
|
102
|
+
onRequestClose === null || onRequestClose === void 0 ? void 0 : onRequestClose();
|
|
103
|
+
};
|
|
104
|
+
const handleActionClick = (event) => {
|
|
105
|
+
event.stopPropagation();
|
|
106
|
+
onActionClick === null || onActionClick === void 0 ? void 0 : onActionClick(event);
|
|
107
|
+
};
|
|
108
|
+
const renderIconSection = () => {
|
|
109
|
+
if (icon === false)
|
|
110
|
+
return null;
|
|
111
|
+
const DefaultIcon = DEFAULT_ICONS[variant];
|
|
112
|
+
return (React.createElement(Styled.IconSection, null,
|
|
113
|
+
React.createElement(Styled.IconBand, null,
|
|
114
|
+
React.createElement(Styled.IconBadge, { "$variant": variant, "$small": small, "aria-hidden": "true" }, icon !== null && icon !== void 0 ? icon : React.createElement(DefaultIcon, null)))));
|
|
115
|
+
};
|
|
116
|
+
return (React.createElement(Styled.Container
|
|
117
|
+
// The live-region role can't be swapped for `role="button"`, and the card holds
|
|
118
|
+
// buttons of its own, so the click is exposed through a real button wrapping the
|
|
119
|
+
// message (`Styled.CardAction`) rather than on the container itself.
|
|
120
|
+
, Object.assign({
|
|
121
|
+
// The live-region role can't be swapped for `role="button"`, and the card holds
|
|
122
|
+
// buttons of its own, so the click is exposed through a real button wrapping the
|
|
123
|
+
// message (`Styled.CardAction`) rather than on the container itself.
|
|
124
|
+
role: isAssertive ? 'alert' : 'status', "aria-live": isAssertive ? 'assertive' : 'polite', "aria-atomic": "true" }, rest, { "$disablePointer": disablePointer !== null && disablePointer !== void 0 ? disablePointer : !onClick, "$maxHeight": maxHeight, onClick: onClick ? handleCardClick : undefined, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, onFocus: handleFocus, onBlur: handleBlur }, (dataTest ? { 'data-test': dataTest } : {})),
|
|
125
|
+
renderIconSection(),
|
|
126
|
+
onClick && !message && (React.createElement(Styled.CardAction, { ref: cardActionRef, type: "button", "$visuallyHidden": true, "aria-label": clickAriaLabel, "aria-labelledby": clickAriaLabel ? undefined : contentId })),
|
|
127
|
+
React.createElement(Styled.Body, null,
|
|
128
|
+
(message || !hideCloseButton) && (React.createElement(Styled.Header, null,
|
|
129
|
+
message && (React.createElement(Styled.Message, Object.assign({ "$small": small }, (testIds.message ? { 'data-test': testIds.message } : {})), onClick ? (React.createElement(Styled.CardAction, { ref: cardActionRef, type: "button", "$visuallyHidden": false, "aria-label": clickAriaLabel }, message)) : message)),
|
|
130
|
+
!hideCloseButton && (React.createElement(Styled.CloseButtonWrapper, null,
|
|
131
|
+
React.createElement(BBButton, Object.assign({ layout: "squared", variant: "subtle", size: "sm", icon: React.createElement(MdClose, { size: "1.25rem" }), ariaLabel: closeButtonAriaLabel, onClick: handleCloseClick }, (testIds.closeButton ? { dataTest: testIds.closeButton } : {}))))))),
|
|
132
|
+
content && (React.createElement(React.Fragment, null,
|
|
133
|
+
showSeparator && message && React.createElement(BBBDivider, null),
|
|
134
|
+
React.createElement(Styled.Content, { id: onClick ? contentId : undefined, "$small": small }, content))),
|
|
135
|
+
actionLabel && (React.createElement(Styled.ActionWrapper, null,
|
|
136
|
+
React.createElement(BBButton, Object.assign({ label: actionLabel, variant: "tertiary", size: "sm", onClick: handleActionClick }, (testIds.actionButton ? { dataTest: testIds.actionButton } : {})))))),
|
|
137
|
+
autoClose !== false && !hideProgressBar && (React.createElement(Styled.ProgressTrack, { "aria-hidden": "true" },
|
|
138
|
+
React.createElement(Styled.ProgressBar
|
|
139
|
+
// A new duration restarts the countdown, so the bar restarts with it.
|
|
140
|
+
, {
|
|
141
|
+
// A new duration restarts the countdown, so the bar restarts with it.
|
|
142
|
+
key: autoClose, "$variant": variant, "$duration": autoClose, "$paused": isPaused })))));
|
|
143
|
+
}
|
|
144
|
+
export default Toast;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { MdCheck, MdError, MdHelp, MdInfo, MdWarning } from 'react-icons/md';
|
|
2
|
+
import { colorBrand1, colorSuccessDark, colorWarningDark, colorError, colorWhite, } from '../../stylesheets/palette';
|
|
3
|
+
export const TOAST_VARIANTS = {
|
|
4
|
+
DEFAULT: 'default',
|
|
5
|
+
INFO: 'info',
|
|
6
|
+
SUCCESS: 'success',
|
|
7
|
+
WARNING: 'warning',
|
|
8
|
+
ERROR: 'error',
|
|
9
|
+
};
|
|
10
|
+
export const TOAST_VARIANT_VALUES = Object.values(TOAST_VARIANTS);
|
|
11
|
+
export const DEFAULT_TOAST_VARIANT = TOAST_VARIANTS.DEFAULT;
|
|
12
|
+
export const DEFAULT_AUTO_CLOSE = 5000;
|
|
13
|
+
export const DEFAULT_CLOSE_BUTTON_ARIA_LABEL = 'Close';
|
|
14
|
+
export const INTERACTIVE_SELECTOR = [
|
|
15
|
+
'a[href]', 'button', 'input', 'select', 'textarea', 'summary', 'label',
|
|
16
|
+
'[role="button"]', '[role="link"]', '[tabindex]:not([tabindex="-1"])',
|
|
17
|
+
].join(', ');
|
|
18
|
+
// Caps the card so tall content scrolls inside it instead of being clipped in silence by
|
|
19
|
+
// the toast engine's own container (react-toastify's is `max-height: 75vh; overflow: hidden`).
|
|
20
|
+
export const DEFAULT_MAX_HEIGHT = '70vh';
|
|
21
|
+
export const DEFAULT_ICONS = {
|
|
22
|
+
default: MdInfo,
|
|
23
|
+
info: MdHelp,
|
|
24
|
+
success: MdCheck,
|
|
25
|
+
warning: MdWarning,
|
|
26
|
+
error: MdError,
|
|
27
|
+
};
|
|
28
|
+
// The success and warning badges take the dark shades of their colors so the white glyph
|
|
29
|
+
// keeps at least the 3:1 non-text contrast WCAG asks for; it fails on the lighter fills.
|
|
30
|
+
export const VARIANT_COLORS = {
|
|
31
|
+
default: { background: colorBrand1, glyph: colorWhite },
|
|
32
|
+
info: { background: colorBrand1, glyph: colorWhite },
|
|
33
|
+
success: { background: colorSuccessDark, glyph: colorWhite },
|
|
34
|
+
warning: { background: colorWarningDark, glyph: colorWhite },
|
|
35
|
+
error: { background: colorError, glyph: colorWhite },
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as BBBToast } from './component';
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import styled, { css, keyframes } from 'styled-components';
|
|
2
|
+
import { colorBackgroundWhite, colorBrand1, colorShadowDefault, colorTextDefault, colorTextLight, } from '../../stylesheets/palette';
|
|
3
|
+
import { borderRadiusSmall, spacingMediumLarge, spacingSmall, spacingSmallMedium, } from '../../stylesheets/sizing';
|
|
4
|
+
import { fontSizeBig, fontSizeDefault, fontSizeSmall, fontSizeXSmall, fontWeightLight, } from '../../stylesheets/typography';
|
|
5
|
+
import { VARIANT_COLORS } from './constants';
|
|
6
|
+
// `message` and `content` take arbitrary nodes, so any media a consumer passes is
|
|
7
|
+
// capped to the card instead of forcing it wider than its container.
|
|
8
|
+
const richContent = css `
|
|
9
|
+
img,
|
|
10
|
+
svg,
|
|
11
|
+
video {
|
|
12
|
+
max-width: 100%;
|
|
13
|
+
}
|
|
14
|
+
`;
|
|
15
|
+
const visuallyHidden = css `
|
|
16
|
+
position: absolute;
|
|
17
|
+
width: 1px;
|
|
18
|
+
height: 1px;
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
clip-path: inset(50%);
|
|
21
|
+
white-space: nowrap;
|
|
22
|
+
`;
|
|
23
|
+
// Unstyled so the message reads as plain text; its focus ring is drawn on the whole card.
|
|
24
|
+
export const CardAction = styled.button `
|
|
25
|
+
margin: 0;
|
|
26
|
+
padding: 0;
|
|
27
|
+
border: 0;
|
|
28
|
+
background: none;
|
|
29
|
+
color: inherit;
|
|
30
|
+
font: inherit;
|
|
31
|
+
line-height: inherit;
|
|
32
|
+
text-align: start;
|
|
33
|
+
cursor: inherit;
|
|
34
|
+
|
|
35
|
+
&:focus {
|
|
36
|
+
outline: none;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
${({ $visuallyHidden }) => $visuallyHidden && visuallyHidden}
|
|
40
|
+
`;
|
|
41
|
+
export const Container = styled.div `
|
|
42
|
+
position: relative;
|
|
43
|
+
display: flex;
|
|
44
|
+
/* Fills the slot it is given even when that slot is a flex container, as toast engines'
|
|
45
|
+
wrappers usually are, so every toast in a stack has the same width. */
|
|
46
|
+
width: 100%;
|
|
47
|
+
flex-direction: row;
|
|
48
|
+
align-items: stretch;
|
|
49
|
+
gap: ${spacingSmallMedium};
|
|
50
|
+
padding: ${spacingMediumLarge};
|
|
51
|
+
background-color: ${colorBackgroundWhite};
|
|
52
|
+
border-radius: ${borderRadiusSmall};
|
|
53
|
+
box-shadow: 0 2px 8px ${colorShadowDefault};
|
|
54
|
+
overflow-wrap: break-word;
|
|
55
|
+
/* So maxHeight caps the whole card, padding included, rather than just its content box. */
|
|
56
|
+
box-sizing: border-box;
|
|
57
|
+
max-height: ${({ $maxHeight }) => $maxHeight};
|
|
58
|
+
cursor: ${({ $disablePointer }) => ($disablePointer ? 'auto' : 'pointer')};
|
|
59
|
+
|
|
60
|
+
&:has(${CardAction}:focus-visible) {
|
|
61
|
+
outline: 2px solid ${colorBrand1};
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
// Mirrors the close button's box. The title row is sized by that button rather than by
|
|
65
|
+
// the text, so pinning the badge to the top left it riding high by half the difference —
|
|
66
|
+
// worse the smaller the badge, which is why it showed up first in the `small` variant.
|
|
67
|
+
// Giving the badge and the title row the same band centers them on one line at any size.
|
|
68
|
+
const titleRowHeight = '2.375rem';
|
|
69
|
+
// The width of BBButton's focus outline, which is drawn outside its box.
|
|
70
|
+
const focusRingWidth = '2px';
|
|
71
|
+
// The icon owns a full-height section of its own on the left; inside it, the badge is
|
|
72
|
+
// centered on the title row so it stays on the title's line as content grows.
|
|
73
|
+
export const IconSection = styled.div `
|
|
74
|
+
display: flex;
|
|
75
|
+
align-items: flex-start;
|
|
76
|
+
flex-shrink: 0;
|
|
77
|
+
`;
|
|
78
|
+
export const IconBand = styled.div `
|
|
79
|
+
display: flex;
|
|
80
|
+
align-items: center;
|
|
81
|
+
min-height: ${titleRowHeight};
|
|
82
|
+
`;
|
|
83
|
+
export const Body = styled.div `
|
|
84
|
+
display: flex;
|
|
85
|
+
flex-direction: column;
|
|
86
|
+
flex: 1;
|
|
87
|
+
min-width: 0;
|
|
88
|
+
gap: ${spacingSmall};
|
|
89
|
+
|
|
90
|
+
/* min-height lets this flex child shrink below its content so the overflow can scroll. */
|
|
91
|
+
min-height: 0;
|
|
92
|
+
overflow-y: auto;
|
|
93
|
+
overflow-x: hidden;
|
|
94
|
+
|
|
95
|
+
/* As a scroll container this clips whatever overflows it, including the focus ring of
|
|
96
|
+
the close button, which spans the full height of the title row. The padding leaves
|
|
97
|
+
room for the ring and the negative margin cancels it out of the layout. */
|
|
98
|
+
padding: ${focusRingWidth};
|
|
99
|
+
margin: -${focusRingWidth};
|
|
100
|
+
`;
|
|
101
|
+
// The close button shares this row with the title only, so it stays on the title's line
|
|
102
|
+
// instead of centering against the content below it.
|
|
103
|
+
export const Header = styled.div `
|
|
104
|
+
display: flex;
|
|
105
|
+
flex-direction: row;
|
|
106
|
+
align-items: center;
|
|
107
|
+
min-height: ${titleRowHeight};
|
|
108
|
+
gap: ${spacingSmall};
|
|
109
|
+
`;
|
|
110
|
+
export const IconBadge = styled.div `
|
|
111
|
+
display: flex;
|
|
112
|
+
align-items: center;
|
|
113
|
+
justify-content: center;
|
|
114
|
+
flex-shrink: 0;
|
|
115
|
+
border-radius: 50%;
|
|
116
|
+
aspect-ratio: 1;
|
|
117
|
+
width: ${({ $small }) => ($small ? '1.5rem' : '2rem')};
|
|
118
|
+
font-size: ${({ $small }) => ($small ? fontSizeXSmall : fontSizeBig)};
|
|
119
|
+
background-color: ${({ $variant }) => VARIANT_COLORS[$variant].background};
|
|
120
|
+
color: ${({ $variant }) => VARIANT_COLORS[$variant].glyph};
|
|
121
|
+
`;
|
|
122
|
+
export const Message = styled.div `
|
|
123
|
+
flex: 1;
|
|
124
|
+
min-width: 0;
|
|
125
|
+
color: ${colorTextDefault};
|
|
126
|
+
font-size: ${({ $small }) => ($small ? fontSizeSmall : fontSizeDefault)};
|
|
127
|
+
font-weight: ${fontWeightLight};
|
|
128
|
+
line-height: normal;
|
|
129
|
+
|
|
130
|
+
${richContent}
|
|
131
|
+
`;
|
|
132
|
+
export const Content = styled.div `
|
|
133
|
+
color: ${colorTextLight};
|
|
134
|
+
font-size: ${({ $small }) => ($small ? fontSizeXSmall : fontSizeSmall)};
|
|
135
|
+
font-weight: ${fontWeightLight};
|
|
136
|
+
line-height: normal;
|
|
137
|
+
|
|
138
|
+
${richContent}
|
|
139
|
+
`;
|
|
140
|
+
export const ActionWrapper = styled.div `
|
|
141
|
+
display: flex;
|
|
142
|
+
justify-content: flex-end;
|
|
143
|
+
`;
|
|
144
|
+
export const CloseButtonWrapper = styled.div `
|
|
145
|
+
display: flex;
|
|
146
|
+
flex-shrink: 0;
|
|
147
|
+
margin-inline-start: auto;
|
|
148
|
+
`;
|
|
149
|
+
const countdown = keyframes `
|
|
150
|
+
from {
|
|
151
|
+
transform: scaleX(1);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
to {
|
|
155
|
+
transform: scaleX(0);
|
|
156
|
+
}
|
|
157
|
+
`;
|
|
158
|
+
// Clips the bar to the card's rounded bottom corners without clipping the card's content.
|
|
159
|
+
export const ProgressTrack = styled.div `
|
|
160
|
+
position: absolute;
|
|
161
|
+
inset-inline: 0;
|
|
162
|
+
bottom: 0;
|
|
163
|
+
height: 0.25rem;
|
|
164
|
+
overflow: hidden;
|
|
165
|
+
border-end-start-radius: ${borderRadiusSmall};
|
|
166
|
+
border-end-end-radius: ${borderRadiusSmall};
|
|
167
|
+
`;
|
|
168
|
+
// Pausing the animation together with the timer keeps the two in step: both resume from
|
|
169
|
+
// where they stopped instead of restarting.
|
|
170
|
+
export const ProgressBar = styled.div `
|
|
171
|
+
height: 100%;
|
|
172
|
+
background-color: ${({ $variant }) => VARIANT_COLORS[$variant].background};
|
|
173
|
+
transform-origin: left;
|
|
174
|
+
animation: ${countdown} ${({ $duration }) => $duration}ms linear forwards;
|
|
175
|
+
animation-play-state: ${({ $paused }) => ($paused ? 'paused' : 'running')};
|
|
176
|
+
|
|
177
|
+
[dir='rtl'] & {
|
|
178
|
+
transform-origin: right;
|
|
179
|
+
}
|
|
180
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -11,7 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import React, { useId } from 'react';
|
|
13
13
|
import * as Styled from './styles';
|
|
14
|
-
import { DEFAULT_TEXT_POSITION } from './constants';
|
|
14
|
+
import { DEFAULT_TEXT_POSITION, TEXT_POSITIONS } from './constants';
|
|
15
15
|
/**
|
|
16
16
|
* A customizable Toggle switch component.
|
|
17
17
|
*
|
|
@@ -20,16 +20,31 @@ import { DEFAULT_TEXT_POSITION } from './constants';
|
|
|
20
20
|
*
|
|
21
21
|
*/
|
|
22
22
|
function Toggle(_a) {
|
|
23
|
-
var { label, helperText, textPosition = DEFAULT_TEXT_POSITION, onChange, ariaLabel, ariaLabelledBy, ariaDescribedBy, id: providedId } = _a, rest = __rest(_a, ["label", "helperText", "textPosition", "onChange", "ariaLabel", "ariaLabelledBy", "ariaDescribedBy", "id"]);
|
|
23
|
+
var { label, helperText, textPosition = DEFAULT_TEXT_POSITION, fullWidth = false, onChange, ariaLabel, ariaLabelledBy, ariaDescribedBy, id: providedId, slotProps } = _a, rest = __rest(_a, ["label", "helperText", "textPosition", "fullWidth", "onChange", "ariaLabel", "ariaLabelledBy", "ariaDescribedBy", "id", "slotProps"]);
|
|
24
24
|
const generatedUniqueId = useId();
|
|
25
25
|
const id = providedId !== null && providedId !== void 0 ? providedId : generatedUniqueId;
|
|
26
26
|
const labelId = label ? `${id}-label` : undefined;
|
|
27
27
|
const helperTextId = helperText ? `${id}-helper` : undefined;
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
const isFullWidth = fullWidth && (textPosition === TEXT_POSITIONS.LEFT || textPosition === TEXT_POSITIONS.RIGHT);
|
|
29
|
+
const ariaLabelledByValue = ariaLabel ? undefined : ariaLabelledBy || labelId;
|
|
30
|
+
// Without a name source, the <label htmlFor> names the input from the helper text,
|
|
31
|
+
// so it can't also be the description.
|
|
32
|
+
const hasNameSource = !!ariaLabel || !!ariaLabelledByValue;
|
|
33
|
+
const a11yInputProps = {
|
|
34
|
+
role: 'switch',
|
|
35
|
+
'aria-label': ariaLabel,
|
|
36
|
+
'aria-labelledby': ariaLabelledByValue,
|
|
37
|
+
'aria-describedby': ariaDescribedBy || (hasNameSource ? helperTextId : undefined),
|
|
38
|
+
};
|
|
39
|
+
const _b = slotProps !== null && slotProps !== void 0 ? slotProps : {}, { input: consumerInputSlotProps } = _b, otherSlotProps = __rest(_b, ["input"]);
|
|
40
|
+
const inputSlotProps = typeof consumerInputSlotProps === 'function'
|
|
41
|
+
? (ownerState) => (Object.assign(Object.assign({}, a11yInputProps), consumerInputSlotProps(ownerState)))
|
|
42
|
+
: Object.assign(Object.assign({}, a11yInputProps), consumerInputSlotProps);
|
|
43
|
+
return (React.createElement(Styled.ToggleWrapper, { "$textPosition": textPosition, "$fullWidth": isFullWidth },
|
|
44
|
+
(label || helperText) && (React.createElement(Styled.TextWrapper, { "$textPosition": textPosition, "$fullWidth": isFullWidth, htmlFor: id, "$hasLabel": !!label, "$hasHelperText": !!helperText },
|
|
30
45
|
label && React.createElement(Styled.Title, { id: labelId }, label),
|
|
31
46
|
helperText && React.createElement(Styled.HelperText, { id: helperTextId }, helperText))),
|
|
32
47
|
React.createElement(Styled.ToggleSwitchWrapper, null,
|
|
33
|
-
React.createElement(Styled.MaterialToggle, Object.assign({}, rest, { id: id, onChange: onChange,
|
|
48
|
+
React.createElement(Styled.MaterialToggle, Object.assign({}, rest, { id: id, onChange: onChange, slotProps: Object.assign(Object.assign({}, otherSlotProps), { input: inputSlotProps }) })))));
|
|
34
49
|
}
|
|
35
50
|
export default Toggle;
|
|
@@ -25,6 +25,10 @@ export const ToggleWrapper = styled.div `
|
|
|
25
25
|
}
|
|
26
26
|
return horizontalStyles;
|
|
27
27
|
}};
|
|
28
|
+
${({ $fullWidth }) => $fullWidth && css `
|
|
29
|
+
width: 100%;
|
|
30
|
+
justify-content: space-between;
|
|
31
|
+
`}
|
|
28
32
|
`;
|
|
29
33
|
export const ToggleSwitchWrapper = styled.div `
|
|
30
34
|
display: flex;
|
|
@@ -44,13 +48,20 @@ export const TextWrapper = styled.label `
|
|
|
44
48
|
}};
|
|
45
49
|
cursor: pointer;
|
|
46
50
|
${({ $hasLabel, $hasHelperText }) => (!$hasLabel || !$hasHelperText) && `justify-content: center;`}
|
|
47
|
-
${({ $textPosition }) => {
|
|
51
|
+
${({ $textPosition, $fullWidth }) => {
|
|
48
52
|
if ($textPosition === TEXT_POSITIONS.TOP || $textPosition === TEXT_POSITIONS.BOTTOM) {
|
|
49
53
|
return css `
|
|
50
54
|
align-items: center;
|
|
51
55
|
`;
|
|
52
56
|
}
|
|
53
|
-
|
|
57
|
+
// A full-width row aligns the text to the container's edge; otherwise it hugs the switch.
|
|
58
|
+
if ($fullWidth && $textPosition === TEXT_POSITIONS.RIGHT) {
|
|
59
|
+
return css `
|
|
60
|
+
align-items: end;
|
|
61
|
+
text-align: end;
|
|
62
|
+
`;
|
|
63
|
+
}
|
|
64
|
+
if ($textPosition === TEXT_POSITIONS.LEFT && !$fullWidth)
|
|
54
65
|
return css `align-items: end;`;
|
|
55
66
|
return css `
|
|
56
67
|
align-items: start;
|
|
@@ -14,5 +14,6 @@ export { BBBSlider } from './Slider';
|
|
|
14
14
|
export { BBBSpinner } from './Spinner';
|
|
15
15
|
export { BBBTextAreaInput } from './TextAreaInput';
|
|
16
16
|
export { BBBTextInput } from './TextInput';
|
|
17
|
+
export { BBBToast } from './Toast';
|
|
17
18
|
export { BBBToggle } from './Toggle';
|
|
18
19
|
export { BBBTypography } from './Typography';
|