From 6f7d6589e5f3b20d01c78567e16ce2610c8975e3 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Sun, 8 Nov 2026 22:06:33 +0000 Subject: [PATCH 1/2] CONTRACT: feat(ui-kit): let the composer host the hold-to-talk MicButton MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `Composer` gains an optional `micControl?: ReactNode`, a caller-drawn mic (the kit's `MicButton`) in the send and plain field's mic slot (#3727). When it is set, `mic`, `onMic` and `micLabel` are ignored, the slot takes the 44px target with -4px block margins (a 54px field) and the field aligns its controls to the last line of a multi-line draft. Without it, the composer renders as before. Stories cover D1 rest, S1 holding with the hint, S1 with "Talk live…" focused, D6 review on one and three lines (M2: no uncertain mark and no hint-line cue) and the offline "Record on this device" mic (M1: no hold), with a play test that the 320px row does not overflow with the hint showing. The package-api contract component and the API report record the prop. Co-Authored-By: Claude Opus 5.5 --- .changeset/composer-mic-control.md | 5 + api-report/ui-kit.txt | 1 + docs/integration-contract/package-api.md | 14 ++ packages/ui-kit/src/chrome/Composer.tsx | 50 ++++- .../stories/chrome/ComposerMic.stories.tsx | 175 ++++++++++++++++++ .../ui-kit/stories/chrome/_composer-mic.tsx | 49 +++++ .../tests/composer-mic-control.test.tsx | 66 +++++++ .../tests/visual/composer-mic.visual.tsx | 69 +++++++ 8 files changed, 422 insertions(+), 7 deletions(-) create mode 100644 .changeset/composer-mic-control.md create mode 100644 packages/ui-kit/stories/chrome/ComposerMic.stories.tsx create mode 100644 packages/ui-kit/stories/chrome/_composer-mic.tsx create mode 100644 packages/ui-kit/tests/composer-mic-control.test.tsx create mode 100644 packages/ui-kit/tests/visual/composer-mic.visual.tsx diff --git a/.changeset/composer-mic-control.md b/.changeset/composer-mic-control.md new file mode 100644 index 0000000000..8cd0c8251f --- /dev/null +++ b/.changeset/composer-mic-control.md @@ -0,0 +1,5 @@ +--- +"@schlessera/brain-ui-kit": minor +--- + +`Composer` can host the hold-to-talk `MicButton` (#3727). The new optional `micControl` prop places a caller-drawn mic in the mic slot. The field grows from 46px to 54px to fit the 44px target, and on a multi-line draft attach, the mic and Send sit on the last line. While `micControl` is set, `mic`, `onMic` and `micLabel` are ignored. Without it, the composer is unchanged. diff --git a/api-report/ui-kit.txt b/api-report/ui-kit.txt index c029d6ebe4..9149b75e81 100644 --- a/api-report/ui-kit.txt +++ b/api-report/ui-kit.txt @@ -883,6 +883,7 @@ signatures (every public export and the types it is made of) micLabel?: string; micTip?: boolean; micUnavailable?: string; + micControl?: ReactNode; maxRows?: number; } ComposerRecall (packages/ui-kit/src/chrome/Composer.tsx) diff --git a/docs/integration-contract/package-api.md b/docs/integration-contract/package-api.md index 970ded3e13..cb6ac60d63 100644 --- a/docs/integration-contract/package-api.md +++ b/docs/integration-contract/package-api.md @@ -4905,6 +4905,20 @@ an `aria-hidden` pointer tooltip; an inert trigger, including a dictating composer's, has neither. Existing props and defaults are otherwise unchanged, and no wire schema changes. `api-report/` records the added prop. + + +## Composer mic control (additive, 0.45.0, #3727) + +`ComposerProps` in `@schlessera/brain-ui-kit` gains optional +`micControl?: ReactNode`, a caller-drawn mic (the kit's `MicButton`) in the +`send` and `plain` field's mic slot. When it is set, `mic`, `onMic`, +`micLabel`, `micTip` and `micUnavailable` are ignored, the slot takes the +control's 44px target with -4px +block margins (a 54px field), and the field aligns its controls to the last +line of a multi-line draft. The `voice` variant keeps its own disc. Omitted, +the composer renders exactly as before. No wire schema changes. +`api-report/` records the added prop. + ## Prospective trust policy data (additive, #3607) diff --git a/packages/ui-kit/src/chrome/Composer.tsx b/packages/ui-kit/src/chrome/Composer.tsx index 5f01c7edbe..b780836bc4 100644 --- a/packages/ui-kit/src/chrome/Composer.tsx +++ b/packages/ui-kit/src/chrome/Composer.tsx @@ -1,4 +1,4 @@ -import type { CSSProperties, ChangeEvent, KeyboardEvent } from "react"; +import type { CSSProperties, ChangeEvent, KeyboardEvent, ReactNode } from "react"; import { useId } from "react"; import { Icon, type IconName } from "../primitives/Icon.js"; @@ -152,6 +152,14 @@ export interface ComposerProps { * its accessible description and tooltip, and a tap or key does nothing. */ micUnavailable?: string; + /** + * A caller-drawn mic (`MicButton`) in the mic slot (#3727). When set, + * `mic`, `onMic`, `micLabel`, `micTip` and `micUnavailable` are ignored; + * the slot gets margin-block -4px and the field aligns its controls to the + * last line. Absent = today, pixel for pixel. Drawn in the `send` and + * `plain` field; the `voice` variant keeps its own hold-to-talk disc. + */ + micControl?: ReactNode; /** Rows the field may grow to, on ⇧⏎ or on soft wrap, before it scrolls. Five when omitted. */ maxRows?: number; } @@ -183,6 +191,16 @@ const LINE_RATIO = 1.45; const LINE = FONT_SIZE * LINE_RATIO; const CEILING = 96; +/** + * Beside a caller's mic (#3727) the field's controls sit on its last line, + * centred on the mic. The mic slot is 36px tall (its 44px target with -4px + * block margins), so a 28px control rises 4px and the last line of text rises + * by half of what the slot has over one line. + */ +const MIC_SLOT = 36; +const LIFT = (MIC_SLOT - 28) / 2; +const TEXT_LIFT = (MIC_SLOT - LINE) / 2; + /** Each state's placeholder and hint; `why` is the offline reason. */ const STATE: Record = { ready: { ph: "Ask your brain anything…", hint: "⌘K for commands · ⏎ to send · ⇧⏎ for a new line" }, @@ -207,7 +225,10 @@ export function Composer(p: ComposerProps) { const recall = p.recall ?? []; const showAttach = p.attach !== false && v !== "plain"; - const showMic = p.mic !== false && (v === "send" || v === "plain"); + const inField = v === "send" || v === "plain"; + // A caller's mic replaces the kit's, and every prop of the kit's mic stops applying. + const micControl = inField && p.micControl != null && p.micControl !== false; + const showMic = !micControl && p.mic !== false && inField; const voiceReasonId = useId(); const voiceUnavailable = p.micUnavailable !== undefined; const voiceAct = Boolean(p.onMic) || voiceUnavailable; @@ -244,7 +265,9 @@ export function Composer(p: ComposerProps) { flex: 1, minWidth: 0, display: "flex", - alignItems: "center", + // A caller's 44px mic makes the field 54px tall; its controls then sit on + // the last line of a multi-line draft, as Send does in any chat. + alignItems: micControl ? "flex-end" : "center", gap: 8, background: color.surface, // The edge lifts a step while a run is live: the field is busy, not idle. @@ -274,6 +297,7 @@ export function Composer(p: ComposerProps) { // `auto`, not the source's `hidden`: a clipped single-line SPAN is fine, // a clipped input takes the caret off-screen as you type. overflow: "auto", + ...(micControl ? { marginBottom: TEXT_LIFT } : null), }; const disc = (size: number, fill: string, glow: boolean): CSSProperties => ({ @@ -300,6 +324,10 @@ export function Composer(p: ComposerProps) { const stopAct = Boolean(p.onStop); + // Beside a caller's mic, the 28px controls sit on the last line, centred on + // the mic. Spread only then, so the default field is unchanged. + const lastLine: CSSProperties | undefined = micControl ? { marginBottom: LIFT } : undefined; + const mono = (weight: number, size: number): string => `${weight} ${size}px/1.5 ${font.mono}`; const oneLine: CSSProperties = { whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" }; @@ -325,7 +353,7 @@ export function Composer(p: ComposerProps) {
{showAttach ? ( - + ) : null}