# Fine-tune Card

A small inspector for the last adjustments to something an agent made.

A compact inspector an agent hands over for the last adjustments to what it made. It holds a layout switch (our segmented control), scrubbable number fields and a type picker (our select). Drag a field's label to scrub it, or type, or use the arrow and page keys; the value never changes width. Once anything differs from where the card started, the header's "Adjust" hint crossfades to "Edited" with a Reset action, without moving anything. Number fields run the Zag number-input machine, through Ark UI's NumberInput in React, Vue and Svelte.

Kind: block · Category: Agent · Status: beta · Targets: React, Vue, Svelte · Behaviour: Zag `number-input` machine, through Ark UI

## Add

```bash
npx fndn add fine-tune-card
```

It writes the folder `fine-tune-card/` into the project's ui folder (`index.ts`, `fine-tune-card.tsx`, `FineTuneCard.vue`, `FineTuneCard.svelte`, `fine-tune-card.recipe.ts`), and what it is built from: [Segmented Control](/components/segmented-control.md), [Select](/components/select.md), [Button](/components/button.md), [Shimmer](/components/shimmer.md). First time: [Installation](/installation.md).

## Usage

```tsx
import { FineTuneCard } from "@/components/ui/fine-tune-card";
```

```vue
import { FineTuneCard } from "@/components/ui/fine-tune-card";
```

```svelte
import { FineTuneCard } from "$lib/components/ui/fine-tune-card";
```

## Parts

In the DOM the root carries `data-slot="fine-tune-card"` and each part `data-slot="fine-tune-card-<part>"`; in the recipe the root is the `base` slot and each part a slot named after it in camelCase.

