Toolbar
A container for grouping related actions or controls.
<script lang="ts">
import { AlignCenter, AlignLeft, AlignRight, DollarSign, Percent } from "@lucide/svelte";
import {
Button,
Select,
SelectItem,
SelectPopup,
SelectTrigger,
SelectValue,
ToggleGroup,
ToggleGroupItem,
Toolbar,
ToolbarButton,
ToolbarGroup,
ToolbarSeparator,
} from "coss-svelte";
const fonts = [
{ label: "Helvetica", value: "helvetica" },
{ label: "Arial", value: "arial" },
{ label: "Times New Roman", value: "times-new-roman" },
];
</script>
<Toolbar aria-label="Formatting options">
<ToggleGroup class="border-none bg-transparent p-0 shadow-none" value="left">
<ToggleGroupItem value="left" aria-label="Align left"><AlignLeft /></ToggleGroupItem>
<ToggleGroupItem value="center" aria-label="Align center"><AlignCenter /></ToggleGroupItem>
<ToggleGroupItem value="right" aria-label="Align right"><AlignRight /></ToggleGroupItem>
</ToggleGroup>
<ToolbarSeparator />
<ToolbarGroup>
<ToolbarButton aria-label="Format as currency"><DollarSign class="size-4" /></ToolbarButton>
<ToolbarButton aria-label="Format as percent"><Percent class="size-4" /></ToolbarButton>
</ToolbarGroup>
<ToolbarSeparator />
<Select value="helvetica" options={fonts}>
<SelectTrigger aria-label="Font family" class="w-44"><SelectValue /></SelectTrigger>
<SelectPopup>
{#each fonts as font}
<SelectItem value={font.value} label={font.label}>{font.label}</SelectItem>
{/each}
</SelectPopup>
</Select>
<ToolbarSeparator />
<Button>Save</Button>
</Toolbar>
Installation
Install the component package, shared coss-svelte theme, and Bits UI peer.
npm install coss-svelte @coss-svelte/theme bits-uiUsage
Import the Svelte component exports directly from the package.
import { Toolbar, ToolbarButton, ToolbarGroup, ToolbarGroupItem, ToolbarLink, ToolbarSeparator } from "coss-svelte";Anatomy
- Toolbar
- ToolbarButton
- ToolbarGroup
- ToolbarGroupItem
- ToolbarLink
- ToolbarSeparator
API Reference
Toolbar
A container for grouping related actions or controls.
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | Orientation | "horizontal" | Layout direction for the component. |
children : Snippet<[]>bind:ref : HTMLElement | nullInherits from Bits UI Toolbar.Root.
ToolbarButton
Renders a button-shaped control for the parent component.
children : Snippet<[]>child : Snippet<[{ props: Record<string, unknown> }]>bind:ref : HTMLElement | nullInherits from Bits UI Toolbar.Button.
ToolbarGroup
Groups related items inside the parent component.
| Prop | Type | Default | Description |
|---|---|---|---|
type | "single" | "multiple" | "button" | Behavior, selection, or HTML type passed to the underlying control. |
bind:value | string | string[] | "" | Current value for the component. Bind with `bind:value` when supported. |
children : Snippet<[]>bind:ref : HTMLElement | nullInherits from Bits UI Toolbar.Group.
ToolbarGroupItem
Renders one item inside a toolbar group.
children : Snippet<[]>bind:ref : HTMLElement | nullInherits from Bits UI Toolbar.GroupItem.
ToolbarLink
Renders a link-styled navigation item.
children : Snippet<[]>child : Snippet<[{ props: Record<string, unknown> }]>bind:ref : HTMLElement | nullInherits from Bits UI Toolbar.Link.
ToolbarSeparator
Visually separates related content.
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | "horizontal" | "vertical" | "vertical" | Layout direction for the component. |
children : Snippet<[]>Inherits from Svelte <span> attributes.
Implementation Details
- Status
- Stable
- Foundation
- bits
- Category
- Layout & Navigation
- Particles
- 1