Tool rail
A board's tools in one vertical rail: pick one, and its name and key show on hover. Free and MIT licensed, as HTML, a typed React component or an Astro component, in three styles with light and dark mode.
Need this designed into your product? Book a call
Install
Add it to your project with the CLI.
HTML, CSS and JS
npx designme add tool-railReact
npx designme add tool-rail --reactAstro
npx designme add tool-rail --astroshadcn, React
npx shadcn@latest add https://designme.dev/r/shadcn/tool-rail.json shadcn, Astro
npx shadcn@latest add https://designme.dev/r/shadcn/astro/tool-rail.json The CLI copies the source into your project, so you own it and can change anything. Where each version lands, what it needs and the shadcn theme bridge: Installation.
About
What it is for and what it does.
Tool rail is the vertical rail of tools from the Whiteboard template: Select and Pan, then Sticky note, Pen, Eraser, Shape, Connector and Text, then Comment, in three groups split by short lines. One tool is picked at a time. The picked tool sits on a soft accent tint (in Studio, its neutral selected fill), and each tool shows its name and its letter in a tooltip on hover.
- When a board, a canvas or a drawing surface needs its tools within reach at the edge of the screen.
- When people switch tools often and should always see which one is on.
- When the tools fall into a few groups (moving round, making things, talking about them) that a line can split.
- Not for actions that happen at once, like undo or zoom: Zoom bar holds those.
- The nine tools are one radio group: a click picks a tool and unpicks the one before. The rail only shows the pick; what each tool does on your board is yours to wire up.
- Each tool's tooltip shows its name and letter: V Select, H Pan, S Sticky note, P Pen, E Eraser, R Shape, A Connector, T Text, C Comment.
- While the focus is in the rail, the arrow keys move the pick up and down it (wrapping at the ends) and a tool's letter picks that tool. The rail listens to no keys outside it.
- Hover is the quiet row fill in the button's own shape, and a press shows at once as a deeper fill, with no scale.
- The rail is Canvas toolbar's bar stood on its end: the same 32px buttons, the same raised pill with its shadow, square in Blueprint and plush squircles in Soft.
- In React,
ToolRailtakesvalueordefaultValueand callsonChangewith the tool's id (select,hand,sticky,pen,eraser,shape,arrow,textorcomment).
- The rail is a
toolbarwitharia-orientation="vertical", and the tools are aradiogroupofradiobuttons, each witharia-checkedand anaria-label. - Only the picked tool is in the tab order; the arrow keys reach the others, the way a radio group works.
- The dividers are
aria-hidden, so a screen reader hears only the tools.
Usage
Import it in React and drive it from your own state, or place it in an Astro page.
React
import { ToolRail } from '@/components/designme/tool-rail/ToolRail';React example
The demo above as a React component, 18 lines you can copy.
'use client';
// The animated preview from designme.dev, rebuilt from the React component: an example of driving it from your own state.
import { useRef, useState } from 'react';
import { ToolRail, type ToolRailTool } from './ToolRail';
import { Demo } from '../lib/Demo';
import { useStory } from '../lib/useScript';
/* ---------- Tool rail: try the pen, a sticky note and a comment, then back to Select ---------- */
export default function ToolRailDemo() {
const ref = useRef<HTMLDivElement>(null);
const [tool, setTool] = useState<ToolRailTool>('select');
useStory(ref, async ({ wait, press }) => {
await wait(1000);
for (const t of ['pen', 'sticky', 'comment', 'select']) { await wait(2000); press(`.dm-tlr-b[data-t="${t}"]`); }
});
return <Demo ref={ref} switcher={null}><ToolRail value={tool} onChange={setTool} /></Demo>;
}
Astro
In a page in src/pages. It plays the demo above; change its tool-rail.js to show your own data. Attributes like class go on its root element.
---
import ToolRail from '../components/designme/tool-rail/ToolRail.astro';
---
<ToolRail />
<ToolRail data-style="soft" class="my-class" />Props
Everything ToolRail takes.
| Prop | Type | What it does |
|---|---|---|
value | ToolRailTool | The picked tool, when you keep it in your state |
defaultValue | ToolRailTool | The tool picked at first, when the rail keeps it. Defaults to 'select' |
onChange | (tool: ToolRailTool) => void | Called with the tool a click, an arrow key or a tool's letter picks |
className | string |
Code
The full source, as the CLI installs it.
ToolRail.tsxReact · 67 lines
'use client';
import { Fragment, useRef, type KeyboardEvent as ReactKeyboardEvent } from 'react';
import { cx } from '../lib/cx';
import { useControllable } from '../lib/hooks';
import { Icon, type IconName } from '../lib/icons';
import { Tip } from '../lib/motion';
import '../designme.css';
import './tool-rail.css';
/** A tool on the rail, by its id */
export type ToolRailTool = 'select' | 'hand' | 'sticky' | 'pen' | 'eraser' | 'shape' | 'arrow' | 'text' | 'comment';
// the Whiteboard's tools in their three groups: moving round, making things, talking about them
const GROUPS: { t: ToolRailTool; icon: IconName; name: string; key: string }[][] = [
[{ t: 'select', icon: 'cursor', name: 'Select', key: 'V' }, { t: 'hand', icon: 'hand', name: 'Pan', key: 'H' }],
[{ t: 'sticky', icon: 'sticky', name: 'Sticky note', key: 'S' }, { t: 'pen', icon: 'pen', name: 'Pen', key: 'P' }, { t: 'eraser', icon: 'eraser', name: 'Eraser', key: 'E' },
{ t: 'shape', icon: 'shape', name: 'Shape', key: 'R' }, { t: 'arrow', icon: 'connector', name: 'Connector', key: 'A' }, { t: 'text', icon: 'text', name: 'Text', key: 'T' }],
[{ t: 'comment', icon: 'comment', name: 'Comment', key: 'C' }]
];
const ALL = GROUPS.flat();
export interface ToolRailProps {
/** The picked tool, when you keep it in your state */
value?: ToolRailTool;
/** The tool picked at first, when the rail keeps it. Defaults to 'select' */
defaultValue?: ToolRailTool;
/** Called with the tool a click, an arrow key or a tool's letter picks */
onChange?: (tool: ToolRailTool) => void;
className?: string;
}
/** A board's tools in one vertical rail, one picked at a time, from the Whiteboard template. The arrows and each tool's
letter pick a tool while the focus is in the rail */
export function ToolRail({ value, defaultValue = 'select', onChange, className }: ToolRailProps) {
const [tool, setTool] = useControllable(value, defaultValue, onChange);
const bar = useRef<HTMLDivElement>(null);
const pick = (t: ToolRailTool) => {
setTool(t);
bar.current?.querySelector<HTMLButtonElement>(`[data-t="${t}"]`)?.focus();
};
const onKey = (e: ReactKeyboardEvent) => {
const d = ({ ArrowDown: 1, ArrowRight: 1, ArrowUp: -1, ArrowLeft: -1 } as Record<string, number>)[e.key];
const at = ALL.findIndex(x => x.t === (document.activeElement as HTMLElement | null)?.dataset.t);
const next = d ? ALL[(at + d + ALL.length) % ALL.length] : !e.metaKey && !e.ctrlKey && !e.altKey ? ALL.find(x => x.key.toLowerCase() === e.key.toLowerCase()) : undefined;
if (!next) return;
e.preventDefault(); pick(next.t);
};
return (
<div className={cx('dm-tlr', className)} data-dm="">
<div ref={bar} className="dm-tlr-bar" role="toolbar" aria-label="Tools" aria-orientation="vertical" onKeyDown={onKey}>
<div className="dm-tlr-tools" role="radiogroup" aria-label="Tool">
{GROUPS.map((g, i) => (
<Fragment key={i}>
{i > 0 && <span className="dm-tlr-sep" aria-hidden="true" />}
{g.map(x => (
<Tip key={x.t} label={x.name} kbd={x.key}>
<button type="button" className="dm-tlr-b dm-mx-press" role="radio" aria-checked={tool === x.t} tabIndex={tool === x.t ? 0 : -1} data-t={x.t} aria-label={x.name} onClick={() => setTool(x.t)}><Icon name={x.icon} /></button>
</Tip>
))}
</Fragment>
))}
</div>
</div>
</div>
);
}
tool-rail.cssReact · 18 lines
/* Generated from designme.dev by scripts/sync.mjs. Edit the site, then sync. */
/* ---------- Tool rail ---------- */
/* the Whiteboard template's tool rail (owner, 27 Nov): Canvas toolbar's bar stood on its end. One tool is picked at a time;
the picked one sits on Canvas toolbar's soft accent tint (Studio: its one neutral selected fill), the others take the quiet
hover. Its buttons do nothing else: what a tool does is the board's */
.dm-tlr{display:flex;justify-content:center}
.dm-tlr-bar{display:inline-flex;flex-direction:column;align-items:center;padding:var(--dm-s-1);border-radius:var(--dm-r-pill);background:var(--dm-raised);box-shadow:var(--dm-shadow-pop)}
.dm-tlr-bar :focus-visible{border-radius:var(--dm-r-pill)}
.dm-tlr-tools{display:flex;flex-direction:column;align-items:center}
.dm-tlr-b{width:32px;height:32px;flex:none;display:grid;place-items:center;border-radius:var(--dm-r-pill);color:var(--dm-fg2);transition:background var(--dm-t-fast),color var(--dm-t-fast)}
@media (hover:hover) and (pointer:fine){.dm-tlr-b:hover{background:var(--dm-row);color:var(--dm-fg)}}
.dm-tlr-b[aria-checked="true"]{background:color-mix(in srgb,var(--dm-accent) 12%,transparent);color:var(--dm-accent-fg)}
@media (hover:hover) and (pointer:fine){.dm-tlr-b[aria-checked="true"]:hover{background:color-mix(in srgb,var(--dm-accent) 12%,transparent);color:var(--dm-accent-fg)}}
.dm-tlr-sep{width:16px;height:1px;margin:var(--dm-s-1) auto;flex:none;background:var(--dm-line)}
/* Studio's picked tool is its one selected fill, neutral, never a hue (as on the Whiteboard) */
:root[data-style="studio"] .dm-tlr-b[aria-checked="true"],:root [data-style="studio"] .dm-tlr-b[aria-checked="true"],:root [data-style="studio"].dm-tlr-b[aria-checked="true"]{background:var(--dm-row-on);color:var(--dm-fg)}
@media (hover:hover) and (pointer:fine){:root[data-style="studio"] .dm-tlr-b[aria-checked="true"]:hover,:root [data-style="studio"] .dm-tlr-b[aria-checked="true"]:hover,:root [data-style="studio"].dm-tlr-b[aria-checked="true"]:hover{background:var(--dm-row-on);color:var(--dm-fg)}}
ToolRail.astroAstro · 40 lines
---
// Generated from designme.dev by scripts/sync.mjs. Edit the site, then sync.
// Tool rail: A board's tools in one vertical rail: pick one, and its name and key show on hover.
// The markup, CSS and script are designme.dev's own, run by the shared core in ../core, which mounts the component when it scrolls
// into view and plays its demo. To show your own data, change tool-rail.js. The markup is kept exactly as it is (is:raw).
import type { HTMLAttributes } from 'astro/types';
import '../core/designme.css';
import './tool-rail.css';
export interface Props extends HTMLAttributes<'div'> {
/** "soft" or "studio" draws it in that style. Leave it out for Blueprint, or for the style set on <html> (data-style="soft" or "studio") */
'data-style'?: 'soft' | 'studio';
}
const { class: className, ...rest } = Astro.props;
---
<div class:list={['card', className]} data-c="tool-rail" {...rest}>
<div class="stage-in"><Fragment is:raw>
<div class="tlr">
<div class="tlr-bar" role="toolbar" aria-label="Tools" aria-orientation="vertical">
<div class="tlr-tools" role="radiogroup" aria-label="Tool">
<button class="tlr-b mx-press" role="radio" aria-checked="true" data-t="select" aria-label="Select" data-tip="Select" data-tip-k="V"><svg class="i s"><use href="#i-cursor"/></svg></button>
<button class="tlr-b mx-press" role="radio" aria-checked="false" tabindex="-1" data-t="hand" aria-label="Pan" data-tip="Pan" data-tip-k="H"><svg class="i s"><use href="#i-hand"/></svg></button>
<span class="tlr-sep" aria-hidden="true"></span>
<button class="tlr-b mx-press" role="radio" aria-checked="false" tabindex="-1" data-t="sticky" aria-label="Sticky note" data-tip="Sticky note" data-tip-k="S"><svg class="i s"><use href="#i-sticky"/></svg></button>
<button class="tlr-b mx-press" role="radio" aria-checked="false" tabindex="-1" data-t="pen" aria-label="Pen" data-tip="Pen" data-tip-k="P"><svg class="i s"><use href="#i-pen"/></svg></button>
<button class="tlr-b mx-press" role="radio" aria-checked="false" tabindex="-1" data-t="eraser" aria-label="Eraser" data-tip="Eraser" data-tip-k="E"><svg class="i s"><use href="#i-eraser"/></svg></button>
<button class="tlr-b mx-press" role="radio" aria-checked="false" tabindex="-1" data-t="shape" aria-label="Shape" data-tip="Shape" data-tip-k="R"><svg class="i s"><use href="#i-shape"/></svg></button>
<button class="tlr-b mx-press" role="radio" aria-checked="false" tabindex="-1" data-t="arrow" aria-label="Connector" data-tip="Connector" data-tip-k="A"><svg class="i s"><use href="#i-connector"/></svg></button>
<button class="tlr-b mx-press" role="radio" aria-checked="false" tabindex="-1" data-t="text" aria-label="Text" data-tip="Text" data-tip-k="T"><svg class="i s"><use href="#i-text"/></svg></button>
<span class="tlr-sep" aria-hidden="true"></span>
<button class="tlr-b mx-press" role="radio" aria-checked="false" tabindex="-1" data-t="comment" aria-label="Comment" data-tip="Comment" data-tip-k="C"><svg class="i s"><use href="#i-comment"/></svg></button>
</div>
</div>
</div>
</Fragment></div>
</div>
<script>
import './tool-rail.js';
</script>
tool-rail.htmlHTML · 22 lines
<div class="card" data-c="tool-rail">
<div class="stage-in">
<div class="tlr">
<div class="tlr-bar" role="toolbar" aria-label="Tools" aria-orientation="vertical">
<div class="tlr-tools" role="radiogroup" aria-label="Tool">
<button class="tlr-b mx-press" role="radio" aria-checked="true" data-t="select" aria-label="Select" data-tip="Select" data-tip-k="V"><svg class="i s"><use href="#i-cursor"/></svg></button>
<button class="tlr-b mx-press" role="radio" aria-checked="false" tabindex="-1" data-t="hand" aria-label="Pan" data-tip="Pan" data-tip-k="H"><svg class="i s"><use href="#i-hand"/></svg></button>
<span class="tlr-sep" aria-hidden="true"></span>
<button class="tlr-b mx-press" role="radio" aria-checked="false" tabindex="-1" data-t="sticky" aria-label="Sticky note" data-tip="Sticky note" data-tip-k="S"><svg class="i s"><use href="#i-sticky"/></svg></button>
<button class="tlr-b mx-press" role="radio" aria-checked="false" tabindex="-1" data-t="pen" aria-label="Pen" data-tip="Pen" data-tip-k="P"><svg class="i s"><use href="#i-pen"/></svg></button>
<button class="tlr-b mx-press" role="radio" aria-checked="false" tabindex="-1" data-t="eraser" aria-label="Eraser" data-tip="Eraser" data-tip-k="E"><svg class="i s"><use href="#i-eraser"/></svg></button>
<button class="tlr-b mx-press" role="radio" aria-checked="false" tabindex="-1" data-t="shape" aria-label="Shape" data-tip="Shape" data-tip-k="R"><svg class="i s"><use href="#i-shape"/></svg></button>
<button class="tlr-b mx-press" role="radio" aria-checked="false" tabindex="-1" data-t="arrow" aria-label="Connector" data-tip="Connector" data-tip-k="A"><svg class="i s"><use href="#i-connector"/></svg></button>
<button class="tlr-b mx-press" role="radio" aria-checked="false" tabindex="-1" data-t="text" aria-label="Text" data-tip="Text" data-tip-k="T"><svg class="i s"><use href="#i-text"/></svg></button>
<span class="tlr-sep" aria-hidden="true"></span>
<button class="tlr-b mx-press" role="radio" aria-checked="false" tabindex="-1" data-t="comment" aria-label="Comment" data-tip="Comment" data-tip-k="C"><svg class="i s"><use href="#i-comment"/></svg></button>
</div>
</div>
</div>
</div>
</div>
tool-rail.cssHTML · 17 lines
/* ---------- Tool rail ---------- */
/* the Whiteboard template's tool rail (owner, 27 Nov): Canvas toolbar's bar stood on its end. One tool is picked at a time;
the picked one sits on Canvas toolbar's soft accent tint (Studio: its one neutral selected fill), the others take the quiet
hover. Its buttons do nothing else: what a tool does is the board's */
.tlr{display:flex;justify-content:center}
.tlr-bar{display:inline-flex;flex-direction:column;align-items:center;padding:var(--dm-s-1);border-radius:var(--dm-r-pill);background:var(--dm-raised);box-shadow:var(--dm-shadow-pop)}
.tlr-bar :focus-visible{border-radius:var(--dm-r-pill)}
.tlr-tools{display:flex;flex-direction:column;align-items:center}
.tlr-b{width:32px;height:32px;flex:none;display:grid;place-items:center;border-radius:var(--dm-r-pill);color:var(--dm-fg2);transition:background var(--dm-t-fast),color var(--dm-t-fast)}
@media (hover:hover) and (pointer:fine){.tlr-b:hover{background:var(--dm-row);color:var(--dm-fg)}}
.tlr-b[aria-checked="true"]{background:color-mix(in srgb,var(--dm-accent) 12%,transparent);color:var(--dm-accent-fg)}
@media (hover:hover) and (pointer:fine){.tlr-b[aria-checked="true"]:hover{background:color-mix(in srgb,var(--dm-accent) 12%,transparent);color:var(--dm-accent-fg)}}
.tlr-sep{width:16px;height:1px;margin:var(--dm-s-1) auto;flex:none;background:var(--dm-line)}
/* Studio's picked tool is its one selected fill, neutral, never a hue (as on the Whiteboard) */
:root[data-style="studio"] .tlr-b[aria-checked="true"],:root [data-style="studio"] .tlr-b[aria-checked="true"],:root [data-style="studio"].tlr-b[aria-checked="true"]{background:var(--dm-row-on);color:var(--dm-fg)}
@media (hover:hover) and (pointer:fine){:root[data-style="studio"] .tlr-b[aria-checked="true"]:hover,:root [data-style="studio"] .tlr-b[aria-checked="true"]:hover,:root [data-style="studio"].tlr-b[aria-checked="true"]:hover{background:var(--dm-row-on);color:var(--dm-fg)}}
tool-rail.jsHTML · 23 lines
DM.def('tool-rail', (r, c) => {
r.innerHTML = r.innerHTML.replace(/\{([\w-]+)\}/g, (m, k) => I(k));
const bs = $$('.tlr-b', r), keys = Object.fromEntries(bs.map(b => [b.dataset.tipK.toLowerCase(), b]));
// one tool at a time, like radio buttons: the picked one is checked and is the one Tab stops on
const pick = b => bs.forEach(x => { const on = x === b; x.setAttribute('aria-checked', String(on)); x.tabIndex = on ? 0 : -1; });
bs.forEach(b => c.on(b, 'click', () => pick(b)));
// the arrows move the pick along the rail, and a tool's letter picks it, while the focus is in the rail
c.on($('.tlr-bar', r), 'keydown', e => {
const d = { ArrowDown:1, ArrowRight:1, ArrowUp:-1, ArrowLeft:-1 }[e.key];
const n = d ? bs[(bs.indexOf(document.activeElement) + d + bs.length) % bs.length] : !e.metaKey && !e.ctrlKey && !e.altKey && keys[e.key.toLowerCase()];
if (!n) return; e.preventDefault(); pick(n); n.focus();
});
// the preview's story: try the pen, a sticky note and a comment, then back to Select
const t = k => $(`.tlr-b[data-t="${k}"]`, r);
c.story(async s => {
await s.beat(2);
await s.point(t('pen')); await s.beat(1.5); await s.tap(t('pen')); await s.beat(2.5);
await s.point(t('sticky')); await s.beat(1.5); await s.tap(t('sticky')); await s.beat(2.5);
await s.tap(t('comment')); await s.beat(2.5);
await s.tap(t('select')); s.away(); await s.beat(2);
});
});
Questions
What people ask about it.
- How do I make the letters work anywhere on my board?
- Listen for the keys on your board and set the tool yourself: in React pass
valueand change it from your handler; in HTML click the tool's button (.tlr-b[data-t="pen"]) from yours. The rail answers its letters only while it has the focus. - Can I lay it out across instead of down?
- The rail is drawn down the side, as on the Whiteboard. For tools across the bottom of a canvas, Canvas toolbar is the horizontal bar.
- Why does Studio show a grey fill on the picked tool?
- Studio keeps its controls monochrome: the picked tool takes its one neutral selected fill, where Soft and Blueprint use the accent tint.
More in Workspace
Navigation, search, settings, models and automations around the agent.