A document's big title, icon, cover and properties.
Icon
Cover
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { PageTitle } from "./ui/uicontext/components/kit/PageTitle.ts"import { sx } from "./ui/uicontext/components/Sx.ts"// A page's header: hover it to change or remove the icon and the cover, and edit the title in place.// Clear the title and "Untitled" shows in its place.const styles = stylex.create({ frame: { inlineSize: "100%", paddingBlockEnd: 24 } })const Message = UiSchema.TaggedEnum({ EditedTitle: { title: Schema.String }, ChoseIcon: { icon: Schema.NullOr(Schema.String) }, ChoseCover: { cover: Schema.NullOr(Schema.String) },})export const NewPage = Html.component({ name: "NewPage", model: Schema.Struct({ title: Schema.String, icon: Schema.NullOr(Schema.String), cover: Schema.NullOr(Schema.String) }), message: Message,}).make({ init: () => ({ title: "Field research", icon: "🧭", cover: "gradient:meadow" }), update: { EditedTitle: ($, { title }) => $.evolve({ title }), ChoseIcon: ($, { icon }) => $.evolve({ icon }), ChoseCover: ($, { cover }) => $.evolve({ cover }), }, view: (h, { title, icon, cover }) => h.div.attrs(sx(styles.frame)).children( PageTitle(h, { props: { id: "new-page", title, icon, cover }, onEmit: { RequestedTitle: ({ title }) => Message.EditedTitle({ title }), RequestedIcon: ({ icon }) => Message.ChoseIcon({ icon }), RequestedCover: ({ cover }) => Message.ChoseCover({ cover }), }, }), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/page-titleUsage
import { PageTitle } from "./ui/uicontext/components/kit/PageTitle.ts"const Message = UiSchema.TaggedEnum({ RenamedPage: { title: Schema.String }, ChoseIcon: { icon: Schema.NullOr(Schema.String) }, ChoseCover: { cover: Schema.NullOr(Schema.String) },})export const Title = (h: Html.H<typeof Message.Type>, page: { title: string; icon: string | null; cover: string | null }) => PageTitle(h, { props: { id: "page-title", title: page.title, icon: page.icon, cover: page.cover }, onEmit: { RequestedTitle: ({ title }) => Message.RenamedPage({ title }), RequestedIcon: ({ icon }) => Message.ChoseIcon({ icon }), RequestedCover: ({ cover }) => Message.ChoseCover({ cover }), }, })Examples
With properties
A page that is a database record passes record, and its fields show under the title.
- Status
- In review
- Owner
- Noor Haddad
- Due
- Mar 31
Icon
Cover
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { PageTitle } from "./ui/uicontext/components/kit/PageTitle.ts"import type { Property } from "./ui/uicontext/components/kit/Property.ts"import { sx } from "./ui/uicontext/components/Sx.ts"// A page that is a record of a database: its fields show under the title, read-only.const styles = stylex.create({ frame: { inlineSize: "100%", paddingBlockEnd: 24 } })const fields: ReadonlyArray<Property> = [ { key: "status", label: "Status", kind: "select", options: [{ value: "draft", label: "Draft", tone: "gray" }, { value: "review", label: "In review", tone: "orange" }] }, { key: "owner", label: "Owner", kind: "person", options: [{ value: "noor", label: "Noor Haddad" }] }, { key: "due", label: "Due", kind: "date" },]const Message = UiSchema.TaggedEnum({ RenamedPage: { title: Schema.String }, ChoseIcon: { icon: Schema.NullOr(Schema.String) }, ChoseCover: { cover: Schema.NullOr(Schema.String) },})export const MeetingNotes = Html.component({ name: "MeetingNotes", model: Schema.Struct({ title: Schema.String, icon: Schema.NullOr(Schema.String), cover: Schema.NullOr(Schema.String) }), message: Message,}).make({ init: () => ({ title: "Quarterly planning notes", icon: "🗓️", cover: "gradient:dusk" }), update: { RenamedPage: ($, { title }) => $.evolve({ title }), ChoseIcon: ($, { icon }) => $.evolve({ icon }), ChoseCover: ($, { cover }) => $.evolve({ cover }), }, view: (h, { title, icon, cover }) => h.div.attrs(sx(styles.frame)).children( PageTitle(h, { props: { id: "planning-notes", title, icon, cover, record: { fields, item: { id: "planning-notes", title, values: { status: "review", owner: "noor", due: "2027-03-31" } } }, }, onEmit: { RequestedTitle: ({ title }) => Message.RenamedPage({ title }), RequestedIcon: ({ icon }) => Message.ChoseIcon({ icon }), RequestedCover: ({ cover }) => Message.ChoseCover({ cover }), }, }), ),})An image cover
Reposition an image cover by dragging it or with the arrow keys; RequestedCover brings back its position.
Icon
Cover
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { PageTitle } from "./ui/uicontext/components/kit/PageTitle.ts"import { sx } from "./ui/uicontext/components/Sx.ts"// An image cover: "Reposition" turns the cover into a slider. Drag the image, or use the arrow keys,// then save; the app keeps `coverPosition` with the page. "Change cover" also takes a pasted image// link, and the icon picker filters by name ("map", "rocket") and moves with the arrow keys.const styles = stylex.create({ frame: { inlineSize: "100%", paddingBlockEnd: 24 } })// a tall drawing of hills, so there's something to move; an app passes its own image addressconst hills = `data:image/svg+xml,${encodeURIComponent( `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 900"><defs><linearGradient id="s" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#9cc3e6"/><stop offset=".6" stop-color="#f3d9b6"/><stop offset="1" stop-color="#f6c9a6"/></linearGradient></defs><rect width="1200" height="900" fill="url(#s)"/><circle cx="880" cy="300" r="70" fill="#fbe7b5"/><path d="M0 620 Q300 470 600 600 T1200 560 V900 H0Z" fill="#7fae8a"/><path d="M0 720 Q350 610 700 720 T1200 700 V900 H0Z" fill="#5d8f6c"/><path d="M0 820 Q400 760 800 830 T1200 810 V900 H0Z" fill="#3f6e52"/></svg>`,)}`const Message = UiSchema.TaggedEnum({ RenamedPage: { title: Schema.String }, ChoseIcon: { icon: Schema.NullOr(Schema.String) }, ChoseCover: { cover: Schema.NullOr(Schema.String), position: Schema.optional(Schema.Number) },})export const TripPlan = Html.component({ name: "TripPlan", model: Schema.Struct({ title: Schema.String, icon: Schema.NullOr(Schema.String), cover: Schema.NullOr(Schema.String), position: Schema.Number }), message: Message,}).make({ init: () => ({ title: "Team offsite in the hills", icon: "🗺️", cover: hills, position: 70 }), update: { RenamedPage: ($, { title }) => $.evolve({ title }), ChoseIcon: ($, { icon }) => $.evolve({ icon }), // a new cover starts centered; a reposition keeps the cover and moves it ChoseCover: ($, { cover, position }) => $.evolve({ cover, position: position ?? 50 }), }, view: (h, { title, icon, cover, position }) => h.div.attrs(sx(styles.frame)).children( PageTitle(h, { props: { id: "offsite", title, icon, cover, coverPosition: position }, onEmit: { RequestedTitle: ({ title }) => Message.RenamedPage({ title }), RequestedIcon: ({ icon }) => Message.ChoseIcon({ icon }), RequestedCover: ({ cover, position }) => Message.ChoseCover(position === undefined ? { cover } : { cover, position }), }, }), ),})Read-only
With can: [] the title is a heading and the icon and cover can't change, for a guest or a locked page.
Travel and expenses policy
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { PageTitle } from "./ui/uicontext/components/kit/PageTitle.ts"import { sx } from "./ui/uicontext/components/Sx.ts"// A page shared with a guest: `can: []` shows the title as a heading, with no buttons to change the// icon or the cover.const styles = stylex.create({ frame: { inlineSize: "100%", paddingBlockEnd: 24 } })export const SharedPolicy = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.frame)).children( PageTitle(h, { props: { id: "travel-policy", title: "Travel and expenses policy", icon: "🧾", cover: "gradient:tide", can: [] }, onEmit: { RequestedTitle: () => undefined, RequestedIcon: () => undefined, RequestedCover: () => undefined }, }), )API reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
idrequired | string | — | Unique on the page |
titlerequired | string | — | The page's title; edits come back as RequestedTitle |
icon | string | null | — | An emoji, or null for none |
cover | string | null | — | An image address, or "gradient:<name>" for a built-in gradient; null for none |
coverPosition | number | 50 | Where an image cover sits vertically, from 0 (its top) to 100 (its bottom); 50 by default |
placeholder | string | "Untitled" | What an empty title shows; "Untitled" by default |
body | string | — | The page's body: the id of the Editor that Enter at the end of the title goes on to |
record | { fields, item } | — | A page that is a record: its fields and values, shown read-only under the title |
icons | string[] | — | The icons to offer |
covers | string[] | — | The covers to offer: image addresses or gradients; the built-in gradients by default |
can | Can(["edit"]) | "edit" | "edit" by default: without it the title, icon and cover can't change |
width | number | — | The column's width in pixels (720) |
locale | string | — | The locale numbers and dates are formatted in; the browser's by default |
Events
| Event | Payload | Description |
|---|---|---|
RequestedTitle | { id: string; title: string } | The person changed the title |
RequestedIcon | { id: string; icon: string | null } | The person picked an icon, or removed it (null) |
RequestedCover | { id: string; cover: string | null; position?: number } | The person picked a cover, or removed it (null); after a reposition, position is where it sits (0–100) |
Accessibility
- The title is a labelled text field; Enter or Down at its end moves into the page's body.
- Add icon and Add cover show on hover and on keyboard focus. The icon and cover pickers are popovers that close with Escape.
- A database page's properties are a description list of names and values.