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

feat: set tooltip component #35

Merged
merged 13 commits into from
Jun 29, 2024
120 changes: 120 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/components/common/icons/RoundedTriangle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions src/components/common/icons/ToastPopup.svg

This file was deleted.

4 changes: 2 additions & 2 deletions src/components/common/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import HeartStraightOutlined from './HeartStraightOutlined.svg'
import Info from './Info.svg'
import InfoCircle from './InfoCircle.svg'
import Plus from './Plus.svg'
import RoundedTriangle from './RoundedTriangle.svg'
import Search from './Search.svg'
import ShareNetwork from './ShareNetwork.svg'
import SignOut from './SignOut.svg'
import ToastPopup from './ToastPopup.svg'
import UploadSimple from './UploadSimple.svg'

export const icons = {
Expand All @@ -27,9 +27,9 @@ export const icons = {
info: Info,
infoCircle: InfoCircle,
plus: Plus,
roundedTriangle: RoundedTriangle,
search: Search,
shareNetwork: ShareNetwork,
signOut: SignOut,
toastPopup: ToastPopup,
uploadSimple: UploadSimple,
}
79 changes: 79 additions & 0 deletions src/components/tooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { HTMLAttributes, forwardRef } from 'react'

import cn from '@/utils/cn'
import { VariantProps, cva } from 'class-variance-authority'
import AccessibleIconButton from './accessible-icon-button'
import Typography from './common/typography'
import Icon from './common/icon'

const TooltipVariants = cva<{
color: Record<'orange' | 'neutral', string>
size: Record<'sm' | 'md' | 'lg', string>
}>(
`absolute whitespace-nowrap flex gap-2.5 items-center z-10 text-white rounded-full left-0 top-[calc(100%+20px)]
`,
{
variants: {
color: {
neutral: `bg-neutral-500`,
orange: `bg-orange-400`,
},
size: {
lg: 'px-7 py-5',
md: 'px-5 py-3',
sm: 'px-3 py-2',
},
},
defaultVariants: {
color: 'orange',
size: 'md',
},
},
)

interface TooltipProps
extends HTMLAttributes<HTMLDivElement>,
VariantProps<typeof TooltipVariants> {
label: string
onClose: () => void
color?: 'orange' | 'neutral'
size?: 'sm' | 'md' | 'lg'
}

const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
({ size, color, className, label, children, onClose, ...props }, ref) => {
return (
<div className="relative">
{children}
<div
role="tooltip"
{...props}
ref={ref}
className={cn(TooltipVariants({ color, size }), className)}
>
<Typography size="h5-2" className="text-white">
{label}
</Typography>
<Icon
type="roundedTriangle"
className="absolute bottom-[calc(100%-6px)] left-5 w-[22px] h-[18px]"
/>
<AccessibleIconButton
label="닫기"
icon={{
type: 'close',
onClick: onClose,
stroke: 'neutral-000',
'aria-hidden': true,
size: 'sm',
}}
/>
</div>
</div>
)
},
)

Tooltip.displayName = 'Tooltip'

export default Tooltip
39 changes: 39 additions & 0 deletions src/stories/tooltip.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import type { Meta, StoryObj } from '@storybook/react'

import Tooltip from '@/components/tooltip'

const meta = {
title: 'DesignSystem/Tooltip',
component: Tooltip,
tags: ['autodocs'],
argTypes: {
color: {
control: 'select',
options: ['neutral', 'orange'],
},
},
} satisfies Meta<typeof Tooltip>

export default meta
type Story = StoryObj<typeof meta>

export const Default: Story = {
args: {
label: 'tooltip Orange example',
onClose: () => {
alert('close')
},
children: 'tooltip Children',
},
}

export const Gray: Story = {
args: {
color: 'neutral',
label: 'tooltip Grey example',
onClose: () => {
alert('close')
},
children: 'tooltip Children',
},
}
Loading