@dvcol/neo-svelte
Version:
Neomorphic ui library for svelte 5
80 lines (79 loc) • 2.84 kB
TypeScript
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 extends TabId> {
id: Id;
top: number;
left: number;
width: number;
height: number;
}
export interface NeoTabContextPositions<Id extends TabId> {
oldTab?: NeoTabContextPosition<Id>;
newTab?: NeoTabContextPosition<Id>;
}
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<Id extends TabId, Value = unknown> = NeoTabContextOptions & {
/**
* The active tab ID.
*/
active?: Id;
/**
* The active tab value.
*/
value?: NeoTabContextValue<Value>;
};
interface NeoTabContextCallbacks<Id extends TabId, Value = unknown> {
onChange?: OnChange<Id, Value>;
onClose?: OnClose<Id, Value>;
}
export declare class NeoTabContext<Id extends TabId, Value = unknown> {
#private;
get active(): Id | undefined;
get value(): NeoTabContextValue<Value> | undefined;
get previous(): NeoTabContextValue<Value> | undefined;
get position(): NeoTabContextPositions<Id>;
get state(): NeoTabsContext<Id, Value>;
constructor({ onChange, onClose }?: NeoTabContextCallbacks<Id, Value>);
getValue(tabId?: Id): NeoTabContextValue<Value> | undefined;
getPane(tabId?: Id): Id | undefined;
onOption(options: NeoTabContextOptions): void;
onPosition(_ref?: HTMLElement | undefined): NeoTabContextPositions<Id>;
onChange(tabId?: Id, emit?: boolean): void;
onClose(tabId?: Id): void;
register(tabId: Id, value: Omit<NeoTabContextValue<Value>, 'index'>, force?: boolean): any;
/**
* Removes the tab from the context.
* @param tabId - The tab ID to remove.
* @param discard - If true, the active tab will be discarded.
*/
remove(tabId: Id, discard?: boolean): void;
clear(discard?: boolean): void;
registerPane(tabId: Id, panelId: Id): any;
removePane(tabId: Id): void;
}
export declare function getTabContext<Id extends TabId, Value = unknown>(): NeoTabContext<Id, Value> | undefined;
export declare function setTabContext<Id extends TabId, Value = unknown>(callback?: NeoTabContextCallbacks<Id, Value>): NeoTabContext<Id, Value>;
export {};