@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.
Files changed (58) hide show
  1. package/accordion/accordion.js +36 -63
  2. package/alert/alert.js +14 -24
  3. package/alertStack/README.md +89 -0
  4. package/alertStack/alertStack.js +98 -28
  5. package/animate/animate.js +2 -0
  6. package/autocomplete/autocomplete.js +130 -164
  7. package/avatar/avatar.js +20 -25
  8. package/breadcrumbs/breadcrumbs.js +34 -30
  9. package/button/button.js +27 -41
  10. package/buttonGroup/buttonGroup.js +20 -27
  11. package/calendar/calendar.js +6 -12
  12. package/carousel/carousel.js +64 -47
  13. package/checkbox/checkbox.js +10 -13
  14. package/chip/chip.js +9 -0
  15. package/collapsible/collapsible.js +73 -47
  16. package/collapsible/index.d.ts +12 -1
  17. package/constants.d.ts +1 -0
  18. package/constants.js +4 -0
  19. package/divider/divider.js +1 -0
  20. package/drawer/drawer.js +48 -1
  21. package/drillDownMenu/drillDownMenu.js +90 -67
  22. package/dropdownMenu/dropdownMenu.js +29 -122
  23. package/fileInput/fileInput.js +4 -0
  24. package/globalStyle/globalStyle.js +75 -30
  25. package/input/input.js +35 -44
  26. package/inputSearch/inputSearch.js +26 -31
  27. package/lazy/lazy.js +8 -5
  28. package/linearProgress/linearProgress.js +12 -24
  29. package/list/list.js +2 -1
  30. package/loadingButton/loadingButton.js +29 -22
  31. package/modal/modal.js +38 -41
  32. package/multiSelect/multiSelect.js +84 -171
  33. package/package.json +13 -5
  34. package/paginationNavigation/paginationNavigation.js +8 -13
  35. package/popover/popover.js +5 -2
  36. package/radioButton/radioButton.js +10 -23
  37. package/radioButtonGroup/radioButtonGroup.js +15 -24
  38. package/resizable/resizable.js +74 -70
  39. package/select/select.js +84 -160
  40. package/selectNative/selectNative.js +2 -0
  41. package/slider/slider.js +6 -12
  42. package/spinner/spinner.js +37 -53
  43. package/stepper/stepper.js +23 -35
  44. package/switch/switch.js +28 -45
  45. package/tableOfContent/tableOfContent.js +55 -84
  46. package/tablePagination/tablePagination.js +39 -69
  47. package/tabs/tabs.js +95 -59
  48. package/textareaAutosize/textareaAutosize.js +13 -16
  49. package/themeSwitch/themeSwitch.js +27 -41
  50. package/toggle/index.d.ts +8 -1
  51. package/toggle/toggle.js +17 -9
  52. package/toggleGroup/toggleGroup.js +23 -28
  53. package/tooltip/tooltip.js +79 -94
  54. package/treeView/treeView.js +57 -25
  55. package/utils/control.js +20 -0
  56. package/utils/popupList.js +137 -0
  57. package/utils/urlChange.js +32 -0
  58. package/vite.config.js +48 -0
@@ -1,30 +1,5 @@
1
1
  import { toPropsAndChildren } from "@grucloud/bau/bau.js";
2
- import { Colors } from "../constants.js";
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
- ${colorsToCss()}
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",
@@ -1,25 +1,19 @@
1
1
  import { toPropsAndChildren } from "@grucloud/bau/bau.js";
2
- import { Colors } from "../constants.js";
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
- ${colorsToCss()}
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
  }
@@ -1,4 +1,4 @@
1
- import { toPropsAndChildren } from "@grucloud/bau/bau.js";
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
- const slideIndex = bau.state(0);
36
-
37
- return function Carousel(...args) {
38
- let [
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
- size = options.size ?? "md",
41
- variant = options.variant ?? "plain",
42
- color = options.color ?? "neutral",
43
- slides,
44
- Slide,
45
- Previous,
46
- Next,
47
- ...props
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
- ] = toPropsAndChildren(args);
49
+ content
50
+ );
51
+ };
50
52
 
