@bigbluebutton/bbb-ui-components-react 0.9.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/README.md +1 -0
- package/dist/components/Accordion.js +7 -7
- package/dist/components/Avatar.js +5 -5
- package/dist/components/Button.js +32 -29
- package/dist/components/Checkbox.js +33 -10
- package/dist/components/Input.js +64 -61
- package/dist/components/Modal.js +46 -43
- package/dist/components/Search.js +3 -2
- package/dist/components/Slider.js +8 -8
- package/dist/components/Spinner.js +1 -0
- package/dist/components/Toast.js +295 -0
- package/dist/components/Toggle.js +23 -16
- package/dist/components/index.js +318 -142
- package/dist/esm/components/Accordion/component.js +2 -1
- package/dist/esm/components/Avatar/component.js +2 -1
- package/dist/esm/components/Button/component.js +26 -5
- package/dist/esm/components/Button/constants.js +11 -4
- package/dist/esm/components/Button/styles.js +25 -1
- package/dist/esm/components/Checkbox/component.js +67 -12
- package/dist/esm/components/Checkbox/constants.js +8 -0
- package/dist/esm/components/Checkbox/styles.js +50 -8
- package/dist/esm/components/Slider/component.js +3 -2
- package/dist/esm/components/Slider/valueLabel.js +36 -0
- 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 +88 -16
- package/dist/esm/components/Toggle/constants.js +8 -0
- package/dist/esm/components/Toggle/styles.js +32 -6
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/stylesheets/palette.js +4 -0
- package/dist/esm/utils/tooltip.js +20 -0
- package/dist/types/components/Button/constants.d.ts +8 -1
- package/dist/types/components/Button/styles.d.ts +2 -1
- package/dist/types/components/Button/type.d.ts +8 -1
- package/dist/types/components/Checkbox/component.d.ts +2 -1
- package/dist/types/components/Checkbox/constants.d.ts +8 -0
- package/dist/types/components/Checkbox/styles.d.ts +5 -3
- package/dist/types/components/Checkbox/types.d.ts +19 -1
- package/dist/types/components/Slider/component.d.ts +1 -1
- package/dist/types/components/Slider/valueLabel.d.ts +7 -0
- package/dist/types/components/TextInput/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 +2 -1
- package/dist/types/components/Toggle/constants.d.ts +8 -0
- package/dist/types/components/Toggle/styles.d.ts +3 -3
- package/dist/types/components/Toggle/types.d.ts +14 -1
- package/dist/types/components/index.d.ts +1 -0
- package/dist/types/stylesheets/palette.d.ts +2 -0
- package/dist/types/utils/tooltip.d.ts +3 -0
- package/package.json +11 -1
|
@@ -3,6 +3,7 @@ import * as Styled from './styles';
|
|
|
3
3
|
import { MdExpandMore } from 'react-icons/md';
|
|
4
4
|
import Tippy from '@tippyjs/react';
|
|
5
5
|
import 'tippy.js/dist/tippy.css';
|
|
6
|
+
import { TOOLTIP_PLUGINS } from '../../utils/tooltip';
|
|
6
7
|
import { DEFAULT_TOOLTIP_PLACEMENT, DEFAULT_BUTTON_HEADER_POSITION } from './constants';
|
|
7
8
|
/**
|
|
8
9
|
* A customizable Accordion component that allows expanding and collapsing content.
|
|
@@ -22,7 +23,7 @@ function Accordion({ title, tooltipLabel = undefined, tooltipPlacement = DEFAULT
|
|
|
22
23
|
React.createElement(Styled.TitleText, null, title),
|
|
23
24
|
React.createElement(Styled.ButtonHeaderWrapper, { "$position": buttonHeaderPosition }, buttonHeader))));
|
|
24
25
|
return (React.createElement(React.Fragment, null,
|
|
25
|
-
tooltipLabel ? (React.createElement(Tippy, { content: tooltipLabel, placement: tooltipPlacement }, expandButton)) : (expandButton),
|
|
26
|
+
tooltipLabel ? (React.createElement(Tippy, { content: tooltipLabel, placement: tooltipPlacement, plugins: TOOLTIP_PLUGINS }, expandButton)) : (expandButton),
|
|
26
27
|
React.createElement(Styled.AccordionContent, { ref: contentRef, "$expanded": isExpanded, "$scrollHeight": ((_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.scrollHeight) || 0 }, children)));
|
|
27
28
|
}
|
|
28
29
|
export default Accordion;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { useEffect, useState } from 'react';
|
|
2
2
|
import Tippy from '@tippyjs/react';
|
|
3
3
|
import 'tippy.js/dist/tippy.css';
|
|
4
|
+
import { TOOLTIP_PLUGINS } from '../../utils/tooltip';
|
|
4
5
|
import * as Styled from './styles';
|
|
5
6
|
import { DEFAULT_AVATAR_SIZE, AVATAR_FALLBACK_COLORS } from './constants';
|
|
6
7
|
import { colorUserYou } from '../../stylesheets/palette';
|
|
@@ -33,6 +34,6 @@ function Avatar({ name, avatarUrl, color, size = DEFAULT_AVATAR_SIZE, isModerato
|
|
|
33
34
|
if (disableTooltip) {
|
|
34
35
|
return avatarElement;
|
|
35
36
|
}
|
|
36
|
-
return (React.createElement(Tippy, { content: name, placement: "top" }, avatarElement));
|
|
37
|
+
return (React.createElement(Tippy, { content: name, placement: "top", plugins: TOOLTIP_PLUGINS }, avatarElement));
|
|
37
38
|
}
|
|
38
39
|
export default Avatar;
|
|
@@ -1,9 +1,10 @@
|
|
|
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, DEFAULT_TYPE, } from './constants';
|
|
3
|
+
import { DEFAULT_VARIANT, DEFAULT_COLOR, DEFAULT_SIZE, DEFAULT_LAYOUT, LAYOUTS, DEFAULT_TOOLTIP_PLACEMENT, DEFAULT_TYPE, DEFAULT_LABEL_OVERFLOW, LABEL_OVERFLOWS, } from './constants';
|
|
4
4
|
import * as Styled from './styles';
|
|
5
5
|
import Tippy from '@tippyjs/react';
|
|
6
6
|
import 'tippy.js/dist/tippy.css';
|
|
7
|
+
import { TOOLTIP_PLUGINS } from '../../utils/tooltip';
|
|
7
8
|
/**
|
|
8
9
|
* A versatile Button component.
|
|
9
10
|
*
|
|
@@ -14,6 +15,9 @@ import 'tippy.js/dist/tippy.css';
|
|
|
14
15
|
*/
|
|
15
16
|
function Button(props) {
|
|
16
17
|
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;
|
|
18
|
+
const labelOverflow = (layout === LAYOUTS.DEFAULT && 'labelOverflow' in props && props.labelOverflow)
|
|
19
|
+
|| DEFAULT_LABEL_OVERFLOW;
|
|
20
|
+
const truncatesLabel = labelOverflow === LABEL_OVERFLOWS.ELLIPSIS;
|
|
17
21
|
const feedbackTimeoutRef = useRef(null);
|
|
18
22
|
const [isFeedbackVisible, setFeedbackVisible] = useState(false);
|
|
19
23
|
useEffect(() => () => {
|
|
@@ -29,6 +33,20 @@ function Button(props) {
|
|
|
29
33
|
feedbackTimeoutRef.current = setTimeout(() => setFeedbackVisible(false), feedbackDuration);
|
|
30
34
|
}
|
|
31
35
|
}, [onClick, showFeedback, feedbackDuration]);
|
|
36
|
+
const labelRef = useRef(null);
|
|
37
|
+
const [isLabelTruncated, setLabelTruncated] = useState(false);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
const labelElement = labelRef.current;
|
|
40
|
+
if (!truncatesLabel || !labelElement || typeof ResizeObserver === 'undefined') {
|
|
41
|
+
setLabelTruncated(false);
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
const observer = new ResizeObserver(() => {
|
|
45
|
+
setLabelTruncated(labelElement.scrollWidth > labelElement.clientWidth);
|
|
46
|
+
});
|
|
47
|
+
observer.observe(labelElement);
|
|
48
|
+
return () => observer.disconnect();
|
|
49
|
+
}, [truncatesLabel, label, isFeedbackVisible]);
|
|
32
50
|
const accessibilityProps = {};
|
|
33
51
|
const generatedId = useId();
|
|
34
52
|
const defaultLabelId = `${id || generatedId}-label`;
|
|
@@ -76,14 +94,17 @@ function Button(props) {
|
|
|
76
94
|
}
|
|
77
95
|
const { iconStart, iconEnd, fullWidth = false } = props;
|
|
78
96
|
const testId = dataTest || `button-${id || label || 'default'}`;
|
|
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,
|
|
97
|
+
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, "$labelOverflow": labelOverflow, disabled: disabled }), isFeedbackVisible ? (React.createElement(Styled.FeedbackContent, { id: defaultLabelId, role: "status", "aria-live": "polite" }, feedbackContent)) : (React.createElement(React.Fragment, null,
|
|
80
98
|
iconStart && iconStart,
|
|
81
|
-
label && React.createElement(
|
|
99
|
+
label && (React.createElement(Styled.Label, { id: defaultLabelId, ref: labelRef, "$truncate": truncatesLabel }, label)),
|
|
82
100
|
children,
|
|
83
101
|
iconEnd && iconEnd))));
|
|
84
102
|
})();
|
|
85
|
-
|
|
86
|
-
|
|
103
|
+
// The truncated-label tooltip repeats text that is already the accessible name
|
|
104
|
+
// (via aria-labelledby), so it must not also be announced as a description.
|
|
105
|
+
const showsTruncatedLabelTooltip = !tooltipLabel && truncatesLabel && Boolean(label);
|
|
106
|
+
if (tooltipLabel || showsTruncatedLabelTooltip) {
|
|
107
|
+
return (React.createElement(Tippy, { content: tooltipLabel || label, placement: tooltipPlacement, plugins: TOOLTIP_PLUGINS, disabled: showsTruncatedLabelTooltip && !isLabelTruncated, aria: { content: showsTruncatedLabelTooltip ? null : 'auto' } }, buttonElement));
|
|
87
108
|
}
|
|
88
109
|
return buttonElement;
|
|
89
110
|
}
|
|
@@ -29,6 +29,13 @@ const LAYOUTS = {
|
|
|
29
29
|
};
|
|
30
30
|
const LAYOUT_VALUES = Object.values(LAYOUTS);
|
|
31
31
|
const DEFAULT_LAYOUT = LAYOUT_VALUES[0];
|
|
32
|
+
const LABEL_OVERFLOWS = {
|
|
33
|
+
NOWRAP: 'nowrap',
|
|
34
|
+
WRAP: 'wrap',
|
|
35
|
+
ELLIPSIS: 'ellipsis',
|
|
36
|
+
};
|
|
37
|
+
const LABEL_OVERFLOW_VALUES = Object.values(LABEL_OVERFLOWS);
|
|
38
|
+
const DEFAULT_LABEL_OVERFLOW = LABEL_OVERFLOWS.NOWRAP;
|
|
32
39
|
const TOOLTIP_PLACEMENTS = {
|
|
33
40
|
TOP: 'top',
|
|
34
41
|
BOTTOM: 'bottom',
|
|
@@ -156,12 +163,12 @@ const CSS_COLOR_PROPERTIES = {
|
|
|
156
163
|
},
|
|
157
164
|
neutral: {
|
|
158
165
|
color: colorGray,
|
|
159
|
-
background:
|
|
166
|
+
background: 'transparent',
|
|
160
167
|
border: false,
|
|
161
168
|
hoverColor: colorGray,
|
|
162
|
-
hoverBackground:
|
|
169
|
+
hoverBackground: colorLightGray,
|
|
163
170
|
hoverBorder: false,
|
|
164
|
-
outline:
|
|
171
|
+
outline: colorIconDefault,
|
|
165
172
|
},
|
|
166
173
|
},
|
|
167
174
|
};
|
|
@@ -181,4 +188,4 @@ const CSS_SIZE_PROPERTIES = {
|
|
|
181
188
|
iconBoxSize: spacingXXLarge,
|
|
182
189
|
},
|
|
183
190
|
};
|
|
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, };
|
|
191
|
+
export { VARIANTS, VARIANT_VALUES, DEFAULT_VARIANT, COLORS, COLOR_VALUES, DEFAULT_COLOR, SIZES, SIZE_VALUES, DEFAULT_SIZE, LAYOUTS, LAYOUT_VALUES, DEFAULT_LAYOUT, LABEL_OVERFLOWS, LABEL_OVERFLOW_VALUES, DEFAULT_LABEL_OVERFLOW, TOOLTIP_PLACEMENTS, TOOLTIP_PLACEMENT_VALUES, DEFAULT_TOOLTIP_PLACEMENT, TYPES, TYPE_VALUES, DEFAULT_TYPE, CSS_COLOR_PROPERTIES, CSS_COLOR_PROPERTIES_DISABLED, CSS_SIZE_PROPERTIES, };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import styled, { css } from 'styled-components';
|
|
2
|
-
import { CSS_COLOR_PROPERTIES, CSS_COLOR_PROPERTIES_DISABLED, CSS_SIZE_PROPERTIES, DEFAULT_COLOR, DEFAULT_SIZE, DEFAULT_VARIANT, VARIANTS, LAYOUTS, } from './constants';
|
|
2
|
+
import { CSS_COLOR_PROPERTIES, CSS_COLOR_PROPERTIES_DISABLED, CSS_SIZE_PROPERTIES, DEFAULT_COLOR, DEFAULT_SIZE, DEFAULT_VARIANT, VARIANTS, LAYOUTS, LABEL_OVERFLOWS, } from './constants';
|
|
3
3
|
import { borderRadiusDefault, borderRadiusSmall, spacingSmall, } from '../../stylesheets/sizing';
|
|
4
4
|
import { colorBorderDefault, colorTextDefault } from '../../stylesheets/palette';
|
|
5
5
|
import { fontSizeSmall } from '../../stylesheets/typography';
|
|
@@ -116,6 +116,22 @@ const squaredLayoutStyles = css `
|
|
|
116
116
|
const defaultLayoutStyles = css `
|
|
117
117
|
display: ${({ $fullWidth }) => ($fullWidth ? 'flex' : 'inline-flex')};
|
|
118
118
|
${({ $fullWidth }) => $fullWidth && 'width: 100%;'}
|
|
119
|
+
${({ $labelOverflow }) => {
|
|
120
|
+
switch ($labelOverflow) {
|
|
121
|
+
case LABEL_OVERFLOWS.WRAP:
|
|
122
|
+
return `
|
|
123
|
+
white-space: normal;
|
|
124
|
+
overflow-wrap: anywhere;
|
|
125
|
+
`;
|
|
126
|
+
case LABEL_OVERFLOWS.ELLIPSIS:
|
|
127
|
+
return `
|
|
128
|
+
min-width: 0;
|
|
129
|
+
max-width: 100%;
|
|
130
|
+
`;
|
|
131
|
+
default:
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
}}
|
|
119
135
|
justify-content: center;
|
|
120
136
|
align-items: center;
|
|
121
137
|
gap: ${spacingSmall};
|
|
@@ -192,6 +208,14 @@ export const FeedbackContent = styled.span `
|
|
|
192
208
|
justify-content: center;
|
|
193
209
|
gap: ${spacingSmall};
|
|
194
210
|
`;
|
|
211
|
+
export const Label = styled.span `
|
|
212
|
+
${({ $truncate }) => $truncate && `
|
|
213
|
+
min-width: 0;
|
|
214
|
+
overflow: hidden;
|
|
215
|
+
text-overflow: ellipsis;
|
|
216
|
+
white-space: nowrap;
|
|
217
|
+
`}
|
|
218
|
+
`;
|
|
195
219
|
export const ButtonText = styled.div `
|
|
196
220
|
color: ${colorTextDefault};
|
|
197
221
|
font-size: ${fontSizeSmall};
|
|
@@ -9,10 +9,17 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import React, { useId } from 'react';
|
|
12
|
+
import React, { useId, useRef } from 'react';
|
|
13
13
|
import * as Styled from './styles';
|
|
14
|
-
import { DEFAULT_LAYOUT, LAYOUTS } from './constants';
|
|
14
|
+
import { DEFAULT_LAYOUT, DEFAULT_TOOLTIP_PLACEMENT, LAYOUTS } from './constants';
|
|
15
15
|
import { RadioButtonUnchecked, RadioButtonChecked } from '@mui/icons-material';
|
|
16
|
+
import Tippy from '@tippyjs/react';
|
|
17
|
+
import 'tippy.js/dist/tippy.css';
|
|
18
|
+
import { TOOLTIP_PLUGINS } from '../../utils/tooltip';
|
|
19
|
+
// Cancelling the click (mouse, label or Space) keeps the box unchanged, and MUI skips
|
|
20
|
+
// `onChange` for a prevented click. It sits on the root because MUI drops event handlers
|
|
21
|
+
// passed through `slotProps.input`, except `onChange`.
|
|
22
|
+
const preventToggle = (event) => event.preventDefault();
|
|
16
23
|
/**
|
|
17
24
|
* A customizable Checkbox component.
|
|
18
25
|
*
|
|
@@ -22,21 +29,69 @@ import { RadioButtonUnchecked, RadioButtonChecked } from '@mui/icons-material';
|
|
|
22
29
|
*
|
|
23
30
|
*/
|
|
24
31
|
function Checkbox(_a) {
|
|
25
|
-
var { label, layout = DEFAULT_LAYOUT, round = false, ariaLabel, id, dataTest, slotProps } = _a, props = __rest(_a, ["label", "layout", "round", "ariaLabel", "id", "dataTest", "slotProps"]);
|
|
32
|
+
var { label, layout = DEFAULT_LAYOUT, helperText, round = false, ariaLabel, id, dataTest, slotProps, disabled, tooltipLabel, tooltipPlacement = DEFAULT_TOOLTIP_PLACEMENT } = _a, props = __rest(_a, ["label", "layout", "helperText", "round", "ariaLabel", "id", "dataTest", "slotProps", "disabled", "tooltipLabel", "tooltipPlacement"]);
|
|
26
33
|
const generatedId = useId();
|
|
34
|
+
const containerRef = useRef(null);
|
|
27
35
|
const checkboxId = id !== null && id !== void 0 ? id : generatedId;
|
|
28
|
-
const
|
|
36
|
+
const labelId = `${checkboxId}-label`;
|
|
37
|
+
const helperTextId = `${checkboxId}-helper`;
|
|
38
|
+
const tooltipDescriptionId = `${checkboxId}-tooltip`;
|
|
39
|
+
// The helper text is a second <label> so clicking it toggles the checkbox, but every
|
|
40
|
+
// associated <label> joins the accessible name. aria-labelledby keeps the name to the
|
|
41
|
+
// label alone, leaving the helper text as the description; with no other name source,
|
|
42
|
+
// the helper text names the checkbox and can't also describe it. The tooltip text
|
|
43
|
+
// follows the same rule when neither a label nor the helper text names the checkbox.
|
|
44
|
+
const hasNameSource = Boolean(ariaLabel || label);
|
|
45
|
+
const tooltipNamesCheckbox = Boolean(tooltipLabel && !hasNameSource && !helperText);
|
|
46
|
+
let ariaLabelledBy;
|
|
47
|
+
if (!ariaLabel && label)
|
|
48
|
+
ariaLabelledBy = labelId;
|
|
49
|
+
else if (tooltipNamesCheckbox)
|
|
50
|
+
ariaLabelledBy = tooltipDescriptionId;
|
|
51
|
+
const describedBy = [
|
|
52
|
+
hasNameSource && helperText && helperTextId,
|
|
53
|
+
tooltipLabel && !tooltipNamesCheckbox && tooltipDescriptionId,
|
|
54
|
+
].filter(Boolean).join(' ');
|
|
55
|
+
const ownInputProps = {
|
|
56
|
+
'aria-label': ariaLabel,
|
|
57
|
+
'aria-labelledby': ariaLabelledBy,
|
|
58
|
+
'aria-describedby': describedBy || undefined,
|
|
59
|
+
'data-test': dataTest,
|
|
60
|
+
};
|
|
61
|
+
// A natively disabled input leaves the tab order, so keyboard users could never reach the
|
|
62
|
+
// tooltip that explains why it is disabled. With a tooltip, the input stays focusable and is
|
|
63
|
+
// announced through aria-disabled instead; dropping `name` and `required` keeps it out of form
|
|
64
|
+
// submission and validation, as a natively disabled input would be.
|
|
65
|
+
const focusableWhileDisabled = Boolean(disabled && tooltipLabel);
|
|
66
|
+
const focusableDisabledInputProps = focusableWhileDisabled
|
|
67
|
+
? {
|
|
68
|
+
disabled: false,
|
|
69
|
+
'aria-disabled': true,
|
|
70
|
+
name: undefined,
|
|
71
|
+
required: false,
|
|
72
|
+
}
|
|
73
|
+
: {};
|
|
29
74
|
const _b = slotProps !== null && slotProps !== void 0 ? slotProps : {}, { input: consumerInputSlotProps } = _b, otherSlotProps = __rest(_b, ["input"]);
|
|
30
75
|
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 }) })));
|
|
34
|
-
if (!label) {
|
|
76
|
+
? (ownerState) => (Object.assign(Object.assign(Object.assign({}, ownInputProps), consumerInputSlotProps(ownerState)), focusableDisabledInputProps))
|
|
77
|
+
: Object.assign(Object.assign(Object.assign({}, ownInputProps), consumerInputSlotProps), focusableDisabledInputProps);
|
|
78
|
+
const checkbox = (React.createElement(Styled.StyledCheckbox, Object.assign({}, props, { id: checkboxId, disabled: disabled, "$round": round }, (focusableWhileDisabled && { onClick: preventToggle }), { icon: round ? React.createElement(RadioButtonUnchecked, null) : undefined, checkedIcon: round ? React.createElement(RadioButtonChecked, null) : undefined, slotProps: Object.assign(Object.assign({}, otherSlotProps), { input: inputSlotProps }) })));
|
|
79
|
+
if (!label && !helperText && !tooltipLabel) {
|
|
35
80
|
return checkbox;
|
|
36
81
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
82
|
+
const labelElement = label && (React.createElement(Styled.Label, { id: labelId, htmlFor: checkboxId, "$disabled": disabled }, label));
|
|
83
|
+
// Tippy sits beside the container instead of wrapping it, so toggling `tooltipLabel`
|
|
84
|
+
// keeps the same root and doesn't remount the checkbox (losing focus and uncontrolled
|
|
85
|
+
// state). It targets the container, not the input: MUI gives the disabled box
|
|
86
|
+
// `pointer-events: none`, so hovering it reaches the container. `focusin` bubbles
|
|
87
|
+
// from the input; Tippy's `focus` would not.
|
|
88
|
+
return (React.createElement(React.Fragment, null,
|
|
89
|
+
React.createElement(Styled.Container, { ref: containerRef, "$layout": layout, "$hasLabel": !!label, "$hasHelperText": !!helperText },
|
|
90
|
+
layout === LAYOUTS.LEFT && labelElement,
|
|
91
|
+
checkbox,
|
|
92
|
+
layout === LAYOUTS.RIGHT && labelElement,
|
|
93
|
+
helperText && (React.createElement(Styled.HelperText, { id: helperTextId, htmlFor: checkboxId, "$disabled": disabled }, helperText)),
|
|
94
|
+
tooltipLabel && (React.createElement("span", { id: tooltipDescriptionId, hidden: true }, tooltipLabel))),
|
|
95
|
+
tooltipLabel && (React.createElement(Tippy, { reference: containerRef, content: tooltipLabel, placement: tooltipPlacement, trigger: "mouseenter focusin", aria: { content: null }, plugins: TOOLTIP_PLUGINS }))));
|
|
41
96
|
}
|
|
42
97
|
export default Checkbox;
|
|
@@ -4,3 +4,11 @@ export const LAYOUTS = {
|
|
|
4
4
|
};
|
|
5
5
|
export const LAYOUT_VALUES = Object.values(LAYOUTS);
|
|
6
6
|
export const DEFAULT_LAYOUT = LAYOUT_VALUES[0];
|
|
7
|
+
export const TOOLTIP_PLACEMENTS = {
|
|
8
|
+
TOP: 'top',
|
|
9
|
+
BOTTOM: 'bottom',
|
|
10
|
+
LEFT: 'left',
|
|
11
|
+
RIGHT: 'right',
|
|
12
|
+
};
|
|
13
|
+
export const TOOLTIP_PLACEMENT_VALUES = Object.values(TOOLTIP_PLACEMENTS);
|
|
14
|
+
export const DEFAULT_TOOLTIP_PLACEMENT = TOOLTIP_PLACEMENTS.TOP;
|
|
@@ -1,27 +1,69 @@
|
|
|
1
1
|
import styled from 'styled-components';
|
|
2
2
|
import { Checkbox as MuiCheckbox } from '@mui/material';
|
|
3
|
-
import { colorTextDefault, colorBrand1 } from '../../stylesheets/palette';
|
|
4
|
-
import { fontSizeDefault } from '../../stylesheets/typography';
|
|
5
|
-
import { spacingSmall } from '../../stylesheets/sizing';
|
|
3
|
+
import { colorTextDefault, colorTextLight, colorBrand1, colorNeutral3, } from '../../stylesheets/palette';
|
|
4
|
+
import { fontSizeDefault, fontSizeSmall } from '../../stylesheets/typography';
|
|
5
|
+
import { borderRadiusSmall, spacingSmall } from '../../stylesheets/sizing';
|
|
6
|
+
import { LAYOUTS } from './constants';
|
|
7
|
+
const getGridTemplateAreas = ({ $layout, $hasLabel, $hasHelperText }) => {
|
|
8
|
+
const textArea = $hasLabel ? 'label' : 'helper';
|
|
9
|
+
const rows = $hasLabel || $hasHelperText ? [['box', textArea]] : [['box']];
|
|
10
|
+
if ($hasLabel && $hasHelperText)
|
|
11
|
+
rows.push(['.', 'helper']);
|
|
12
|
+
const orderedRows = $layout === LAYOUTS.LEFT ? rows.map((row) => [...row].reverse()) : rows;
|
|
13
|
+
return orderedRows.map((row) => `"${row.join(' ')}"`).join(' ');
|
|
14
|
+
};
|
|
15
|
+
// A grid rather than a flex row so the box stays centered on the label's line
|
|
16
|
+
// while the helper text sits below the label, not below the box.
|
|
6
17
|
export const Container = styled.div `
|
|
7
|
-
display: inline-
|
|
18
|
+
display: inline-grid;
|
|
19
|
+
grid-template-areas: ${getGridTemplateAreas};
|
|
20
|
+
column-gap: ${spacingSmall};
|
|
8
21
|
align-items: center;
|
|
9
|
-
|
|
22
|
+
text-align: ${({ $layout }) => ($layout === LAYOUTS.LEFT ? 'end' : 'start')};
|
|
23
|
+
|
|
24
|
+
& > .MuiCheckbox-root {
|
|
25
|
+
grid-area: box;
|
|
26
|
+
}
|
|
10
27
|
`;
|
|
11
28
|
export const Label = styled.label `
|
|
12
|
-
color: ${colorTextDefault};
|
|
29
|
+
color: ${({ $disabled }) => ($disabled ? colorNeutral3 : colorTextDefault)};
|
|
13
30
|
font-size: ${fontSizeDefault};
|
|
14
31
|
font-style: normal;
|
|
15
32
|
font-weight: 400;
|
|
16
33
|
line-height: normal;
|
|
17
|
-
cursor: pointer;
|
|
34
|
+
cursor: ${({ $disabled }) => ($disabled ? 'not-allowed' : 'pointer')};
|
|
35
|
+
grid-area: label;
|
|
36
|
+
`;
|
|
37
|
+
export const HelperText = styled.label `
|
|
38
|
+
color: ${({ $disabled }) => ($disabled ? colorNeutral3 : colorTextLight)};
|
|
39
|
+
font-size: ${fontSizeSmall};
|
|
40
|
+
font-style: normal;
|
|
41
|
+
font-weight: 400;
|
|
42
|
+
line-height: normal;
|
|
43
|
+
cursor: ${({ $disabled }) => ($disabled ? 'not-allowed' : 'pointer')};
|
|
44
|
+
grid-area: helper;
|
|
18
45
|
`;
|
|
46
|
+
// The root has no padding, so MUI's focus ripple only tints the inside of the
|
|
47
|
+
// box; the outline is what makes keyboard focus visible. MUI never sets
|
|
48
|
+
// `Mui-focusVisible` while disabled, so a focusable disabled input (one with a
|
|
49
|
+
// tooltip) is matched through `:has` instead.
|
|
50
|
+
// MUI's own checked/indeterminate color rule is as specific as `&.Mui-checked`
|
|
51
|
+
// and can be injected after it (it is in BigBlueButton), so the brand color
|
|
52
|
+
// doubles the class to win either way. A disabled box keeps MUI's disabled color.
|
|
19
53
|
export const StyledCheckbox = styled(MuiCheckbox) `
|
|
20
54
|
&.MuiCheckbox-root {
|
|
21
55
|
padding: 0;
|
|
56
|
+
border-radius: ${({ $round }) => ($round ? '50%' : borderRadiusSmall)};
|
|
22
57
|
}
|
|
23
58
|
|
|
24
|
-
|
|
59
|
+
&&.Mui-checked:not(.Mui-disabled),
|
|
60
|
+
&&.MuiCheckbox-indeterminate:not(.Mui-disabled) {
|
|
25
61
|
color: ${colorBrand1};
|
|
26
62
|
}
|
|
63
|
+
|
|
64
|
+
&.Mui-focusVisible,
|
|
65
|
+
&.Mui-disabled:has(input:focus-visible) {
|
|
66
|
+
outline: 2px solid ${colorBrand1};
|
|
67
|
+
outline-offset: 2px;
|
|
68
|
+
}
|
|
27
69
|
`;
|
|
@@ -13,6 +13,7 @@ import React, { useCallback, useEffect, useId, useMemo, useRef, useState } from
|
|
|
13
13
|
import { createTheme, ThemeProvider, useTheme } from '@mui/material/styles';
|
|
14
14
|
import * as Styled from './styles';
|
|
15
15
|
import { DEFAULT_ANIMATE, DEFAULT_SHOW_MARK_TICKS, DEFAULT_VALUE_LABEL_DISPLAY } from './constants';
|
|
16
|
+
import DismissibleValueLabel from './valueLabel';
|
|
16
17
|
/**
|
|
17
18
|
* A horizontal, single-thumb slider for picking a value inside a range.
|
|
18
19
|
*
|
|
@@ -21,7 +22,7 @@ import { DEFAULT_ANIMATE, DEFAULT_SHOW_MARK_TICKS, DEFAULT_VALUE_LABEL_DISPLAY }
|
|
|
21
22
|
*
|
|
22
23
|
*/
|
|
23
24
|
function Slider(_a) {
|
|
24
|
-
var { label, helperText, iconStart, iconEnd, showMarkTicks = DEFAULT_SHOW_MARK_TICKS, animate = DEFAULT_ANIMATE, valueLabelDisplay = DEFAULT_VALUE_LABEL_DISPLAY, onChange, onChangeCommitted, id: providedId, dataTest, ariaLabel, ariaLabelledBy, ariaDescribedBy, slotProps } = _a, rest = __rest(_a, ["label", "helperText", "iconStart", "iconEnd", "showMarkTicks", "animate", "valueLabelDisplay", "onChange", "onChangeCommitted", "id", "dataTest", "ariaLabel", "ariaLabelledBy", "ariaDescribedBy", "slotProps"]);
|
|
25
|
+
var { label, helperText, iconStart, iconEnd, showMarkTicks = DEFAULT_SHOW_MARK_TICKS, animate = DEFAULT_ANIMATE, valueLabelDisplay = DEFAULT_VALUE_LABEL_DISPLAY, onChange, onChangeCommitted, id: providedId, dataTest, ariaLabel, ariaLabelledBy, ariaDescribedBy, slots, slotProps } = _a, rest = __rest(_a, ["label", "helperText", "iconStart", "iconEnd", "showMarkTicks", "animate", "valueLabelDisplay", "onChange", "onChangeCommitted", "id", "dataTest", "ariaLabel", "ariaLabelledBy", "ariaDescribedBy", "slots", "slotProps"]);
|
|
25
26
|
const generatedUniqueId = useId();
|
|
26
27
|
const id = providedId !== null && providedId !== void 0 ? providedId : generatedUniqueId;
|
|
27
28
|
const labelId = label ? `${id}-label` : undefined;
|
|
@@ -57,7 +58,7 @@ function Slider(_a) {
|
|
|
57
58
|
React.createElement(Styled.SliderRow, { "$showMarkTicks": showMarkTicks, "$animate": animate, "$isRtl": isRtl },
|
|
58
59
|
iconStart && React.createElement(Styled.IconWrapper, { "aria-hidden": true }, iconStart),
|
|
59
60
|
React.createElement(ThemeProvider, { theme: theme },
|
|
60
|
-
React.createElement(Styled.MaterialSlider, Object.assign({}, rest, { valueLabelDisplay: valueLabelDisplay, onChange: handleChange, onChangeCommitted: handleChangeCommitted, "aria-label": ariaLabel, "aria-labelledby": ariaLabel ? undefined : ariaLabelledBy || labelId, "data-test": dataTest, slotProps: Object.assign(Object.assign({}, slotProps), { input: Object.assign(Object.assign({ id, 'aria-describedby': ariaDescribedBy || helperTextId }, (dataTest ? { 'data-test': `${dataTest}-input` } : {})), (typeof (slotProps === null || slotProps === void 0 ? void 0 : slotProps.input) === 'object' ? slotProps.input : {})) }) }))),
|
|
61
|
+
React.createElement(Styled.MaterialSlider, Object.assign({}, rest, { valueLabelDisplay: valueLabelDisplay, onChange: handleChange, onChangeCommitted: handleChangeCommitted, "aria-label": ariaLabel, "aria-labelledby": ariaLabel ? undefined : ariaLabelledBy || labelId, "data-test": dataTest, slots: Object.assign({ valueLabel: DismissibleValueLabel }, slots), slotProps: Object.assign(Object.assign({}, slotProps), { input: Object.assign(Object.assign({ id, 'aria-describedby': ariaDescribedBy || helperTextId }, (dataTest ? { 'data-test': `${dataTest}-input` } : {})), (typeof (slotProps === null || slotProps === void 0 ? void 0 : slotProps.input) === 'object' ? slotProps.input : {})) }) }))),
|
|
61
62
|
iconEnd && React.createElement(Styled.IconWrapper, { "aria-hidden": true }, iconEnd))));
|
|
62
63
|
}
|
|
63
64
|
export default Slider;
|
|
@@ -0,0 +1,36 @@
|
|
|
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, useState } from 'react';
|
|
13
|
+
import { SliderValueLabel } from '@mui/material';
|
|
14
|
+
import { VALUE_LABEL_DISPLAYS } from './constants';
|
|
15
|
+
// WCAG 1.4.13 requires a tooltip to be dismissible without moving the pointer or focus, and
|
|
16
|
+
// MUI keeps the label's open state internal with no Escape handling. A label that is always
|
|
17
|
+
// shown ('on') is not hover content, so it stays.
|
|
18
|
+
function DismissibleValueLabel(_a) {
|
|
19
|
+
var { open } = _a, props = __rest(_a, ["open"]);
|
|
20
|
+
const [dismissed, setDismissed] = useState(false);
|
|
21
|
+
const dismissible = open && props.valueLabelDisplay !== VALUE_LABEL_DISPLAYS.ON;
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!dismissible) {
|
|
24
|
+
setDismissed(false);
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
const onKeyDown = (event) => {
|
|
28
|
+
if (event.key === 'Escape')
|
|
29
|
+
setDismissed(true);
|
|
30
|
+
};
|
|
31
|
+
document.addEventListener('keydown', onKeyDown, true);
|
|
32
|
+
return () => document.removeEventListener('keydown', onKeyDown, true);
|
|
33
|
+
}, [dismissible]);
|
|
34
|
+
return React.createElement(SliderValueLabel, Object.assign({}, props, { open: open && !dismissed }));
|
|
35
|
+
}
|
|
36
|
+
export default DismissibleValueLabel;
|
|
@@ -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';
|