Environment Variables Example

A runnable example block that composes the environment-variables component into a list of variables with required badges, a show/hide values toggle, and a copy-as-export button. It is a reference implementation to copy and adapt, not a standalone component.

block · no preview
This item cannot be built as published, so there is no live preview: install:
See how it was built

Installation

pnpm dlx shadcn@latest add @ai-elements/example-environment-variables

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

Usage

usage.tsx
import Example from "@/components/ai-elements/example-environment-variables";export default function Page() {  return <Example />;}
  • Showing a project's .env-style configuration list in an AI app settings or onboarding screen
  • Demonstrating how to wire the environment-variables parts together with a data array
  • Providing a starting point for a panel that lists required and optional variables with copy support

Examples

Default example with copy and required markers

Renders the full example as shipped: a header with title and toggle, and four variables, two marked required, each with a copy-as-export button.

default-example-with-copy-and-required-markers.tsx
import Example from "@/components/ai-elements/example-environment-variables";export default function Page() {  return <Example />;}

Minimal read-only list without copy or toggle

Composes only the title, name, and value parts for a compact read-only view of a single variable.

minimal-read-only-list-without-copy-or-toggle.tsx
import {  EnvironmentVariable,  EnvironmentVariableGroup,  EnvironmentVariableName,  EnvironmentVariableValue,  EnvironmentVariables,  EnvironmentVariablesContent,  EnvironmentVariablesHeader,  EnvironmentVariablesTitle,} from "@/components/ai-elements/environment-variables";const Minimal = () => (  <EnvironmentVariables>    <EnvironmentVariablesHeader>      <EnvironmentVariablesTitle />    </EnvironmentVariablesHeader>    <EnvironmentVariablesContent>      <EnvironmentVariable name="NODE_ENV" value="production">        <EnvironmentVariableGroup>          <EnvironmentVariableName />        </EnvironmentVariableGroup>        <EnvironmentVariableGroup>          <EnvironmentVariableValue />        </EnvironmentVariableGroup>      </EnvironmentVariable>    </EnvironmentVariablesContent>  </EnvironmentVariables>);export default Minimal;

API reference

PropTypeDefaultDescription
Example() => JSX.Element—Default export of the block. Takes no props; the variable list is defined inside the file as a constant array.
EnvironmentVariables.defaultShowValuesboolean—Passed as false in the example so values start hidden. Type inferred from usage; the authoritative definition lives in the environment-variables registry item.
EnvironmentVariable.namestring—Variable key, for example DATABASE_URL. Used as the React key in the example.
EnvironmentVariable.valuestring—Variable value shown or masked by the value part. Type inferred from usage.
EnvironmentVariableCopyButton.copyFormatstring—Set to "export" in the example so copied text is formatted as an export statement. Allowed values beyond "export" are not shown in this source.
EnvironmentVariableCopyButton.onCopy() => void—Callback invoked after copy. The example logs to the console.

Accessibility

  • Copy and toggle controls are buttons and should keep their accessible names; verify they are announced by a screen reader in your app.
  • Values are masked by default via defaultShowValues={false}, so secrets are not exposed on first render; reveal state changes should be perceivable by keyboard users.
  • Required status is conveyed by the EnvironmentVariableRequired text marker, not color alone; keep visible text when customizing.
  • The example's onCopy only logs to the console; replace it with user feedback such as a toast or live-region message so copy success is announced.

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 "Environment Variables Example" component (ai-elements/example-environment-variables) from its shadcn registry.1. Install it with: npx shadcn@latest add @ai-elements/example-environment-variables2. 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: Example, EnvironmentVariables.defaultShowValues, EnvironmentVariable.name, EnvironmentVariable.value, EnvironmentVariableCopyButton.copyFormat, EnvironmentVariableCopyButton.onCopy.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport Example from "@/components/ai-elements/example-environment-variables";export default function Page() {  return <Example />;}```

Files & dependencies

  • registry/default/examples/environment-variables.tsx→ components/ai-elements/example-environment-variables.tsx
registryDependencieshttps://elements.ai-sdk.dev/environment-variables.json

Looks similar, elsewhere

There is no screenshot of this item to compare yet.