mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-14 18:05:55 +08:00
[ui][collapsible] initial implementation
This commit is contained in:
46
apps/storybook/stories/collapsible.stories.tsx
Normal file
46
apps/storybook/stories/collapsible.stories.tsx
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import type { ComponentMeta } from '@storybook/react';
|
||||||
|
import { Collapsible } from '@tih/ui';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
argTypes: {
|
||||||
|
children: {
|
||||||
|
control: { type: 'text' },
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
control: { type: 'text' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
component: Collapsible,
|
||||||
|
title: 'Collapsible',
|
||||||
|
} as ComponentMeta<typeof Collapsible>;
|
||||||
|
|
||||||
|
export const Basic = {
|
||||||
|
args: {
|
||||||
|
children:
|
||||||
|
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
|
||||||
|
label: 'Reveal more content below',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export function AccordionLayout() {
|
||||||
|
return (
|
||||||
|
<div className="divide-y divide-slate-200">
|
||||||
|
<div className="py-2">
|
||||||
|
<Collapsible label="What is your name?">
|
||||||
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
|
||||||
|
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
|
||||||
|
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
|
||||||
|
aliquip ex ea commodo consequat.
|
||||||
|
</Collapsible>
|
||||||
|
</div>
|
||||||
|
<div className="py-2">
|
||||||
|
<Collapsible label="What is your age?">
|
||||||
|
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
|
||||||
|
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
|
||||||
|
proident, sunt in culpa qui officia deserunt mollit anim id est
|
||||||
|
laborum.
|
||||||
|
</Collapsible>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
32
packages/ui/src/Collapsible/Collapsible.tsx
Normal file
32
packages/ui/src/Collapsible/Collapsible.tsx
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import clsx from 'clsx';
|
||||||
|
import type { ReactNode } from 'react';
|
||||||
|
import { Disclosure } from '@headlessui/react';
|
||||||
|
import { ChevronDownIcon } from '@heroicons/react/20/solid';
|
||||||
|
|
||||||
|
type Props = Readonly<{
|
||||||
|
children: ReactNode;
|
||||||
|
label: string;
|
||||||
|
}>;
|
||||||
|
|
||||||
|
export default function Collapsible({ children, label }: Props) {
|
||||||
|
return (
|
||||||
|
<Disclosure>
|
||||||
|
{({ open }) => (
|
||||||
|
<>
|
||||||
|
<Disclosure.Button className="text-primary-900 hover:bg-primary-100 focus-visible:ring-primary-500 -mx-2.5 box-content flex w-full justify-between rounded-lg px-2.5 py-2 text-left text-sm font-medium focus:outline-none focus-visible:ring focus-visible:ring-opacity-75">
|
||||||
|
<ChevronDownIcon
|
||||||
|
className={clsx(
|
||||||
|
'text-primary-500 mr-1 -ml-1 h-5 w-5',
|
||||||
|
open && 'rotate-180 transform',
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<span className="flex-1">{label}</span>
|
||||||
|
</Disclosure.Button>
|
||||||
|
<Disclosure.Panel className="pt-1 pb-2 text-sm text-gray-500">
|
||||||
|
{children}
|
||||||
|
</Disclosure.Panel>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Disclosure>
|
||||||
|
);
|
||||||
|
}
|
@ -7,6 +7,9 @@ export { default as Badge } from './Badge/Badge';
|
|||||||
// Button
|
// Button
|
||||||
export * from './Button/Button';
|
export * from './Button/Button';
|
||||||
export { default as Button } from './Button/Button';
|
export { default as Button } from './Button/Button';
|
||||||
|
// Collapsible
|
||||||
|
export * from './Collapsible/Collapsible';
|
||||||
|
export { default as Collapsible } from './Collapsible/Collapsible';
|
||||||
// Dialog
|
// Dialog
|
||||||
export * from './Dialog/Dialog';
|
export * from './Dialog/Dialog';
|
||||||
export { default as Dialog } from './Dialog/Dialog';
|
export { default as Dialog } from './Dialog/Dialog';
|
||||||
|
Reference in New Issue
Block a user