'use client'
import { HStack } from '@chakra-ui/react'
import { Tag } from '@saas-ui/react'
export const TagBasic = () => {
return (
<HStack>
<Tag>Plain Tag</Tag>
<Tag closable>Closable Tag</Tag>
</HStack>
)
}
Anatomy
import { Tag } from '@saas-ui/react/tag'
<Tag>Tag here</Tag>
Examples
Icon
Use the startElement
prop to add an icon to the tag.
'use client'
import { HStack } from '@chakra-ui/react'
import { Tag } from '@saas-ui/react'
import { LuCircleUser, LuFileBadge } from 'react-icons/lu'
export const TagWithIcon = () => {
return (
<HStack>
<Tag startElement={<LuCircleUser />}>Tag 2</Tag>
<Tag startElement={<LuFileBadge />}>Top Rated</Tag>
</HStack>
)
}
Variants
Use the variant
prop to change the appearance of the tag.
'use client'
import { For, HStack, Stack } from '@chakra-ui/react'
import { Tag } from '@saas-ui/react'
import { HiCheck } from 'react-icons/hi'
export const TagWithVariants = () => {
return (
<Stack gap="8">
<For each={['subtle', 'solid', 'outline', 'surface']}>
{(variant) => (
<HStack key={variant}>
<Tag variant={variant}>Gray</Tag>
<Tag variant={variant} closable>
Gray
</Tag>
<Tag endElement={<HiCheck />} variant={variant}>
Gray
</Tag>
</HStack>
)}
</For>
</Stack>
)
}
Sizes
Use the size
prop to change the size of the tag.
'use client'
import { For, HStack, Stack } from '@chakra-ui/react'
import { Tag } from '@saas-ui/react'
import { HiCheck } from 'react-icons/hi'
export const TagWithSizes = () => {
return (
<Stack gap="8">
<For each={['sm', 'md', 'lg']}>
{(size) => (
<HStack key={size}>
<Tag size={size}>Gray</Tag>
<Tag size={size} closable>
Gray
</Tag>
<Tag endElement={<HiCheck />} size={size}>
Gray
</Tag>
</HStack>
)}
</For>
</Stack>
)
}
Colors
Use the colorPalette
prop to change the color of the tag.
gray
zinc
neutral
stone
red
orange
amber
yellow
lime
green
emerald
teal
cyan
sky
blue
indigo
violet
purple
fuchsia
pink
rose
'use client'
import { Stack, Text } from '@chakra-ui/react'
import { Tag } from '@saas-ui/react'
import { HiPlus } from 'react-icons/hi'
import { colorPalettes } from '../lib/color-palettes'
export const TagWithColors = () => {
return (
<Stack gap="2" align="flex-start">
{colorPalettes.map((colorPalette) => (
<Stack
align="center"
key={colorPalette}
direction="row"
gap="10"
px="4"
>
<Text minW="8ch">{colorPalette}</Text>
<Tag size="sm" colorPalette={colorPalette}>
Content
</Tag>
<Tag startElement={<HiPlus />} size="sm" colorPalette={colorPalette}>
Content
</Tag>
<Tag size="sm" colorPalette={colorPalette} variant="solid" closable>
Content
</Tag>
</Stack>
))}
</Stack>
)
}
Closable
Use the closable
prop to make the tag closable.
'use client'
import { HStack } from '@chakra-ui/react'
import { Tag } from '@saas-ui/react'
import { LuActivity } from 'react-icons/lu'
export const TagWithClose = () => {
return (
<HStack>
<Tag startElement={<LuActivity />} closable>
Tag 1
</Tag>
<Tag closable>Tag 2</Tag>
</HStack>
)
}
Overflow
Use the maxWidth
prop to control the maximum width of the tag. When the
content exceeds this width, it will be truncated with an ellipsis.
This is particularly useful when dealing with dynamic or user-generated content where the length might vary.
'use client'
import { Tag } from '@saas-ui/react'
export const TagWithOverflow = () => {
return (
<Tag size="sm" colorPalette="blue" maxW="200px" closable>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam
molestias, laboriosam, quod, quia quidem quae voluptatem natus
exercitationem autem quibusdam
</Tag>
)
}
Avatar
Here's an example of a tag with an avatar.
'use client'
import { For, HStack } from '@chakra-ui/react'
import { Avatar, Tag } from '@saas-ui/react'
export const TagWithAvatar = () => {
return (
<HStack>
<For each={['sm', 'md', 'lg', 'xl']}>
{(size) => (
<Tag
key={size}
rounded="full"
size={size}
startElement={
<Avatar
size="full"
src="https://i.pravatar.cc/300?u=1"
name="John Doe"
/>
}
>
Emily ({size})
</Tag>
)}
</For>
</HStack>
)
}
As Button
Use the asChild
prop to render the tag as a button.
Note that you'll need to import the Tag from @chakra-ui/react
to use this
prop.
'use client'
import { Tag } from '@saas-ui/react'
import { LuCheck } from 'react-icons/lu'
export const TagAsButton = () => {
return (
<Tag as="button" variant="solid" endElement={<LuCheck />}>
Fish
</Tag>
)
}
Props
Root
Prop | Default | Type |
---|---|---|
colorPalette | 'gray' | 'gray' | 'zinc' | 'neutral' | 'stone' | 'red' | 'orange' | 'amber' | 'yellow' | 'lime' | 'green' | 'emerald' | 'teal' | 'cyan' | 'sky' | 'blue' | 'indigo' | 'violet' | 'purple' | 'fuchsia' | 'pink' | 'rose' | 'presence' | 'status' | 'sidebar' | 'sidebar.accent' | 'accent' | 'slate' The color palette of the component |
size | 'md' | 'sm' | 'md' | 'lg' | 'xl' The size of the component |
variant | 'surface' | 'subtle' | 'solid' | 'outline' | 'surface' The variant of the component |