material 3.16.0 → 3.16.1
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 +5 -5
- package/dist/components/button/button.js +2 -15
- package/dist/components/button/compose.js +17 -0
- package/dist/components/button/config.js +20 -2
- package/dist/components/drawer/drawer.js +1 -0
- package/dist/components/drawer/index.d.ts +63 -10
- package/dist/components/drawer/index.js +1 -1
- package/dist/components/fab-menu/fab-menu.js +55 -10
- package/dist/components/index.js +2 -2
- package/dist/components/menu/features/position.js +18 -27
- package/dist/components/menu/types.d.ts +1 -1
- package/dist/components/search/features/input.js +12 -11
- package/dist/components/select/index.d.ts +4 -1
- package/dist/components/top-app-bar/index.d.ts +22 -4
- package/dist/components/top-app-bar/index.js +1 -1
- package/dist/components/top-app-bar/top-app-bar.js +1 -0
- package/dist/core/dom/placement.js +11 -0
- package/dist/elements/app-bar.js +106 -0
- package/dist/elements/button.js +3 -2
- package/dist/elements/css/dialog.css +1 -1
- package/dist/elements/css/fab-menu.css +1 -1
- package/dist/elements/css/fab-menu.js +1 -0
- package/dist/elements/css/hosts/app-bar.css +1 -0
- package/dist/elements/css/hosts/navigation-drawer.css +1 -0
- package/dist/elements/css/menu.css +1 -1
- package/dist/elements/drawer.js +4 -175
- package/dist/elements/extended-fab.js +3 -2
- package/dist/elements/fab-menu.js +1 -1
- package/dist/elements/fab.js +3 -2
- package/dist/elements/form-button.d.ts +40 -0
- package/dist/elements/form-button.js +45 -1
- package/dist/elements/icon-button.d.ts +21 -6
- package/dist/elements/icon-button.js +3 -2
- package/dist/elements/index.d.ts +492 -44
- package/dist/elements/index.js +10 -1
- package/dist/elements/navigation-drawer.js +197 -0
- package/dist/elements/preupgrade/app-bar.css +2 -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-drawer.css +2 -0
- 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 +2 -2
- package/dist/elements/split-button.js +4 -1
- package/dist/elements/styles.js +4 -4
- package/dist/elements/top-app-bar.js +2 -102
- package/dist/index.d.ts +4 -4
- package/dist/react/app-bar.js +5 -0
- package/dist/react/fab-menu.js +1 -0
- package/dist/react/index.d.ts +11 -2
- package/dist/react/index.js +3 -0
- package/dist/react/jsx.d.ts +6 -0
- package/dist/react/navigation-drawer-item.js +4 -0
- package/dist/react/navigation-drawer.js +5 -0
- package/dist/solid/app-bar.js +4 -0
- package/dist/solid/fab-menu.js +1 -0
- package/dist/solid/index.d.ts +11 -2
- package/dist/solid/index.js +3 -0
- package/dist/solid/jsx.d.ts +12 -3
- package/dist/solid/navigation-drawer-item.js +3 -0
- package/dist/solid/navigation-drawer.js +4 -0
- 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 +1 -1
- 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 +2 -2
- 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 +2 -2
- package/dist/styles/fab-menu.js +1 -0
- 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 +1 -1
- package/dist/styles/loading-indicator.css +1 -1
- package/dist/styles/menu.css +2 -2
- 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 +2 -2
- package/dist/svelte/AppBar.svelte +25 -0
- package/dist/svelte/AppBar.svelte.d.ts +5 -0
- package/dist/svelte/Drawer.svelte.d.ts +1 -0
- package/dist/svelte/DrawerItem.svelte.d.ts +1 -0
- package/dist/svelte/FabMenu.svelte +1 -0
- package/dist/svelte/NavigationDrawer.svelte +26 -0
- package/dist/svelte/NavigationDrawer.svelte.d.ts +5 -0
- package/dist/svelte/NavigationDrawerItem.svelte +11 -0
- package/dist/svelte/NavigationDrawerItem.svelte.d.ts +5 -0
- package/dist/svelte/TopAppBar.svelte.d.ts +1 -0
- package/dist/svelte/index.d.ts +3 -0
- package/dist/svelte/index.js +3 -0
- 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 +12 -3
- package/dist/vue/app-bar.js +4 -0
- package/dist/vue/fab-menu.js +1 -0
- package/dist/vue/index.d.ts +11 -2
- package/dist/vue/index.js +3 -0
- package/dist/vue/navigation-drawer-item.js +3 -0
- package/dist/vue/navigation-drawer.js +4 -0
- package/package.json +1 -1
- package/src/styles/components/_dialog.scss +2 -1
- package/src/styles/components/_fab-menu.scss +50 -9
- package/src/styles/components/_menu.scss +3 -0
- package/src/styles/elements/_app-bar.scss +6 -0
- package/src/styles/elements/_drawer.scss +3 -12
- package/src/styles/elements/_index.scss +2 -0
- package/src/styles/elements/_navigation-drawer.scss +10 -0
- package/src/styles/elements/_shared-app-bar.scss +49 -0
- package/src/styles/elements/_shared-drawer.scss +18 -0
- package/src/styles/elements/_top-app-bar.scss +2 -46
package/README.md
CHANGED
|
@@ -135,14 +135,14 @@ What a bundler keeps, minified and gzipped (kB is 1,000 bytes), measured from th
|
|
|
135
135
|
<!-- sizes -->
|
|
136
136
|
| Import | gzip |
|
|
137
137
|
|--------|-----:|
|
|
138
|
-
| `createButton` from `material`, with code splitting: the initial chunks (the progress indicator loads on demand) | 7.
|
|
139
|
-
| `createButton`, without code splitting (the progress indicator included) |
|
|
140
|
-
| `createButton`, `createTextField` and `createCheckbox`, without code splitting | 20.
|
|
141
|
-
| Everything the root exports (`export * from 'material'`), without code splitting |
|
|
138
|
+
| `createButton` from `material`, with code splitting: the initial chunks (the progress indicator loads on demand) | 7.6 kB |
|
|
139
|
+
| `createButton`, without code splitting (the progress indicator included) | 14.0 kB |
|
|
140
|
+
| `createButton`, `createTextField` and `createCheckbox`, without code splitting | 20.5 kB |
|
|
141
|
+
| Everything the root exports (`export * from 'material'`), without code splitting | 134.0 kB |
|
|
142
142
|
| `material/styles/base` | 3.1 kB |
|
|
143
143
|
| `material/styles/base-lite` | 1.7 kB |
|
|
144
144
|
| `material/styles/base` and `material/styles/button` | 5.4 kB |
|
|
145
|
-
| `material/styles`, the full stylesheet | 60.
|
|
145
|
+
| `material/styles`, the full stylesheet | 60.5 kB |
|
|
146
146
|
<!-- /sizes -->
|
|
147
147
|
|
|
148
148
|
`material` publishes ESM only, so bundlers drop what you do not import. Each component's page on [md3.io/components](https://md3.io/components/) gives its size.
|
|
@@ -1,21 +1,8 @@
|
|
|
1
|
-
import { pipe } from "../../core/compose/index.js";
|
|
2
|
-
import { createBase, withElement } from "../../core/compose/component.js";
|
|
3
|
-
import { withEvents, withText, withIcon, withVariant, withSize, withRipple, withDisabled, withLifecycle, } from "../../core/compose/features/index.js";
|
|
4
1
|
import { withProgress } from "./features/progress.js";
|
|
5
|
-
import {
|
|
6
|
-
import { withAPI } from "./api.js";
|
|
7
|
-
import { createBaseConfig, getElementConfig, getApiConfig } from "./config.js";
|
|
2
|
+
import { composeButton } from "./compose.js";
|
|
8
3
|
const createButton = (config = {}) => {
|
|
9
|
-
const baseConfig = createBaseConfig(config);
|
|
10
4
|
try {
|
|
11
|
-
|
|
12
|
-
if (baseConfig.shape && component.element) {
|
|
13
|
-
const className = `${baseConfig.prefix}-${baseConfig.componentName}--${baseConfig.shape}`;
|
|
14
|
-
component.element.classList.add(className);
|
|
15
|
-
}
|
|
16
|
-
return component;
|
|
17
|
-
}, (comp) => withAPI(getApiConfig(comp))(comp))(baseConfig);
|
|
18
|
-
return button;
|
|
5
|
+
return composeButton(config, withProgress);
|
|
19
6
|
}
|
|
20
7
|
catch (error) {
|
|
21
8
|
console.error("Button creation error:", error);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { pipe } from "../../core/compose/index.js";
|
|
2
|
+
import { createBase, withElement } from "../../core/compose/component.js";
|
|
3
|
+
import { withEvents, withText, withIcon, withVariant, withSize, withRipple, withDisabled, withLifecycle, } from "../../core/compose/features/index.js";
|
|
4
|
+
import { withToggle } from "./features/toggle.js";
|
|
5
|
+
import { withAPI } from "./api.js";
|
|
6
|
+
import { createBaseConfig, getElementConfig, getApiConfig } from "./config.js";
|
|
7
|
+
const identity = () => (component) => component;
|
|
8
|
+
export const composeButton = (config = {}, progress = identity, isolated = false) => {
|
|
9
|
+
const baseConfig = createBaseConfig(config, isolated);
|
|
10
|
+
return pipe(createBase, withEvents(), withElement(getElementConfig(baseConfig)), withVariant(baseConfig), withSize(baseConfig), withText(baseConfig), withIcon(baseConfig), withDisabled(baseConfig), withToggle(baseConfig), withRipple(baseConfig), withLifecycle(), progress(baseConfig), (component) => {
|
|
11
|
+
if (baseConfig.shape && component.element) {
|
|
12
|
+
const className = `${baseConfig.prefix}-${baseConfig.componentName}--${baseConfig.shape}`;
|
|
13
|
+
component.element.classList.add(className);
|
|
14
|
+
}
|
|
15
|
+
return component;
|
|
16
|
+
}, (comp) => withAPI(getApiConfig(comp))(comp))(baseConfig);
|
|
17
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PREFIX } from "../../core/config.js";
|
|
2
|
+
import { createComponentConfig, createElementConfig } from "../../core/config/component.js";
|
|
2
3
|
import { BUTTON_VARIANTS, BUTTON_TYPES, DEFAULT_RIPPLE_CONFIG, BUTTON_SIZES, BUTTON_SHAPES, } from "./constants.js";
|
|
3
4
|
export const defaultConfig = {
|
|
4
5
|
variant: BUTTON_VARIANTS.FILLED,
|
|
@@ -11,7 +12,24 @@ rippleConfig: {
|
|
|
11
12
|
duration: DEFAULT_RIPPLE_CONFIG.DURATION,
|
|
12
13
|
},
|
|
13
14
|
};
|
|
14
|
-
|
|
15
|
+
const isolatedButtonConfig = (config) => {
|
|
16
|
+
const userClassName = config.className !== undefined ? config.className : config.class;
|
|
17
|
+
const defaultClassName = defaultConfig.className !== undefined ? defaultConfig.className : defaultConfig.class;
|
|
18
|
+
const merged = {
|
|
19
|
+
...defaultConfig,
|
|
20
|
+
...config,
|
|
21
|
+
componentName: "button",
|
|
22
|
+
prefix: PREFIX,
|
|
23
|
+
className: userClassName !== undefined ? userClassName : defaultClassName,
|
|
24
|
+
};
|
|
25
|
+
if ("class" in merged && merged.className !== undefined) {
|
|
26
|
+
delete merged.class;
|
|
27
|
+
}
|
|
28
|
+
return merged;
|
|
29
|
+
};
|
|
30
|
+
export const createBaseConfig = (config = {}, isolated = false) => (isolated
|
|
31
|
+
? isolatedButtonConfig(config)
|
|
32
|
+
: createComponentConfig(defaultConfig, config, "button"));
|
|
15
33
|
export const getElementConfig = (config) => {
|
|
16
34
|
const attributes = {
|
|
17
35
|
type: config.type || "button",
|
|
@@ -4,18 +4,32 @@ import type { ForwardedEventPayload } from "../../core/dom/index.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* Creates a new Drawer component with the specified configuration.
|
|
6
6
|
* @param config
|
|
7
|
+
* @deprecated use {@link createNavigationDrawer}. Material Design 3 names the
|
|
8
|
+
* component the navigation drawer; this name stays for 3.x.
|
|
7
9
|
*/
|
|
8
10
|
declare function createDrawer(config?: DrawerConfig): DrawerComponent;
|
|
9
11
|
|
|
10
12
|
declare const createShadowDrawer: (config: DrawerConfig) => DrawerComponent;
|
|
11
13
|
|
|
12
|
-
/**
|
|
14
|
+
/** Creates a navigation drawer: the same factory as {@link createDrawer}, under the name Material Design 3 gives the component. */
|
|
15
|
+
declare const createNavigationDrawer: typeof createDrawer;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Drawer variant type — controls layout behavior
|
|
19
|
+
* @deprecated use `NavigationDrawerVariant`. Removal in 4.0.
|
|
20
|
+
*/
|
|
13
21
|
type DrawerVariant = "standard" | "modal";
|
|
14
22
|
|
|
15
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* Drawer position — which edge the drawer anchors to
|
|
25
|
+
* @deprecated use `NavigationDrawerPosition`. Removal in 4.0.
|
|
26
|
+
*/
|
|
16
27
|
type DrawerPosition = "start" | "end";
|
|
17
28
|
|
|
18
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Configuration for a navigation destination item
|
|
31
|
+
* @deprecated use `NavigationDrawerItemConfig`. Removal in 4.0.
|
|
32
|
+
*/
|
|
19
33
|
interface DrawerItemConfig {
|
|
20
34
|
/** Item type — defaults to 'item' if omitted */
|
|
21
35
|
type?: "item" | "divider" | "section";
|
|
@@ -43,7 +57,10 @@ interface DrawerItemConfig {
|
|
|
43
57
|
disabled?: boolean;
|
|
44
58
|
}
|
|
45
59
|
|
|
46
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* Event detail emitted when a drawer item is selected
|
|
62
|
+
* @deprecated use `NavigationDrawerSelectEvent`. Removal in 4.0.
|
|
63
|
+
*/
|
|
47
64
|
interface DrawerSelectEvent {
|
|
48
65
|
/** The selected item's id */
|
|
49
66
|
id: string;
|
|
@@ -57,7 +74,10 @@ interface DrawerSelectEvent {
|
|
|
57
74
|
originalEvent: Event;
|
|
58
75
|
}
|
|
59
76
|
|
|
60
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* The new state of a drawer disclosure section.
|
|
79
|
+
* @deprecated use `NavigationDrawerSectionEvent`. Removal in 4.0.
|
|
80
|
+
*/
|
|
61
81
|
interface DrawerSectionEvent {
|
|
62
82
|
id: string;
|
|
63
83
|
value: string;
|
|
@@ -66,7 +86,10 @@ interface DrawerSectionEvent {
|
|
|
66
86
|
originalEvent?: Event;
|
|
67
87
|
}
|
|
68
88
|
|
|
69
|
-
/**
|
|
89
|
+
/**
|
|
90
|
+
* Events emitted by drawer state, navigation items and root DOM forwarding.
|
|
91
|
+
* @deprecated use `NavigationDrawerEvents`. Removal in 4.0.
|
|
92
|
+
*/
|
|
70
93
|
interface DrawerEvents {
|
|
71
94
|
open: () => void;
|
|
72
95
|
close: () => void;
|
|
@@ -78,7 +101,10 @@ interface DrawerEvents {
|
|
|
78
101
|
keydown: (payload: ForwardedEventPayload<KeyboardEvent, HTMLElement>) => void;
|
|
79
102
|
}
|
|
80
103
|
|
|
81
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* Configuration interface for the Drawer component
|
|
106
|
+
* @deprecated use `NavigationDrawerConfig`. Removal in 4.0.
|
|
107
|
+
*/
|
|
82
108
|
interface DrawerConfig extends BaseComponentConfig {
|
|
83
109
|
/**
|
|
84
110
|
* Drawer variant that determines layout behavior
|
|
@@ -143,7 +169,10 @@ interface DrawerConfig extends BaseComponentConfig {
|
|
|
143
169
|
onCollapse?: DrawerEvents["collapse"];
|
|
144
170
|
}
|
|
145
171
|
|
|
146
|
-
/**
|
|
172
|
+
/**
|
|
173
|
+
* Drawer component interface — public API
|
|
174
|
+
* @deprecated use `NavigationDrawerComponent`. Removal in 4.0.
|
|
175
|
+
*/
|
|
147
176
|
interface DrawerComponent {
|
|
148
177
|
/** The drawer's root DOM element */
|
|
149
178
|
element: HTMLElement;
|
|
@@ -221,5 +250,29 @@ interface DrawerComponent {
|
|
|
221
250
|
destroy: () => void;
|
|
222
251
|
};
|
|
223
252
|
}
|
|
224
|
-
|
|
225
|
-
|
|
253
|
+
|
|
254
|
+
/** The navigation drawer's config; the drawer is the navigation drawer. */
|
|
255
|
+
type NavigationDrawerConfig = DrawerConfig;
|
|
256
|
+
|
|
257
|
+
/** The navigation drawer's component. */
|
|
258
|
+
type NavigationDrawerComponent = DrawerComponent;
|
|
259
|
+
|
|
260
|
+
/** The navigation drawer's variant. */
|
|
261
|
+
type NavigationDrawerVariant = DrawerVariant;
|
|
262
|
+
|
|
263
|
+
/** The navigation drawer's position. */
|
|
264
|
+
type NavigationDrawerPosition = DrawerPosition;
|
|
265
|
+
|
|
266
|
+
/** The navigation drawer's item config. */
|
|
267
|
+
type NavigationDrawerItemConfig = DrawerItemConfig;
|
|
268
|
+
|
|
269
|
+
/** The navigation drawer's select event detail. */
|
|
270
|
+
type NavigationDrawerSelectEvent = DrawerSelectEvent;
|
|
271
|
+
|
|
272
|
+
/** The navigation drawer's section event detail. */
|
|
273
|
+
type NavigationDrawerSectionEvent = DrawerSectionEvent;
|
|
274
|
+
|
|
275
|
+
/** The navigation drawer's events. */
|
|
276
|
+
type NavigationDrawerEvents = DrawerEvents;
|
|
277
|
+
export type { DrawerComponent, DrawerConfig, DrawerEvents, DrawerItemConfig, DrawerPosition, DrawerSectionEvent, DrawerSelectEvent, DrawerVariant, NavigationDrawerComponent, NavigationDrawerConfig, NavigationDrawerEvents, NavigationDrawerItemConfig, NavigationDrawerPosition, NavigationDrawerSectionEvent, NavigationDrawerSelectEvent, NavigationDrawerVariant };
|
|
278
|
+
export { createDrawer, createDrawer as default, createNavigationDrawer };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default, default as createDrawer } from "./drawer.js";
|
|
1
|
+
export { default, default as createDrawer, createNavigationDrawer } from "./drawer.js";
|
|
@@ -8,7 +8,9 @@ import { activeElementOf } from "../../core/dom/focus.js";
|
|
|
8
8
|
import { setHTML } from "../../core/dom/html.js";
|
|
9
9
|
import { getIcon } from "../../core/icons/registry.js";
|
|
10
10
|
import { warnDev } from "../../core/utils/warn.js";
|
|
11
|
+
import { composeButton } from "../button/compose.js";
|
|
11
12
|
import createFab from "../fab/index.js";
|
|
13
|
+
import { fitVertically } from "../../core/dom/placement.js";
|
|
12
14
|
import { createConfig, CLOSE_ICON } from "./config.js";
|
|
13
15
|
import { staggerDelays } from "./stagger.js";
|
|
14
16
|
import { FAB_MENU_EVENTS, FAB_MENU_ITEMS, FAB_MENU_ITEM_EXIT, FAB_MENU_MENU_FROM, FAB_MENU_MENU_GAP, FAB_MENU_LIST_GAP, } from "./constants.js";
|
|
@@ -61,9 +63,13 @@ list.setAttribute("role", "menu");
|
|
|
61
63
|
list.setAttribute("aria-labelledby", button.id);
|
|
62
64
|
list.setAttribute("inert", "");
|
|
63
65
|
const entries = items.map((item) => {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
const itemButton = composeButton({
|
|
67
|
+
variant: "text",
|
|
68
|
+
size: "m",
|
|
69
|
+
class: `${block}__item`,
|
|
70
|
+
}, undefined, true);
|
|
71
|
+
resources.add(() => itemButton.destroy());
|
|
72
|
+
const element = itemButton.element;
|
|
67
73
|
element.setAttribute("role", "menuitem");
|
|
68
74
|
element.tabIndex = -1;
|
|
69
75
|
const content = document.createElement("span");
|
|
@@ -157,8 +163,10 @@ preload();
|
|
|
157
163
|
button.addEventListener("pointerenter", preload, { once: true });
|
|
158
164
|
button.addEventListener("focus", preload, { once: true });
|
|
159
165
|
const reduced = () => matches("(prefers-reduced-motion: reduce)");
|
|
160
|
-
|
|
161
|
-
const
|
|
166
|
+
let opensDownward = false;
|
|
167
|
+
const stagger = (opening, downward = false) => {
|
|
168
|
+
const byDistance = reduced() ? entries.map(() => 0) : staggerDelays(entries.length, opening);
|
|
169
|
+
const delays = downward ? [...byDistance].reverse() : byDistance;
|
|
162
170
|
entries.forEach(({ element }, index) => element.style.setProperty(`--${PREFIX}-fab-menu-delay`, `${delays[index]}ms`));
|
|
163
171
|
return Math.max(0, ...delays);
|
|
164
172
|
};
|
|
@@ -167,14 +175,51 @@ if (!event.composedPath().includes(root))
|
|
|
167
175
|
closeList(false);
|
|
168
176
|
};
|
|
169
177
|
const measure = () => entries.forEach(({ element }) => {
|
|
170
|
-
const content = element.
|
|
178
|
+
const content = element.querySelector(`.${block}__item-content`);
|
|
171
179
|
element.style.setProperty(`--${PREFIX}-fab-menu-item-width`, `${content.offsetWidth}px`);
|
|
172
180
|
});
|
|
181
|
+
const placeList = () => {
|
|
182
|
+
const fab = root.getBoundingClientRect();
|
|
183
|
+
if (fab.height === 0)
|
|
184
|
+
return false;
|
|
185
|
+
const above = fab.top - FAB_MENU_LIST_GAP - WINDOW_MARGIN;
|
|
186
|
+
const below = window.innerHeight - fab.bottom - FAB_MENU_LIST_GAP - WINDOW_MARGIN;
|
|
187
|
+
const fit = fitVertically({ preferred: "top", height: list.scrollHeight, above, below });
|
|
188
|
+
const downward = fit.side === "bottom";
|
|
189
|
+
root.classList.toggle(`${block}--list-down`, downward);
|
|
190
|
+
placeHorizontally(fab);
|
|
191
|
+
list.style.maxHeight = downward
|
|
192
|
+
? fit.maxHeight === null ? "" : `${fit.maxHeight}px`
|
|
193
|
+
: above > 0 ? `${above}px` : "";
|
|
194
|
+
return downward;
|
|
195
|
+
};
|
|
196
|
+
const placeHorizontally = (fab) => {
|
|
197
|
+
const width = widest();
|
|
198
|
+
const rtl = getComputedStyle(root).direction === "rtl";
|
|
199
|
+
const endLeft = rtl ? fab.left : fab.right - width;
|
|
200
|
+
const startLeft = rtl ? fab.right - width : fab.left;
|
|
201
|
+
const inside = (left) => left >= 0 && left + width <= window.innerWidth;
|
|
202
|
+
let start = false;
|
|
203
|
+
let shift = 0;
|
|
204
|
+
if (width > 0 && !inside(endLeft)) {
|
|
205
|
+
if (inside(startLeft)) {
|
|
206
|
+
start = true;
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
shift = endLeft < 0 ? -endLeft : window.innerWidth - (endLeft + width);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
root.classList.toggle(`${block}--list-start`, start);
|
|
213
|
+
root.style.setProperty(`--${PREFIX}-fab-menu-shift`, `${shift}px`);
|
|
214
|
+
};
|
|
215
|
+
const widest = () => entries.reduce((widest, { element }) => {
|
|
216
|
+
const content = element.querySelector(`.${block}__item-content`);
|
|
217
|
+
return Math.max(widest, content?.offsetWidth ?? 0);
|
|
218
|
+
}, 0);
|
|
173
219
|
const openList = () => {
|
|
174
220
|
measure();
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
list.style.maxHeight = top > 0 ? `${Math.max(0, top - FAB_MENU_LIST_GAP - WINDOW_MARGIN)}px` : "";
|
|
221
|
+
opensDownward = placeList();
|
|
222
|
+
stagger(true, opensDownward);
|
|
178
223
|
list.removeAttribute("inert");
|
|
179
224
|
root.classList.add(`${block}--open`);
|
|
180
225
|
document.addEventListener("pointerdown", onOutside, true);
|
|
@@ -183,7 +228,7 @@ setOpened(true);
|
|
|
183
228
|
function closeList(restoreFocus) {
|
|
184
229
|
if (!opened)
|
|
185
230
|
return;
|
|
186
|
-
const last = stagger(false);
|
|
231
|
+
const last = stagger(false, opensDownward);
|
|
187
232
|
list.style.setProperty(`--${PREFIX}-fab-menu-exit`, `${last + FAB_MENU_ITEM_EXIT}ms`);
|
|
188
233
|
const hadFocus = list.contains(activeElementOf(list));
|
|
189
234
|
list.setAttribute("inert", "");
|
package/dist/components/index.js
CHANGED
|
@@ -11,7 +11,7 @@ export { createAssistChip, createFilterChip, createInputChip, createSuggestionCh
|
|
|
11
11
|
export { default as createDatePicker } from "./datepicker/index.js";
|
|
12
12
|
export { default as createDialog } from "./dialog/index.js";
|
|
13
13
|
export { createDivider } from "./divider/index.js";
|
|
14
|
-
export { default as createDrawer } from "./drawer/index.js";
|
|
14
|
+
export { default as createDrawer, createNavigationDrawer } from "./drawer/index.js";
|
|
15
15
|
export { default as createFab } from "./fab/index.js";
|
|
16
16
|
export { default as createFabMenu } from "./fab-menu/index.js";
|
|
17
17
|
export { default as createExtendedFab } from "./extended-fab/index.js";
|
|
@@ -35,6 +35,6 @@ export { createTab } from "./tabs/tab.js";
|
|
|
35
35
|
export { default as createTextField } from "./text-field/index.js";
|
|
36
36
|
export { default as createTimePicker } from "./timepicker/index.js";
|
|
37
37
|
export { default as createToolbar } from "./toolbar/index.js";
|
|
38
|
-
export { default as createTopAppBar } from "./top-app-bar/index.js";
|
|
38
|
+
export { default as createTopAppBar, createAppBar } from "./top-app-bar/index.js";
|
|
39
39
|
export { default as createTooltip } from "./tooltip/index.js";
|
|
40
40
|
export { createCardContent, createCardHeader, createCardActions, createCardMedia, } from "./card/content.js";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fitVertically } from "../../../core/dom/placement.js";
|
|
1
2
|
export const createPositioner = (component, config) => {
|
|
2
3
|
const VIEWPORT_MARGIN = 48;
|
|
3
4
|
const MIN_MENU_HEIGHT = 100;
|
|
@@ -49,15 +50,17 @@ let left = 0;
|
|
|
49
50
|
let calculatedPosition = preferredPosition;
|
|
50
51
|
if (isSubmenu) {
|
|
51
52
|
calculatedPosition = preferredPosition || "right-start";
|
|
52
|
-
if (
|
|
53
|
+
if (config.autoFlip !== false &&
|
|
54
|
+
calculatedPosition.startsWith("right") &&
|
|
53
55
|
horizontalRect.right + menuRect.width + offset > viewportWidth - 16) {
|
|
54
56
|
calculatedPosition = calculatedPosition.replace("right", "left");
|
|
55
57
|
}
|
|
56
|
-
else if (
|
|
58
|
+
else if (config.autoFlip !== false &&
|
|
59
|
+
calculatedPosition.startsWith("left") &&
|
|
57
60
|
horizontalRect.left - menuRect.width - offset < 16) {
|
|
58
61
|
calculatedPosition = calculatedPosition.replace("left", "right");
|
|
59
62
|
}
|
|
60
|
-
if (openerRect.top + menuRect.height > viewportHeight - 48) {
|
|
63
|
+
if (config.autoFlip !== false && openerRect.top + menuRect.height > viewportHeight - 48) {
|
|
61
64
|
if (calculatedPosition === "right-start") {
|
|
62
65
|
calculatedPosition = "right-end";
|
|
63
66
|
}
|
|
@@ -68,23 +71,6 @@ calculatedPosition = "left-end";
|
|
|
68
71
|
}
|
|
69
72
|
else {
|
|
70
73
|
switch (preferredPosition) {
|
|
71
|
-
case "top-start":
|
|
72
|
-
case "top":
|
|
73
|
-
case "top-end":
|
|
74
|
-
if (openerRect.top < menuRect.height + offset + 48) {
|
|
75
|
-
calculatedPosition = preferredPosition.replace("top", "bottom");
|
|
76
|
-
}
|
|
77
|
-
break;
|
|
78
|
-
case "bottom-start":
|
|
79
|
-
case "bottom":
|
|
80
|
-
case "bottom-end":
|
|
81
|
-
if (openerRect.bottom + menuRect.height + offset + 48 >
|
|
82
|
-
viewportHeight) {
|
|
83
|
-
if (openerRect.top > viewportHeight - openerRect.bottom) {
|
|
84
|
-
calculatedPosition = preferredPosition.replace("bottom", "top");
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
break;
|
|
88
74
|
case "right-start":
|
|
89
75
|
case "right":
|
|
90
76
|
case "left-start":
|
|
@@ -113,13 +99,18 @@ let fitted = null;
|
|
|
113
99
|
if (!isSubmenu && /^(top|bottom)/.test(calculatedPosition)) {
|
|
114
100
|
const below = viewportHeight - openerRect.bottom - offset - VIEWPORT_MARGIN;
|
|
115
101
|
const above = openerRect.top - offset - VIEWPORT_MARGIN;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
102
|
+
const fit = fitVertically({
|
|
103
|
+
preferred: calculatedPosition.startsWith("top") ? "top" : "bottom",
|
|
104
|
+
height,
|
|
105
|
+
above,
|
|
106
|
+
below,
|
|
107
|
+
minHeight: MIN_MENU_HEIGHT,
|
|
108
|
+
autoFlip: config.autoFlip !== false,
|
|
109
|
+
});
|
|
110
|
+
calculatedPosition = calculatedPosition.replace(/^(top|bottom)/, fit.side);
|
|
111
|
+
if (fit.maxHeight !== null) {
|
|
112
|
+
fitted = fit.maxHeight;
|
|
113
|
+
height = fit.maxHeight;
|
|
123
114
|
}
|
|
124
115
|
}
|
|
125
116
|
menuElement.style.maxHeight = fitted !== null ? `${fitted}px` : (config.maxHeight ?? "");
|
|
@@ -126,7 +126,7 @@ export interface MenuConfig {
|
|
|
126
126
|
*/
|
|
127
127
|
offset?: number;
|
|
128
128
|
/**
|
|
129
|
-
* Whether the menu
|
|
129
|
+
* Whether the menu may take the other side of its opener to stay in the viewport.
|
|
130
130
|
* @default true
|
|
131
131
|
*/
|
|
132
132
|
autoFlip?: boolean;
|
|
@@ -202,25 +202,26 @@ clear();
|
|
|
202
202
|
}
|
|
203
203
|
});
|
|
204
204
|
}
|
|
205
|
-
|
|
206
|
-
leadingIcon.addEventListener("click", (e) => {
|
|
207
|
-
e.preventDefault();
|
|
205
|
+
const activateLeadingIcon = () => {
|
|
208
206
|
if (component.states?.isExpanded?.()) {
|
|
209
207
|
component.states.collapse();
|
|
208
|
+
return;
|
|
210
209
|
}
|
|
211
|
-
|
|
212
|
-
|
|
210
|
+
if (config.expandOnFocus === false) {
|
|
211
|
+
input.focus();
|
|
212
|
+
return;
|
|
213
213
|
}
|
|
214
|
+
component.states?.expand();
|
|
215
|
+
};
|
|
216
|
+
if (leadingIcon) {
|
|
217
|
+
leadingIcon.addEventListener("click", (e) => {
|
|
218
|
+
e.preventDefault();
|
|
219
|
+
activateLeadingIcon();
|
|
214
220
|
});
|
|
215
221
|
leadingIcon.addEventListener("keydown", (e) => {
|
|
216
222
|
if (e.key === "Enter" || e.key === " ") {
|
|
217
223
|
e.preventDefault();
|
|
218
|
-
|
|
219
|
-
component.states.collapse();
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
component.states?.expand();
|
|
223
|
-
}
|
|
224
|
+
activateLeadingIcon();
|
|
224
225
|
}
|
|
225
226
|
});
|
|
226
227
|
}
|
|
@@ -59,7 +59,10 @@ interface SelectConfig {
|
|
|
59
59
|
container?: HTMLElement | null;
|
|
60
60
|
/** The menu's max height (a CSS length); the list scrolls inside it */
|
|
61
61
|
maxHeight?: string;
|
|
62
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* Whether the menu may take the other side of the field when it does not fit below.
|
|
64
|
+
* @default true
|
|
65
|
+
*/
|
|
63
66
|
autoFlip?: boolean;
|
|
64
67
|
/** The menu's variant: 'vertical' is the M3 expressive menu, items apart in a rounded container */
|
|
65
68
|
variant?: MenuVariant;
|
|
@@ -2,14 +2,23 @@ import { ElementComponent } from "../../core/compose/index.js";
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Creates a top app bar component
|
|
5
|
+
* @deprecated use {@link createAppBar}. Material Design 3 names the
|
|
6
|
+
* component the app bar; this name stays for 3.x.
|
|
5
7
|
* @param config
|
|
6
8
|
*/
|
|
7
9
|
declare const createTopAppBar: (config?: TopAppBarConfig) => TopAppBarComponent;
|
|
8
10
|
|
|
11
|
+
/** Creates an app bar: the same factory as {@link createTopAppBar}, under the name Material Design 3 gives the component. */
|
|
12
|
+
declare const createAppBar: (config?: TopAppBarConfig) => TopAppBarComponent;
|
|
13
|
+
|
|
9
14
|
/** Top App Bar types */
|
|
10
15
|
type TopAppBarType = 'small' | 'medium' | 'large' | 'center';
|
|
11
16
|
|
|
12
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Configuration options for Top App Bar component
|
|
19
|
+
* @deprecated use `AppBarConfig`. Material Design 3 names the component the
|
|
20
|
+
* app bar. Removal in 4.0.
|
|
21
|
+
*/
|
|
13
22
|
interface TopAppBarConfig {
|
|
14
23
|
/**
|
|
15
24
|
* Element to use for the container
|
|
@@ -51,7 +60,10 @@ interface TopAppBarConfig {
|
|
|
51
60
|
componentName?: string;
|
|
52
61
|
}
|
|
53
62
|
|
|
54
|
-
/**
|
|
63
|
+
/**
|
|
64
|
+
* Top App Bar component interface
|
|
65
|
+
* @deprecated use `AppBarComponent`. Removal in 4.0.
|
|
66
|
+
*/
|
|
55
67
|
interface TopAppBarComponent extends ElementComponent {
|
|
56
68
|
/**
|
|
57
69
|
* Sets the title of the top app bar
|
|
@@ -87,6 +99,12 @@ interface TopAppBarComponent extends ElementComponent {
|
|
|
87
99
|
/** Gets the trailing container element */
|
|
88
100
|
getTrailingContainer: () => HTMLElement;
|
|
89
101
|
}
|
|
90
|
-
|
|
91
|
-
|
|
102
|
+
|
|
103
|
+
/** The app bar's configuration; the top app bar is the app bar. */
|
|
104
|
+
type AppBarConfig = TopAppBarConfig;
|
|
105
|
+
|
|
106
|
+
/** The app bar's component; the top app bar is the app bar. */
|
|
107
|
+
type AppBarComponent = TopAppBarComponent;
|
|
108
|
+
export type { AppBarComponent, AppBarConfig, TopAppBarComponent, TopAppBarConfig };
|
|
109
|
+
export { createAppBar, createTopAppBar, createTopAppBar as default };
|
|
92
110
|
export { TOP_APP_BAR_CLASSES, TOP_APP_BAR_DEFAULTS, TOP_APP_BAR_STATES, TOP_APP_BAR_TYPES } from "./constants.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { createTopAppBar } from "./top-app-bar.js";
|
|
2
2
|
export { TOP_APP_BAR_TYPES, TOP_APP_BAR_STATES, TOP_APP_BAR_DEFAULTS, TOP_APP_BAR_CLASSES } from "./constants.js";
|
|
3
3
|
export default createTopAppBar;
|
|
4
|
-
export { createTopAppBar };
|
|
4
|
+
export { createTopAppBar, createAppBar } from "./top-app-bar.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const MIN_VERTICAL_FIT = 100;
|
|
2
|
+
export const fitVertically = ({ preferred, height, above, below, minHeight = MIN_VERTICAL_FIT, autoFlip = true, }) => {
|
|
3
|
+
const room = (side) => (side === "top" ? above : below);
|
|
4
|
+
if (height <= room(preferred))
|
|
5
|
+
return { side: preferred, maxHeight: null };
|
|
6
|
+
const side = !autoFlip || above === below
|
|
7
|
+
? preferred
|
|
8
|
+
: below > above ? "bottom" : "top";
|
|
9
|
+
const available = Math.max(room(side), minHeight);
|
|
10
|
+
return { side, maxHeight: available < height ? available : null };
|
|
11
|
+
};
|