diff --git a/.storybook/utils.ts b/.storybook/utils.ts deleted file mode 100644 index 8ebed11..0000000 --- a/.storybook/utils.ts +++ /dev/null @@ -1,17 +0,0 @@ -export function generateHexColor(index: number) { - const hue = (index * 137) % 360; // Golden angle approximation for color diversity - return hslToHex(hue, 100, 50); // Convert HSL to HEX -} - -function hslToHex(h: number, s: number, l: number) { - l /= 100; - const a = (s * Math.min(l, 1 - l)) / 100; - const f = (n) => { - const k = (n + h / 30) % 12; - const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1); - return Math.round(255 * color) - .toString(16) - .padStart(2, "0"); // Convert to hex and pad with zeros - }; - return `${f(0)}${f(8)}${f(4)}`; -} diff --git a/src/components/data/itemgrid/itemgrid.stories.tsx b/src/components/data/itemgrid/itemgrid.stories.tsx index acbe679..ab657f0 100644 --- a/src/components/data/itemgrid/itemgrid.stories.tsx +++ b/src/components/data/itemgrid/itemgrid.stories.tsx @@ -1,10 +1,15 @@ import type { Meta, StoryObj } from "@storybook/react"; import * as React from "react"; -import { useEffect, useState } from "react"; import { PAGE_DECORATOR } from "../../../../.storybook/decorators"; -import { generateHexColor } from "../../../../.storybook/utils"; -import { AttributeData, FieldSet } from "../../../lib"; +import { + FIXTURE_TODOS, + FIXTURE_TODOS_STATUS_DONE, + FIXTURE_TODOS_STATUS_IN_PROGRESS, + FIXTURE_TODOS_STATUS_IN_REVIEW, + FIXTURE_TODOS_STATUS_TODO, +} from "../../../../.storybook/fixtures/todos"; +import { AttributeData } from "../../../lib"; import { ItemGrid, ItemGridProps } from "./itemgrid"; const meta: Meta = { @@ -17,59 +22,25 @@ export default meta; type Story = StoryObj; export const ItemGridComponent: Story = { - // @ts-expect-error - Fix never + // @ts-expect-error - never args: { title: "The quick brown fox jumps over the lazy dog.", fieldsets: [ - ["Even", { fields: ["title"], title: "title" }], - ["Odd", { fields: ["title"], title: "title" }], + ["Todo", { fields: ["title"], title: "title" }], + ["In Progress", { fields: ["title"], title: "title" }], + ["In Review", { fields: ["title"], title: "title" }], + ["Done", { fields: ["title"], title: "title" }], + ], + objectLists: [ + FIXTURE_TODOS_STATUS_TODO, + FIXTURE_TODOS_STATUS_IN_PROGRESS, + FIXTURE_TODOS_STATUS_IN_REVIEW, + FIXTURE_TODOS_STATUS_DONE, ], - }, - render: (args: ItemGridProps) => { - const abortController = new AbortController(); - const [objectList, setObjectList] = useState([]); - // Process sorting and pagination locally in place for demonstration purposes. - - useEffect(() => { - const limit = "groupBy" in args ? 200 : 11; - fetch(`https://jsonplaceholder.typicode.com/photos?_limit=${limit}`, { - signal: abortController.signal, - }) - .then((response) => response.json()) - .then((data: AttributeData[]) => { - setObjectList( - data.map((d) => { - const url = `https://placehold.co/600x400/${generateHexColor(d.id as number)}/000`; - return { - ...d, - alphaIndex: String(d.title?.toString()[0]).toUpperCase(), - url: url, - thumbnailUrl: url, - }; - }), - ); - }); - }, [args]); - - const even = objectList.filter((o, index) => index % 2 === 0); - const odd = objectList.filter((o, index) => index % 2 !== 0); - - return "groupBy" in args ? ( - - ) : ( - - ); }, }; -export const WithCustomPreview: Story = { +export const CustomPreview: Story = { ...ItemGridComponent, // @ts-expect-error - Fix never args: { @@ -77,10 +48,9 @@ export const WithCustomPreview: Story = { renderPreview: (attributeData: AttributeData) => ( {attributeData.title} ), }, @@ -90,7 +60,10 @@ export const GroupBy: Story = { ...ItemGridComponent, // @ts-expect-error - Fix never args: { + ...(ItemGridComponent.args as ItemGridProps), + title: "The quick brown fox jumps over the lazy dog.", fieldset: [`{group}`, { fields: ["title"], title: "title" }], - groupBy: "alphaIndex", + objectList: FIXTURE_TODOS, + groupBy: "status", }, }; diff --git a/src/components/data/itemgrid/itemgrid.tsx b/src/components/data/itemgrid/itemgrid.tsx index adcecc2..55ba5c2 100644 --- a/src/components/data/itemgrid/itemgrid.tsx +++ b/src/components/data/itemgrid/itemgrid.tsx @@ -93,7 +93,7 @@ export const ItemGridSection: React.FC = ({ {fieldset[0] && ( -

{fieldset[0]}

+

{field2Title(fieldset[0])}

)} {objectList.map((o, index) => (