-
Notifications
You must be signed in to change notification settings - Fork 1
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-15 Menu, InfoPopover Component 추가 #83
Open
cause38
wants to merge
1
commit into
DESIGN-12
Choose a base branch
from
DESIGN-15
base: DESIGN-12
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,36 @@ | ||
import { Meta } from '@storybook/react'; | ||
|
||
import IconButton from '@/core/components/Button/IconButton'; | ||
import Icon from '@/core/components/Icon'; | ||
import Menu from '@/core/components/Menu'; | ||
|
||
const meta = { | ||
title: 'core/Menu', | ||
component: Menu, | ||
} satisfies Meta<typeof Menu>; | ||
|
||
export default meta; | ||
|
||
export const Default = () => { | ||
return ( | ||
<Menu | ||
trigger={ | ||
<IconButton | ||
colorTheme={'secondary'} | ||
icon={<Icon iconKey={'gear'} weight={'fill'} className={'text-lg'} />} | ||
size={'h-40'} | ||
/> | ||
} | ||
items={[ | ||
<Menu.Item key={'update'} content={'수정'} />, | ||
<Menu.Item | ||
key={'delete'} | ||
content={'삭제'} | ||
colorTheme={'error'} | ||
rightIcon={<Icon iconKey={'trash'} weight={'bold'} />} | ||
/>, | ||
]} | ||
popoverOptions={{ className: 'w-20' }} | ||
/> | ||
); | ||
}; |
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,60 @@ | ||
import { ComponentPropsWithoutRef, ElementType, MouseEvent } from 'react'; | ||
import clsx from 'clsx'; | ||
|
||
import { LIGHT_COLOR_THEME } from '@/constants/theme'; | ||
import { MENU_ITEM_THEME } from './constants'; | ||
import { BUTTON_GAP, GAP } from '@/core/components/Button/ButtonBase/constants'; | ||
import { MenuItemProps } from './types'; | ||
|
||
const MenuItem = <T extends ElementType = 'button'>({ | ||
element: Element, | ||
content, | ||
leftIcon, | ||
rightIcon, | ||
className, | ||
disabled, | ||
onClick, | ||
gap = GAP['GAP_6'], | ||
colorTheme = LIGHT_COLOR_THEME['SECONDARY'], | ||
...props | ||
}: MenuItemProps<T> & ComponentPropsWithoutRef<T>) => { | ||
const Component: ElementType = Element || 'button'; | ||
const defaultProps = | ||
Component === 'button' ? { disabled, type: 'button' } : {}; | ||
|
||
const handleClick = (e: MouseEvent<T>) => { | ||
e.preventDefault(); | ||
|
||
if (!disabled) { | ||
onClick?.(e); | ||
} | ||
}; | ||
|
||
return ( | ||
<li | ||
className={clsx( | ||
'text-body-02-medium', | ||
!disabled && 'rounded-md transition-all', | ||
MENU_ITEM_THEME[colorTheme], | ||
)} | ||
> | ||
<Component | ||
className={clsx( | ||
'flex w-full items-center p-2 text-start', | ||
disabled && 'cursor-not-allowed text-gray-04', | ||
(leftIcon || rightIcon) && gap && BUTTON_GAP[gap], | ||
className, | ||
)} | ||
onClick={handleClick} | ||
{...defaultProps} | ||
{...props} | ||
> | ||
{leftIcon && leftIcon} | ||
{content} | ||
{rightIcon && rightIcon} | ||
</Component> | ||
</li> | ||
); | ||
}; | ||
|
||
export default MenuItem; |
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,7 @@ | ||
import { LIGHT_COLOR_THEME } from '@/constants/theme'; | ||
import { MenuItemColorTheme } from '@/core/components/Menu/types'; | ||
|
||
export const MENU_ITEM_THEME: Record<MenuItemColorTheme, string> = { | ||
[LIGHT_COLOR_THEME['ERROR']]: 'text-rose-600 hover:bg-[#FFEDEF]', | ||
[LIGHT_COLOR_THEME['SECONDARY']]: 'hover:bg-gray-00 hover:text-primary-03', | ||
} as const; |
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,27 @@ | ||
import clsx from 'clsx'; | ||
|
||
import { MenuProps, MenuReturnType } from '@/core/components/Menu/types'; | ||
import Popover from '@/core/components/Popover/PopoverBase'; | ||
import MenuPopoverItem from '@/core/components/Menu/MenuItem'; | ||
|
||
const Menu = ({ items, popoverOptions = {}, ...props }: MenuProps) => { | ||
const { className, ...rest } = popoverOptions; | ||
|
||
return ( | ||
<Popover | ||
popover={<ul className={'flex-v-stack gap-y-1'}>{items}</ul>} | ||
popoverOptions={{ | ||
backgroundColor: 'white', | ||
hasShadow: true, | ||
className: clsx('p-1.5', className), | ||
...rest, | ||
}} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
export default Menu as unknown as MenuReturnType; | ||
|
||
Menu.displayName = 'Menu'; | ||
Menu.Item = MenuPopoverItem; |
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,31 @@ | ||
import { ElementType, ReactElement, ReactNode } from 'react'; | ||
|
||
import { ButtonProps } from '@/core/components/Button/Button/types'; | ||
import { LightColorThemeType } from '@/types'; | ||
import { PopoverProps } from '@/core/components/Popover/PopoverBase/types'; | ||
import MenuPopoverItem from '@/core/components/Menu/MenuItem'; | ||
|
||
export interface MenuProps extends Omit<PopoverProps, 'popover'> { | ||
items: ReactNode[]; | ||
} | ||
|
||
export type MenuItemColorTheme = Extract< | ||
LightColorThemeType, | ||
'error' | 'secondary' | ||
>; | ||
|
||
export interface MenuItemProps<T extends ElementType> | ||
extends Pick< | ||
ButtonProps, | ||
'content' | 'leftIcon' | 'rightIcon' | 'disabled' | 'gap' | ||
> { | ||
element?: T; | ||
colorTheme?: MenuItemColorTheme; | ||
} | ||
|
||
type Menu = (props: MenuProps) => ReactElement; | ||
|
||
export type MenuReturnType = Menu & { | ||
displayName: string; | ||
Item: typeof MenuPopoverItem; | ||
}; |
53 changes: 53 additions & 0 deletions
53
src/core/components/Popover/InfoPopover/InfoPopover.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,53 @@ | ||
import { Meta } from '@storybook/react'; | ||
|
||
import IconButton from '@/core/components/Button/IconButton'; | ||
import Icon from '@/core/components/Icon'; | ||
import InfoPopover from '@/core/components/Popover/InfoPopover/index'; | ||
|
||
const meta = { | ||
title: 'core/InfoPopover', | ||
component: InfoPopover, | ||
argTypes: { | ||
heading: { | ||
control: 'text', | ||
description: 'Information Popover Heading', | ||
}, | ||
items: { | ||
control: 'object', | ||
description: 'Information Popover Items', | ||
}, | ||
}, | ||
} satisfies Meta<typeof InfoPopover>; | ||
|
||
export default meta; | ||
|
||
export const Default = () => { | ||
const data = [ | ||
{ | ||
title: '제목1', | ||
description: '설명', | ||
}, | ||
{ | ||
title: '제목2', | ||
description: '설명', | ||
}, | ||
]; | ||
|
||
return ( | ||
<InfoPopover | ||
heading={'정보 설명'} | ||
trigger={ | ||
<IconButton | ||
colorTheme={'warning'} | ||
rounded={'rounded-full'} | ||
icon={ | ||
<Icon iconKey={'question'} weight={'bold'} className={'text-lg'} /> | ||
} | ||
size={'h-40'} | ||
/> | ||
} | ||
items={data} | ||
popoverOptions={{ className: 'w-32' }} | ||
/> | ||
); | ||
}; |
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,67 @@ | ||
import { InfoPopoverProps } from '@/core/components/Popover/InfoPopover/types'; | ||
import Typography from '@/core/components/Typography'; | ||
import Icon from '@/core/components/Icon'; | ||
import Popover from '@/core/components/Popover/PopoverBase'; | ||
|
||
const InfoPopover = ({ | ||
trigger, | ||
heading, | ||
items, | ||
popoverOptions = {}, | ||
...props | ||
}: InfoPopoverProps) => { | ||
const ITEMS = () => { | ||
return items.map(({ title, description }) => ( | ||
<li key={title + description}> | ||
<div className={'flex gap-x-1'}> | ||
<Typography | ||
theme={'body-02-bold'} | ||
color={'primary-03'} | ||
text={ | ||
<> | ||
<Icon | ||
iconKey={'circle'} | ||
weight={'fill'} | ||
className={'text-[6px]'} | ||
/> | ||
{title} | ||
</> | ||
} | ||
className={'flex gap-1'} | ||
/> | ||
</div> | ||
<Typography | ||
element={'p'} | ||
theme={'body-02-regular'} | ||
text={description} | ||
/> | ||
</li> | ||
)); | ||
}; | ||
|
||
return ( | ||
<Popover | ||
trigger={trigger} | ||
popover={ | ||
<> | ||
<Typography | ||
element={'strong'} | ||
theme={'body-02-bold'} | ||
color={'primary-06'} | ||
text={heading} | ||
className={'block border-b p-3'} | ||
/> | ||
<ul className={'flex-v-stack gap-y-4 p-3'}>{ITEMS()}</ul> | ||
</> | ||
} | ||
popoverOptions={{ | ||
backgroundColor: 'white', | ||
hasShadow: true, | ||
...popoverOptions, | ||
}} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
export default InfoPopover; |
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,6 @@ | ||
import { PopoverProps } from '@/core/components/Popover/PopoverBase/types'; | ||
|
||
export interface InfoPopoverProps extends Omit<PopoverProps, 'popover'> { | ||
heading: string; | ||
items: { title: string; description: string }[]; | ||
} |
2 changes: 1 addition & 1 deletion
2
...re/components/Popover/Popover.stories.tsx → ...s/Popover/PopoverBase/Popover.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
2 changes: 1 addition & 1 deletion
2
.../hooks/effects/useRootScrollLockEffect.ts → .../hooks/effects/useRootScrollLockEffect.ts
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
4 changes: 2 additions & 2 deletions
4
...effects/useUpdatePopoverPositionEffect.ts → ...effects/useUpdatePopoverPositionEffect.ts
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
4 changes: 2 additions & 2 deletions
4
...nents/Popover/hooks/usePopoverPosition.ts → ...r/PopoverBase/hooks/usePopoverPosition.ts
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
6 changes: 3 additions & 3 deletions
6
src/core/components/Popover/index.tsx → .../components/Popover/PopoverBase/index.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
2 changes: 1 addition & 1 deletion
2
...mponents/Popover/types/PopoverPosition.ts → ...over/PopoverBase/types/PopoverPosition.ts
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p3: 디렉터리 구조로 맞춰주는건 어떨까요?