import React from "react";
import { DataEditorAll as DataEditor } from "../../data-editor-all.js";
import {
BeautifulWrapper,
Description,
MoreInfo,
PropName,
useMockDataGenerator,
defaultProps,
} from "../../data-editor/stories/utils.js";
import { GridCellKind } from "../../internal/data-grid/data-grid-types.js";
import { SimpleThemeWrapper } from "../../stories/story-utils.js";
export default {
title: "Glide-Data-Grid/DataEditor Demos",
decorators: [
(Story: React.ComponentType) => (
Data can be validated using the validateCell callback
This example only allows the word "Valid" inside text cells.
>
}>
),
],
};
export const ValidateData: React.VFC = () => {
const { cols, getCellContent, setCellValue } = useMockDataGenerator(60, false);
return (
{
if (newValue.kind !== GridCellKind.Text) return true;
if (newValue.data === "Valid") return true;
if (newValue.data.toLowerCase() === "valid") {
return {
...newValue,
data: "Valid",
selectionRange: [0, 3],
};
}
return false;
}}
/>
);
};