67 lines
2.3 KiB
TypeScript
67 lines
2.3 KiB
TypeScript
import type { CollectionKey } from "../collection/keys";
|
|
import type { useTableNavigation } from "./navigation";
|
|
export type TableKey = CollectionKey;
|
|
import type { ComputedRef, InjectionKey, Ref } from "vue";
|
|
import type { tableVariants } from "@heroui-vue/styles";
|
|
|
|
export type TableSlots = ReturnType<typeof tableVariants>;
|
|
export type TableSortDirection = "ascending" | "descending" | "none";
|
|
|
|
export interface TableContextValue {
|
|
columnDefinitions?: Ref<{ id?: string; isRowHeader: boolean }[]>;
|
|
columns?: Ref<
|
|
Map<symbol, { node: HTMLElement; id?: string; isRowHeader: boolean }>
|
|
>;
|
|
navigation?: ReturnType<typeof useTableNavigation>;
|
|
slots: ComputedRef<TableSlots>;
|
|
variant: ComputedRef<string>;
|
|
selectionMode: ComputedRef<"none" | "single" | "multiple">;
|
|
selectedKeys: ComputedRef<readonly TableKey[]>;
|
|
disabledKeys: ComputedRef<readonly TableKey[]>;
|
|
sortDescriptor: ComputedRef<{
|
|
column: string;
|
|
direction: TableSortDirection;
|
|
} | null>;
|
|
expandedKeys: ComputedRef<readonly TableKey[]>;
|
|
treeColumn: ComputedRef<string | undefined>;
|
|
toggleSelect: (key: TableKey, event?: MouseEvent | KeyboardEvent) => void;
|
|
toggleExpand: (key: TableKey) => void;
|
|
isRowSelected: (key: TableKey) => boolean;
|
|
isRowDisabled: (key: TableKey) => boolean;
|
|
isRowExpanded: (key: TableKey) => boolean;
|
|
sort: (column: string) => void;
|
|
}
|
|
|
|
export const tableContextKey: InjectionKey<TableContextValue> =
|
|
Symbol("hv-table");
|
|
|
|
export interface TableRowContextValue {
|
|
nextCellIndex: () => number;
|
|
key: TableKey;
|
|
isSelected: ComputedRef<boolean>;
|
|
isDisabled: ComputedRef<boolean>;
|
|
isExpanded: ComputedRef<boolean>;
|
|
hasChildItems: boolean;
|
|
}
|
|
|
|
export const tableRowContextKey: InjectionKey<TableRowContextValue> =
|
|
Symbol("hv-table-row");
|
|
|
|
export interface TableColumnContextValue {
|
|
key: ComputedRef<string | undefined>;
|
|
allowsSorting: ComputedRef<boolean>;
|
|
sortDirection: ComputedRef<TableSortDirection>;
|
|
}
|
|
|
|
export const tableColumnContextKey: InjectionKey<TableColumnContextValue> =
|
|
Symbol("hv-table-column");
|
|
|
|
export interface TableColumnWidthContext {
|
|
minWidth: ComputedRef<number | undefined>;
|
|
maxWidth: ComputedRef<number | undefined>;
|
|
width: ComputedRef<string | number | undefined>;
|
|
setWidth: (width: number) => void;
|
|
}
|
|
export const tableColumnWidthKey: InjectionKey<TableColumnWidthContext> =
|
|
Symbol("hv-table-column-width");
|