Sidebars
A sidebar holds panels. Each panel shows content you give it: a list of page thumbnails, search results, the cards of a plugin’s records, or markup of your own. Inkbar places nothing for you. Put a sidebar on either side of the viewport with your own flex or grid layout.
A sidebar of panels
Section titled “A sidebar of panels”Each panel has an id, a label (a string, or a function that returns one, see Translations), an optional icon (an IconNode from @inkbar/icons) and an optional badge, a number or short string that stays hidden when it is empty or 0.
<script setup lang="ts">import { MessageSquare, Square } from '@inkbar/icons'import { InkPanel, InkRoot, InkSidebar, InkThumbnails, InkViewport } from '@inkbar/vue'import { assets } from 'virtual:inkbar-assets'import { ref } from 'vue'
import MyNotes from './MyNotes.vue'
defineProps<{ file: File }>()
const open = ref<string | null>('pages')const noteCount = ref(3)</script>
<template> <InkRoot :src="file" :assets="assets"> <div class="app"> <InkSidebar side="left" layout="rail" v-model:open="open"> <InkPanel id="pages" label="Pages" :icon="Square"> <InkThumbnails /> </InkPanel> <InkPanel id="notes" label="Notes" :icon="MessageSquare" :badge="noteCount"> <MyNotes /> </InkPanel> </InkSidebar> <InkViewport /> </div> </InkRoot></template>import { MessageSquare, Square } from '@inkbar/icons'import { InkPanel, InkRoot, InkSidebar, InkThumbnails, InkViewport } from '@inkbar/react'import { assets } from 'virtual:inkbar-assets'import { useState } from 'react'
import { MyNotes } from './MyNotes'
export function Viewer({ file }: { file: File }) { const [open, setOpen] = useState<string | null>('pages') const noteCount = 3
return ( <InkRoot src={file} assets={assets}> <div className="app"> <InkSidebar side="left" layout="rail" open={open} onOpenChange={setOpen}> <InkPanel id="pages" label="Pages" icon={Square}> <InkThumbnails /> </InkPanel> <InkPanel id="notes" label="Notes" icon={MessageSquare} badge={noteCount}> <MyNotes /> </InkPanel> </InkSidebar> <InkViewport /> </div> </InkRoot> )}<script lang="ts"> import { MessageSquare, Square } from '@inkbar/icons' import { InkPanel, InkRoot, InkSidebar, InkThumbnails, InkViewport, } from '@inkbar/svelte' import { assets } from 'virtual:inkbar-assets'
import MyNotes from './MyNotes.svelte'
let { file }: { file: File } = $props()
let open = $state<string | null>('pages') const noteCount = 3</script>
<InkRoot src={file} {assets}> <div class="app"> <InkSidebar side="left" layout="rail" bind:open> <InkPanel id="pages" label="Pages" icon={Square}> <InkThumbnails /> </InkPanel> <InkPanel id="notes" label="Notes" icon={MessageSquare} badge={noteCount}> <MyNotes /> </InkPanel> </InkSidebar> <InkViewport /> </div></InkRoot>import { createSidebar, createThumbnails, createViewer } from '@inkbar/core/dom'import { MessageSquare, Square } from '@inkbar/icons'import { assets } from 'virtual:inkbar-assets'
const viewer = createViewer(el, { source: file, assets })
const { element, controller } = createSidebar({ layout: 'rail', side: 'left', panels: [ { id: 'pages', label: 'Pages', icon: Square }, { id: 'notes', label: 'Notes', icon: MessageSquare, badge: 3 }, ], content: { pages: createThumbnails(viewer), notes: notesElement }, onOpenChange: (open) => console.log(open),})shell.prepend(element)createSidebar needs no viewer, so it works anywhere you can append an element. Call controller.destroy() when you remove the sidebar.
In the framework packages, panels take their place in the order they appear in your markup, including one added later with a conditional. The sidebar needs no document and works outside InkRoot. During server rendering it draws its frame with the open panel showing. Rail and tab buttons appear once it has mounted.
Layouts
Section titled “Layouts”layout is one of three:
rail(the default) is a strip of icon buttons on the inner edge, beside the document, with each label as a tooltip. One panel is open at a time, with its label as a title above its content, and pressing the open panel’s button closes it, leaving only the rail.tabsshows labelled tabs across the top with one panel open.stackshows every panel as a section with a header button, one under another. Any number can be expanded.
side is left by default and decides which edge the rail and the border sit on. You can change layout at any time, and each panel keeps its content when you do.
A closed panel stays in the page, hidden. Its content keeps its state and scroll position, so a half-typed note is still there when the panel opens again.
Showing and hiding
Section titled “Showing and hiding”visible (default true) shows or hides the whole sidebar, rail and all. A hidden sidebar keeps its open panel, content and scroll for when it shows again. Your code decides when. A results sidebar can stay out of the way until a search finds something:
<script setup lang="ts">import { InkPanel, InkSearchResults, InkSidebar, useSearch } from '@inkbar/vue'import { Search } from '@inkbar/icons'import { computed } from 'vue'
const { state } = useSearch()const hasResults = computed(() => state.value.hits.length > 0)</script>
<template> <InkSidebar side="right" :visible="hasResults"> <InkPanel id="results" label="Search results" :icon="Search"> <InkSearchResults :field="false" /> </InkPanel> </InkSidebar></template>function ResultsSidebar() { const hasResults = useSearch().state.hits.length > 0 return ( <InkSidebar side="right" visible={hasResults}> <InkPanel id="results" label="Search results" icon={Search}> <InkSearchResults field={false} /> </InkPanel> </InkSidebar> )}<script lang="ts"> import { InkPanel, InkSearchResults, InkSidebar, useSearch } from '@inkbar/svelte' import { Search } from '@inkbar/icons'
const search = useSearch() const hasResults = $derived(search.state.hits.length > 0)</script>
<InkSidebar side="right" visible={hasResults}> <InkPanel id="results" label="Search results" icon={Search}> <InkSearchResults field={false} /> </InkPanel></InkSidebar>const hasResults = () => viewer.search.state.get().hits.length > 0const results = createSidebar({ side: 'right', visible: hasResults(), panels: [{ id: 'results', label: 'Search results', icon: Search }], content: { results: createSearchResults(viewer, { field: false }) },})viewer.search.state.subscribe(() => results.controller.update({ visible: hasResults() }))useSearch needs InkRoot, so in the framework packages the sidebar goes in a component of its own inside the root.
Open and closed
Section titled “Open and closed”open is the id of the open panel (or null) for rail and tabs, and the list of expanded ids for stack. Left out, the sidebar starts with its first panel open and keeps its own state. Pass null to collapse a tabs sidebar, from a toolbar button of your own for instance.
Pass it and you control the sidebar: a click reports the new value and nothing changes until you set it. The prop to use is v-model:open in Vue, open with onOpenChange in React (or defaultOpen to set only where it starts), bind:open in Svelte, and open with onOpenChange and controller.update({ open }) in plain DOM. When the open panel goes away, rail and tabs open the first one left and stack drops it, and you get the new value the same way.
Keyboard
Section titled “Keyboard”Rail and tabs follow the tabs pattern. The sidebar is one Tab stop. On a rail the Up and Down arrows move between buttons, and in tabs the Left and Right arrows do. Home and End go to the first and last, and Enter or Space opens a panel.
Stack headers follow the accordion pattern. Each header is its own Tab stop with aria-expanded. Up and Down move between headers, and Enter or Space expands or collapses a section.
Every sidebar has a resize handle on its inner edge, beside the document. Drag it with a mouse, pen or finger. From the keyboard, Tab to it and use Left and Right to move it 16px at a time, Home for the narrowest and End for the widest. The arrows follow the edge, so on a right-hand sidebar Left makes it wider. Enter or a double-click puts the default width back. The handle hides while no panel is open. Screen readers hear it as “Resize left sidebar” or “Resize right sidebar”; pass handleLabel (handle-label in Vue) to name it yourself. Like a panel’s label, it takes a string or a function.
A sidebar starts 320px wide and stays between 240px and 480px. Change the numbers with defaultWidth, minWidth and maxWidth.
When there’s no room
Section titled “When there’s no room”Sidebars that share a parent element make room for the document together. While they sit beside it, the document keeps at least 480px. When it would get narrower, because the window shrank, a sidebar opened or someone dragged a handle, a rail sidebar’s panel floats over the pages instead, like a drawer. Its rail stays in place, so the buttons that close and reopen the panel never move. When there’s room again, the panel goes back beside the document.
With two rail sidebars open, the one being resized floats first, then the one opened most recently. Tabs and stack sidebars never float: they narrow toward minWidth so the document keeps its room. Floating never changes the width: the saved width, and the one you hear about, stay the width the reader chose.
A floating panel closes the way a drawer does:
- A tap or click on the pages closes it, and does nothing else. No tool draws, no link opens and no field takes focus.
Escapecloses it, unless a menu, popover or editor has used the key first.- Opening the find bar closes it, so the panel never hides the bar.
A scroll, swipe or pinch on the pages leaves it open. When it closes, focus goes back to the rail button, unless the reader was typing somewhere else. A controlled sidebar only reports the close; it stays open until you set open.
A sidebar with no room when it first mounts starts with its panel closed, so a phone doesn’t open every document under a drawer. That only applies when you haven’t set open or defaultOpen. On the server, sidebars render beside the document; floating and starting closed are decided in the browser.
Set the document’s minimum width with minDocumentWidth, in CSS pixels. Pass it to the root for every sidebar inside it, or to one sidebar, whose own wins:
<InkRoot :src="src" :assets="assets" :min-document-width="600"><InkRoot src={src} assets={assets} minDocumentWidth={600}><InkRoot {src} {assets} minDocumentWidth={600}>const { element, controller } = createSidebar({ minDocumentWidth: 600, panels, content })The sidebar reads it once, when it is created.
Keeping the width
Section titled “Keeping the width”Inside the root, a sidebar saves its width in the root’s storage under sidebar.<name>.width, so it comes back on the next visit when the store keeps it. name defaults to the side, so give two sidebars on one side different names. A sidebar outside the root, or one that should use another store, takes its own storage. The sidebar reads storage and name once, when it is created.
Controlling the width
Section titled “Controlling the width”To hold the width yourself, bind it the way you bind open: v-model:width in Vue, width with onWidthChange in React, bind:width in Svelte, and width with onWidthChange and controller.update({ width }) in plain DOM. The handle then only reports the new width, and the sidebar neither reads nor saves it.
<InkSidebar name="tools" side="right" :default-width="360" v-model:width="toolsWidth"><InkSidebar name="tools" side="right" defaultWidth={360} width={toolsWidth} onWidthChange={setToolsWidth}><InkSidebar name="tools" side="right" defaultWidth={360} bind:width={toolsWidth}>const { element, controller } = createSidebar({ side: 'right', name: 'tools', storage, defaultWidth: 360, panels, content,})In Vue and React, a width that starts undefined takes control after the first drag and stops saving. Svelte can’t tell an unbound width from one bound to undefined, so there the sidebar keeps saving until you bind a number.
During server rendering the sidebar draws at its default width with the handle in place. A saved width applies once it mounts.
In CSS
Section titled “In CSS”The sidebar sets --ink-sidebar-width on itself, so a CSS override of that variable no longer changes it. Pass defaultWidth instead. The rail’s width is still yours to set in CSS with --ink-sidebar-rail-width (48px by default). While someone drags the handle, the sidebar has data-resizing. A floating sidebar has data-overlay: @inkbar/theme gives its panel a shadow and puts it above the pages, below menus, popovers and dialogs. Restyle it with .ink-sidebar[data-overlay] .ink-sidebar-panels.
Lists of records
Section titled “Lists of records”InkRecordList (createRecordList in plain DOM) lists a plugin’s records as cards. They are the cards the records’ marks open, with the same actions. Name the records <plugin>.<name>, as Writing a plugin names them. The list fills its parent’s height and scrolls, so put it in a panel.
<InkPanel id="suggestions" label="Suggestions" :icon="MessageSquare" :badge="count"> <InkRecordList records="review.suggestions" @update:count="count = $event"> <template #empty>No suggestions left.</template> </InkRecordList></InkPanel><InkPanel id="suggestions" label="Suggestions" icon={MessageSquare} badge={count}> <InkRecordList records="review.suggestions" onCountChange={setCount} empty="No suggestions left." /></InkPanel><script lang="ts"> let count = $state(0)</script>
<InkPanel id="suggestions" label="Suggestions" icon={MessageSquare} badge={count}> <InkRecordList records="review.suggestions" bind:count> {#snippet empty()}No suggestions left.{/snippet} </InkRecordList></InkPanel>import { createRecordList } from '@inkbar/core/dom'
panel.append(createRecordList(viewer, { records: 'review.suggestions' }))Each record takes its card from the first plugin.marks call over those records whose where it passes, and the list shows only the records that pass one. When no marks call exists for those records, every record is listed, titled with its id and with no actions. A mark with no card titles its record with the mark’s label. To choose for yourself, pass where, card or sort. Actions on a card you pass run in one undo step too. The default order is by page, then top to bottom and left to right by the mark’s box.
A new function rebuilds the list, so define card, where and sort once, outside the template or component. In React, wrap them in useCallback.
Selection
Section titled “Selection”The list and the marks share one selection for each set of records, so every list over the same records agrees with the marks.
- Clicking a card, or pressing Enter on it, selects the record, marks its mark with
data-selectedand scrolls the viewer to it. Focus stays in the list and no popover opens. - Activating a mark selects its card and scrolls every list over those records to it, without moving the page. A list in a closed panel scrolls when it shows.
- Escape in the list clears the selection. So does removing the record or undoing it away.
The list is one Tab stop. Arrow keys move between cards, and Home and End go to the first and last. When the focused card goes, after an action or an undo for instance, focus moves to the next card, then the previous one, then the list. A polite live region says “3 items” when an action or your app adds or removes cards. It stays quiet on undo and redo. An empty list reads “Nothing here yet.”
The count is ready for a panel badge: @update:count in Vue, onCountChange in React and bind:count in Svelte.
Search results
Section titled “Search results”InkSearchResults (createSearchResults in plain DOM) is the same list over the viewer’s search: one card for each match, titled with its page (“Page 2”), with its place on the page (“Match 3”) and the text around it. Choosing a card makes its match the current one, as next and previous in the find bar do.
It has its own field, labelled “Find in document”, above the cards, and the find bar’s match count in a footer below them. Before a search it reads “Search to list every match.” The field and the find bar share one search state, so they never disagree. When a find bar is on the page, leave the field out: :field="false" in Vue, field={false} in React and Svelte, { field: false } in plain DOM. Unlike other lists, Escape in the results does not clear the current match.
Your own list
Section titled “Your own list”To read and write a plugin’s records from your own component, use useRecords<T>(name). It returns the live records and a handle to read and write them, and each write is one undo step. useRecordSelection(name) returns selected and select(id | null). select does nothing for an id that has no mark. Both need InkRoot. Plugins are set up once the root has mounted, so until then handle is null, records is empty and nothing is selected.
What the values look like depends on the framework. In Vue, records, handle and selected are refs. In React they are plain values. In Svelte the hooks return an object with getters, so keep the object and read suggestions.records or selection.selected. Destructuring a Svelte hook loses reactivity.
In plain DOM, viewer.records<T>(key) gives the same handle for a key such as review.suggestions. Its list emits as the records change.
const suggestions = viewer.records<Suggestion>('review.suggestions')suggestions.list.subscribe((items) => render(items))suggestions.batch(() => { suggestions.update('s1', { status: 'accepted' }) suggestions.remove('s2')})To list something that is not a record set, build a source with recordsSource or searchSource from @inkbar/core/dom, or write one of your own. In the framework packages, pass it as source in place of records; in plain DOM use createRecordListController(source). It gets the same cards, keys and selection. card, where and sort do not apply to a source. With both source and records given, source wins and a development build warns.
To render your own cards, pass a source to createRecordListController(source). Its rows give each item, its card and whether it is selected, and count and announcement give the count and the live-region text. Render each row as an element with data-ink-record set to the item’s id, call attach(element) on the element holding them, and call act(id, label) from each action button. choose(id) selects and reveals an item from code. Call destroy() when you are done.
Theming
Section titled “Theming”@inkbar/theme styles the list with .ink-records, .ink-record-list, .ink-record and .ink-record-list-empty. The selected card has aria-current="true", so style that to change how selection looks. The cards use the same .ink-card-* classes as the cards that marks open.