ToolPicker
function ToolPicker(props: ToolPickerProps): ReactElement
A PencilKit-style tool palette: undo and redo, drawn instruments that rise when selected, a ruler toggle, colour swatches, and a rainbow button for any colour. Tapping the selected ink instrument or eraser opens a card above the bar with its widths and eraser modes. Each instrument remembers its own colour and width while another one is active. See the Tool picker guide.
<ToolPicker
tool={tool}
onToolChange={setTool}
drawing={drawing}
items={['undo', 'redo', 'pen', 'eraser', 'swatches']}
layout={{ position: 'absolute', bottom: 24, alignSelf: 'center' }}
/>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
tool | Tool | Required | The active tool, usually also passed to SketchCanvas's tool. |
onToolChange | (tool: Tool) => void | Required | Called with the tool the user picks. Store it and pass it back as tool. |
items | readonly ToolPickerItem[] | defaultToolPickerItems | Controls to show, in bar order. Without 'colorPicker', the swatches stay in the bar at every density. |
drawing | Drawing | The drawing undo and redo act on. Without it they are hidden. | |
rulerActive | boolean | false | Whether the canvas shows its ruler. |
onRulerActiveChange | (rulerActive: boolean) => void | Called when the ruler item is tapped. Without it the ruler item is hidden. | |
colors | readonly number[] | defaultPaletteColors | Swatch colours as 0xRRGGBBAA, in two rows in the bar, or in the colour card. |
density | ToolPickerDensity | By window width | 'compact' below 500 points, 'comfortable' otherwise. |
widths | InstrumentWidths | defaultInstrumentWidths | Widths offered in the options card. |
labels | ToolPickerLabels | defaultToolPickerLabels | Eraser mode titles. |
theme | ToolPickerTheme | light or dark preset | Colours and shape; follows the system colour scheme by default. |
accessory | ReactNode | Extra content at the end of the bar, such as a ToolPickerButton. Scrolls with the controls. | |
layout | NitroUI layout | Layout of the picker: a column holding the options card, when open, above the bar. | |
ref | Ref<ToolPickerHandle> | Receives a handle to close the options card. |
ToolPickerHandle
interface ToolPickerHandle {
dismissOptions(): void
}
dismissOptions() closes the options card (widths, eraser modes or colours) when it is open. Call it from SketchCanvas's onTouchDown.
ToolPickerItem
type ToolPickerItem = Instrument | 'ruler' | 'undo' | 'redo' | 'swatches' | 'colorPicker'
type Instrument =
| 'pen'
| 'marker'
| 'pencil'
| 'monoline'
| 'fountainPen'
| 'watercolor'
| 'crayon'
| 'eraser'
| 'lasso'
defaultToolPickerItems, in bar order:
;[
'undo',
'redo',
'pen',
'monoline',
'fountainPen',
'marker',
'pencil',
'crayon',
'watercolor',
'eraser',
'lasso',
'ruler',
'swatches',
'colorPicker',
]
ToolPickerDensity
type ToolPickerDensity = 'compact' | 'comfortable' | 'spacious'
| Density | Bar height | Swatch | Button | Swatches in bar |
|---|---|---|---|---|
compact | 64 | 26 | 28 | ❌ |
comfortable | 80 | 30 | 32 | ✅ |
spacious | 96 | 34 | 36 | ✅ |
Sizes are in points.
InstrumentWidths
Stroke widths in content points for each ink and the pixel eraser, thinnest first. defaultInstrumentWidths:
| Field | Default widths |
|---|---|
pen | 1, 2, 4, 7, 12 |
marker | 8, 14, 20, 28, 36 |
pencil | 1, 2, 3, 5, 8 |
monoline | 1, 2, 3, 5, 8 |
fountainPen | 2, 4, 6, 9, 14 |
watercolor | 10, 18, 28, 40, 56 |
crayon | 4, 7, 10, 15, 22 |
eraser | 8, 16, 28, 44, 64 |
ToolPickerLabels
| Field | Default | Description |
|---|---|---|
strokeEraser | 'Object' | Eraser mode that removes whole strokes. |
pixelEraser | 'Pixel' | Eraser mode that removes only the touched parts. |
defaultPaletteColors
const defaultPaletteColors: readonly number[] = [
0x000000ff, 0x007affff, 0x34c759ff, 0xffcc00ff, 0xff3b30ff, 0xaf52deff,
]
Black, blue, green, yellow, red and purple.
ToolPickerTheme
Colours and shape of a ToolPicker and its parts. Start from a preset in toolPickerThemes (light, dark, solidLight, solidDark) and override fields with a spread. See Theming.
| Field | Type | Description |
|---|---|---|
glass | { style: GlassStyle; tint?: ColorValue } | Liquid Glass for the bar and options card on iOS 26 and later. Omit for a solid background everywhere. |
background | ColorValue | Fill of the bar and the options card; with glass, only where glass is unavailable. |
borderColor | ColorValue | Hairline around the bar and the options card. |
borderWidth | number | Hairline width in points. 0 removes it. |
shadows | readonly BoxShadow[] | Shadows of the bar and the options card, front to back. Skipped where the platform has no shadows. |
cornerRadius | number | Corner radius of the bar in points, capped at half its height (a capsule). |
foreground | ColorValue | Glyphs and labels, and the fill of the selected stroke width. |
secondaryForeground | ColorValue | Width numbers printed on the instruments and other quiet text. |
controlBackground | ColorValue | Fill of round buttons and of the segmented control. |
selectedControlBackground | ColorValue | Fill of the selected segment. |
separator | ColorValue | Hairline around colour swatches, so light colours stay visible. |
barrel | ColorValue | Instrument barrel colour. |
barrelShade | ColorValue | Barrel edge colour; the barrel is shaded from this colour to barrel and back. |
eraserCap | ColorValue | Rubber cap of the eraser. |
eraserMark | ColorValue | Mark printed on the eraser. |