UNPKG

@dvcol/neo-svelte

Version:

Neomorphic ui library for svelte 5

74 lines (73 loc) 2.4 kB
import type { NeoButtonGroupProps } from '../buttons/neo-button-group.model.js'; import type { TabId } from './neo-tab.model.js'; import type { NeoTabContextValue, OnChange, OnClose } from './neo-tabs.model.js'; export interface NeoTabContextPosition { id: TabId; top: number; left: number; width: number; height: number; } export interface NeoTabContextPositions { oldTab?: NeoTabContextPosition; newTab?: NeoTabContextPosition; } type NeoTabContextOptions = { /** * Disables all tabs. */ disabled?: boolean; /** * Whether to animate the tab transition. * @default true */ slide?: boolean; /** * Clicking the active tab will unselect it. */ toggle?: boolean; /** * Add a button to add new tabs. */ add?: boolean; /** * Add a close button to each tab. */ close?: boolean; } & Pick<NeoButtonGroupProps, 'elevation' | 'pressed' | 'convex' | 'borderless' | 'glass' | 'start' | 'vertical'>; export type NeoTabsContext<T = unknown> = NeoTabContextOptions & { /** * The active tab ID. */ active?: TabId; /** * The active tab value. */ value?: NeoTabContextValue<T>; }; interface NeoTabContextCallbacks<T = unknown> { onChange?: OnChange<T>; onClose?: OnClose<T>; } export declare class NeoTabContext<T = unknown> { #private; get active(): TabId | undefined; get value(): NeoTabContextValue<T> | undefined; get previous(): NeoTabContextValue<T> | undefined; get position(): NeoTabContextPositions; get state(): NeoTabsContext; constructor({ onChange, onClose }?: NeoTabContextCallbacks<T>); getValue(tabId?: TabId): NeoTabContextValue<T> | undefined; getPane(tabId?: TabId): TabId | undefined; onOption(options: NeoTabContextOptions): void; onPosition(_ref?: HTMLElement | undefined): NeoTabContextPositions; onChange(tabId?: TabId, emit?: boolean): void; onClose(tabId?: TabId): void; register(tabId: TabId, value: Omit<NeoTabContextValue<T>, 'index'>): any; remove(tabId: TabId): void; registerPane(tabId: TabId, panelId: TabId): any; removePane(tabId: TabId): void; } export declare function getTabContext<T = unknown>(): NeoTabContext<T> | undefined; export declare function setTabContext<T = unknown>(callback?: NeoTabContextCallbacks<T>): NeoTabContext<T>; export {};