@grucloud/bau-ui 0.300.0 → 0.302.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/accordion/accordion.js +36 -63
- package/alert/alert.js +14 -24
- package/alertStack/README.md +89 -0
- package/alertStack/alertStack.js +98 -28
- package/animate/animate.js +2 -0
- package/autocomplete/autocomplete.js +130 -164
- package/avatar/avatar.js +20 -25
- package/breadcrumbs/breadcrumbs.js +34 -30
- package/button/button.js +27 -41
- package/buttonGroup/buttonGroup.js +20 -27
- package/calendar/calendar.js +6 -12
- package/carousel/carousel.js +64 -47
- package/checkbox/checkbox.js +10 -13
- package/chip/chip.js +9 -0
- package/collapsible/collapsible.js +73 -47
- package/collapsible/index.d.ts +12 -1
- package/constants.d.ts +1 -0
- package/constants.js +4 -0
- package/divider/divider.js +1 -0
- package/drawer/drawer.js +48 -1
- package/drillDownMenu/drillDownMenu.js +90 -67
- package/dropdownMenu/dropdownMenu.js +29 -122
- package/fileInput/fileInput.js +4 -0
- package/globalStyle/globalStyle.js +75 -30
- package/input/input.js +35 -44
- package/inputSearch/inputSearch.js +26 -31
- package/lazy/lazy.js +8 -5
- package/linearProgress/linearProgress.js +12 -24
- package/list/list.js +2 -1
- package/loadingButton/loadingButton.js +29 -22
- package/modal/modal.js +38 -41
- package/multiSelect/multiSelect.js +84 -171
- package/package.json +13 -5
- package/paginationNavigation/paginationNavigation.js +8 -13
- package/popover/popover.js +5 -2
- package/radioButton/radioButton.js +10 -23
- package/radioButtonGroup/radioButtonGroup.js +15 -24
- package/resizable/resizable.js +74 -70
- package/select/select.js +84 -160
- package/selectNative/selectNative.js +2 -0
- package/slider/slider.js +6 -12
- package/spinner/spinner.js +37 -53
- package/stepper/stepper.js +23 -35
- package/switch/switch.js +28 -45
- package/tableOfContent/tableOfContent.js +55 -84
- package/tablePagination/tablePagination.js +39 -69
- package/tabs/tabs.js +95 -59
- package/textareaAutosize/textareaAutosize.js +13 -16
- package/themeSwitch/themeSwitch.js +27 -41
- package/toggle/index.d.ts +8 -1
- package/toggle/toggle.js +17 -9
- package/toggleGroup/toggleGroup.js +23 -28
- package/tooltip/tooltip.js +79 -94
- package/treeView/treeView.js +57 -25
- package/utils/control.js +20 -0
- package/utils/popupList.js +137 -0
- package/utils/urlChange.js +32 -0
- package/vite.config.js +48 -0
|
@@ -1,30 +1,5 @@
|
|
|
1
1
|
import { toPropsAndChildren } from "@grucloud/bau/bau.js";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
const colorsToCss = () =>
|
|
5
|
-
Colors.map(
|
|
6
|
-
(color) =>
|
|
7
|
-
`
|
|
8
|
-
&.button-group.${color} {
|
|
9
|
-
& .button:not(:last-child) {
|
|
10
|
-
border-right: 1px solid var(--color-${color}) !important;
|
|
11
|
-
}
|
|
12
|
-
& .button:not(:first-child) {
|
|
13
|
-
border-left: 1px solid var(--color-${color}) !important;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
&.button-group.outline.${color} {
|
|
18
|
-
border: none;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
&.button-group.solid.${color} {
|
|
22
|
-
& .button:not(:last-child) {
|
|
23
|
-
border-right: 1px solid var(--color-${color}-lightest) !important;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
`
|
|
27
|
-
).join("\n");
|
|
2
|
+
import { ofColor } from "../constants.js";
|
|
28
3
|
|
|
29
4
|
export default function (context, options = {}) {
|
|
30
5
|
const { bau, css } = context;
|
|
@@ -42,7 +17,24 @@ export default function (context, options = {}) {
|
|
|
42
17
|
border-top-left-radius: 0;
|
|
43
18
|
border-bottom-left-radius: 0;
|
|
44
19
|
}
|
|
45
|
-
${
|
|
20
|
+
&.button-group${ofColor} {
|
|
21
|
+
& .button:not(:last-child) {
|
|
22
|
+
border-right: 1px solid var(--accent-text) !important;
|
|
23
|
+
}
|
|
24
|
+
& .button:not(:first-child) {
|
|
25
|
+
border-left: 1px solid var(--accent-text) !important;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&.button-group.outline${ofColor} {
|
|
30
|
+
border: none;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&.button-group.solid${ofColor} {
|
|
34
|
+
& .button:not(:last-child) {
|
|
35
|
+
border-right: 1px solid var(--accent-lightest) !important;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
46
38
|
`;
|
|
47
39
|
|
|
48
40
|
return function ButtonGroup(...args) {
|
|
@@ -58,6 +50,7 @@ export default function (context, options = {}) {
|
|
|
58
50
|
|
|
59
51
|
return div(
|
|
60
52
|
{
|
|
53
|
+
role: "group",
|
|
61
54
|
...props,
|
|
62
55
|
class: [
|
|
63
56
|
"button-group",
|
package/calendar/calendar.js
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
import { toPropsAndChildren } from "@grucloud/bau/bau.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ofColor } from "../constants.js";
|
|
3
3
|
|
|
4
4
|
export default function (context, options = {}) {
|
|
5
5
|
const { bau, css } = context;
|
|
6
6
|
const { input } = bau.tags;
|
|
7
7
|
|
|
8
|
-
const colorsToCss = () =>
|
|
9
|
-
Colors.map(
|
|
10
|
-
(color) =>
|
|
11
|
-
`
|
|
12
|
-
&.calendar.${color} {
|
|
13
|
-
accent-color: var(--color-${color});
|
|
14
|
-
}
|
|
15
|
-
`
|
|
16
|
-
).join("\n");
|
|
17
|
-
|
|
18
8
|
const className = css`
|
|
19
9
|
padding: 0.3rem;
|
|
20
10
|
border-radius: var(--global-radius);
|
|
21
11
|
border: none;
|
|
22
|
-
|
|
12
|
+
/* WCAG 2.5.8, the size of a target */
|
|
13
|
+
min-height: 24px;
|
|
14
|
+
&.calendar${ofColor} {
|
|
15
|
+
accent-color: var(--accent);
|
|
16
|
+
}
|
|
23
17
|
&:hover {
|
|
24
18
|
filter: brightness(var(--brightness-hover));
|
|
25
19
|
}
|
package/carousel/carousel.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { controlIn, onkeydownButton } from "../utils/control.js";
|
|
2
2
|
|
|
3
3
|
export default function (context, options = {}) {
|
|
4
4
|
const { bau, css } = context;
|
|
@@ -15,14 +15,10 @@ export default function (context, options = {}) {
|
|
|
15
15
|
position: absolute;
|
|
16
16
|
padding: 0.5rem;
|
|
17
17
|
cursor: pointer;
|
|
18
|
-
}
|
|
19
|
-
& .control-previous {
|
|
20
18
|
top: 50%;
|
|
21
19
|
transform: translateY(-50%);
|
|
22
20
|
}
|
|
23
21
|
& .control-next {
|
|
24
|
-
top: 50%;
|
|
25
|
-
transform: translateY(-50%);
|
|
26
22
|
right: 0;
|
|
27
23
|
}
|
|
28
24
|
& .track {
|
|
@@ -32,36 +28,44 @@ export default function (context, options = {}) {
|
|
|
32
28
|
}
|
|
33
29
|
`;
|
|
34
30
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
// A control the user gives, Previous or Next: its button is named, or the
|
|
32
|
+
// control is the button
|
|
33
|
+
const Control = ({ className, label, onclick, content }) => {
|
|
34
|
+
const control = controlIn(content);
|
|
35
|
+
if (control && !control.hasAttribute("aria-label")) {
|
|
36
|
+
control.setAttribute("aria-label", label);
|
|
37
|
+
}
|
|
38
|
+
return div(
|
|
39
39
|
{
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
class: ["control", className],
|
|
41
|
+
onclick,
|
|
42
|
+
...(!control && {
|
|
43
|
+
role: "button",
|
|
44
|
+
tabindex: "0",
|
|
45
|
+
"aria-label": label,
|
|
46
|
+
onkeydown: onkeydownButton(onclick),
|
|
47
|
+
}),
|
|
48
48
|
},
|
|
49
|
-
|
|
49
|
+
content
|
|
50
|
+
);
|
|
51
|
+
};
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
return function Carousel({
|
|
54
|
+
size = options.size ?? "md",
|
|
55
|
+
variant = options.variant ?? "plain",
|
|
56
|
+
color = options.color ?? "neutral",
|
|
57
|
+
slides,
|
|
58
|
+
Slide,
|
|
59
|
+
Previous,
|
|
60
|
+
Next,
|
|
61
|
+
...props
|
|
62
|
+
}) {
|
|
63
|
+
// The slide shown, of this carousel
|
|
64
|
+
const slideIndex = bau.state(0);
|
|
58
65
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
} else {
|
|
63
|
-
slideIndex.val++;
|
|
64
|
-
}
|
|
66
|
+
// To the slide before or after, from one end to the other
|
|
67
|
+
const move = (step) => () => {
|
|
68
|
+
slideIndex.val = (slideIndex.val + step + slides.length) % slides.length;
|
|
65
69
|
};
|
|
66
70
|
|
|
67
71
|
const trackEl = div(
|
|
@@ -69,29 +73,42 @@ export default function (context, options = {}) {
|
|
|
69
73
|
class: "track",
|
|
70
74
|
style: () => `transform: translateX(${-100 * slideIndex.val}%);`,
|
|
71
75
|
},
|
|
72
|
-
slides.map(
|
|
76
|
+
slides.map((slide, index) => {
|
|
77
|
+
const slideEl = Slide(slide, index);
|
|
78
|
+
slideEl.setAttribute("role", "group");
|
|
79
|
+
slideEl.setAttribute("aria-roledescription", "slide");
|
|
80
|
+
slideEl.setAttribute("aria-label", `${index + 1} of ${slides.length}`);
|
|
81
|
+
return slideEl;
|
|
82
|
+
})
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// The slides out of view: out of the Tab order and of the readers
|
|
86
|
+
bau.derive(() =>
|
|
87
|
+
[...trackEl.children].forEach(
|
|
88
|
+
(slideEl, index) => (slideEl.inert = index != slideIndex.val)
|
|
89
|
+
)
|
|
73
90
|
);
|
|
74
91
|
|
|
75
92
|
return div(
|
|
76
93
|
{
|
|
94
|
+
role: "region",
|
|
95
|
+
"aria-roledescription": "carousel",
|
|
96
|
+
"aria-label": "Carousel",
|
|
77
97
|
...props,
|
|
78
98
|
class: ["carousel", size, className, options?.class, props?.class],
|
|
79
99
|
},
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
},
|
|
93
|
-
Next()
|
|
94
|
-
),
|
|
100
|
+
Control({
|
|
101
|
+
className: "control-previous",
|
|
102
|
+
label: "Previous slide",
|
|
103
|
+
onclick: move(-1),
|
|
104
|
+
content: Previous(),
|
|
105
|
+
}),
|
|
106
|
+
Control({
|
|
107
|
+
className: "control-next",
|
|
108
|
+
label: "Next slide",
|
|
109
|
+
onclick: move(1),
|
|
110
|
+
content: Next(),
|
|
111
|
+
}),
|
|
95
112
|
trackEl
|
|
96
113
|
);
|
|
97
114
|
};
|
package/checkbox/checkbox.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { toPropsAndChildren } from "@grucloud/bau/bau.js";
|
|
2
|
-
|
|
3
1
|
export default function (context, options = {}) {
|
|
4
2
|
const { bau, css } = context;
|
|
5
3
|
const { input } = bau.tags;
|
|
@@ -14,6 +12,10 @@ export default function (context, options = {}) {
|
|
|
14
12
|
transition: all var(--transition-fast) ease-in-out;
|
|
15
13
|
box-shadow: var(--shadow-s);
|
|
16
14
|
position: relative;
|
|
15
|
+
&:focus-visible {
|
|
16
|
+
outline: 2px solid var(--color-primary);
|
|
17
|
+
outline-offset: 2px;
|
|
18
|
+
}
|
|
17
19
|
&:hover {
|
|
18
20
|
transform: scale(1.05);
|
|
19
21
|
filter: brightness(var(--brightness-hover));
|
|
@@ -64,17 +66,12 @@ export default function (context, options = {}) {
|
|
|
64
66
|
}
|
|
65
67
|
`;
|
|
66
68
|
|
|
67
|
-
return function Checkbox(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
...props
|
|
74
|
-
},
|
|
75
|
-
children,
|
|
76
|
-
] = toPropsAndChildren(args);
|
|
77
|
-
|
|
69
|
+
return function Checkbox({
|
|
70
|
+
size = options.size ?? "md",
|
|
71
|
+
variant = options.variant ?? "plain",
|
|
72
|
+
color = options.color ?? "neutral",
|
|
73
|
+
...props
|
|
74
|
+
} = {}) {
|
|
78
75
|
return input({
|
|
79
76
|
type: "checkbox",
|
|
80
77
|
...props,
|
package/chip/chip.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { toPropsAndChildren } from "@grucloud/bau/bau.js";
|
|
2
|
+
import { onkeydownButton } from "../utils/control.js";
|
|
2
3
|
|
|
3
4
|
export default function (context, options = {}) {
|
|
4
5
|
const { bau, css } = context;
|
|
@@ -16,6 +17,8 @@ export default function (context, options = {}) {
|
|
|
16
17
|
white-space: nowrap;
|
|
17
18
|
&.clickable {
|
|
18
19
|
cursor: pointer;
|
|
20
|
+
/* A target of 24px at least, WCAG 2.5.8 */
|
|
21
|
+
min-height: 24px;
|
|
19
22
|
}
|
|
20
23
|
&.sm {
|
|
21
24
|
padding: 0rem 0.4rem;
|
|
@@ -42,6 +45,12 @@ export default function (context, options = {}) {
|
|
|
42
45
|
|
|
43
46
|
return span(
|
|
44
47
|
{
|
|
48
|
+
// Clickable: focused with Tab, pressed with Enter or Space
|
|
49
|
+
...(onclick && {
|
|
50
|
+
role: "button",
|
|
51
|
+
tabindex: "0",
|
|
52
|
+
onkeydown: onkeydownButton((event) => event.currentTarget.click()),
|
|
53
|
+
}),
|
|
45
54
|
...props,
|
|
46
55
|
onclick,
|
|
47
56
|
class: [
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { controlIn, onkeydownButton } from "../utils/control.js";
|
|
2
|
+
|
|
3
|
+
// The ids of the contents, for aria-controls
|
|
4
|
+
let contentCount = 0;
|
|
2
5
|
|
|
3
6
|
export default function (context, options = {}) {
|
|
4
7
|
const { bau, css } = context;
|
|
@@ -17,13 +20,11 @@ export default function (context, options = {}) {
|
|
|
17
20
|
transition: transform var(--transition-fast) linear;
|
|
18
21
|
line-height: 1rem;
|
|
19
22
|
}
|
|
20
|
-
&.close::before
|
|
23
|
+
&.close::before,
|
|
24
|
+
&.open::before {
|
|
21
25
|
content: "\u203A";
|
|
22
|
-
padding: 0.5rem;
|
|
23
26
|
}
|
|
24
27
|
&.open::before {
|
|
25
|
-
content: "\u203A";
|
|
26
|
-
padding: 0.5rem;
|
|
27
28
|
transform: rotate(90deg);
|
|
28
29
|
}
|
|
29
30
|
}
|
|
@@ -31,49 +32,70 @@ export default function (context, options = {}) {
|
|
|
31
32
|
background-color: inherit;
|
|
32
33
|
will-change: height;
|
|
33
34
|
transition: height var(--transition-fast) ease-out;
|
|
34
|
-
|
|
35
|
+
/* Clipped while it opens or closes: not a scroll area, which the
|
|
36
|
+
keyboard would stop on */
|
|
37
|
+
overflow: hidden;
|
|
35
38
|
}
|
|
36
39
|
`;
|
|
37
40
|
|
|
38
|
-
|
|
41
|
+
// The height animated: closing, from the height of the content to 0;
|
|
42
|
+
// opening, up to it, then free for the content to change
|
|
43
|
+
const collapseOrExpandSection = ({ element, open }) => {
|
|
39
44
|
if (element.scrollHeight == 0) return;
|
|
40
|
-
closeState.val ? collapseSection(element) : expandSection(element);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
function collapseSection(element) {
|
|
44
45
|
element.style.height = element.scrollHeight + "px";
|
|
45
|
-
|
|
46
|
-
element.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
46
|
+
if (open) {
|
|
47
|
+
element.addEventListener(
|
|
48
|
+
"transitionend",
|
|
49
|
+
() => (element.style.height = null),
|
|
50
|
+
{ once: true }
|
|
51
|
+
);
|
|
52
|
+
} else {
|
|
53
|
+
window.requestAnimationFrame(() => (element.style.height = "0px"));
|
|
54
|
+
}
|
|
55
|
+
};
|
|
53
56
|
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
return function Collapsible({
|
|
58
|
+
size = options.size ?? "md",
|
|
59
|
+
variant = options.variant ?? "plain",
|
|
60
|
+
color = options.color ?? "neutral",
|
|
61
|
+
Header,
|
|
62
|
+
Content,
|
|
63
|
+
expanded = false,
|
|
64
|
+
// Open or closed: a state of the caller, like an accordion, or its own
|
|
65
|
+
openState = bau.state(expanded),
|
|
66
|
+
onToggle,
|
|
67
|
+
...props
|
|
68
|
+
}) {
|
|
69
|
+
const contentId = `collapsible-content-${++contentCount}`;
|
|
70
|
+
const toggle = () => {
|
|
71
|
+
openState.val = !openState.val;
|
|
72
|
+
onToggle?.({ open: openState.val });
|
|
58
73
|
};
|
|
59
|
-
element.addEventListener("transitionend", animationEndHandler);
|
|
60
|
-
element.style.height = element.scrollHeight + "px";
|
|
61
|
-
}
|
|
62
74
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
// The keyboard reaches the header through its control, a button or a
|
|
76
|
+
// link, which tells whether the content is shown. A header without one,
|
|
77
|
+
// a text, is the button itself. A button first: a header with a link and
|
|
78
|
+
// a button to expand, like a menu.
|
|
79
|
+
const headerContent = Header();
|
|
80
|
+
const control =
|
|
81
|
+
Content &&
|
|
82
|
+
(controlIn(headerContent, "button") ??
|
|
83
|
+
controlIn(headerContent, "button, a[href]"));
|
|
84
|
+
if (control) {
|
|
85
|
+
control.setAttribute("aria-controls", contentId);
|
|
86
|
+
bau.derive(() =>
|
|
87
|
+
control.setAttribute("aria-expanded", String(openState.val))
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
const headerButtonProps = Content &&
|
|
91
|
+
!control && {
|
|
92
|
+
role: "button",
|
|
93
|
+
tabindex: "0",
|
|
94
|
+
"aria-controls": contentId,
|
|
95
|
+
"aria-expanded": () => String(openState.val),
|
|
96
|
+
onkeydown: onkeydownButton(toggle),
|
|
97
|
+
};
|
|
75
98
|
|
|
76
|
-
const closeState = bau.state(!expanded);
|
|
77
99
|
return div(
|
|
78
100
|
{
|
|
79
101
|
...props,
|
|
@@ -81,27 +103,31 @@ export default function (context, options = {}) {
|
|
|
81
103
|
},
|
|
82
104
|
div(
|
|
83
105
|
{
|
|
106
|
+
...headerButtonProps,
|
|
84
107
|
class: () => [
|
|
85
108
|
"header",
|
|
86
|
-
Content ? (
|
|
109
|
+
Content ? (openState.val ? "open" : "close") : "",
|
|
87
110
|
],
|
|
88
111
|
onclick: (event) => {
|
|
89
|
-
|
|
112
|
+
toggle();
|
|
113
|
+
// A collapsible in a collapsible: only the one clicked
|
|
90
114
|
event.stopPropagation();
|
|
91
115
|
},
|
|
92
116
|
},
|
|
93
|
-
|
|
117
|
+
headerContent
|
|
94
118
|
),
|
|
95
119
|
div(
|
|
96
120
|
{
|
|
121
|
+
id: contentId,
|
|
97
122
|
class: "content",
|
|
98
|
-
|
|
123
|
+
// Closed: out of the Tab order and of the screen readers
|
|
124
|
+
inert: () => !openState.val,
|
|
99
125
|
bauMounted: ({ element }) => {
|
|
100
|
-
|
|
126
|
+
!openState.val && (element.style.height = "0px");
|
|
101
127
|
},
|
|
102
|
-
"
|
|
103
|
-
collapseOrExpandSection({ element,
|
|
104
|
-
return
|
|
128
|
+
"data-open": ({ element }) => {
|
|
129
|
+
collapseOrExpandSection({ element, open: openState.val });
|
|
130
|
+
return openState.val;
|
|
105
131
|
},
|
|
106
132
|
},
|
|
107
133
|
Content && Content()
|
package/collapsible/index.d.ts
CHANGED
|
@@ -2,7 +2,18 @@ declare module "@grucloud/bau-ui/collapsible" {
|
|
|
2
2
|
type DefaultDesignProps = import("../constants").DefaultDesignProps;
|
|
3
3
|
type ComponentOption = import("../bau-ui").ComponentOption;
|
|
4
4
|
|
|
5
|
-
export type CollapsibleProps = {
|
|
5
|
+
export type CollapsibleProps = {
|
|
6
|
+
// The header, always shown: a button in it, or the header itself, opens
|
|
7
|
+
// and closes the content
|
|
8
|
+
Header: () => import("@grucloud/bau").ChildDom;
|
|
9
|
+
Content?: () => import("@grucloud/bau").ChildDom;
|
|
10
|
+
// Open at first
|
|
11
|
+
expanded?: boolean;
|
|
12
|
+
// Open or closed, a state of the caller
|
|
13
|
+
openState?: import("@grucloud/bau").State<boolean>;
|
|
14
|
+
// Called when the user opens or closes it
|
|
15
|
+
onToggle?: (input: { open: boolean }) => void;
|
|
16
|
+
} & DefaultDesignProps;
|
|
6
17
|
|
|
7
18
|
type Component = import("../bau-ui").Component<CollapsibleProps>;
|
|
8
19
|
|
package/constants.d.ts
CHANGED
package/constants.js
CHANGED
|
@@ -8,3 +8,7 @@ export const Colors = [
|
|
|
8
8
|
];
|
|
9
9
|
export const Variants = ["plain", "outline", "solid"];
|
|
10
10
|
export const Sizes = ["sm", "md", "lg"];
|
|
11
|
+
|
|
12
|
+
// The elements of a color: their rules use its shades, --accent and the
|
|
13
|
+
// others, set by the global style
|
|
14
|
+
export const ofColor = `:is(${Colors.map((color) => `.${color}`).join(", ")})`;
|
package/divider/divider.js
CHANGED
package/drawer/drawer.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { toPropsAndChildren } from "@grucloud/bau/bau.js";
|
|
2
|
+
import { focusable } from "../utils/control.js";
|
|
2
3
|
|
|
3
4
|
export default function (context, options) {
|
|
4
5
|
const { bau, css } = context;
|
|
@@ -50,8 +51,47 @@ export default function (context, options) {
|
|
|
50
51
|
return function Drawer(...args) {
|
|
51
52
|
let [{ color, variant = "outline", size, openState, ...props }, children] =
|
|
52
53
|
toPropsAndChildren(args);
|
|
54
|
+
// The element focused when the drawer opened, focused again when it
|
|
55
|
+
// closes
|
|
56
|
+
let openerEl;
|
|
57
|
+
const onOpenChange = (element, open) => {
|
|
58
|
+
if (open) {
|
|
59
|
+
openerEl = document.activeElement;
|
|
60
|
+
requestAnimationFrame(() => element.querySelector(focusable)?.focus());
|
|
61
|
+
} else if (element.contains(document.activeElement)) {
|
|
62
|
+
openerEl?.focus();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// Open, Tab goes round the content: from the last element to the first,
|
|
67
|
+
// with Shift from the first to the last. The page under the overlay is out
|
|
68
|
+
// of reach.
|
|
69
|
+
const keepFocusIn = (event) => {
|
|
70
|
+
const elements = [
|
|
71
|
+
...event.currentTarget
|
|
72
|
+
.querySelector(".content")
|
|
73
|
+
.querySelectorAll(focusable),
|
|
74
|
+
].filter((element) => !element.disabled);
|
|
75
|
+
const [first, last] = [elements[0], elements.at(-1)];
|
|
76
|
+
const [from, to] = event.shiftKey ? [first, last] : [last, first];
|
|
77
|
+
if (document.activeElement == from) {
|
|
78
|
+
event.preventDefault();
|
|
79
|
+
to.focus();
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
53
83
|
return div(
|
|
54
|
-
{
|
|
84
|
+
{
|
|
85
|
+
class: [className, options?.class, props.class],
|
|
86
|
+
// Closed, the drawer is inert: the keys come from it open
|
|
87
|
+
onkeydown: (event) => {
|
|
88
|
+
if (event.key == "Escape") {
|
|
89
|
+
openState.val = false;
|
|
90
|
+
} else if (event.key == "Tab") {
|
|
91
|
+
keepFocusIn(event);
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
},
|
|
55
95
|
// Overlay
|
|
56
96
|
div({
|
|
57
97
|
class: () => ["overlay", openState.val && "overlay-open"],
|
|
@@ -62,7 +102,14 @@ export default function (context, options) {
|
|
|
62
102
|
// Content
|
|
63
103
|
div(
|
|
64
104
|
{
|
|
105
|
+
...props,
|
|
65
106
|
class: () => ["content", openState.val && "content-open"],
|
|
107
|
+
// Closed: out of the screen, of the Tab order and of the readers
|
|
108
|
+
inert: ({ element }) => {
|
|
109
|
+
const open = openState.val;
|
|
110
|
+
onOpenChange(element, open);
|
|
111
|
+
return !open;
|
|
112
|
+
},
|
|
66
113
|
},
|
|
67
114
|
children
|
|
68
115
|
)
|