Tag
A small label for a keyword or a choice, which the user can often remove.
Usage
import { Tag } from '@leverui/components';
<Tag.Root>
<Tag.Label>Tag here</Tag.Label>
</Tag.Root>
For one ready-made component, see the snippet below.
Examples
Icon
Use the Tag.StartElement and Tag.EndElement components to add an icon to the start or end of the tag
Variants
Use the variant prop to change the appearance of the tag.
Sizes
Use the size prop to change the size of the tag.
Colors
Use the colorPalette prop to change the color of the tag.
gray
red
green
blue
teal
pink
purple
cyan
orange
yellow
Closable
Use the Tag.CloseTrigger within the Tag.EndElement to make the tag closable.
Overflow
Use the max-width style 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.
Avatar
The tag component has been designed to work well with the Avatar component.
Note: Set the avatar size to
fullto ensure it's sized correctly.
Render as button
Use the asChild prop to render the tag as a button.
Closed Component
import { Show, omit } from 'solid-js';
import type { JSX } from '@solidjs/web';
import { Tag, type TagRootProps } from '@leverui/components';
export type ClosedTagProps = TagRootProps & {
startElement?: JSX.Element;
endElement?: JSX.Element;
onClose?: () => void;
closable?: boolean;
};
export function ClosedTag(props: ClosedTagProps) {
const root = omit(props, 'startElement', 'endElement', 'onClose', 'closable', 'children');
return (
<Tag.Root {...root}>
<Show when={props.startElement}>
<Tag.StartElement>{props.startElement}</Tag.StartElement>
</Show>
<Tag.Label>{props.children}</Tag.Label>
<Show when={props.endElement}>
<Tag.EndElement>{props.endElement}</Tag.EndElement>
</Show>
<Show when={props.closable ?? Boolean(props.onClose)}>
<Tag.EndElement>
<Tag.CloseTrigger onClick={() => props.onClose?.()} />
</Tag.EndElement>
</Show>
</Tag.Root>
);
}
Props
Root
| Prop | Default | Type | Description |
|---|---|---|---|
colorPalette | gray | 'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | Color palette. |
size | md | 'sm' | 'md' | 'lg' | 'xl' | Tag size. Responsive. |
variant | surface | 'subtle' | 'solid' | 'outline' | 'surface' | Tag style. Responsive. |
as | div | Native HTML tag | HTML tag to render. |
asChild | — | Solid render function | Render your own element with the tag's props. |
unstyled | false | boolean | Turn off the Lever UI styles. |
The root is a native div with no ARIA role. The label and the start and end
elements are span elements. The label stays on one line. For long text, limit
the root's width with style.
Tag.CloseTrigger is a native type="button" with a decorative close icon.
Screen readers announce it as Close. Pass a more specific aria-label when
the user needs to know what closes. It does not remove the tag, so do that in
onClick.
With asChild, spread getProps() on your element to keep the Tag styles,
attributes, and events. Tag.RootPropsProvider takes its defaults as an object
or a Solid accessor. Use an accessor when they depend on signals. A prop on a
tag wins.
Customize with CSS
Import @leverui/components/styles.css, then style .leverui-tag__root,
.leverui-tag__label, .leverui-tag__startElement,
.leverui-tag__endElement, and .leverui-tag__closeTrigger. The class names
do not change.
The root has attributes for its size, variant, and palette. Responsive values
add data-size-sm through data-size-2xl and data-variant-sm through
data-variant-2xl. Override the --leverui-* variables on a theme scope or on
a single Tag.
.leverui-tag__label {
letter-spacing: 0.01em;
}
A part's class gives your own element that part's default styles.
<span class="leverui-tag__label">Custom</span> inside Tag.Root follows the
root's current size.
Explorer
Click a part name to highlight it in the preview.
Component Anatomy
Hover to highlight, click to select parts