@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,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
  import checkbox from "../checkbox/checkbox";
7
- import { Colors } from "../constants.js";
8
-
9
- const colorsToCss = () =>
10
- Colors.map(
11
- (color) =>
12
- `
13
- & button.plain.${color}::after {
14
- color: var(--color-${color});
15
- }
16
- & button.outline.${color}::after {
17
- color: var(--color-${color});
18
- }
19
- `
20
- ).join("\n");
4
+ import { ofColor } from "../constants.js";
21
5
 
22
6
  export default function (context, componentOptions = {}) {
23
7
  const { bau, css } = context;
24
- const { div, li, select } = bau.tags;
25
- const Button = button(context);
26
- const Popover = popover(context);
27
- const List = list(context);
8
+ const { div, select, option } = bau.tags;
9
+ const PopupList = popupList(context);
28
10
  const Checkbox = checkbox(context, { color: "neutral", variant: "outline" });
29
11
 
30
12
  const className = css`
@@ -41,175 +23,106 @@ export default function (context, componentOptions = {}) {
41
23
  display: none;
42
24
  }
43
25
  }
44
- & label {
26
+ & .option {
45
27
  display: flex;
46
28
  gap: 0.5rem;
47
29
  align-items: center;
48
30
  flex-grow: 1;
49
31
  }
50
- ${colorsToCss()}
32
+ & button:is(.plain, .outline)${ofColor}::after {
33
+ color: var(--accent-text);
34
+ }
51
35
  `;
52
36
 
53
- return function MultiSelect(...args) {
54
- let [
55
- {
56
- size = componentOptions.size ?? "md",
57
- variant = componentOptions.variant ?? "outline",
58
- color = componentOptions.color ?? "neutral",
59
- name,
60
- label,
61
- Option,
62
- options,
63
- defaultValue = [],
64
- getOptionLabel,
65
- getOptionValue,
66
- renderValue,
67
- onSelect = () => {},
68
- loading,
69
- ...props
70
- },
71
- children,
72
- ] = toPropsAndChildren(args);
73
-
37
+ return function MultiSelect({
38
+ size = componentOptions.size ?? "md",
39
+ variant = componentOptions.variant ?? "outline",
40
+ color = componentOptions.color ?? "neutral",
41
+ name,
42
+ label,
43
+ Option,
44
+ options,
45
+ defaultValue = [],
46
+ getOptionLabel,
47
+ getOptionValue,
48
+ renderValue,
49
+ onSelect = () => {},
50
+ loading,
51
+ // For the hidden select of the form; the rest for the component
52
+ required,
53
+ oninvalid,
54
+ ...props
55
+ }) {
74
56
  const Spinner = spinner(context, { variant, color, size });
75
57
 
76
58
  const selectedState = bau.state(defaultValue);
77
- const openState = bau.state(false);
78
- const itemIndexActive = bau.state(0);
79
-
80
- const dialogOpen = () => {
81
- popoverEl.openDialog();
82
- popoverEl.focus();
83
- openState.val = true;
84
- };
85
-
86
- const dialogClose = () => {
87
- popoverEl.closeDialog();
88
- openState.val = false;
89
- };
90
-
91
- const onClose = () => {
92
- openState.val = false;
93
- };
94
-
95
- const onclickButton = (event) => {
96
- popoverEl.open ? dialogClose() : dialogOpen();
97
- event.preventDefault();
98
- };
99
-
100
- const findOptions = () =>
101
- Array.from(selectEl.selectedOptions).map(({ value }) =>
102
- options.find((option) => getOptionValue(option) == value)
59
+ const isSelected = (option) =>
60
+ selectedState.val.some(
61
+ (selected) => getOptionValue(selected) == getOptionValue(option)
103
62
  );
104
63
 
105
- const onkeydown = (event) => {
106
- event.preventDefault();
107
- switch (event.key) {
108
- case "Escape":
109
- dialogClose();
110
- break;
111
- case "ArrowDown":
112
- if (itemIndexActive.val < options.length - 1) {
113
- itemIndexActive.val++;
114
- } else {
115
- itemIndexActive.val = 0;
116
- }
117
- break;
118
- case "ArrowUp":
119
- if (itemIndexActive.val <= 0) {
120
- itemIndexActive.val = options.length - 1;
121
- } else {
122
- itemIndexActive.val--;
123
- }
124
- break;
125
- case "Enter":
126
- if (popoverEl.open) {
127
- const checkbox =
128
- event.currentTarget.querySelectorAll("input")[
129
- itemIndexActive.val
130
- ];
131
- checkbox.checked = !checkbox.checked;
132
- const currentOption = selectEl.options[itemIndexActive.val + 1];
133
- currentOption.selected = !currentOption.selected;
134
- selectedState.val = findOptions();
135
- } else {
136
- dialogOpen();
137
- }
138
- break;
139
- }
140
- };
141
-
142
- const onChangeCheckbox = (opt) => (event) => {
143
- const option = [...selectEl.options].find(
144
- ({ value }) => value == getOptionValue(opt)
145
- );
146
- if (event.target.checked) {
147
- option.selected = true;
148
- } else {
149
- option.selected = false;
150
- }
151
- selectedState.val = findOptions();
152
- };
153
-
154
- const Content = () => {
155
- return List(
156
- { tabindex: "0", class: [color, variant] },
157
- options.map((option, index) =>
158
- li(
159
- {
160
- class: () => itemIndexActive.val == index && "active",
161
- },
162
- bau.tags.label(
163
- Checkbox({
164
- checked: defaultValue.find(
165
- (v) => getOptionValue(v) == getOptionValue(option)
166
- ),
167
- name: `${name}-${getOptionValue(option)}`,
168
- onchange: onChangeCheckbox(option),
169
- }),
170
- Option(option)
171
- )
64
+ // Selected or not, in the state and in the hidden select of the form
65
+ const toggle = (index) => {
66
+ const option = options[index];
67
+ selectedState.val = isSelected(option)
68
+ ? selectedState.val.filter(
69
+ (selected) => getOptionValue(selected) != getOptionValue(option)
172
70
  )
173
- )
174
- );
71
+ : [...selectedState.val, option];
72
+ selectEl.options[index + 1].selected = isSelected(option);
73
+ onSelect(selectedState.val);
175
74
  };
176
75
 
177
- const buttonEl = Button(
178
- {
179
- type: "button",
76
+ const { buttonEl, popoverEl, onkeydown } = PopupList({
77
+ role: "listbox",
78
+ label,
79
+ items: options,
80
+ // Shows the choice: the option says it to the screen readers, the
81
+ // click on it toggles it
82
+ Item: (option) =>
83
+ div(
84
+ { class: "option" },
85
+ Checkbox({ checked: () => isSelected(option), inert: true }),
86
+ Option(option)
87
+ ),
88
+ itemProps: (index) => ({
89
+ role: "option",
90
+ "aria-selected": () => String(isSelected(options[index])),
91
+ }),
92
+ onClickItem: toggle,
93
+ listProps: { "aria-multiselectable": "true" },
94
+ buttonProps: {
180
95
  role: "combobox",
181
- "aria-autocomplete": "list",
182
- "aria-expanded": openState,
183
96
  "aria-label": label,
184
- onclick: onclickButton,
185
- color,
186
- variant,
187
- size,
188
97
  class: loading == true && "loading",
189
98
  disabled: loading,
190
99
  },
191
- () => (selectedState.val.length ? renderValue(selectedState.val) : label),
192
- () => loading == true && Spinner({ visibility: loading })
193
- );
194
-
195
- const popoverEl = Popover({
196
- triggerEl: buttonEl,
197
- contentEl: Content(),
198
- onClose,
100
+ buttonChildren: [
101
+ () =>
102
+ selectedState.val.length ? renderValue(selectedState.val) : label,
103
+ () => loading == true && Spinner({ visibility: loading }),
104
+ ],
105
+ color,
106
+ variant,
107
+ size,
199
108
  });
200
- // Hidden select, required to save the value.
109
+
110
+ // Hidden select, required to save the value; hidden from the keyboard
111
+ // and the screen readers: the button is the combobox
201
112
  const selectEl = select(
202
- { name, multiple: true, ...props },
203
- bau.tags.option({ value: "" }, "--Category--"),
204
- options.map((option) =>
205
- bau.tags.option(
206
- {
207
- value: getOptionValue(option),
208
- selected: defaultValue.find(
209
- (v) => getOptionValue(v) == getOptionValue(option)
210
- ),
211
- },
212
- getOptionLabel(option)
113
+ {
114
+ name,
115
+ required,
116
+ oninvalid,
117
+ multiple: true,
118
+ tabindex: "-1",
119
+ "aria-hidden": "true",
120
+ },
121
+ option({ value: "" }, "--Category--"),
122
+ options.map((opt) =>
123
+ option(
124
+ { value: getOptionValue(opt), selected: isSelected(opt) },
125
+ getOptionLabel(opt)
213
126
  )
214
127
  )
215
128
  );
@@ -222,8 +135,8 @@ export default function (context, componentOptions = {}) {
222
135
  color,
223
136
  size,
224
137
  className,
225
- componentOptions?.class,
226
- props?.class,
138
+ componentOptions.class,
139
+ props.class,
227
140
  ],
228
141
  onkeydown,
229
142
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@grucloud/bau-ui",
3
3
  "description": "Components library built with Bau",
4
- "version": "0.300.0",
4
+ "version": "0.302.0",
5
5
  "type": "module",
6
6
  "license": "BSD",
7
7
  "keywords": [
@@ -12,6 +12,8 @@
12
12
  ],
13
13
  "author": "Frederic Heem",
14
14
  "scripts": {
15
+ "test": "vitest run",
16
+ "test:coverage": "vitest run --coverage",
15
17
  "typedoc": "typedoc --exclude myComponent/index.d.ts *.d.ts **/*.d.ts "
16
18
  },
17
19
  "repository": {
@@ -20,11 +22,17 @@
20
22
  "directory": "bau-ui"
21
23
  },
22
24
  "dependencies": {
23
- "@grucloud/bau": "^0.300.0",
24
- "@grucloud/bau-css": "^0.300.0"
25
+ "@grucloud/bau": "^0.302.0",
26
+ "@grucloud/bau-css": "^0.302.0"
25
27
  },
26
28
  "devDependencies": {
27
- "typedoc": "0.24.8"
29
+ "@vitest/browser-playwright": "^5.1.2",
30
+ "@vitest/coverage-istanbul": "^5.1.2",
31
+ "axe-core": "^4.14.1",
32
+ "playwright": "1.65.1",
33
+ "typedoc": "0.24.8",
34
+ "vite": "^8.4.1",
35
+ "vitest": "^5.1.2"
28
36
  },
29
- "gitHead": "7fcb57be43447051724d80dcb42308f8fb51286d"
37
+ "gitHead": "91e8032cd2d9cf76fdbaf56b5e191c29c5e2b954"
30
38
  }
@@ -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, config } = context;
5
3
  const { div, a, span, nav } = bau.tags;
@@ -48,21 +46,18 @@ export default function (context, options = {}) {
48
46
  ({ text }) =>
49
47
  ({ name, label, href }) =>
50
48
  a(
51
- { href: `${config.base}${href}` },
49
+ { href: `${config?.base ?? ""}${href}` },
52
50
  span({ class: "sublabel" }, text),
53
51
  div({ class: `label ${text}` }, label ?? name)
54
52
  );
55
53
 
56
- return function PaginationNavigation(...args) {
57
- let [
58
- {
59
- size = options.size ?? "md",
60
- variant = options.variant ?? "plain",
61
- color = options.color ?? "neutral",
62
- data = {},
63
- ...props
64
- },
65
- ] = toPropsAndChildren(args);
54
+ return function PaginationNavigation({
55
+ size = options.size ?? "md",
56
+ variant = options.variant ?? "plain",
57
+ color = options.color ?? "neutral",
58
+ data = {},
59
+ ...props
60
+ } = {}) {
66
61
  const { next, previous } = data;
67
62
  return nav(
68
63
  {
@@ -63,11 +63,14 @@ export default function (context, options) {
63
63
 
64
64
  const dialogEl = dialog(
65
65
  {
66
- role: "presentation",
66
+ ...props,
67
67
  class: ["popover", className, options?.class, props?.class],
68
+ // A click on the backdrop, outside the content
68
69
  onclick: (event) => {
69
- event.target === dialogEl && (closeDialog(), onClose?.call());
70
+ event.target === dialogEl && closeDialog();
70
71
  },
72
+ // Closed by a click outside, Escape or closeDialog
73
+ onclose: () => onClose?.call(),
71
74
  },
72
75
  contentEl
73
76
  );
@@ -1,20 +1,9 @@
1
- import { toPropsAndChildren } from "@grucloud/bau/bau.js";
2
- import { Colors } from "../constants.js";
1
+ import { ofColor } from "../constants.js";
3
2
 
4
3
  export default function (context, options = {}) {
5
4
  const { bau, css } = context;
6
5
  const { input } = bau.tags;
7
6
 
8
- const colorsToCss = () =>
9
- Colors.map(
10
- (color) =>
11
- `
12
- &.radio-button.${color} {
13
- accent-color: var(--color-${color});
14
- }
15
- `
16
- ).join("\n");
17
-
18
7
  const className = css`
19
8
  cursor: pointer;
20
9
  &.sm {
@@ -25,19 +14,17 @@ export default function (context, options = {}) {
25
14
  &.lg {
26
15
  transform: scale(1.5);
27
16
  }
28
- ${colorsToCss()}
17
+ &.radio-button${ofColor} {
18
+ accent-color: var(--accent);
19
+ }
29
20
  `;
30
21
 
31
- return function RadioButton(...args) {
32
- let [
33
- {
34
- size = options.size ?? "md",
35
- variant = options.variant ?? "plain",
36
- color = options.color ?? "neutral",
37
- ...props
38
- },
39
- ] = toPropsAndChildren(args);
40
-
22
+ return function RadioButton({
23
+ size = options.size ?? "md",
24
+ variant = options.variant ?? "plain",
25
+ color = options.color ?? "neutral",
26
+ ...props
27
+ } = {}) {
41
28
  return input({
42
29
  ...props,
43
30
  type: "radio",
@@ -1,5 +1,3 @@
1
- import { toPropsAndChildren } from "@grucloud/bau/bau.js";
2
- import { Colors } from "../constants.js";
3
1
  import radioButton from "../radioButton";
4
2
 
5
3
  export default function (context, options = {}) {
@@ -7,13 +5,6 @@ export default function (context, options = {}) {
7
5
  const { div, label } = bau.tags;
8
6
  const RadioButton = radioButton(context);
9
7
 
10
- const colorsToCss = () =>
11
- Colors.map(
12
- (color) =>
13
- `
14
- `
15
- ).join("\n");
16
-
17
8
  const className = css`
18
9
  display: flex;
19
10
  flex-direction: row;
@@ -32,24 +23,24 @@ export default function (context, options = {}) {
32
23
  flex-direction: column;
33
24
  }
34
25
  }
35
- ${colorsToCss()};
36
26
  `;
37
27
 
38
- return function RadioButtonGroup(...args) {
39
- let [
40
- {
41
- size = options.size ?? "md",
42
- variant = options.variant ?? "none",
43
- color = options.color ?? "neutral",
44
- name,
45
- oninput,
46
- radios = [],
47
- ...props
48
- },
49
- ] = toPropsAndChildren(args);
50
-
28
+ return function RadioButtonGroup({
29
+ size = options.size ?? "md",
30
+ variant = options.variant ?? "none",
31
+ color = options.color ?? "neutral",
32
+ name,
33
+ oninput,
34
+ radios = [],
35
+ "aria-label": ariaLabel,
36
+ "aria-labelledby": ariaLabelledby,
37
+ ...props
38
+ } = {}) {
51
39
  return div(
52
40
  {
41
+ role: "radiogroup",
42
+ "aria-label": ariaLabel,
43
+ "aria-labelledby": ariaLabelledby,
53
44
  class: [
54
45
  "radioButtonGroup",
55
46
  size,
@@ -67,7 +58,7 @@ export default function (context, options = {}) {
67
58
  size,
68
59
  variant,
69
60
  color,
70
- id: value,
61
+ id: name ? `${name}-${value}` : undefined,
71
62
  name,
72
63
  checked: value == props.value,
73
64
  value,