| Part | Element | data-slot | Flags | Notes |
| --- | --- | --- | --- | --- |
| `root` | `div` | `fine-tune-card` |  | data-slot="fine-tune-card"; changed (anything differs from where the card started) is a recipe variant |
| `header` | `div` | `fine-tune-card-header` |  |  |
| `title` | `span` | `fine-tune-card-title` |  |  |
| `state` | `div` | `fine-tune-card-state` |  | One grid cell holding both the hint and the edited group, so the swap never moves the header |
| `hint` | `span` | `fine-tune-card-hint` |  | Shown until something changes |
| `hint-icon` | `span` | `fine-tune-card-hint-icon` |  |  |
| `hint-text` | `span` | `fine-tune-card-hint-text` |  | "Adjust": the real Shimmer (speed fast, tone accent), marked data-fine-tune-card="hint-text"; plain accent text under reduced motion |
| `edited` | `span` | `fine-tune-card-edited` |  | Shown once something changes: the edited text and the Reset action |
| `edited-text` | `span` | `fine-tune-card-edited-text` |  |  |
| `reset` | `button` | `fine-tune-card-reset` |  | The real Button (ghost sm), marked data-fine-tune-card="reset"; restores every field default and the layout and type the card started with, then focuses the selected layout segment |
| `status` | `span` | `fine-tune-card-status` |  | role=status, visually hidden (sr-only); says "Edited" when the card becomes edited |
| `body` | `div` | `fine-tune-card-body` |  |  |
| `section` | `span` | `fine-tune-card-section` |  | The "Layout" label |
| `layout` | `div` | `fine-tune-card-layout` |  | The real SegmentedControl (sm, fill, icons), marked data-fine-tune-card="layout" |
| `fields` | `div` | `fine-tune-card-fields` |  | Two-column grid of fields |
| `field` | `div` | `fine-tune-card-field` | repeats | Number-input root, the shared control (`lib/control.ts`: sm, subtle; the ring for any focus); data-key; changed (differs from its default) is a recipe variant; data-focus, data-scrubbing, data-invalid from the engine |
| `scrubber` | `div` | `fine-tune-card-scrubber` |  | Number-input scrubber around the label: press and drag sideways to change the value |
| `field-label` | `label` | `fine-tune-card-field-label` |  |  |
| `input` | `input` | `fine-tune-card-input` |  | role=spinbutton; tabular figures |
| `suffix` | `span` | `fine-tune-card-suffix` | optional |  |
| `footer` | `div` | `fine-tune-card-footer` |  |  |
| `footer-label` | `span` | `fine-tune-card-footer-label` |  | The "Type" label |
| `type` | `div` | `fine-tune-card-type` |  | The real Select (sm, subtle, opens upwards at the end), marked data-fine-tune-card="type" on its root |

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `fields` | `{ key: string; label: string; value: number; min: number; max: number; step?: number; suffix?: string }[]` |  | The number properties, laid out in pairs. `value` is the default, the value Reset returns to. Defaults to W, H, Radius, Opacity. |
| `values` | `object` |  | Bindable (React: `defaultValues` and `onValuesChange`; Vue: `v-model:values`; Svelte: `bind:values`). Current value per field key. A missing key shows the field's default. |
| `layout` | `"row" \| "col" \| "grid"` | `"row"` | Bindable (React: `defaultLayout` and `onLayoutChange`; Vue: `v-model:layout`; Svelte: `bind:layout`). Selected layout segment (reaches the segmented control, not the card's CSS). |
| `type` | `string` |  | Bindable (React: `defaultType` and `onTypeChange`; Vue: `v-model:type`; Svelte: `bind:type`). Selected type, or null for the placeholder. |
| `types` | `{ value: string; label: string }[]` |  | Options of the type picker. Strings are accepted as value = label. Defaults to Default, Featured, Compact. |
| `changed` | `boolean` |  | Bindable (React: `defaultChanged` and `onChangedChange`; Vue: `v-model:changed`; Svelte: `bind:changed`). Shows the edited state and Reset. Uncontrolled it follows the card: true while the layout, the type or any field differs from where the card started; the change event reports every flip. |
| `labels` | `object` |  | Copy: title, layout, row, col, grid, type, placeholder, adjust, edited, reset. |

Other attributes and `class` go to the root; `class` is merged through the recipe.

## Events

| Event | Payload |
| --- | --- |
| `layoutChange` | (layout: "row" \| "col" \| "grid") |
| `valuesChange` | (values: Record<string, number>) |
| `typeChange` | (type: string \| null) |
| `changedChange` | (changed: boolean) |
| `reset` | () |

## States

`changed`, `hover`, `press`, `focus-visible`, `scrubbing`, `invalid`

## Keyboard and accessibility

Role: group of controls: radiogroup (layout), spinbuttons (fields), combobox (type).

Keyboard:

- Tab moves through the layout switch (one stop), each field, Reset when shown, and the type picker
- Layout: ArrowLeft / ArrowRight select, Home / End jump
- Field: ArrowUp / ArrowDown change by one step, with Shift by ten; Page Up / Page Down by ten; Home / End go to the minimum / maximum; typing enters a value, clamped on blur
- Type: the select contract (Enter / Space / ArrowDown open, arrows move, Enter selects, Escape closes)
- Reset: Enter / Space; focus then moves to the selected layout segment

Notes:

- Each field's label is its input's label; the scrubber only adds the drag.
- Scrubbing is a mouse gesture (pointer lock); on touch, type the value.
- Becoming edited is announced once through the role=status region.

## Motion

- hint ⇄ edited: opacity and a 2px blur crossfade over duration.base in one grid cell; no layout change
- field changed / focus: background and ring over duration.base
- hint text: the shared shimmer loop; stops under reduced motion
- layout thumb and type popup: as in segmented-control and select

## Tokens

`color.surface`, `color.line`, `color.ink`, `color.ink-2`, `color.ink-3`, `color.accent`, `color.accent-ink`, `color.accent-tint`, `color.green`, `color.field`, `color.red`, `shadow.raised`, `radius.card`, `radius.chip`, `text.xs`, `text.sm`, `duration.fast`, `duration.base`

## Dependencies

- [Segmented Control](/components/segmented-control.md)
- [Select](/components/select.md)
- [Button](/components/button.md)
- [Shimmer](/components/shimmer.md)

## Examples

### Tune the pricing card it generated

React · `default.tsx`

```tsx
import type { ComponentProps } from "react";
import { FineTuneCard } from "@/components/ui/fine-tune-card";

type Props = ComponentProps<typeof FineTuneCard>;

const fields: Props["fields"] = [
  { key: "width", label: "W", value: 320, min: 200, max: 640 },
  { key: "height", label: "H", value: 440, min: 240, max: 960 },
  { key: "radius", label: "Radius", value: 16, min: 0, max: 48 },
  { key: "gap", label: "Gap", value: 24, min: 0, max: 64 },
];

const plans = ["Starter", "Team", "Business"];

const labels = { title: "Pricing card", type: "Plan", placeholder: "Select plan" };

export default function Default() {
  return (
    <FineTuneCard
      fields={fields}
      types={plans}
      labels={labels}
      defaultType="Team"
    />
  );
}
```

Vue · `default.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { FineTuneCard } from "@/components/ui/fine-tune-card";

const fields = [
  { key: "width", label: "W", value: 320, min: 200, max: 640 },
  { key: "height", label: "H", value: 440, min: 240, max: 960 },
  { key: "radius", label: "Radius", value: 16, min: 0, max: 48 },
  { key: "gap", label: "Gap", value: 24, min: 0, max: 64 },
];

const plans = ["Starter", "Team", "Business"];

const labels = { title: "Pricing card", type: "Plan", placeholder: "Select plan" };

const type = ref("Team");
</script>

<template>
  <FineTuneCard
    :fields="fields"
    :types="plans"
    :labels="labels"
    v-model:type="type"
  />
</template>
```

Svelte · `default.svelte`

```svelte
<script lang="ts">
  import { FineTuneCard } from "$lib/components/ui/fine-tune-card";

  const fields = [
    { key: "width", label: "W", value: 320, min: 200, max: 640 },
    { key: "height", label: "H", value: 440, min: 240, max: 960 },
    { key: "radius", label: "Radius", value: 16, min: 0, max: 48 },
    { key: "gap", label: "Gap", value: 24, min: 0, max: 64 },
  ];

  const plans = ["Starter", "Team", "Business"];

  const labels = { title: "Pricing card", type: "Plan", placeholder: "Select plan" };

  let type = $state("Team");
</script>

<FineTuneCard
  fields={fields}
  types={plans}
  labels={labels}
  bind:type={type}
/>
```

### Wider card in a grid, ready to reset

React · `edited.tsx`

```tsx
import type { ComponentProps } from "react";
import { FineTuneCard } from "@/components/ui/fine-tune-card";

type Props = ComponentProps<typeof FineTuneCard>;

const fields: Props["fields"] = [
  { key: "width", label: "W", value: 320, min: 200, max: 640 },
  { key: "height", label: "H", value: 440, min: 240, max: 960 },
  { key: "radius", label: "Radius", value: 16, min: 0, max: 48 },
  { key: "gap", label: "Gap", value: 24, min: 0, max: 64 },
];

const plans = ["Starter", "Team", "Business"];

const labels = { title: "Pricing card", type: "Plan", placeholder: "Select plan" };

export default function Edited() {
  return (
    <FineTuneCard
      fields={fields}
      types={plans}
      labels={labels}
      defaultLayout="grid"
      defaultValues={{ width: 360, radius: 12 }}
      defaultType="Business"
    />
  );
}
```

Vue · `edited.vue`

```vue
<script setup lang="ts">
import { ref } from "vue";
import { FineTuneCard, type FineTuneLayout } from "@/components/ui/fine-tune-card";

const fields = [
  { key: "width", label: "W", value: 320, min: 200, max: 640 },
  { key: "height", label: "H", value: 440, min: 240, max: 960 },
  { key: "radius", label: "Radius", value: 16, min: 0, max: 48 },
  { key: "gap", label: "Gap", value: 24, min: 0, max: 64 },
];

const plans = ["Starter", "Team", "Business"];

const labels = { title: "Pricing card", type: "Plan", placeholder: "Select plan" };

const layout = ref<FineTuneLayout>("grid");

const values = ref({ width: 360, radius: 12 });

const type = ref("Business");
</script>

<template>
  <FineTuneCard
    :fields="fields"
    :types="plans"
    :labels="labels"
    v-model:layout="layout"
    v-model:values="values"
    v-model:type="type"
  />
</template>
```

Svelte · `edited.svelte`

```svelte
<script lang="ts">
  import type { ComponentProps } from "svelte";
  import { FineTuneCard } from "$lib/components/ui/fine-tune-card";

  type Props = ComponentProps<typeof FineTuneCard>;

  const fields = [
    { key: "width", label: "W", value: 320, min: 200, max: 640 },
    { key: "height", label: "H", value: 440, min: 240, max: 960 },
    { key: "radius", label: "Radius", value: 16, min: 0, max: 48 },
    { key: "gap", label: "Gap", value: 24, min: 0, max: 64 },
  ];

  const plans = ["Starter", "Team", "Business"];

  const labels = { title: "Pricing card", type: "Plan", placeholder: "Select plan" };

  let layout = $state<Props["layout"]>("grid");

  let values = $state({ width: 360, radius: 12 });

  let type = $state("Business");
</script>

<FineTuneCard
  fields={fields}
  types={plans}
  labels={labels}
  bind:layout={layout}
  bind:values={values}
  bind:type={type}
/>
```

## Recipe

`fine-tune-card.recipe.ts`:

```ts
import { tv, type VariantProps } from "../lib/tv";
import { control, controlSize, controlVariant } from "../lib/control";

const ctl = control({ kind: "field" });

/* fine-tune-card — compact inspector: a layout switch (our segmented control), scrubbable number
 * fields (the Zag number-input machine) and a type picker (our select). The card marks itself
 * `changed` once anything differs from where it started; each field is `changed` when it
 * differs from its default (recipe variants). The "Adjust" hint and the "Edited · Reset" group share one
 * grid cell, so swapping them never moves the header: a crossfade with a 2px blur, never a jump.
 *
 * Composed parts, rendered by the adapter: the hint word is a Shimmer (fast, accent), Reset is a
 * ghost sm Button with a slimmer box (so the header keeps its height), the layout switch is a
 * SegmentedControl and the type picker a Select; marked data-fine-tune-card="hint-text|reset|layout"
 * (the Select passes on only its className: unmarked).
 *
 * Author text (title, field labels, footer label) takes its direction from its own first letter,
 * so a name in the other script keeps its ellipsis at its own end. */

/* a field's label turns accent while it is pressed, scrubbed or its input has focus */
const LABEL_ON = [
  "[[data-slot=fine-tune-card-scrubber]:active>&]:text-accent-ink",
  "[[data-slot=fine-tune-card-field][data-scrubbing]_&]:text-accent-ink",
  "[[data-slot=fine-tune-card-field][data-focus]_&]:text-accent-ink",
];

export const fineTuneCard = tv({
  slots: {
    base: "relative flex flex-col w-full max-w-[240px] min-w-0 rounded-card bg-surface shadow-raised",
    header: "flex items-center justify-between gap-2 min-w-0 py-2.5 px-3 border-b border-solid border-b-line",
    title: "min-w-0 overflow-hidden text-ellipsis whitespace-nowrap text-sm font-medium text-ink [unicode-bidi:plaintext]",
    state: "grid shrink-0 items-center justify-items-end",
    /* both states sit in the same cell; the one not shown is transparent, blurred and hidden */
    hint: [
      "[grid-area:1/1] inline-flex items-center gap-1.5 whitespace-nowrap",
      "motion-opacity-base motion-filter-base motion-also-[visibility_var(--fndn-duration-base)]",
    ],
    hintIcon: [
      "inline-flex shrink-0 items-center justify-center size-[18px] rounded-[5px] bg-accent-tint text-[10px] text-accent",
      "shadow-[inset_0_0_0_1px_color-mix(in_oklch,var(--fndn-accent)_30%,transparent)]",
    ],
    /* the Shimmer */
    hintText: "text-xs font-medium",
    edited: [
      "[grid-area:1/1] inline-flex items-center gap-1.5 whitespace-nowrap",
      "motion-opacity-base motion-filter-base motion-also-[visibility_var(--fndn-duration-base)]",
    ],
    editedText: "inline-flex items-center gap-[5px] text-xs font-medium text-green [&>[data-slot=icon]]:text-[11px]",
    /* the Button: its look and press, a slimmer box */
    reset: "-my-1.5 -me-1.5 px-1.5 text-ink-2",
    status: "sr-only",
    body: "flex flex-col gap-2 min-w-0 p-3 border-b border-solid border-b-line",
    section: "text-dense font-medium text-ink",
    /* the SegmentedControl */
    layout: "w-full",
    fields: "grid grid-cols-2 gap-2",
    /* a number field: scrub handle (the label), the input, an optional suffix */
    /* the shared control recipe (lib/control.ts): sm, subtle (an inspector field), field kind: the
     * ring for any focus, red when invalid, half opacity when disabled */
    field: [ctl.base(), controlSize.sm, controlVariant.subtle, "flex items-center gap-1 py-1 ps-0.5 pe-1"],
    /* a long label truncates and leaves the value at least half the field; the handle is small,
     * so it gets a larger invisible hit area */
    scrubber: [
      "relative flex min-w-0 max-w-[50%] items-center h-full rounded-[4px] cursor-ew-resize touch-none select-none",
      "after:content-[''] after:absolute after:inset-y-[-5px] after:inset-x-[-2px]",
    ],
    fieldLabel: [
      "min-w-0 overflow-hidden text-ellipsis px-0.5 text-xs leading-none whitespace-nowrap text-ink-2 cursor-[inherit] [unicode-bidi:plaintext]",
      "motion-colors-fast",
      /* :where keeps the hover below the accent states */
      "[@media(hover:hover)_and_(pointer:fine)]:[:where([data-slot=fine-tune-card-scrubber]:hover)>&]:text-ink",
      ...LABEL_ON,
    ],
    /* tabular figures: scrubbing never makes the value jitter in width */
    input: [
      "flex-1 min-w-0 h-full p-0 border-0 bg-transparent",
      "[font-family:inherit] [font-style:inherit] [font-weight:inherit] [font-stretch:inherit] [line-height:inherit]",
      "text-xs tabular-nums text-ink outline-none [@media(pointer:coarse)]:text-[16px]",
    ],
    suffix: "shrink-0 pe-0.5 text-[11.5px] text-ink-2",
    footer: "flex items-center justify-between gap-2 min-w-0 p-2.5",
    footerLabel: "min-w-0 overflow-hidden text-ellipsis whitespace-nowrap ps-0.5 text-xs text-ink-2 [unicode-bidi:plaintext]",
    /* the Select */
    type: "shrink-0 w-[120px] -me-0.5",
  },
  variants: {
    /* the card: something differs from where it started (the hint gives way to Edited · Reset);
     * a field (passed to its slot): its value differs from its default */
    changed: {
      true: {
        hint: "opacity-0 blur-[2px] invisible",
        field: [
          "bg-accent-tint shadow-[0_0_0_1px_var(--fndn-accent)] forced-colors:[outline:1px_solid_Highlight]",
          /* the tint stays under the pointer: an edited field keeps saying so */
          "[@media(hover:hover)_and_(pointer:fine)]:[&:where(:hover:not(:focus-visible,:has(:focus-visible),[aria-expanded=true],[readonly],[data-readonly],[aria-readonly=true]))]:bg-accent-tint",
        ],
      },
      false: { edited: "opacity-0 blur-[2px] invisible" },
    },
  },
  defaultVariants: { changed: false },
});

export type FineTuneCardRecipeProps = VariantProps<typeof fineTuneCard>;
```
