// Copyright 2024, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import { Meta, StoryObj } from "@storybook/react"; import { Avatar } from "./avatar"; import { List } from "./list"; import "./list.less"; const meta: Meta = { title: "Elements/List", component: List, argTypes: { items: { control: "object" }, renderItem: { control: false }, }, }; export default meta; type Story = StoryObj; // Container style for limiting the width to 360px const Container = (props: any) => (
{props.children}
); const basicItems = [ { text: "Inbox", icon: , onClick: () => console.log("Inbox clicked"), }, { text: "Sent Mail", icon: , onClick: () => console.log("Sent Mail clicked"), }, { text: "Drafts", icon: , onClick: () => console.log("Drafts clicked"), }, ]; const nestedItems = [ { text: "Inbox", icon: , onClick: () => console.log("Inbox clicked"), children: [ { text: "Starred", icon: , onClick: () => console.log("Starred clicked"), }, { text: "Important", icon: , onClick: () => console.log("Important clicked"), }, { text: "Inbox", icon: , onClick: () => console.log("Inbox clicked"), children: [ { text: "Starred", icon: , onClick: () => console.log("Starred clicked"), }, { text: "Important", icon: , onClick: () => console.log("Important clicked"), }, { text: "Inbox", icon: , onClick: () => console.log("Inbox clicked"), children: [ { text: "Starred", icon: , onClick: () => console.log("Starred clicked"), }, { text: "Important", icon: , onClick: () => console.log("Important clicked"), }, { text: "Inbox", icon: , onClick: () => console.log("Inbox clicked"), children: [ { text: "Starred", icon: , onClick: () => console.log("Starred clicked"), }, { text: "Important", icon: , onClick: () => console.log("Important clicked"), }, ], }, ], }, ], }, ], }, { text: "Sent Mail", icon: , onClick: () => console.log("Sent Mail clicked"), }, { text: "Drafts", icon: , onClick: () => console.log("Drafts clicked"), }, ]; const customRenderItem = (item: any, isOpen: boolean, handleClick: () => void) => (
{item.icon} {item.text} {item.children && }
); export const Default: Story = { args: { items: basicItems, }, render: (args) => ( ), }; export const NestedList: Story = { args: { items: nestedItems, }, render: (args) => ( ), }; export const CustomRender: Story = { args: { items: nestedItems, renderItem: customRenderItem, }, render: (args) => ( ), }; export const WithClickHandlers: Story = { args: { items: basicItems, }, render: (args) => ( ), }; export const NestedWithClickHandlers: Story = { args: { items: nestedItems, }, render: (args) => ( ), }; const avatarItems = [ { text: "John Doe", icon: , onClick: () => console.log("John Doe clicked"), }, { text: "Jane Smith", icon: , onClick: () => console.log("Jane Smith clicked"), }, { text: "Robert Brown", icon: , onClick: () => console.log("Robert Brown clicked"), }, ]; export const WithAvatars: Story = { args: { items: avatarItems, }, render: (args) => ( ), };