import React from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { Button } from '../Button/Button';
import { IconButton } from '../IconButton/IconButton';
import { ReorderableListing } from './ReorderableListing';
import type { ReorderableListingItemData, ReorderableListingKey } from './ReorderableListing';
import { ReorderableListingItem } from './ReorderableListingItem';
const ChangeCategoriesButton = (
);
const Thumbnail = () => (
);
const meta: Meta = {
title: 'UI kit/ReorderableListing',
component: ReorderableListing,
tags: ['autodocs'],
args: {
'aria-label': 'Reorderable list',
},
decorators: [
Story => (
),
],
};
export default meta;
type Story = StoryObj;
const defaultItems: ReorderableListingItemData[] = [
{ id: 'a', label: 'Label A' },
{ id: 'b', label: 'Label B' },
];
const exampleItems: ReorderableListingItemData[] = [
{ id: 'chairs', label: 'Chairs' },
{
id: 'tables',
label: 'Tables',
children: [
{ id: 'dining', label: 'Dining' },
{ id: 'coffee', label: 'Coffee' },
],
},
{ id: 'armchairs', label: 'Armchairs', disabled: true },
{ id: 'stools', label: 'Stools', draggable: false },
{ id: 'sofas', label: 'Sofas', hidden: true },
{ id: 'dressers', label: 'Dressers' },
];
export const Default: Story = {
args: {
defaultItems,
footer: ChangeCategoriesButton,
},
};
export const Example: Story = {
args: {
defaultItems: exampleItems,
footer: ChangeCategoriesButton,
},
};
export const WithoutFooter: Story = {
args: {
defaultItems: exampleItems,
},
};
export const Controlled: Story = {
render: function Controlled() {
const [items, setItems] = React.useState(exampleItems);
const onHiddenChange = (id: ReorderableListingKey, hidden: boolean, parentId?: ReorderableListingKey) => {
setItems(prev =>
prev.map(item => {
if (parentId !== undefined && item.id === parentId) {
return { ...item, children: item.children?.map(c => (c.id === id ? { ...c, hidden } : c)) };
}
return item.id === id ? { ...item, hidden } : item;
})
);
};
return (
setItems(next)}
onHiddenChange={onHiddenChange}
footer={ChangeCategoriesButton}
/>
);
},
};
export const InUse: Story = {
render: function InUse() {
const blocks: ReorderableListingItemData[] = [
{ id: 'main-banner', label: 'Main banner' },
{ id: 'categories', label: 'Categories' },
{ id: 'product-banner', label: 'Product banner' },
];
return (
Add block
}
renderMedia={() => }
renderActions={item => (
<>
>
)}
/>
);
},
};
/** All states and modes of the presentational row. */
export const ItemStates: StoryObj = {
render: () => (
),
};