mtrl 0.8.0-next.31 → 0.8.0-next.33

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.
@@ -10,6 +10,7 @@
10
10
  export { default as createBadge } from "./badge";
11
11
  export { default as createBottomAppBar } from "./bottom-app-bar";
12
12
  export { default as createBottomSheet } from "./bottom-sheet";
13
+ export { default as createSideSheet } from "./side-sheet";
13
14
  export { default as createButton } from "./button";
14
15
  export { default as createButtonGroup } from "./button-group";
15
16
  export { default as createCard } from "./card";
@@ -51,6 +52,7 @@ export { createCardContent, createCardHeader, createCardActions, createCardMedia
51
52
  export type { BadgeConfig, BadgeComponent } from "./badge/types";
52
53
  export type { BottomAppBarConfig, BottomAppBar } from "./bottom-app-bar/types";
53
54
  export type { BottomSheetConfig, BottomSheetComponent, BottomSheetVariant, BottomSheetState, BottomSheetStateEvent, BottomSheetEventHandlers, } from "./bottom-sheet/types";
55
+ export type { SideSheetConfig, SideSheetComponent, SideSheetVariant, SideSheetPosition, SideSheetEventHandlers, } from "./side-sheet/types";
54
56
  export type { ButtonConfig, ButtonComponent, ButtonVariant, } from "./button/types";
55
57
  export type { ButtonGroupConfig, ButtonGroupComponent, ButtonGroupItemConfig, ButtonGroupEvent, ButtonGroupEventType, ButtonGroupVariant, ButtonGroupOrientation, ButtonGroupDensity, } from "./button-group/types";
56
58
  export type { CardSchema } from "./card/types";
@@ -1,6 +1,18 @@
1
1
  import { SheetConfig } from "./types";
2
2
  /**
3
3
  * Creates a new Sheet component
4
+ *
5
+ * @deprecated Since 0.8.0. Use {@link createBottomSheet} for a sheet anchored
6
+ * to the bottom edge, or {@link createSideSheet} for one docked to a vertical
7
+ * edge. Those follow the M3 bottom sheet and side sheet specifications, which
8
+ * this component predates and does not match.
9
+ *
10
+ * This component is also broken: `open()`, `close()` and the drag gestures
11
+ * call `component.events.emit(...)`, but it composes the event feature that
12
+ * provides `emit` directly and no `events` object, so every one of them
13
+ * throws. Its scrim is never inserted into the page either. It is kept only so
14
+ * that existing imports keep resolving, and it will be removed.
15
+ *
4
16
  * @param {SheetConfig} config - Sheet configuration object
5
17
  * @returns {SheetComponent} Sheet component instance
6
18
  */
@@ -24,6 +24,10 @@ export declare const SHEET_EVENTS: {
24
24
  readonly DRAG_START: "dragstart";
25
25
  readonly DRAG_END: "dragend";
26
26
  };
27
+ /**
28
+ * @deprecated Since 0.8.0. Use BottomSheetConfig or SideSheetConfig.
29
+ * The sheet component this belongs to does not open: see createSheet.
30
+ */
27
31
  /**
28
32
  * Configuration interface for the Sheet component
29
33
  * @category Components
@@ -146,6 +150,10 @@ export interface TitleAPI {
146
150
  */
147
151
  getElement: () => HTMLElement | null;
148
152
  }
