refactor: refactor tag component

This commit is contained in:
jinhojang6 2023-02-16 20:08:24 +09:00
parent 4cf53a8cae
commit 0df15ca89d
No known key found for this signature in database
GPG Key ID: 0E7AA62CB0D9E6F3
2 changed files with 12 additions and 24 deletions

View File

@ -3,5 +3,5 @@ export const tagClasses = {
outlined: `lsd-tag--outlined`,
filled: `lsd-tag--filled`,
disabled: 'lsd-breadcrumb--disabled',
disabled: 'lsd-tag--disabled',
}

View File

@ -1,12 +1,13 @@
import clsx from 'clsx'
import React from 'react'
import { Typography } from '../Typography'
import { tagClasses } from './Tag.classes'
export type TagProps = React.HTMLAttributes<HTMLDivElement> & {
variant?: 'outlined' | 'filled'
label: string
icon?: React.ReactNode
iconDirection?: 'left' | 'right' | 'none'
iconDirection?: 'left' | 'right'
disabled?: boolean
}
@ -17,35 +18,22 @@ export const Tag: React.FC<TagProps> & {
variant = 'outlined',
disabled = 'false',
icon,
iconDirection,
iconDirection = 'left',
children,
...props
}) => {
const renderItems = () => {
switch (iconDirection) {
case 'left':
return (
const renderItems = () => (
<>
{icon}
{label}
{iconDirection === 'left' && icon}
<Typography className={tagClasses[variant]}>{label}</Typography>
{iconDirection === 'right' && icon}
</>
)
case 'right':
return (
<>
{label}
{icon}
</>
)
default:
return <>{label}</>
}
}
return (
<div
{...props}
aria-label={label}
{...props}
className={clsx(
props.className,
tagClasses.root,