Env Editor

A .env file editor that shows environment variables as an editable key-value grid, with per-variable password masking of values, add and remove rows, and import and export of .env files.

Env Editor
LIVE · running in a sandboxed iframe
Installed with plain shadcn add · no workarounds · theme neutral (none shipped)
See how it was built

Installation

pnpm dlx shadcn@latest add @elements/env-editor

Requires @elements in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { EnvEditor, type EnvVariable } from "@/components/elements/env-editor";const [variables, setVariables] = React.useState<EnvVariable[]>([  { key: "DATABASE_URL", value: "postgres://localhost:5432/app" },  { key: "API_KEY", value: "sk_test_123" },]);<EnvEditor value={variables} onChange={setVariables} />
  • Editing environment variables for a project, deployment, or settings screen where users enter KEY=VALUE pairs
  • Letting users import an existing .env file and review or change its values before saving
  • Showing secret values (API keys, tokens) masked by default while still allowing users to reveal them
  • Displaying a read-only view of environment variables by setting readOnly, which hides all editing controls

Examples

Basic editable editor

A stateful editor whose changes are stored in parent state through onChange.

basic-editable-editor.tsx
import * as React from "react";import { EnvEditor, type EnvVariable } from "@/components/elements/env-editor";export default function Example() {  const [variables, setVariables] = React.useState<EnvVariable[]>([    { key: "DATABASE_URL", value: "postgres://localhost:5432/app" },    { key: "API_KEY", value: "sk_test_123" },  ]);  return <EnvEditor value={variables} onChange={setVariables} />;}

Read-only view

Displays variables without import, export, add, or remove controls. Values remain maskable.

read-only-view.tsx
import { EnvEditor, type EnvVariable } from "@/components/elements/env-editor";const variables: EnvVariable[] = [  { key: "NODE_ENV", value: "production" },  { key: "SECRET_TOKEN", value: "abc123" },];export default function ReadOnlyExample() {  return <EnvEditor value={variables} readOnly />;}

Values visible by default

Sets masked to false so values are shown in plain text until the user masks them.

values-visible-by-default.tsx
import * as React from "react";import { EnvEditor, type EnvVariable } from "@/components/elements/env-editor";export default function VisibleExample() {  const [variables, setVariables] = React.useState<EnvVariable[]>([    { key: "PUBLIC_URL", value: "https://example.com" },  ]);  return (    <EnvEditor      value={variables}      onChange={setVariables}      masked={false}      className="max-w-xl"    />  );}

API reference

PropTypeDefaultDescription
valueEnvVariable[][]The list of variables to display. Each item has a key and a value string. Internal state is synced whenever this prop changes.
onChange(variables: EnvVariable[]) => void—Called with the full updated list after a key or value is edited, a row is added or removed, or a .env file is imported.
readOnlybooleanfalseWhen true, inputs are read-only and the import, export, add, and remove controls are hidden.
maskedbooleantrueInitial masking behavior. When true, variable values start masked. It is applied when value changes and after an import, not on the very first render, where all keys start masked.
classNamestring—Additional class names merged onto the root container.

Accessibility

  • The import and export icon buttons have aria-labels 'Import .env file' and 'Export .env file'. The add and remove buttons also have aria-labels.
  • Each key input is labeled 'Variable name'. Each value input is labeled 'Value for <KEY>' and falls back to 'variable' when the key is empty.
  • The show/hide button's aria-label switches between 'Show value' and 'Hide value', and aria-pressed reflects the masked state. Because the label and the pressed state can point in opposite directions, screen reader users may find it confusing.
  • The '=' separator is aria-hidden to avoid noise for screen readers.
  • Rows use role="row" without a parent role="grid" or column roles, so table semantics are only partially exposed.
  • Masked values use type="password", so browsers and password managers may treat them as credentials.
  • Removal and hover states rely on color (red trash icon), and there is no keyboard shortcut for adding or removing rows.
  • The hidden file input is triggered by the upload button, so keyboard users must activate that button to import a file.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "Env Editor" component (elements/env-editor) from its shadcn registry.1. Install it with: npx shadcn@latest add @elements/env-editor2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: value, onChange, readOnly, masked, className.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { EnvEditor, type EnvVariable } from "@/components/elements/env-editor";const [variables, setVariables] = React.useState<EnvVariable[]>([  { key: "DATABASE_URL", value: "postgres://localhost:5432/app" },  { key: "API_KEY", value: "sk_test_123" },]);<EnvEditor value={variables} onChange={setVariables} />```

Files & dependencies

  • registry/default/blocks/devtools/env-editor/components/elements/env-editor.tsx
dependencieslucide-react

Looks similar, elsewhere