mirror of
https://github.com/khoaliber/dockhand.git
synced 2026-03-03 13:18:56 +00:00
Initial commit
This commit is contained in:
28
lib/components/data-grid/context.ts
Normal file
28
lib/components/data-grid/context.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* DataGrid Context
|
||||
*
|
||||
* Provides shared state to child components via Svelte context.
|
||||
*/
|
||||
|
||||
import { getContext, setContext } from 'svelte';
|
||||
import type { DataGridContext } from './types';
|
||||
|
||||
const DATA_GRID_CONTEXT_KEY = Symbol('data-grid');
|
||||
|
||||
/**
|
||||
* Set the DataGrid context (called by DataGrid.svelte)
|
||||
*/
|
||||
export function setDataGridContext<T>(ctx: DataGridContext<T>): void {
|
||||
setContext(DATA_GRID_CONTEXT_KEY, ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the DataGrid context (called by child components)
|
||||
*/
|
||||
export function getDataGridContext<T = unknown>(): DataGridContext<T> {
|
||||
const ctx = getContext<DataGridContext<T>>(DATA_GRID_CONTEXT_KEY);
|
||||
if (!ctx) {
|
||||
throw new Error('DataGrid context not found. Ensure component is used within a DataGrid.');
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
Reference in New Issue
Block a user