import { type TemplateResult } from 'lit'; import type { CloseDetail } from '../shared/events.js'; import { UiElement } from '../shared/element.js'; import { type NotificationKind, type NotificationRole, type NotificationVariant } from '../../core/notification.js'; export type { NotificationKind, NotificationVariant, NotificationRole } from '../../core/notification.js'; /** * Carbon notification in one element: `InlineNotification` (default), `ToastNotification` * (`variant="toast"`), `ActionableNotification` (any variant with `action-label`) and `Callout` * (`variant="callout"`: static inline box with no role, no close button and no autofocus — for * persistent on-page guidance; its action button is described by the title). * * Follows Carbon's SCSS: 3px status bar on the start edge, 20px status icon, high-contrast * (inverse) surface by default or `low-contrast` tinted surface with a 1px status border, * 48px close button, inline min-height 48px / toast width 288px with a drop shadow. * `role` defaults to `status`; with `action-label` it becomes `alertdialog`, focus moves to the * action button, Tab stays inside it (Carbon `wrapFocus`) and Esc closes it while focus is inside * (Carbon `hasFocus` / `closeOnEscape`). `full-width` lets an inline notification fill its container (no Carbon * counterpart: Carbon caps it at 288 / 608 / 736 / 832px by breakpoint). A toast with `timeout` * closes itself — the countdown pauses while it is hovered or focused, and a notification with an * action never closes on its own (WCAG 2.2.1). * * Closing: the close button, Esc or the timeout fire a cancelable `ui-request-close`; unless * prevented the element sets `open` to false (hidden, still in the DOM) and fires `ui-close`. * * @slot - Extra content after the subtitle (links, details) * @slot title - Title with markup; the `heading` attribute is the plain-text fallback * @slot subtitle - Subtitle with markup; the `subtitle` attribute is the plain-text fallback * @fires ui-request-close - Cancelable; detail: { reason: 'close-button' | 'escape' | 'timeout' } * @fires ui-close - After it closed * @fires ui-action - The action button was pressed * @csspart base - The notification box * @csspart icon - The status icon * @csspart title - The title * @csspart subtitle - The subtitle * @csspart caption - The toast caption * @csspart action-button - The action button * @csspart close-button - The close button * @cssprop --ui-notification-radius - Corner radius (default 0; Kanok: 8px) * @cssprop --ui-notification-bar-width - Width of the status bar at the start (default 3px; Kanok: 0, the icon tells the kind) * @cssprop --ui-notification-frame-start - Low contrast: the frame's start side (default 0, the bar is there; Kanok: 1px) * @cssprop --ui-notification-background / --ui-notification-ink / --ui-notification-edge - The high-contrast box: fill, text and an extra `box-shadow` (default Carbon's inverse block, none; Kanok: the raised floating surface) * @cssprop --ui-notification-link / --ui-notification-hover / --ui-notification-focus - On that box: links and the action, the action's hover and the focus ring (default link-inverse, inverse hover, inverse ink) * @cssprop --ui-toast-shadow - A toast's shadow (default `0 2px 6px 0 rgb(0 0 0 / 0.2)`) * @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) */ export declare class UiNotification extends UiElement { static readonly styles: import("lit").CSSResult; /** Inline (default) or toast. */ variant: NotificationVariant; private readonly localize; /** Status kind; sets the colour and the icon. */ kind: NotificationKind; /** Tinted surface with primary text instead of the inverse surface. */ lowContrast: boolean; /** Bold title; the `title` slot replaces it when markup is needed. (Before 0.5: the `title` attribute, still accepted.) */ heading: string; /** @deprecated Use `heading` (a `title` attribute also shows the browser's tooltip). */ get titleText(): string; set titleText(value: string); static get observedAttributes(): string[]; attributeChangedCallback(name: string, old: string | null, value: string | null): void; /** Body text; the `subtitle` slot replaces it when markup is needed. */ subtitle: string; /** Toast only: small text under the subtitle, e.g. the time. */ caption: string; /** Label of the action button; set it to get Carbon's actionable notification. */ actionLabel: string; /** ARIA role of the notification box; defaults to `status`, or `alertdialog` when there is an action button. A `role` attribute is read and moved inside. */ role: NotificationRole | null; /** Milliseconds after which the notification closes itself (toast); 0 = never. Paused on hover / focus; ignored with `action-label`. */ timeout: number; hideCloseButton: boolean; /** Esc closes an actionable notification while focus is inside it (Carbon `closeOnEscape`). */ closeOnEscape: boolean; /** Keep focus where it is instead of moving it to the action button (Carbon `hasFocus={false}`). */ noAutofocus: boolean; /** Fills its container instead of Carbon's 288–832px cap (inline / callout; a toast stays 288px). */ fullWidth: boolean; /** Accessible name of the close button. */ closeLabel: string; /** Accessible description of the status icon; defaults to "`kind` icon" (e.g. "error icon") like Carbon. */ iconLabel: string; /** False once closed (reflects `open="false"`); set back to true to show it again. */ open: boolean; private readonly actionButton?; private readonly ids; private readonly slots; private timer?; connectedCallback(): void; disconnectedCallback(): void; protected firstUpdated(): void; protected updated(changed: Map): void; /** core/notification: the asked role, none for a callout (static content), alertdialog with an action, status otherwise. */ private get effectiveRole(); /** Time left before `timeout` closes the toast; paused while it is hovered or holds focus (WCAG 2.2.1). */ private countdown; private hovered; private focusWithin; private startTimer; private resumeTimer; private pauseTimer; private readonly onPointerEnter; private readonly onPointerLeave; /** Where focus came from; closing while focus is inside sends it back there instead of to ``. */ private returnFocus; private readonly onFocusIn; private readonly onFocusOut; /** Carbon `useEscapeToClose`: Esc closes it only while focus is inside it, so it never takes an Esc meant for another notification or a modal. */ private readonly onKeydown; private holdsFocus; /** The Tab stops in order: links / controls in the content, then the action and close buttons. */ private get tabStops(); /** Carbon `wrapFocus`: in an alertdialog notification Tab and Shift+Tab go round its stops. */ private readonly onTabKey; /** Asks to close (`ui-request-close`, cancelable); hides and fires `ui-close` unless prevented. */ close(reason?: NotificationCloseReason): void; private onAction; private renderAction; private renderClose; /** Focus the action button, else the close button. */ focus(options?: FocusOptions): void; render(): TemplateResult<1>; } export type NotificationCloseReason = 'close-button' | 'escape' | 'timeout'; export interface UiNotificationEventMap extends HTMLElementEventMap { 'ui-close': CustomEvent>; 'ui-action': CustomEvent; 'ui-request-close': CustomEvent>; } /** Typed listeners for UiNotification's events (declaration merging with the class). */ export interface UiNotification { addEventListener(type: K, listener: (this: UiNotification, event: UiNotificationEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: K, listener: (this: UiNotification, event: UiNotificationEventMap[K]) => unknown, options?: boolean | EventListenerOptions): void; removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; } declare global { interface HTMLElementTagNameMap { 'ui-notification': UiNotification; } }