/* ! * (c) Copyright 2026 Palantir Technologies Inc. All rights reserved. */ import type { Meta, StoryObj } from "@storybook/react-vite"; import { storybookLayoutDecorator, StoryLabel } from "@storybook-common"; import { useArgs, useCallback } from "storybook/preview-api"; import { Flex } from "@blueprintjs/labs"; import { Card } from "../card/card"; import { CardList } from "./cardList"; type CardListStoryArgs = React.ComponentProps & { selectedIndex: number }; const meta: Meta = { title: "Core/CardList", component: CardList, decorators: [storybookLayoutDecorator], tags: ["autodocs"], args: { bordered: true, compact: false, }, argTypes: { bordered: { control: "boolean" }, compact: { control: "boolean" }, }, } satisfies Meta; export default meta; type Story = StoryObj; const FRUITS = ["Apples", "Oranges", "Bananas", "Grapes", "Mangoes"]; /** * A basic CardList with simple Card children. */ export const Default: Story = { render: args => ( {FRUITS.map(fruit => ( {fruit} ))} ), }; /** * CardList supports `bordered`, `compact`, `interactive`, and `selected` states across its Card children. */ export const StateExample: Story = { name: "State", argTypes: { bordered: { table: { disable: true } }, compact: { table: { disable: true } }, }, render: args => ( Plain Interactive Selected Plain Interactive Selected Plain Interactive Selected ), }; /** * All configurations: bordered vs non-bordered, default vs compact, with interactive and selected states. */ export const AllConfigurations: Story = { argTypes: { bordered: { table: { disable: true } }, compact: { table: { disable: true } }, }, render: () => ( {[false, true].map(compact => ( {[true, false].map(bordered => ( Plain Interactive Selected ))} ))} ), }; /** * Interactive playground with all props exposed via Storybook controls. * Click a card to select it. Click again to deselect. */ export const Playground: Story = { args: { selectedIndex: -1, }, argTypes: { selectedIndex: { control: "number", description: "Index of the currently selected card (-1 for none)" }, }, render: function Render(args) { const { selectedIndex, ...cardListProps } = args; const [, updateArgs] = useArgs(); const handleCardClick = useCallback( (index: number) => () => { updateArgs({ selectedIndex: selectedIndex === index ? -1 : index }); }, [selectedIndex, updateArgs], ); return ( {FRUITS.map((fruit, i) => ( {fruit} ))} ); }, };