feat: migrate ScrollShadow and Tabs with docs and keyboard support
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { inject, type InjectionKey, type Ref, type ComputedRef } from "vue";
|
||||
export type TabsKey = string | number;
|
||||
export interface TabBox {
|
||||
x: number;
|
||||
y: number;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
export interface TabsContext {
|
||||
selected: ComputedRef<TabsKey | undefined>;
|
||||
keyboardActivation: ComputedRef<"automatic" | "manual">;
|
||||
select: (value: TabsKey) => void;
|
||||
orientation: ComputedRef<"horizontal" | "vertical">;
|
||||
variant: ComputedRef<"primary" | "secondary">;
|
||||
dir: ComputedRef<"ltr" | "rtl">;
|
||||
disabled: (key: TabsKey) => boolean;
|
||||
domId: (kind: "tab" | "panel", key: TabsKey) => string;
|
||||
panels: Ref<Set<TabsKey>>;
|
||||
list: Ref<HTMLElement | undefined>;
|
||||
elements: Map<TabsKey, HTMLElement>;
|
||||
boxes: Ref<Map<TabsKey, TabBox>>;
|
||||
ready: Ref<boolean>;
|
||||
measure: () => void;
|
||||
}
|
||||
export const tabsKey: InjectionKey<TabsContext> = Symbol("hv-tabs");
|
||||
export function useTabs() {
|
||||
const ctx = inject(tabsKey);
|
||||
if (!ctx) throw new Error("Tabs parts require Tabs.");
|
||||
return ctx;
|
||||
}
|
||||
export const tabKey: InjectionKey<ComputedRef<TabsKey>> = Symbol("hv-tab");
|
||||
export function useTabKey() {
|
||||
const value = inject(tabKey);
|
||||
if (!value) throw new Error("TabsIndicator requires TabsTab.");
|
||||
return value;
|
||||
}
|
||||
|
||||
// An empty string is reserved for no selection. Encode user keys so Reka is
|
||||
// always controlled, even when an empty/disabled collection initially has no key.
|
||||
export function tabsWireKey(key: TabsKey | undefined): string {
|
||||
return key === undefined
|
||||
? ""
|
||||
: `${typeof key === "number" ? "n" : "s"}:${key}`;
|
||||
}
|
||||
Reference in New Issue
Block a user