# Field (Lumen Halo): prompt.md (v1.0.0)

- id: `lumen-field` · version 1.0.0 · component · free
- category: Inputs
- build: Base UI (this item also ships a Radix build)
- install (this build): `npx shadcn@latest add https://beautiful-ui.dev/r/lumen-field.json`
- npm dependencies: class-variance-authority@^0.7
- registry dependencies: utils, @beautiful-ui/lumen-label, https://beautiful-ui.dev/r/lumen-foundation.json
- docs: https://beautiful-ui.dev/components/lumen-field
- The install command carries everything this item needs (files, CSS, tokens, npm and registry dependencies). Prefer it to copying source by hand.

Forms that always show where you are: the label brightens with focus, help stays quiet, and errors arrive with a coral dot and a voice for screen readers. shadcn's Field, cut from Lumen glass.

## Build it
- Stack: React 19 (`ref` is a plain prop), TypeScript, Tailwind CSS v4 utilities, a shadcn-initialised project with the `@/*` alias.
- Packages: `class-variance-authority@^0.7`.
- Files: `components/ui/lumen/field.tsx`; shared code: `lib/beautiful-ui/lumen/field-label.ts`.
- Registry dependencies, installed with it automatically: shadcn `utils` (cn), `lumen-label`, `lumen-foundation`.
- Builds: separate Base UI and Radix files. Install the one that matches the project (see Install): a free item's bare URL installs the Base UI build of it and its dependencies.
- Exports to keep: `Field`, `FieldLabel`, `FieldDescription`, `FieldError`, `FieldGroup / FieldSet / FieldLegend`, `FieldContent / FieldTitle / FieldSeparator`, `FieldAside`, and every exported type.
- CSS: the install merges this item's rules (the registry `css` field) into your global stylesheet, in `@layer components`, and adds the lumen foundation (tokens, keyframes, motion levels) once. Nothing to import by hand.
- Re-running `add` (or `--overwrite`) re-applies those rules: put overrides in your own CSS, never in the installed rules.
- Tokens: retheme with the `--lumen-*` custom properties (`--lumen-accent`, `--lumen-accent-text`, `--lumen-bad`, `--lumen-bad-text`, `--lumen-focus`, `--lumen-good`, `--lumen-good-text`, `--lumen-hairline`, `--lumen-ink`, `--lumen-muted-ink`, `--lumen-series-1`, `--lumen-series-2`, `--lumen-series-3`, `--lumen-series-4`, `--lumen-series-5`, `--lumen-series-6`, `--lumen-warn`, `--lumen-warn-text`); this item's CSS also reads `--lumen-font-mono`, `--lumen-font-sans`, `--lumen-radius-k`. Never add Tailwind colour classes inside the component.

```tsx
import { Field, FieldDescription, FieldError, FieldLabel } from "@/components/ui/lumen/field";
```

## Parts

| Part | data-slot | What it is for |
|---|---|---|
| `Field` | `field` | One field: label, control, description, error. |
| `FieldLabel` | `field-label` | The label; accent while the field has focus. |
| `FieldDescription` | `field-description` | Help text. |
| `FieldError` | `field-error` | The announced error with the coral dot. |
| `FieldGroup / FieldSet / FieldLegend` | `field-group` | Grouping and headings. |
| `FieldContent / FieldTitle / FieldSeparator` | `field-content` | Layout helpers, as shadcn. |
| `FieldAside` | `field-aside` | Beautiful UI: the end of the label row. |

Style a part with `[data-slot="<slot>"]` selectors or its `className`; keep the attributes when editing.

## Sound
- Keep every `data-slot` and `data-sound` attribute: the sound layer reads them.
- Installing this item adds no audio. Nothing plays until the app mounts `GlassSoundProvider` once (install: `npx shadcn@latest add https://beautiful-ui.dev/r/glass-sound.json`, import from `@/components/beautiful-ui/glass-sound`); `GlassSoundToggle` is its mute control. Without a provider the audio engine never loads.

