// Copyright 2024, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import { Meta, StoryObj } from "@storybook/react"; import { Avatar } from "./avatar"; import { CollapsibleMenu } from "./collapsiblemenu"; const meta: Meta = { title: "Elements/CollapsibleMenu", component: CollapsibleMenu, 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 = [ { label: "Inbox", icon: , onClick: () => console.log("Inbox clicked"), }, { label: "Sent Mail", icon: , onClick: () => console.log("Sent Mail clicked"), }, { label: "Drafts", icon: , onClick: () => console.log("Drafts clicked"), }, ]; const nestedItems = [ { label: "Inbox", icon: , onClick: () => console.log("Inbox clicked"), subItems: [ { label: "Starred", icon: , onClick: () => console.log("Starred clicked"), }, { label: "Important", icon: , onClick: () => console.log("Important clicked"), }, ], }, { label: "Sent Mail", icon: , onClick: () => console.log("Sent Mail clicked"), }, { label: "Drafts", icon: , onClick: () => console.log("Drafts clicked"), }, ]; const customRenderItem = ( item: MenuItem, isOpen: boolean, handleClick: (e: React.MouseEvent, item: MenuItem, itemKey: string) => void ) => (
handleClick(e, item, `${item.label}`)}> {item.icon} handleClick(e, item, `${item.label}`)}> {item.label} {item.subItems && }
); 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 = [ { label: "John Doe", icon: , onClick: () => console.log("John Doe clicked"), }, { label: "Jane Smith", icon: , onClick: () => console.log("Jane Smith clicked"), }, { label: "Robert Brown", icon: , onClick: () => console.log("Robert Brown clicked"), }, { label: "Alice Lambert", icon: , onClick: () => console.log("Alice Lambert clicked"), }, ];