@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.
- 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
package/tabs/tabs.js
CHANGED
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { onUrlChange } from "../utils/urlChange.js";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
let tabsCount = 0;
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
Colors.map(
|
|
7
|
-
(color) =>
|
|
8
|
-
`
|
|
9
|
-
&.tabs.solid.${color} {
|
|
10
|
-
}
|
|
11
|
-
`
|
|
12
|
-
).join("\n");
|
|
13
|
-
|
|
14
|
-
export default function (context, options = {}) {
|
|
5
|
+
export default function (context, options) {
|
|
15
6
|
const { bau, css, window } = context;
|
|
16
7
|
const { tabDefs } = options;
|
|
17
8
|
const { div, ul, li, a } = bau.tags;
|
|
@@ -39,6 +30,11 @@ export default function (context, options = {}) {
|
|
|
39
30
|
padding: 0.6rem 1rem 0.6rem 1rem;
|
|
40
31
|
color: inherit;
|
|
41
32
|
text-decoration: none;
|
|
33
|
+
/* Inside the li, which hides its overflow */
|
|
34
|
+
&:focus-visible {
|
|
35
|
+
outline: 2px solid var(--color-primary);
|
|
36
|
+
outline-offset: -2px;
|
|
37
|
+
}
|
|
42
38
|
}
|
|
43
39
|
text-align: center;
|
|
44
40
|
color: inherit;
|
|
@@ -47,8 +43,7 @@ export default function (context, options = {}) {
|
|
|
47
43
|
transition: var(--transition-fast) ease-in-out;
|
|
48
44
|
overflow: hidden;
|
|
49
45
|
&:hover {
|
|
50
|
-
color: var(--color-primary-
|
|
51
|
-
background-color: var(--color-emphasis-200);
|
|
46
|
+
color: var(--color-primary-text);
|
|
52
47
|
}
|
|
53
48
|
&::after {
|
|
54
49
|
transition: var(--transition-fast) ease-in-out;
|
|
@@ -77,49 +72,38 @@ export default function (context, options = {}) {
|
|
|
77
72
|
}
|
|
78
73
|
}
|
|
79
74
|
}
|
|
80
|
-
${colorsToCss()}
|
|
81
75
|
`;
|
|
82
76
|
|
|
83
|
-
return function Tabs(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
...props
|
|
91
|
-
},
|
|
92
|
-
] = toPropsAndChildren(args);
|
|
93
|
-
|
|
77
|
+
return function Tabs({
|
|
78
|
+
size = options.size ?? "md",
|
|
79
|
+
variant = options.variant ?? "plain",
|
|
80
|
+
color = options.color ?? "neutral",
|
|
81
|
+
tabsKey = "tabs",
|
|
82
|
+
...props
|
|
83
|
+
} = {}) {
|
|
94
84
|
const tabsState = bau.state(tabDefs);
|
|
95
85
|
const tabByName = (name) => tabsState.val.find((tab) => tab.name == name);
|
|
96
86
|
const tabCurrentState = bau.state(tabDefs[0]);
|
|
97
87
|
|
|
88
|
+
const tabsId = `tabs-${++tabsCount}`;
|
|
89
|
+
const panelId = `${tabsId}-panel`;
|
|
90
|
+
// An id has no space: the name is encoded
|
|
91
|
+
const tabId = (name) => `${tabsId}-tab-${encodeURIComponent(name)}`;
|
|
92
|
+
|
|
98
93
|
const hashchange = () => {
|
|
99
|
-
//console.log("tabs hashchange");
|
|
100
94
|
const search = new URLSearchParams(window.location.search);
|
|
101
95
|
const tabName = search.get(tabsKey) ?? tabDefs[0].name;
|
|
96
|
+
const nextTab = tabByName(tabName);
|
|
102
97
|
|
|
103
|
-
if (tabName != tabCurrentState.val.name) {
|
|
104
|
-
const nextTab = tabByName(tabName);
|
|
98
|
+
if (nextTab && tabName != tabCurrentState.val.name) {
|
|
105
99
|
tabCurrentState.val.exit?.call();
|
|
106
100
|
tabCurrentState.val = nextTab;
|
|
107
|
-
nextTab
|
|
101
|
+
nextTab.enter?.call();
|
|
108
102
|
}
|
|
109
103
|
};
|
|
110
104
|
|
|
111
105
|
hashchange();
|
|
112
|
-
|
|
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
|
-
//console.log("tabs pushState ", url);
|
|
118
|
-
if (["?", "#"].includes(url[0])) {
|
|
119
|
-
hashchange();
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
});
|
|
106
|
+
let removeUrlListener;
|
|
123
107
|
|
|
124
108
|
const buildHref = (nextTab) => {
|
|
125
109
|
const search = new URLSearchParams(window.location.search);
|
|
@@ -128,19 +112,66 @@ export default function (context, options = {}) {
|
|
|
128
112
|
return `?${search.toString()}`;
|
|
129
113
|
};
|
|
130
114
|
|
|
115
|
+
// The tab is in the url, for the back button and the links
|
|
116
|
+
const selectTab = ({ name, disabled }) => {
|
|
117
|
+
if (!disabled && name != tabCurrentState.val.name) {
|
|
118
|
+
window.history.pushState({}, "", buildHref(name));
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
131
122
|
const TabHeader = (tab) => {
|
|
132
123
|
const { Header, disabled, name } = tab;
|
|
124
|
+
const selected = () => tabCurrentState.val.name == name;
|
|
133
125
|
return li(
|
|
134
126
|
{
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
disabled && "disabled",
|
|
138
|
-
],
|
|
127
|
+
role: "presentation",
|
|
128
|
+
class: () => [selected() && "active", disabled && "disabled"],
|
|
139
129
|
},
|
|
140
|
-
a(
|
|
130
|
+
a(
|
|
131
|
+
{
|
|
132
|
+
role: "tab",
|
|
133
|
+
id: tabId(name),
|
|
134
|
+
href: buildHref(name),
|
|
135
|
+
"aria-controls": panelId,
|
|
136
|
+
"aria-selected": () => String(selected()),
|
|
137
|
+
"aria-disabled": disabled ? "true" : undefined,
|
|
138
|
+
// One Tab stop: the selected tab; the arrow keys move between them
|
|
139
|
+
tabindex: () => (selected() ? "0" : "-1"),
|
|
140
|
+
onclick: (event) => {
|
|
141
|
+
const { button, metaKey, ctrlKey, shiftKey, altKey } = event;
|
|
142
|
+
// Opened in another tab or window by the browser
|
|
143
|
+
if (button || metaKey || ctrlKey || shiftKey || altKey) return;
|
|
144
|
+
event.preventDefault();
|
|
145
|
+
selectTab(tab);
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
Header(tab)
|
|
149
|
+
)
|
|
141
150
|
);
|
|
142
151
|
};
|
|
143
152
|
|
|
153
|
+
// The arrow keys, Home and End select a tab, the disabled ones are skipped
|
|
154
|
+
const onkeydown = (event) => {
|
|
155
|
+
const enabled = tabsState.val.filter(({ disabled }) => !disabled);
|
|
156
|
+
const index = enabled.findIndex(
|
|
157
|
+
({ name }) => name == tabCurrentState.val.name
|
|
158
|
+
);
|
|
159
|
+
const last = enabled.length - 1;
|
|
160
|
+
const nextIndex = {
|
|
161
|
+
ArrowRight: index >= last ? 0 : index + 1,
|
|
162
|
+
ArrowDown: index >= last ? 0 : index + 1,
|
|
163
|
+
ArrowLeft: index <= 0 ? last : index - 1,
|
|
164
|
+
ArrowUp: index <= 0 ? last : index - 1,
|
|
165
|
+
Home: 0,
|
|
166
|
+
End: last,
|
|
167
|
+
}[event.key];
|
|
168
|
+
if (nextIndex == undefined || !enabled[nextIndex]) return;
|
|
169
|
+
event.preventDefault();
|
|
170
|
+
const nextTab = enabled[nextIndex];
|
|
171
|
+
selectTab(nextTab);
|
|
172
|
+
document.getElementById(tabId(nextTab.name))?.focus();
|
|
173
|
+
};
|
|
174
|
+
|
|
144
175
|
const rootEl = div(
|
|
145
176
|
{
|
|
146
177
|
class: [
|
|
@@ -152,22 +183,27 @@ export default function (context, options = {}) {
|
|
|
152
183
|
options?.class,
|
|
153
184
|
props.class,
|
|
154
185
|
],
|
|
155
|
-
bauMounted: (
|
|
156
|
-
window
|
|
157
|
-
},
|
|
158
|
-
bauUnmounted: () => {
|
|
159
|
-
window.removeEventListener("popstate", hashchange);
|
|
186
|
+
bauMounted: () => {
|
|
187
|
+
removeUrlListener = onUrlChange(window, hashchange);
|
|
160
188
|
},
|
|
189
|
+
bauUnmounted: () => removeUrlListener?.(),
|
|
161
190
|
},
|
|
162
191
|
// Header
|
|
163
|
-
bau.loop(tabsState, ul(), TabHeader),
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
(
|
|
169
|
-
|
|
170
|
-
|
|
192
|
+
bau.loop(tabsState, ul({ role: "tablist", onkeydown }), TabHeader),
|
|
193
|
+
div(
|
|
194
|
+
{
|
|
195
|
+
role: "tabpanel",
|
|
196
|
+
id: panelId,
|
|
197
|
+
"aria-labelledby": () => tabId(tabCurrentState.val.name),
|
|
198
|
+
},
|
|
199
|
+
bau.bind({
|
|
200
|
+
deps: [tabCurrentState],
|
|
201
|
+
render:
|
|
202
|
+
() =>
|
|
203
|
+
({ Content }) =>
|
|
204
|
+
Content ? Content(props) : "",
|
|
205
|
+
})
|
|
206
|
+
)
|
|
171
207
|
);
|
|
172
208
|
|
|
173
209
|
rootEl.addEventListener(
|
|
@@ -1,22 +1,9 @@
|
|
|
1
|
-
import { Colors } from "../constants.js";
|
|
2
|
-
|
|
3
|
-
const colorsToCss = () =>
|
|
4
|
-
Colors.map(
|
|
5
|
-
(color) =>
|
|
6
|
-
`
|
|
7
|
-
`
|
|
8
|
-
).join("\n");
|
|
9
|
-
|
|
10
1
|
// Inspired by https://css-tricks.com/auto-growing-inputs-textareas/#aa-other-ideas
|
|
11
2
|
|
|
12
3
|
export default function (context, options = {}) {
|
|
13
4
|
const { bau, css } = context;
|
|
14
5
|
const { textarea, div } = bau.tags;
|
|
15
6
|
|
|
16
|
-
const oninput = (event) => {
|
|
17
|
-
event.target.parentNode.dataset.value = event.target.value;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
7
|
return function TextareaAutosize({
|
|
21
8
|
size = options.size ?? "md",
|
|
22
9
|
color = options.color ?? "primary",
|
|
@@ -24,7 +11,6 @@ export default function (context, options = {}) {
|
|
|
24
11
|
...otherProps
|
|
25
12
|
} = {}) {
|
|
26
13
|
const className = css`
|
|
27
|
-
${colorsToCss()}
|
|
28
14
|
display: inline-grid;
|
|
29
15
|
&::after,
|
|
30
16
|
textarea {
|
|
@@ -39,11 +25,22 @@ export default function (context, options = {}) {
|
|
|
39
25
|
}
|
|
40
26
|
`;
|
|
41
27
|
|
|
28
|
+
// The text sizes the textarea: copied in data-value, drawn hidden after
|
|
29
|
+
// it. The first value, and the one of a state.
|
|
30
|
+
const { value, defaultValue, oninput } = otherProps;
|
|
31
|
+
const valueOf = () =>
|
|
32
|
+
(value && typeof value == "object" ? value.val : value) ??
|
|
33
|
+
defaultValue ??
|
|
34
|
+
"";
|
|
35
|
+
|
|
42
36
|
return div(
|
|
43
|
-
{ class: ["textarea-autosize", className] },
|
|
37
|
+
{ class: ["textarea-autosize", className], "data-value": valueOf },
|
|
44
38
|
textarea({
|
|
45
39
|
...otherProps,
|
|
46
|
-
oninput
|
|
40
|
+
oninput: (event) => {
|
|
41
|
+
event.target.parentNode.dataset.value = event.target.value;
|
|
42
|
+
oninput?.(event);
|
|
43
|
+
},
|
|
47
44
|
})
|
|
48
45
|
);
|
|
49
46
|
};
|
|
@@ -1,45 +1,29 @@
|
|
|
1
1
|
import { toPropsAndChildren } from "@grucloud/bau/bau.js";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
const defaultMode = "light";
|
|
5
|
-
|
|
6
|
-
const colorsToCss = () =>
|
|
7
|
-
Colors.map(
|
|
8
|
-
(color) =>
|
|
9
|
-
`
|
|
10
|
-
&.theme-switch.outline.${color} {
|
|
11
|
-
color: var(--color-${color})
|
|
12
|
-
}
|
|
13
|
-
`
|
|
14
|
-
).join("\n");
|
|
2
|
+
import { ofColor } from "../constants.js";
|
|
15
3
|
|
|
16
4
|
export default function (context, options = {}) {
|
|
17
5
|
const { bau, css, window } = context;
|
|
18
6
|
const { input } = bau.tags;
|
|
19
7
|
|
|
8
|
+
// The theme is kept for the next visit, when the storage is allowed
|
|
20
9
|
const setDataThemeAttribute = (theme) => {
|
|
21
10
|
window.document.documentElement.setAttribute("data-theme", theme);
|
|
22
|
-
localStorage.setItem("theme", theme);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const getStoredTheme = () => {
|
|
26
11
|
try {
|
|
27
|
-
|
|
12
|
+
localStorage.setItem("theme", theme);
|
|
28
13
|
} catch (err) {}
|
|
29
14
|
};
|
|
30
15
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
16
|
+
// The theme stored, else the one of the system, light by default
|
|
17
|
+
let storedTheme;
|
|
18
|
+
try {
|
|
19
|
+
storedTheme = localStorage.getItem("theme");
|
|
20
|
+
} catch (err) {}
|
|
21
|
+
setDataThemeAttribute(
|
|
22
|
+
storedTheme ??
|
|
23
|
+
(window.matchMedia("(prefers-color-scheme: dark)").matches
|
|
24
|
+
? "dark"
|
|
25
|
+
: "light")
|
|
26
|
+
);
|
|
43
27
|
|
|
44
28
|
const className = css`
|
|
45
29
|
position: relative;
|
|
@@ -49,29 +33,25 @@ export default function (context, options = {}) {
|
|
|
49
33
|
border-radius: var(--global-radius);
|
|
50
34
|
appearance: none;
|
|
51
35
|
transition: all var(--transition-fast);
|
|
52
|
-
&:hover {
|
|
53
|
-
cursor: pointer;
|
|
54
|
-
}
|
|
55
36
|
&::after {
|
|
56
37
|
content: "\u2600";
|
|
57
38
|
font-size: x-large;
|
|
58
39
|
transition: all var(--transition-fast);
|
|
59
40
|
}
|
|
60
|
-
&:checked {
|
|
61
|
-
}
|
|
62
41
|
&:checked::after {
|
|
63
42
|
content: "\u263D";
|
|
64
|
-
font-size: x-large;
|
|
65
43
|
}
|
|
66
44
|
&:hover {
|
|
45
|
+
cursor: pointer;
|
|
67
46
|
filter: brightness(var(--brightness-hover));
|
|
68
47
|
}
|
|
69
48
|
&:hover.solid {
|
|
70
49
|
filter: brightness(var(--brightness-hover-always));
|
|
71
50
|
}
|
|
72
51
|
&.sm {
|
|
73
|
-
|
|
74
|
-
|
|
52
|
+
/* WCAG 2.5.8, the size of a target */
|
|
53
|
+
width: max(24px, 1.7rem);
|
|
54
|
+
height: max(24px, 1.7rem);
|
|
75
55
|
}
|
|
76
56
|
&.sm::after {
|
|
77
57
|
font-size: 1rem;
|
|
@@ -90,7 +70,9 @@ export default function (context, options = {}) {
|
|
|
90
70
|
&.lg::after {
|
|
91
71
|
font-size: 2.3rem;
|
|
92
72
|
}
|
|
93
|
-
${
|
|
73
|
+
&.theme-switch.outline${ofColor} {
|
|
74
|
+
color: var(--accent-text);
|
|
75
|
+
}
|
|
94
76
|
`;
|
|
95
77
|
|
|
96
78
|
return function ThemeSwitch(...args) {
|
|
@@ -106,7 +88,9 @@ export default function (context, options = {}) {
|
|
|
106
88
|
|
|
107
89
|
return input(
|
|
108
90
|
{
|
|
109
|
-
|
|
91
|
+
// Read as "Dark theme, switch, on"
|
|
92
|
+
role: "switch",
|
|
93
|
+
"aria-label": "Dark theme",
|
|
110
94
|
title: "Switch Theme",
|
|
111
95
|
name: "theme-switch",
|
|
112
96
|
...props,
|
|
@@ -120,7 +104,9 @@ export default function (context, options = {}) {
|
|
|
120
104
|
props.class,
|
|
121
105
|
],
|
|
122
106
|
type: "checkbox",
|
|
123
|
-
|
|
107
|
+
// The theme shown, stored or the one of the system
|
|
108
|
+
checked:
|
|
109
|
+
window.document.documentElement.getAttribute("data-theme") == "dark",
|
|
124
110
|
onclick: (event) => {
|
|
125
111
|
setDataThemeAttribute(event.target.checked ? "dark" : "light");
|
|
126
112
|
},
|
package/toggle/index.d.ts
CHANGED
|
@@ -2,7 +2,14 @@ declare module "@grucloud/bau-ui/toggle" {
|
|
|
2
2
|
type DefaultDesignProps = import("../constants").DefaultDesignProps;
|
|
3
3
|
type ComponentOption = import("../bau-ui").ComponentOption;
|
|
4
4
|
|
|
5
|
-
export type ToggleProps = {
|
|
5
|
+
export type ToggleProps = {
|
|
6
|
+
// Pressed or not: the toggle follows it, a boolean, a state or a function
|
|
7
|
+
// reading states. Without it, the toggle is pressed and released by itself.
|
|
8
|
+
selected?:
|
|
9
|
+
| boolean
|
|
10
|
+
| import("@grucloud/bau").StateView<boolean>
|
|
11
|
+
| (() => boolean);
|
|
12
|
+
} & DefaultDesignProps;
|
|
6
13
|
|
|
7
14
|
type Component = import("../bau-ui").Component<
|
|
8
15
|
ToggleProps,
|
package/toggle/toggle.js
CHANGED
|
@@ -32,11 +32,13 @@ export default function (context, options = {}) {
|
|
|
32
32
|
transition: all var(--transition-slow);
|
|
33
33
|
box-sizing: border-box;
|
|
34
34
|
cursor: pointer;
|
|
35
|
-
&[selected="true"]
|
|
35
|
+
&[selected="true"],
|
|
36
|
+
&[aria-pressed="true"] {
|
|
36
37
|
background-color: var(--toggle-background-color);
|
|
37
38
|
box-shadow: var(--shadow-lg);
|
|
38
39
|
}
|
|
39
|
-
&[selected="true"].solid
|
|
40
|
+
&[selected="true"].solid,
|
|
41
|
+
&[aria-pressed="true"].solid {
|
|
40
42
|
filter: brightness(80%) !important;
|
|
41
43
|
}
|
|
42
44
|
&.outline,
|
|
@@ -71,6 +73,9 @@ export default function (context, options = {}) {
|
|
|
71
73
|
variant = options.variant ?? "outline",
|
|
72
74
|
color = options.color ?? "neutral",
|
|
73
75
|
onclick,
|
|
76
|
+
selected,
|
|
77
|
+
// Controlled by selected, a boolean or a state, or pressed at first
|
|
78
|
+
"aria-pressed": pressed = selected ?? "false",
|
|
74
79
|
...props
|
|
75
80
|
},
|
|
76
81
|
children,
|
|
@@ -80,14 +85,17 @@ export default function (context, options = {}) {
|
|
|
80
85
|
{
|
|
81
86
|
type: "button",
|
|
82
87
|
...props,
|
|
88
|
+
selected,
|
|
89
|
+
"aria-pressed": pressed,
|
|
83
90
|
onclick: (event) => {
|
|
84
|
-
|
|
85
|
-
//
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
// The button, not the icon clicked in it. Pressed or released by
|
|
92
|
+
// itself, unless selected drives it.
|
|
93
|
+
const button = event.currentTarget;
|
|
94
|
+
selected === undefined &&
|
|
95
|
+
button.setAttribute(
|
|
96
|
+
"aria-pressed",
|
|
97
|
+
button.getAttribute("aria-pressed") == "true" ? "false" : "true"
|
|
98
|
+
);
|
|
91
99
|
onclick && onclick(event);
|
|
92
100
|
},
|
|
93
101
|
|
|
@@ -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
|
-
&.toggle-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
|
-
&.toggle-group.outline.${color} {
|
|
18
|
-
border: none;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
&.toggle-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;
|
|
@@ -40,7 +15,24 @@ export default function (context, options = {}) {
|
|
|
40
15
|
border-top-left-radius: 0;
|
|
41
16
|
border-bottom-left-radius: 0;
|
|
42
17
|
}
|
|
43
|
-
${
|
|
18
|
+
&.toggle-group${ofColor} {
|
|
19
|
+
& button:not(:last-child) {
|
|
20
|
+
border-right: 1px solid var(--accent-text) !important;
|
|
21
|
+
}
|
|
22
|
+
& button:not(:first-child) {
|
|
23
|
+
border-left: 1px solid var(--accent-text) !important;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
&.toggle-group.outline${ofColor} {
|
|
28
|
+
border: none;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
&.toggle-group.solid${ofColor} {
|
|
32
|
+
& button:not(:last-child) {
|
|
33
|
+
border-right: 1px solid var(--accent-lightest) !important;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
44
36
|
`;
|
|
45
37
|
|
|
46
38
|
return function ToggleGroup(...args) {
|
|
@@ -59,7 +51,9 @@ export default function (context, options = {}) {
|
|
|
59
51
|
const selectedSet = new Set();
|
|
60
52
|
|
|
61
53
|
const onclick = (event) => {
|
|
62
|
-
const
|
|
54
|
+
const toggle = event.target.closest("button");
|
|
55
|
+
if (!toggle) return;
|
|
56
|
+
const { value } = toggle;
|
|
63
57
|
if (exclusive) {
|
|
64
58
|
selectedSet.clear();
|
|
65
59
|
selectedSet.add(value);
|
|
@@ -75,6 +69,7 @@ export default function (context, options = {}) {
|
|
|
75
69
|
|
|
76
70
|
return div(
|
|
77
71
|
{
|
|
72
|
+
role: "group",
|
|
78
73
|
...props,
|
|
79
74
|
class: [
|
|
80
75
|
"toggle-group",
|