51
- const onclickPrevious = () => {
52
- if (slideIndex.val <= 0) {
53
- slideIndex.val = slides.length - 1;
54
- } else {
55
- slideIndex.val--;
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
- const onclickNext = () => {
60
- if (slideIndex.val >= slides.length - 1) {
61
- slideIndex.val = 0;
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(Slide)
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
- div(
82
- {
83
- class: ["control", "control-previous"],
84
- onclick: onclickPrevious,
85
- },
86
- Previous()
87
- ),
88
- div(
89
- {
90
- class: ["control", "control-next"],
91
- onclick: onclickNext,
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
  };
@@ -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(...args) {
68
- let [
69
- {
70
- size = options.size ?? "md",
71
- variant = options.variant ?? "plain",
72
- color = options.color ?? "neutral",
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 { toPropsAndChildren } from "@grucloud/bau/bau.js";
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
- overflow-y: scroll;
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
- const collapseOrExpandSection = ({ element, closeState }) => {
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
- const animationEndHandler = () => {
46
- element.removeEventListener("transitionend", animationEndHandler);
47
- };
48
- element.addEventListener("transitionend", animationEndHandler);
49
- window.requestAnimationFrame(() => {
50
- element.style.height = "0px";
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 expandSection(element) {
55
- const animationEndHandler = () => {
56
- element.removeEventListener("transitionend", animationEndHandler);
57
- element.style.height = null;
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
- return function Collapsible(...args) {
64
- let [
65
- {
66
- size = options.size ?? "md",
67
- variant = options.variant ?? "plain",
68
- color = options.color ?? "neutral",
69
- Header,
70
- Content,
71
- expanded = false,
72
- ...props
73
- },
74
- ] = toPropsAndChildren(args);
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 ? (closeState.val ? "close" : "open") : "",
109
+ Content ? (openState.val ? "open" : "close") : "",
87
110
  ],
88
111
  onclick: (event) => {
89
- closeState.val = !closeState.val;
112
+ toggle();
113
+ // A collapsible in a collapsible: only the one clicked
90
114
  event.stopPropagation();
91
115
  },
92
116
  },
93
- Header()
117
+ headerContent
94
118
  ),
95
119
  div(
96
120
  {
121
+ id: contentId,
97
122
  class: "content",
98
- role: "region",
123
+ // Closed: out of the Tab order and of the screen readers
124
+ inert: () => !openState.val,
99
125
  bauMounted: ({ element }) => {
100
- closeState.val && (element.style.height = "0px");
126
+ !openState.val && (element.style.height = "0px");
101
127
  },
102
- "aria-expanded": ({ element }) => {
103
- collapseOrExpandSection({ element, closeState });
104
- return !closeState.val;
128
+ "data-open": ({ element }) => {
129
+ collapseOrExpandSection({ element, open: openState.val });
130
+ return openState.val;
105
131
  },
106
132
  },
107
133
  Content && Content()
@@ -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 = { expanded?: boolean } & DefaultDesignProps;
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
@@ -11,6 +11,7 @@ export type Color =
11
11
  export const Variants: Variant[];
12
12
  export const Colors: Color[];
13
13
  export const Sizes: Size[];
14
+ export const ofColor: string;
14
15
 
15
16
  export type DefaultDesignProps = {
16
17
  variant?: Variant;
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(", ")})`;
@@ -32,6 +32,7 @@ export default function (context, options = {}) {
32
32
  ] = toPropsAndChildren(args);
33
33
  return div(
34
34
  {
35
+ ...(!children?.length && { role: "separator" }),
35
36
  ...props,
36
37
  class: ["divider", size, className, options?.class, props?.class],
37
38
  },
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
- { class: [className, options?.class, props.class] },
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
  )