feat(app): try session header separators from an Experiments tab (#57568)

This commit is contained in:
Kit Langton
2026-10-20 22:04:36 -07:00
committed by GitHub
Unverified
parent 6a28455553
commit 409d6bb710
5 changed files with 142 additions and 8 deletions
+8 -1
View File
@@ -23,7 +23,7 @@ export function mountMotionPanel(container: HTMLElement, options: { title?: stri
}
async function start() {
const { action, defineControls, knob, spring, toggle } = await import("knobs")
const { action, choice, defineControls, knob, spring, toggle } = await import("knobs")
const field = (item: MotionKnob) => {
const meta = { label: item.label, group: item.group, tab: item.group === global ? undefined : item.group }
@@ -32,6 +32,8 @@ export function mountMotionPanel(container: HTMLElement, options: { title?: stri
if (item.kind === "toggle") return toggle(item.initial, meta)
if (item.kind === "choice") return choice(item.initial, item.options, { ...meta, labels: item.labels })
return knob(item.initial, { ...meta, min: item.min, max: item.max, step: item.step, unit: item.unit ?? "×" })
}
@@ -46,6 +48,11 @@ export function mountMotionPanel(container: HTMLElement, options: { title?: stri
return motionTuning.set(item, value as boolean)
}
if (item.kind === "choice") {
// SAFETY: a choice knob's field is a choice field.
return motionTuning.set(item, value as string)
}
// SAFETY: a number knob's field is a number field.
motionTuning.set(item, value as number)
}
+21
View File
@@ -45,3 +45,24 @@ describe("motionTuning.spring", () => {
expect(spring().duration).toBeCloseTo(0.8)
})
})
describe("motionTuning.choice", () => {
test("starts on its shipped option and switches to another", () => {
const choice = motionTuning.choice("test.choice", {
label: "Choice",
group: "Experiments",
value: "b",
labels: { a: "A", b: "B", c: "C" },
})
const knob = motionTuning.list().find((item) => item.id === "test.choice")
if (knob?.kind !== "choice") throw new Error("expected a choice knob")
expect(choice()).toBe("b")
expect(knob.options).toEqual(["a", "b", "c"])
motionTuning.set(knob, "c")
expect(choice()).toBe("c")
})
})
+26 -3
View File
@@ -1,8 +1,8 @@
import type { DurationOptions } from "./motion"
// Live motion settings for developer mode. Each surface registers knobs under its own group with their shipped defaults,
// plus actions that replay its motion; the Motion workspace (`motion-tuning-panel`) shows a section per group. Edits
// persist on this device.
// plus actions that replay its motion; the Motion workspace (`motion-tuning-panel`) shows a section per group. Choices
// in the "Experiments" group are design variants to try before one ships. Edits persist on this device.
type Knob<Kind extends string, Value> = {
kind: Kind
@@ -22,6 +22,7 @@ export type MotionKnob =
| (Knob<"spring", DurationOptions> & { presets: Record<MotionPreset, DurationOptions> })
| Knob<"toggle", boolean>
| (Knob<"number", number> & { min: number; max: number; step: number; unit?: string })
| (Knob<"choice", string> & { options: readonly [string, ...string[]]; labels: Record<string, string> })
export type MotionAction = { id: string; label: string; group: string; run: () => void }
@@ -36,7 +37,7 @@ const actions = new Map<string, MotionAction>()
const listeners = new Set<() => void>()
// Saved as numbers only: `<id>.duration` and `<id>.bounce` for springs, 0 or 1 for toggles.
// Saved as numbers only: `<id>.duration` and `<id>.bounce` for springs, 0 or 1 for toggles, the option's index for choices.
const saved = load()
export const motionTuning = {
@@ -71,6 +72,25 @@ export const motionTuning = {
return () => knob.value
},
/** One of several named variants, such as a design experiment. `labels` maps each option to what the panel shows. */
choice<const T extends string>(id: string, meta: Meta & { value: NoInfer<T>; labels: Record<T, string> }) {
// SAFETY: a labels record always has at least the initial value's key.
const options = Object.keys(meta.labels) as [T, ...T[]]
const knob = register({
kind: "choice",
id,
label: meta.label,
group: meta.group,
initial: meta.value,
value: options[number(id, options.indexOf(meta.value))] ?? meta.value,
options,
labels: meta.labels,
})
// SAFETY: the panel only sets one of the knob's options.
return () => knob.value as T
},
/**
* A tuned number. A `time` of "duration" is seconds, stretched by the global speed and slow motion; "rate" is per
* second, so it shrinks by the same factor.
@@ -194,6 +214,9 @@ function save() {
if (knob.kind === "toggle") return [[knob.id, Number(knob.value), Number(knob.initial)]]
if (knob.kind === "choice")
return [[knob.id, knob.options.indexOf(knob.value), knob.options.indexOf(knob.initial)]]
return [[knob.id, knob.value, knob.initial]]
})
.flatMap(([id, value, initial]) => (value === initial ? [] : [[id, value]]))