Tag Group
An information summary component that displays multiple attributes, states, and metadata at a glance by listing icon and text tags horizontally.
import { IconLocationpinFill } from "@karrotmarket/react-monochrome-icon";
import { TagGroupRoot, TagGroupItem } from "seed-design/ui/tag-group";
export default function TagGroupPreview() {
return (
<TagGroupRoot>
<TagGroupItem prefixIcon={<IconLocationpinFill />} label="500m" />
<TagGroupItem label="Downtown" />
<TagGroupItem label="3 min ago" />
</TagGroupRoot>
);
}Installation
npx @seed-design/cli@latest add ui:tag-grouppnpm dlx @seed-design/cli@latest add ui:tag-groupyarn dlx @seed-design/cli@latest add ui:tag-groupbun x @seed-design/cli@latest add ui:tag-groupInstall dependencies
npm install @seed-design/reactyarn add @seed-design/reactpnpm add @seed-design/reactbun add @seed-design/reactCopy the code below and paste it in
/**
* @file ui:tag-group
* @requires @seed-design/react@^2.0.0
* @requires @seed-design/css@^2.0.0
**/
"use client";
import { PrefixIcon, TagGroup as SeedTagGroup, SuffixIcon } from "@seed-design/react";
import * as React from "react";
export interface TagGroupRootProps extends SeedTagGroup.RootProps {}
/**
* @see https://crispy.carrot-soft.tech/react/components/tag-group
*/
export const TagGroupRoot = SeedTagGroup.Root;
export interface TagGroupItemProps extends Omit<SeedTagGroup.ItemProps, "children"> {
prefixIcon?: React.ReactNode;
label: React.ReactNode;
suffixIcon?: React.ReactNode;
}
/**
* @see https://crispy.carrot-soft.tech/react/components/tag-group
*/
export const TagGroupItem = React.forwardRef<HTMLSpanElement, TagGroupItemProps>(
({ prefixIcon, label, suffixIcon, ...props }, ref) => {
return (
<SeedTagGroup.Item {...props} ref={ref}>
{prefixIcon && <PrefixIcon svg={prefixIcon} />}
<SeedTagGroup.ItemLabel>{label}</SeedTagGroup.ItemLabel>
{suffixIcon && <SuffixIcon svg={suffixIcon} />}
</SeedTagGroup.Item>
);
},
);
/**
* This file is a snippet from Crispy, helping you get started quickly with @seed-design/* packages.
* You can extend this snippet however you want.
*/
Props
TagGroupRoot
Prop
Type
separator?React.ReactNodeTagGroupItem
Prop
Type
prefixIcon?React.ReactNodelabelReact.ReactNodesuffixIcon?React.ReactNodeExamples
Sizes
import { VStack } from "@seed-design/react";
import { TagGroupRoot, TagGroupItem } from "seed-design/ui/tag-group";
export default function TagGroupSizes() {
return (
<VStack gap="spacingY.componentDefault" align="center">
<TagGroupRoot size="t2">
<TagGroupItem label="t2" />
<TagGroupItem label="t2" />
<TagGroupItem label="t2" />
</TagGroupRoot>
<TagGroupRoot size="t3">
<TagGroupItem label="t3" />
<TagGroupItem label="t3" />
<TagGroupItem label="t3" />
</TagGroupRoot>
<TagGroupRoot size="t4">
<TagGroupItem label="t4" />
<TagGroupItem label="t4" />
<TagGroupItem label="t4" />
</TagGroupRoot>
</VStack>
);
}Weights
import { VStack } from "@seed-design/react";
import { TagGroupRoot, TagGroupItem } from "seed-design/ui/tag-group";
export default function TagGroupWeights() {
return (
<VStack gap="spacingY.componentDefault" align="center">
<TagGroupRoot weight="regular">
<TagGroupItem label="regular" />
<TagGroupItem label="regular" />
<TagGroupItem label="regular" />
</TagGroupRoot>
<TagGroupRoot weight="bold">
<TagGroupItem label="bold" />
<TagGroupItem label="bold" />
<TagGroupItem label="bold" />
</TagGroupRoot>
</VStack>
);
}Tones
import { VStack } from "@seed-design/react";
import { TagGroupRoot, TagGroupItem } from "seed-design/ui/tag-group";
export default function TagGroupTones() {
return (
<VStack gap="spacingY.componentDefault" align="center">
<TagGroupRoot tone="neutralSubtle">
<TagGroupItem label="neutralSubtle" />
<TagGroupItem label="neutralSubtle" />
<TagGroupItem label="neutralSubtle" />
</TagGroupRoot>
<TagGroupRoot tone="neutral">
<TagGroupItem label="neutral" />
<TagGroupItem label="neutral" />
<TagGroupItem label="neutral" />
</TagGroupRoot>
<TagGroupRoot tone="brand">
<TagGroupItem label="brand" />
<TagGroupItem label="brand" />
<TagGroupItem label="brand" />
</TagGroupRoot>
</VStack>
);
}With Icons
import { IconLocationpinFill, IconMegaphoneFill } from "@karrotmarket/react-monochrome-icon";
import { VStack } from "@seed-design/react";
import { TagGroupRoot, TagGroupItem } from "seed-design/ui/tag-group";
export default function TagGroupWithIcons() {
return (
<VStack gap="spacingY.componentDefault" align="center">
<TagGroupRoot>
<TagGroupItem label="광고" suffixIcon={<IconMegaphoneFill />} />
<TagGroupItem label="끌올 3시간 전" />
<TagGroupItem label="서초4동" />
</TagGroupRoot>
<TagGroupRoot>
<TagGroupItem prefixIcon={<IconLocationpinFill />} label="서초4동" />
<TagGroupItem label="인증 5회" />
<TagGroupItem label="3분 전" />
</TagGroupRoot>
</VStack>
);
}Customizing TagGroupItem
The size, tone, and weight specified on TagGroupRoot can be overridden on TagGroupItem.
If needed, you can customize the internal elements of TagGroupItem by directly using compound components.
import {
IconCheckmarkCircleFill,
IconHeartFill,
IconHorizline2VerticalChatbubbleRectangularRightFill,
IconStarFill,
} from "@karrotmarket/react-monochrome-icon";
import { Icon, VStack } from "@seed-design/react";
import { TagGroupRoot, TagGroupItem } from "seed-design/ui/tag-group";
import { TagGroup as SeedTagGroup } from "@seed-design/react";
export default function TagGroupCustomizingItem() {
return (
<VStack gap="spacingY.componentDefault" align="center">
<TagGroupRoot>
{/* You can use the compound components to customize the items */}
<SeedTagGroup.Item weight="bold" tone="neutral" aria-label="평점 4.5">
<Icon svg={<IconStarFill />} color="fg.brand" />
<SeedTagGroup.ItemLabel>4.5</SeedTagGroup.ItemLabel>
</SeedTagGroup.Item>
<TagGroupItem label="후기 37" />
<TagGroupItem label="단골 12" />
</TagGroupRoot>
<TagGroupRoot tone="neutral">
<TagGroupItem tone="brand" suffixIcon={<IconCheckmarkCircleFill />} label="인증됨" />
<TagGroupItem aria-label="관심 10개" prefixIcon={<IconHeartFill />} label="10" />
<TagGroupItem
aria-label="댓글 3개"
prefixIcon={<IconHorizline2VerticalChatbubbleRectangularRightFill />}
label="3"
/>
</TagGroupRoot>
</VStack>
);
}Customizing Separators
You can change the separator by specifying separator on TagGroupRoot.
Screen readers do not read the specified separator between each tag item. Avoid using semantic information as a separator.
import { VStack } from "@seed-design/react";
import { TagGroupRoot, TagGroupItem } from "seed-design/ui/tag-group";
export default function TagGroupCustomizingSeparators() {
return (
<VStack gap="spacingY.componentDefault" align="center">
<TagGroupRoot separator=" | " size="t4">
<TagGroupItem label="가" />
<TagGroupItem label="나" />
<TagGroupItem label="다" />
<TagGroupItem label="라" />
</TagGroupRoot>
<TagGroupRoot separator=" " size="t4">
<TagGroupItem label="가" />
<TagGroupItem label="나" />
<TagGroupItem label="다" />
<TagGroupItem label="라" />
</TagGroupRoot>
</VStack>
);
}Wrapping Behavior
By default, TagGroupRoot wraps when it exceeds the container width.
When you specify the truncate prop on TagGroupRoot, TagGroupRoot is maintained on one line, and if it exceeds the container width, ellipsis may occur on all TagGroupItem labels by default.
To prevent a specific item from shrinking while using the truncate prop, specify flexShrink={0} on that TagGroupItem. You can adjust the priority of shrinking when exceeding container width by specifying flexShrink={number} on TagGroupItem.
import { IconBellFill, IconLocationpinFill } from "@karrotmarket/react-monochrome-icon";
import { Flex, Text, VStack } from "@seed-design/react";
import { TagGroupRoot, TagGroupItem } from "seed-design/ui/tag-group";
import type { PropsWithChildren, ReactNode } from "react";
export default function TagGroupWrappingBehavior() {
return (
<Flex
align="center"
justify="center"
grow
width="full"
bg="bg.layerBasement"
borderRadius="r2"
p="x4"
>
<VStack
gap="x2"
width="350px"
maxWidth="max-content"
overflowX="auto"
style={{ resize: "horizontal" }}
>
<Wrapper title="default (wrap)">
<TagGroupRoot>
<TagGroupItem prefixIcon={<IconLocationpinFill />} label="부산광역시 해운대구" />
<TagGroupItem prefixIcon={<IconBellFill />} label="123 456 789 012 345" />
<TagGroupItem label="Ut minim laboris enim" />
</TagGroupRoot>
</Wrapper>
<Wrapper title="truncate">
<TagGroupRoot truncate>
<TagGroupItem prefixIcon={<IconLocationpinFill />} label="부산광역시 해운대구" />
<TagGroupItem prefixIcon={<IconBellFill />} label="123 456 789 012 345" />
<TagGroupItem label="Ut minim laboris enim" />
</TagGroupRoot>
</Wrapper>
<Wrapper title="truncate, keep one fixed">
<TagGroupRoot truncate>
<TagGroupItem prefixIcon={<IconLocationpinFill />} label="부산광역시 해운대구" />
<TagGroupItem
flexShrink={0}
prefixIcon={<IconBellFill />}
label="123 456 789 012 345"
/>
<TagGroupItem label="Ut minim laboris enim" />
</TagGroupRoot>
</Wrapper>
<Wrapper title="truncate, mixed shrink ratios">
<TagGroupRoot truncate>
<TagGroupItem
prefixIcon={<IconLocationpinFill />}
flexShrink={1}
label="부산광역시 해운대구"
/>
<TagGroupItem
flexShrink={100}
prefixIcon={<IconBellFill />}
label="123 456 789 012 345"
/>
<TagGroupItem flexShrink={100} label="Ut minim laboris enim" />
</TagGroupRoot>
</Wrapper>
</VStack>
</Flex>
);
}
function Wrapper({ title, children }: PropsWithChildren<{ title: ReactNode }>) {
return (
<VStack
align="flex-start"
justify="center"
padding="x3"
bg="bg.layerDefault"
borderRadius="r2"
borderWidth={1}
borderColor="stroke.neutralWeak"
gap="x1"
overflowX="hidden"
>
<Text textStyle="t2Medium">{title}</Text>
{children}
</VStack>
);
}