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

[Refactor/BAR-233] Dropdown 컴포넌트 수정 #58

Merged
merged 13 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .storybook/preview-body.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<div id="modal-root" />
<div id="toast-root" />
<div id="tooltip-root" />
<div id="dropdown-root" />
7 changes: 4 additions & 3 deletions src/assets/icons/profileDialog.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions src/assets/icons/profileHeader.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 10 additions & 17 deletions src/components/Card/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import {
createContext,
type PropsWithChildren,
useContext,
useState,
} from 'react';
import { createContext, type PropsWithChildren, useContext } from 'react';
import clsx from 'clsx';

import useDisclosure from '@hooks/useDisclosure';

import * as styles from './style.css';

interface CardProps {
Expand Down Expand Up @@ -34,22 +31,18 @@ const CardRoot = ({
className,
color = 'white',
}: PropsWithChildren<CardProps>) => {
const [isVisible, setIsVisible] = useState(false);

const handleMenuShow = () => {
setIsVisible(true);
};

const handleMenuHide = () => {
setIsVisible(false);
};
const {
isOpen: isVisible,
onOpen: onShow,
onClose: onHide,
} = useDisclosure();

return (
<CardContext.Provider value={{ isVisibleMenu: isVisible }}>
<li
className={clsx(styles.wrapper({ color }), className)}
onMouseEnter={handleMenuShow}
onMouseLeave={handleMenuHide}
onMouseEnter={onShow}
onMouseLeave={onHide}
>
{children}
</li>
Expand Down
69 changes: 0 additions & 69 deletions src/components/Dialog/Dialog.stories.tsx

This file was deleted.

24 changes: 0 additions & 24 deletions src/components/Dialog/components/DialogButton.tsx

This file was deleted.

14 changes: 0 additions & 14 deletions src/components/Dialog/components/DialogTitle.tsx

This file was deleted.

63 changes: 0 additions & 63 deletions src/components/Dialog/index.tsx

This file was deleted.

116 changes: 116 additions & 0 deletions src/components/Dropdown/Dropdown.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import Icon from '@components/Icon';
import { action } from '@storybook/addon-actions';
import type { Meta, StoryObj } from '@storybook/react';

import Dropdown from '.';
import * as styles from './style.css';

const meta: Meta<typeof Dropdown> = {
title: 'Components/Dropdown',
component: Dropdown,
parameters: {
componentSubtitle: '다양한 액션을 제공하는 컴포넌트',
},
decorators: [
(Story) => (
<div style={{ display: 'flex', justifyContent: 'center' }}>
<Story />
</div>
),
],
};

export default meta;

type Story = StoryObj<typeof Dropdown>;

export const Small: Story = {
args: {
size: 'small',
placement: 'bottom-left',
},
render: (args) => (
<Dropdown {...args}>
<Dropdown.Trigger>버튼</Dropdown.Trigger>
<Dropdown.List>
<Dropdown.Item onClick={action('수정하기 클릭')}>
수정하기
</Dropdown.Item>
<Dropdown.Item onClick={action('삭제하기 클릭')}>
삭제하기
</Dropdown.Item>
</Dropdown.List>
</Dropdown>
),
};

export const Medium: Story = {
args: {
size: 'medium',
placement: 'bottom-left',
},
render: (args) => (
<Dropdown {...args}>
<Dropdown.Trigger>버튼</Dropdown.Trigger>
<Dropdown.List>
<Dropdown.Item onClick={action('수정하기 클릭')}>
수정하기
</Dropdown.Item>
<Dropdown.Item onClick={action('삭제하기 클릭')}>
삭제하기
</Dropdown.Item>
</Dropdown.List>
</Dropdown>
),
};

export const FolderDropdown: Story = {
render: () => (
<Dropdown size="medium" placement="bottom-center">
<Dropdown.Trigger>버튼</Dropdown.Trigger>
<Dropdown.List>
<Dropdown.Item onClick={action('기본 폴더 클릭')}>
바로님의 폴더<span className={styles.badge}>기본</span>
</Dropdown.Item>
<Dropdown.Item onClick={action('폴더 이름1 클릭')}>
폴더 이름1
</Dropdown.Item>
<Dropdown.Item onClick={action('폴더 이름2 클릭')}>
폴더 이름2
</Dropdown.Item>
<Dropdown.Item onClick={action('새 폴더 만들기 클릭')}>
<Icon icon="add" width={20} height={20} />
<span className={styles.newFolderText}>새 폴더 만들기</span>
</Dropdown.Item>
</Dropdown.List>
</Dropdown>
),
};

export const UserProfileDropdown: Story = {
render: () => (
<Dropdown
className={styles.dialogWrapper}
size="medium"
placement="bottom-right"
>
<Dropdown.Trigger className={styles.profile}>
<Icon icon="profileHeader" width={28} height={28} />
</Dropdown.Trigger>
<Dropdown.List>
<Dropdown.Title>
<Icon icon="profileDialog" width={40} height={40} />
<span className={styles.profileName}>바로님</span>
</Dropdown.Title>
<Dropdown.Item onClick={action('계정 설정 클릭')}>
<Icon icon="setting" width={20} height={20} />
<span className={styles.buttonText}>계정 설정</span>
</Dropdown.Item>
<Dropdown.Item onClick={action('로그아웃 클릭')}>
<Icon icon="logout" width={20} height={20} />
<span className={styles.buttonText}>로그아웃</span>
</Dropdown.Item>
</Dropdown.List>
</Dropdown>
),
};
28 changes: 28 additions & 0 deletions src/components/Dropdown/components/DropdownMenuItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { type ButtonHTMLAttributes, type PropsWithChildren } from 'react';
import clsx from 'clsx';

import Button from '@components/Button';
import * as styles from '@components/Dropdown/style.css';

import { useDropdownContext } from '..';

interface DropdownMenuItemProps
extends ButtonHTMLAttributes<HTMLButtonElement> {}

const DropdownMenuItem = ({
children,
className,
...props
}: PropsWithChildren<DropdownMenuItemProps>) => {
const { size } = useDropdownContext();

return (
<li>
<Button {...props} className={clsx(styles.menuItem({ size }), className)}>
{children}
</Button>
</li>
);
};

export default DropdownMenuItem;
Loading
Loading