## Match the original
- Read `components/ui/lumen/field.tsx` as the reference implementation before changing or recreating anything, and match it: sizes, colours per theme, motion timings, copy and behaviour.
- If you deviate (a prop you can't honour, a style you changed, a dependency you swapped), say so in your reply, part by part.
- Keep the accessibility contract, the keyboard map and the motion levels listed below.

## Use it when
- field, form field, form layout, label and description, error message, fieldset, settings form, shadcn field, Lumen
- Laying out forms: label, control, description and error for each field
- Settings pages: responsive rows put the label beside the control when there is room
- A drop-in for shadcn's Field: same parts and data-slots

### Not when
- A single search box with no label row: use Lumen Input with aria-label

## Mistakes
- Also set aria-invalid on the control: data-invalid on Field only styles it
- Import from @/components/ui/lumen/field: it never replaces your own

## Usage

```tsx
import { Field, FieldDescription, FieldError, FieldLabel } from "@/components/ui/lumen/field";
import { Input } from "@/components/ui/lumen/input";

<Field data-invalid={!!error}>
  <FieldLabel htmlFor="billing">Billing email</FieldLabel>
  <Input id="billing" aria-invalid={!!error} />
  <FieldDescription>Invoices go here each month.</FieldDescription>
  {error && <FieldError>{error}</FieldError>}
</Field>
```

## Props

| Prop | Type | Default | What it does |
|---|---|---|---|
| `Field orientation` | `"vertical" \| "horizontal" \| "responsive"` | `"vertical"` | responsive: side by side once the FieldGroup is 28rem wide. |
| `Field data-invalid / data-disabled` | `boolean` |  | Marks the field (dims the label when disabled). |
| `FieldError children / errors` | `ReactNode / { message }[]` |  | One message, or a list (duplicates dropped, as shadcn does). role=alert, coral dot, fades in. |
| `FieldAside` | `ReactNode` |  | Beautiful UI: Optional, Locked or a count at the end of the label row. |
| `FieldSeparator children` | `ReactNode` |  | A hairline with an optional mono caption. |

Full docs: https://beautiful-ui.dev/components/lumen-field

## Customising
- Colours: set the `--lumen-*` tokens on `:root`, or on a container with the `lumen-scope` class to retheme one area. Add the `lumen-inherit` class to follow your shadcn palette instead (`--chart-N`, `--destructive`).
- Dark mode follows the `.dark` class on an ancestor (the shadcn and next-themes convention).
- Update later by re-running the install with `--overwrite` (review the diff if you edited it). Changelog: https://beautiful-ui.dev/r/changelog.json

## Keyboard

| Keys | Action |
|---|---|
| Tab | Move through the fields in order; the focused one's label turns accent |

## Motion inventory

| Interaction | What moves |
|---|---|
| Focus | The label eases to the accent (.2s) |
| Error | Fades in and drops 2px into place (.2s) |

## Accessibility contract (preserve when editing)
- FieldSet and FieldLegend are a real fieldset and legend
- FieldError has role=alert, so a new error is announced
- The accent label is decoration: the label text itself names the control

## Install

Base UI project (a base-* style in components.json):

```bash
npx shadcn@latest add https://beautiful-ui.dev/r/lumen-field.json
```

Radix project (a radix-*, new-york or default style):

```bash
npx shadcn@latest add https://beautiful-ui.dev/r/radix-nova/lumen-field.json
```

Or add the `@beautiful-ui` registry to components.json and run `npx shadcn@latest add @beautiful-ui/lumen-field`: the CLI picks the build from your style.

## Credits
- Built on shadcn/ui (https://ui.shadcn.com)

## Source (Base UI build)

### components/ui/lumen/field.tsx

```tsx
"use client";

/**
 * Field (Lumen Halo) v1.0.0 · Beautiful UI
 * Docs: https://beautiful-ui.dev/components/lumen-field · Agent prompt: https://beautiful-ui.dev/md/lumen-field.md
 * Licensed to the purchaser under the Beautiful UI license: https://beautiful-ui.dev/license
 */

import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";
import { Label } from "@/components/ui/lumen/label";
import { FieldLabelContext } from "@/lib/beautiful-ui/lumen/field-label";

/*
 * Lumen Field (Base UI build). shadcn's Field in Lumen Halo: the label turns accent while
 * anything in the field has focus; descriptions sit in 12px secondary text; an error leads with the
 * coral dot, fades in and is announced (role="alert"). Same exports, parts and data-slots as shadcn,
 * plus FieldAside for "Optional" or "Locked" at the end of the label row.
 */

function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">) {
  return <fieldset data-slot="field-set" className={cn(`lumen-field-set`, className)} {...props} />;
}

function FieldLegend({ className, variant = "legend", ...props }: React.ComponentProps<"legend"> & { variant?: "legend" | "label" }) {
  return <legend data-slot="field-legend" data-variant={variant} className={cn(`lumen-field-legend`, className)} {...props} />;
}

function FieldGroup({ className, ...props }: React.ComponentProps<"div">) {
  return <div data-slot="field-group" className={cn(`lumen-field-group`, className)} {...props} />;
}

const fieldVariants = cva(`lumen-field`, {
  variants: { orientation: { vertical: "", horizontal: "", responsive: "" } },
  defaultVariants: { orientation: "vertical" },
});

// Beautiful UI: the Field shares one id with its label, so a Select trigger inside is named by it.
function Field({ className, orientation = "vertical", ...props }: React.ComponentProps<"div"> & VariantProps<typeof fieldVariants>) {
  const labelId = React.useId();
  return (
    <FieldLabelContext.Provider value={labelId}>
      <div role="group" data-slot="field" data-orientation={orientation} className={cn(fieldVariants({ orientation }), className)} {...props} />
    </FieldLabelContext.Provider>
  );
}

function FieldContent({ className, ...props }: React.ComponentProps<"div">) {
  return <div data-slot="field-content" className={cn(`lumen-field-content`, className)} {...props} />;
}

function FieldLabel({ className, id, htmlFor, ...props }: React.ComponentProps<typeof Label>) {
  // The label takes the Field's shared id (unless you give it one), so a Select trigger can point at it.
  const fieldLabelId = React.useContext(FieldLabelContext);
  return <Label data-slot="field-label" id={id ?? fieldLabelId} htmlFor={htmlFor} className={cn(`lumen-field-label`, className)} {...props} />;
}

function FieldTitle({ className, ...props }: React.ComponentProps<"div">) {
  return <div data-slot="field-label" className={cn(`lumen-field-title`, className)} {...props} />;
}

/** Beautiful UI: "Optional", "Locked" or a count at the end of the label row (inside FieldLabel). */
function FieldAside({ className, ...props }: React.ComponentProps<"span">) {
  return <span data-slot="field-aside" className={className} {...props} />;
}

function FieldDescription({ className, ...props }: React.ComponentProps<"p">) {
  return <p data-slot="field-description" className={cn(`lumen-field-description`, className)} {...props} />;
}

function FieldSeparator({ children, className, ...props }: React.ComponentProps<"div"> & { children?: React.ReactNode }) {
  return (
    <div data-slot="field-separator" data-content={!!children} className={cn(`lumen-field-separator`, className)} {...props}>
      {children && <span data-slot="field-separator-content">{children}</span>}
    </div>
  );
}

function FieldError({ className, children, errors, ...props }: React.ComponentProps<"div"> & { errors?: Array<{ message?: string } | undefined> }) {
  const content = React.useMemo(() => {
    // Text gets the coral dot; your own markup renders as it is.
    if (typeof children === "string" || typeof children === "number") return <span className={`lumen-field-error-message`}>{children}</span>;
    if (children) return children;
    if (!errors?.length) return null;
    const unique = [...new Map(errors.map((e) => [e?.message, e])).values()].filter((e) => e?.message);
    if (unique.length === 1) return <span className={`lumen-field-error-message`}>{unique[0]?.message}</span>;
    return (
      <ul className={`lumen-field-error-list`}>
        {unique.map((e, i) => (
          <li key={i} className={`lumen-field-error-message`}>
            {e?.message}
          </li>
        ))}
      </ul>
    );
  }, [children, errors]);
  if (!content) return null;
  return (
    <div role="alert" data-slot="field-error" className={cn(`lumen-field-error`, className)} {...props}>
      {content}
    </div>
  );
}

export { Field, FieldLabel, FieldDescription, FieldError, FieldGroup, FieldLegend, FieldSeparator, FieldSet, FieldContent, FieldTitle, FieldAside };
```

### lib/beautiful-ui/lumen/field-label.ts

```tsx
"use client";

import * as React from "react";

/*
 * The id a Lumen Field gives its label. A control that is a button rather than an input (Select's
 * trigger, a combobox) isn't named by a <label>, so it points at this id with aria-labelledby.
 */
export const FieldLabelContext = React.createContext<string | undefined>(undefined);

/** The id of the enclosing Field's label, or undefined outside a Field. */
export function useFieldLabelId() {
  return React.useContext(FieldLabelContext);
}
```

### CSS (the registry `css` / `cssVars`, merged into the global stylesheet by the shadcn CLI)

```css
@layer components {
  .lumen-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font: 500 13px/1.3 var(--lumen-font-sans, var(--font-sans, var(--font-geist, var(--font-geist-sans, 'Geist')))), system-ui, sans-serif;
    letter-spacing: normal;
    color: var(--gc-m85);
    user-select: none;
    transition: color var(--gc-t-c) ease;
  }
  .lumen-label:has(+:disabled),.lumen-label[data-disabled] {
    color: var(--gc-m45);
    cursor: not-allowed;
  }
  .lumen-field-set {
    display: flex;
    flex-direction: column;
    gap: 18px;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: none;
  }
  .lumen-field-legend {
    margin-bottom: 4px;
    padding: 0;
    font: 600 15px/1.3 var(--lumen-font-sans, var(--font-sans, var(--font-geist, var(--font-geist-sans, 'Geist')))), system-ui, sans-serif;
    color: var(--gc-ink);
  }
  .lumen-field-legend[data-variant="label"] {
    font: 500 13px/1.3 var(--lumen-font-sans, var(--font-sans, var(--font-geist, var(--font-geist-sans, 'Geist')))), system-ui, sans-serif;
    color: var(--gc-m85);
  }
  .lumen-field-group {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    container: lumen-field-group/inline-size;
  }
  .lumen-field {
    display: flex;
    flex-direction: column;
    gap: 7px;
    width: 100%;
    min-width: 0;
    font-family: var(--lumen-font-sans, var(--font-sans, var(--font-geist, var(--font-geist-sans, 'Geist')))), system-ui, sans-serif;
  }
  .lumen-field[data-orientation="horizontal"] {
    flex-direction: row;
    align-items: center;
    gap: 12px;
  }
  .lumen-field[data-orientation="horizontal"]>.lumen-field-label {
    flex: 1 1 auto;
  }
  @container lumen-field-group (min-width: 28rem) {
    .lumen-field[data-orientation="responsive"] {
      flex-direction: row;
      align-items: center;
      gap: 16px;
    }
    .lumen-field[data-orientation="responsive"]>.lumen-field-label,.lumen-field[data-orientation="responsive"]>.lumen-field-content {
      flex: 0 0 38%;
    }
  }
  .lumen-field-content {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
  }
  .lumen-field-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font: 500 13px/1.3 var(--lumen-font-sans, var(--font-sans, var(--font-geist, var(--font-geist-sans, 'Geist')))), system-ui, sans-serif;
    color: var(--gc-ink);
  }
  .lumen-field:focus-within>.lumen-field-label,.lumen-field:focus-within>.lumen-field-content>.lumen-field-label {
    color: var(--gc-acc-tint);
  }
  .lumen-field[data-disabled="true"] .lumen-field-label {
    color: var(--gc-m45);
  }
  .lumen-field-label>[data-slot="field-aside"] {
    margin-inline-start: auto;
    font: 500 10px var(--lumen-font-mono, var(--font-mono, var(--font-geist-mono, 'Geist Mono'))), ui-monospace, monospace;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--gc-sec);
  }
  .lumen-field-description {
    margin: 0;
    font: 400 12px/1.45 var(--lumen-font-sans, var(--font-sans, var(--font-geist, var(--font-geist-sans, 'Geist')))), system-ui, sans-serif;
    color: var(--gc-sec);
    overflow-wrap: anywhere;
  }
  .lumen-field-description a {
    color: var(--gc-acc-ui);
    text-underline-offset: 3px;
  }
  .lumen-field-error {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font: 400 12px/1.45 var(--lumen-font-sans, var(--font-sans, var(--font-geist, var(--font-geist-sans, 'Geist')))), system-ui, sans-serif;
    color: var(--gc-bad-tint);
    overflow-wrap: anywhere;
    animation: lumen-field-msg var(--gc-t-c) ease both;
  }
  .lumen-field-error-message {
    display: flex;
    align-items: baseline;
    gap: 7px;
  }
  .lumen-field-error-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0;
    padding: 0;
    list-style: none;
  }
  .lumen-field-error-message::before {
    content: "";
    width: 5px;
    height: 5px;
    flex: none;
    border-radius: calc(1.5px * var(--lumen-radius-k, 1));
    background: var(--gc-bad);
    transform: translateY(-1px);
  }
  @keyframes lumen-field-msg {
    from {
      opacity: 0;
      transform: translateY(-2px);
    }
  }
  .lumen-field-separator {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 20px;
    font: 500 10px var(--lumen-font-mono, var(--font-mono, var(--font-geist-mono, 'Geist Mono'))), ui-monospace, monospace;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--gc-sec);
  }
  .lumen-field-separator::before,.lumen-field-separator::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--gc-hair);
  }
  .lumen-field-separator[data-content="false"] {
    gap: 0;
  }
}
```

The lumen foundation (the tokens listed above, keyframes and motion levels) installs once with the first component; its CSS is public at https://beautiful-ui.dev/r/lumen-foundation.json.
