---
title: Your own components
description: Put your own React, Vue, Svelte or Angular components in the viewer's toolbars, panels and header, with your styles, your app's state, and the viewer's commands.
---
{/* Generated from docs/content — edit there, then `pnpm docs:sync`. */}
# Your own components
Put your own component in a toolbar, in a panel, or above and below the viewer. It stays a component
of your app: your framework renders it, your CSS styles it, and it reads your app's state as it always
does. The viewer only decides where it goes.
Two steps: make room for it in the [layout](layout), then give the viewer the component. This one
puts a version picker from your app in the toolbar:
`{ custom: 'versions' }` makes room in the toolbar, and the id ties it to your component. The
toolbar measures your component like any button, so it fits it in, and when the toolbar runs out of
room, `command` takes its place in the "More" menu: here, a command of yours that opens the same
choice in a dialog. Leave `command` out, and your component stays in the toolbar while other items
make room. Without a component for it, the place shows its `command` as a button, so one layout
works with and without your component.
Here a review status from your app sits at the end of the toolbar, with `{ custom: 'status' }` and
no `command`:
> **Try it:** pick **Approved** from the status at the top right of the toolbar: the dot beside it
> turns green.
## Know where it sits
The same component can sit in a top bar, a vertical rail or a floating bar. `useToolbarItem()` tells
it where it is, so it can lay itself out:
| Field | What it is |
| :-- | :-- |
| `orientation` | `'horizontal'` or `'vertical'` |
| `edge` | The bar's place: `'top'`, `'bottom'`, `'start'`, `'end'`, `'float'` or `'selection'` |
| `variant` | Which of your `variants` the toolbar picked, when you gave some |
| `size` | The viewer's [size](small-screens): `'compact'`, `'medium'` or `'expanded'` |
The same values are on your element as `data-orientation`, `data-edge`, `data-variant` and
`data-size`, for CSS.
To have the toolbar pick a smaller form when it's short of room, list your forms, largest first:
`{ custom: 'versions', variants: ['full', 'short'], command: 'acme:versions' }`. Draw the one
`variant` names.
To have your component take the room its bar has left, as a search field or a title does, add
`grow: true`: `{ custom: 'title', grow: true }`. The toolbar fits it in at its own width, like any
item, and then gives it the rest of the bar. Draw your component at `width: 100%` to fill it.
## Look like the viewer
`Button`, `Menu`, `MenuItem` and `Icon` are the viewer's own, for your components. A menu made
with them opens the way the viewer's menus do: away from its bar, flipped when there's no room, and
up from the bottom on a phone.
| Component | What it is |
| :-- | :-- |
| `Button` | A toolbar button. `command="zoom:in"` makes it that command, with its icon, tooltip and state; or give it `icon`, `label` and a click handler. `active` shows it pressed. |
| `Menu` | A button that opens a menu: `icon`, `label`, and `MenuItem`s inside |
| `MenuItem` | A row in a menu: `icon`, its text, and what happens when it's picked. `command="…"` makes it a command. `active` shows it checked. |
| `Icon` | One of the viewer's icons, or yours, by `name`: `size` pixels square (`20`, a toolbar button's, unless you say), in the color of the text around it. With a `label`, screen readers read it; without one, they skip it. |
`active` is for a button of your own that turns something on and off: it shows pressed while it's
on, as the viewer's own do, and screen readers hear it pressed (checked, in a menu). A command's
button and row show their command's `active` already.
Icons are the viewer's icons and [yours](commands#icons), by name. For anything else, the viewer's
colors are CSS variables your styles can use: `var(--epdf-surface)`, `var(--epdf-text)`,
`var(--epdf-border)`, `var(--epdf-accent)`. See [Theming](theming#in-your-own-components).
## Use the viewer's commands and state
`useCommand(id)` gives you a command as a button needs it: its `label`, `icon` and `shortcutLabel`,
whether it's `enabled`, `active` and `visible`, and `run()`. It's always there: an id the viewer
doesn't have is neither visible nor enabled. And every hook from the [headless
docs](/docs/headless) works inside the viewer, so your component reads the viewer's state the same
way a headless app does:
`useStageState()` is the [Stage](/docs/headless/viewing/stage#state) plugin's state, from the
headless adapter for your framework. Install it next to the viewer (`@embedpdf/react`,
`@embedpdf/vue`, `@embedpdf/svelte` or `@embedpdf/angular`) and use any of its hooks: the search
results, the selected annotation, the form values.
## A panel of your own
Add the panel to the layout with a side, a title and an icon, then give the viewer what goes inside:
Every panel gets a `panel:` command that opens and closes it, so `panel:notes` is the toolbar
button. The viewer draws the panel's frame: the header with its title and close button, and the way
it opens, beside the pages on a wide screen and up from the bottom on a phone. You draw what's
inside. See [Panels](panels).
## Above, below, and when nothing is open
Regions are places around the viewer for your own components:
| Region | Where it is |
| :-- | :-- |
| `header` | Above everything, across the whole viewer |
| `footer` | Below everything |
| `tabs` | In place of the document tabs, for your own |
| `empty` | Over the pages while no document is open |
A region you don't fill shows nothing, or the viewer's own (the tabs). A region the layout hides,
such as the tabs with `tabs('never')`, hides your component for it too.
## In the menu over selected text
To add an action to the bar that appears over selected text, such as "Explain this", make it a
command and add it there:
```js
{
commands: [
{
id: 'acme:explain',
label: 'Explain',
icon: 'message',
run: async ({ get }) => openAssistant(await get('selection').readText()),
},
],
layout: (layout) => layout.add('acme:explain', { to: 'selection' }),
}
```
The bar over selected annotations is `annotation`. See [Menus](menus#over-a-selection).
## Good to know
### Your styles apply, the viewer's don't
Your component lives in your page, not inside the viewer's shadow DOM. Your CSS styles it, and
the viewer's CSS never touches it. It does inherit the viewer's font and text color and its CSS
variables, so text fits in without any styling. Form controls are the exception: browsers give
`