/** * Site header component. * * @augments IvComponent */ export class Navbar extends IvComponent { /** @type {Readonly} */ static defaults: Readonly; /** * Returns the navbar instance attached to `el`, if any. * * @param {Element} el Host element. * @returns {Navbar|undefined} The instance or `undefined`. */ static get(el: Element): Navbar | undefined; /** * Returns the existing instance or creates one. * * @param {Element} el Host element. * @param {Partial} [options] Options passed in JavaScript. * @returns {Navbar} The instance. */ static getOrCreate(el: Element, options?: Partial): Navbar; /** * Instantiates every `[data-iv-component="navbar"]` inside `root`. * * @param {ParentNode} [root] Subtree to scan. * @returns {Navbar[]} Newly created instances. */ static initAll(root?: ParentNode): Navbar[]; /** * @param {Element} el A `
` element. * @param {Partial} [options] Options passed in JavaScript. */ constructor(el: Element, options?: Partial); /** @type {Map>} Attributes to restore. */ _saved: Map>; /** @type {Map} Original attribute order, per element. */ _order: Map; /** @type {HTMLElement|null} The `__toggle` of this header. */ _toggle: HTMLElement | null; /** @type {HTMLElement|null} The `__panel` of this header. */ _panel: HTMLElement | null; /** @type {boolean} Whether the collapsed panel is unfolded. */ _open: boolean; /** @type {boolean} Whether the header is currently condensed. */ _condensed: boolean; /** @type {boolean} Whether the header is currently slid away. */ _away: boolean; /** @type {boolean} Whether the viewport is below the collapse breakpoint. */ _collapsible: boolean; /** @type {MediaQueryList|null} Watcher of the collapse breakpoint. */ _mql: MediaQueryList | null; /** @type {number} Pending animation frame of the scroll handler. */ _frame: number; /** @type {boolean} Whether a measurement is already scheduled. */ _pending: boolean; /** @type {number} Scroll offset read on the previous frame. */ _lastY: number; /** @type {string|null} Inline `scroll-padding-block-start` this instance replaced. */ _scrollPadding: string | null; /** * Resolved options. * * @returns {Readonly} The options. */ get options(): Readonly; /** * Whether the collapsed panel is unfolded. Above the collapse breakpoint the * panel is always visible and this getter stays `false`: there is nothing * folded to open. * * @returns {boolean} `true` while the panel is unfolded. */ get isOpen(): boolean; /** * Whether the header is condensed by the scroll offset. * * @returns {boolean} `true` while condensed. */ get isCondensed(): boolean; /** * Remembers the current value of an attribute, once per element. * * @param {Element} el Element to remember. * @param {string} name Attribute name. * @returns {void} */ _remember(el: Element, name: string): void; /** * Sets a managed attribute, remembering its previous value. * * @param {Element} el Target element. * @param {string} name Attribute name. * @param {string} value Attribute value. * @returns {void} */ _set(el: Element, name: string, value: string): void; /** * Removes a managed attribute, remembering its previous value. * * @param {Element} el Target element. * @param {string} name Attribute name. * @returns {void} */ _unset(el: Element, name: string): void; /** * Subscribes to the collapse breakpoint. Below it the panel folds; above it * the panel is the bar itself. An unknown name is reported once and leaves * the header unfolded. * * @returns {void} */ _setupCollapse(): void; /** * Reflects the collapse state on the header, which is what the CSS reads to * fold the panel and to show the toggle. * * @returns {void} */ _syncCollapsible(): void; /** * Installs the scroll watcher when the header is sticky or hides on scroll, * plus the scroll padding that keeps anchors clear of a sticky header. * * @returns {void} */ _setupScroll(): void; /** * Keeps in-page anchors from landing under the sticky header. * * @returns {void} */ _applyScrollPadding(): void; /** * Puts the scroll padding back the way the page had it. * * @returns {void} */ _restoreScrollPadding(): void; /** * Coalesces scroll events into one measurement per frame. * * @returns {void} */ _onScroll(): void; /** * Reads the scroll offset and updates the condensed and slid-away states. * * @returns {void} */ _measure(): void; /** * Whether focus currently sits inside the header. * * @returns {boolean} `true` when it does. */ _focusInside(): boolean; /** * Closes when a click lands outside the header. * * @param {Event} event Click event. * @returns {void} */ _onDocumentClick(event: Event): void; /** * Escape closes the panel and hands focus back to the toggle. * * @param {Event} event Keydown event. * @returns {void} */ _onDocumentKeydown(event: Event): void; /** * Unfolds the panel. Emits the cancelable `iv:open` first. A no-op above the * collapse breakpoint, where the panel is already the bar. * * @param {{ trigger?: Element }} [detail] Element that asked for it. * @returns {void} */ open(detail?: { trigger?: Element; }): void; /** * Shared body of `open` and `toggle`: the only difference is the reason and * the element credited as the trigger. * * @param {NavbarReason} reason Why it opens. * @param {Element} [trigger] Element that asked for it. * @returns {void} */ _unfold(reason: NavbarReason, trigger?: Element): void; /** * Folds the panel back. Emits the cancelable `iv:close` first. * * @param {NavbarReason} [reason] Why it closes. * @returns {void} */ close(reason?: NavbarReason): void; /** * Unfolds the panel when folded, folds it when open. * * @returns {void} */ toggle(): void; } export type NavbarOptions = { /** * Breakpoint name below which the panel folds. `"none"` never folds. */ collapseBelow: string; /** * Keep the header at the top of the viewport and condense it on scroll. */ sticky: boolean; /** * Scroll offset, in pixels, that turns the condensed state on. */ condenseAt: number; /** * Slide the header away while scrolling down. */ hideOnScroll: boolean; /** * Close the open panel when a click lands outside the header. */ closeOnOutside: boolean; }; export type NavbarReason = "trigger" | "escape" | "external" | "api" | "viewport"; import { IvComponent } from "../core/component.js";