material 3.13.1 → 3.14.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/README.md +28 -1
- package/dist/components/bottom-app-bar-toolbar/index.d.ts +8 -0
- package/dist/components/bottom-app-bar-toolbar/index.js +66 -0
- package/dist/components/bottom-app-bar-toolbar/structure.js +18 -0
- package/dist/components/chips/chip/chip.js +6 -4
- package/dist/components/dialog/features.js +9 -24
- package/dist/components/fab-menu/fab-menu.js +5 -6
- package/dist/components/fab-menu/index.d.ts +7 -0
- package/dist/components/listbox/index.d.ts +100 -0
- package/dist/components/listbox/index.js +1 -0
- package/dist/components/listbox/listbox.js +633 -0
- package/dist/elements/preupgrade/badge.css +1 -1
- package/dist/elements/preupgrade/bottom-app-bar.css +1 -1
- package/dist/elements/preupgrade/bottom-sheet.css +1 -1
- package/dist/elements/preupgrade/button-group.css +1 -1
- package/dist/elements/preupgrade/button.css +1 -1
- package/dist/elements/preupgrade/card.css +1 -1
- package/dist/elements/preupgrade/carousel.css +1 -1
- package/dist/elements/preupgrade/checkbox.css +1 -1
- package/dist/elements/preupgrade/chips.css +1 -1
- package/dist/elements/preupgrade/datepicker.css +1 -1
- package/dist/elements/preupgrade/dialog.css +1 -1
- package/dist/elements/preupgrade/divider.css +1 -1
- package/dist/elements/preupgrade/drawer.css +1 -1
- package/dist/elements/preupgrade/extended-fab.css +1 -1
- package/dist/elements/preupgrade/fab-menu.css +1 -1
- package/dist/elements/preupgrade/fab.css +1 -1
- package/dist/elements/preupgrade/icon-button.css +1 -1
- package/dist/elements/preupgrade/list.css +1 -1
- package/dist/elements/preupgrade/loading-indicator.css +1 -1
- package/dist/elements/preupgrade/menu.css +1 -1
- package/dist/elements/preupgrade/navigation-bar.css +1 -1
- package/dist/elements/preupgrade/navigation-rail.css +1 -1
- package/dist/elements/preupgrade/progress.css +1 -1
- package/dist/elements/preupgrade/radios.css +1 -1
- package/dist/elements/preupgrade/search.css +1 -1
- package/dist/elements/preupgrade/select.css +1 -1
- package/dist/elements/preupgrade/side-sheet.css +1 -1
- package/dist/elements/preupgrade/slider.css +1 -1
- package/dist/elements/preupgrade/snackbar.css +1 -1
- package/dist/elements/preupgrade/split-button.css +1 -1
- package/dist/elements/preupgrade/switch.css +1 -1
- package/dist/elements/preupgrade/tabs.css +1 -1
- package/dist/elements/preupgrade/text-field.css +1 -1
- package/dist/elements/preupgrade/timepicker.css +1 -1
- package/dist/elements/preupgrade/toolbar.css +1 -1
- package/dist/elements/preupgrade/tooltip.css +1 -1
- package/dist/elements/preupgrade/top-app-bar.css +1 -1
- package/dist/elements/preupgrade.css +1 -1
- package/dist/styles/badge.css +1 -1
- package/dist/styles/base-elements.css +1 -1
- package/dist/styles/base-lite.css +1 -1
- package/dist/styles/base.css +1 -1
- package/dist/styles/bottom-app-bar-toolbar.css +2 -0
- package/dist/styles/bottom-app-bar-toolbar.js +2 -0
- package/dist/styles/bottom-app-bar.css +1 -1
- package/dist/styles/bottom-sheet.css +1 -1
- package/dist/styles/button-filled-small-round.css +1 -1
- package/dist/styles/button-group.css +1 -1
- package/dist/styles/button.css +1 -1
- package/dist/styles/card.css +1 -1
- package/dist/styles/carousel.css +1 -1
- package/dist/styles/checkbox.css +1 -1
- package/dist/styles/chips.css +1 -1
- package/dist/styles/contrast.css +1 -1
- package/dist/styles/datepicker.css +1 -1
- package/dist/styles/dialog.css +1 -1
- package/dist/styles/divider.css +1 -1
- package/dist/styles/drawer.css +1 -1
- package/dist/styles/extended-fab.css +1 -1
- package/dist/styles/fab-menu.css +1 -1
- package/dist/styles/fab.css +1 -1
- package/dist/styles/icon-button.css +1 -1
- package/dist/styles/list.css +1 -1
- package/dist/styles/listbox.css +2 -0
- package/dist/styles/listbox.js +2 -0
- package/dist/styles/loading-indicator.css +1 -1
- package/dist/styles/menu.css +1 -1
- package/dist/styles/navigation-bar.css +1 -1
- package/dist/styles/navigation-rail.css +1 -1
- package/dist/styles/progress.css +1 -1
- package/dist/styles/radios.css +1 -1
- package/dist/styles/search.css +1 -1
- package/dist/styles/select.css +1 -1
- package/dist/styles/side-sheet.css +1 -1
- package/dist/styles/slider.css +1 -1
- package/dist/styles/snackbar.css +1 -1
- package/dist/styles/split-button.css +1 -1
- package/dist/styles/switch.css +1 -1
- package/dist/styles/tabs.css +1 -1
- package/dist/styles/text-field.css +1 -1
- package/dist/styles/timepicker.css +1 -1
- package/dist/styles/toolbar.css +1 -1
- package/dist/styles/tooltip.css +1 -1
- package/dist/styles/top-app-bar.css +1 -1
- package/dist/styles/typography.css +1 -1
- package/dist/styles/utilities.css +1 -1
- package/dist/styles.css +1 -1
- package/dist/themes/autumn-contrast.css +1 -1
- package/dist/themes/autumn.css +1 -1
- package/dist/themes/baseline-contrast.css +1 -1
- package/dist/themes/baseline.css +1 -1
- package/dist/themes/brownbeige-contrast.css +1 -1
- package/dist/themes/brownbeige.css +1 -1
- package/dist/themes/content-contrast.css +1 -1
- package/dist/themes/content.css +1 -1
- package/dist/themes/desert-contrast.css +1 -1
- package/dist/themes/desert.css +1 -1
- package/dist/themes/expressive-contrast.css +1 -1
- package/dist/themes/expressive.css +1 -1
- package/dist/themes/fidelity-contrast.css +1 -1
- package/dist/themes/fidelity.css +1 -1
- package/dist/themes/forest-contrast.css +1 -1
- package/dist/themes/forest.css +1 -1
- package/dist/themes/fruit-salad-contrast.css +1 -1
- package/dist/themes/fruit-salad.css +1 -1
- package/dist/themes/highcontrast-contrast.css +1 -1
- package/dist/themes/highcontrast.css +1 -1
- package/dist/themes/monochrome-contrast.css +1 -1
- package/dist/themes/monochrome.css +1 -1
- package/dist/themes/neutral-contrast.css +1 -1
- package/dist/themes/neutral.css +1 -1
- package/dist/themes/ocean-contrast.css +1 -1
- package/dist/themes/ocean.css +1 -1
- package/dist/themes/rainbow-contrast.css +1 -1
- package/dist/themes/rainbow.css +1 -1
- package/dist/themes/sageivory-contrast.css +1 -1
- package/dist/themes/sageivory.css +1 -1
- package/dist/themes/spring-contrast.css +1 -1
- package/dist/themes/spring.css +1 -1
- package/dist/themes/summer-contrast.css +1 -1
- package/dist/themes/summer.css +1 -1
- package/dist/themes/sunset-contrast.css +1 -1
- package/dist/themes/sunset.css +1 -1
- package/dist/themes/tealcaramel-contrast.css +1 -1
- package/dist/themes/tealcaramel.css +1 -1
- package/dist/themes/vibrant-contrast.css +1 -1
- package/dist/themes/vibrant.css +1 -1
- package/dist/tokens/catalogue.json +3 -3
- package/package.json +19 -1
- package/src/styles/components/_listbox.scss +95 -0
package/README.md
CHANGED
|
@@ -66,6 +66,31 @@ Import `material/styles/button` for any other variant, size or shape. This inclu
|
|
|
66
66
|
|
|
67
67
|
Every component comes three ways: a factory, a custom element and a framework component. Each has a page with a playground on [md3.io/components](https://md3.io/components/).
|
|
68
68
|
|
|
69
|
+
## Bottom app bar compatibility entry
|
|
70
|
+
|
|
71
|
+
The experimental `material/components/bottom-app-bar-toolbar` factory keeps the legacy bottom app bar API with docked-toolbar styling. Import its stylesheet explicitly, including on pages using the full stylesheet:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import createBottomAppBarToolbar from 'material/components/bottom-app-bar-toolbar';
|
|
75
|
+
import 'material/styles/base';
|
|
76
|
+
import 'material/styles/bottom-app-bar-toolbar';
|
|
77
|
+
|
|
78
|
+
const save = document.createElement('button');
|
|
79
|
+
save.type = 'button';
|
|
80
|
+
save.textContent = 'Save';
|
|
81
|
+
const bar = createBottomAppBarToolbar({ autoHide: true });
|
|
82
|
+
bar.addAction(save);
|
|
83
|
+
document.body.append(bar.element);
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Use it when a factory screen needs legacy chaining, native Tab order, live action containers, a centred or late-added FAB, or custom transition duration. It is absent from the root export and has no element, framework adapter or SSR registration.
|
|
87
|
+
|
|
88
|
+
For new screens, use the docked toolbar from `material/components/toolbar`. The legacy `createBottomAppBar` is deprecated in 3.x but remains available with its existing behaviour. See the [migration note](https://github.com/floor/material/blob/main/MIGRATING.md#bottom-app-bar-in-3x).
|
|
89
|
+
|
|
90
|
+
The [implementation measurements](https://github.com/floor/material#measured-entry-cost) record 4,386 B gzip for the compatibility JavaScript graph versus 4,248 B for the legacy graph. A standalone styled Vite page needs 11,157 B initially versus 7,358 B, with no deferred bytes; caller-owned controls, fonts, external icons and HTML are outside those costs.
|
|
91
|
+
|
|
92
|
+
That snapshot added 1,655 B compressed, 7,158 B unpacked and five package files. Root and existing default payloads were byte-identical; the entry provides no root or default-bundle saving.
|
|
93
|
+
|
|
69
94
|
## Web components
|
|
70
95
|
|
|
71
96
|
A page imports the base stylesheet and the elements' CSS once, then registers the elements with `defineAll()`. After that `<m-button>` and the rest are HTML, in plain pages, server templates and any framework.
|
|
@@ -87,7 +112,9 @@ The framework components render the elements, load their CSS and register each o
|
|
|
87
112
|
|
|
88
113
|
`renderElement` from `material/ssr` renders an element to declarative shadow DOM. Each framework has a bridge, such as `material/ssr/react`, that makes its components emit the same roots and hydrate.
|
|
89
114
|
|
|
90
|
-
Node and Bun
|
|
115
|
+
Node and Bun use the server entries. Under the `workerd` and `worker` export conditions, the SSR entry and its four bridges select those same server entries ahead of browser; enabling `worker` selects server code even for a client worker. Browser-only builds keep the safe-to-import stub, whose retained `renderElement` call throws "material/ssr is server-only".
|
|
116
|
+
|
|
117
|
+
Wrangler selects `workerd`. For Vite webworker SSR, set `ssr.target: "webworker"` and `ssr.noExternal: ["material"]`; also set `ssr.resolve.conditions: ["workerd", "worker", "browser"]` so default webworker browser conditions do not select the stub. CI checks the packed package and four framework renders in pinned workerd without Node compatibility. Guide: [md3.io/docs/server-rendering](https://md3.io/docs/server-rendering/).
|
|
91
118
|
|
|
92
119
|
## Themes
|
|
93
120
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BottomAppBarConfig, BottomAppBarComponent } from "../bottom-app-bar/index.js";
|
|
2
|
+
export type { BottomAppBarConfig as BottomAppBarToolbarConfig, BottomAppBarComponent as BottomAppBarToolbarComponent } from "../bottom-app-bar/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Self-contained opt-in bottom app bar with docked styling and legacy policy.
|
|
5
|
+
* @param config
|
|
6
|
+
*/
|
|
7
|
+
export declare function createBottomAppBarToolbar(config?: BottomAppBarConfig): BottomAppBarComponent;
|
|
8
|
+
export default createBottomAppBarToolbar;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { processClassNames } from "../../core/config/component.js";
|
|
2
|
+
import { getCleanup } from "../../core/compose/cleanup.js";
|
|
3
|
+
import { PREFIX } from "../../core/config.js";
|
|
4
|
+
import { createConfig } from "../bottom-app-bar/config.js";
|
|
5
|
+
import { createToolbarStructure, createToolbarFab } from "./structure.js";
|
|
6
|
+
export function createBottomAppBarToolbar(config = {}) {
|
|
7
|
+
const settings = createConfig(config);
|
|
8
|
+
const block = `${PREFIX}-bottom-app-bar`;
|
|
9
|
+
const { component, bar } = createToolbarStructure(settings, {
|
|
10
|
+
tag: settings.tag,
|
|
11
|
+
componentName: "bottom-app-bar",
|
|
12
|
+
className: [
|
|
13
|
+
`${PREFIX}-toolbar`, `${PREFIX}-toolbar--docked`, `${PREFIX}-toolbar--bottom`, `${PREFIX}-toolbar--standard`,
|
|
14
|
+
`${block}-toolbar`,
|
|
15
|
+
settings.hasFab ? `${block}--with-fab` : "",
|
|
16
|
+
settings.fabPosition === "center" ? `${block}--fab-center` : "",
|
|
17
|
+
processClassNames(settings.className || ""),
|
|
18
|
+
].filter(Boolean),
|
|
19
|
+
attributes: { role: "toolbar", "aria-label": "Bottom app bar" },
|
|
20
|
+
interactive: true,
|
|
21
|
+
}, `${PREFIX}-toolbar__bar ${block}__actions`, {});
|
|
22
|
+
const root = component.element;
|
|
23
|
+
const fab = createToolbarFab(root, `${PREFIX}-toolbar__fab ${block}__fab-container`);
|
|
24
|
+
const resources = getCleanup(component);
|
|
25
|
+
let visible = true;
|
|
26
|
+
let previous = window.scrollY;
|
|
27
|
+
const setVisible = (next) => {
|
|
28
|
+
root.classList.toggle(`${block}--hidden`, !next);
|
|
29
|
+
const changed = visible !== next;
|
|
30
|
+
visible = next;
|
|
31
|
+
if (changed)
|
|
32
|
+
settings.onVisibilityChange?.(next);
|
|
33
|
+
};
|
|
34
|
+
const api = {
|
|
35
|
+
...component,
|
|
36
|
+
addClass(...classes) { component.addClass(...classes); return this; },
|
|
37
|
+
addAction(action) { bar.appendChild(action); return this; },
|
|
38
|
+
addFab(element) {
|
|
39
|
+
fab.replaceChildren(element);
|
|
40
|
+
root.classList.add(`${block}--with-fab`);
|
|
41
|
+
return this;
|
|
42
|
+
},
|
|
43
|
+
getActionsContainer() { return bar; },
|
|
44
|
+
show() { setVisible(true); return this; },
|
|
45
|
+
hide() { setVisible(false); return this; },
|
|
46
|
+
isVisible() { return visible; },
|
|
47
|
+
destroy() { component.lifecycle.destroy(); },
|
|
48
|
+
};
|
|
49
|
+
if (settings.autoHide) {
|
|
50
|
+
const scroll = () => {
|
|
51
|
+
const current = window.scrollY;
|
|
52
|
+
if (current > previous + 10 && visible)
|
|
53
|
+
api.hide();
|
|
54
|
+
else if (current < previous - 10 && !visible)
|
|
55
|
+
api.show();
|
|
56
|
+
previous = current;
|
|
57
|
+
};
|
|
58
|
+
window.addEventListener("scroll", scroll, { passive: true });
|
|
59
|
+
resources.add(() => window.removeEventListener("scroll", scroll));
|
|
60
|
+
}
|
|
61
|
+
if (settings.autoHide && settings.transitionDuration) {
|
|
62
|
+
root.style.transition = `transform ${settings.transitionDuration}ms ease-in-out`;
|
|
63
|
+
}
|
|
64
|
+
return api;
|
|
65
|
+
}
|
|
66
|
+
export default createBottomAppBarToolbar;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { pipe } from "../../core/compose/pipe.js";
|
|
2
|
+
import { createBase, withElement } from "../../core/compose/component.js";
|
|
3
|
+
import { withEvents, withLifecycle } from "../../core/compose/features/index.js";
|
|
4
|
+
export function createToolbarStructure(settings, options, barClass, attributes) {
|
|
5
|
+
const component = pipe(createBase, withEvents(), withElement(options), withLifecycle())(settings);
|
|
6
|
+
const bar = document.createElement("div");
|
|
7
|
+
bar.className = barClass;
|
|
8
|
+
for (const [name, value] of Object.entries(attributes))
|
|
9
|
+
bar.setAttribute(name, value);
|
|
10
|
+
component.element.appendChild(bar);
|
|
11
|
+
return { component, bar };
|
|
12
|
+
}
|
|
13
|
+
export function createToolbarFab(root, className, before = null) {
|
|
14
|
+
const fab = document.createElement("div");
|
|
15
|
+
fab.className = className;
|
|
16
|
+
root.insertBefore(fab, before);
|
|
17
|
+
return fab;
|
|
18
|
+
}
|
|
@@ -5,11 +5,13 @@ import { withEvents, withLifecycle } from "../../../core/compose/features/index.
|
|
|
5
5
|
import { createRipple } from "../../../core/compose/features/ripple.js";
|
|
6
6
|
import { createComponentConfig, createElementConfig } from "../../../core/config/component.js";
|
|
7
7
|
import { setHTML } from "../../../core/dom/html.js";
|
|
8
|
+
import { getIcon } from "../../../core/icons/registry.js";
|
|
8
9
|
const CHECK = '<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M9 16.2 4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z"/></svg>';
|
|
9
10
|
const DROP_DOWN = '<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M7 10l5 5 5-5z"/></svg>';
|
|
10
11
|
const CLOSE = '<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>';
|
|
11
12
|
const createChip = (config = {}) => {
|
|
12
13
|
const options = createComponentConfig({ type: "filter", ripple: true }, config, "chip");
|
|
14
|
+
const closeGlyph = getIcon("close", CLOSE);
|
|
13
15
|
const type = options.type ?? "filter";
|
|
14
16
|
const selectable = type === "filter" || type === "input";
|
|
15
17
|
const elementConfig = createElementConfig(options, { tag: "div" });
|
|
@@ -57,7 +59,7 @@ if (type === "input") {
|
|
|
57
59
|
remove = document.createElement("button");
|
|
58
60
|
remove.type = "button";
|
|
59
61
|
remove.className = base.getClass("chip__remove");
|
|
60
|
-
setHTML(remove, trailingIcon ||
|
|
62
|
+
setHTML(remove, trailingIcon || closeGlyph);
|
|
61
63
|
root.append(remove);
|
|
62
64
|
root.setAttribute("role", "group");
|
|
63
65
|
}
|
|
@@ -70,7 +72,7 @@ if (options.trailingMenu) {
|
|
|
70
72
|
trailingAction.setAttribute("aria-haspopup", "menu");
|
|
71
73
|
trailingAction.setAttribute("aria-expanded", "false");
|
|
72
74
|
}
|
|
73
|
-
setHTML(trailingAction, trailingIcon || (options.trailingMenu ? DROP_DOWN :
|
|
75
|
+
setHTML(trailingAction, trailingIcon || (options.trailingMenu ? DROP_DOWN : closeGlyph));
|
|
74
76
|
root.append(trailingAction);
|
|
75
77
|
root.setAttribute("role", "group");
|
|
76
78
|
}
|
|
@@ -162,9 +164,9 @@ setLeadingIcon,
|
|
|
162
164
|
setTrailingIcon(icon) {
|
|
163
165
|
trailingIcon = type === "suggestion" ? "" : icon;
|
|
164
166
|
if (trailingAction)
|
|
165
|
-
setHTML(trailingAction, trailingIcon || (options.trailingMenu ? DROP_DOWN :
|
|
167
|
+
setHTML(trailingAction, trailingIcon || (options.trailingMenu ? DROP_DOWN : closeGlyph));
|
|
166
168
|
else
|
|
167
|
-
setHTML(remove ?? trailing, trailingIcon || (remove ?
|
|
169
|
+
setHTML(remove ?? trailing, trailingIcon || (remove ? closeGlyph : ""));
|
|
168
170
|
render();
|
|
169
171
|
return api;
|
|
170
172
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import createButton from "../button/index.js";
|
|
2
2
|
import { addClass, removeClass } from "../../core/dom/classes.js";
|
|
3
3
|
import { setHTML } from "../../core/dom/html.js";
|
|
4
|
+
import { getIcon } from "../../core/icons/registry.js";
|
|
4
5
|
import { deepActiveElement, tabStops, wrapTab } from "../../core/dom/focus.js";
|
|
5
6
|
import { hideFromTopLayer, onModalEscape, onTopLayerClose, showInTopLayer } from "../../core/dom/layer.js";
|
|
6
7
|
const DIALOG_EVENTS = {
|
|
@@ -45,18 +46,16 @@ if (showCloseButton) {
|
|
|
45
46
|
const closeButton = document.createElement("button");
|
|
46
47
|
closeButton.classList.add(component.getClass("dialog__header-close"));
|
|
47
48
|
closeButton.setAttribute("aria-label", "Close dialog");
|
|
48
|
-
setHTML(closeButton, `
|
|
49
|
+
setHTML(closeButton, getIcon("close", `
|
|
49
50
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">
|
|
50
51
|
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
51
52
|
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
52
53
|
</svg>
|
|
53
|
-
`);
|
|
54
|
+
`));
|
|
54
55
|
closeButton.addEventListener("click", (e) => {
|
|
55
56
|
e.preventDefault();
|
|
56
57
|
e.stopPropagation();
|
|
57
|
-
if (component && component.emit) {
|
|
58
58
|
component.emit("dialog:close", { source: "closeButton" });
|
|
59
|
-
}
|
|
60
59
|
});
|
|
61
60
|
header.appendChild(closeButton);
|
|
62
61
|
}
|
|
@@ -209,10 +208,8 @@ console.error("Error in onClick handler:", err);
|
|
|
209
208
|
}
|
|
210
209
|
}
|
|
211
210
|
if (shouldClose) {
|
|
212
|
-
if (component && component.emit) {
|
|
213
211
|
component.emit("dialog:close", { source: "button", text });
|
|
214
212
|
}
|
|
215
|
-
}
|
|
216
213
|
});
|
|
217
214
|
if (autofocus) {
|
|
218
215
|
button.element.setAttribute("autofocus", "true");
|
|
@@ -516,11 +513,9 @@ cleanupEvents();
|
|
|
516
513
|
unscopeScrim();
|
|
517
514
|
},
|
|
518
515
|
};
|
|
519
|
-
if (component && component.on) {
|
|
520
516
|
component.on("dialog:close", () => {
|
|
521
517
|
visibility.close();
|
|
522
518
|
});
|
|
523
|
-
}
|
|
524
519
|
if (top) {
|
|
525
520
|
onTopLayerClose(component.element, () => visibility.close(true));
|
|
526
521
|
}
|
|
@@ -555,7 +550,7 @@ titleElement.textContent = title;
|
|
|
555
550
|
},
|
|
556
551
|
getTitle() {
|
|
557
552
|
const titleElement = headerElement.querySelector(`.${component.getClass("dialog__header-title")}`);
|
|
558
|
-
return titleElement
|
|
553
|
+
return titleElement?.textContent || "";
|
|
559
554
|
},
|
|
560
555
|
setSubtitle(subtitle) {
|
|
561
556
|
let subtitleElement = headerElement.querySelector(`.${component.getClass("dialog__header-subtitle")}`);
|
|
@@ -572,7 +567,7 @@ subtitleElement.textContent = subtitle;
|
|
|
572
567
|
},
|
|
573
568
|
getSubtitle() {
|
|
574
569
|
const subtitleElement = headerElement.querySelector(`.${component.getClass("dialog__header-subtitle")}`);
|
|
575
|
-
return subtitleElement
|
|
570
|
+
return subtitleElement?.textContent || "";
|
|
576
571
|
},
|
|
577
572
|
setContent(content) {
|
|
578
573
|
setHTML(contentElement, content);
|
|
@@ -616,21 +611,13 @@ component.structure.footer = footer;
|
|
|
616
611
|
addButton(footer, button, component, getComponent);
|
|
617
612
|
},
|
|
618
613
|
removeButton(indexOrText) {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
button.instance.destroy();
|
|
623
|
-
buttonRecords.splice(indexOrText, 1);
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
else {
|
|
627
|
-
const index = buttonRecords.findIndex((button) => button.config.text === indexOrText);
|
|
628
|
-
if (index !== -1) {
|
|
614
|
+
const numeric = typeof indexOrText === "number";
|
|
615
|
+
const index = numeric ? indexOrText : buttonRecords.findIndex((button) => button.config.text === indexOrText);
|
|
616
|
+
if (numeric ? index >= 0 && index < buttonRecords.length : index !== -1) {
|
|
629
617
|
const button = buttonRecords[index];
|
|
630
618
|
button.instance.destroy();
|
|
631
619
|
buttonRecords.splice(index, 1);
|
|
632
620
|
}
|
|
633
|
-
}
|
|
634
621
|
if (buttonRecords.length === 0 && component.structure.footer) {
|
|
635
622
|
component.element.removeChild(component.structure.footer);
|
|
636
623
|
component.structure.footer = null;
|
|
@@ -643,11 +630,9 @@ setFooterAlignment(alignment) {
|
|
|
643
630
|
const footer = component.structure.footer;
|
|
644
631
|
if (!footer)
|
|
645
632
|
return;
|
|
646
|
-
const ALL_ALIGNMENTS = ["
|
|
633
|
+
const ALL_ALIGNMENTS = ["left", "center", "space-between"];
|
|
647
634
|
ALL_ALIGNMENTS.forEach((align) => {
|
|
648
|
-
if (align !== "right") {
|
|
649
635
|
removeClass(footer, `${component.getClass("dialog__footer")}--${align}`);
|
|
650
|
-
}
|
|
651
636
|
});
|
|
652
637
|
if (alignment !== "right") {
|
|
653
638
|
addClass(footer, `${component.getClass("dialog__footer")}--${alignment}`);
|
|
@@ -5,6 +5,7 @@ import { withEvents, withLifecycle } from "../../core/compose/features/index.js"
|
|
|
5
5
|
import { getCleanup } from "../../core/compose/cleanup.js";
|
|
6
6
|
import { PREFIX } from "../../core/config.js";
|
|
7
7
|
import { setHTML } from "../../core/dom/html.js";
|
|
8
|
+
import { getIcon } from "../../core/icons/registry.js";
|
|
8
9
|
import { warnDev } from "../../core/utils/warn.js";
|
|
9
10
|
import createFab from "../fab/index.js";
|
|
10
11
|
import { createConfig, CLOSE_ICON } from "./config.js";
|
|
@@ -49,7 +50,7 @@ button.setAttribute("aria-controls", `${id}-list`);
|
|
|
49
50
|
const closeIcon = document.createElement("span");
|
|
50
51
|
closeIcon.className = `${block}__close`;
|
|
51
52
|
closeIcon.setAttribute("aria-hidden", "true");
|
|
52
|
-
setHTML(closeIcon, settings.closeIcon || CLOSE_ICON);
|
|
53
|
+
setHTML(closeIcon, settings.closeIcon || getIcon("close", CLOSE_ICON));
|
|
53
54
|
button.appendChild(closeIcon);
|
|
54
55
|
root.appendChild(button);
|
|
55
56
|
const list = document.createElement("div");
|
|
@@ -224,7 +225,8 @@ menu.close();
|
|
|
224
225
|
else
|
|
225
226
|
setOpened(false);
|
|
226
227
|
};
|
|
227
|
-
|
|
228
|
+
const toggle = (event) => opened ? close() : open(event);
|
|
229
|
+
button.addEventListener("click", toggle);
|
|
228
230
|
button.addEventListener("keydown", (event) => {
|
|
229
231
|
if (!opened || presentation !== "list")
|
|
230
232
|
return;
|
|
@@ -299,10 +301,7 @@ close();
|
|
|
299
301
|
return this;
|
|
300
302
|
},
|
|
301
303
|
toggle(event) {
|
|
302
|
-
|
|
303
|
-
close();
|
|
304
|
-
else
|
|
305
|
-
open(event);
|
|
304
|
+
toggle(event);
|
|
306
305
|
return this;
|
|
307
306
|
},
|
|
308
307
|
isOpen() {
|
|
@@ -95,6 +95,13 @@ interface FabMenuComponent extends ElementComponent {
|
|
|
95
95
|
destroy(): void;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
/** Registers FabMenuConfig with the global defaults map, so `setComponentDefaults("fab-menu", ...)` is typed without core importing anything from this component. */
|
|
99
|
+
declare module "../../core/config/global" {
|
|
100
|
+
interface ComponentConfigMap {
|
|
101
|
+
"fab-menu"?: Partial<FabMenuConfig>;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
98
105
|
/**
|
|
99
106
|
* Creates a FAB menu: M3 Expressive's FAB that opens a list of related actions.
|
|
100
107
|
* @param config
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/** The lean selection popup's public types. */
|
|
2
|
+
/** One option of a listbox. */
|
|
3
|
+
interface ListboxOption<T = unknown> {
|
|
4
|
+
/** The value the option commits. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** The row's text, set as `textContent` -- never HTML. */
|
|
7
|
+
text: string;
|
|
8
|
+
/** A disabled option is shown and read, but navigation and activation skip it. */
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
/** Returned to the application with the option; never rendered. */
|
|
11
|
+
data?: T;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** What the `open` and `close` events carry. */
|
|
15
|
+
interface ListboxEventDetail<T = unknown> {
|
|
16
|
+
/** The listbox that emitted the event. */
|
|
17
|
+
listbox: ListboxComponent<T>;
|
|
18
|
+
/** The event that caused it, when there was one. */
|
|
19
|
+
originalEvent?: Event;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** What the `change` event carries: the value a user choice committed. */
|
|
23
|
+
interface ListboxChangeDetail<T = unknown> extends ListboxEventDetail<T> {
|
|
24
|
+
/** The committed option's id. */
|
|
25
|
+
value: string;
|
|
26
|
+
/** The value before this choice. */
|
|
27
|
+
previousValue: string | null;
|
|
28
|
+
/** The committed option, as a snapshot. */
|
|
29
|
+
option: ListboxOption<T>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The listbox's typed events, by name. */
|
|
33
|
+
interface ListboxEvents<T = unknown> {
|
|
34
|
+
open: ListboxEventDetail<T>;
|
|
35
|
+
change: ListboxChangeDetail<T>;
|
|
36
|
+
close: ListboxEventDetail<T>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The handler each typed event takes, by event name. */
|
|
40
|
+
type ListboxEventHandlers<T = unknown> = {
|
|
41
|
+
[K in keyof ListboxEvents<T>]: (detail: ListboxEvents<T>[K]) => void;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** Configuration for `createListbox`. */
|
|
45
|
+
interface ListboxConfig<T = unknown> {
|
|
46
|
+
/** The dedicated value control. */
|
|
47
|
+
control: HTMLDivElement;
|
|
48
|
+
/** The nonempty accessible name, distinct from the value text. */
|
|
49
|
+
ariaLabel: string;
|
|
50
|
+
/** The options, in display order. */
|
|
51
|
+
options: readonly ListboxOption<T>[];
|
|
52
|
+
/** The initial selected option's id, or `null` for none. */
|
|
53
|
+
value?: string | null;
|
|
54
|
+
/** The control's text while no option is selected. */
|
|
55
|
+
placeholder?: string;
|
|
56
|
+
/** A disabled control stays in the tab order but cannot open or change. */
|
|
57
|
+
disabled?: boolean;
|
|
58
|
+
/** Event handlers, installed before the first interaction. */
|
|
59
|
+
on?: Partial<ListboxEventHandlers<T>>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The handle `createListbox` returns. */
|
|
63
|
+
interface ListboxComponent<T = unknown> {
|
|
64
|
+
/** The popup root (`role="listbox"`), stable until `destroy()`. */
|
|
65
|
+
element: HTMLElement;
|
|
66
|
+
/** Opens the popup, focusing the control. */
|
|
67
|
+
open: (event?: Event) => ListboxComponent<T>;
|
|
68
|
+
/** Closes the popup without committing. */
|
|
69
|
+
close: (event?: Event) => ListboxComponent<T>;
|
|
70
|
+
/** Opens a closed popup, closes an open one. */
|
|
71
|
+
toggle: (event?: Event) => ListboxComponent<T>;
|
|
72
|
+
/** Whether the popup is showing. */
|
|
73
|
+
isOpen: () => boolean;
|
|
74
|
+
/** The committed option's id, or `null`. */
|
|
75
|
+
getValue: () => string | null;
|
|
76
|
+
/** Selects an option by id, or clears the selection with `null`. */
|
|
77
|
+
setValue: (value: string | null) => ListboxComponent<T>;
|
|
78
|
+
/** The options, as snapshots: mutating them cannot bypass rendering. */
|
|
79
|
+
getOptions: () => ListboxOption<T>[];
|
|
80
|
+
/** Replaces the options, validating all of them before changing anything. */
|
|
81
|
+
setOptions: (options: readonly ListboxOption<T>[]) => ListboxComponent<T>;
|
|
82
|
+
/** Disables or enables the control; disabling closes without committing. */
|
|
83
|
+
setDisabled: (disabled: boolean) => ListboxComponent<T>;
|
|
84
|
+
/** Whether the control is disabled. */
|
|
85
|
+
isDisabled: () => boolean;
|
|
86
|
+
/** Subscribes to an event. */
|
|
87
|
+
on: <K extends keyof ListboxEvents<T>>(type: K, handler: (detail: ListboxEvents<T>[K]) => void) => ListboxComponent<T>;
|
|
88
|
+
/** Removes the exact subscription. */
|
|
89
|
+
off: <K extends keyof ListboxEvents<T>>(type: K, handler: (detail: ListboxEvents<T>[K]) => void) => ListboxComponent<T>;
|
|
90
|
+
/** Idempotent and terminal. */
|
|
91
|
+
destroy: () => void;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Creates a listbox handle on a dedicated control.
|
|
96
|
+
* @param config
|
|
97
|
+
*/
|
|
98
|
+
declare function createListbox<T = unknown>(config: ListboxConfig<T>): ListboxComponent<T>;
|
|
99
|
+
export type { ListboxChangeDetail, ListboxComponent, ListboxConfig, ListboxEventDetail, ListboxEventHandlers, ListboxEvents, ListboxOption };
|
|
100
|
+
export { createListbox, createListbox as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default, default as createListbox } from "./listbox.js";
|