@grucloud/bau-ui 0.301.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,8 +1,4 @@
1
- import { toPropsAndChildren } from "@grucloud/bau/bau.js";
2
-
3
- import { Colors } from "../constants.js";
4
-
5
- const colorsToCss = () => Colors.map((color) => ``).join("\n");
1
+ import { onUrlChange } from "../utils/urlChange.js";
6
2
 
7
3
  export const NextUrl = (context, stepperName) => (nextStep, state) => {
8
4
  const search = new URLSearchParams(context.window.location.search);
@@ -40,7 +36,8 @@ export default function (context, options = {}) {
40
36
  color: inherit;
41
37
  font-weight: var(--font-weight-semibold);
42
38
  transition: all var(--transition-slow) ease-in-out;
43
- background-color: var(--background-color);
39
+ /* The one of the variant: the text color goes with it */
40
+ background-color: inherit;
44
41
  overflow: hidden;
45
42
  & .step-number {
46
43
  background-color: var(--color-primary);
@@ -79,7 +76,10 @@ export default function (context, options = {}) {
79
76
  transform: none;
80
77
  }
81
78
  }
82
- ${colorsToCss()}
79
+ /* On the color of solid, the gray of the steps to come is not read */
80
+ &.solid > ul > .not-completed .step-label {
81
+ color: inherit;
82
+ }
83
83
  &.stepper > section > .content {
84
84
  visibility: hidden;
85
85
  display: none;
@@ -91,35 +91,21 @@ export default function (context, options = {}) {
91
91
  }
92
92
  `;
93
93
 
94
- return function Stepper(...args) {
95
- let [
96
- {
97
- color,
98
- variant = "plain",
99
- size,
100
- stepperDefs = [],
101
- stepperName,
102
- activeStepIndex = bau.state(0),
103
- ...props
104
- },
105
- children,
106
- ] = toPropsAndChildren(args);
94
+ return function Stepper({
95
+ color,
96
+ variant = "plain",
97
+ size,
98
+ stepperDefs,
99
+ stepperName,
100
+ activeStepIndex = bau.state(0),
101
+ ...props
102
+ }) {
107
103
  const stepperState = bau.state(
108
104
  stepperDefs.map((stepper, index) => ({ ...stepper, index }))
109
105
  );
110
106
 
111
107
  const stepsCreatedState = bau.state([]);
112
108
 
113
- window.history.pushState = new Proxy(window.history.pushState, {
114
- apply: (target, thisArg, argArray) => {
115
- target.apply(thisArg, argArray);
116
- const url = argArray[2] ?? "";
117
- if (["?", "#"].includes(url[0])) {
118
- hashchange();
119
- }
120
- },
121
- });
122
-
123
109
  const stepperCurrentState = bau.derive(
124
110
  () => stepperState.val[activeStepIndex.val]
125
111
  );
@@ -128,6 +114,9 @@ export default function (context, options = {}) {
128
114
  const { Header, disabled, name, index } = stepper;
129
115
  return li(
130
116
  {
117
+ // The current step, for the screen readers
118
+ "aria-current": () =>
119
+ stepperCurrentState.val.name == name ? "step" : "false",
131
120
  class: () => [
132
121
  stepperCurrentState.val.name == name && "active",
133
122
  activeStepIndex.val < index && "not-completed",
@@ -160,15 +149,14 @@ export default function (context, options = {}) {
160
149
  };
161
150
 
162
151
  hashchange();
152
+ let removeUrlListener;
163
153
 
164
154
  return div(
165
155
  {
166
- bauMounted: ({ element }) => {
167
- window.addEventListener("popstate", hashchange);
168
- },
169
- bauUnmounted: () => {
170
- window.removeEventListener("popstate", hashchange);
156
+ bauMounted: () => {
157
+ removeUrlListener = onUrlChange(window, hashchange);
171
158
  },
159
+ bauUnmounted: () => removeUrlListener?.(),
172
160
  class: [
173
161
  "stepper",
174
162
  variant,
package/switch/switch.js CHANGED
@@ -1,48 +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
- &.switch.plain.${color} {
9
- &::after {
10
- background-color: var(--color-emphasis-400);
11
- }
12
- &:checked::after {
13
- background-color: var(--color-${color});
14
- }
15
- }
16
- &.switch.outline.${color} {
17
- &::after {
18
- background-color: var(--color-emphasis-400);
19
- }
20
- &:checked::after {
21
- background-color: var(--color-${color});
22
- }
23
- }
24
- &.switch.soft.${color} {
25
- &::after {
26
- background-color: var(--color-emphasis-400);
27
- }
28
- &:checked::after {
29
- background-color: var(--color-${color});
30
- }
31
- }
32
- &.switch.solid.${color} {
33
- background-color: var(--color-emphasis-800);
34
- &::after {
35
- background-color: var(--color-emphasis-400);
36
- }
37
- &:checked {
38
- background-color: var(--color-${color}) ;
39
- }
40
- &:checked::after {
41
- background-color: var(--color-emphasis-400);
42
- }
43
- }
44
- `
45
- ).join("\n");
2
+ import { ofColor } from "../constants.js";
46
3
 
47
4
  export default function (context, options = {}) {
48
5
  const { bau, css } = context;
@@ -71,6 +28,10 @@ export default function (context, options = {}) {
71
28
  content: "";
72
29
  transform: translate(0%, -50%);
73
30
  }
31
+ &:focus-visible {
32
+ outline: 2px solid var(--color-primary);
33
+ outline-offset: 2px;
34
+ }
74
35
  &:hover {
75
36
  filter: brightness(var(--brightness-hover));
76
37
  }
@@ -104,7 +65,28 @@ export default function (context, options = {}) {
104
65
  width: 1.5rem;
105
66
  height: 1.5rem;
106
67
  }
107
- ${colorsToCss()}
68
+ &.switch:is(.plain, .outline, .soft)${ofColor} {
69
+ &::after {
70
+ background-color: var(--color-emphasis-500);
71
+ }
72
+ /* Light enough on the dark background */
73
+ &:checked::after {
74
+ background-color: var(--accent-text);
75
+ }
76
+ }
77
+ &.switch.solid${ofColor} {
78
+ background-color: var(--color-emphasis-800);
79
+ &::after {
80
+ background-color: var(--color-emphasis-400);
81
+ }
82
+ &:checked {
83
+ background-color: var(--accent);
84
+ }
85
+ /* Light on the color of the track */
86
+ &:checked::after {
87
+ background-color: var(--color-content-inverse);
88
+ }
89
+ }
108
90
  `;
109
91
 
110
92
  return function Switch(...args) {
@@ -119,6 +101,7 @@ export default function (context, options = {}) {
119
101
  ] = toPropsAndChildren(args);
120
102
  return input(
121
103
  {
104
+ role: "switch",
122
105
  ...props,
123
106
  class: [
124
107
  "switch",
@@ -1,19 +1,9 @@
1
- import { toPropsAndChildren } from "@grucloud/bau/bau.js";
2
-
3
1
  export default function (context, options = {}) {
4
2
  const { bau, css, window } = context;
5
3
  const { nav, ul, li, a } = bau.tags;
6
4
  const { headerSelector = "h2,h3" } = options;
7
5
  const activeHeadingId = bau.state("no");
8
6
 
9
- const debounce = (callback, wait) => {
10
- let timeoutId = null;
11
- return (...args) => {
12
- window.clearTimeout(timeoutId);
13
- timeoutId = window.setTimeout(() => callback(...args), wait);
14
- };
15
- };
16
-
17
7
  const className = css`
18
8
  grid-area: toc;
19
9
  position: sticky;
@@ -58,90 +48,75 @@ export default function (context, options = {}) {
58
48
  }
59
49
  `;
60
50
 
61
- const TocItem = ({ value, id, children = [] }) => {
51
+ const TocItem = ({ value, id, children }) => {
52
+ const active = () => activeHeadingId.val == id;
62
53
  const link = a({
63
- class: () => (activeHeadingId.val == id ? "active" : ""),
64
- href: `#${id}`,
54
+ class: () => [active() && "active"],
55
+ href: `#${encodeURIComponent(id)}`,
56
+ // The section read
57
+ "aria-current": () => (active() ? "location" : "false"),
65
58
  });
66
59
  link.innerHTML = value;
67
60
  return li(
68
- { class: () => (activeHeadingId.val == id ? "active" : "") },
61
+ { class: () => [active() && "active"] },
69
62
  link,
70
63
  children.length > 0 && ul(children.map(TocItem))
71
64
  );
72
65
  };
