Skip to Content
Grist Widgets

Your first widget

Scaffold a widget, publish it, change it, test it, see it in your own Grist, release it and protect its repository.

The scaffold is a working widget: it shows the selected task of a Grist table and marks it done. This page publishes it, then adds a column to it and releases that. You need Node 22.22.2 or later (or 24.15 or later), pnpm, git with your name and email set (git config --global user.name and user.email: the scaffold commits with them), and a GitHub account. Docker is optional, for one step.

1. Scaffold it

npm create grist-widget my-widget
cd my-widget
pnpm dev

The command writes the widget, installs its dependencies with pnpm, and commits it on main, with a dev branch next to it.

Open http://localhost:5173/demo/index.html: Grist itself, running in your browser, with a document and the widget in it. Your data stays in the browser; the page loads Grist from the network. Stop the server (Ctrl-C) when you're done looking.

2. Publish the first version

Create an empty, public GitHub repository named my-widget, then push main:

git remote add origin https://github.com/<you>/my-widget.git
git push -u origin main

That push runs the widget's deploy workflow, which publishes version 0.0.1: it creates the gh-pages branch, commits the widget's install URL to the README on main, and sets dev to main. Point GitHub Pages at it once: Settings → Pages → Deploy from a branch → gh-pages, / (root). If the workflow failed to push, allow it (Settings → Actions → General → Read and write permissions) and run it again.

Once the workflow is green, bring both branches up to date and work on dev from now on:

git pull
git switch dev
git pull origin dev
git push -u origin dev

3. Read the widget

The widget is src/app/App.tsx. Its declaration says what it asks Grist for:

export const widget = defineGristWidget({
  title: "My Widget",
  description: "Mark the selected task done.",
  requiredAccess: "full",
  columns: [
    { name: "Title", type: "Text" },
    { name: "Done", type: "Bool" },
  ],
})
  • columns are the widget's own names. In Grist, the person maps a column of their table to each: their Task name to your Title, say. Until they do, the widget shows "Map your columns".
  • requiredAccess is "full" because the widget writes. A widget that only reads asks for "read table".

The component reads the selected row with widget.useGrist(), typed from the declaration: w.mappedRecord.Title is a string | null, Done a boolean | null. It writes with w.updateRecord({ Done: !Done }), under your names, into the column the person mapped. If Grist refuses a write, an alert above the widget says why.

4. Add a column

Add an optional due date to the declaration, after Done:

    { name: "Due", type: "Date", optional: true },

and, in App, read it with the others and show it under the title:

const { Title, Done, Due } = w.mappedRecord
// …
<h1 className="text-base font-medium">{Title || "Untitled"}</h1>
{Due ? <p>Due {Due.toLocaleDateString(undefined, { timeZone: "UTC" })}</p> : null}

Due is a Date, or nothing when the cell is empty or the column isn't mapped: being optional, it doesn't stop the widget from rendering. Grist stores a date at midnight UTC, hence timeZone: "UTC": without it, a reader west of UTC sees the day before. If you have Docker, pnpm demo --save regenerates the demo page's document with the new column; without it, the demo page simply lacks Due.

5. Test it

src/app/App.test.tsx runs the widget against an emulated Grist: a table built from the declared columns, mapped, with the rows you give. Add a test next to the ones already there:

it("shows the due date", async () => {
  renderWithGrist(<App />, {
    widget,
    rows: [{ Title: "Buy milk", Done: false, Due: new Date("2026-03-16") }],
  })
  expect(await screen.findByText(`Due ${new Date("2026-03-16").toLocaleDateString(undefined, { timeZone: "UTC" })}`)).toBeInTheDocument()
})
pnpm test

6. See it in your own Grist

Commit the change on dev and push it:

git add -A
git commit -m "Show the due date"
git push

The workflow serves dev at https://<you>.github.io/my-widget/dev/. In a Grist document, add a Custom widget section, paste that URL, and map your columns. Each push to dev reloads it there.

7. Release it

Once it works on /dev/:

pnpm release minor

That raises the version to 0.1.0 and writes the changelog entry, on a branch with its pull request into dev. Merge it, then open the pull request from dev into main (the command prints its link), and merge that one once its checks are green. The workflow publishes …/my-widget/v0.1.0/, which never changes, and moves …/my-widget/latest/ to it: paste one of those into the documents that use the widget.

8. Protect the repository

Any time after the first version is out (the workflow opened an issue to remind you):

pnpm exec create-grist-widget protect

It needs the GitHub CLI (gh auth login first) and admin rights on the repository. From then on, main changes only through a pull request with green checks, neither branch can be force-pushed or deleted, and release tags can't be moved.

Next

On this page