Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[๐Ÿ’… design system] drawer ์ปดํฌ๋„ŒํŠธ ์ƒ์„ฑ #52

Merged
merged 11 commits into from
Aug 10, 2024
18 changes: 15 additions & 3 deletions apps/web/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
"use client";
import { Headers, Text } from "@tripie/design-system";
import {
Drawer,
Headers,
MyButton,
Text,
useDrawer,
} from "@tripie/design-system";
import Container from "@tripie/design-system/components/container/_container";
import UnstyledLink from "@tripie/design-system/components/typography/link/_link";
import Paragraph from "@tripie/design-system/components/typography/paragraph/_paragraph";
Expand All @@ -8,8 +14,9 @@ import ThemeButton from "../components/ThemeButton";
export default function Home() {
const text =
"Lorem, ipsum dolor sit amet consectetur adipisicing elit. Omnis\npariatur, ab voluptates saepe eum at excepturi, eaque accusamus labore\ntemporibus ex nostrum in hic iure porro quod doloribus deleniti! Qui.\ntemporibus ex nostrum in hic iure porro quod doloribus deleniti!";
const { isOpen, toggle, close, open } = useDrawer();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์™ธ๋ถ€ ์‚ฌ์šฉ์ฒ˜์—์„œ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•˜๋„๋ก ๋บด์คฌ์Šต๋‹ˆ๋‹ค

return (
<Container margin="sm">
<>
<ThemeButton />
<ThemeButton.Toggle />

Expand All @@ -33,6 +40,11 @@ export default function Home() {
</Container>
</Container>
<UnstyledLink href="/">๋–ก๋ณถ์ด</UnstyledLink>
</Container>
<Drawer isOpen={isOpen} toggle={toggle} close={close} overlay={false}>
<div>show contents</div>
<div>:)</div>
</Drawer>
<MyButton onClick={open}>ํ† ๊ธ€</MyButton>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ $space-map: (
m: space(1rem),
sm: space(0.6rem),
xsm: space(0.2rem),
none: space(0),
);

@mixin margins($direction, $size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ReactNode } from "react";
import Style from "./_container.module.scss";

export type ContainerProps = {
margin?: "xl" | "l" | "m" | "sm" | "xsm";
margin?: "xl" | "l" | "m" | "sm" | "xsm" | "none";
align?: "left" | "center" | "right";
children?: ReactNode;
applyMargin?:
Expand Down Expand Up @@ -38,7 +38,8 @@ const Container = ({
)}
{...props}
>
<div>{children}</div>
{children}
{/* <div>{children}</div> */}
</div>
);
};
Expand Down
32 changes: 32 additions & 0 deletions packages/design-system/src/components/drawer/_drawer.module.scss
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 packages/design-system/src/components/drawer/_drawer.stories.tsx
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,
},
};
49 changes: 49 additions & 0 deletions packages/design-system/src/components/drawer/_drawer.tsx
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;
2 changes: 2 additions & 0 deletions packages/design-system/src/components/drawer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./_drawer";
export { default } from "./_drawer";
1 change: 1 addition & 0 deletions packages/design-system/src/components/index.ts
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";
1 change: 1 addition & 0 deletions packages/design-system/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./useAppTheme";
export * from "./useDrawer";
28 changes: 28 additions & 0 deletions packages/design-system/src/hooks/useDrawer.ts
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),
};
};
Loading