mtrl 0.8.0-next.30 → 0.8.0-next.32
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/dist/components/bottom-sheet/api.d.ts +43 -0
- package/dist/components/bottom-sheet/bottom-sheet.d.ts +24 -0
- package/dist/components/bottom-sheet/config.d.ts +34 -0
- package/dist/components/bottom-sheet/constants.d.ts +65 -0
- package/dist/components/bottom-sheet/features/drag.d.ts +32 -0
- package/dist/components/bottom-sheet/features/index.d.ts +3 -0
- package/dist/components/bottom-sheet/features/state.d.ts +31 -0
- package/dist/components/bottom-sheet/features/structure.d.ts +26 -0
- package/dist/components/bottom-sheet/index.d.ts +2 -0
- package/dist/components/bottom-sheet/types.d.ts +116 -0
- package/dist/components/index.d.ts +6 -0
- package/dist/components/side-sheet/api.d.ts +33 -0
- package/dist/components/side-sheet/config.d.ts +34 -0
- package/dist/components/side-sheet/constants.d.ts +60 -0
- package/dist/components/side-sheet/features/index.d.ts +2 -0
- package/dist/components/side-sheet/features/state.d.ts +28 -0
- package/dist/components/side-sheet/features/structure.d.ts +21 -0
- package/dist/components/side-sheet/index.d.ts +2 -0
- package/dist/components/side-sheet/side-sheet.d.ts +24 -0
- package/dist/components/side-sheet/types.d.ts +102 -0
- package/dist/index.cjs +13 -13
- package/dist/index.cjs.map +17 -4
- package/dist/index.js +13 -13
- package/dist/index.js.map +17 -4
- package/dist/package.json +1 -1
- package/dist/styles.css +2 -2
- package/package.json +1 -1
- package/src/styles/components/_bottom-sheet.scss +167 -0
- package/src/styles/components/_side-sheet.scss +175 -0
- package/src/styles/main.scss +2 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { BottomSheetComponent, BottomSheetEventHandlers, BottomSheetState } from "./types";
|
|
2
|
+
interface ApiOptions {
|
|
3
|
+
state: {
|
|
4
|
+
open: () => void;
|
|
5
|
+
close: () => void;
|
|
6
|
+
expand: () => void;
|
|
7
|
+
collapse: () => void;
|
|
8
|
+
isOpen: () => boolean;
|
|
9
|
+
getState: () => BottomSheetState;
|
|
10
|
+
release: () => void;
|
|
11
|
+
};
|
|
12
|
+
structure: {
|
|
13
|
+
setContent: (content: string | HTMLElement) => void;
|
|
14
|
+
setTitle: (title: string) => void;
|
|
15
|
+
};
|
|
16
|
+
drag: {
|
|
17
|
+
release: () => void;
|
|
18
|
+
};
|
|
19
|
+
lifecycle: {
|
|
20
|
+
destroy: () => void;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
interface BaseComponent {
|
|
24
|
+
element: HTMLElement;
|
|
25
|
+
getClass: (name: string) => string;
|
|
26
|
+
on: (event: string, handler: (...args: never[]) => void) => unknown;
|
|
27
|
+
off: (event: string, handler: (...args: never[]) => void) => unknown;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The public surface. Every method here is backed by a feature above it; none
|
|
31
|
+
* is declared and left unwired.
|
|
32
|
+
*/
|
|
33
|
+
export declare const withAPI: ({ state, structure, drag, lifecycle }: ApiOptions) => <C extends BaseComponent>(component: C) => BottomSheetComponent;
|
|
34
|
+
/**
|
|
35
|
+
* Registers the handlers given at creation.
|
|
36
|
+
*
|
|
37
|
+
* Several components in this library declare an `on` option and never read it,
|
|
38
|
+
* so handlers passed at creation are silently dropped. This one reads it.
|
|
39
|
+
*/
|
|
40
|
+
export declare const applyEventHandlers: (component: {
|
|
41
|
+
on: (event: string, handler: (...args: never[]) => void) => unknown;
|
|
42
|
+
}, handlers?: BottomSheetEventHandlers) => void;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BottomSheetConfig, BottomSheetComponent } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a bottom sheet: a surface anchored to the bottom edge holding
|
|
4
|
+
* content secondary to the page.
|
|
5
|
+
*
|
|
6
|
+
* A modal sheet covers the page with a scrim and takes focus, for a task that
|
|
7
|
+
* must finish first. A standard sheet leaves the page usable alongside it.
|
|
8
|
+
*
|
|
9
|
+
* @param {BottomSheetConfig} config - Bottom sheet configuration
|
|
10
|
+
* @returns {BottomSheetComponent} Bottom sheet instance
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const sheet = createBottomSheet({
|
|
15
|
+
* title: 'Share',
|
|
16
|
+
* content: '<p>Choose where to send it.</p>',
|
|
17
|
+
* on: { close: () => console.info('closed') }
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* sheet.open();
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
declare const createBottomSheet: (config?: BottomSheetConfig) => BottomSheetComponent;
|
|
24
|
+
export default createBottomSheet;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { BottomSheetConfig } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* What the component applies when the caller says nothing.
|
|
4
|
+
*/
|
|
5
|
+
export declare const defaultConfig: Partial<BottomSheetConfig>;
|
|
6
|
+
/**
|
|
7
|
+
* Merges the caller's configuration over the defaults.
|
|
8
|
+
*/
|
|
9
|
+
export declare const createBaseConfig: (config?: BottomSheetConfig) => BottomSheetConfig;
|
|
10
|
+
/**
|
|
11
|
+
* The root element: a fixed layer holding the scrim and the sheet itself.
|
|
12
|
+
*/
|
|
13
|
+
export declare const getElementConfig: (config: BottomSheetConfig) => {
|
|
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,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bottom sheet variants.
|
|
3
|
+
*
|
|
4
|
+
* A standard sheet sits alongside the page and leaves it usable. A modal sheet
|
|
5
|
+
* puts a scrim over the page and takes focus, so it is the one to reach for
|
|
6
|
+
* when the sheet's task must finish before anything else continues.
|
|
7
|
+
*/
|
|
8
|
+
export declare const BOTTOM_SHEET_VARIANTS: {
|
|
9
|
+
readonly STANDARD: "standard";
|
|
10
|
+
readonly MODAL: "modal";
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* How far the sheet is open.
|
|
14
|
+
*
|
|
15
|
+
* `partial` shows the peek height, enough to say what the sheet holds without
|
|
16
|
+
* covering the page. `expanded` shows as much as the content needs.
|
|
17
|
+
*/
|
|
18
|
+
export declare const BOTTOM_SHEET_STATES: {
|
|
19
|
+
readonly HIDDEN: "hidden";
|
|
20
|
+
readonly PARTIAL: "partial";
|
|
21
|
+
readonly EXPANDED: "expanded";
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Defaults, from Compose BottomSheetDefaults and SheetBottomTokens.
|
|
25
|
+
*/
|
|
26
|
+
export declare const BOTTOM_SHEET_DEFAULTS: {
|
|
27
|
+
readonly VARIANT: "modal";
|
|
28
|
+
/** BottomSheetDefaults.SheetPeekHeight */
|
|
29
|
+
readonly PEEK_HEIGHT: 56;
|
|
30
|
+
/** BottomSheetDefaults.SheetMaxWidth; wider viewports centre the sheet */
|
|
31
|
+
readonly MAX_WIDTH: 640;
|
|
32
|
+
/** A drag handle is part of the anatomy, so it is on unless asked otherwise */
|
|
33
|
+
readonly DRAG_HANDLE: true;
|
|
34
|
+
readonly CLOSE_ON_SCRIM_CLICK: true;
|
|
35
|
+
readonly CLOSE_ON_ESCAPE: true;
|
|
36
|
+
/**
|
|
37
|
+
* BottomSheetDefaults.PositionalThreshold: how far the sheet must be dragged
|
|
38
|
+
* before it settles at the next anchor rather than springing back.
|
|
39
|
+
*/
|
|
40
|
+
readonly POSITIONAL_THRESHOLD: 56;
|
|
41
|
+
/** BottomSheetDefaults.VelocityThreshold, in dp per second */
|
|
42
|
+
readonly VELOCITY_THRESHOLD: 125;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Class names, without the prefix. `getClass` adds it.
|
|
46
|
+
*/
|
|
47
|
+
export declare const BOTTOM_SHEET_CLASSES: {
|
|
48
|
+
readonly ROOT: "bottom-sheet";
|
|
49
|
+
readonly SCRIM: "bottom-sheet-scrim";
|
|
50
|
+
readonly CONTAINER: "bottom-sheet-container";
|
|
51
|
+
readonly HANDLE: "bottom-sheet-handle";
|
|
52
|
+
readonly HEADER: "bottom-sheet-header";
|
|
53
|
+
readonly TITLE: "bottom-sheet-title";
|
|
54
|
+
readonly CONTENT: "bottom-sheet-content";
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Events the sheet emits.
|
|
58
|
+
*/
|
|
59
|
+
export declare const BOTTOM_SHEET_EVENTS: {
|
|
60
|
+
readonly OPEN: "open";
|
|
61
|
+
readonly CLOSE: "close";
|
|
62
|
+
readonly STATE_CHANGE: "stateChange";
|
|
63
|
+
readonly DRAG_START: "dragStart";
|
|
64
|
+
readonly DRAG_END: "dragEnd";
|
|
65
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BottomSheetConfig, BottomSheetState } from "../types";
|
|
2
|
+
interface DragComponent {
|
|
3
|
+
getClass: (name: string) => string;
|
|
4
|
+
emit: (event: string, data?: unknown) => unknown;
|
|
5
|
+
structure: {
|
|
6
|
+
container: HTMLElement;
|
|
7
|
+
handle: HTMLElement | null;
|
|
8
|
+
};
|
|
9
|
+
state: {
|
|
10
|
+
getState: () => BottomSheetState;
|
|
11
|
+
setState: (next: BottomSheetState) => void;
|
|
12
|
+
close: () => void;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Dragging the sheet between its heights.
|
|
17
|
+
*
|
|
18
|
+
* Where the sheet settles follows Compose's rule: a drag past the positional
|
|
19
|
+
* threshold moves to the next anchor, and a flick past the velocity threshold
|
|
20
|
+
* does the same however short it was, so a quick flick works without having to
|
|
21
|
+
* cover the distance.
|
|
22
|
+
*/
|
|
23
|
+
export declare const withDrag: (config: BottomSheetConfig) => <C extends DragComponent>(component: C) => (C & {
|
|
24
|
+
drag: {
|
|
25
|
+
release: () => void;
|
|
26
|
+
};
|
|
27
|
+
}) | (C & {
|
|
28
|
+
drag: {
|
|
29
|
+
release: () => void;
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BottomSheetConfig, BottomSheetState } 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
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Opening, closing and the two open heights.
|
|
13
|
+
*
|
|
14
|
+
* Events go through `component.emit`, which is what the composed events
|
|
15
|
+
* enhancer provides. Reaching for `component.events.emit` throws, because that
|
|
16
|
+
* shape comes from a different enhancer the barrel exports under another name.
|
|
17
|
+
*/
|
|
18
|
+
export declare const withState: (config: BottomSheetConfig) => <C extends StateComponent>(component: C) => C & {
|
|
19
|
+
state: {
|
|
20
|
+
open: (to?: BottomSheetState) => void;
|
|
21
|
+
close: () => void;
|
|
22
|
+
expand: () => void;
|
|
23
|
+
collapse: () => void;
|
|
24
|
+
isOpen: () => boolean;
|
|
25
|
+
getState: () => BottomSheetState;
|
|
26
|
+
setState: (next: BottomSheetState) => void;
|
|
27
|
+
/** Releases the listeners this feature put on the document */
|
|
28
|
+
release: () => void;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BottomSheetConfig } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Builds the parts of the sheet and puts the whole thing on the page.
|
|
4
|
+
*
|
|
5
|
+
* The root element is a fixed layer that holds the scrim and the sheet
|
|
6
|
+
* container, so both are children of something that exists. An earlier sheet
|
|
7
|
+
* in this library inserted its scrim through `element.parentNode` at
|
|
8
|
+
* construction, when the element had no parent yet, and so never had a scrim
|
|
9
|
+
* at all.
|
|
10
|
+
*/
|
|
11
|
+
export declare const withStructure: (config: BottomSheetConfig) => <C extends {
|
|
12
|
+
element: HTMLElement;
|
|
13
|
+
getClass: (n: string) => string;
|
|
14
|
+
}>(component: C) => C & {
|
|
15
|
+
structure: {
|
|
16
|
+
scrim: HTMLElement;
|
|
17
|
+
container: HTMLDivElement;
|
|
18
|
+
handle: HTMLElement;
|
|
19
|
+
title: HTMLElement;
|
|
20
|
+
content: HTMLDivElement;
|
|
21
|
+
/** Replaces the body */
|
|
22
|
+
setContent(next: string | HTMLElement): void;
|
|
23
|
+
/** Replaces the headline, adding one if the sheet had none */
|
|
24
|
+
setTitle(next: string): void;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { BOTTOM_SHEET_VARIANTS, BOTTOM_SHEET_STATES } from "./constants";
|
|
2
|
+
/** Standard or modal */
|
|
3
|
+
export type BottomSheetVariant = (typeof BOTTOM_SHEET_VARIANTS)[keyof typeof BOTTOM_SHEET_VARIANTS];
|
|
4
|
+
/** How far the sheet is open */
|
|
5
|
+
export type BottomSheetState = (typeof BOTTOM_SHEET_STATES)[keyof typeof BOTTOM_SHEET_STATES];
|
|
6
|
+
/** What a state change reports */
|
|
7
|
+
export interface BottomSheetStateEvent {
|
|
8
|
+
/** The state the sheet has moved to */
|
|
9
|
+
state: BottomSheetState;
|
|
10
|
+
/** The state it came from */
|
|
11
|
+
previous: BottomSheetState;
|
|
12
|
+
}
|
|
13
|
+
/** Handlers accepted at creation, one per event name */
|
|
14
|
+
export interface BottomSheetEventHandlers {
|
|
15
|
+
open?: () => void;
|
|
16
|
+
close?: () => void;
|
|
17
|
+
stateChange?: (event: BottomSheetStateEvent) => void;
|
|
18
|
+
dragStart?: () => void;
|
|
19
|
+
dragEnd?: (event: BottomSheetStateEvent) => void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Configuration for the bottom sheet.
|
|
23
|
+
*
|
|
24
|
+
* @category Components
|
|
25
|
+
*/
|
|
26
|
+
export interface BottomSheetConfig {
|
|
27
|
+
/**
|
|
28
|
+
* Standard sheets leave the page usable; modal sheets cover it with a scrim
|
|
29
|
+
* and take focus.
|
|
30
|
+
* @default 'modal'
|
|
31
|
+
*/
|
|
32
|
+
variant?: BottomSheetVariant;
|
|
33
|
+
/**
|
|
34
|
+
* Headline shown above the content. Also names the sheet for assistive
|
|
35
|
+
* technology, through `aria-labelledby`.
|
|
36
|
+
*/
|
|
37
|
+
title?: string;
|
|
38
|
+
/** Body of the sheet, as markup or an element */
|
|
39
|
+
content?: string | HTMLElement;
|
|
40
|
+
/**
|
|
41
|
+
* The 32x4dp bar at the top edge, which says the sheet can be dragged.
|
|
42
|
+
* Turning it off also turns off dragging, since nothing would indicate it.
|
|
43
|
+
* @default true
|
|
44
|
+
*/
|
|
45
|
+
dragHandle?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Height of the partially expanded state, in pixels.
|
|
48
|
+
* @default 56
|
|
49
|
+
*/
|
|
50
|
+
peekHeight?: number;
|
|
51
|
+
/**
|
|
52
|
+
* The sheet stops growing at this width and centres itself, so it does not
|
|
53
|
+
* stretch across a desktop window.
|
|
54
|
+
* @default 640
|
|
55
|
+
*/
|
|
56
|
+
maxWidth?: number;
|
|
57
|
+
/**
|
|
58
|
+
* State to start in. `hidden` builds the sheet without showing it.
|
|
59
|
+
* @default 'hidden'
|
|
60
|
+
*/
|
|
61
|
+
initialState?: BottomSheetState;
|
|
62
|
+
/**
|
|
63
|
+
* Whether a click on the scrim closes a modal sheet. Standard sheets have no
|
|
64
|
+
* scrim, so this does nothing for them.
|
|
65
|
+
* @default true
|
|
66
|
+
*/
|
|
67
|
+
closeOnScrimClick?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Whether Escape closes a modal sheet.
|
|
70
|
+
* @default true
|
|
71
|
+
*/
|
|
72
|
+
closeOnEscape?: boolean;
|
|
73
|
+
/** Where to mount the sheet. Defaults to `document.body` */
|
|
74
|
+
container?: HTMLElement;
|
|
75
|
+
/** Handlers registered at creation, equivalent to calling `on` for each */
|
|
76
|
+
on?: BottomSheetEventHandlers;
|
|
77
|
+
/** Extra classes for the root element */
|
|
78
|
+
class?: string;
|
|
79
|
+
/** @internal */
|
|
80
|
+
prefix?: string;
|
|
81
|
+
/** @internal */
|
|
82
|
+
componentName?: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* A bottom sheet instance.
|
|
86
|
+
*
|
|
87
|
+
* @category Components
|
|
88
|
+
*/
|
|
89
|
+
export interface BottomSheetComponent {
|
|
90
|
+
/** The root element, which holds the scrim and the container */
|
|
91
|
+
element: HTMLElement;
|
|
92
|
+
/** Opens the sheet, partially expanded */
|
|
93
|
+
open: () => BottomSheetComponent;
|
|
94
|
+
/** Closes the sheet */
|
|
95
|
+
close: () => BottomSheetComponent;
|
|
96
|
+
/** Opens the sheet to its full height */
|
|
97
|
+
expand: () => BottomSheetComponent;
|
|
98
|
+
/** Returns the sheet to the peek height */
|
|
99
|
+
collapse: () => BottomSheetComponent;
|
|
100
|
+
/** Whether the sheet is showing at all */
|
|
101
|
+
isOpen: () => boolean;
|
|
102
|
+
/** How far the sheet is open */
|
|
103
|
+
getState: () => BottomSheetState;
|
|
104
|
+
/** Replaces the body of the sheet */
|
|
105
|
+
setContent: (content: string | HTMLElement) => BottomSheetComponent;
|
|
106
|
+
/** Replaces the headline */
|
|
107
|
+
setTitle: (title: string) => BottomSheetComponent;
|
|
108
|
+
/** Adds an event listener */
|
|
109
|
+
on: <T extends keyof BottomSheetEventHandlers>(event: T, handler: NonNullable<BottomSheetEventHandlers[T]>) => BottomSheetComponent;
|
|
110
|
+
/** Removes an event listener */
|
|
111
|
+
off: <T extends keyof BottomSheetEventHandlers>(event: T, handler: NonNullable<BottomSheetEventHandlers[T]>) => BottomSheetComponent;
|
|
112
|
+
/** Removes the sheet from the page and releases its listeners */
|
|
113
|
+
destroy: () => void;
|
|
114
|
+
/** Prefixes a class name, for styling hooks */
|
|
115
|
+
getClass: (name: string) => string;
|
|
116
|
+
}
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export { default as createBadge } from "./badge";
|
|
11
11
|
export { default as createBottomAppBar } from "./bottom-app-bar";
|
|
12
|
+
export { default as createBottomSheet } from "./bottom-sheet";
|
|
13
|
+
export { default as createSideSheet } from "./side-sheet";
|
|
12
14
|
export { default as createButton } from "./button";
|
|
13
15
|
export { default as createButtonGroup } from "./button-group";
|
|
14
16
|
export { default as createCard } from "./card";
|
|
@@ -34,6 +36,7 @@ export { default as createSearch } from "./search";
|
|
|
34
36
|
export { default as createSelect } from "./select";
|
|
35
37
|
export { default as createSegmentedButton } from "./segmented-button";
|
|
36
38
|
export { createSegment } from "./segmented-button/segment";
|
|
39
|
+
/** @deprecated Since 0.8.0. Use createBottomSheet or createSideSheet. */
|
|
37
40
|
export { default as createSheet } from "./sheet";
|
|
38
41
|
export { default as createSlider } from "./slider";
|
|
39
42
|
export { default as createSnackbar } from "./snackbar";
|
|
@@ -48,6 +51,8 @@ export { default as createTooltip } from "./tooltip";
|
|
|
48
51
|
export { createCardContent, createCardHeader, createCardActions, createCardMedia, } from "./card/content";
|
|
49
52
|
export type { BadgeConfig, BadgeComponent } from "./badge/types";
|
|
50
53
|
export type { BottomAppBarConfig, BottomAppBar } from "./bottom-app-bar/types";
|
|
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";
|
|
51
56
|
export type { ButtonConfig, ButtonComponent, ButtonVariant, } from "./button/types";
|
|
52
57
|
export type { ButtonGroupConfig, ButtonGroupComponent, ButtonGroupItemConfig, ButtonGroupEvent, ButtonGroupEventType, ButtonGroupVariant, ButtonGroupOrientation, ButtonGroupDensity, } from "./button-group/types";
|
|
53
58
|
export type { CardSchema } from "./card/types";
|
|
@@ -71,6 +76,7 @@ export type { RadiosConfig, RadiosComponent, RadioOptionConfig, } from "./radios
|
|
|
71
76
|
export type { SearchConfig, SearchComponent } from "./search/types";
|
|
72
77
|
export type { SelectConfig, SelectComponent, SelectOption, SelectEvent, SelectChangeEvent, } from "./select/types";
|
|
73
78
|
export type { SegmentedButtonConfig, SegmentedButtonComponent, } from "./segmented-button/types";
|
|
79
|
+
/** @deprecated Since 0.8.0. Use the BottomSheet or SideSheet types. */
|
|
74
80
|
export type { SheetConfig, SheetComponent } from "./sheet/types";
|
|
75
81
|
export type { SliderConfig, SliderComponent, SliderEvent, } from "./slider/types";
|
|
76
82
|
export type { SnackbarConfig, SnackbarComponent } from "./snackbar/types";
|
|
@@ -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,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,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;
|