-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cb6e5a
commit 4cf53a8
Showing
7 changed files
with
153 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const tagClasses = { | ||
root: `lsd-tag`, | ||
|
||
outlined: `lsd-tag--outlined`, | ||
filled: `lsd-tag--filled`, | ||
disabled: 'lsd-breadcrumb--disabled', | ||
} |
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,39 @@ | ||
import { Meta, Story } from '@storybook/react' | ||
import { FolderIcon } from '../Icons' | ||
import { Tag, TagProps } from './Tag' | ||
|
||
export default { | ||
title: 'Tag', | ||
component: Tag, | ||
argTypes: { | ||
variant: { | ||
type: { | ||
name: 'enum', | ||
value: ['outlined', 'filled'], | ||
}, | ||
}, | ||
iconDirection: { | ||
type: { | ||
name: 'enum', | ||
value: ['left', 'right', 'none'], | ||
}, | ||
}, | ||
disabled: { | ||
type: { | ||
name: 'boolean', | ||
value: [true, false], | ||
}, | ||
}, | ||
}, | ||
} as Meta | ||
|
||
export const Root: Story<TagProps> = (args) => ( | ||
<Tag {...args} icon={<FolderIcon color="primary" />} /> | ||
) | ||
|
||
Root.args = { | ||
variant: 'outlined', | ||
label: 'Tag', | ||
iconDirection: 'left', | ||
disabled: false, | ||
} |
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,42 @@ | ||
import { css } from '@emotion/react' | ||
import { tagClasses } from './Tag.classes' | ||
|
||
export const TagStyles = css` | ||
.${tagClasses.root} { | ||
width: fit-content; | ||
height: 28px; | ||
padding: 4px 12px; | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: center; | ||
gap: 12px; | ||
border: 1px solid rgb(var(--lsd-icon-primary)); | ||
&:hover, | ||
&:focus { | ||
text-decoration: underline; | ||
cursor: pointer; | ||
} | ||
} | ||
.${tagClasses.filled} { | ||
background-color: rgb(var(--lsd-icon-primary)); | ||
color: rgb(var(--lsd-text-secondary)); | ||
svg { | ||
--lsd-icon-primary: var(--lsd-icon-secondary); | ||
} | ||
} | ||
.${tagClasses.outlined} { | ||
color: rgb(var(--lsd-text-primary)); | ||
} | ||
.${tagClasses.disabled} { | ||
opacity: 0.3; | ||
cursor: initial; | ||
pointer-events: none; | ||
} | ||
` |
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,61 @@ | ||
import clsx from 'clsx' | ||
import React from 'react' | ||
import { tagClasses } from './Tag.classes' | ||
|
||
export type TagProps = React.HTMLAttributes<HTMLDivElement> & { | ||
variant?: 'outlined' | 'filled' | ||
label: string | ||
icon?: React.ReactNode | ||
iconDirection?: 'left' | 'right' | 'none' | ||
disabled?: boolean | ||
} | ||
|
||
export const Tag: React.FC<TagProps> & { | ||
classes: typeof tagClasses | ||
} = ({ | ||
label, | ||
variant = 'outlined', | ||
disabled = 'false', | ||
icon, | ||
iconDirection, | ||
children, | ||
...props | ||
}) => { | ||
const renderItems = () => { | ||
switch (iconDirection) { | ||
case 'left': | ||
return ( | ||
<> | ||
{icon} | ||
{label} | ||
</> | ||
) | ||
case 'right': | ||
return ( | ||
<> | ||
{label} | ||
{icon} | ||
</> | ||
) | ||
default: | ||
return <>{label}</> | ||
} | ||
} | ||
|
||
return ( | ||
<div | ||
{...props} | ||
aria-label={label} | ||
className={clsx( | ||
props.className, | ||
tagClasses.root, | ||
tagClasses[variant], | ||
disabled && tagClasses.disabled, | ||
)} | ||
> | ||
{renderItems()} | ||
</div> | ||
) | ||
} | ||
|
||
Tag.classes = tagClasses |
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 @@ | ||
export * from './Tag' |
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