Install and configure widgets
How to install and configure widgets for the Dashboard tool for Sanity Studio
The Dashboard tool for Sanity Studio renders the widgets you configure for it. This guide shows you how to install a widget, change its layout, and configure its options.
Prerequisites:
- A Sanity Studio project.
- The Dashboard tool (
@sanity/dashboard) installed and added to thepluginsarray in your studio configuration. To set it up, see The Dashboard tool for Sanity Studio.
Install widgets for the Dashboard tool
You install Dashboard widgets the same way you'd install any studio plugin, or indeed any other package, using your preferred package manager.
You can find some popular widgets at the Sanity Exchange.
For example, to install the document list widget, follow these steps:
Step 1: Install the widget
In the root folder of your project, install the widget:
npm install sanity-plugin-dashboard-widget-document-listpnpm add sanity-plugin-dashboard-widget-document-listyarn add sanity-plugin-dashboard-widget-document-listbun add sanity-plugin-dashboard-widget-document-listStep 2: Add the widget to your studio configuration
In your sanity.config.ts file, import the widget and add it to the widgets array of the Dashboard tool:
import { defineConfig } from "sanity";
import { dashboardTool } from "@sanity/dashboard";
import { documentListWidget } from "sanity-plugin-dashboard-widget-document-list";
export default defineConfig({
// ...
plugins: [
dashboardTool({
widgets: [documentListWidget({})],
}),
],
});Step 3: View the widget in your studio
Start your studio and open the Dashboard tool. The widget, titled Last created, lists up to 10 of your most recently created documents.
Change widget layout
To set a widget’s size, pass a layout option to the widget function:
dashboardTool({
widgets: [
documentListWidget({ layout: { width: "small" } }),
],
})The accepted values for layout.width and layout.height are:
autosmallmediumlargefull
Configure widget options
Some widgets accept options that change aspects of their behavior. Check the widget’s README.md for the options it supports. For example, you can configure the document list widget like this:
documentListWidget({
showCreateButton: true,
limit: 5,
types: ["my-document-type"],
})You can add multiple instances of a widget, each with its own configuration. For example, to show the newest documents across all document types alongside the most recently edited books, add two document list widgets to the Dashboard tool:
import { defineConfig } from "sanity";
import { dashboardTool } from "@sanity/dashboard";
import { documentListWidget } from "sanity-plugin-dashboard-widget-document-list";
export default defineConfig({
// ...
plugins: [
dashboardTool({
widgets: [
documentListWidget({ title: "New", order: "_createdAt desc" }),
documentListWidget({
title: "Last edited books",
order: "_updatedAt desc",
types: ["book"],
}),
],
}),
],
});Was this page helpful?
Feedback submitted, thanks for helping us improve the docs. Have you tried these alternatives?