import React from "react";
import { DataEditorAll as DataEditor } from "../../data-editor-all.js";
import {
BeautifulWrapper,
Description,
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";
import range from "lodash/range.js";
import { faker } from "@faker-js/faker";
export default {
title: "Glide-Data-Grid/DataEditor Demos",
decorators: [
(Story: React.ComponentType) => (
Text cells can have wrapping text by setting the allowWrapping prop to
true.
}>
),
],
};
export const WrappingText: React.VFC<{
alignment: "left" | "center" | "right";
length: number;
hyperWrapping: boolean;
}> = p => {
const { cols, getCellContent, onColumnResize } = useMockDataGenerator(6);
const suffix = React.useMemo(() => {
return range(0, 100).map(() => faker.lorem.sentence(p.length));
}, [p.length]);
const mangledGetCellContent = React.useCallback(
i => {
const [col, row] = i;
if (col === 0) {
return {
kind: GridCellKind.Text,
allowOverlay: true,
displayData: `${row},\n${suffix[row % suffix.length]}`,
data: `${row}, \n${suffix}`,
allowWrapping: true,
contentAlign: p.alignment,
};
}
return getCellContent(i);
},
[getCellContent, p.alignment, suffix]
);
return (
);
};
(WrappingText as any).args = {
alignment: "left",
length: 20,
hyperWrapping: false,
};
(WrappingText as any).argTypes = {
alignment: {
control: { type: "select" },
options: ["left", "center", "right"],
},
length: {
control: {
type: "range",
min: 2,
max: 200,
},
},
};