Skip to content

Commit

Permalink
expose renderers prop to allow custom internal renderers
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHung committed Jun 23, 2024
1 parent 5983dca commit e58e90d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/core/src/data-editor-all.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { sprites } from "./internal/data-grid/sprites.js";
import ImageWindowLoaderImpl from "./common/image-window-loader.js";
import type { ImageWindowLoader } from "./internal/data-grid/image-window-loader-interface.js";

export interface DataEditorAllProps extends Omit<DataEditorProps, "renderers" | "imageWindowLoader"> {
export interface DataEditorAllProps extends Omit<DataEditorProps, "imageWindowLoader"> {
imageWindowLoader?: ImageWindowLoader;
}

Expand All @@ -14,14 +14,18 @@ const DataEditorAllImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEdito
return { ...sprites, ...p.headerIcons };
}, [p.headerIcons]);

const renderers = React.useMemo(() => {
return p.renderers ?? AllCellRenderers;
}, [p.renderers])

const imageWindowLoader = React.useMemo(() => {
return p.imageWindowLoader ?? new ImageWindowLoaderImpl();
}, [p.imageWindowLoader]);

return (
<DataEditor
{...p}
renderers={AllCellRenderers}
renderers={renderers}
headerIcons={allSprites}
ref={ref}
imageWindowLoader={imageWindowLoader}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export { markerCellRenderer } from "./cells/marker-cell.js";
export { bubbleCellRenderer } from "./cells/bubble-cell.js";
export { protectedCellRenderer } from "./cells/protected-cell.js";
export { rowIDCellRenderer } from "./cells/row-id-cell.js";
export type { InternalCellRenderer } from "./cells/cell-types.js"
export { AllCellRenderers } from "./cells/index.js";
export { sprites } from "./internal/data-grid/sprites.js";
export { default as ImageWindowLoaderImpl } from "./common/image-window-loader.js";
Expand Down
28 changes: 28 additions & 0 deletions packages/core/test/data-editor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {
GridCellKind,
isSizedGridColumn,
type Item,
markerCellRenderer,
type InnerGridCell,
type InternalCellRenderer,
AllCellRenderers,
} from "../src/index.js";
import type { CustomCell } from "../src/internal/data-grid/data-grid-types.js";
import type { DataEditorRef } from "../src/data-editor/data-editor.js";
Expand Down Expand Up @@ -2572,6 +2576,30 @@ describe("data-editor", () => {
expect(onClickSpy).not.toBeCalled();
});

test("renderers can override internal cells", async () => {
const spy = vi.fn();

vi.useFakeTimers();
render(
<DataEditor
{...basicProps}
renderers={[
...AllCellRenderers,
{
...markerCellRenderer,
draw: spy
} as InternalCellRenderer<InnerGridCell>,
]}
rowMarkers="both"
/>,
{
wrapper: Context,
}
);
prep();
expect(spy).toHaveBeenCalledTimes(31); // Math.ceil((height - headerHeight) / rowHeight)
});

test("onCellsEdited blocks onCellEdited", async () => {
const spy = vi.fn();
vi.useFakeTimers();
Expand Down

0 comments on commit e58e90d

Please sign in to comment.