Tone
Brand voice rewriting card with Friendly, Confident, and Empathetic voice chips, discrete three-step Formality and Detail sliders, height-reserved sentence crossfades, word-level diff highlights, and one-click Copy.
import { ToneTuner } from '@uthereal/ui/tone-tuner'Tone tuner playground
Overview
ToneTuner rewrites a customer reply or short draft without requiring a free-form prompt. Readers steer the copy with three brand voice preset chips (Friendly, Confident, Empathetic) and two discrete three-step sliders (Formality: Casual, Balanced, Formal; Detail: Brief, Standard, Thorough). Changes debounce cleanly, aborting superseded requests. Only sentences whose words actually changed crossfade in place inside a height-reserved text area so switching voices never resizes the card. A Changes switch highlights added words with semantic <mark> elements alongside a live changed-word counter, and Copy copies the current version.
Use ToneTuner in support reply composers, sales outreach drafts, and marketing copy editors where a few predictable dials outperform a blank prompt box. For open-ended multi-turn editing, use Prompt input.
Usage
'use client'
import { ToneTuner } from '@uthereal/ui/tone-tuner'
export function SupportReplyTuner({ draft }: { draft: string }) {
return (
<ToneTuner
text={draft}
recipient={{
name: 'Sofia Ramirez',
subject: 'Re: Duplicate charge on INV-20481',
}}
rewrite={async ({ text, instructions }, signal) => {
const res = await fetch('/api/rewrite', {
method: 'POST',
signal,
body: JSON.stringify({ text, instructions }),
})
if (!res.ok) throw new Error('The model did not respond')
return (await res.json()).text
}}
onRewrite={(rewritten, settings) => {
console.log('Rewritten', settings, rewritten)
}}
/>
)
}Omit rewrite to tune the built-in billing support reply across all 36 prewritten voice, formality, and detail combinations locally (zero network requests).
Examples
Casual brief rewrite with diff highlights
Start on defaultValue={{ voice: 'friendly', formality: 0, detail: 0 }} with defaultShowChanges={true} to show a rewritten friendly-brief reply immediately with <mark> highlights and the changed-word badge active.
Formal thorough register without highlights
Configure defaultValue={{ voice: 'empathetic', formality: 2, detail: 2 }}, a custom recipient, model, and defaultShowChanges={false} for executive or enterprise replies where full context is needed without diff tinting.
Controls and rewrite behavior
Voice chips and discrete sliders
| Control | Levels / Values | Behavior |
|---|---|---|
| Voice | Friendly, Confident, Empathetic (toggleable) | Pressing a chip activates that voice and moves both sliders to its starting point; pressing the active chip returns to neutral. |
| Formality | 0 Casual · 1 Balanced · 2 Formal | Discrete three-step RangeInput speaking level names in aria-valuetext. |
| Detail | 0 Brief · 1 Standard · 2 Thorough | Discrete three-step RangeInput speaking level names in aria-valuetext. |
| Changes | Boolean Switch | Toggles <mark> background highlights on words added relative to the original draft without shifting text layout. |
| Copy | Button (copyValue) | Copies the current plain text and confirms with a drawn check; disabled automatically when the draft is empty. |
Height reservation and diffing
- An invisible sizer laid into the same CSS grid cell holds the longest voice for the active
formalityanddetaillevels (or the longer oforiginalanddocwith customrewrite), preventing vertical layout shift across voice toggles. - Word-level longest-common-subsequence diffing (
diffDoc) runs against the original draft so added words are wrapped in<mark>elements and counted in the header badge.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
text | string— | The original draft to tune, paired with the React-only rewrite callback. The sample billing reply renders when omitted. |
recipient | ToneRecipientDefault: {"name":"Sofia Ramirez","subject":"Re: Duplicate charge on INV-20481"} | Who the message is for, shown in the header: name, optional avatar URL, optional subject line. Defaults to the sample recipient Sofia Ramirez. |
model | stringDefault: "Claude Sonnet 5.5" | Model name shown in the Rewriting status, for example Claude Sonnet 5.5. |
defaultValue | ToneSettingsDefault: {"formality":1,"detail":1,"voice":"neutral"} | Starting tone when uncontrolled: voice, formality level (0 to 2), detail level (0 to 2). Edits do not reset a mounted instance. |
presets | TonePreset[]Default: [{"voice":"friendly","formality":0,"detail":1,"label":"Friendly"},{"voice":"confident","formality":1,"detail":0,"label":"Confident"},{"voice":"empathetic","formality":1,"detail":2,"label":"Empathetic"}] | Voice chips (Friendly, Confident, Empathetic by default). A chip sets the voice and moves both sliders; pressing the active chip returns to neutral. |
debounceMs | integerDefault: 220 | Quiet time after the last change before a rewrite starts, in milliseconds. |
defaultShowChanges | booleanDefault: true | Highlight words that differ from the original draft on first render. |
autoPlay | booleanDefault: false | Tour the presets while the card is on screen until the first press or focus inside it. Demo opt-in; never runs when a rewrite callback is wired. |
copyLabel | stringDefault: "Copy" | Label of the copy button taking the current version. |
copiedLabel | stringDefault: "Copied" | Label shown briefly after Copy succeeds. |
copyFailedLabel | stringDefault: "Copy failed" | Label shown when the clipboard rejects the copy. |
changesLabel | stringDefault: "Changes" | Visible label of the switch toggling highlights. |
changesSwitchName | stringDefault: "Highlight changes" | Accessible name of the Changes switch. |
voiceGroupLabel | stringDefault: "Voice" | Accessible name of the voice chip group. |
formalityLabel | stringDefault: "Formality" | Accessible name of the formality slider. |
detailLabel | stringDefault: "Detail" | Accessible name of the detail slider. |
wordsLabel | stringDefault: "{count} words" | Word count template; {count} fills the current word total. |
changedWordsLabel | stringDefault: "{count} changed" | Changed-word badge template; {count} fills words that differ from the original. |
originalLabel | stringDefault: "Original draft" | Status pill label before any rewrite. |
rewritingLabel | stringDefault: "Rewriting with {model}" | Status pill label while a rewrite runs; {model} fills the model name. |
rewrittenLabel | stringDefault: "Rewritten" | Status pill label after a rewrite lands. |
notRewrittenLabel | stringDefault: "Couldn’t rewrite" | Status pill label when a rewrite fails. |
retryLabel | stringDefault: "Retry" | Label of the button retrying a failed rewrite. |
emptyLabel | stringDefault: "Add a draft to tune its tone" | Message shown when the draft is empty. |
messageLabel | stringDefault: "Message" | Accessible name of the message preview area. |
simulatedNoteLabel | stringDefault: "Simulated, nothing was sent" | Live-region note when a rewrite came from the built-in sample corpus instead of a host model. |
errorFallbackLabel | stringDefault: "The model did not respond" | Error text when a failed rewrite reports no message of its own. |
rewriteAction | string— | Registered host action requested when a debounced rewrite starts. |
copyAction | string— | Registered host action requested when Copy succeeds. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes preserve interaction behavior. |
theme | ToneTunerThemeDefault: {} | Color mode, accent, and typed semantic token overrides. |
motion | none | subtle | expressiveDefault: "subtle" | Animation preset. System reduced-motion preferences take precedence. |
motionOptions | ToneTunerMotionOptionsDefault: {} | Sentence crossfade, reserved-height spring, and status swap timing overrides in milliseconds. |
dir | ltr | rtl— | Reading direction; inherited from the page when omitted. |
ToneSettingsaccepts{ voice: 'neutral' | 'friendly' | 'confident' | 'empathetic', formality: 0 | 1 | 2, detail: 0 | 1 | 2 }.TonePresetaccepts{ voice: 'friendly' | 'confident' | 'empathetic', label, formality, detail }with uniquevoicevalues (1–6chips).ToneRecipientaccepts{ name, avatar?, subject? }.
React integration
| Prop | Purpose |
|---|---|
value / onValueChange | Controlled ToneSettings and immediate change callback (fires before debounceMs). |
rewrite(request, signal) | Calls your model with { text, formality, detail, voice, instructions } and resolves to plain text; superseded calls abort signal. |
onRewrite(text, value) | Fires after a rewrite lands with the resulting plain text and settings. |
onCopy(text) | Fires after Copy succeeds with the copied plain text. |
showChanges / onShowChangesChange | Controlled boolean and change callback for the Changes switch. |
onAction(action) | Called with rewriteAction when a debounced rewrite begins or copyAction when Copy succeeds. |
preset | Application defaults overridden by explicit instance arguments. |
tokens | CSS variables applied after the typed theme, forwarded to the root card, avatar, sliders, switch, and copy button. |
ref, className, style | Applied to the root <div> element. |
| Native attributes | id, aria-*, data-*, and remaining <div> props forwarded to the root element. |
Keyboard & accessibility
| Key | Action |
|---|---|
Tab | Moves across the voice toggle chips, Formality slider, Detail slider, Changes, and Copy. |
Enter / Space | Toggles the focused voice chip, flips Changes, activates Retry, or copies the message. |
ArrowLeft / ArrowRight | Steps the focused slider between its three named levels (respects RTL). |
Home / End | Jumps the focused slider to its first (0) or last (2) level. |
- Voice chips are native toggle buttons (
aria-pressed) inside arole="group"named byvoiceGroupLabel. - Both sliders speak human-readable level names (
"Casual","Balanced","Formal"/"Brief","Standard","Thorough") rather than raw integers. - Added words use semantic
<mark>elements paired with a changed-word count badge in the header so differences never rely on color alone. - A pre-mounted polite
role="status"live region announces landed rewrites with their voice and slider settings (plus"Simulated, nothing was sent."offline) and rewrite failures. - Container queries adapt the card below
520px(stacking sliders into one column and hiding status detail text) and below440px(dropping chip icons and changed-word count, and wrapping footer controls cleanly without horizontal overflow).
Motion & theming
Each changed sentence fades out (120ms), swaps while invisible on a shared frame so paragraphs reflow out of sight, and fades back in (160ms); unchanged sentences never animate. When a slider changes the reserved height, the text container eases smoothly on the zero-bounce smooth spring (0.4s) while width resizes cut immediately.
Under prefers-reduced-motion: reduce, height springs, status shimmer, chip press scale, and the optional autoPlay tour turn off while sentence and status swaps keep 120ms opacity crossfades. Setting motion="none" swaps sentences and status immediately (0ms) and disables shimmer and press scale.
theme accepts mode, accent, and typed tokens across these groups:
| Token group | CSS custom properties |
|---|---|
core | --ui-surface, --ui-surface-raised, --ui-text, --ui-text-secondary, --ui-muted, --ui-border, --ui-highlight, --ui-accent, --ui-accent-foreground, --ui-danger, --ui-focus-ring, --ui-radius, --ui-border-width, --ui-shadow, --ui-disabled-opacity, --ui-font, --ui-font-size, --ui-font-weight |
extended | --ui-surface-sunken, --ui-border-strong, --ui-border-subtle, --ui-track, --ui-info, --ui-success, --ui-warning, --ui-tone-foreground, --ui-overlay, --ui-tint-strength |
shape | --ui-radius-sm, --ui-popup-radius, --ui-surface-radius |
control | --ui-control-height, --ui-control-padding-x, --ui-control-gap, --ui-icon-size |
An application-wide UtherealProvider supplies defaults.
Composition
In an agent composition, ToneTuner is a leaf block. Configure recipient, model, defaultValue, presets, defaultShowChanges, and registered host actions (rewriteAction, copyAction). See Building with agents.
{
"type": "ToneTuner",
"props": {
"recipient": {
"name": "Sofia Ramirez",
"subject": "Re: Duplicate charge on INV-20481"
},
"model": "Claude Sonnet 5.5",
"defaultValue": {
"voice": "friendly",
"formality": 0,
"detail": 1
},
"defaultShowChanges": true,
"rewriteAction": "rewrite_reply_tone",
"copyAction": "copy_tuned_reply"
},
"children": []
}