153
+ /**
154
+ * @deprecated Since 0.8.0. Use BottomSheetComponent or SideSheetComponent.
155
+ * The sheet component this belongs to does not open: see createSheet.
156
+ */
149
157
  /**
150
158
  * Sheet component interface
151
159
  * @category Components
@@ -0,0 +1,33 @@
1
+ import { SideSheetComponent, SideSheetEventHandlers } from "./types";
2
+ interface ApiOptions {
3
+ state: {
4
+ open: () => void;
5
+ close: () => void;
6
+ toggle: () => void;
7
+ isOpen: () => boolean;
8
+ release: () => void;
9
+ };
10
+ structure: {
11
+ setContent: (content: string | HTMLElement) => void;
12
+ setTitle: (title: string) => void;
13
+ };
14
+ lifecycle: {
15
+ destroy: () => void;
16
+ };
17
+ }
18
+ interface BaseComponent {
19
+ element: HTMLElement;
20
+ getClass: (name: string) => string;
21
+ on: (event: string, handler: (...args: never[]) => void) => unknown;
22
+ off: (event: string, handler: (...args: never[]) => void) => unknown;
23
+ }
24
+ /**
25
+ * The public surface. Every method is backed by a feature; none is declared
26
+ * and left unwired.
27
+ */
28
+ export declare const withAPI: ({ state, structure, lifecycle }: ApiOptions) => <C extends BaseComponent>(component: C) => SideSheetComponent;
29
+ /** Registers the handlers given at creation */
30
+ export declare const applyEventHandlers: (component: {
31
+ on: (event: string, handler: (...args: never[]) => void) => unknown;
32
+ }, handlers?: SideSheetEventHandlers) => void;
33
+ export {};
@@ -0,0 +1,34 @@
1
+ import { SideSheetConfig } from "./types";
2
+ /**
3
+ * What the component applies when the caller says nothing.
4
+ */
5
+ export declare const defaultConfig: Partial<SideSheetConfig>;
6
+ /**
7
+ * Merges the caller's configuration over the defaults.
8
+ */
9
+ export declare const createBaseConfig: (config?: SideSheetConfig) => SideSheetConfig;
10
+ /**
11
+ * The root element: a fixed layer holding the scrim and the sheet itself.
12
+ */
13
+ export declare const getElementConfig: (config: SideSheetConfig) => {
14
+ tag: string;
15
+ componentName: string;
16
+ attributes: Record<string, any>;
17
+ className: string[];
18
+ rawClass: string | string[];
19
+ id: string;
20
+ name: string;
21
+ title: string;
22
+ tabIndex: number;
23
+ style: string | Partial<CSSStyleDeclaration>;
24
+ data: Record<string, string>;
25
+ role: string;
26
+ ariaLabel: string;
27
+ ariaDescribedBy: string;
28
+ ariaLabelledBy: string;
29
+ ariaHidden: boolean;
30
+ html: string;
31
+ text: string;
32
+ forwardEvents: Record<string, boolean | ((component: any, event: Event) => boolean)>;
33
+ interactive: boolean;
34
+ };
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Side sheet variants.
3
+ *
4
+ * A standard sheet is docked: it sits in the layout beside the page and leaves
5
+ * it usable. A modal sheet floats over the page behind a scrim and takes focus.
6
+ * They differ in colour as well as behaviour, which is why the variant is not
7
+ * only a class (m3.material.io/components/side-sheets).
8
+ */
9
+ export declare const SIDE_SHEET_VARIANTS: {
10
+ readonly STANDARD: "standard";
11
+ readonly MODAL: "modal";
12
+ };
13
+ /**
14
+ * Which edge the sheet is docked to.
15
+ *
16
+ * These are logical, not physical: `end` is the right edge in a left-to-right
17
+ * document and the left edge in a right-to-left one, so a sheet does not need
18
+ * reconfiguring per language.
19
+ */
20
+ export declare const SIDE_SHEET_POSITIONS: {
21
+ readonly START: "start";
22
+ readonly END: "end";
23
+ };
24
+ /**
25
+ * Defaults, from the M3 side sheet specs and the Android implementation.
26
+ */
27
+ export declare const SIDE_SHEET_DEFAULTS: {
28
+ readonly VARIANT: "modal";
29
+ /** Side sheets dock to the trailing edge unless told otherwise */
30
+ readonly POSITION: "end";
31
+ /** The width the Android implementation uses for a standard sheet */
32
+ readonly WIDTH: 256;
33
+ /** m3.material.io side sheet specs, container maximum width */
34
+ readonly MAX_WIDTH: 400;
35
+ /** A modal sheet offers a way out of itself */
36
+ readonly CLOSE_BUTTON: true;
37
+ readonly CLOSE_ON_SCRIM_CLICK: true;
38
+ readonly CLOSE_ON_ESCAPE: true;
39
+ };
40
+ /**
41
+ * Class names, without the prefix. `getClass` adds it.
42
+ */
43
+ export declare const SIDE_SHEET_CLASSES: {
44
+ readonly ROOT: "side-sheet";
45
+ readonly SCRIM: "side-sheet-scrim";
46
+ readonly CONTAINER: "side-sheet-container";
47
+ readonly HEADER: "side-sheet-header";
48
+ readonly TITLE: "side-sheet-title";
49
+ readonly CLOSE: "side-sheet-close";
50
+ readonly DIVIDER: "side-sheet-divider";
51
+ readonly CONTENT: "side-sheet-content";
52
+ readonly ACTIONS: "side-sheet-actions";
53
+ };
54
+ /**
55
+ * Events the sheet emits.
56
+ */
57
+ export declare const SIDE_SHEET_EVENTS: {
58
+ readonly OPEN: "open";
59
+ readonly CLOSE: "close";
60
+ };
@@ -0,0 +1,2 @@
1
+ export { withStructure } from "./structure";
2
+ export { withState } from "./state";
@@ -0,0 +1,28 @@
1
+ import { SideSheetConfig } from "../types";
2
+ interface StateComponent {
3
+ element: HTMLElement;
4
+ getClass: (name: string) => string;
5
+ emit: (event: string, data?: unknown) => unknown;
6
+ structure: {
7
+ scrim: HTMLElement | null;
8
+ container: HTMLElement;
9
+ closeButton: HTMLButtonElement | null;
10
+ };
11
+ }
12
+ /**
13
+ * Opening and closing, and everything that closes it.
14
+ *
15
+ * Events go through `component.emit`, which is what the composed events
16
+ * enhancer provides.
17
+ */
18
+ export declare const withState: (config: SideSheetConfig) => <C extends StateComponent>(component: C) => C & {
19
+ state: {
20
+ open: () => void;
21
+ close: () => void;
22
+ toggle: () => void;
23
+ isOpen: () => boolean;
24
+ /** Releases the listeners this feature put on the document */
25
+ release: () => void;
26
+ };
27
+ };
28
+ export {};
@@ -0,0 +1,21 @@
1
+ import { SideSheetConfig } from "../types";
2
+ /**
3
+ * Builds the parts of the sheet and puts the whole thing on the page.
4
+ *
5
+ * As with the bottom sheet, the root element holds both the scrim and the
6
+ * container, so neither depends on a parent that does not exist yet.
7
+ */
8
+ export declare const withStructure: (config: SideSheetConfig) => <C extends {
9
+ element: HTMLElement;
10
+ getClass: (n: string) => string;
11
+ }>(component: C) => C & {
12
+ structure: {
13
+ scrim: HTMLElement;
14
+ container: HTMLDivElement;
15
+ title: HTMLElement;
16
+ closeButton: HTMLButtonElement;
17
+ content: HTMLDivElement;
18
+ setContent(next: string | HTMLElement): void;
19
+ setTitle(next: string): void;
20
+ };
21
+ };
@@ -0,0 +1,2 @@
1
+ export { default as createSideSheet, default } from "./side-sheet";
2
+ export type { SideSheetConfig, SideSheetComponent, SideSheetVariant, SideSheetPosition, SideSheetEventHandlers, } from "./types";
@@ -0,0 +1,24 @@
1
+ import { SideSheetConfig, SideSheetComponent } from "./types";
2
+ /**
3
+ * Creates a side sheet: a surface docked to a vertical edge, holding content
4
+ * that supports the page rather than replacing it.
5
+ *
6
+ * A standard sheet sits beside the page and leaves it usable. A modal sheet
7
+ * floats over it behind a scrim and takes focus.
8
+ *
9
+ * @param {SideSheetConfig} config - Side sheet configuration
10
+ * @returns {SideSheetComponent} Side sheet instance
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const filters = createSideSheet({
15
+ * title: 'Filters',
16
+ * content: '<p>Narrow the results.</p>',
17
+ * on: { close: () => applyFilters() }
18
+ * });
19
+ *
20
+ * filters.open();
21
+ * ```
22
+ */
23
+ declare const createSideSheet: (config?: SideSheetConfig) => SideSheetComponent;
24
+ export default createSideSheet;
@@ -0,0 +1,102 @@
1
+ import { SIDE_SHEET_VARIANTS, SIDE_SHEET_POSITIONS } from "./constants";
2
+ /** Docked or floating over a scrim */
3
+ export type SideSheetVariant = (typeof SIDE_SHEET_VARIANTS)[keyof typeof SIDE_SHEET_VARIANTS];
4
+ /** Which edge it docks to, in logical terms */
5
+ export type SideSheetPosition = (typeof SIDE_SHEET_POSITIONS)[keyof typeof SIDE_SHEET_POSITIONS];
6
+ /** Handlers accepted at creation, one per event name */
7
+ export interface SideSheetEventHandlers {
8
+ open?: () => void;
9
+ close?: () => void;
10
+ }
11
+ /**
12
+ * Configuration for the side sheet.
13
+ *
14
+ * @category Components
15
+ */
16
+ export interface SideSheetConfig {
17
+ /**
18
+ * Standard sheets dock beside the page and leave it usable; modal sheets
19
+ * float over it behind a scrim and take focus.
20
+ * @default 'modal'
21
+ */
22
+ variant?: SideSheetVariant;
23
+ /**
24
+ * Which edge to dock to. Logical, so `end` follows the writing direction.
25
+ * @default 'end'
26
+ */
27
+ position?: SideSheetPosition;
28
+ /**
29
+ * Headline in the header. Also names the sheet for assistive technology,
30
+ * through `aria-labelledby`.
31
+ */
32
+ title?: string;
33
+ /** Body of the sheet, as markup or an element */
34
+ content?: string | HTMLElement;
35
+ /**
36
+ * Width in pixels. Capped by `maxWidth`.
37
+ * @default 256
38
+ */
39
+ width?: number;
40
+ /**
41
+ * The sheet never grows past this, so it does not take over a wide window.
42
+ * @default 400
43
+ */
44
+ maxWidth?: number;
45
+ /**
46
+ * Whether the header carries a close button.
47
+ * @default true
48
+ */
49
+ closeButton?: boolean;
50
+ /**
51
+ * Whether a click on the scrim closes a modal sheet. Standard sheets have no
52
+ * scrim, so this does nothing for them.
53
+ * @default true
54
+ */
55
+ closeOnScrimClick?: boolean;
56
+ /**
57
+ * Whether Escape closes it.
58
+ * @default true
59
+ */
60
+ closeOnEscape?: boolean;
61
+ /** Whether the sheet starts open */
62
+ open?: boolean;
63
+ /** Where to mount the sheet. Defaults to `document.body` */
64
+ container?: HTMLElement;
65
+ /** Handlers registered at creation, equivalent to calling `on` for each */
66
+ on?: SideSheetEventHandlers;
67
+ /** Extra classes for the root element */
68
+ class?: string;
69
+ /** @internal */
70
+ prefix?: string;
71
+ /** @internal */
72
+ componentName?: string;
73
+ }
74
+ /**
75
+ * A side sheet instance.
76
+ *
77
+ * @category Components
78
+ */
79
+ export interface SideSheetComponent {
80
+ /** The root element, which holds the scrim and the container */
81
+ element: HTMLElement;
82
+ /** Opens the sheet */
83
+ open: () => SideSheetComponent;
84
+ /** Closes the sheet */
85
+ close: () => SideSheetComponent;
86
+ /** Opens it if closed, closes it if open */
87
+ toggle: () => SideSheetComponent;
88
+ /** Whether the sheet is showing */
89
+ isOpen: () => boolean;
90
+ /** Replaces the body */
91
+ setContent: (content: string | HTMLElement) => SideSheetComponent;
92
+ /** Replaces the headline */
93
+ setTitle: (title: string) => SideSheetComponent;
94
+ /** Adds an event listener */
95
+ on: <T extends keyof SideSheetEventHandlers>(event: T, handler: NonNullable<SideSheetEventHandlers[T]>) => SideSheetComponent;
96
+ /** Removes an event listener */
97
+ off: <T extends keyof SideSheetEventHandlers>(event: T, handler: NonNullable<SideSheetEventHandlers[T]>) => SideSheetComponent;
98
+ /** Removes the sheet from the page and releases its listeners */
99
+ destroy: () => void;
100
+ /** Prefixes a class name, for styling hooks */
101
+ getClass: (name: string) => string;
102
+ }