Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jassmith committed Apr 22, 2022
1 parent a223bee commit be51224
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
43 changes: 43 additions & 0 deletions packages/core/API.md
Expand Up @@ -1048,3 +1048,46 @@ If `isDraggable` is set, the whole Grid is draggable, and `onDragStart` will be
Behavior not defined or officially supported. Feel free to check out what this does in github but anything in here is up for grabs to be changed at any time.

---

# Hooks

## useCustomCells

```ts
// arguments passed to the draw callback
interface DrawArgs {
ctx: CanvasRenderingContext2D;
theme: Theme;
rect: Rectangle;
hoverAmount: number;
hoverX: number | undefined;
hoverY: number | undefined;
col: number;
row: number;
highlighted: boolean;
imageLoader: ImageWindowLoader;
}

// a standardized cell renderer consumed by the hook
type CustomCellRenderer<T extends CustomCell> = {
isMatch: (cell: CustomCell) => cell is T;
draw: (args: DrawArgs, cell: T) => boolean;
provideEditor: ProvideEditorCallback<T>;
};

// the hook itself
declare function useCustomCells(cells: readonly CustomCellRenderer<any>[]): { drawCell: DrawCustomCellCallback, provideEditor: ProvideEditorCallback<GridCell> };
```

The useCustomCells hook provides a standardized method of integrating custom cells into the Glide Data Grid. All cells in the `@glideapps/glide-data-grid-source` package are already in this format and can be used individually by passing them to this hook as so. The result of the hook is an object which can be spread on the DataEditor to implement the cells.

```tsx
import StarCell from "@glideapps/glide-data-grid-cells/cells/star-cell";
import DropdownCell from "@glideapps/glide-data-grid-cells/cells/dropdown-cell";

const MyGrid = () => {
const args = useCustomCells([StarCell, DropdownCell])

return <DataEditor {...args} />
}
```
2 changes: 1 addition & 1 deletion packages/core/src/data-editor/use-custom-cells.ts
Expand Up @@ -6,7 +6,7 @@ import { DataEditorProps } from "./data-editor";

type DrawCallback = NonNullable<DataEditorProps["drawCell"]>;

interface DrawArgs {
export interface DrawArgs {
ctx: CanvasRenderingContext2D;
theme: Theme;
rect: Rectangle;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Expand Up @@ -4,7 +4,7 @@ export type { OverlayImageEditorProps } from "./data-grid-overlay-editor/private
export type { MarkdownDivProps } from "./markdown-div/markdown-div";
export type { SpriteMap } from "./data-grid/data-grid-sprites";
export type { Theme } from "./common/styles";
export type { CustomCellRenderer } from "./data-editor/use-custom-cells";
export type { CustomCellRenderer, DrawArgs } from "./data-editor/use-custom-cells";

export * from "./data-editor/data-editor";
export * from "./data-grid/data-grid-types";
Expand Down

0 comments on commit be51224

Please sign in to comment.