diff --git a/.oxlintrc.json b/.oxlintrc.json index fce8518f9c..22a60ef1c2 100644 --- a/.oxlintrc.json +++ b/.oxlintrc.json @@ -101,6 +101,7 @@ "maple/no-raw-shadow": "error", "maple/no-transition-all": "error", "maple/single-tooltip-delay": "error", + "maple/one-save-bar": "error", "maple/tone-alpha-steps": "error", "maple/no-raw-color": "error", "maple/no-arbitrary-text-size": "error", diff --git a/apps/web/src/lab/entries/kit/buttons.ts b/apps/web/src/lab/entries/kit/buttons.ts index cac28fd6be..c0ad1a6698 100644 --- a/apps/web/src/lab/entries/kit/buttons.ts +++ b/apps/web/src/lab/entries/kit/buttons.ts @@ -19,6 +19,7 @@ import { textLink } from "@maple/views/ui/text-link" import { typography } from "@maple/views/ui/typography" import * as Toggle from "@maple/views/ui/toggle" import * as ToggleGroup from "@maple/views/ui/toggle-group" +import { saveBar } from "../../../page/kit/save-bar" import { defineLab } from "../../define" import { kitPage, kitRow, kitSection } from "../../kit/kit-layout" @@ -403,17 +404,31 @@ const cardButtons = (h: HtmlBuilder): Html => /** The kit action bar in its three uses; `static` so the lab shows them in place, not stuck. */ const actionBars = (h: HtmlBuilder): ReadonlyArray => [ kitRow(h, "Unsaved changes (settings save bar)", [ - actionBar(h, { - label: "Unsaved changes", - className: "static w-full", - leading: [ - statusDot(h, { tone: "live" }), - typography(h, { size: "sm", tone: "foreground" }, ["Unsaved changes"]), - ], - actions: [ - button(h, { variant: "ghost", size: "sm" }, ["Discard"]), - button(h, { size: "sm" }, ["Save"]), - ], + ...saveBar(h, { + isDirty: true, + className: "static", + onDiscard: Message.ClickedRefresh(), + onSave: Message.ClickedRefresh(), + }), + ]), + kitRow(h, "Save bar, with context", [ + ...saveBar(h, { + isDirty: true, + className: "static", + changeCount: 2, + context: "Applies to 3 members on their next request.", + saveLabel: "Save role", + onDiscard: Message.ClickedRefresh(), + onSave: Message.ClickedRefresh(), + }), + ]), + kitRow(h, "Save bar, saving", [ + ...saveBar(h, { + isDirty: true, + isPending: true, + className: "static", + onDiscard: Message.ClickedRefresh(), + onSave: Message.ClickedRefresh(), }), ]), kitRow(h, "Editor, with a notice", [ diff --git a/apps/web/src/page/kit/save-bar.ts b/apps/web/src/page/kit/save-bar.ts index f48276079e..328ad7c201 100644 --- a/apps/web/src/page/kit/save-bar.ts +++ b/apps/web/src/page/kit/save-bar.ts @@ -5,12 +5,18 @@ import { statusDot } from "@maple/views/ui/status-dot" import { typography } from "@maple/views/ui/typography" import { actionBar } from "@maple/views/ui/action-bar" -// Pinned while a settings tab has unsaved edits. TODO(settings): confirm before navigating away -// (and the browser's beforeunload prompt) needs a root-level navigation blocker. +// Floats while a settings tab has unsaved edits; Mod+S presses its Save (the shell's `globalShortcuts`). +// TODO(settings): confirm before navigating away (and the browser's beforeunload prompt) needs a +// root-level navigation blocker. + +/** Marks the button Mod+S presses: the one save bar on the page. */ +export const SAVE_SHORTCUT_ATTRIBUTE = "shortcut-save" export type SaveBarOptions = Readonly<{ isDirty: boolean isPending?: boolean + /** How many edits are unsaved, when the page counts them ("2 unsaved changes"). */ + changeCount?: number context?: string onDiscard: M onSave: M @@ -19,19 +25,40 @@ export type SaveBarOptions = Readonly<{ className?: string }> +// The pill's buttons take its corners, so the hover fill follows the curve. +const PILL_BUTTON = "rounded-full before:rounded-full" + +const statusOf = (count: number | undefined): string => + count === undefined ? "Unsaved changes" : `${count} unsaved ${count === 1 ? "change" : "changes"}` + export const saveBar = (h: HtmlBuilder, options: SaveBarOptions): ReadonlyArray => { const isPending = options.isPending ?? false if (!options.isDirty && !isPending) return [] return [ actionBar(h, { label: "Unsaved changes", + shape: "pill", className: cn("mt-6", options.className), leading: [ - statusDot(h, { tone: "live" }), - typography(h, { size: "sm", tone: "foreground", className: "shrink-0" }, ["Unsaved changes"]), - ...(options.context === undefined + statusDot(h, { tone: isPending ? "neutral" : "live" }), + typography(h, { size: "sm", tone: "foreground", className: "shrink-0 whitespace-nowrap" }, [ + isPending ? "Saving changes" : statusOf(options.changeCount), + ]), + // The context is a hint; a phone keeps the status and both buttons on one line instead. + ...(options.context === undefined || options.context.length === 0 ? [] - : [typography(h, { size: "sm", tone: "muted", truncate: true }, [options.context])]), + : [ + typography( + h, + { + size: "sm", + tone: "muted", + truncate: true, + className: "max-w-64 max-sm:hidden", + }, + [options.context], + ), + ]), ], actions: [ button( @@ -39,6 +66,7 @@ export const saveBar = (h: HtmlBuilder, options: SaveBarOptions): Reado { variant: "ghost", size: "sm", + className: PILL_BUTTON, isDisabled: isPending, attributes: [h.OnClick(options.onDiscard)], }, @@ -48,9 +76,14 @@ export const saveBar = (h: HtmlBuilder, options: SaveBarOptions): Reado h, { size: "sm", + className: PILL_BUTTON, isLoading: isPending, isDisabled: options.isSaveDisabled ?? false, - attributes: [h.OnClick(options.onSave)], + attributes: [ + h.OnClick(options.onSave), + h.DataAttribute(SAVE_SHORTCUT_ATTRIBUTE, ""), + h.Attribute("aria-keyshortcuts", "Meta+S Control+S"), + ], }, [options.saveLabel ?? "Save"], ), diff --git a/apps/web/src/shell/command.ts b/apps/web/src/shell/command.ts index 85c0ca7519..0a999e2823 100644 --- a/apps/web/src/shell/command.ts +++ b/apps/web/src/shell/command.ts @@ -4,6 +4,7 @@ import { Command } from "foldkit" import { load } from "foldkit/navigation" import { clearSessionToken } from "../platform/auth-api" import { Message, Theme } from "./message" +import { SAVE_SHORTCUT_ATTRIBUTE } from "../page/kit/save-bar" /** `maple.global-namespace.`. */ export const NAMESPACE_STORAGE_PREFIX = "maple.global-namespace." @@ -161,6 +162,16 @@ export const LogOut = Command.define("LogOut", { * A page tags its primary search with `data-shortcut-focus="search"`. A field is * focused and selected; anything else (an Advanced Filter trigger) is clicked. */ +/** Presses the save bar's Save, unless it is disabled or already saving. */ +export const PressSaveBar = Command.define("PressSaveBar", { + messages: [Message.CompletedSaveShortcut], + execute: Effect.sync(() => { + const target = document.querySelector(`[data-${SAVE_SHORTCUT_ATTRIBUTE}]`) + if (target instanceof HTMLButtonElement && !target.disabled) target.click() + return Message.CompletedSaveShortcut() + }), +}) + export const FocusShortcutSearch = Command.define("FocusShortcutSearch", { messages: [Message.CompletedFocusShortcutSearch], execute: Effect.sync(() => { diff --git a/apps/web/src/shell/message.ts b/apps/web/src/shell/message.ts index 7bdf5fc2e3..dd95705f26 100644 --- a/apps/web/src/shell/message.ts +++ b/apps/web/src/shell/message.ts @@ -124,6 +124,9 @@ export const Message = defineMessageUnion({ PressedThemeKey: {}, PressedFocusSearchKey: {}, CompletedFocusShortcutSearch: {}, + /** Mod+S while the page shows a save bar. */ + PressedSaveShortcut: {}, + CompletedSaveShortcut: {}, GotPaletteMessage: { message: Palette.Message }, GotShortcutsDialogMessage: { message: Dialog.Message }, MeasuredShortcutsPanel: {}, diff --git a/apps/web/src/shell/palette/global-shortcuts.test.ts b/apps/web/src/shell/palette/global-shortcuts.test.ts index 49820d381b..77735170a0 100644 --- a/apps/web/src/shell/palette/global-shortcuts.test.ts +++ b/apps/web/src/shell/palette/global-shortcuts.test.ts @@ -27,6 +27,13 @@ describe("global shortcuts", () => { expect(step(opened, Message.PressedPaletteShortcut()).model.palette).toBe(opened.palette) }) + test("Mod+S presses the page's save bar and changes nothing in the shell", () => { + const model = signedIn() + const pressed = step(model, Message.PressedSaveShortcut()) + expect(commandNames(pressed)).toEqual(["PressSaveBar"]) + expect(pressed.model).toBe(model) + }) + test("Escape unmounts the palette and starts the services read's idle TTL", () => { const opened = step(signedIn(), Message.ClickedSearch()).model const closed = step( diff --git a/apps/web/src/shell/palette/shortcuts.ts b/apps/web/src/shell/palette/shortcuts.ts index 206eb3ae4b..3540e4b015 100644 --- a/apps/web/src/shell/palette/shortcuts.ts +++ b/apps/web/src/shell/palette/shortcuts.ts @@ -31,6 +31,7 @@ const key = (name: string): Combo => ({ key: name }) export const SHORTCUTS: ReadonlyArray = [ { label: "Open command palette", group: "Global", combo: { modifiers: ["Mod"], key: "K" } }, { label: "Show keyboard shortcuts", group: "Global", combo: key("?"), display: ["?"] }, + { label: "Save unsaved changes", group: "Global", combo: { modifiers: ["Mod"], key: "S" } }, { label: "Toggle dark / light mode", group: "Global", combo: key("T") }, { label: "Focus search", group: "Search & time", combo: key("/") }, { label: "Open time range picker", group: "Search & time", combo: key("D") }, diff --git a/apps/web/src/shell/subscription.ts b/apps/web/src/shell/subscription.ts index 5c10bb2945..ddbe506161 100644 --- a/apps/web/src/shell/subscription.ts +++ b/apps/web/src/shell/subscription.ts @@ -5,6 +5,7 @@ import { DASHBOARD_FAVORITES_EVENT, readDashboardFavorites } from "./favorites" import { Message } from "./message" import type { Model } from "./model" import { ONCALL_CHANGED_EVENT } from "../page/alerts/shared/oncall-schedules" +import { SAVE_SHORTCUT_ATTRIBUTE } from "../page/kit/save-bar" /** `max-md`: below 768px the sidebar is a sheet. */ export const MOBILE_QUERY = "(max-width: 767px)" @@ -42,7 +43,8 @@ export const sidebarShortcut: Stream.Stream = Dom.streamFromEventFilter }) /** - * The document keydown: Mod+K opens the palette anywhere; `?`, `T` and `/` only + * The document keydown: Mod+K opens the palette anywhere, Mod+S presses the save bar's Save (in a + * field too) when the page shows one; `?`, `T` and `/` only * outside fields and dialogs, and not after an element handled the key (stopped propagation). */ export const globalShortcuts: Stream.Stream = Dom.streamFromEventFilterMap({ @@ -54,6 +56,13 @@ export const globalShortcuts: Stream.Stream = Dom.streamFromEventFilter event.preventDefault() return Option.some(Message.PressedPaletteShortcut()) } + if ((event.metaKey || event.ctrlKey) && !event.altKey && !event.shiftKey && key === "s") { + if (isDialogOpen() || document.querySelector(`[data-${SAVE_SHORTCUT_ATTRIBUTE}]`) === null) + return Option.none() + // The browser's "Save page" is never what Mod+S means while edits are unsaved. + event.preventDefault() + return Option.some(Message.PressedSaveShortcut()) + } if ( event.defaultPrevented || isEditableTarget(event.target) || diff --git a/apps/web/src/shell/update.ts b/apps/web/src/shell/update.ts index acfbe700cd..91f53c388a 100644 --- a/apps/web/src/shell/update.ts +++ b/apps/web/src/shell/update.ts @@ -15,6 +15,7 @@ import { FocusElement, FocusSiblingMenuItem, FocusShortcutSearch, + PressSaveBar, LogOut, SaveCollapsedNavGroups, SaveNoSchedules, @@ -639,6 +640,8 @@ const foldMessage = (model: Model, message: Message): UpdateReturn => PressedThemeKey: () => toggleTheme(model), PressedFocusSearchKey: () => ({ model, commands: [FocusShortcutSearch()] }), CompletedFocusShortcutSearch: () => ({ model }), + PressedSaveShortcut: () => ({ model, commands: [PressSaveBar()] }), + CompletedSaveShortcut: () => ({ model }), GotPaletteMessage: ({ message: child }) => paletteStep(model, child), GotShortcutsDialogMessage: ({ message: child }) => shortcutsDialogStep(model, child), MeasuredShortcutsPanel: () => ({ model }), diff --git a/docs/design-rules.md b/docs/design-rules.md index 5994d3de21..d980a5d331 100644 --- a/docs/design-rules.md +++ b/docs/design-rules.md @@ -33,7 +33,10 @@ only shrink (`bun run ui:patterns:check` in CI). The workflow is in `apps/web/CL - A form, editor or step flow pins its actions in the kit `actionBar`: a floating card at the bottom of the scroll area, status or Back on the left, buttons on the right, primary last. The settings - `saveBar` is an `actionBar` that shows while edits are unsaved. A hand-built sticky bottom bar is + `saveBar` is the `pill` shape of `actionBar`: a compact, centred float that shows while edits + are unsaved, with Mod+S to save. Every unsaved-edits bar is `saveBar` (`changeCount`, `context` + and `saveLabel` cover the variations); an `actionBar` labelled "Unsaved changes" is flagged + (`maple/one-save-bar`). A hand-built sticky bottom bar is flagged (`maple/no-handrolled-kit-look`). - A side sheet's width is its `size`, picked by what it holds: `default` a filter list or a few fields, `detail` a peek at one item, `form` a create or edit form, `wide` a log, review or guide, @@ -75,6 +78,7 @@ Depth comes from surfaces and the hairline. The only shadows are tokens, colour | ------------------------------------------------- | --------------------------------------------------------------------- | | `shadow-raised` | A control or card lifted off its surface | | `shadow-popup` | Menus, popovers, selects, dialogs, sheets, toasts | +| `shadow-float` | A bar floating over its page (the `actionBar` pill), deep in dark | | `shadow-control` | A control's 1px highlight (a shade in light, a line of light in dark) | | `shadow-accent-start` | The current row's leading accent bar | | `shadow-overflow-up` | A sticky footer over scrolled content | diff --git a/packages/ui/src/styles/tokens.css b/packages/ui/src/styles/tokens.css index 6d0e41f066..b55eb26278 100644 --- a/packages/ui/src/styles/tokens.css +++ b/packages/ui/src/styles/tokens.css @@ -249,6 +249,8 @@ --border-raised: color-mix(in oklab, var(--border) 60%, transparent); /* The shade under a raised control or card: faint on white, deeper on a dark surface. */ --raised-shade: oklch(0 0 0 / 5%); + /* Under a bar floating over the page it sits on (the save pill): a soft lift in light. */ + --float-shade: 0 8px 24px -6px oklch(0 0 0 / 14%), 0 2px 6px -2px oklch(0 0 0 / 8%); /* A keycap (`kbd`): its face, and its layers: a hairline ring, a lit top edge, a darker bottom lip and a 1px drop, so it reads as a key standing on any surface. */ --key: oklch(1 0 0); @@ -406,6 +408,8 @@ --scrim-panel: oklch(0 0 0 / 24%); --border-raised: oklch(1 0 0 / 10%); --raised-shade: oklch(0 0 0 / 35%); + /* A dark page needs real black under a float, or rows scrolling past read as level with it. */ + --float-shade: 0 12px 32px -8px oklch(0 0 0 / 65%), 0 2px 8px -2px oklch(0 0 0 / 45%); --key: color-mix(in oklab, var(--foreground) 10%, var(--popover)); --key-shade: 0 0 0 1px oklch(1 0 0 / 6%), inset 0 1px 0 oklch(1 0 0 / 10%), inset 0 -1px 0 oklch(0 0 0 / 30%), @@ -521,11 +525,13 @@ --radius-2xl-inset: calc(var(--radius-2xl) - 1px); /* Depth comes from surfaces and the hairline; these are the only shadows. `raised` lifts a control or card off its surface, `popup` floats menus, popovers, dialogs and toasts, - `control` is a control's 1px highlight (swaps per theme), `accent-start` marks the current - row's leading edge. Tailwind's sizes and raw `shadow-[…]` are lint errors. */ + `float` lifts the save pill over the page, `control` is a control's 1px highlight (swaps + per theme), `accent-start` marks the current row's leading edge. Tailwind's sizes and raw + `shadow-[…]` are lint errors. */ --shadow-raised: 0 1px 2px 0 var(--raised-shade); --shadow-popup: 0 10px 15px -3px oklch(0 0 0 / 5%), 0 4px 6px -4px oklch(0 0 0 / 5%); --shadow-control: var(--control-highlight); + --shadow-float: var(--float-shade); --shadow-accent-start: inset 2px 0 0 var(--color-primary); /* A sticky footer lifting over content scrolled under it. */ --shadow-overflow-up: 0 -6px 12px oklch(0 0 0 / 35%); diff --git a/packages/views/src/ui/INDEX.md b/packages/views/src/ui/INDEX.md index f0eea1608e..5075a1db33 100644 --- a/packages/views/src/ui/INDEX.md +++ b/packages/views/src/ui/INDEX.md @@ -317,7 +317,7 @@ existing copies onto it (see `apps/web/CLAUDE.md`). - `apps/web/src/page/kit/route-window.ts` `isWindowChange`, `snapModeOf`, `routeWindowStep`: A page's time window across `routeChanged`: re-resolved only when its own fields moved, and only Reload revalidates unchanged keys. - `apps/web/src/page/kit/row-warning.ts` `rowWarning`, `rowWarnings`: A list row's warning: a small glyph and a few words in the warning tone, under the row's name. - `apps/web/src/page/kit/ruled-section.ts` `ruledSection`: A section set off from the content above it by a full-width rule, its children stacked 12px apart. -- `apps/web/src/page/kit/save-bar.ts` `saveBar`: Pinned while a settings tab has unsaved edits. +- `apps/web/src/page/kit/save-bar.ts` `saveBar`: Floats while a settings tab has unsaved edits; Mod+S presses its Save (the shell's `globalShortcuts`). - `apps/web/src/page/kit/saved-views/index.ts` `loadCommand`, `pageStep`: Saved views as a Submodel: the Views button an explorer's toolbar embeds (`/logs`, `/traces`, `/metrics`), with its menu and its save, rename and delete dialogs. - `apps/web/src/page/kit/saved-views/model.ts` `activeViewOf`, `remembered`: The Views control an explorer embeds (`/logs`, `/traces`, `/metrics`): its menu, the views it lists, and the save, rename and delete dialogs. - `apps/web/src/page/kit/saved-views/state.ts` `searchParamsOf`, `readSearch`, `memoHref`: What a saved view stores and how it is read back: the explorer's URL search params, and nothing that is not in the URL. diff --git a/packages/views/src/ui/action-bar.ts b/packages/views/src/ui/action-bar.ts index 811a75a5db..6acab24930 100644 --- a/packages/views/src/ui/action-bar.ts +++ b/packages/views/src/ui/action-bar.ts @@ -1,5 +1,6 @@ import { cn } from "@maple/ui/lib/utils" import type { Attribute, Html, HtmlBuilder } from "foldkit/html" +import { separator } from "./display" import { hstack, vstack } from "./stack" // `ActionBar`: the one sticky bar a form, editor or step flow pins to the bottom of its scroll area: @@ -12,8 +13,13 @@ export type ActionBarOptions = Readonly<{ leading?: ReadonlyArray /** Buttons on the right, primary last. */ actions: ReadonlyArray - /** A full-width line above the row, such as a save failure. */ + /** A full-width line above the row, such as a save failure. Card only. */ notice?: ReadonlyArray + /** + * `card` spans the column (step flows, editors with Back and a notice). `pill` is a compact, + * centred float for a short status and two buttons (the save bar). + */ + shape?: "card" | "pill" as?: "section" | "footer" /** Layout only: margins and the sticky offset when the scroll area pads its edge. */ className?: string @@ -26,9 +32,14 @@ export type ActionBarOptions = Readonly<{ const BAR = "sticky bottom-4 z-10 mt-auto rounded-lg border bg-popover py-2 pr-2 pl-4 text-popover-foreground shadow-popup after:pointer-events-none after:absolute after:-inset-x-px after:top-full after:h-4 after:bg-(--action-bar-backdrop,var(--color-background)) after:shadow-backdrop-below" -export const actionBar = (h: HtmlBuilder, options: ActionBarOptions): Html => { - const attributes = [h.AriaLabel(options.label), ...(options.attributes ?? [])] - const row = hstack(h, { gap: "4", align: "center", justify: "between", wrap: true }, [ +// Narrow and centred, so it never lines up with the cards and reads as one more of them. It lifts +// a step in dark (the popover barely clears the page) and takes a deeper shade, so rows scrolling +// under it stay behind it without a backdrop strip. It rises in once; reduced motion just shows it. +const PILL = + "sticky bottom-4 z-10 mt-auto mx-auto w-fit max-w-full self-center rounded-full border border-input bg-popover py-1 pr-1 pl-3.5 text-popover-foreground shadow-float before:pointer-events-none before:absolute before:inset-0 before:rounded-full before:shadow-control dark:bg-secondary animate-in fade-in-0 slide-in-from-bottom-3 zoom-in-97 duration-300 ease-out motion-reduce:animate-none sm:bottom-6" + +const cardRow = (h: HtmlBuilder, options: ActionBarOptions): Html => + hstack(h, { gap: "4", align: "center", justify: "between", wrap: true }, [ hstack(h, { gap: "2", align: "center", shrink: true }, [...(options.leading ?? [])]), // The buttons wrap onto a second line on a narrow screen rather than run past the edge. hstack( @@ -37,13 +48,30 @@ export const actionBar = (h: HtmlBuilder, options: ActionBarOptions): H options.actions, ), ]) + +// One line that never wraps: the status gives way (it truncates) before the buttons do. +const pillRow = (h: HtmlBuilder, options: ActionBarOptions): Html => + hstack(h, { gap: "2", align: "center" }, [ + hstack(h, { gap: "2", align: "center", shrink: true, className: "min-w-0" }, [ + ...(options.leading ?? []), + ]), + // The rule takes the pill's border tone (`border` vanishes on the lifted dark fill) and extra room on + // its left, since the ghost button's padding already sits on its right. + separator(h, "vertical", "ml-1 h-4 self-center bg-input"), + hstack(h, { gap: "1", align: "center", className: "shrink-0" }, options.actions), + ]) + +export const actionBar = (h: HtmlBuilder, options: ActionBarOptions): Html => { + const isPill = options.shape === "pill" + const attributes = [h.AriaLabel(options.label), ...(options.attributes ?? [])] + const row = isPill ? pillRow(h, options) : cardRow(h, options) const children = - options.notice === undefined || options.notice.length === 0 + isPill || options.notice === undefined || options.notice.length === 0 ? [row] : [vstack(h, { gap: "2", className: "pt-1" }, [...options.notice, row])] return vstack( h, - { as: options.as ?? "section", className: cn(BAR, options.className), attributes }, + { as: options.as ?? "section", className: cn(isPill ? PILL : BAR, options.className), attributes }, children, ) } diff --git a/scripts/oxlint-plugins/design-rules.mjs b/scripts/oxlint-plugins/design-rules.mjs index f9074f443b..3d48415d50 100644 --- a/scripts/oxlint-plugins/design-rules.mjs +++ b/scripts/oxlint-plugins/design-rules.mjs @@ -66,6 +66,7 @@ const SHADOW_TOKENS = new Set([ "overflow-up", "rule-bottom", "backdrop-below", + "float", "key", "none", ]) @@ -84,7 +85,7 @@ const isRawShadow = (token) => { const noRawShadow = ratcheted("no-raw-shadow", { description: "Depth comes from surfaces, the hairline and the shadow tokens.", message: - "`{{token}}` is not a shadow token. Use `shadow-raised`, `shadow-popup`, `shadow-control`, `shadow-accent-start`, `shadow-overflow-up`, `shadow-rule-bottom`, `shadow-backdrop-below` or `shadow-key` (inset: `inset-shadow-highlight`, `inset-shadow-pressed`). A shadow's colour is part of its token; a new depth gets a new token in tokens.css.", + "`{{token}}` is not a shadow token. Use `shadow-raised`, `shadow-popup`, `shadow-float`, `shadow-control`, `shadow-accent-start`, `shadow-overflow-up`, `shadow-rule-bottom`, `shadow-backdrop-below` or `shadow-key` (inset: `inset-shadow-highlight`, `inset-shadow-pressed`). A shadow's colour is part of its token; a new depth gets a new token in tokens.css.", collect: (_context, push) => classStrings((node, tokens) => { for (const token of tokens) if (isRawShadow(splitToken(token).utility)) push(node, { token }) @@ -254,6 +255,38 @@ const singleTooltipDelay = { }, } +// Every page with unsaved edits shows the same pill, built in one place. +const SAVE_BAR_HOME = "apps/web/src/page/kit/save-bar.ts" + +const oneSaveBar = { + meta: { + type: "problem", + docs: { description: "An unsaved-changes bar is the kit `saveBar`." }, + messages: { + bad: "Show unsaved edits with `saveBar` (`apps/web/src/page/kit/save-bar.ts`), not an `actionBar` of your own: `changeCount`, `context` and `saveLabel` cover the variations, so every page shows the same pill.", + }, + }, + create(context) { + if ((context.filename ?? context.getFilename()).replaceAll("\\", "/").endsWith(SAVE_BAR_HOME)) + return {} + return { + CallExpression(node) { + if (node.callee.type !== "Identifier" || node.callee.name !== "actionBar") return + const options = node.arguments[1] + if (options?.type !== "ObjectExpression") return + for (const property of options.properties) + if ( + property.type === "Property" && + property.key.name === "label" && + property.value.type === "Literal" && + property.value.value === "Unsaved changes" + ) + context.report({ node, messageId: "bad" }) + }, + } + }, +} + const noDimmedIcon = { meta: { type: "problem", @@ -503,6 +536,7 @@ export const designRules = { "no-dimmed-icon": noDimmedIcon, "no-raw-shadow": noRawShadow, "no-transition-all": noTransitionAll, + "one-save-bar": oneSaveBar, "single-tooltip-delay": singleTooltipDelay, "tone-alpha-steps": toneAlphaSteps, }