Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a5bddd9
commit e6cfacb
Showing
5 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react' | ||
import { Story, Meta } from '@storybook/react' | ||
|
||
import Drawer, { DrawerProps } from '.' | ||
|
||
export default { | ||
title: 'Layout/Drawer', | ||
component: Drawer, | ||
} as Meta | ||
|
||
export const Default: Story<DrawerProps> = (args) => { | ||
const drawerContent = ( | ||
<div className="flex flex-col items-center justify-center align-middle drawer-content"> | ||
<h1>Some drawer content! 🍉 (Not required)</h1> | ||
</div> | ||
) | ||
|
||
return ( | ||
<> | ||
<div className="flex flex-col items-center justify-center p-2"> | ||
<label htmlFor="sidebar-id"> | ||
👀 Open/Close drawer by alternating the Storybook controls below 👇 | ||
</label> | ||
</div> | ||
|
||
<Drawer | ||
{...args} | ||
id="sidebar-id" | ||
className="h-screen w-full bg-base-100 rounded border" | ||
drawerContent={drawerContent} | ||
> | ||
<ul className="menu p-4 overflow-y-auto w-80 bg-base-200"> | ||
<li> | ||
<a>Sidebar Item 1</a> | ||
</li> | ||
<li> | ||
<a>Sidebar Item 2</a> | ||
</li> | ||
</ul> | ||
</Drawer> | ||
</> | ||
) | ||
} | ||
|
||
Default.args = { | ||
open: true, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React, { ReactNode } from 'react' | ||
import clsx from 'clsx' | ||
|
||
import { IComponentBaseProps } from '../types' | ||
|
||
export type DrawerProps = | ||
& React.HTMLAttributes<HTMLDivElement> | ||
& IComponentBaseProps | ||
& { | ||
id: string | ||
drawerContent?: ReactNode | ||
open?: boolean | ||
} | ||
|
||
const Drawer = ({ | ||
className, | ||
id, | ||
open = false, | ||
drawerContent, | ||
...props | ||
}: DrawerProps) => ( | ||
<div className={clsx('drawer', className)} {...props}> | ||
<input | ||
readOnly | ||
id={id} | ||
type="checkbox" | ||
checked={open} | ||
className="drawer-toggle" | ||
/> | ||
|
||
{drawerContent ? ( | ||
<div className="drawer-content">{drawerContent}</div> | ||
) : null} | ||
|
||
<div className="drawer-side"> | ||
<label htmlFor={id} className="drawer-overlay"></label> | ||
{props.children} | ||
</div> | ||
</div> | ||
) | ||
|
||
export default Drawer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Drawer, { DrawerProps as TDrawerProps } from './Drawer' | ||
export type DrawerProps = TDrawerProps | ||
export default Drawer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters