refactor: refactor tag component

This commit is contained in:
jinhojang6 2023-04-05 20:49:11 +09:00 committed by jeangovil
parent dc277c503e
commit e1622255cd
4 changed files with 19 additions and 20 deletions

View File

@ -1,6 +1,8 @@
export const tagClasses = { export const tagClasses = {
root: `lsd-tag`, root: `lsd-tag`,
label: `lsd-tag__label`,
outlined: `lsd-tag--outlined`, outlined: `lsd-tag--outlined`,
filled: `lsd-tag--filled`, filled: `lsd-tag--filled`,
disabled: 'lsd-tag--disabled', disabled: 'lsd-tag--disabled',

View File

@ -35,12 +35,13 @@ export default {
} as Meta } as Meta
export const Root: Story<TagProps> = (args) => ( export const Root: Story<TagProps> = (args) => (
<Tag {...args} icon={<FolderIcon color="primary" />} /> <Tag {...args} icon={<FolderIcon color="primary" />}>
Tag
</Tag>
) )
Root.args = { Root.args = {
variant: 'outlined', variant: 'outlined',
label: 'Tag',
iconDirection: 'left', iconDirection: 'left',
disabled: false, disabled: false,
size: 'large', size: 'large',

View File

@ -33,7 +33,10 @@ export const TagStyles = css`
.${tagClasses.filled} { .${tagClasses.filled} {
background-color: rgb(var(--lsd-icon-primary)); background-color: rgb(var(--lsd-icon-primary));
.${tagClasses.label} {
color: rgb(var(--lsd-text-secondary)); color: rgb(var(--lsd-text-secondary));
}
svg { svg {
--lsd-icon-primary: var(--lsd-icon-secondary); --lsd-icon-primary: var(--lsd-icon-secondary);
} }

View File

@ -5,7 +5,6 @@ import { tagClasses } from './Tag.classes'
export type TagProps = React.HTMLAttributes<HTMLDivElement> & { export type TagProps = React.HTMLAttributes<HTMLDivElement> & {
variant?: 'outlined' | 'filled' variant?: 'outlined' | 'filled'
label: string
icon?: React.ReactNode icon?: React.ReactNode
iconDirection?: 'left' | 'right' iconDirection?: 'left' | 'right'
disabled?: boolean disabled?: boolean
@ -15,7 +14,6 @@ export type TagProps = React.HTMLAttributes<HTMLDivElement> & {
export const Tag: React.FC<TagProps> & { export const Tag: React.FC<TagProps> & {
classes: typeof tagClasses classes: typeof tagClasses
} = ({ } = ({
label,
variant = 'outlined', variant = 'outlined',
disabled = 'false', disabled = 'false',
icon, icon,
@ -24,22 +22,9 @@ export const Tag: React.FC<TagProps> & {
size = 'large', size = 'large',
...props ...props
}) => { }) => {
const renderItems = () => (
<>
{iconDirection === 'left' && icon}
<Typography
variant={size === 'small' ? 'label2' : 'label1'}
className={tagClasses[variant]}
>
{label}
</Typography>
{iconDirection === 'right' && icon}
</>
)
return ( return (
<div <div
aria-label={label} aria-label={children as string}
{...props} {...props}
className={clsx( className={clsx(
props.className, props.className,
@ -49,7 +34,15 @@ export const Tag: React.FC<TagProps> & {
tagClasses[size], tagClasses[size],
)} )}
> >
{renderItems()} {iconDirection === 'left' && icon}
<Typography
variant={size === 'small' ? 'label2' : 'label1'}
className={tagClasses.label}
component="span"
>
{children}
</Typography>
{iconDirection === 'right' && icon}
</div> </div>
) )
} }