2025-02-26 08:15:58 +08:00
|
|
|
import type { Meta, StoryObj } from '@storybook/react';
|
2025-02-26 13:16:50 +08:00
|
|
|
import { Select } from './Select';
|
|
|
|
import { User, MapSettings, Mailbox } from '../icons';
|
2025-03-04 06:42:29 +08:00
|
|
|
import { fn } from '@storybook/test';
|
2025-02-26 08:15:58 +08:00
|
|
|
|
|
|
|
const meta: Meta<typeof Select> = {
|
2025-02-27 23:40:07 +08:00
|
|
|
title: 'UI/Select/Select',
|
2025-02-26 08:15:58 +08:00
|
|
|
component: Select,
|
2025-02-26 13:16:50 +08:00
|
|
|
parameters: {
|
|
|
|
layout: 'centered'
|
|
|
|
},
|
2025-03-04 06:42:29 +08:00
|
|
|
args: {
|
|
|
|
onChange: fn()
|
|
|
|
},
|
2025-02-26 13:16:50 +08:00
|
|
|
tags: ['autodocs']
|
2025-02-26 08:15:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default meta;
|
|
|
|
type Story = StoryObj<typeof Select>;
|
|
|
|
|
2025-02-26 13:16:50 +08:00
|
|
|
const basicItems = [
|
2025-04-12 04:25:27 +08:00
|
|
|
{ value: 'apples', label: 'Apples' },
|
|
|
|
{ value: 'bananas', label: 'Bananas' },
|
|
|
|
{ value: 'cherries', label: 'Cherries' }
|
2025-02-26 13:16:50 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
const itemsWithIcons = [
|
|
|
|
{ value: 'profile', label: 'Profile', icon: <User /> },
|
|
|
|
{ value: 'settings', label: 'Settings', icon: <MapSettings /> },
|
|
|
|
{ value: 'messages', label: 'Messages', icon: <Mailbox /> }
|
|
|
|
];
|
|
|
|
|
|
|
|
const groupedItems = [
|
|
|
|
{
|
|
|
|
label: 'Fruits',
|
|
|
|
items: [
|
|
|
|
{ value: 'apple', label: 'Apple' },
|
|
|
|
{ value: 'banana', label: 'Banana' },
|
|
|
|
{ value: 'orange', label: 'Orange' }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'Vegetables',
|
|
|
|
items: [
|
|
|
|
{ value: 'carrot', label: 'Carrot' },
|
|
|
|
{ value: 'broccoli', label: 'Broccoli' },
|
|
|
|
{ value: 'spinach', label: 'Spinach' }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
const itemsWithSecondaryLabel = [
|
|
|
|
{ value: 'user1', label: 'John Doe', secondaryLabel: 'Admin' },
|
|
|
|
{ value: 'user2', label: 'Jane Smith', secondaryLabel: 'Editor' },
|
|
|
|
{ value: 'user3', label: 'Bob Johnson', secondaryLabel: 'Viewer', disabled: true }
|
|
|
|
];
|
|
|
|
|
|
|
|
const itemsWithSomeDisabled = [
|
|
|
|
{ value: 'active1', label: 'Available Option 1' },
|
|
|
|
{ value: 'disabled1', label: 'Unavailable Option 1', disabled: true },
|
|
|
|
{ value: 'active2', label: 'Available Option 2' },
|
|
|
|
{ value: 'disabled2', label: 'Unavailable Option 2', disabled: true },
|
|
|
|
{ value: 'active3', label: 'Available Option 3' }
|
|
|
|
];
|
|
|
|
|
|
|
|
export const Basic: Story = {
|
|
|
|
args: {
|
|
|
|
items: basicItems,
|
|
|
|
placeholder: 'Select an option'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const WithIcons: Story = {
|
|
|
|
args: {
|
|
|
|
items: itemsWithIcons,
|
|
|
|
placeholder: 'Select an option'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Grouped: Story = {
|
|
|
|
args: {
|
|
|
|
items: groupedItems,
|
|
|
|
placeholder: 'Select an option'
|
|
|
|
}
|
2025-02-26 08:15:58 +08:00
|
|
|
};
|
|
|
|
|
2025-02-26 13:16:50 +08:00
|
|
|
export const WithSecondaryLabels: Story = {
|
|
|
|
args: {
|
|
|
|
items: itemsWithSecondaryLabel,
|
|
|
|
placeholder: 'Select a user'
|
|
|
|
}
|
2025-02-26 08:15:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export const Disabled: Story = {
|
2025-02-26 13:16:50 +08:00
|
|
|
args: {
|
|
|
|
items: basicItems,
|
|
|
|
placeholder: 'Select an option',
|
|
|
|
disabled: true
|
|
|
|
}
|
2025-02-26 08:15:58 +08:00
|
|
|
};
|
|
|
|
|
2025-02-26 13:16:50 +08:00
|
|
|
export const WithShowIndex: Story = {
|
|
|
|
args: {
|
|
|
|
items: basicItems,
|
|
|
|
placeholder: 'Select an option',
|
|
|
|
showIndex: true
|
|
|
|
}
|
2025-02-26 08:15:58 +08:00
|
|
|
};
|
|
|
|
|
2025-02-26 13:16:50 +08:00
|
|
|
export const PartiallyDisabled: Story = {
|
|
|
|
args: {
|
|
|
|
items: itemsWithSomeDisabled,
|
|
|
|
placeholder: 'Select an available option'
|
|
|
|
}
|
2025-02-26 08:15:58 +08:00
|
|
|
};
|
2025-03-25 04:44:31 +08:00
|
|
|
|
|
|
|
export const WithLowCharacters: Story = {
|
|
|
|
args: {
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
value: 'gyj',
|
|
|
|
label: 'gyj - GYJ'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
placeholder: 'Select an option'
|
|
|
|
}
|
|
|
|
};
|