import "capsomer/tokens.css";
import "capsomer/generated-file.css";
import { GeneratedFile } from "capsomer/react/generated-file";
Usage
<section class="cap-panel cap-generated">
<header class="cap-panel-head">
<h2>Program PDF</h2>
<p class="cap-panel-desc">Made from the schedule. It can take up to a minute.</p>
</header>
<div class="cap-panel-body">
<div class="cap-generated-body" data-state="ready">
<p class="cap-generated-status" role="status">
<span class="cap-status" data-tone="ok">[ok glyph]Ready</span>
<span class="cap-generated-says">Made <time class="cap-time" datetime="2027-02-19T21:04:00.000Z" data-format="exact">February 19, 2027, 9:04 PM UTC</time>.</span>
</p>
<p class="cap-generated-file"><a href="/program/download" data-link="file" download>Download the PDF</a> <span class="cap-link-meta">PDF, 2.4 MB</span></p>
</div>
</div>
<footer class="cap-panel-foot">
<div class="cap-generated-actions">
<form method="post" class="cap-generated-form">
<input type="hidden" name="intent" value="document-generate">
<button type="submit" class="cap-btn">Regenerate the PDF</button>
</form>
[Publish to the archive]
</div>
</footer>
</section>
// On the server, before a run:
if (!mayStart(row && { status: row.genStatus, startedAt: row.updatedAt }, Date.now())) throw new ValidationError("A file is already being made.");
<GeneratedFile title="Program PDF" description="Made from the schedule. It can take up to a minute."
record={{ status: doc.genStatus, startedAt: doc.updatedAt, generatedAt: doc.generatedAt, bytes: doc.size, changedAt: program.updatedAt }}
downloadHref={`/admin/editions/${id}/program-document/download`}
fields={{ intent: "document-generate" }} busy={navigation.state === "submitting"}
renderForm={({ className, children }) => <Form method="post" className={className}>{children}</Form>}>
[Publish to the archive]
</GeneratedFile>
Examples
Generating, first run
<div data-mount="generating"></div>
Regenerating, the earlier file kept
<div data-mount="regenerating"></div>
Ready, with its size and date, and a Publish action
<div data-mount="ready"></div>
Stale: the data changed after it was made
<div data-mount="stale"></div>
Failed, with the reason
<div data-mount="failed"></div>
A run that stopped without finishing
<div data-mount="stalled"></div>
The form being sent
<div data-mount="busy"></div>
Made by another step, with no Generate button
<div data-mount="made-elsewhere"></div>
API reference
GeneratedFile
Prop
Type
Required
Does
title
ReactNode
Yes
The panel's heading: "Program PDF".
description
ReactNode
What the file is made from and how long a run takes.
record
GeneratedRecord | null | undefined
Yes
What the store recorded; null when nothing has run.
now
number
A fixed now, for a report or a test.
lockMs
number
How long a run holds the lock (default LOCK_MS, 5 minutes).
format
string
The file's format, said beside the link with its size: "PDF".
downloadHref
string
Yes
downloadLabel
string
generateLabel
string
The button's words before a first run, and after.
regenerateLabel
string
action
string
The form: its action and hidden fields ({ intent: "document-generate" }), or a router's Form drawn by renderForm, which is given the class and the button.
fields
Record<string, string>
renderForm
(props: GeneratedFileFormProps) => ReactNode
generate
boolean
false: no Generate form, for a file another step makes (a book PDF made on publish); the panel then only says the state and offers the file.
busy
boolean
The form is being sent: the button says so and takes no second press.
messages
Partial<Record<GeneratedState, ReactNode>>
The sentence after a state's word, in the app's own words, in place of the default.
level
2 | 3
children
ReactNode
More of the file's actions, after Generate: Publish to the archive.