UI

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

Sofia RamirezRe: Duplicate charge on INV-20481

Hello Sofia,

Thank you for reporting the duplicate charge on your October invoice. We have refunded the extra $1,240.00, and it should reach your card within 5 to 10 business days.

Let me know if anything else looks wrong.

Best,Jordan

Original draft
Original draft.
Loading interactive preview…

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.

Sofia RamirezRe: Duplicate charge on INV-20481

Hi Sofia,

Thanks so much for the heads up about the double charge, and sorry for the hassle! We've refunded the extra $1,240.

Shout if anything else looks off, happy to help!

Cheers,Jordan

Rewrittenfriendly voice, casual, brief
Rewritten: friendly voice, casual, brief. Simulated, nothing was sent.

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.

Marcus LindholmRe: Annual enterprise renewal & SLA addendum

Dear Ms. Ramirez,

Please accept our apologies for the duplicate charge. We understand how disruptive this is at month end. A full refund of $1,240.00 has been issued to your card ending 4417 and should appear on your statement within 5 to 10 business days. The cause was a payment retry that ran twice following a timeout; we have since added a safeguard to prevent any recurrence.

Should this have caused any difficulty on your side, please reply and we will make it right.

Kind regards,Jordan Reyes, Billing support

Rewrittenempathetic voice, formal, thorough
Rewritten: empathetic voice, formal, thorough. Simulated, nothing was sent.

Controls and rewrite behavior

Voice chips and discrete sliders

ControlLevels / ValuesBehavior
VoiceFriendly, Confident, Empathetic (toggleable)Pressing a chip activates that voice and moves both sliders to its starting point; pressing the active chip returns to neutral.
Formality0 Casual · 1 Balanced · 2 FormalDiscrete three-step RangeInput speaking level names in aria-valuetext.
Detail0 Brief · 1 Standard · 2 ThoroughDiscrete three-step RangeInput speaking level names in aria-valuetext.
ChangesBoolean SwitchToggles <mark> background highlights on words added relative to the original draft without shifting text layout.
CopyButton (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 formality and detail levels (or the longer of original and doc with custom rewrite), 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.

ArgumentType / defaultDescription
textstring—The original draft to tune, paired with the React-only rewrite callback. The sample billing reply renders when omitted.
recipientToneRecipientDefault: {"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.
modelstringDefault: "Claude Sonnet 5.5"Model name shown in the Rewriting status, for example Claude Sonnet 5.5.
defaultValueToneSettingsDefault: {"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.
presetsTonePreset[]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.
debounceMsintegerDefault: 220Quiet time after the last change before a rewrite starts, in milliseconds.
defaultShowChangesbooleanDefault: trueHighlight words that differ from the original draft on first render.
autoPlaybooleanDefault: falseTour 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.
copyLabelstringDefault: "Copy"Label of the copy button taking the current version.
copiedLabelstringDefault: "Copied"Label shown briefly after Copy succeeds.
copyFailedLabelstringDefault: "Copy failed"Label shown when the clipboard rejects the copy.
changesLabelstringDefault: "Changes"Visible label of the switch toggling highlights.
changesSwitchNamestringDefault: "Highlight changes"Accessible name of the Changes switch.
voiceGroupLabelstringDefault: "Voice"Accessible name of the voice chip group.
formalityLabelstringDefault: "Formality"Accessible name of the formality slider.
detailLabelstringDefault: "Detail"Accessible name of the detail slider.
wordsLabelstringDefault: "{count} words"Word count template; {count} fills the current word total.
changedWordsLabelstringDefault: "{count} changed"Changed-word badge template; {count} fills words that differ from the original.
originalLabelstringDefault: "Original draft"Status pill label before any rewrite.
rewritingLabelstringDefault: "Rewriting with {model}"Status pill label while a rewrite runs; {model} fills the model name.
rewrittenLabelstringDefault: "Rewritten"Status pill label after a rewrite lands.
notRewrittenLabelstringDefault: "Couldn’t rewrite"Status pill label when a rewrite fails.
retryLabelstringDefault: "Retry"Label of the button retrying a failed rewrite.
emptyLabelstringDefault: "Add a draft to tune its tone"Message shown when the draft is empty.
messageLabelstringDefault: "Message"Accessible name of the message preview area.
simulatedNoteLabelstringDefault: "Simulated, nothing was sent"Live-region note when a rewrite came from the built-in sample corpus instead of a host model.
errorFallbackLabelstringDefault: "The model did not respond"Error text when a failed rewrite reports no message of its own.
rewriteActionstring—Registered host action requested when a debounced rewrite starts.
copyActionstring—Registered host action requested when Copy succeeds.
recipestudio | softDefault: "studio"Visual treatment. Both recipes preserve interaction behavior.
themeToneTunerThemeDefault: {}Color mode, accent, and typed semantic token overrides.
motionnone | subtle | expressiveDefault: "subtle"Animation preset. System reduced-motion preferences take precedence.
motionOptionsToneTunerMotionOptionsDefault: {}Sentence crossfade, reserved-height spring, and status swap timing overrides in milliseconds.
dirltr | rtl—Reading direction; inherited from the page when omitted.
  • ToneSettings accepts { voice: 'neutral' | 'friendly' | 'confident' | 'empathetic', formality: 0 | 1 | 2, detail: 0 | 1 | 2 }.
  • TonePreset accepts { voice: 'friendly' | 'confident' | 'empathetic', label, formality, detail } with unique voice values (1–6 chips).
  • ToneRecipient accepts { name, avatar?, subject? }.

React integration

PropPurpose
value / onValueChangeControlled 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 / onShowChangesChangeControlled boolean and change callback for the Changes switch.
onAction(action)Called with rewriteAction when a debounced rewrite begins or copyAction when Copy succeeds.
presetApplication defaults overridden by explicit instance arguments.
tokensCSS variables applied after the typed theme, forwarded to the root card, avatar, sliders, switch, and copy button.
ref, className, styleApplied to the root <div> element.
Native attributesid, aria-*, data-*, and remaining <div> props forwarded to the root element.

Keyboard & accessibility

KeyAction
TabMoves across the voice toggle chips, Formality slider, Detail slider, Changes, and Copy.
Enter / SpaceToggles the focused voice chip, flips Changes, activates Retry, or copies the message.
ArrowLeft / ArrowRightSteps the focused slider between its three named levels (respects RTL).
Home / EndJumps the focused slider to its first (0) or last (2) level.
  • Voice chips are native toggle buttons (aria-pressed) inside a role="group" named by voiceGroupLabel.
  • 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 below 440px (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 groupCSS 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": []
}

On this page