Skip to content
synccn

Key-Value Editor

New

Environment 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-editor

First 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[]) => void

    Called with every change.

  • keyFormat
    "env" | "free"

    Default "env"

    "env" upper-cases keys and only allows letters, digits and underscores, like environment variables.

  • allowSecrets
    boolean

    Default true

    Shows a lock on each row to mark values as secret.

  • keyPlaceholder
    string

    Default "KEY"

    Placeholder for new keys.

  • valuePlaceholder
    string

    Default "value"

    Placeholder for new values.

  • className
    string

    Extra 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

npm packages

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