Skip to content

armgit / ui

Public Imported from GitHub
0
TypeScript
3.1 KB
Raw Blame
---
title: Document Splits
description: Organize long PDFs into smaller documents with lazy page thumbnails and drag-and-drop grouping.
component: true
---

Document Splits provide editable split groups for long documents. Pair them with the PDF Viewer block when users need to preview pages while organizing output documents.

See it composed with the PDF Viewer in the [Document Splits block](/blocks#document-splits).

<DocumentSplitsDemo />

## Installation

<CodeTabs>

<TabsList>
  <TabsTrigger value="cli">Command</TabsTrigger>
  <TabsTrigger value="manual">Manual</TabsTrigger>
</TabsList>
<TabsContent value="cli">

```bash
npx shadcn@latest add @extend/document-splits
```

</TabsContent>

<TabsContent value="manual">

<Steps className="mb-0 pt-2">

<Step>Install the following dependencies:</Step>

```bash
npm install @dnd-kit/core@^6.3.1 @dnd-kit/sortable@^10.0.0 @dnd-kit/utilities@^3.2.2
```

<Step>Install the icon library configured in your `components.json`:</Step>

The component source references icons through the shadcn CLI's
`IconPlaceholder`, which supports every `iconLibrary` the CLI does: `lucide`,
`tabler`, `hugeicons`, `phosphor`, and `remixicon`. Installing with the CLI
replaces each placeholder with the matching icon from your configured library,
so make sure that library's package is installed. When copying the source
manually, replace each `IconPlaceholder` element with the icon named by the
prop for your library.

<Step>Copy and paste the following code into your project.</Step>

<DocumentSplitsSource />

<Step>Update the import paths to match your project setup.</Step>

</Steps>

</TabsContent>

</CodeTabs>

## Useful behaviors

- Lazy PDF page thumbnails rendered from the source document.
- Drag pages between split groups and reorder split groups.
- Vertically scrollable split groups with horizontally scrolling page rows.
- Pair with the PDF Viewer block when selected pages should scroll the document canvas.

## API Reference

### DocumentSplits

The DocumentSplits component renders controlled split groups and paints cached page images through FileThumbnail.

| Prop               | Type                                  | Default | Required |
| ------------------ | ------------------------------------- | ------- | -------- |
| `activePage`       | `number`                              | `-`     | Yes      |
| `className`        | `string`                              | `-`     | No       |
| `splits`           | `DocumentSplit[]`                     | `-`     | Yes      |
| `thumbnailImages`  | `Record<DocumentSplitPageId, string>` | `{}`    | No       |
| `withFrameDivider` | `boolean`                             | `true`  | No       |
| `onSelectPage`     | `(pageNumber: number) => void`        | `-`     | Yes      |
| `onSplitsChange`   | `(splits: DocumentSplit[]) => void`   | `-`     | Yes      |

### DocumentSplit

| Prop    | Type                    | Default | Required |
| ------- | ----------------------- | ------- | -------- |
| `id`    | `string`                | `-`     | Yes      |
| `title` | `string`                | `-`     | Yes      |
| `pages` | `DocumentSplitPageId[]` | `-`     | Yes      |