# Env editor

> A structured .env and secrets editor with multi-line .env bulk paste, automatic 8×8 Bayer secret veiling, copy-while-veiled, duplicate key checks and Prod/Prev/Dev scopes.

Entering environment variables one input at a time is tedious, and showing raw credentials or plain password dots on a deployment screen feels brittle. EnvEditor brings cloud-dashboard ergonomics into one hairline component: paste a whole multi-line .env file into any key input and it strips comments, export prefixes and surrounding quotes, keeps equals signs inside connection URLs, spawns every row cleanly and automatically classifies secret-looking keys (SECRET, KEY, TOKEN, PASSWORD, DATABASE_URL) while keeping PUBLIC_ keys readable. Veiled secrets sit behind a full-slot 1.5px 8×8 Bayer optical pane that copies straight to the clipboard even while concealed with an emerald Bayer sweep. Auto-uppercase key normalisation, live duplicate-key warnings, optional Prod/Prev/Dev scope toggles and exported parseEnvText() and serializeEnvText() helpers are built in.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/env-editor.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `text-morph`, `number-roll`, `status-button`
- Docs and live preview: https://hairlineui.com/ui/env-editor
- Registry item (source): https://hairlineui.com/r/env-editor.json

## Usage

```tsx
import { EnvEditor, type EnvVar } from "@/components/env-editor";

<EnvEditor
  value={vars}
  onChange={setVars}
  showScopes
/>
```

## Project environment settings wired to bulk save and .env export

Store EnvEditor state in React and guard your Save button whenever duplicate keys exist.

```tsx
"use client";
import { useState } from "react";
import { EnvEditor, type EnvVar } from "@/components/env-editor";

export function ProjectEnvSettings({ initial, onSave }: { initial: EnvVar[]; onSave: (vars: EnvVar[]) => Promise<void> }) {
  const [vars, setVars] = useState<EnvVar[]>(initial);

  const keys = vars.map((v) => v.key.trim().toUpperCase()).filter(Boolean);
  const hasDuplicates = new Set(keys).size !== keys.length;

  return (
    <div className="space-y-3">
      <EnvEditor value={vars} onChange={setVars} showScopes />
      <button
        type="button"
        disabled={hasDuplicates}
        onClick={() => void onSave(vars)}
        className="h-9 rounded-xl bg-primary px-4 text-xs font-medium text-primary-foreground disabled:opacity-40"
      >
        Save environment variables
      </button>
    </div>
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value / defaultValue / onChange` | `EnvVar[] / EnvVar[] / (v: EnvVar[]) => void` | – | Controlled or uncontrolled array of { id, key, value, secret?, scopes? }. |
| `normalizeKeys / autoDetectSecrets` | `boolean / boolean` | `true / true` | Auto-uppercase keys to snake_case on blur and automatically veil secret-like keys. |
| `showScopes / allowExport` | `boolean / boolean` | `false / true` | Toggle per-row Prod/Prev/Dev scope pills and the header Copy .env export action. |
| `label / sound` | `string / boolean` | `"Environment variables" / false` | Accessible region label and opt-in Web Audio feedback cues. |
| `parseEnvText / serializeEnvText / isLikelySecretKey` | `exported utility functions` | – | Parse raw .env files, serialise back to .env syntax and classify secret keys outside the editor. |

## States

- **veiled secret**: Sensitive values sit behind a full-slot multi-tonal 1.5px 8×8 Bayer pane that reveals on click or Eye button while concealing token length.
- **copy while veiled**: Copying a veiled secret writes straight to the clipboard and sweeps an emerald Bayer pulse across that cell while swapping Copy to a Check.
- **bulk paste import**: Pasting multi-line .env text splits into rows, auto-veils credential keys, sweeps new cells emerald and shows an inline import summary chip.
- **duplicate key**: Colliding keys highlight in amber with an inline Duplicate badge so deployment overrides are caught before save.
- **reduced motion**: Bayer flash sweeps skip animation and static veiled grain stays crisp at 0% CPU.

## What it handles

Real deployment editors have to handle messy multi-line pastes, keep credentials safe during screen shares and prevent silent duplicate keys.

- **Multi-line .env bulk paste**: Pasting KEY=VALUE blocks into any key input strips # comments, export prefixes and quotes, preserves = inside URLs and imports all rows in one action.
- **Automatic Bayer secret veiling**: Keys matching SECRET, KEY, TOKEN, PASSWORD or DATABASE_URL (excluding NEXT_PUBLIC_ and PUBLIC_) automatically veil behind a full-slot 1.5px 8×8 Bayer pane.
- **Copy while veiled with emerald sweep**: Pressing Copy lifts a secret directly to the clipboard without exposing it on screen, confirming with an emerald Bayer wavefront across the veiled cell.
- **Key normalisation and duplicate guard**: Converts spaces and hyphens to uppercase snake_case on blur and flags colliding variable names live with an amber Duplicate pill.
- **Optional Prod / Prev / Dev scopes**: Enable showScopes to attach per-variable environment target pills (Production, Preview, Development).
- **Exported parser and serialiser**: Exports parseEnvText(), serializeEnvText(), normalizeEnvKey() and isLikelySecretKey() alongside EnvEditor.

## Replaces

custom key-value repeater, dotenv paste parser, password-dot secret rows, env scope selector

## Where it fits

- **Cloud and deployment dashboards**: Let developers paste an entire .env file straight from their editor, assign Production/Preview/Development scopes and export cleanly.
- **AI agent and MCP tool credentials**: Auto-veil API keys and tokens in Bayer grain while letting users copy values during screen shares without revealing them.
- **Webhook and integration settings**: Catch duplicate variable names live and normalise stray spaces or lowercase keys to uppercase snake_case on blur.
- **Internal admin configuration**: Reuse parseEnvText() and serializeEnvText() across forms, imports and clipboard exports.

## Notes

- Veiled secret panes render a static 1.5px 8×8 Bayer canvas at rest (0 rAF loops / 0% CPU) and wake briefly for ~0.56s only during an import or copy-while-veiled emerald sweep.
- Keys prefixed with NEXT_PUBLIC_, VITE_, PUBLIC_, REACT_APP_ or EXPO_PUBLIC_ are never auto-classified as secrets.
- Copy .env serialises values containing spaces or # inside escaped double quotes automatically.
- Under prefers-reduced-motion: reduce, flash waves stay still while all paste parsing, veiling and copy controls work unchanged.

License: MIT (https://hairlineui.com/license#components)