73
66
 
74
- const headerLevel = (el) => el.tagName.charAt(1);
75
- const createToc = ({ contentEl }) => {
76
- const headings = contentEl.querySelectorAll(headerSelector);
77
-
78
- let levelCurrent = 2;
79
- let newNode = {};
80
- let nodeCurrent = { children: [] };
81
- let parentNode = nodeCurrent;
82
- const tree = parentNode;
83
- let parents = [parentNode];
84
- [...headings].forEach((heading) => {
85
- const level = headerLevel(heading);
86
- heading.setAttribute("id", heading.textContent);
87
- //TODO
88
- if (heading.innerHTML.includes("<button")) {
89
- return;
67
+ // The headings in a tree: each one under the last heading of a higher
68
+ // level before it
69
+ const createToc = (contentEl) => {
70
+ const root = { level: 0, children: [] };
71
+ const parents = [root];
72
+ for (const heading of contentEl.querySelectorAll(headerSelector)) {
73
+ // The id of the heading, else its text: the target of the link
74
+ if (!heading.id) {
75
+ heading.id = heading.textContent;
90
76
  }
91
- newNode = {
77
+ //TODO
78
+ if (heading.innerHTML.includes("<button")) continue;
79
+ const node = {
80
+ level: Number(heading.tagName[1]),
92
81
  value: heading.innerHTML,
93
- id: heading.id ?? heading.textContent,
82
+ id: heading.id,
94
83
  children: [],
95
84
  };
96
- if (levelCurrent == level) {
97
- nodeCurrent = newNode;
98
- parentNode.children.push(nodeCurrent);
99
- } else if (levelCurrent < level) {
100
- parents.push(parentNode);
101
- parentNode = nodeCurrent;
102
- nodeCurrent.children.push(newNode);
103
- nodeCurrent = newNode;
104
- } else if (levelCurrent > level) {
105
- parentNode = parents[level - 1];
106
- parents = parents.slice(0, level - 1);
107
- parentNode.children.push(newNode);
108
- nodeCurrent = newNode;
109
- }
110
- levelCurrent = level;
111
- });
112
-
113
- return tree;
85
+ while (parents.at(-1).level >= node.level) parents.pop();
86
+ parents.at(-1).children.push(node);
87
+ parents.push(node);
88
+ }
89
+ return root.children;
114
90
  };
115
91
 
116
- return function TableOfContent(...args) {
117
- let [
118
- {
119
- size = options.size ?? "md",
120
- variant = options.variant ?? "plain",
121
- color = options.color ?? "neutral",
122
- contentEl,
123
- ...props
124
- },
125
- ] = toPropsAndChildren(args);
126
-
127
- const toc = createToc({ contentEl });
128
-
129
- const handleScroll = debounce(() => {
130
- const headings = contentEl.querySelectorAll(headerSelector);
131
- const activeHeading = [...headings].find((heading) => {
132
- const { top, height } = heading.getBoundingClientRect();
133
- //TODO
134
- if (top + height > 60) {
135
- return true;
92
+ return function TableOfContent({
93
+ size = options.size ?? "md",
94
+ variant = options.variant ?? "plain",
95
+ color = options.color ?? "neutral",
96
+ contentEl,
97
+ ...props
98
+ }) {
99
+ // The first heading not scrolled out at the top, once the scroll
100
+ // pauses
101
+ let timeoutId;
102
+ const onscroll = () => {
103
+ clearTimeout(timeoutId);
104
+ timeoutId = setTimeout(() => {
105
+ const activeHeading = [
106
+ ...contentEl.querySelectorAll(headerSelector),
107
+ ].find((heading) => {
108
+ const { top, height } = heading.getBoundingClientRect();
109
+ return top + height > 60;
110
+ });
111
+ if (activeHeading) {
112
+ activeHeadingId.val = activeHeading.id;
136
113
  }
137
- });
138
- if (activeHeading) {
139
- activeHeadingId.val = activeHeading?.id;
140
- }
141
- }, 100);
114
+ }, 100);
115
+ };
142
116
 
143
117
  return nav(
144
118
  {
119
+ "aria-label": "Table of contents",
145
120
  ...props,
146
121
  class: [
147
122
  "tableOfContent",
@@ -149,17 +124,13 @@ export default function (context, options = {}) {
149
124
  variant,
150
125
  color,
151
126
  className,
152
- options?.class,
153
- props?.class,
127
+ options.class,
128
+ props.class,
154
129
  ],
155
- bauMounted: (/*{ element }*/) => {
156
- window.addEventListener("scroll", handleScroll);
157
- },
158
- bauUnmounted: (/*{ element }*/) => {
159
- window.removeEventListener("scroll", handleScroll);
160
- },
130
+ bauMounted: () => window.addEventListener("scroll", onscroll),
131
+ bauUnmounted: () => window.removeEventListener("scroll", onscroll),
161
132
  },
162
- toc.children && ul(toc.children.map(TocItem))
133
+ ul(createToc(contentEl).map(TocItem))
163
134
  );
164
135
  };
165
136
  }
@@ -1,4 +1,3 @@
1
- import { toPropsAndChildren } from "@grucloud/bau/bau.js";
2
1
  import button from "../button/button.js";
3
2
  import buttonGroup from "../buttonGroup/buttonGroup.js";
4
3
 
@@ -26,83 +25,45 @@ export default function (context, options = {}) {
26
25
  }
27
26
  `;
28
27
 
29
- const ActionButton = ({ label, icon, ...props }) =>
30
- Button({ "aria-label": label, title: label, ...props }, icon);
31
-
28
+ // The rows shown, and of how many when the total is known
32
29
  const PagesNumbers = ({ count, totalCount, page, rowsPerPage }) =>
33
- div(
34
- { class: "pages-numbers" },
35
- Number(page - 1) * Number(rowsPerPage) + (count > 0 ? 1 : 0),
36
- "-",
37
- Math.min(page * rowsPerPage, totalCount),
38
- " of ",
39
- totalCount
40
- );
41
-
42
- const PagesNumbersNoTotal = ({ count, page, rowsPerPage }) =>
43
30
  div(
44
31
  { class: "pages-numbers" },
45
32
  (page - 1) * rowsPerPage + (count > 0 ? 1 : 0),
46
33
  "-",
47
- page * rowsPerPage
34
+ totalCount > 0
35
+ ? [Math.min(page * rowsPerPage, totalCount), " of ", totalCount]
36
+ : page * rowsPerPage
48
37
  );
49
38
 
50
39
  const isFirstPage = (page) => page <= 1;
51
40
  const isLastPage = (page, count, rowsPerPage) =>
52
41
  page >= Math.ceil(count / rowsPerPage);
53
42
 
54
- return function TablePagination(...args) {
55
- let [
56
- {
57
- size = options.size ?? "md",
58
- variant = options.variant ?? "outline",
59
- color = options.color ?? "neutral",
60
- count = 0,
61
- totalCount = 0,
62
- page = 1,
63
- rowsPerPage = 50,
64
- onPageChange,
65
- isLoading = false,
66
- disableFirst = () => isFirstPage(page),
67
- disablePrevious = () => isFirstPage(page),
68
- disableNext = () => isLastPage(page, totalCount, rowsPerPage),
69
- disableLast = () => isLastPage(page, totalCount, rowsPerPage),
70
- ...props
71
- },
72
- ] = toPropsAndChildren(args);
43
+ return function TablePagination({
44
+ size = options.size ?? "md",
45
+ variant = options.variant ?? "outline",
46
+ color = options.color ?? "neutral",
47
+ count = 0,
48
+ totalCount = 0,
49
+ page = 1,
50
+ rowsPerPage = 50,
51
+ onPageChange,
52
+ isLoading = false,
53
+ disableFirst = () => isFirstPage(page),
54
+ disablePrevious = () => isFirstPage(page),
55
+ disableNext = () => isLastPage(page, totalCount, rowsPerPage),
56
+ disableLast = () => isLastPage(page, totalCount, rowsPerPage),
57
+ ...props
58
+ }) {
73
59
  const maxPages = Math.max(0, Math.ceil(totalCount / rowsPerPage));
74
60
 
75
- const onclickFirst = onPageChange({ page: 1 });
76
- const onclickPrevious = onPageChange({ page: page - 1 });
77
- const onclickNext = onPageChange({ page: page + 1 });
78
- const onclickLast = onPageChange({
79
- page: maxPages,
80
- });
61
+ // Its label, icon, the page it goes to, disabled or not
81
62
  const actions = [
82
- {
83
- label: "First",
84
- icon: "\u27EA",
85
- onclick: onclickFirst,
86
- disabled: disableFirst(),
87
- },
88
- {
89
- label: "Previous",
90
- icon: "\u27E8",
91
- onclick: onclickPrevious,
92
- disabled: disablePrevious(),
93
- },
94
- {
95
- label: "Next",
96
- icon: "\u27E9",
97
- onclick: onclickNext,
98
- disabled: disableNext(),
99
- },
100
- {
101
- label: "Last",
102
- icon: "\u27EB",
103
- onclick: onclickLast,
104
- disabled: disableLast(),
105
- },
63
+ ["First", "\u27EA", 1, disableFirst()],
64
+ ["Previous", "\u27E8", page - 1, disablePrevious()],
65
+ ["Next", "\u27E9", page + 1, disableNext()],
66
+ ["Last", "\u27EB", maxPages, disableLast()],
106
67
  ];
107
68
 
108
69
  return div(
@@ -117,13 +78,22 @@ export default function (context, options = {}) {
117
78
  ],
118
79
  },
119
80
  Spinner({ class: "spinner", visibility: isLoading, size: "md" }),
120
- totalCount > 0
121
- ? PagesNumbers({ count, totalCount, page, maxPages, rowsPerPage })
122
- : PagesNumbersNoTotal({ count, page, maxPages, rowsPerPage }),
123
-
81
+ PagesNumbers({ count, totalCount, page, rowsPerPage }),
124
82
  ButtonGroup(
125
83
  { variant, color },
126
- actions.map((action) => ActionButton({ ...action, variant, color }))
84
+ actions.map(([label, icon, page, disabled]) =>
85
+ Button(
86
+ {
87
+ "aria-label": label,
88
+ title: label,
89
+ onclick: onPageChange({ page }),
90
+ disabled,
91
+ variant,
92
+ color,
93
+ },
94
+ icon
95
+ )
96
+ )
127
97
  )
128
98
  );
129
99
  };