import type { CloseDetail } from '../shared/events.js'; import { UiElement } from '../shared/element.js'; import { type ModalCloseReason } from '../../core/modal.js'; export type { ModalCloseReason } from '../../core/modal.js'; /** * Carbon-style modal built on the native `` + showModal(), which gives us the * top layer, an inert page behind, a focus trap, Esc handling and focus return for free. * * Put `autofocus` on the element that should receive focus first; otherwise, as Carbon (cds-modal / * React Modal, traced key by key), the first focusable control in the body gets it, then the first * footer button, then the close button — or, with `alert`, the least destructive footer button. * Tab cycles inside the dialog; Esc closes and focus returns to the control that opened it. Over other overlays (a * side panel, a tearsheet, another modal) one Esc closes only the topmost, and a vetoed close stays vetoed however * often Esc is pressed. * * - `alert`: role="alertdialog" for confirmations that interrupt (e.g. delete); the body * becomes the description. * - A body that overflows becomes a focusable, labelled region so keyboard users can scroll it. * - Outside clicks (Carbon): a modal with footer buttons (transactional) never closes on a click * outside it, so typed input isn't lost; a passive modal (no footer) does, unless `persistent`. * * @slot - Body content * @slot label - Small label above the heading (the row renders only when slotted) * @slot footer - Action buttons (laid out full-bleed, Carbon style) * @slot header-actions - Controls at the top end of the header, beside the close button (one 48px button fits) * @fires ui-request-close - Cancelable; detail: { reason }. preventDefault() keeps it open. * @fires ui-close - After the modal has closed * @csspart dialog - The native `` panel * @csspart header - Header row * @csspart header-actions - Wrapper of the `header-actions` slot * @csspart label - The small label above the heading * @csspart heading - The heading * @csspart close-button - The × button * @csspart body - Scrollable body * @csspart footer - Footer holding the action buttons * @cssprop --ui-modal-radius - Corner radius (default 0; Kanok: 12px) * @cssprop --ui-modal-shadow - `box-shadow` of the box (default none) * @cssprop --ui-modal-scrim - The overlay behind the box (default `rgb(22 22 22 / 0.5)`) * @cssprop --ui-overlay-background - The box's surface, shared by every floating surface (default layer 1) * @cssprop --ui-overlay-border - The box's border, shared by modal, side panel and tearsheet (default none) * @cssprop --ui-modal-footer-gap - Gap between footer buttons (default none: they touch) * @cssprop --ui-modal-footer-height - Footer `min-height` (default 64px) * @cssprop --ui-modal-footer-padding - Footer padding (default 0: full-bleed buttons) * @cssprop --ui-modal-footer-border - Border above the footer (default none) * @cssprop --ui-modal-button-flex - `flex` of each footer button (default `0 1 50%`: halves) * @cssprop --ui-modal-button-height - Height of the footer buttons (default 64px) * @cssprop --ui-modal-button-align - `align-items` of their content (default `flex-start`: text at the top) * @cssprop --ui-modal-button-padding-top - Their top padding (default 14px) * @cssprop --ui-close-size - Size of the × button (default 48px; Kanok: 32px) * @cssprop --ui-close-inset - Margin that sets the × in from the corner (default 0; Kanok: 8px) * @cssprop --ui-icon-control-radius - Corners of the ×, its hover fill and its ring (default 0; Kanok: round) * @cssprop --ui-focus-offset - `outline-offset` of the ×'s focus ring (default -2px: inside; Kanok: 2px outside) * @cssprop --ui-modal-body-focus-radius - Corners of the scrolling body's focus ring (default 0; Kanok: 6px) */ export declare class UiModal extends UiElement { static readonly styles: import("lit").CSSResult; open: boolean; private readonly localize; heading: string; /** Accessible name when there is no heading (Carbon `aria-label`); the `label` slot is used before it. */ label: string; /** Dialog width (Carbon modal sizes): sm 480px, md 672px, lg 1056px — never wider than the viewport minus 16px a side. */ size: 'sm' | 'md' | 'lg'; /** A passive modal (no footer) ignores outside clicks too; one with footer buttons always does (Carbon). */ persistent: boolean; /** Accessible name for the close button. */ closeLabel: string; /** Interrupting confirmation: role="alertdialog", focus starts on the safest action. */ alert: boolean; private bodyScrollable; private readonly dialog; private readonly body; private readonly content; private resizeObserver?; /** Created on connect (none at construction, for server rendering); re-observed after the element moves. */ private observeSize; private readonly headingId; private readonly labelId; private readonly bodyId; private hasFooter; private pointerDownOnBackdrop; /** Shown, on the overlay stack and holding the page still; cleared (once) by finishClose. */ private active; /** A `
` inside is closing the dialog: honour it, as before. */ private formClosing; /** Its place on the page's overlay stack: Esc reaches it only while it is the topmost layer. */ private readonly layer; show(): void; close(): void; /** Ask to close — fires cancelable `ui-request-close` first. */ requestClose(reason: ModalCloseReason): void; protected updated(changed: Map): void; connectedCallback(): void; firstUpdated(): void; disconnectedCallback(): void; /** * Initial focus once the elements inside have rendered: a modal open from its first render would * otherwise find its `ui-button`s without their inner button yet and fall back to ×. */ private focusWhenReady; /** Carbon: the first focusable control in the body, else the first footer button, else × (the native dialog would pick × as it comes first). */ private focusInitial; /** Alert dialogs start on the safest action (e.g. Cancel), unless the page chose `autofocus`. */ private focusLeastDestructive; /** Idempotent cleanup — runs on our own close and on the native `close` event. */ private finishClose; /** * A close request the page's Esc listener didn't take (Esc is routed there, core/overlay.ts; this is e.g. Android's * back gesture): through requestClose, so the app can veto it, and only when this is the topmost layer. */ private onCancel; private onSubmit; /** * The dialog closed. Our own close has already set `open` false. A `` inside closes it: keep * `open` in sync. Anything else that closed it without asking (the browser's close watcher after a vetoed Esc) is * a request: vetoed, the dialog opens again. */ private onClose; private onPointerDown; /** Carbon: transactional modals (footer buttons) never close on an outside click; passive ones do unless `persistent`. */ private get closesOnOutsideClick(); private onClick; private isOutside; private hasHeaderActions; private readonly slots; private readonly onHeaderActionsSlotChange; private onFooterSlotChange; /** Focus inside the open dialog (the least destructive control, as on open). */ focus(options?: FocusOptions): void; /** The heading names the dialog; without one the `label` slot does. */ private get nameId(); render(): import("lit-html").TemplateResult<1>; } export interface UiModalEventMap extends HTMLElementEventMap { 'ui-close': Event; 'ui-request-close': CustomEvent>; } /** Typed listeners for UiModal's events (declaration merging with the class). */ export interface UiModal { addEventListener(type: K, listener: (this: UiModal, event: UiModalEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: K, listener: (this: UiModal, event: UiModalEventMap[K]) => unknown, options?: boolean | EventListenerOptions): void; removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; } declare global { interface HTMLElementTagNameMap { 'ui-modal': UiModal; } }