# View Toolbar

> Filter, sort and group the records a view shows.

Page: https://uicontext.com/docs/components/view-toolbar

Group: Records.

## When to use

Filter, sort and group the records a view shows. Use [Search](https://uicontext.com/docs/components/search.md) instead when people search by words, not by fields.

## Usage

```ts
import { type Property, View } from "./ui/uicontext/components/domain/Record.ts"
import { ViewToolbar } from "./ui/uicontext/components/Filter.ts"

const Message = UiSchema.TaggedEnum({ ChangedView: { view: View } })

// Keep one View in your model and pass it to the toolbar and to the List, Board or Data Grid under it.
export const TaskToolbar = (h: Html.H<typeof Message.Type>, fields: ReadonlyArray<Property>, view: View) =>
	ViewToolbar(h, {
		props: { label: "Tasks", fields, view, layouts: ["list", "board", "table"] },
		onEmit: {
			RequestedView: ({ view }) => Message.ChangedView({ view }),
			RequestedSelectView: () => undefined,
			RequestedSaveView: () => undefined,
			RequestedDeleteView: () => undefined,
			RequestedRenameView: () => undefined,
			RequestedShareView: () => undefined,
			RequestedEditField: () => undefined,
		},
	})
```

## Examples

Each example is a complete file. Its imports point where the CLI installs the source.

### Saved views

Switch views as tabs. Change the filter, sort or grouping and Save or Reset; rename, duplicate, share or delete a view from its menu.

This example also uses Board, Record List, and Data Grid. Install them too:

```sh
npx shadcn@latest add checkfu/uicontext/board checkfu/uicontext/record-list checkfu/uicontext/data-grid
```

```ts title="src/demo.ts" source="www/src/examples/view-toolbar/demo.ts"
import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Schema } from "effect"
import { Outcome } from "./ui/uicontext/components/domain/Outcome.ts"
import { SavedView, View, viewOf } from "./ui/uicontext/components/domain/Record.ts"
import { Board } from "./ui/uicontext/components/Board.ts"
import { filterItems, ViewToolbar } from "./ui/uicontext/components/Filter.ts"
import { RecordList } from "./ui/uicontext/components/RecordList.ts"
import { Item, Value } from "./ui/uicontext/components/Property.ts"
import { Table } from "./ui/uicontext/components/Table.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { applyEdit, issueFields, issues } from "./issues.ts"

// One View in the model, passed to the toolbar and to the record view under it. Every record view
// takes the same `records`, `fields` and `view`, so switching the layout is swapping the component.

const savedViews: ReadonlyArray<SavedView> = [
	{ id: "triage", label: "Triage", shared: true, view: viewOf({ groupBy: "status", sort: [{ key: "priority", direction: "asc" }] }, "list") },
	{ id: "board", label: "By status", shared: true, view: viewOf({ groupBy: "status", hidden: ["customer", "impact"] }, "board") },
	{
		id: "customers",
		label: "Customer asks",
		view: viewOf(
			{
				filter: { match: "all", conditions: [{ key: "customer", op: "isNotEmpty", value: null }] },
				sort: [{ key: "impact", direction: "desc" }],
			},
			"table",
		),
	},
]

const styles = stylex.create({
	stack: { display: "grid", gridTemplateColumns: "minmax(0, 1fr)", gap: 12 },
	frame: { blockSize: 420, inlineSize: "100%" },
})

const Message = UiSchema.TaggedEnum({
	RequestedEditIssue: { request: Schema.String, item: Schema.String, key: Schema.String, value: Value },
	RequestedIssueView: { view: View },
	SelectedSavedView: { view: Schema.String },
	RequestedSaveIssueView: { view: Schema.NullOr(Schema.String), label: Schema.String, config: View },
	RequestedRenameIssueView: { view: Schema.String, label: Schema.String },
	RequestedShareIssueView: { view: Schema.String, shared: Schema.Boolean },
	RequestedDeleteIssueView: { view: Schema.String },
})

export const IssueViews = Html.component({
	name: "IssueViews",
	model: Schema.Struct({
		records: Schema.Array(Item),
		outcomes: Schema.Array(Outcome),
		views: Schema.Array(SavedView),
		active: Schema.NullOr(Schema.String),
		view: View,
	}),
	message: Message,
}).make({
	init: () => ({ records: issues, outcomes: [], views: savedViews, active: "triage", view: savedViews[0]!.view }),
	update: {
		RequestedEditIssue: ($, { request, item, key, value }) =>
			$.evolve({
				records: (records) => records.map((r) => (r.id === item ? applyEdit(r, key, value) : r)),
				outcomes: (o) => [...o.slice(-10), { _tag: "Accepted", request }],
			}),
		// the toolbar and the view under it both ask for changes the same way: the whole next view
		RequestedIssueView: ($, { view }) => $.evolve({ view }),
		SelectedSavedView: ($, { view }) =>
			$.evolve({ active: view, view: $.model.views.find((v) => v.id === view)?.view ?? $.model.view }),
		RequestedSaveIssueView: ($, { view, label, config }) => {
			if (view !== null) return $.evolve({ views: (all) => all.map((v) => (v.id === view ? { ...v, view: config } : v)) })
			const id = `view-${$.model.views.length + 1}`
			return $.evolve({ views: (all) => [...all, { id, label, view: config }], active: id, view: config })
		},
		RequestedRenameIssueView: ($, { view, label }) =>
			$.evolve({ views: (all) => all.map((v) => (v.id === view ? { ...v, label } : v)) }),
		RequestedShareIssueView: ($, { view, shared }) =>
			$.evolve({ views: (all) => all.map((v) => (v.id === view ? { ...v, shared } : v)) }),
		// deleting the view on screen moves to the first one left
		RequestedDeleteIssueView: ($, { view }) => {
			const views = $.model.views.filter((v) => v.id !== view)
			const next = $.model.active === view ? (views[0] ?? null) : undefined
			return $.evolve({
				views,
				...(next === undefined ? {} : { active: next?.id ?? null, view: next?.view ?? $.model.view }),
			})
		},
	},
	view: (h, { records, outcomes, views, active, view }) => {
		const props = { label: "Issues", records, fields: issueFields, view, outcomes }
		const shared = {
			RequestedEdit: (edit: { request: string; item: string; key: string; value: Value }) => Message.RequestedEditIssue(edit),
			RequestedView: ({ view }: { view: View }) => Message.RequestedIssueView({ view }),
			RequestedOpen: () => undefined,
			RequestedAction: () => undefined,
			RequestedCreate: () => undefined,
			RequestedReorder: () => undefined,
			Selected: () => undefined,
		}
		return h.div.attrs(sx(styles.stack)).children(
			ViewToolbar(h, {
				props: {
					label: "Issues",
					fields: issueFields,
					view,
					views,
					active,
					layouts: ["list", "board", "table"],
					count: { shown: filterItems(records, view.filter, issueFields).length, total: records.length },
					can: ["shareViews"],
				},
				onEmit: {
					RequestedView: ({ view }) => Message.RequestedIssueView({ view }),
					RequestedSelectView: ({ view }) => Message.SelectedSavedView({ view }),
					RequestedSaveView: ({ view, label, config }) => Message.RequestedSaveIssueView({ view, label, config }),
					RequestedDeleteView: ({ view }) => Message.RequestedDeleteIssueView({ view }),
					RequestedRenameView: ({ view, label }) => Message.RequestedRenameIssueView({ view, label }),
					RequestedShareView: ({ view, shared }) => Message.RequestedShareIssueView({ view, shared }),
					RequestedEditField: () => undefined,
				},
			}),
			h.div.attrs(sx(styles.frame)).children(
				view.layout === "board"
					? Board(h, { key: "board", props, onEmit: shared })
					: view.layout === "table"
						? Table(h, {
								key: "table",
								props: { ...props, title: { label: "Issue", width: 300 }, resizable: true },
								onEmit: {
									...shared,
									RequestedCellAction: () => undefined,
									RequestedAddColumn: () => undefined,
									RequestedColumnAction: () => undefined,
								},
							})
						: RecordList(h, {
								key: "list",
								props: {
									...props,
									columns: [
										{ key: "priority", at: "start", compact: true },
										{ key: "status", at: "start", compact: true },
										{ key: "labels" },
										{ key: "impact" },
										{ key: "due" },
										{ key: "assignee", compact: true },
									],
								},
								onEmit: shared,
							}),
			),
		)
	},
})
```

### Filter groups and sort stacks

Ana's deals that are won or worth $50,000 or more, sorted by stage, then amount. Add a group from Filter, and more sort levels from Sort.

This example also uses Data Grid. Install it too:

```sh
npx shadcn@latest add checkfu/uicontext/data-grid
```

```ts title="src/filter-groups.ts" source="www/src/examples/view-toolbar/filter-groups.ts"
import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Schema } from "effect"
import { View, viewOf } from "./ui/uicontext/components/domain/Record.ts"
import { filterItems, ViewToolbar } from "./ui/uicontext/components/Filter.ts"
import { Table } from "./ui/uicontext/components/Table.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { dealFields, deals } from "./deals.ts"

// A filter with a group: Ana's deals that are won or worth at least $50,000. A group counts as one
// condition, with its own "all of" or "any of". The sort stack orders by stage, then by amount.

const styles = stylex.create({
	stack: { display: "grid", gridTemplateColumns: "minmax(0, 1fr)", gap: 12 },
	frame: { blockSize: 320, inlineSize: "100%" },
})

const Message = UiSchema.TaggedEnum({ RequestedPipelineView: { view: View } })

export const BigDeals = Html.component({
	name: "BigDeals",
	model: Schema.Struct({ view: View }),
	message: Message,
}).make({
	init: () => ({
		view: viewOf(
			{
				filter: {
					match: "all",
					conditions: [{ key: "owner", op: "is", value: ["ana"] }],
					groups: [
						{
							match: "any",
							conditions: [
								{ key: "stage", op: "is", value: ["won"] },
								{ key: "amount", op: "gte", value: 50000 },
							],
						},
					],
				},
				sort: [
					{ key: "stage", direction: "asc" },
					{ key: "amount", direction: "desc" },
				],
			},
			"table",
		),
	}),
	update: { RequestedPipelineView: ($, { view }) => $.evolve({ view }) },
	view: (h, { view }) =>
		h.div.attrs(sx(styles.stack)).children(
			ViewToolbar(h, {
				props: {
					label: "Deals",
					agentId: "deals-grouped",
					fields: dealFields,
					view,
					layouts: ["table"],
					count: { shown: filterItems(deals, view.filter, dealFields).length, total: deals.length },
					locale: "en-US",
				},
				onEmit: {
					RequestedView: ({ view }) => Message.RequestedPipelineView({ view }),
					RequestedSelectView: () => undefined,
					RequestedSaveView: () => undefined,
					RequestedDeleteView: () => undefined,
					RequestedRenameView: () => undefined,
					RequestedShareView: () => undefined,
					RequestedEditField: () => undefined,
				},
			}),
			h.div.attrs(sx(styles.frame)).children(
				Table(h, {
					props: {
						label: "Deals",
						agentId: "deals-grouped-grid",
						records: deals,
						fields: dealFields,
						view,
						title: { label: "Deal", width: 260 },
						readOnly: "This example only filters and sorts.",
						selectable: false,
						locale: "en-US",
					},
					onEmit: {
						RequestedView: ({ view }) => Message.RequestedPipelineView({ view }),
						RequestedEdit: () => undefined,
						RequestedOpen: () => undefined,
						RequestedCreate: () => undefined,
						RequestedAction: () => undefined,
						RequestedReorder: () => undefined,
						Selected: () => undefined,
						RequestedCellAction: () => undefined,
						RequestedAddColumn: () => undefined,
						RequestedColumnAction: () => undefined,
					},
				}),
			),
		),
})
```

### Filter bar

The filter on its own, over a list. It starts on bugs; add a condition for priority or assignee.

This example also uses Record List. Install it too:

```sh
npx shadcn@latest add checkfu/uicontext/record-list
```

```ts title="src/filter-bar.ts" source="www/src/examples/view-toolbar/filter-bar.ts"
import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Schema } from "effect"
import { Filter } from "./ui/uicontext/components/domain/Record.ts"
import { FilterBar, filterItems } from "./ui/uicontext/components/Filter.ts"
import { RecordList } from "./ui/uicontext/components/RecordList.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { issueFields, issues } from "./issues.ts"

// Just the filter: FilterBar edits one Filter, and `filterItems` applies it the way every record
// view does. Use it where the layout, sort and saved views are fixed.

const styles = stylex.create({
	stack: { display: "grid", gridTemplateColumns: "minmax(0, 1fr)", gap: 12, inlineSize: "100%" },
	frame: { blockSize: 320 },
})

const Message = UiSchema.TaggedEnum({ ChangedFilter: { filter: Filter } })

const filterable = issueFields.filter((field) => ["status", "priority", "assignee", "labels", "due"].includes(field.key))

export const BugFilter = Html.component({
	name: "BugFilter",
	model: Schema.Struct({ filter: Filter }),
	message: Message,
}).make({
	init: () => ({
		filter: { match: "all", conditions: [{ key: "labels", op: "hasAny", value: ["bug"] }] },
	}),
	update: { ChangedFilter: ($, { filter }) => $.evolve({ filter }) },
	view: (h, { filter }) => {
		const shown = filterItems(issues, filter, issueFields)
		return h.div.attrs(sx(styles.stack)).children(
			FilterBar(h, {
				props: { label: "Issues", properties: filterable, filter, saveAs: false, count: { shown: shown.length, total: issues.length } },
				onEmit: {
					RequestedChangeFilter: ({ filter }) => Message.ChangedFilter({ filter }),
					RequestedSelectView: () => undefined,
					RequestedSaveView: () => undefined,
					RequestedDeleteView: () => undefined,
				},
			}),
			h.div.attrs(sx(styles.frame)).children(
				RecordList(h, {
					props: {
						label: "Filtered issues",
						records: shown,
						fields: issueFields,
						columns: [{ key: "priority", at: "start", compact: true }, { key: "status", at: "start", compact: true }, { key: "labels" }, { key: "assignee", compact: true }],
						selectable: false,
						empty: { title: "No issues match", hint: "Remove a condition to see more." },
					},
					onEmit: {
						RequestedEdit: () => undefined,
						RequestedOpen: () => undefined,
						RequestedView: () => undefined,
						RequestedAction: () => undefined,
						RequestedReorder: () => undefined,
						RequestedCreate: () => undefined,
						Selected: () => undefined,
					},
				}),
			),
		)
	},
})
```

### Locked views

A guest filters and sorts for themselves; saving, renaming and deleting stay with members.

```ts title="src/locked.ts" source="www/src/examples/view-toolbar/locked.ts"
import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import { Schema } from "effect"
import { type SavedView, View, viewOf } from "./ui/uicontext/components/domain/Record.ts"
import { filterItems, ViewToolbar } from "./ui/uicontext/components/Filter.ts"
import { dealFields, deals } from "./deals.ts"

// A guest can still filter, sort and switch views for themselves, but can't save, rename or delete
// the team's views: `locked` says why, and the save and view menus don't show.

const views: ReadonlyArray<SavedView> = [
	{ id: "open", label: "Open pipeline", shared: true, view: viewOf({ filter: { match: "any", conditions: [{ key: "stage", op: "isNot", value: ["won", "lost"] }] } }, "table") },
	{ id: "closing", label: "Closing this month", shared: true, view: viewOf({ sort: [{ key: "close", direction: "asc" }] }, "table") },
]

const Message = UiSchema.TaggedEnum({
	RequestedGuestView: { view: View },
	SelectedGuestView: { view: Schema.String },
})

export const GuestToolbar = Html.component({
	name: "GuestToolbar",
	model: Schema.Struct({ active: Schema.String, view: View }),
	message: Message,
}).make({
	init: () => ({ active: "open", view: views[0]!.view }),
	update: {
		RequestedGuestView: ($, { view }) => $.evolve({ view }),
		SelectedGuestView: ($, { view }) => $.evolve({ active: view, view: views.find((v) => v.id === view)?.view ?? $.model.view }),
	},
	view: (h, { active, view }) =>
		ViewToolbar(h, {
			props: {
				label: "Deals",
				agentId: "deals-guest",
				fields: dealFields,
				view,
				views,
				active,
				layouts: ["table", "board"],
				locked: "Only members can change views",
				count: { shown: filterItems(deals, view.filter, dealFields).length, total: deals.length },
				locale: "en-US",
			},
			onEmit: {
				RequestedView: ({ view }) => Message.RequestedGuestView({ view }),
				RequestedSelectView: ({ view }) => Message.SelectedGuestView({ view }),
				RequestedSaveView: () => undefined,
				RequestedDeleteView: () => undefined,
				RequestedRenameView: () => undefined,
				RequestedShareView: () => undefined,
				RequestedEditField: () => undefined,
			},
		}),
})
```

### Sample data

The examples above import these files.

```ts title="src/issues.ts" source="www/src/examples/_shared/issues.ts"
import type { Item, Property } from "./ui/uicontext/components/Property.ts"
import { color } from "./ui/uicontext/components/tokens.stylex.ts"

// One set of issues for every record view: the list, the board, the data grid, the form and the
// detail all take the same `records` and `fields` (and a `view`), so switching views is switching
// components.

export const people = [
	{ value: "ada", label: "Ada Lovelace", glyph: { _tag: "Person" as const, id: "ada", name: "Ada Lovelace", agent: false } },
	{ value: "grace", label: "Grace Hopper", glyph: { _tag: "Person" as const, id: "grace", name: "Grace Hopper", agent: false } },
	{ value: "alan", label: "Alan Turing", glyph: { _tag: "Person" as const, id: "alan", name: "Alan Turing", agent: false } },
	{ value: "scout", label: "Scout", glyph: { _tag: "Person" as const, id: "scout", name: "Scout", agent: true } },
]

// a relation's options are the records it can link to, with their titles
export const customers = [
	{ value: "northwind", label: "Northwind Freight" },
	{ value: "halcyon", label: "Halcyon Health" },
	{ value: "bluebird", label: "Bluebird Credit Union" },
]

export const issueFields: ReadonlyArray<Property> = [
	{
		key: "status",
		label: "Status",
		kind: "select",
		options: [
			{ value: "todo", label: "Todo", glyph: { _tag: "Ring", color: color.muted, progress: 0, label: "Todo" } },
			{ value: "doing", label: "In Progress", glyph: { _tag: "Ring", color: color.caution, progress: 0.5, label: "In Progress" } },
			{ value: "review", label: "In Review", glyph: { _tag: "Ring", color: color.success, progress: 0.75, label: "In Review" } },
			{ value: "done", label: "Done", glyph: { _tag: "Ring", color: color.done, progress: 1, mark: "check", label: "Done" } },
		],
	},
	{
		key: "priority",
		label: "Priority",
		kind: "select",
		empty: "No priority",
		options: [
			{ value: "urgent", label: "Urgent", glyph: { _tag: "Bars", level: 3, alert: true, label: "Urgent" } },
			{ value: "high", label: "High", glyph: { _tag: "Bars", level: 3, label: "High" } },
			{ value: "medium", label: "Medium", glyph: { _tag: "Bars", level: 2, label: "Medium" } },
			{ value: "low", label: "Low", glyph: { _tag: "Bars", level: 1, label: "Low" } },
		],
	},
	{ key: "assignee", label: "Assignee", kind: "person", empty: "No assignee", options: people },
	{
		key: "labels",
		label: "Labels",
		kind: "multiSelect",
		options: [
			{ value: "bug", label: "Bug", glyph: { _tag: "Swatch", color: color.danger } },
			{ value: "feature", label: "Feature", glyph: { _tag: "Swatch", color: color.info } },
			{ value: "design", label: "Design", glyph: { _tag: "Swatch", color: color.agent } },
		],
	},
	{ key: "estimate", label: "Estimate", kind: "number", empty: "No estimate", description: "In points" },
	{ key: "due", label: "Due", kind: "date" },
	{
		key: "customer",
		label: "Customer",
		kind: "relation",
		relation: { target: "Companies", multiple: false },
		options: customers,
		empty: "No customer",
	},
	{ key: "impact", label: "Impact", kind: "rating", max: 3, description: "How much it matters to the customer" },
]

const issue = (n: number, title: string, values: Item["values"], extra: Partial<Item> = {}): Item => ({
	id: `eng-${n}`,
	prefix: `ENG-${n}`,
	title,
	values,
	...extra,
})

export const issues: ReadonlyArray<Item> = [
	issue(142, "Sign-in link expires before the email arrives", { status: "doing", priority: "urgent", assignee: "ada", labels: ["bug"], estimate: 3, due: "2026-12-04", customer: ["northwind"], impact: 3 }),
	issue(139, "Keyboard shortcuts for triage", { status: "todo", priority: "high", assignee: "grace", labels: ["feature"], estimate: 5, due: "2026-12-11", customer: [], impact: 2 }),
	issue(137, "Export drops the last row of a filtered view", { status: "review", priority: "high", assignee: "alan", labels: ["bug"], estimate: 2, due: "2026-12-03", customer: ["halcyon"], impact: 3 }),
	issue(135, "Draft release notes for 2.4", { status: "doing", priority: "medium", assignee: "scout", labels: [], estimate: 1, due: "2026-12-06", customer: [], impact: null }, { busy: "Scout is writing" }),
	issue(131, "Empty states for saved views", { status: "todo", priority: "medium", assignee: "ada", labels: ["design"], estimate: 3, due: null, customer: [], impact: 1 }),
	issue(128, "Notifications arrive twice on mobile", { status: "todo", priority: "low", assignee: null, labels: ["bug"], estimate: null, due: null, customer: ["bluebird"], impact: 2 }),
	issue(126, "Bulk move issues between teams", { status: "review", priority: "medium", assignee: "grace", labels: ["feature"], estimate: 8, due: "2026-12-09", customer: ["northwind"], impact: 2 }),
	issue(121, "Webhook retries with backoff", { status: "done", priority: "high", assignee: "alan", labels: ["feature"], estimate: 5, due: "2026-11-27", customer: ["halcyon"], impact: 1 }),
	issue(118, "Dark mode contrast on badges", { status: "done", priority: "low", assignee: "ada", labels: ["design"], estimate: 1, due: "2026-11-24", customer: [], impact: 1 }),
	issue(144, "Invoice PDF cuts off long company names", { status: "todo", priority: "urgent", assignee: "grace", labels: ["bug"], estimate: 2, due: "2026-12-02", customer: ["bluebird"], impact: 3 }, { attention: true, note: "Reported by three customers this week" }),
	issue(140, "SAML sign-in for the admin console", { status: "doing", priority: "high", assignee: "alan", labels: ["feature"], estimate: 8, due: "2026-12-18", customer: ["halcyon"], impact: 3 }),
	issue(133, "Triage suggestions for new bug reports", { status: "review", priority: "medium", assignee: "scout", labels: ["feature"], estimate: 3, due: "2026-12-10", customer: [], impact: 2 }),
]

/** Single keys that open a field's picker on the focused (or every selected) issue. */
export const issueShortcuts = [
	{ key: "s", field: "status", label: "Status" },
	{ key: "p", field: "priority", label: "Priority" },
	{ key: "a", field: "assignee", label: "Assignee" },
]

/** Applies an accepted edit to a record: the title, or one of its values. */
export const applyEdit = (record: Item, key: string, value: Item["values"][string]): Item =>
	key === "title" ? { ...record, title: String(value) } : { ...record, values: { ...record.values, [key]: value } }
```

```ts title="src/deals.ts" source="www/src/examples/view-toolbar/deals.ts"
import type { Item, Property } from "./ui/uicontext/components/domain/Record.ts"

// A sales pipeline: the deals a small team is working this quarter.

export const owners = [
	{ value: "ana", label: "Ana Ruiz", glyph: { _tag: "Person" as const, id: "ana", name: "Ana Ruiz", agent: false } },
	{ value: "kofi", label: "Kofi Mensah", glyph: { _tag: "Person" as const, id: "kofi", name: "Kofi Mensah", agent: false } },
	{ value: "lena", label: "Lena Park", glyph: { _tag: "Person" as const, id: "lena", name: "Lena Park", agent: false } },
]

export const dealFields: ReadonlyArray<Property> = [
	{
		key: "stage",
		label: "Stage",
		kind: "select",
		options: [
			{ value: "lead", label: "Lead", tone: "gray" },
			{ value: "qualified", label: "Qualified", tone: "blue" },
			{ value: "proposal", label: "Proposal", tone: "purple" },
			{ value: "won", label: "Won", tone: "green" },
			{ value: "lost", label: "Lost", tone: "red" },
		],
	},
	{ key: "owner", label: "Owner", kind: "person", empty: "No owner", options: owners },
	{ key: "amount", label: "Amount", kind: "number", format: { style: "currency", currency: "USD", decimals: 0 } },
	{ key: "close", label: "Close date", kind: "date" },
	{
		key: "source",
		label: "Source",
		kind: "select",
		options: [
			{ value: "inbound", label: "Inbound", tone: "yellow" },
			{ value: "referral", label: "Referral", tone: "orange" },
			{ value: "outbound", label: "Outbound", tone: "indigo" },
		],
	},
	{ key: "probability", label: "Probability", kind: "number", format: { style: "percent", decimals: 0 } },
]

const deal = (id: string, title: string, values: Item["values"]): Item => ({ id, title, values })

export const deals: ReadonlyArray<Item> = [
	deal("d1", "Northwind Freight: fleet tracking", { stage: "proposal", owner: "ana", amount: 84000, close: "2026-12-18", source: "inbound", probability: 0.6 }),
	deal("d2", "Halcyon Health: patient portal", { stage: "won", owner: "kofi", amount: 126000, close: "2026-11-20", source: "referral", probability: 1 }),
	deal("d3", "Bluebird Credit Union: renewal", { stage: "qualified", owner: "ana", amount: 32000, close: "2027-01-09", source: "outbound", probability: 0.4 }),
	deal("d4", "Juniper Schools: pilot", { stage: "lead", owner: "lena", amount: 12500, close: "2027-02-01", source: "inbound", probability: 0.1 }),
	deal("d5", "Copperline Mining: safety audit", { stage: "lost", owner: "kofi", amount: 58000, close: "2026-11-02", source: "outbound", probability: 0 }),
	deal("d6", "Atlas Dental Group: 40 seats", { stage: "won", owner: "ana", amount: 47500, close: "2026-11-28", source: "referral", probability: 1 }),
	deal("d7", "Riverbend Logistics: expansion", { stage: "proposal", owner: "lena", amount: 210000, close: "2026-12-30", source: "referral", probability: 0.5 }),
	deal("d8", "Marlow & Sons: starter plan", { stage: "qualified", owner: null, amount: 6400, close: null, source: "inbound", probability: 0.3 }),
]
```

## API reference

### FilterBar (component)

**Props**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `label` (required) | `string` | — | What the bar filters, for its accessible name: "Issues" |
| `agentId` | `string` | `filter:<label>` | This bar's id for agents, unique on the page; `filter:<label>` by default |
| `properties` (required) | `Property[]` | — | The properties a person can filter on |
| `filter` (required) | `Filter` | — | The conditions applied now; every change comes back as `RequestedChangeFilter` |
| `current` | `ViewInput` | — | The rest of the view this filter belongs to (layout, sort, grouping); a saved view keeps all of it |
| `views` | `SavedView[]` | — | The saved views the bar lists to switch between |
| `view` | `string \| null` | — | The active view's id |
| `saveAs` | `boolean` | `true` | Whether the bar offers "Save as view"; true by default (the View Toolbar saves whole views itself) |
| `locked` | `string` | — | Why views can't be changed here: "Views are locked" |
| `outcome` | `Outcome \| null` | — | Pass null before saving, then return the outcome for each new view request. |
| `count` | `{ shown, total, noun }` | — | How many items pass, of how many: "12 of 340" |
| `locale` | `string` | — | The locale numbers and dates are formatted in; the browser's by default |

**Events**

| Event | Payload | Description |
| --- | --- | --- |
| `RequestedChangeFilter` | `{ filter: Filter }` | The person changed the filter here; keep it as view state and pass it back as `filter` |
| `RequestedSelectView` | `{ view: string }` | Show this saved view; pass its id back as `view` |
| `RequestedSaveView` | `{ view: string \| null; label: string; config: View; request?: string }` | Save `config` (the current view with this filter) to the view (null: a new view named `label`) |
| `RequestedDeleteView` | `{ view: string }` | Delete this saved view |

**Agent actions**

| Action | Description |
| --- | --- |
| `SetFilter` | Replace the whole filter. Each condition is { key, op, value }: op from the field's ops; value an option value list for choices, text, a number, an ISO date, true/false |
| `AddedCondition` | Add one condition: key, and optionally op, value, and group (a group's index, to add inside it) |
| `RemovedCondition` | Remove the condition at this index (in the group at group, when given) |
| `AddedGroup` | Add an empty group: its conditions count as one, joined by its own match (any by default) |
| `RemovedGroup` | Remove the group at this index, with its conditions |
| `ClearedFilter` | Remove every condition and group |
| `ClickedView` | Switch to a saved view by id |
| `ClickedSaveView` | Save the current filter to the active view (shared views change for everyone) |
| `SubmittedNewView` | Save the current filter as a new view named label |
| `ClickedDeleteView` (asks first) | Delete a saved view |

### ViewToolbar (component)

**Props**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `label` (required) | `string` | — | What the view shows, for accessible names: "Deals" |
| `agentId` | `string` | `view:<label>` | This toolbar's id for agents, unique on the page; `view:<label>` by default |
| `fields` (required) | `Property[]` | — | The fields the view can filter, sort, group and show |
| `view` (required) | `ViewInput` | — | The view as shown now; every change comes back as `RequestedView` |
| `views` | `SavedView[]` | — | The saved views the switcher lists |
| `active` | `string \| null` | — | The saved view being shown, by id; null when the view is unsaved |
| `layouts` | `ViewLayout[]` | — | The layouts the switcher offers, in order; every layout by default |
| `count` | `{ shown, total, noun }` | — | How many records pass the filter, of how many |
| `locked` | `string` | — | Why saved views can't be changed here: "Views are locked" |
| `outcome` | `Outcome \| null` | — | Pass null before saving, then return the outcome for each new view request. |
| `locale` | `string` | — | The locale numbers and dates are formatted in; the browser's by default |
| `can` | `Can(["editFields", "shareViews"])` | — | "editFields" offers New field and Edit field in the Fields menu; "shareViews" offers sharing a saved view with everyone, and making a shared one private again |
| `display` | `boolean` | — | One Display button in place of the layout switch and the Sort, Group and Fields menus: a panel with the layouts, grouping and sub-grouping, ordering, and the fields as toggles. The filter row keeps to filters. |

**Events**

| Event | Payload | Description |
| --- | --- | --- |
| `RequestedView` | `{ view: View }` | The person changed the view (layout, filter, sort, grouping, fields); pass it back as `view` |
| `RequestedSelectView` | `{ view: string }` | Show this saved view |
| `RequestedSaveView` | `{ view: string \| null; label: string; config: View; request?: string }` | Save `config` to the view (null: a new view named `label`) |
| `RequestedDeleteView` | `{ view: string }` | Delete this saved view |
| `RequestedRenameView` | `{ view: string; label: string }` | Give this saved view a new name; pass the renamed view back in `views` |
| `RequestedShareView` | `{ view: string; shared: boolean }` | Share this saved view with everyone (true), or make it the person's own again (false) |
| `RequestedEditField` | `{ key: string \| null }` | Open the field editor on this field, or on a new one (null) |

**Agent actions**

| Action | Description |
| --- | --- |
| `RequestedView` | Change parts of the view; the rest stays. view: { layout?, filter?: { conditions: [{ key, op, value }], match }, sort?: [{ key, direction: asc\|desc }], groupBy?: key\|null, hidden?: [keys] } |
| `PickedLayout` | Show the records in another layout |
| `ClickedView` | Switch to a saved view by id |
| `ClickedSaveView` | Save the view as it is now to the active saved view (shared views change for everyone) |
| `SubmittedNewView` | Save the view as it is now as a new view named label |
| `ClickedResetView` | Undo the unsaved changes to the active view |
| `ClickedDeleteView` (asks first) | Delete a saved view |
| `SubmittedRename` | Rename a saved view: { view: its id, label: the new name } |
| `ClickedDuplicateView` | Copy a saved view as a new view named after it |
| `ClickedShareView` (asks first) | Share a saved view with everyone (shared: true), or make it private again (false) |
| `PickedEditField` | Open the field editor on a field by key, or on a new field (null) |

## Keyboard and accessibility

- The filter bar is a `search` landmark named for its records; saved views are a `nav` of links with the open one marked `aria-current`, and an unsaved view says so.
- Each filter chip is a button named for the whole condition ("Status is Done: edit filter") with a Remove button beside it; a rating value is a radio group.
- The count of matching records is a status, so it's announced as filters change. Sort, group and fields are menus.
- Agents add and remove conditions, switch and save views, and get the reason when a field doesn't exist or can't group.

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/view-toolbar
```

With npm: `npx shadcn@latest add checkfu/uicontext/view-toolbar`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/view-toolbar`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/view-toolbar`.

It writes these files:

- `src/ui/uicontext/components/Button.ts`
- `src/ui/uicontext/components/Direction.ts`
- `src/ui/uicontext/components/Filter.ts`
- `src/ui/uicontext/components/FormControls.ts`
- `src/ui/uicontext/components/Glyph.ts`
- `src/ui/uicontext/components/IconStroke.ts`
- `src/ui/uicontext/components/InlineNotice.ts`
- `src/ui/uicontext/components/Kbd.ts`
- `src/ui/uicontext/components/Menu.ts`
- `src/ui/uicontext/components/Motion.ts`
- `src/ui/uicontext/components/Popover.ts`
- `src/ui/uicontext/components/Property.ts`
- `src/ui/uicontext/components/RequestNonce.ts`
- `src/ui/uicontext/components/SegmentedControl.ts`
- `src/ui/uicontext/components/ShowText.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/agent/Agent.ts`
- `src/ui/uicontext/components/button.stylex.ts`
- `src/ui/uicontext/components/domain/Format.ts`
- `src/ui/uicontext/components/domain/Glyph.ts`
- `src/ui/uicontext/components/domain/Outcome.ts`
- `src/ui/uicontext/components/domain/Permission.ts`
- `src/ui/uicontext/components/domain/Record.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`
- `src/ui/uicontext/components/touch.stylex.ts`
- `src/ui/uicontext/components/variants.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/Filter.ts](https://github.com/checkfu/uicontext/blob/main/src/Filter.ts)

## Used in

- [Task manager](https://uicontext.com/blocks/issue-tracker.md)
- [Database](https://uicontext.com/blocks/tables.md)
- [CRM](https://uicontext.com/blocks/crm.md)

## Related

- [Data Grid](https://uicontext.com/docs/components/data-grid.md) (`data-grid`): A spreadsheet-like grid for editing records, with typed columns, sorting and grouping.
- [Pivot Table](https://uicontext.com/docs/components/pivot-table.md) (`pivot-table`): Records summed two ways, such as revenue by region and quarter, with totals on both edges and cells tinted by size.
- [Table](https://uicontext.com/docs/components/table.md) (`table`): A simple read-only table with a caption, row headers and an empty state.
- [Group Header](https://uicontext.com/docs/components/group-header.md) (`group-header`): The line over a group of rows with its count, sticky while they scroll, folding the group.
- [Description List](https://uicontext.com/docs/components/description-list.md) (`description-list`): A record's facts as label and value pairs, in rows or columns, with Copy for ids.
- [Fact Grid](https://uicontext.com/docs/components/fact-grid.md) (`fact-grid`): A few numbers about one thing, such as a customer's plan and seats, as small tiles.
