@gustavogalveza/design-system 0.1.0 → 0.2.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/CHANGELOG.md +110 -0
- package/README.md +21 -0
- package/package.json +1 -1
- package/src/behaviors/_shared.d.ts +78 -0
- package/src/behaviors/bottom-sheet.d.ts +72 -0
- package/src/behaviors/carousel.d.ts +15 -0
- package/src/behaviors/date-picker.d.ts +113 -0
- package/src/behaviors/date-picker.js +27 -0
- package/src/behaviors/fab-menu.d.ts +61 -0
- package/src/behaviors/fab-menu.js +18 -2
- package/src/behaviors/menu.d.ts +49 -0
- package/src/behaviors/menu.js +78 -10
- package/src/behaviors/navigation-drawer.d.ts +65 -0
- package/src/behaviors/search.d.ts +68 -0
- package/src/behaviors/side-sheet.d.ts +56 -0
- package/src/behaviors/side-sheet.js +22 -2
- package/src/behaviors/tabs.d.ts +50 -0
- package/src/behaviors/time-picker.d.ts +82 -0
- package/src/behaviors/time-picker.js +18 -2
- package/src/behaviors/toolbar.d.ts +23 -0
- package/src/behaviors/tooltip.d.ts +34 -0
- package/src/behaviors/tooltip.js +40 -3
- package/src/components/app-bar.css +105 -18
- package/src/components/badge.css +46 -24
- package/src/components/bottom-sheet.css +102 -31
- package/src/components/button-group.css +79 -54
- package/src/components/button.css +70 -15
- package/src/components/card.css +84 -24
- package/src/components/carousel.css +81 -19
- package/src/components/checkbox.css +163 -19
- package/src/components/chip.css +182 -39
- package/src/components/date-picker.css +121 -17
- package/src/components/dialog.css +124 -32
- package/src/components/divider.css +39 -13
- package/src/components/extended-fab.css +101 -34
- package/src/components/fab-menu.css +197 -71
- package/src/components/fab.css +16 -4
- package/src/components/field.css +252 -118
- package/src/components/icon-button.css +25 -5
- package/src/components/list.css +46 -10
- package/src/components/loading-indicator.css +51 -14
- package/src/components/menu.css +96 -10
- package/src/components/navigation-bar.css +93 -15
- package/src/components/navigation-drawer.css +110 -28
- package/src/components/navigation-rail.css +102 -35
- package/src/components/progress.css +70 -9
- package/src/components/radio.css +80 -19
- package/src/components/search.css +121 -20
- package/src/components/segmented-button.css +110 -18
- package/src/components/side-sheet.css +93 -19
- package/src/components/slider.css +124 -28
- package/src/components/snackbar.css +71 -25
- package/src/components/split-button.css +50 -29
- package/src/components/switch.css +125 -8
- package/src/components/tabs.css +38 -10
- package/src/components/time-picker.css +92 -18
- package/src/components/toolbar.css +63 -21
- package/src/components/tooltip.css +118 -12
package/src/behaviors/menu.js
CHANGED
|
@@ -192,12 +192,36 @@ export function initMenu(root) {
|
|
|
192
192
|
items[index].focus();
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
/* Hueco real sobre y bajo el disparador. Se consulta antes de abrir, para
|
|
196
|
+
marcar el lado del que entra el panel, y después, para colocarlo. */
|
|
197
|
+
function roomAroundTrigger() {
|
|
198
|
+
const margin = 8;
|
|
199
|
+
const gap = 4;
|
|
200
|
+
const view = menu.ownerDocument.defaultView ?? globalThis;
|
|
201
|
+
const triggerRect = trigger.getBoundingClientRect();
|
|
202
|
+
return {
|
|
203
|
+
margin,
|
|
204
|
+
gap,
|
|
205
|
+
view,
|
|
206
|
+
triggerRect,
|
|
207
|
+
roomBelow: view.innerHeight - margin - triggerRect.bottom - gap,
|
|
208
|
+
roomAbove: triggerRect.top - margin - gap,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
195
212
|
function openMenu({ focus = true, focusLast = false } = {}) {
|
|
196
213
|
if (open) return;
|
|
197
214
|
|
|
198
215
|
open = true;
|
|
199
216
|
trigger.setAttribute("aria-expanded", "true");
|
|
200
217
|
|
|
218
|
+
/* El lado se marca antes de mostrar: el CSS deriva de él la esquina y el
|
|
219
|
+
sentido del `transform` de entrada. Cambiarlo después arrancaría la
|
|
220
|
+
animación desde otra esquina. */
|
|
221
|
+
const space = roomAroundTrigger();
|
|
222
|
+
menu.dataset.m3MenuSide =
|
|
223
|
+
space.roomAbove > space.roomBelow ? "above" : "below";
|
|
224
|
+
|
|
201
225
|
if (supportsPopover) {
|
|
202
226
|
try {
|
|
203
227
|
if (!menu.matches(":popover-open")) menu.showPopover();
|
|
@@ -219,10 +243,45 @@ export function initMenu(root) {
|
|
|
219
243
|
if (focus) focusItem(focusLast ? "last" : 0);
|
|
220
244
|
}
|
|
221
245
|
|
|
246
|
+
/* Caja del panel sin la animación de entrada. `getBoundingClientRect()`
|
|
247
|
+
devuelve la caja ya escalada y desplazada por la transición de apertura:
|
|
248
|
+
medir con ella dejaba el reposo a 8/12 px del ancla y el recorte a 2 px del
|
|
249
|
+
borde. Se deshace el `transform` con su propio origen en vez de apagarlo,
|
|
250
|
+
porque quitar el estilo a mitad de la transición cancelaría la entrada. El
|
|
251
|
+
`translate` de colocación ya está retirado cuando se llama. */
|
|
252
|
+
function layoutBox() {
|
|
253
|
+
const rect = menu.getBoundingClientRect();
|
|
254
|
+
const width = menu.offsetWidth;
|
|
255
|
+
const height = menu.offsetHeight;
|
|
256
|
+
let { left, top } = rect;
|
|
257
|
+
|
|
258
|
+
const style = getComputedStyle(menu);
|
|
259
|
+
if (style.transform !== "none") {
|
|
260
|
+
const m = new DOMMatrixReadOnly(style.transform);
|
|
261
|
+
/* La entrada solo escala y desplaza. Con rotación o reflejo el rect ya no
|
|
262
|
+
es la caja transformada y se usa tal cual. */
|
|
263
|
+
if (m.b === 0 && m.c === 0 && m.a > 0 && m.d > 0) {
|
|
264
|
+
const [originX, originY] = style.transformOrigin
|
|
265
|
+
.split(" ")
|
|
266
|
+
.map(parseFloat);
|
|
267
|
+
left = rect.left - (1 - m.a) * originX - m.e;
|
|
268
|
+
top = rect.top - (1 - m.d) * originY - m.f;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return {
|
|
273
|
+
left,
|
|
274
|
+
top,
|
|
275
|
+
right: left + width,
|
|
276
|
+
bottom: top + height,
|
|
277
|
+
width,
|
|
278
|
+
height,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
222
282
|
function fitToViewport() {
|
|
223
|
-
const margin =
|
|
224
|
-
|
|
225
|
-
const view = menu.ownerDocument.defaultView ?? globalThis;
|
|
283
|
+
const { margin, gap, view, triggerRect, roomBelow, roomAbove } =
|
|
284
|
+
roomAroundTrigger();
|
|
226
285
|
|
|
227
286
|
menu.style.removeProperty("max-inline-size");
|
|
228
287
|
menu.style.removeProperty("max-block-size");
|
|
@@ -236,11 +295,8 @@ export function initMenu(root) {
|
|
|
236
295
|
|
|
237
296
|
/* 2) Lado: se elige el que deja más hueco. Con el disparador pegado al
|
|
238
297
|
borde inferior, el hueco de abajo puede ser de 8 px y el menú quedaba en
|
|
239
|
-
16 px, sin ítems. */
|
|
240
|
-
const
|
|
241
|
-
const roomBelow = view.innerHeight - margin - triggerRect.bottom - gap;
|
|
242
|
-
const roomAbove = triggerRect.top - margin - gap;
|
|
243
|
-
const useAbove = roomAbove > roomBelow;
|
|
298
|
+
16 px, sin ítems. El lado ya está marcado en el panel al abrir. */
|
|
299
|
+
const useAbove = menu.dataset.m3MenuSide === "above";
|
|
244
300
|
const room = Math.max(0, useAbove ? roomAbove : roomBelow);
|
|
245
301
|
|
|
246
302
|
if (room > 0 && menu.offsetHeight > room) {
|
|
@@ -248,7 +304,7 @@ export function initMenu(root) {
|
|
|
248
304
|
}
|
|
249
305
|
|
|
250
306
|
/* 3) Si el CSS no lo dejó en ese lado, se coloca con `translate`. */
|
|
251
|
-
const rect =
|
|
307
|
+
const rect = layoutBox();
|
|
252
308
|
let dx = 0;
|
|
253
309
|
if (rect.left < margin) dx = margin - rect.left;
|
|
254
310
|
else if (rect.right > view.innerWidth - margin) {
|
|
@@ -258,7 +314,7 @@ export function initMenu(root) {
|
|
|
258
314
|
let dy = 0;
|
|
259
315
|
if (room > 0) {
|
|
260
316
|
const targetTop = useAbove
|
|
261
|
-
? triggerRect.top - gap -
|
|
317
|
+
? triggerRect.top - gap - rect.height
|
|
262
318
|
: triggerRect.bottom + gap;
|
|
263
319
|
dy = targetTop - rect.top;
|
|
264
320
|
}
|
|
@@ -266,6 +322,16 @@ export function initMenu(root) {
|
|
|
266
322
|
if (Math.abs(dx) > 1 || Math.abs(dy) > 1) {
|
|
267
323
|
menu.style.translate = `${Math.round(dx)}px ${Math.round(dy)}px`;
|
|
268
324
|
}
|
|
325
|
+
|
|
326
|
+
/* 4) Esquina del ancla para el origen del `transform`: el borde del panel
|
|
327
|
+
que comparte con el disparador, contando el ajuste. `flip-inline` y
|
|
328
|
+
`dir="rtl"` en la raíz lo llevan al lado derecho. */
|
|
329
|
+
const sideLeft = rect.left + dx;
|
|
330
|
+
menu.dataset.m3MenuSideInline =
|
|
331
|
+
Math.abs(sideLeft + rect.width - triggerRect.right) <
|
|
332
|
+
Math.abs(sideLeft - triggerRect.left)
|
|
333
|
+
? "right"
|
|
334
|
+
: "left";
|
|
269
335
|
}
|
|
270
336
|
|
|
271
337
|
function closeMenu({ returnFocus = true } = {}) {
|
|
@@ -511,6 +577,8 @@ export function initMenu(root) {
|
|
|
511
577
|
menu.style.removeProperty("max-inline-size");
|
|
512
578
|
menu.style.removeProperty("max-block-size");
|
|
513
579
|
menu.style.removeProperty("translate");
|
|
580
|
+
delete menu.dataset.m3MenuSide;
|
|
581
|
+
delete menu.dataset.m3MenuSideInline;
|
|
514
582
|
menu.removeAttribute("data-m3-menu-open");
|
|
515
583
|
|
|
516
584
|
if (anchorName) {
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Navigation drawer — drawer modal de Material 3 Expressive.
|
|
3
|
+
*
|
|
4
|
+
* Emite `navigation-drawer:open` y `navigation-drawer:close` en el root
|
|
5
|
+
* (burbujean).
|
|
6
|
+
*
|
|
7
|
+
* Atributos leídos del DOM:
|
|
8
|
+
* `data-navigation-drawer-lock-scroll="false"`,
|
|
9
|
+
* `data-navigation-drawer-close-on-navigate="false"` y
|
|
10
|
+
* `data-navigation-drawer-initial-focus="<selector>"`.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export interface NavigationDrawerOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Selector del primer elemento enfocado; `"self"` enfoca el panel.
|
|
16
|
+
* Por defecto, el primer destino.
|
|
17
|
+
*/
|
|
18
|
+
initialFocus?: string | null;
|
|
19
|
+
/** Devuelve el foco al disparador al cerrar. Por defecto `true`. */
|
|
20
|
+
returnFocus?: boolean;
|
|
21
|
+
/** Cierra al elegir un destino. Por defecto `true`. */
|
|
22
|
+
closeOnNavigate?: boolean;
|
|
23
|
+
/** Bloquea el scroll de la página. Por defecto `true`. */
|
|
24
|
+
lockScroll?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface NavigationDrawerCloseOptions {
|
|
28
|
+
restoreFocus?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** `event.detail` de `navigation-drawer:open` y `navigation-drawer:close`. */
|
|
32
|
+
export interface NavigationDrawerEventDetail {
|
|
33
|
+
drawer: NavigationDrawer;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class NavigationDrawer {
|
|
37
|
+
/**
|
|
38
|
+
* @param root Contenedor con `data-navigation-drawer` y un `[role="dialog"]`.
|
|
39
|
+
* Reinstanciar el mismo root devuelve la instancia existente.
|
|
40
|
+
*/
|
|
41
|
+
constructor(root: HTMLElement, options?: NavigationDrawerOptions);
|
|
42
|
+
|
|
43
|
+
readonly root: HTMLElement;
|
|
44
|
+
readonly dialog: Element;
|
|
45
|
+
readonly scrim: Element | null;
|
|
46
|
+
readonly id: string;
|
|
47
|
+
options: Required<NavigationDrawerOptions>;
|
|
48
|
+
isOpen: boolean;
|
|
49
|
+
|
|
50
|
+
open(opener?: HTMLElement | null): this;
|
|
51
|
+
close(options?: NavigationDrawerCloseOptions): this;
|
|
52
|
+
toggle(opener?: HTMLElement | null): this;
|
|
53
|
+
destroy(): void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Inicializa (o devuelve) un drawer; `null` si no hay root. */
|
|
57
|
+
export function initNavigationDrawer(
|
|
58
|
+
root: HTMLElement | null | undefined,
|
|
59
|
+
options?: NavigationDrawerOptions,
|
|
60
|
+
): NavigationDrawer | null;
|
|
61
|
+
|
|
62
|
+
/** Inicializa los `[data-navigation-drawer]` del ámbito. */
|
|
63
|
+
export function initNavigationDrawers(
|
|
64
|
+
scope?: ParentNode,
|
|
65
|
+
): NavigationDrawer[];
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search — barra y vista de búsqueda de Material 3 Expressive.
|
|
3
|
+
*
|
|
4
|
+
* Eventos (burbujean):
|
|
5
|
+
* `search:open` / `search:close` en la vista.
|
|
6
|
+
* `search:submit` / `search:clear` en el formulario.
|
|
7
|
+
*
|
|
8
|
+
* Atributos leídos del DOM:
|
|
9
|
+
* `data-m3-search-modal="false"` en la vista, `data-m3-search-open="<id>"`
|
|
10
|
+
* en los disparadores.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export interface SearchOptions {
|
|
14
|
+
/** Fuerza el modo modal. Por defecto se deduce del `<dialog>`/`aria-modal`. */
|
|
15
|
+
modal?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface SearchCloseOptions {
|
|
19
|
+
/** Devuelve el foco al disparador. Por defecto `true`. */
|
|
20
|
+
restoreFocus?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface SearchController {
|
|
24
|
+
/** Vista conectada. */
|
|
25
|
+
readonly view: HTMLElement;
|
|
26
|
+
readonly options: SearchOptions;
|
|
27
|
+
readonly isOpen: boolean;
|
|
28
|
+
/** Añade disparadores y formularios nuevos dentro de `scope`. */
|
|
29
|
+
refresh(scope?: ParentNode): void;
|
|
30
|
+
open(opener?: HTMLElement | null): SearchController;
|
|
31
|
+
close(options?: SearchCloseOptions): SearchController;
|
|
32
|
+
toggle(opener?: HTMLElement | null): SearchController;
|
|
33
|
+
destroy(): void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** `event.detail` de `search:open` y `search:close`. */
|
|
37
|
+
export interface SearchToggleDetail {
|
|
38
|
+
view: HTMLElement;
|
|
39
|
+
trigger: HTMLElement | null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** `event.detail` de `search:submit`. */
|
|
43
|
+
export interface SearchSubmitDetail {
|
|
44
|
+
value: string;
|
|
45
|
+
query: string;
|
|
46
|
+
form: HTMLFormElement;
|
|
47
|
+
view: Element | null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** `event.detail` de `search:clear`. */
|
|
51
|
+
export interface SearchClearDetail {
|
|
52
|
+
form: HTMLFormElement;
|
|
53
|
+
value: "";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Conecta una vista de búsqueda (o su contenedor). Si el ámbito solo tiene
|
|
58
|
+
* formularios, los cablea y devuelve `null`.
|
|
59
|
+
*/
|
|
60
|
+
export function initSearch(
|
|
61
|
+
root: Element,
|
|
62
|
+
options?: SearchOptions,
|
|
63
|
+
): SearchController | null;
|
|
64
|
+
|
|
65
|
+
/** Inicializa las vistas del ámbito y cablea las barras sueltas. */
|
|
66
|
+
export function initAllSearches(
|
|
67
|
+
scope?: Document | ShadowRoot | Element,
|
|
68
|
+
): SearchController[];
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Side sheet — hoja lateral modal de Material 3 Expressive.
|
|
3
|
+
*
|
|
4
|
+
* Emite `side-sheet:open` y `side-sheet:close` en el root (burbujean).
|
|
5
|
+
*
|
|
6
|
+
* Atributos leídos del DOM:
|
|
7
|
+
* `data-side-sheet-lock-scroll="false"` y
|
|
8
|
+
* `data-side-sheet-initial-focus="<selector>"`.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export interface SideSheetOptions {
|
|
12
|
+
/** Selector del primer elemento enfocado. Por defecto, el primero enfocable. */
|
|
13
|
+
initialFocus?: string | null;
|
|
14
|
+
/** Devuelve el foco al disparador al cerrar. Por defecto `true`. */
|
|
15
|
+
returnFocus?: boolean;
|
|
16
|
+
/** Bloquea el scroll de la página. Por defecto `true`. */
|
|
17
|
+
lockScroll?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface SideSheetCloseOptions {
|
|
21
|
+
restoreFocus?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** `event.detail` de `side-sheet:open` y `side-sheet:close`. */
|
|
25
|
+
export interface SideSheetEventDetail {
|
|
26
|
+
sheet: SideSheet;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class SideSheet {
|
|
30
|
+
/**
|
|
31
|
+
* @param root Contenedor con `data-side-sheet` y un `[role="dialog"]`.
|
|
32
|
+
* Reinstanciar el mismo root devuelve la instancia existente.
|
|
33
|
+
*/
|
|
34
|
+
constructor(root: HTMLElement, options?: SideSheetOptions);
|
|
35
|
+
|
|
36
|
+
readonly root: HTMLElement;
|
|
37
|
+
readonly dialog: Element;
|
|
38
|
+
readonly scrim: Element | null;
|
|
39
|
+
readonly id: string;
|
|
40
|
+
options: Required<SideSheetOptions>;
|
|
41
|
+
isOpen: boolean;
|
|
42
|
+
|
|
43
|
+
open(opener?: HTMLElement | null): this;
|
|
44
|
+
close(options?: SideSheetCloseOptions): this;
|
|
45
|
+
toggle(opener?: HTMLElement | null): this;
|
|
46
|
+
destroy(): void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Inicializa (o devuelve) una hoja; `null` si no hay root. */
|
|
50
|
+
export function initSideSheet(
|
|
51
|
+
root: HTMLElement | null | undefined,
|
|
52
|
+
options?: SideSheetOptions,
|
|
53
|
+
): SideSheet | null;
|
|
54
|
+
|
|
55
|
+
/** Inicializa las `[data-side-sheet]` del ámbito (el documento por defecto). */
|
|
56
|
+
export function initSideSheets(scope?: ParentNode): SideSheet[];
|
|
@@ -35,7 +35,12 @@ import {
|
|
|
35
35
|
} from "./_shared.js";
|
|
36
36
|
|
|
37
37
|
const OPEN_CLASS = "m3-side-sheet-container--open";
|
|
38
|
+
const CLOSING_CLASS = "m3-side-sheet-container--closing";
|
|
38
39
|
const TOGGLE_ATTR = "data-side-sheet-toggle";
|
|
40
|
+
/* La salida del panel dura 500 ms (`spatial-default`): hasta que termina, la
|
|
41
|
+
* hoja sigue visible y debe seguir bloqueando el puntero, así que `inert` se
|
|
42
|
+
* aplica con este margen. */
|
|
43
|
+
const EXIT_INERT_MS = 520;
|
|
39
44
|
|
|
40
45
|
const instances = new Map();
|
|
41
46
|
|
|
@@ -138,6 +143,8 @@ export class SideSheet {
|
|
|
138
143
|
this._opener = opener instanceof HTMLElement ? opener : null;
|
|
139
144
|
this.isOpen = true;
|
|
140
145
|
this.root.classList.add(OPEN_CLASS);
|
|
146
|
+
clearTimeout(this._inertTimer);
|
|
147
|
+
this.root.classList.remove(CLOSING_CLASS);
|
|
141
148
|
this._syncOpenState();
|
|
142
149
|
this._syncToggles();
|
|
143
150
|
this._lockScroll();
|
|
@@ -152,6 +159,8 @@ export class SideSheet {
|
|
|
152
159
|
|
|
153
160
|
this.isOpen = false;
|
|
154
161
|
this.root.classList.remove(OPEN_CLASS);
|
|
162
|
+
/* El contenedor sigue bloqueando el puntero mientras la hoja se ve. */
|
|
163
|
+
this.root.classList.add(CLOSING_CLASS);
|
|
155
164
|
this._syncToggles();
|
|
156
165
|
this._unlockScroll();
|
|
157
166
|
|
|
@@ -164,8 +173,15 @@ export class SideSheet {
|
|
|
164
173
|
document.activeElement.blur();
|
|
165
174
|
}
|
|
166
175
|
|
|
167
|
-
/*
|
|
168
|
-
|
|
176
|
+
/* El foco ya salió. `inert` se aplica al terminar la salida: además de
|
|
177
|
+
quitar el foco, bloquea el puntero, y aplicarlo ahora dejaba pasar los
|
|
178
|
+
clics a través de una hoja todavía visible (medido: a los 45 ms un clic
|
|
179
|
+
activaba el botón de debajo). */
|
|
180
|
+
clearTimeout(this._inertTimer);
|
|
181
|
+
this._inertTimer = setTimeout(() => {
|
|
182
|
+
this.root.classList.remove(CLOSING_CLASS);
|
|
183
|
+
if (!this.isOpen) this._syncOpenState();
|
|
184
|
+
}, EXIT_INERT_MS);
|
|
169
185
|
this._emit("side-sheet:close");
|
|
170
186
|
return this;
|
|
171
187
|
}
|
|
@@ -178,6 +194,7 @@ export class SideSheet {
|
|
|
178
194
|
if (this._destroyed) return;
|
|
179
195
|
this._destroyed = true;
|
|
180
196
|
this.isOpen = false;
|
|
197
|
+
clearTimeout(this._inertTimer);
|
|
181
198
|
|
|
182
199
|
document.removeEventListener("click", this._onDocumentClick);
|
|
183
200
|
document.removeEventListener("keydown", this._onKeydown);
|
|
@@ -187,6 +204,9 @@ export class SideSheet {
|
|
|
187
204
|
cancelFocusFrame(this);
|
|
188
205
|
this._unlockScroll();
|
|
189
206
|
this.root.classList.remove(OPEN_CLASS);
|
|
207
|
+
/* Si se destruye a mitad de la salida, `--closing` dejaba el contenedor
|
|
208
|
+
* bloqueando el puntero para siempre: la página dejaba de responder. */
|
|
209
|
+
this.root.classList.remove(CLOSING_CLASS);
|
|
190
210
|
this.root.removeAttribute("inert");
|
|
191
211
|
this.root.removeAttribute("aria-hidden");
|
|
192
212
|
this._opener = null;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tabs — comportamiento para `role="tablist"` de Material 3 Expressive.
|
|
3
|
+
*
|
|
4
|
+
* Emite `m3-tab-change` en el tablist (burbujea).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface TabsOptions {
|
|
8
|
+
/**
|
|
9
|
+
* `manual` (por defecto) mueve el foco con las flechas y selecciona con
|
|
10
|
+
* Enter/Espacio; `automatic` selecciona al enfocar.
|
|
11
|
+
*/
|
|
12
|
+
readonly activation?: "manual" | "automatic";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface TabSelectOptions {
|
|
16
|
+
/** Enfoca la pestaña seleccionada. */
|
|
17
|
+
focus?: boolean;
|
|
18
|
+
/** Emite `m3-tab-change`. Por defecto `true`. */
|
|
19
|
+
emit?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface TabsController {
|
|
23
|
+
/** Tablist conectado. */
|
|
24
|
+
readonly tablist: Element;
|
|
25
|
+
/** Pestañas habilitadas, en orden de documento. */
|
|
26
|
+
readonly tabs: Element[];
|
|
27
|
+
/** Pestaña seleccionada o `null`. */
|
|
28
|
+
readonly selected: Element | null;
|
|
29
|
+
/** Selecciona por índice, `id` o elemento. */
|
|
30
|
+
select(target: number | string | Element, options?: TabSelectOptions): void;
|
|
31
|
+
/** Desconecta los listeners y libera el registro. */
|
|
32
|
+
destroy(): boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** `event.detail` de `m3-tab-change`. */
|
|
36
|
+
export interface TabChangeDetail {
|
|
37
|
+
tab: Element;
|
|
38
|
+
panel: Element | null;
|
|
39
|
+
previousTab: Element | null;
|
|
40
|
+
previousPanel: Element | null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Conecta un tablist (o un ancestro que lo contenga). */
|
|
44
|
+
export function initTabs(root: Element, options?: TabsOptions): TabsController;
|
|
45
|
+
|
|
46
|
+
/** Inicializa los `[data-m3-tabs]` del ámbito (el documento por defecto). */
|
|
47
|
+
export function initAllTabs(
|
|
48
|
+
scope?: Document | ShadowRoot | Element,
|
|
49
|
+
options?: TabsOptions,
|
|
50
|
+
): TabsController[];
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Time picker — selector de hora de Material 3 Expressive (esfera y campos).
|
|
3
|
+
*
|
|
4
|
+
* Emite `time-picker:change` en la raíz (burbujea).
|
|
5
|
+
*
|
|
6
|
+
* Atributos leídos del DOM:
|
|
7
|
+
* `data-value` (`"HH:MM"`), `data-view` (`"dial" | "input"`) y
|
|
8
|
+
* `data-field` (`"hour" | "minute"`) en el root.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Hora y minuto ya normalizados. */
|
|
12
|
+
export interface TimeParts {
|
|
13
|
+
hours: number;
|
|
14
|
+
minutes: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface TimePickerOptions {
|
|
18
|
+
/** Hora inicial `"HH:MM"` o `{ hours, minutes }`; gana a `data-value`. */
|
|
19
|
+
value?: string | TimeParts;
|
|
20
|
+
/** Vista inicial; gana a `data-view`. */
|
|
21
|
+
view?: "dial" | "input";
|
|
22
|
+
/** Campo activo inicial; gana a `data-field`. */
|
|
23
|
+
field?: "hour" | "minute";
|
|
24
|
+
/** Al elegir la hora salta a los minutos. Por defecto `true`. */
|
|
25
|
+
autoAdvance?: boolean;
|
|
26
|
+
/** Callback además del evento. */
|
|
27
|
+
onChange?: (detail: TimePickerChangeDetail) => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** `event.detail` de `time-picker:change`. */
|
|
31
|
+
export interface TimePickerChangeDetail {
|
|
32
|
+
/** 0–23. */
|
|
33
|
+
hours: number;
|
|
34
|
+
/** 0–59. */
|
|
35
|
+
minutes: number;
|
|
36
|
+
period: "AM" | "PM";
|
|
37
|
+
/** Hora en 24 h, `"HH:MM"`. */
|
|
38
|
+
value: string;
|
|
39
|
+
/** Origen: `"dial"`, `"input"`, `"period"`, `"api"` o `"init"`. */
|
|
40
|
+
source: string;
|
|
41
|
+
/** Elemento raíz del picker. */
|
|
42
|
+
picker: Element;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface TimePickerController {
|
|
46
|
+
readonly root: Element;
|
|
47
|
+
/** Hora en 24 h, `"HH:MM"`. */
|
|
48
|
+
readonly value: string;
|
|
49
|
+
readonly hours: number;
|
|
50
|
+
readonly minutes: number;
|
|
51
|
+
readonly period: "AM" | "PM";
|
|
52
|
+
readonly view: "dial" | "input";
|
|
53
|
+
readonly field: "hour" | "minute";
|
|
54
|
+
/** Devuelve `false` si la hora no se entiende. */
|
|
55
|
+
setValue(
|
|
56
|
+
value: string | TimeParts,
|
|
57
|
+
options?: { source?: string; emit?: boolean },
|
|
58
|
+
): boolean;
|
|
59
|
+
/** Cambia de vista; `focus` mueve el foco al campo o número activo. */
|
|
60
|
+
setView(view: "dial" | "input", options?: { focus?: boolean }): void;
|
|
61
|
+
destroy(): boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Acepta `"9:05"`, `"09:05"`, `"9:05 PM"`, `"21:05"` y `{ hours, minutes }`.
|
|
66
|
+
* Devuelve horas 0–23 o `null` si no se entiende.
|
|
67
|
+
*/
|
|
68
|
+
export function parseTime(
|
|
69
|
+
input: string | TimeParts | null | undefined,
|
|
70
|
+
): TimeParts | null;
|
|
71
|
+
|
|
72
|
+
/** Conecta un `[data-m3-time-picker]`; idempotente. */
|
|
73
|
+
export function initTimePicker(
|
|
74
|
+
root: Element,
|
|
75
|
+
options?: TimePickerOptions,
|
|
76
|
+
): TimePickerController;
|
|
77
|
+
|
|
78
|
+
/** Inicializa los `[data-m3-time-picker]` del ámbito. */
|
|
79
|
+
export function initAllTimePickers(
|
|
80
|
+
scope?: Document | ShadowRoot | Element,
|
|
81
|
+
options?: TimePickerOptions,
|
|
82
|
+
): TimePickerController[];
|
|
@@ -179,6 +179,21 @@ export function initTimePicker(root, options = {}) {
|
|
|
179
179
|
const minuteIndex = () => Math.round(state.minutes / MINUTE_STEP) % 12;
|
|
180
180
|
const activeIndex = () => (field === "hour" ? hourIndex() : minuteIndex());
|
|
181
181
|
|
|
182
|
+
/* Ángulo acumulado de la manecilla. Sin esto la transición de `rotate`
|
|
183
|
+
interpola el número tal cual y 55 → 00 (330° → 0°) gira 330° hacia atrás
|
|
184
|
+
en vez de 30° hacia delante. Se guarda sin normalizar para que la
|
|
185
|
+
interpolación de CSS tome siempre el camino corto. Solo afecta a la
|
|
186
|
+
animación: el valor de la hora no se toca. */
|
|
187
|
+
let dialAngle = null;
|
|
188
|
+
|
|
189
|
+
function shortAngle(target) {
|
|
190
|
+
if (dialAngle === null) return target; // primer render: sin giro de entrada
|
|
191
|
+
let delta = (((target - dialAngle) % 360) + 540) % 360 - 180;
|
|
192
|
+
/* En el empate exacto (180°) se sigue hacia delante, como las agujas. */
|
|
193
|
+
if (delta === -180) delta = 180;
|
|
194
|
+
return dialAngle + delta;
|
|
195
|
+
}
|
|
196
|
+
|
|
182
197
|
/**
|
|
183
198
|
* Pinta el estado en todas las representaciones. `syncInputs: false` evita
|
|
184
199
|
* pisar lo que la persona está escribiendo.
|
|
@@ -239,8 +254,9 @@ export function initTimePicker(root, options = {}) {
|
|
|
239
254
|
"aria-label",
|
|
240
255
|
isMinute ? "Esfera de minutos" : "Esfera de horas",
|
|
241
256
|
);
|
|
242
|
-
const
|
|
243
|
-
|
|
257
|
+
const target = isMinute ? state.minutes * 6 : hourIndex() * 30;
|
|
258
|
+
dialAngle = shortAngle(target);
|
|
259
|
+
dial.style.setProperty("--m3-time-picker-angle", `${dialAngle}deg`);
|
|
244
260
|
}
|
|
245
261
|
|
|
246
262
|
for (const button of periodButtons) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Toolbar — navegación por flechas con un solo tab-stop en `role="toolbar"`.
|
|
3
|
+
* Sin eventos personalizados.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface ToolbarOptions {
|
|
7
|
+
/** Fuerza RTL; por defecto lo deduce de `direction`. */
|
|
8
|
+
rtl?: boolean | null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ToolbarController {
|
|
12
|
+
/** Retira los listeners y el roving tabindex. */
|
|
13
|
+
destroy(): void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Conecta una toolbar; throws si no es un `HTMLElement`. */
|
|
17
|
+
export function initToolbar(
|
|
18
|
+
toolbar: HTMLElement,
|
|
19
|
+
options?: ToolbarOptions,
|
|
20
|
+
): ToolbarController;
|
|
21
|
+
|
|
22
|
+
/** Inicializa las `[role="toolbar"]` del ámbito (el documento por defecto). */
|
|
23
|
+
export function initToolbars(scope?: ParentNode): ToolbarController[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tooltip — colocación, volteo y `Esc` para `.m3-tooltip-anchor`.
|
|
3
|
+
*
|
|
4
|
+
* El comportamiento es opcional: sin él, el CSS sigue abriendo la burbuja.
|
|
5
|
+
* No emite eventos personalizados; escribe `data-side` y las variables
|
|
6
|
+
* `--m3-tooltip-shift-*` en la burbuja.
|
|
7
|
+
*
|
|
8
|
+
* Los anclajes con `data-m3-tooltip` se autoinicializan al cargar el módulo.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export interface TooltipController {
|
|
12
|
+
/** Anclaje `.m3-tooltip-anchor`. */
|
|
13
|
+
readonly anchor: HTMLElement;
|
|
14
|
+
/** Primer hijo del anclaje que no es la burbuja. */
|
|
15
|
+
readonly trigger: HTMLElement | null;
|
|
16
|
+
/** Burbuja `.m3-tooltip`. */
|
|
17
|
+
readonly tooltip: HTMLElement;
|
|
18
|
+
/** Abre la burbuja de forma programática y la recoloca. */
|
|
19
|
+
show(): void;
|
|
20
|
+
/** Oculta la burbuja hasta que el puntero o el foco vuelvan a entrar. */
|
|
21
|
+
hide(): void;
|
|
22
|
+
/** Vuelve a medir y colocar; útil tras cambiar texto o layout. */
|
|
23
|
+
reposition(): void;
|
|
24
|
+
destroy(): void;
|
|
25
|
+
readonly isVisible: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Conecta un anclaje (o la burbuja, o un descendiente); idempotente. */
|
|
29
|
+
export function initTooltip(root: Element): TooltipController;
|
|
30
|
+
|
|
31
|
+
/** Inicializa los `.m3-tooltip-anchor` del ámbito (el documento por defecto). */
|
|
32
|
+
export function initAllTooltips(
|
|
33
|
+
scope?: Document | ShadowRoot | Element,
|
|
34
|
+
): TooltipController[];
|