Skip to content

Commit 29dc16e

Browse files
author
nicosammito
committed
feat: add SidebarComponent with resizable panel functionality
1 parent fe43ad1 commit 29dc16e

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React from "react";
2+
import {Button, Code0ComponentProps, Color, Flex, Text} from "@code0-tech/pictor";
3+
import {PanelProps, usePanelRef} from "react-resizable-panels";
4+
import {ResizablePanel} from "@code0-tech/pictor/dist/components/resizable/Resizable";
5+
import {IconLayoutSidebar} from "@tabler/icons-react";
6+
7+
8+
type ResizablePanelProps = Code0ComponentProps & PanelProps & { color?: Color }
9+
10+
export interface SidebarComponentProps extends ResizablePanelProps {
11+
title?: string
12+
description?: string
13+
}
14+
15+
export const SidebarComponent: React.FC<SidebarComponentProps> = (props) => {
16+
17+
const {children, title, description, ...rest} = props
18+
const panelRef = usePanelRef()
19+
20+
return <ResizablePanel defaultSize={"20%"}
21+
collapsedSize={"0%"}
22+
collapsible
23+
minSize={"10%"}
24+
style={{textWrap: "nowrap"}}
25+
panelRef={panelRef}
26+
{...rest}
27+
>
28+
<Flex style={{flexDirection: "column", gap: "0.7rem"}}>
29+
<Flex style={{gap: "0.7rem"}} align={"center"} justify={"space-between"}>
30+
{title && <Text size={"md"} hierarchy={"secondary"}>{title}</Text>}
31+
32+
<Button variant={"none"} paddingSize={"xxs"} onClick={() => panelRef.current?.collapse()}>
33+
<IconLayoutSidebar size={16}/>
34+
</Button>
35+
</Flex>
36+
{description && <Text size={"sm"} hierarchy={"tertiary"} style={{textWrap: "wrap"}}>
37+
{description}
38+
</Text>}
39+
{children}
40+
</Flex>
41+
</ResizablePanel>
42+
43+
}

0 commit comments

Comments
 (0)