Key-Value Editor
NewEnvironment variable editor: secret values, duplicate and invalid key checks, paste a whole .env file, copy it back out.
Environment variables
Production · 3 variables
Tip: paste a .env file into any key.
Installation
$ pnpm dlx shadcn@latest add @synccn/key-value-editorFirst time in this project? Connect synccn with one command.
Usage
import { KeyValueEditor, parseEnv, toEnv } from "@/components/ui/key-value-editor";<KeyValueEditor value={vars} onValueChange={setVars} />API reference
Generated from the component's TypeScript types, so it always matches the code.
KeyValueEditor
Editor for environment variables, headers or metadata: add and remove rows, mark values secret, paste a whole .env file into any key field, and copy everything back out. Duplicate and invalid keys are flagged as you type.
- value
KeyValuePair[]Controlled rows.
- defaultValue
KeyValuePair[]Default
[]Rows at first, when uncontrolled.
- onValueChange
(pairs: KeyValuePair[]) => voidCalled with every change.
- keyFormat
"env" | "free"Default
"env""env" upper-cases keys and only allows letters, digits and underscores, like environment variables.
- allowSecrets
booleanDefault
trueShows a lock on each row to mark values as secret.
- keyPlaceholder
stringDefault
"KEY"Placeholder for new keys.
- valuePlaceholder
stringDefault
"value"Placeholder for new values.
- className
stringExtra classes for the root element.
parseEnv
Parses `KEY=value` lines (a .env file), skipping blanks and comments and unquoting values.
Takes no props.
toEnv
Writes rows as a .env file, quoting values that need it.
Takes no props.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
Helpers
- lib/clipboardcopyText (copies to the clipboard)
- lib/hooksuseControllable (works controlled or uncontrolled)
- lib/utilscn (merges class names)
npm packages
- clsx for cn()
- tailwind-merge for cn()
- lucide-react for Check, Copy, Eye, EyeOff, Lock, LockOpen, Plus, Trash2
Keyboard
- TabMove between key, value, secret and remove
Accessibility
- Every field has a label naming its row or key, and invalid keys set aria-invalid with the reason shown under the row.
- Pasting a .env file reports how many variables were imported in a polite live region.
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA attributes: aria-invalid, aria-label, aria-live, aria-pressed
- Shows a visible focus ring for keyboard users
- Announces changes to screen readers