-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from f-lab-edu/51-design-system-component-drawer
[๐ design system] ๏ฟฝdrawer ์ปดํฌ๋ํธ ์์ฑ
- Loading branch information
Showing
10 changed files
with
187 additions
and
5 deletions.
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
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
32 changes: 32 additions & 0 deletions
32
packages/design-system/src/components/drawer/_drawer.module.scss
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,32 @@ | ||
@use "../../functions/" as *; | ||
@use "../../mixins/" as *; | ||
@use "sass:map"; | ||
|
||
.drawer-menu { | ||
position: fixed; | ||
z-index: z-index("modal"); | ||
width: min(100%, 32rem); | ||
height: 100vh; | ||
top: 0; | ||
bottom: 0; | ||
left: 0; | ||
transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1); | ||
background-color: color(default, 50); | ||
display: grid; | ||
} | ||
|
||
.drawer-menu.is-closed { | ||
transform: translateX(-100%); | ||
} | ||
|
||
.is-open { | ||
top: 0; | ||
left: 0; | ||
position: fixed; | ||
background-color: color(default, 800); | ||
width: 100vw; | ||
height: 100vh; | ||
z-index: z-index("overlay"); | ||
bottom: 0; | ||
opacity: 0.85; | ||
} |
55 changes: 55 additions & 0 deletions
55
packages/design-system/src/components/drawer/_drawer.stories.tsx
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,55 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { useEffect } from "react"; | ||
import { useAppTheme } from "../../hooks"; | ||
import Drawer from "./_drawer"; | ||
|
||
const meta: Meta<typeof Drawer> = { | ||
title: "tripie-ui/Drawer", | ||
component: Drawer, | ||
tags: ["autodocs"], | ||
decorators: [ | ||
(story, context) => { | ||
const { mode, setMode } = useAppTheme(); | ||
const selectedTheme = context.globals.theme || mode; | ||
|
||
useEffect(() => { | ||
setMode(selectedTheme); | ||
}, [selectedTheme]); | ||
|
||
return ( | ||
<div | ||
className={`${context.globals.theme}`} | ||
style={{ height: "100vh", overflow: "hidden" }} | ||
> | ||
{story()} | ||
</div> | ||
); | ||
}, | ||
], | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
name: "Default", | ||
args: { | ||
children: "default Drawer", | ||
}, | ||
}; | ||
|
||
export const NoOverLayDrawer: Story = { | ||
name: "No OverLay", | ||
args: { | ||
children: "Drawer No OverLay", | ||
overlay: false, | ||
}, | ||
}; | ||
|
||
export const NoCloseButtonDrawer: Story = { | ||
name: "No Close Button", | ||
args: { | ||
children: "Drawer No Close Button", | ||
withCloseButton: false, | ||
}, | ||
}; |
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,49 @@ | ||
import classNames from "classnames/bind"; | ||
import { ReactNode } from "react"; | ||
import { useDrawerOutput } from "../../hooks"; | ||
import Container from "../container"; | ||
import MyButton from "../myButton"; | ||
import Style from "./_drawer.module.scss"; | ||
|
||
export type DrawerProps = { | ||
children?: ReactNode; | ||
overlay?: boolean; | ||
|
||
withCloseButton?: boolean; | ||
} & Omit<React.ComponentProps<"div">, "children"> & | ||
Partial<useDrawerOutput>; | ||
|
||
const style = classNames.bind(Style); | ||
|
||
const Drawer = ({ | ||
children, | ||
overlay = true, | ||
withCloseButton = true, | ||
isOpen, | ||
|
||
close, | ||
}: DrawerProps) => { | ||
return ( | ||
<> | ||
{overlay ? ( | ||
<div className={style(isOpen ? "is-open" : null)} onClick={close} /> | ||
) : null} | ||
|
||
<aside className={style("drawer-menu", !isOpen && "is-closed")}> | ||
<nav className={style("menu")}> | ||
<Container className={style("menu-item")}> | ||
{withCloseButton && close != null ? ( | ||
<Container align="right" margin="none"> | ||
<MyButton onClick={() => close()}>Close</MyButton> | ||
{/* !! ์์ด์ฝ์ผ๋ก ๋ณ๊ฒฝํ๊ธฐ */} | ||
</Container> | ||
) : null} | ||
{children} | ||
</Container> | ||
</nav> | ||
</aside> | ||
</> | ||
); | ||
}; | ||
|
||
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,2 @@ | ||
export * from "./_drawer"; | ||
export { default } from "./_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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { default as Body } from "./body"; | ||
export { default as Drawer } from "./drawer"; | ||
export { default as MyButton } from "./myButton"; | ||
export { default as Headers } from "./typography"; | ||
export { default as Text } from "./typography/text"; |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./useAppTheme"; | ||
export * from "./useDrawer"; |
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,28 @@ | ||
import { useState } from "react"; | ||
|
||
const DRAWER_MODE = { | ||
OPEN: true, | ||
CLOSE: false, | ||
} as const; | ||
|
||
type DrawerMode = (typeof DRAWER_MODE)[keyof typeof DRAWER_MODE]; | ||
|
||
export type useDrawerOutput = { | ||
isOpen: DrawerMode; | ||
toggle: () => void; | ||
close: () => void; | ||
open: () => void; | ||
}; | ||
|
||
export const useDrawer = (): useDrawerOutput => { | ||
const [isOpen, setIsOpen] = useState<DrawerMode>(DRAWER_MODE.CLOSE); | ||
|
||
return { | ||
isOpen, | ||
toggle: () => { | ||
setIsOpen((previous) => !previous); | ||
}, | ||
open: () => setIsOpen(DRAWER_MODE.OPEN), | ||
close: () => setIsOpen(DRAWER_MODE.CLOSE), | ||
}; | ||
}; |