Toolbar
A container for grouping a set of buttons and controls.
<?phem
use Phem\Attribute\Component;
use Phem\Node;
use Phem\Ui\{Select, ToggleGroup, Toolbar};
use function Phem\Ui\{SelectIcon, SelectItem, SelectItemIndicator, SelectItemText, SelectList, SelectPopup, SelectTrigger, SelectValue, Toggle, ToolbarButton, ToolbarGroup, ToolbarLink, ToolbarSeparator};
#[Component]
function ToolbarHeroDemo(): Node
{
return (
<Toolbar className="w-150">
<ToggleGroup aria-label="Alignment">
<Toggle aria-label="Align left" value="align-left">Align Left</Toggle>
<Toggle aria-label="Align right" value="align-right">Align Right</Toggle>
</ToggleGroup>
<ToolbarSeparator />
<ToolbarGroup aria-label="Numerical format">
<ToolbarButton aria-label="Format as currency" className="px-0">$</ToolbarButton>
<ToolbarButton aria-label="Format as percent" className="px-0">%</ToolbarButton>
</ToolbarGroup>
<ToolbarSeparator />
<Select defaultValue="Helvetica" sideOffset={{ 4 }}>
<SelectTrigger>
<SelectValue />
<SelectIcon />
</SelectTrigger>
<SelectPopup>
<SelectList>
<SelectItem value="Helvetica">
<SelectItemIndicator />
<SelectItemText>Helvetica</SelectItemText>
</SelectItem>
<SelectItem value="Arial">
<SelectItemIndicator />
<SelectItemText>Arial</SelectItemText>
</SelectItem>
</SelectList>
</SelectPopup>
</Select>
<ToolbarSeparator />
<ToolbarLink href="#">Edited 51m ago</ToolbarLink>
</Toolbar>
);
}
Examples#
#
All popup components that provide a Trigger component can be integrated with a toolbar: in a Toolbar, the trigger is an item of the toolbar, with the look of a ToolbarButton.
This applies to AlertDialog, Dialog, Menu, Popover, and Select.
Using with Tooltip#
A TooltipTrigger in a Toolbar is an item of the toolbar.
<?phem
use Phem\Attribute\Component;
use Phem\Node;
use Phem\Ui\{Toolbar, Tooltip};
use function Phem\Ui\{TooltipPopup, TooltipTrigger};
#[Component]
function ToolbarTooltipDemo(): Node
{
return (
<Toolbar aria-label="Text formatting">
<Tooltip sideOffset={{ 10 }}>
<TooltipTrigger aria-label="Bold">
<BoldIcon />
</TooltipTrigger>
<TooltipPopup>Bold</TooltipPopup>
</Tooltip>
<Tooltip sideOffset={{ 10 }}>
<TooltipTrigger aria-label="Italic">
<ItalicIcon />
</TooltipTrigger>
<TooltipPopup>Italic</TooltipPopup>
</Tooltip>
</Toolbar>
);
}
#[Component]
function BoldIcon(): Node
{
return (
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 16 16" fill="currentColor" className="block">
<path d="M3.73353 2.13333C3.4386 2.13333 3.2002 2.37226 3.2002 2.66666C3.2002 2.96106 3.4386 3.2 3.73353 3.2H4.26686V12.8H3.73353C3.4386 12.8 3.2002 13.0389 3.2002 13.3333C3.2002 13.6277 3.4386 13.8667 3.73353 13.8667H9.86686C11.7783 13.8667 13.3335 12.3115 13.3335 10.4C13.3335 8.9968 12.4945 7.78881 11.2929 7.24375C11.8897 6.70615 12.2669 5.93066 12.2669 5.06666C12.2669 3.44906 10.9506 2.13333 9.33353 2.13333H3.73353ZM6.93353 3.2H8.26686C9.29619 3.2 10.1335 4.03733 10.1335 5.06666C10.1335 6.096 9.29619 6.93333 8.26686 6.93333H6.93353V3.2ZM6.93353 8H7.73353H8.26686C9.59006 8 10.6669 9.0768 10.6669 10.4C10.6669 11.7232 9.59006 12.8 8.26686 12.8H6.93353V8Z" />
</svg>
);
}
#[Component]
function ItalicIcon(): Node
{
return (
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 16 16" fill="currentColor" className="block">
<path d="M8.52599 2.12186C8.48583 2.12267 8.44578 2.1265 8.4062 2.13332H6.93328C6.86261 2.13232 6.79244 2.14538 6.72686 2.17173C6.66127 2.19808 6.60158 2.23721 6.55125 2.28683C6.50092 2.33646 6.46096 2.39559 6.43368 2.46079C6.4064 2.526 6.39235 2.59597 6.39235 2.66665C6.39235 2.73733 6.4064 2.80731 6.43368 2.87251C6.46096 2.93772 6.50092 2.99685 6.55125 3.04647C6.60158 3.0961 6.66127 3.13522 6.72686 3.16157C6.79244 3.18793 6.86261 3.20099 6.93328 3.19999H7.70099L6.69057 12.8H5.86661C5.79594 12.799 5.72577 12.812 5.66019 12.8384C5.59461 12.8648 5.53492 12.9039 5.48459 12.9535C5.43425 13.0031 5.39429 13.0623 5.36701 13.1275C5.33973 13.1927 5.32568 13.2626 5.32568 13.3333C5.32568 13.404 5.33973 13.474 5.36701 13.5392C5.39429 13.6044 5.43425 13.6635 5.48459 13.7131C5.53492 13.7628 5.59461 13.8019 5.66019 13.8282C5.72577 13.8546 5.79594 13.8677 5.86661 13.8667H9.06661C9.13729 13.8677 9.20745 13.8546 9.27304 13.8282C9.33862 13.8019 9.39831 13.7628 9.44864 13.7131C9.49897 13.6635 9.53894 13.6044 9.56622 13.5392C9.5935 13.474 9.60754 13.404 9.60754 13.3333C9.60754 13.2626 9.5935 13.1927 9.56622 13.1275C9.53894 13.0623 9.49897 13.0031 9.44864 12.9535C9.39831 12.9039 9.33862 12.8648 9.27304 12.8384C9.20745 12.812 9.13729 12.799 9.06661 12.8H8.2989L9.30932 3.19999H10.1333C10.204 3.20099 10.2741 3.18793 10.3397 3.16157C10.4053 3.13522 10.465 3.0961 10.5153 3.04647C10.5656 2.99685 10.6056 2.93772 10.6329 2.87251C10.6602 2.80731 10.6742 2.73733 10.6742 2.66665C10.6742 2.59597 10.6602 2.526 10.6329 2.46079C10.6056 2.39559 10.5656 2.33646 10.5153 2.28683C10.465 2.23721 10.4053 2.19808 10.3397 2.17173C10.2741 2.14538 10.204 2.13232 10.1333 2.13332H8.66349C8.61807 2.12555 8.57207 2.12171 8.52599 2.12186Z" />
</svg>
);
}
Using toggles with Tooltip#
A Toggle or a ToolbarButton in a Tooltip is a trigger of the tooltip: a toggle of a ToggleGroup keeps its group, and gets a tooltip.
<?phem
use Phem\Attribute\Component;
use Phem\Node;
use Phem\Ui\{ToggleGroup, Toolbar, Tooltip};
use function Phem\Ui\{Toggle, ToolbarButton, ToolbarSeparator, TooltipPopup};
#[Component]
function ToolbarToggleTooltipDemo(): Node
{
return (
<Toolbar aria-label="Text formatting">
<ToggleGroup multiple aria-label="Text style">
<Tooltip sideOffset={{ 10 }}>
<Toggle value="bold" aria-label="Bold">
<BoldIcon />
</Toggle>
<TooltipPopup>Bold</TooltipPopup>
</Tooltip>
<Tooltip sideOffset={{ 10 }}>
<Toggle value="italic" aria-label="Italic">
<ItalicIcon />
</Toggle>
<TooltipPopup>Italic</TooltipPopup>
</Tooltip>
</ToggleGroup>
<ToolbarSeparator />
<Tooltip sideOffset={{ 10 }}>
<ToolbarButton>Share</ToolbarButton>
<TooltipPopup>Share this document</TooltipPopup>
</Tooltip>
</Toolbar>
);
}
#[Component]
function BoldIcon(): Node
{
return (
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 16 16" fill="currentColor" className="block">
<path d="M3.73353 2.13333C3.4386 2.13333 3.2002 2.37226 3.2002 2.66666C3.2002 2.96106 3.4386 3.2 3.73353 3.2H4.26686V12.8H3.73353C3.4386 12.8 3.2002 13.0389 3.2002 13.3333C3.2002 13.6277 3.4386 13.8667 3.73353 13.8667H9.86686C11.7783 13.8667 13.3335 12.3115 13.3335 10.4C13.3335 8.9968 12.4945 7.78881 11.2929 7.24375C11.8897 6.70615 12.2669 5.93066 12.2669 5.06666C12.2669 3.44906 10.9506 2.13333 9.33353 2.13333H3.73353ZM6.93353 3.2H8.26686C9.29619 3.2 10.1335 4.03733 10.1335 5.06666C10.1335 6.096 9.29619 6.93333 8.26686 6.93333H6.93353V3.2ZM6.93353 8H7.73353H8.26686C9.59006 8 10.6669 9.0768 10.6669 10.4C10.6669 11.7232 9.59006 12.8 8.26686 12.8H6.93353V8Z" />
</svg>
);
}
#[Component]
function ItalicIcon(): Node
{
return (
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 16 16" fill="currentColor" className="block">
<path d="M8.52599 2.12186C8.48583 2.12267 8.44578 2.1265 8.4062 2.13332H6.93328C6.86261 2.13232 6.79244 2.14538 6.72686 2.17173C6.66127 2.19808 6.60158 2.23721 6.55125 2.28683C6.50092 2.33646 6.46096 2.39559 6.43368 2.46079C6.4064 2.526 6.39235 2.59597 6.39235 2.66665C6.39235 2.73733 6.4064 2.80731 6.43368 2.87251C6.46096 2.93772 6.50092 2.99685 6.55125 3.04647C6.60158 3.0961 6.66127 3.13522 6.72686 3.16157C6.79244 3.18793 6.86261 3.20099 6.93328 3.19999H7.70099L6.69057 12.8H5.86661C5.79594 12.799 5.72577 12.812 5.66019 12.8384C5.59461 12.8648 5.53492 12.9039 5.48459 12.9535C5.43425 13.0031 5.39429 13.0623 5.36701 13.1275C5.33973 13.1927 5.32568 13.2626 5.32568 13.3333C5.32568 13.404 5.33973 13.474 5.36701 13.5392C5.39429 13.6044 5.43425 13.6635 5.48459 13.7131C5.53492 13.7628 5.59461 13.8019 5.66019 13.8282C5.72577 13.8546 5.79594 13.8677 5.86661 13.8667H9.06661C9.13729 13.8677 9.20745 13.8546 9.27304 13.8282C9.33862 13.8019 9.39831 13.7628 9.44864 13.7131C9.49897 13.6635 9.53894 13.6044 9.56622 13.5392C9.5935 13.474 9.60754 13.404 9.60754 13.3333C9.60754 13.2626 9.5935 13.1927 9.56622 13.1275C9.53894 13.0623 9.49897 13.0031 9.44864 12.9535C9.39831 12.9039 9.33862 12.8648 9.27304 12.8384C9.20745 12.812 9.13729 12.799 9.06661 12.8H8.2989L9.30932 3.19999H10.1333C10.204 3.20099 10.2741 3.18793 10.3397 3.16157C10.4053 3.13522 10.465 3.0961 10.5153 3.04647C10.5656 2.99685 10.6056 2.93772 10.6329 2.87251C10.6602 2.80731 10.6742 2.73733 10.6742 2.66665C10.6742 2.59597 10.6602 2.526 10.6329 2.46079C10.6056 2.39559 10.5656 2.33646 10.5153 2.28683C10.465 2.23721 10.4053 2.19808 10.3397 2.17173C10.2741 2.14538 10.204 2.13232 10.1333 2.13332H8.66349C8.61807 2.12555 8.57207 2.12171 8.52599 2.12186Z" />
</svg>
);
}
Using with NumberField#
A NumberFieldInput in a Toolbar is an item of the toolbar, as a ToolbarInput.
<?phem
use Phem\Attribute\Component;
use Phem\Node;
use Phem\Ui\{NumberField, Toolbar};
use function Phem\Ui\{NumberFieldDecrement, NumberFieldGroup, NumberFieldIncrement, NumberFieldInput, ToolbarButton};
#[Component]
function ToolbarNumberFieldDemo(): Node
{
return (
<Toolbar aria-label="Zoom">
<ToolbarButton>Fit</ToolbarButton>
<NumberField id="zoom" defaultValue={{ 100 }} min={{ 10 }} max={{ 400 }} step={{ 10 }}>
<NumberFieldGroup>
<NumberFieldDecrement />
<NumberFieldInput aria-label="Zoom" />
<NumberFieldIncrement />
</NumberFieldGroup>
</NumberField>
</Toolbar>
);
}
API reference#
Import the components of the family:
use Phem\Ui\Toolbar;
use function Phem\Ui\{ToolbarButton, ToolbarLink, ToolbarInput, ToolbarGroup, ToolbarSeparator};Toolbar#
A row of controls with one tab stop: Base UI Toolbar.Root, on the phem-toolbar controller. The arrow keys move the focus between the items. A Toggle, a ToggleGroup and a Select trigger in it are items and groups of the toolbar.
| Prop | Type | Default |
|---|---|---|
orientation | 'horizontal' | 'vertical' | Orientation::Horizontal |
loopFocus | bool | true |
disabled | bool | false |
children | ?Html | null |
...attrs | array | [] |
ToolbarSeparator#
A line between two groups of items of the toolbar.
| Prop | Type | Default |
|---|---|---|
...rest | mixed | — |
ToolbarButton#
A button of the toolbar. With disabled, it stays in the focus order (aria-disabled).
| Prop | Type | Default |
|---|---|---|
disabled | bool | false |
children | ?Html | null |
...rest | mixed | — |
ToolbarLink#
A link in the toolbar. The arrow keys move the focus to it, as to the other items.
| Prop | Type | Default |
|---|---|---|
href (required) | string | — |
children | ?Html | null |
...rest | mixed | — |
ToolbarInput#
A text field of the toolbar. The arrow keys move the caret until it is at an edge of the text.
| Prop | Type | Default |
|---|---|---|
...rest | mixed | — |
ToolbarGroup#
A group of items. Give it an aria-label.
| Prop | Type | Default |
|---|---|---|
disabled | bool | false |
children | ?Html | null |
...rest | mixed | — |
The source of the examples: examples/ui/Toolbar.phem.