@grucloud/bau-ui 0.301.0 → 0.303.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 (61) 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/virtualList/index.d.ts +27 -0
  59. package/virtualList/index.js +1 -0
  60. package/virtualList/virtualList.js +111 -0
  61. package/vite.config.js +48 -0
@@ -11,6 +11,10 @@ export default function (context, options = {}) {
11
11
  }
12
12
  & .handle {
13
13
  position: relative;
14
+ &:focus-visible {
15
+ outline: 2px solid var(--color-primary);
16
+ outline-offset: -2px;
17
+ }
14
18
  width: 1px;
15
19
  cursor: col-resize;
16
20
  display: flex;
@@ -67,89 +71,89 @@ export default function (context, options = {}) {
67
71
 
68
72
  function Handle(...args) {
69
73
  let [props, children] = toPropsAndChildren(args);
70
-
71
- // The current position of mouse
72
- let _x = 0;
73
- let _y = 0;
74
- let _panelGroup;
75
- let _nextPanel;
76
- let _nextPanelRect;
77
- let _previousPanel;
78
- let _previousPanelRect;
79
-
80
- const isHorizontal = () => direction === "horizontal";
81
-
82
- const mouseMoveHandler = (event) =>
83
- isHorizontal()
84
- ? mouseMoveHandlerHorizontal(event)
85
- : mouseMoveHandlerVertical(event);
86
-
87
- const mouseMoveHandlerHorizontal = (event) => {
88
- const dx = event.clientX - _x;
89
- if (_previousPanelRect) {
90
- _previousPanel.style.width = `${_previousPanelRect.width + dx}px`;
91
- }
92
- if (_nextPanelRect) {
93
- _nextPanel.style.width = `${_nextPanelRect.width - dx}px`;
94
- }
74
+ const horizontal = direction === "horizontal";
75
+ const property = horizontal ? "width" : "height";
76
+ const sizeOf = (element) =>
77
+ element ? element.getBoundingClientRect()[property] : 0;
78
+ const panelsOf = (handleEl) => [
79
+ handleEl.previousElementSibling,
80
+ handleEl.nextElementSibling,
81
+ ];
82
+
83
+ // The size of the first panel, in percent of both, for the readers
84
+ const updateValue = (handleEl) => {
85
+ const [previous, next] = panelsOf(handleEl);
86
+ const total = sizeOf(previous) + sizeOf(next);
87
+ previous &&
88
+ next &&
89
+ total &&
90
+ handleEl.setAttribute(
91
+ "aria-valuenow",
92
+ String(Math.round((100 * sizeOf(previous)) / total))
93
+ );
95
94
  };
96
95
 
97
- const mouseMoveHandlerVertical = (event) => {
98
- const dy = event.clientY - _y;
99
- if (_previousPanelRect) {
100
- _previousPanel.style.height = `${_previousPanelRect.height + dy}px`;
101
- }
102
- if (_nextPanelRect) {
103
- _nextPanel.style.height = `${_nextPanelRect.height - dy}px`;
104
- }
96
+ // The panels around the handle: their sizes, given, moved by delta
97
+ const resize = (handleEl, [previousSize, nextSize], delta) => {
98
+ const [previous, next] = panelsOf(handleEl);
99
+ if (previous) previous.style[property] = `${previousSize + delta}px`;
100
+ if (next) next.style[property] = `${nextSize - delta}px`;
101
+ updateValue(handleEl);
105
102
  };
106
103
 
107
- const mouseUpHandler = () => {
108
- _nextPanel = null;
109
- _previousPanel = null;
110
- _nextPanelRect = null;
111
- _previousPanelRect = null;
112
- _panelGroup.style.cursor = null;
113
- _panelGroup.style["user-select"] = "auto";
114
- document.removeEventListener("mousemove", mouseMoveHandler);
115
- document.removeEventListener("mouseup", mouseUpHandler);
104
+ // A drag: the moves and the release are on the document, the pointer
105
+ // leaves the handle
106
+ const onmousedown = (event) => {
107
+ const handleEl = event.currentTarget;
108
+ const groupEl = handleEl.closest(".resizablePanelGroup");
109
+ const positionOf = (event) =>
110
+ horizontal ? event.clientX : event.clientY;
111
+ const start = positionOf(event);
112
+ const sizes = panelsOf(handleEl).map(sizeOf);
113
+ const onmousemove = (event) =>
114
+ resize(handleEl, sizes, positionOf(event) - start);
115
+ const onmouseup = () => {
116
+ groupEl.style.cursor = null;
117
+ groupEl.style.userSelect = "auto";
118
+ document.removeEventListener("mousemove", onmousemove);
119
+ document.removeEventListener("mouseup", onmouseup);
120
+ };
121
+ groupEl.style.cursor = horizontal ? "col-resize" : "row-resize";
122
+ groupEl.style.userSelect = "none";
123
+ document.addEventListener("mousemove", onmousemove);
124
+ document.addEventListener("mouseup", onmouseup);
116
125
  };
117
126
 
118
- const mouseDownHandler = (event) => {
119
- // Get the current mouse position
120
- _x = event.clientX;
121
- _y = event.clientY;
122
-
123
- const { target } = event;
124
- const handleEl = target.closest(".handle");
125
- _panelGroup = target.closest(".resizablePanelGroup");
126
- _panelGroup.style.cursor = isHorizontal() ? "col-resize" : "row-resize";
127
- _panelGroup.style["user-select"] = "none";
128
-
129
- _nextPanel = handleEl.nextSibling;
130
- _previousPanel = handleEl.previousSibling;
131
-
132
- if (_previousPanel) {
133
- _previousPanelRect = _previousPanel.getBoundingClientRect();
134
- }
135
- if (_nextPanel) {
136
- _nextPanelRect = _nextPanel.getBoundingClientRect();
137
- }
138
- document.addEventListener("mousemove", mouseMoveHandler);
139
- document.addEventListener("mouseup", mouseUpHandler);
127
+ // The keyboard moves the handle too: the arrow keys of its direction,
128
+ // within the two panels
129
+ const keyStep = 10;
130
+ const keys = horizontal
131
+ ? { ArrowLeft: -keyStep, ArrowRight: keyStep }
132
+ : { ArrowUp: -keyStep, ArrowDown: keyStep };
133
+ const onkeydown = (event) => {
134
+ const delta = keys[event.key];
135
+ if (!delta) return;
136
+ event.preventDefault();
137
+ const handleEl = event.currentTarget;
138
+ const sizes = panelsOf(handleEl).map(sizeOf);
139
+ resize(handleEl, sizes, Math.max(-sizes[0], Math.min(sizes[1], delta)));
140
140
  };
141
141
 
142
142
  return div(
143
143
  {
144
+ // Reached with Tab, named; its orientation is the one of the line,
145
+ // across the direction of the panels
146
+ tabindex: "0",
147
+ "aria-label": "Resize",
148
+ "aria-orientation": horizontal ? "vertical" : "horizontal",
149
+ "aria-valuemin": "0",
150
+ "aria-valuemax": "100",
151
+ onkeydown,
152
+ onmousedown,
144
153
  ...props,
145
154
  class: ["handle", direction],
146
155
  role: "separator",
147
- bauMounted: ({ element }) => {
148
- element.addEventListener("mousedown", mouseDownHandler);
149
- },
150
- bauUnmounted: ({ element }) => {
151
- element.removeEventListener("mousedown", mouseDownHandler);
152
- },
156
+ bauMounted: ({ element }) => updateValue(element),
153
157
  },
154
158
  children
155
159
  );
package/select/select.js CHANGED
@@ -1,34 +1,12 @@
1
- import { toPropsAndChildren } from "@grucloud/bau/bau.js";
2
- import popover from "../popover/popover.js";
3
- import button from "../button/button.js";
4
- import list from "../list/list.js";
1
+ import popupList from "../utils/popupList.js";
5
2
  import spinner from "../spinner/spinner.js";
6
3
 
7
- import { Colors } from "../constants.js";
8
-
9
- const colorsToCss = () =>
10
- Colors.map(
11
- (color) =>
12
- `
13
- & button.plain {
14
- color: var(--font-color-secondary);
15
- }
16
- & button.plain.${color}::after {
17
- color: var(--font-color-secondary);
18
- }
19
- & button.outline.${color}::after {
20
- color: var(--color-${color});
21
- }
22
- `
23
- ).join("\n");
4
+ import { ofColor } from "../constants.js";
24
5
 
25
6
  export default function (context, componentOptions = {}) {
26
7
  const { bau, css } = context;
27
- const { div, li, select, option } = bau.tags;
28
- const Button = button(context);
29
- const Popover = popover(context);
30
- const List = list(context);
31
-
8
+ const { div, select, option } = bau.tags;
9
+ const PopupList = popupList(context);
32
10
  const className = css`
33
11
  & select {
34
12
  width: 0;
@@ -52,158 +30,104 @@ export default function (context, componentOptions = {}) {
52
30
  display: none;
53
31
  }
54
32
  }
55
- ${colorsToCss()}
33
+ & button.plain {
34
+ color: var(--font-color-secondary);
35
+ }
36
+ & button.plain${ofColor}::after {
37
+ color: var(--font-color-secondary);
38
+ }
39
+ & button.outline${ofColor}::after {
40
+ color: var(--accent-text);
41
+ }
56
42
  `;
57
43
 
58
- return function Select(...args) {
59
- let [
60
- {
61
- size = componentOptions.size ?? "md",
62
- variant = componentOptions.variant ?? "outline",
63
- color = componentOptions.color ?? "neutral",
64
- label,
65
- Option,
66
- options,
67
- defaultOption,
68
- getOptionLabel,
69
- getOptionValue,
70
- onSelect = () => {},
71
- loading,
72
- ...props
73
- },
74
- children,
75
- ] = toPropsAndChildren(args);
76
-
44
+ return function Select({
45
+ size = componentOptions.size ?? "md",
46
+ variant = componentOptions.variant ?? "outline",
47
+ color = componentOptions.color ?? "neutral",
48
+ label,
49
+ Option,
50
+ options,
51
+ defaultOption,
52
+ getOptionLabel,
53
+ getOptionValue,
54
+ onSelect = () => {},
55
+ loading,
56
+ // For the hidden select of the form; the rest for the component
57
+ name,
58
+ required,
59
+ value,
60
+ oninvalid,
61
+ ...props
62
+ }) {
77
63
  const Spinner = spinner(context, { variant, color, size });
78
64
 
79
- const inputState = bau.state(
80
- defaultOption ? getOptionLabel(defaultOption) : label
65
+ const selectedIndex = bau.state(
66
+ defaultOption
67
+ ? options.findIndex(
68
+ (option) => getOptionValue(option) == getOptionValue(defaultOption)
69
+ )
70
+ : -1
81
71
  );
82
- const openState = bau.state(false);
83
- const itemIndexActive = bau.state(0);
84
-
85
- const dialogOpen = () => {
86
- popoverEl.openDialog();
87
- popoverEl.focus();
88
- openState.val = true;
89
- };
90
-
91
- const dialogClose = () => {
92
- popoverEl.closeDialog();
93
- openState.val = false;
94
- };
95
-
96
- const onClose = () => {
97
- openState.val = false;
98
- };
99
72
 
100
- const onclickButton = (event) => {
101
- popoverEl.open ? dialogClose() : dialogOpen();
102
- event.preventDefault();
73
+ // In the hidden select of the form too
74
+ const choose = (index) => {
75
+ const option = options[index];
76
+ selectEl.value = getOptionValue(option);
77
+ selectEl.setCustomValidity("");
78
+ selectedIndex.val = index;
79
+ close();
80
+ onSelect(option);
103
81
  };
104
82
 
105
- const onclickItem =
106
- ({ option, index }) =>
107
- (event) => {
108
- inputState.val = getOptionLabel(option);
109
- selectEl.value = getOptionValue(option);
110
- selectEl.setCustomValidity("");
111
- itemIndexActive.val = index;
112
- dialogClose();
113
- onSelect(option);
114
- event.preventDefault();
115
- };
116
-
117
- const onkeydown = (event) => {
118
- if (!popoverEl.open) {
119
- return;
120
- }
121
- event.preventDefault();
122
- switch (event.key) {
123
- case "Escape":
124
- dialogClose();
125
- break;
126
- case "ArrowDown":
127
- if (itemIndexActive.val < options.length - 1) {
128
- itemIndexActive.val++;
129
- } else {
130
- itemIndexActive.val = 0;
131
- }
132
- break;
133
- case "ArrowUp":
134
- if (itemIndexActive.val <= 0) {
135
- itemIndexActive.val = options.length - 1;
136
- } else {
137
- itemIndexActive.val--;
138
- }
139
- break;
140
- case "Enter":
141
- if (popoverEl.open) {
142
- inputState.val = getOptionLabel(options[itemIndexActive.val]);
143
- selectEl.value = getOptionValue(options[itemIndexActive.val]);
144
- onSelect(options[itemIndexActive.val]);
145
- dialogClose();
146
- } else {
147
- dialogOpen();
148
- }
149
- break;
150
- }
151
- };
152
-
153
- const Content = () =>
154
- List(
155
- { tabindex: "0", class: [color, variant] },
156
- options.map((option, index) =>
157
- li(
158
- {
159
- class: () => itemIndexActive.val == index && "active",
160
- onclick: onclickItem({ option, index }),
161
- },
162
- Option(option)
163
- )
164
- )
165
- );
166
-
167
- const buttonEl = Button(
168
- {
169
- type: "button",
83
+ const { buttonEl, popoverEl, onkeydown, close } = PopupList({
84
+ role: "listbox",
85
+ label,
86
+ items: options,
87
+ Item: Option,
88
+ itemProps: (index) => ({
89
+ role: "option",
90
+ "aria-selected": () => String(selectedIndex.val == index),
91
+ }),
92
+ onClickItem: choose,
93
+ // On the option chosen, else the first one
94
+ activeOnOpen: () => Math.max(selectedIndex.val, 0),
95
+ buttonProps: {
170
96
  role: "combobox",
171
- "aria-autocomplete": "list",
172
- "aria-expanded": openState,
173
97
  "aria-label": label,
174
- onclick: onclickButton,
175
- color,
176
- variant,
177
- size,
178
98
  class: loading == true && "loading",
179
99
  disabled: loading,
180
100
  },
181
- () => !inputState.val && label,
182
- inputState,
183
- () => loading == true && Spinner({ visibility: loading })
184
- );
185
-
186
- const popoverEl = Popover({
187
- // id,
188
- triggerEl: buttonEl,
189
- contentEl: Content(),
190
- onClose,
101
+ buttonChildren: [
102
+ // The label, until an option is chosen
103
+ () =>
104
+ selectedIndex.val < 0
105
+ ? label
106
+ : getOptionLabel(options[selectedIndex.val]),
107
+ () => loading == true && Spinner({ visibility: loading }),
108
+ ],
109
+ color,
110
+ variant,
111
+ size,
191
112
  });
192
- // Hidden select, required to save the value.
113
+
114
+ // Hidden select, required to save the value; hidden from assistive
115
+ // technologies too: the button is the combobox
193
116
  const selectEl = select(
194
- // Hidden from assistive technologies too: the button is the combobox
195
- { ...props, "aria-label": label, tabindex: "-1", "aria-hidden": "true" },
117
+ {
118
+ name,
119
+ required,
120
+ oninvalid,
121
+ "aria-label": label,
122
+ tabindex: "-1",
123
+ "aria-hidden": "true",
124
+ },
196
125
  option({ value: "" }, "--Select Category--"),
197
126
  options.map((opt) =>
198
127
  option({ value: getOptionValue(opt) }, getOptionLabel(opt))
199
128
  )
200
129
  );
201
-
202
- if (defaultOption) {
203
- selectEl.value = getOptionValue(defaultOption);
204
- } else {
205
- selectEl.value = props.value;
206
- }
130
+ selectEl.value = defaultOption ? getOptionValue(defaultOption) : value;
207
131
 
208
132
  return div(
209
133
  {
@@ -213,8 +137,8 @@ export default function (context, componentOptions = {}) {
213
137
  color,
214
138
  size,
215
139
  className,
216
- componentOptions?.class,
217
- props?.class,
140
+ componentOptions.class,
141
+ props.class,
218
142
  ],
219
143
  onkeydown,
220
144
  },
@@ -7,6 +7,8 @@ export default function (context, componentOptions = {}) {
7
7
  const className = css`
8
8
  border-radius: var(--global-radius);
9
9
  &.sm {
10
+ /* A target of 24px at least, WCAG 2.5.8 */
11
+ min-height: 24px;
10
12
  }
11
13
  &.md {
12
14
  padding: 0.5rem;
package/slider/slider.js CHANGED
@@ -1,22 +1,16 @@
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
- &.slider.${color} {
13
- accent-color: var(--color-${color});
14
- }
15
- `
16
- ).join("\n");
17
-
18
8
  const className = css`
19
- ${colorsToCss()};
9
+ /* WCAG 2.5.8, the size of a target */
10
+ min-height: 24px;
11
+ &.slider${ofColor} {
12
+ accent-color: var(--accent);
13
+ }
20
14
  `;
21
15
 
22
16
  return function Slider(...args) {
@@ -1,4 +1,4 @@
1
- import { Colors } from "../constants.js";
1
+ import { ofColor } from "../constants.js";
2
2
 
3
3
  const sizeToPixel = {
4
4
  sm: 12,
@@ -6,33 +6,6 @@ const sizeToPixel = {
6
6
  lg: 24,
7
7
  };
8
8
 
9
- const colorsToCss = () =>
10
- Colors.map(
11
- (color) =>
12
- `
13
- &.${color} {
14
- background-color:transparent;
15
- }
16
- &.plain.${color} {
17
- & .path {
18
- stroke: var(--color-${color});
19
- }
20
- }
21
- &.outline.${color} {
22
- border: none;
23
- & .path {
24
- stroke: var(--color-${color});
25
- }
26
- }
27
- &.solid.${color} {
28
- background-color: transparent;
29
- & .path {
30
- stroke: var(--font-color-inverse);
31
- }
32
- }
33
- `
34
- ).join("\n");
35
-
36
9
  export default function (context, options = {}) {
37
10
  const { bau, css, keyframes } = context;
38
11
  const { svg, circle } = bau.tagsNS("http://www.w3.org/2000/svg");
@@ -57,6 +30,36 @@ export default function (context, options = {}) {
57
30
  }
58
31
  `;
59
32
 
33
+ const className = css`
34
+ visibility: hidden;
35
+ opacity: 0;
36
+ transition: all var(--transition-slow) ease-in-out;
37
+ &.visibility {
38
+ visibility: visible;
39
+ opacity: 1;
40
+ }
41
+ animation: ${rotate} 2s linear infinite;
42
+ & .path {
43
+ stroke-linecap: round;
44
+ animation: ${dash} 1.5s ease-in-out infinite;
45
+ }
46
+ &${ofColor} {
47
+ background-color: transparent;
48
+ }
49
+ &:is(.plain, .outline)${ofColor} .path {
50
+ stroke: var(--accent-text);
51
+ }
52
+ &.outline${ofColor} {
53
+ border: none;
54
+ }
55
+ &.solid${ofColor} {
56
+ background-color: transparent;
57
+ & .path {
58
+ stroke: var(--font-color-inverse);
59
+ }
60
+ }
61
+ `;
62
+
60
63
  return function Spinner({
61
64
  size = options.size ?? "md",
62
65
  color = options.color ?? "primary",
@@ -64,26 +67,11 @@ export default function (context, options = {}) {
64
67
  visibility = true,
65
68
  ...otherProps
66
69
  } = {}) {
67
- const className = css`
68
- visibility: hidden;
69
- opacity: 0;
70
- transition: all var(--transition-slow) ease-in-out;
71
- &.visibility {
72
- visibility: visible;
73
- opacity: 1;
74
- }
75
- animation: ${rotate} 2s linear infinite;
76
- width: ${sizeToPixel[size]};
77
- height: ${sizeToPixel[size]};
78
- & .path {
79
- stroke-linecap: round;
80
- animation: ${dash} 1.5s ease-in-out infinite;
81
- }
82
- ${colorsToCss()}
83
- `;
84
-
85
70
  return svg(
86
71
  {
72
+ "aria-label": "Loading",
73
+ // First: its class is added to the ones of the spinner
74
+ ...otherProps,
87
75
  class: {
88
76
  deps: [visibility],
89
77
  renderProp: () => (visibility) =>
@@ -93,18 +81,14 @@ export default function (context, options = {}) {
93
81
  color,
94
82
  variant,
95
83
  visibility == false ? "" : "visibility",
96
- options?.class,
84
+ options.class,
97
85
  otherProps.class,
98
86
  ],
99
87
  },
100
- version: "1.1",
101
- x: "0px",
102
- y: "0px",
88
+ role: "progressbar",
103
89
  width: sizeToPixel[size],
104
90
  height: sizeToPixel[size],
105
- viewBox: `0 0 50 50`,
106
- enableBackground: `new 0 0 50 50`,
107
- ...otherProps,
91
+ viewBox: "0 0 50 50",
108
92
  },
109
93
  circle({
110
94
  class: "path",