2024-08-20 13:57:58 +00:00
|
|
|
import type { Meta, StoryObj } from "@storybook/react";
|
2024-08-21 15:14:40 +00:00
|
|
|
import { Dropdown, DropdownOption } from "../src/components/Dropdown/Dropdown";
|
|
|
|
import { ChangeEvent, useState } from "react";
|
2024-08-22 18:04:24 +00:00
|
|
|
import { fn } from "@storybook/test";
|
2024-11-06 18:56:37 +00:00
|
|
|
import { WebFileIcon } from "../src/components/WebFileIcon/WebFileIcon";
|
2024-08-20 13:57:58 +00:00
|
|
|
|
|
|
|
const meta = {
|
|
|
|
title: "Forms/Dropdown",
|
|
|
|
component: Dropdown,
|
|
|
|
parameters: {
|
|
|
|
layout: "centered",
|
|
|
|
},
|
|
|
|
tags: ["autodocs"],
|
|
|
|
argTypes: {},
|
2024-08-22 18:04:24 +00:00
|
|
|
args: {
|
|
|
|
onChange: fn(),
|
|
|
|
onSelected: fn(),
|
|
|
|
onFocus: fn(),
|
|
|
|
onBlur: fn(),
|
|
|
|
onMouseEnter: fn(),
|
|
|
|
onMouseLeave: fn(),
|
|
|
|
},
|
2024-08-20 13:57:58 +00:00
|
|
|
} satisfies Meta<typeof Dropdown>;
|
|
|
|
|
|
|
|
export default meta;
|
|
|
|
type Story = StoryObj<typeof meta>;
|
|
|
|
|
2024-08-22 18:04:24 +00:00
|
|
|
type Props = {
|
|
|
|
onChange: (e: ChangeEvent<HTMLInputElement>) => void;
|
|
|
|
|
|
|
|
onSelected?: (o: DropdownOption) => void;
|
|
|
|
|
|
|
|
onClick?: () => void;
|
|
|
|
|
|
|
|
onMouseEnter?: () => void;
|
|
|
|
|
|
|
|
onBlur?: () => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
const Template = (p: Props) => {
|
2024-08-20 13:57:58 +00:00
|
|
|
const [value, setValue] = useState<string>("");
|
2024-08-28 08:03:26 +00:00
|
|
|
|
2024-08-22 18:04:24 +00:00
|
|
|
const onChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
|
|
p.onChange(e);
|
2024-08-20 13:57:58 +00:00
|
|
|
setValue(e.currentTarget.value);
|
2024-08-22 18:04:24 +00:00
|
|
|
};
|
2024-08-20 13:57:58 +00:00
|
|
|
|
2024-08-22 18:04:24 +00:00
|
|
|
const onSelected = (o: DropdownOption) => {
|
|
|
|
setValue(o.title);
|
|
|
|
p.onSelected?.(o);
|
|
|
|
};
|
2024-08-20 13:57:58 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Dropdown
|
2024-08-22 18:04:24 +00:00
|
|
|
{...p}
|
2024-08-20 13:57:58 +00:00
|
|
|
placeholder="Select your file"
|
|
|
|
onChange={onChange}
|
|
|
|
onSelected={onSelected}
|
|
|
|
value={value}
|
2024-08-28 08:03:26 +00:00
|
|
|
id={"dropdown"}
|
|
|
|
label={"Dropdown"}
|
2024-08-20 13:57:58 +00:00
|
|
|
options={[
|
|
|
|
{
|
|
|
|
title: "File1.pdf",
|
2024-11-06 18:56:37 +00:00
|
|
|
Icon: () => <WebFileIcon type="application/pdf"></WebFileIcon>,
|
2024-08-20 13:57:58 +00:00
|
|
|
subtitle: "cid1",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "File2.jpg",
|
2024-11-06 18:56:37 +00:00
|
|
|
Icon: () => <WebFileIcon type="image/png"></WebFileIcon>,
|
2024-08-20 13:57:58 +00:00
|
|
|
subtitle: "cid2",
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-08-22 18:04:24 +00:00
|
|
|
export const Default = Template;
|
2024-08-20 13:57:58 +00:00
|
|
|
|
|
|
|
export const CustomStyle: Story = {
|
|
|
|
args: {
|
|
|
|
placeholder: "Select your file",
|
|
|
|
options: [],
|
|
|
|
value: "",
|
2024-08-28 08:03:26 +00:00
|
|
|
id: "dropdown",
|
|
|
|
label: "Dropdown",
|
2024-08-20 13:57:58 +00:00
|
|
|
},
|
|
|
|
};
|