@bigbluebutton/bbb-ui-components-react 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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/Slider.js +8 -8
- package/dist/components/Toast.js +47 -44
- package/dist/components/Toggle.js +18 -18
- package/dist/components/index.js +285 -259
- 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/Toggle/component.js +87 -16
- package/dist/esm/components/Toggle/constants.js +8 -0
- package/dist/esm/components/Toggle/styles.js +19 -4
- package/dist/esm/utils/tooltip.js +20 -0
- package/dist/types/components/Accordion/constants.d.ts +1 -1
- package/dist/types/components/Button/constants.d.ts +12 -5
- 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/styles.d.ts +1 -1
- package/dist/types/components/Slider/valueLabel.d.ts +7 -0
- package/dist/types/components/Toggle/component.d.ts +2 -1
- package/dist/types/components/Toggle/constants.d.ts +10 -2
- package/dist/types/components/Toggle/styles.d.ts +3 -3
- package/dist/types/components/Toggle/types.d.ts +11 -1
- package/dist/types/utils/tooltip.d.ts +3 -0
- package/package.json +1 -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;
|
|
@@ -9,9 +9,29 @@ 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, { useEffect, useId, useRef, useState, } from 'react';
|
|
13
|
+
import { switchClasses } from '@mui/material';
|
|
13
14
|
import * as Styled from './styles';
|
|
14
|
-
import { DEFAULT_TEXT_POSITION, TEXT_POSITIONS } from './constants';
|
|
15
|
+
import { DEFAULT_TEXT_POSITION, DEFAULT_TOOLTIP_PLACEMENT, TEXT_POSITIONS } from './constants';
|
|
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 switch unchanged, and MUI skips
|
|
20
|
+
// `onChange` for a prevented click. It sits on the switch because MUI drops event handlers
|
|
21
|
+
// passed through `slotProps.input`, except `onChange`.
|
|
22
|
+
const preventToggle = (event) => event.preventDefault();
|
|
23
|
+
// Bridges the gap between the text and the switch, which are separate tooltip triggers,
|
|
24
|
+
// so moving the pointer from one to the other doesn't hide and reshow the tooltip.
|
|
25
|
+
const TOOLTIP_DELAY = [0, 100];
|
|
26
|
+
const isElement = (element) => element !== null;
|
|
27
|
+
const getBoundingRect = (elements) => {
|
|
28
|
+
const rects = elements.map((element) => element.getBoundingClientRect());
|
|
29
|
+
const left = Math.min(...rects.map((rect) => rect.left));
|
|
30
|
+
const top = Math.min(...rects.map((rect) => rect.top));
|
|
31
|
+
const right = Math.max(...rects.map((rect) => rect.right));
|
|
32
|
+
const bottom = Math.max(...rects.map((rect) => rect.bottom));
|
|
33
|
+
return new DOMRect(left, top, right - left, bottom - top);
|
|
34
|
+
};
|
|
15
35
|
/**
|
|
16
36
|
* A customizable Toggle switch component.
|
|
17
37
|
*
|
|
@@ -20,31 +40,82 @@ import { DEFAULT_TEXT_POSITION, TEXT_POSITIONS } from './constants';
|
|
|
20
40
|
*
|
|
21
41
|
*/
|
|
22
42
|
function Toggle(_a) {
|
|
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"]);
|
|
43
|
+
var { label, helperText, textPosition = DEFAULT_TEXT_POSITION, fullWidth = false, disabled, onChange, ariaLabel, ariaLabelledBy, ariaDescribedBy, id: providedId, slotProps, tooltipLabel, tooltipPlacement = DEFAULT_TOOLTIP_PLACEMENT } = _a, rest = __rest(_a, ["label", "helperText", "textPosition", "fullWidth", "disabled", "onChange", "ariaLabel", "ariaLabelledBy", "ariaDescribedBy", "id", "slotProps", "tooltipLabel", "tooltipPlacement"]);
|
|
24
44
|
const generatedUniqueId = useId();
|
|
45
|
+
const titleRef = useRef(null);
|
|
46
|
+
const helperTextRef = useRef(null);
|
|
47
|
+
const switchWrapperRef = useRef(null);
|
|
48
|
+
const wrapperRef = useRef(null);
|
|
49
|
+
const [tooltipTriggers, setTooltipTriggers] = useState([]);
|
|
50
|
+
// MUI's Switch ref points at its inner button, which a disabled switch hides from the
|
|
51
|
+
// pointer; the root, which holds the track, is looked up instead.
|
|
52
|
+
const getSwitchRoot = () => {
|
|
53
|
+
var _a, _b;
|
|
54
|
+
return ((_b = (_a = switchWrapperRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(`.${switchClasses.root}`)) !== null && _b !== void 0 ? _b : null);
|
|
55
|
+
};
|
|
56
|
+
// The wrapper spans the whole row, so it can't be the tooltip's trigger or anchor: the
|
|
57
|
+
// tooltip would open over empty space and center on the row. The text and the switch
|
|
58
|
+
// trigger it instead, and it points at the text, or at the switch when there is none.
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (!tooltipLabel)
|
|
61
|
+
return;
|
|
62
|
+
setTooltipTriggers([titleRef.current, helperTextRef.current, getSwitchRoot()].filter(isElement));
|
|
63
|
+
}, [tooltipLabel, label, helperText]);
|
|
64
|
+
const getTooltipAnchorRect = () => {
|
|
65
|
+
const textElements = [titleRef.current, helperTextRef.current].filter(isElement);
|
|
66
|
+
const anchorElements = textElements.length > 0 ? textElements : [getSwitchRoot()].filter(isElement);
|
|
67
|
+
return anchorElements.length > 0 ? getBoundingRect(anchorElements) : new DOMRect();
|
|
68
|
+
};
|
|
25
69
|
const id = providedId !== null && providedId !== void 0 ? providedId : generatedUniqueId;
|
|
26
70
|
const labelId = label ? `${id}-label` : undefined;
|
|
27
71
|
const helperTextId = helperText ? `${id}-helper` : undefined;
|
|
72
|
+
const tooltipDescriptionId = tooltipLabel ? `${id}-tooltip` : undefined;
|
|
28
73
|
const isFullWidth = fullWidth && (textPosition === TEXT_POSITIONS.LEFT || textPosition === TEXT_POSITIONS.RIGHT);
|
|
29
|
-
const
|
|
74
|
+
const explicitLabelledBy = ariaLabel ? undefined : ariaLabelledBy || labelId;
|
|
30
75
|
// Without a name source, the <label htmlFor> names the input from the helper text,
|
|
31
|
-
// so it can't also be the description.
|
|
32
|
-
|
|
76
|
+
// so it can't also be the description. The tooltip text follows the same rule when
|
|
77
|
+
// neither a label nor the helper text names the toggle.
|
|
78
|
+
const hasNameSource = !!ariaLabel || !!explicitLabelledBy;
|
|
79
|
+
const tooltipNamesToggle = Boolean(tooltipLabel && !hasNameSource && !helperText);
|
|
33
80
|
const a11yInputProps = {
|
|
34
81
|
role: 'switch',
|
|
35
82
|
'aria-label': ariaLabel,
|
|
36
|
-
'aria-labelledby':
|
|
37
|
-
'aria-describedby':
|
|
83
|
+
'aria-labelledby': tooltipNamesToggle ? tooltipDescriptionId : explicitLabelledBy,
|
|
84
|
+
'aria-describedby': [
|
|
85
|
+
ariaDescribedBy || (hasNameSource ? helperTextId : undefined),
|
|
86
|
+
!tooltipNamesToggle && tooltipDescriptionId,
|
|
87
|
+
].filter(Boolean).join(' ') || undefined,
|
|
38
88
|
};
|
|
89
|
+
// A natively disabled input leaves the tab order, so keyboard users could never reach the
|
|
90
|
+
// tooltip that explains why it is disabled. With a tooltip, the input stays focusable and is
|
|
91
|
+
// announced through aria-disabled instead; dropping `name` and `required` keeps it out of form
|
|
92
|
+
// submission and validation, as a natively disabled input would be.
|
|
93
|
+
const focusableWhileDisabled = Boolean(disabled && tooltipLabel);
|
|
94
|
+
const focusableDisabledInputProps = focusableWhileDisabled
|
|
95
|
+
? {
|
|
96
|
+
disabled: false,
|
|
97
|
+
'aria-disabled': true,
|
|
98
|
+
name: undefined,
|
|
99
|
+
required: false,
|
|
100
|
+
}
|
|
101
|
+
: {};
|
|
39
102
|
const _b = slotProps !== null && slotProps !== void 0 ? slotProps : {}, { input: consumerInputSlotProps } = _b, otherSlotProps = __rest(_b, ["input"]);
|
|
40
103
|
const inputSlotProps = typeof consumerInputSlotProps === 'function'
|
|
41
|
-
? (ownerState) => (Object.assign(Object.assign({}, a11yInputProps), consumerInputSlotProps(ownerState)))
|
|
42
|
-
: Object.assign(Object.assign({}, a11yInputProps), consumerInputSlotProps);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
104
|
+
? (ownerState) => (Object.assign(Object.assign(Object.assign({}, a11yInputProps), consumerInputSlotProps(ownerState)), focusableDisabledInputProps))
|
|
105
|
+
: Object.assign(Object.assign(Object.assign({}, a11yInputProps), consumerInputSlotProps), focusableDisabledInputProps);
|
|
106
|
+
// Tippy sits beside the wrapper instead of wrapping it, so toggling `tooltipLabel` keeps
|
|
107
|
+
// the same root and doesn't remount the toggle (losing focus and uncontrolled state).
|
|
108
|
+
// The switch root, not the input, triggers it: MUI gives the disabled switch's input
|
|
109
|
+
// `pointer-events: none`, so hovering it reaches the root. `focusin` bubbles from the
|
|
110
|
+
// input; Tippy's `focus` would not.
|
|
111
|
+
return (React.createElement(React.Fragment, null,
|
|
112
|
+
React.createElement(Styled.ToggleWrapper, { ref: wrapperRef, "$textPosition": textPosition, "$fullWidth": isFullWidth },
|
|
113
|
+
(label || helperText) && (React.createElement(Styled.TextWrapper, { "$textPosition": textPosition, "$fullWidth": isFullWidth, htmlFor: id, "$hasLabel": !!label, "$hasHelperText": !!helperText, "$disabled": disabled },
|
|
114
|
+
label && React.createElement(Styled.Title, { ref: titleRef, id: labelId, "$disabled": disabled }, label),
|
|
115
|
+
helperText && (React.createElement(Styled.HelperText, { ref: helperTextRef, id: helperTextId, "$disabled": disabled }, helperText)))),
|
|
116
|
+
React.createElement(Styled.ToggleSwitchWrapper, { ref: switchWrapperRef },
|
|
117
|
+
React.createElement(Styled.MaterialToggle, Object.assign({}, rest, { id: id, disabled: disabled }, (focusableWhileDisabled && { onClick: preventToggle }), { onChange: onChange, slotProps: Object.assign(Object.assign({}, otherSlotProps), { input: inputSlotProps }) }))),
|
|
118
|
+
tooltipLabel && (React.createElement("span", { id: tooltipDescriptionId, hidden: true }, tooltipLabel))),
|
|
119
|
+
tooltipLabel && (React.createElement(Tippy, { reference: wrapperRef, content: tooltipLabel, placement: tooltipPlacement, trigger: "mouseenter focusin", triggerTarget: tooltipTriggers.length > 0 ? tooltipTriggers : null, getReferenceClientRect: getTooltipAnchorRect, delay: TOOLTIP_DELAY, aria: { content: null }, plugins: TOOLTIP_PLUGINS }))));
|
|
49
120
|
}
|
|
50
121
|
export default Toggle;
|
|
@@ -6,3 +6,11 @@ export const TEXT_POSITIONS = {
|
|
|
6
6
|
};
|
|
7
7
|
export const TEXT_POSITIONS_VALUES = Object.values(TEXT_POSITIONS);
|
|
8
8
|
export const DEFAULT_TEXT_POSITION = TEXT_POSITIONS_VALUES[0];
|
|
9
|
+
export const TOOLTIP_PLACEMENTS = {
|
|
10
|
+
TOP: 'top',
|
|
11
|
+
BOTTOM: 'bottom',
|
|
12
|
+
LEFT: 'left',
|
|
13
|
+
RIGHT: 'right',
|
|
14
|
+
};
|
|
15
|
+
export const TOOLTIP_PLACEMENT_VALUES = Object.values(TOOLTIP_PLACEMENTS);
|
|
16
|
+
export const DEFAULT_TOOLTIP_PLACEMENT = TOOLTIP_PLACEMENTS.TOP;
|