Skip to content

Commit 5ea3642

Browse files
committed
Feat: new component added - collapsible
1 parent fcc8b72 commit 5ea3642

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react';
2+
import {Meta} from '@storybook/react';
3+
import Collapsible from './Collapsible';
4+
import SandboxEditor from '~/components/tools/SandboxEditor/SandboxEditor';
5+
6+
const placeholderText= ['“One of the penalties for refusing to participate in politics is that you end up being governed by your inferiors.“ – Plato',
7+
'“The superior man understands what is right; the inferior man understands what will sell.” – Confucius',
8+
'“There are no secrets on the internet.” – Paul Babicki'];
9+
10+
11+
const meta: Meta<typeof Collapsible> = {
12+
component: Collapsible,
13+
title: 'UI/Data Display/Collapsible',
14+
};
15+
16+
export default meta;
17+
18+
export const Default = () => {
19+
return (<section>
20+
<SandboxEditor className=''>
21+
<Collapsible>
22+
<div className='grid gap-4 border-2 border-zinc-200 p-2'>
23+
{placeholderText.map((text) =>
24+
<p key={text}> {text} </p>,
25+
)}
26+
</div>
27+
</Collapsible>
28+
</SandboxEditor>
29+
</section>
30+
);
31+
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React, {PropsWithChildren, useState} from 'react';
2+
import Button from '../Button/Button';
3+
4+
export type CollapsibleProps = { open?: boolean } & PropsWithChildren;
5+
6+
const ExpandIcon = () => (
7+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="size-6">
8+
<path strokeLinecap="round" strokeLinejoin="round" d="M3.75 3.75v4.5m0-4.5h4.5m-4.5 0L9 9M3.75 20.25v-4.5m0 4.5h4.5m-4.5 0L9 15M20.25 3.75h-4.5m4.5 0v4.5m0-4.5L15 9m5.25 11.25h-4.5m4.5 0v-4.5m0 4.5L15 15" />
9+
</svg>
10+
);
11+
12+
const CollapseIcon = () => (
13+
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="size-6">
14+
<path strokeLinecap="round" strokeLinejoin="round" d="M9 9V4.5M9 9H4.5M9 9 3.75 3.75M9 15v4.5M9 15H4.5M9 15l-5.25 5.25M15 9h4.5M15 9V4.5M15 9l5.25-5.25M15 15h4.5M15 15v4.5m0-4.5 5.25 5.25" />
15+
</svg>
16+
);
17+
18+
const Collapsible = ({children, ...props}: CollapsibleProps) => {
19+
const [open, setOpen] = useState(props.open ?? true);
20+
21+
const toggleCollapse=() => setOpen((p) => !p);
22+
23+
return (
24+
<article>
25+
<Button onClick={toggleCollapse}>{open?<CollapseIcon/>:<ExpandIcon/>}</Button>
26+
27+
<div aria-hidden={!open} className={'relative flex-col flex overflow-hidden' + (!open && ' h-0')}>
28+
{children}
29+
</div>
30+
31+
</article>
32+
);
33+
};
34+
35+
export default Collapsible;

0 commit comments

Comments
 (0)