Environment variables
Environment variables and secrets manager with masked values, write-only sensitive rows, scope toggle matrix, .env paste import, fingerprint comparison, and a redeploy banner.
import { EnvVariables } from '@uthereal/ui/env-variables'Env variables playground
Environment variables
- DATABASE_URLUpdated Aug 12 by Emma CollinsHidden value
- DATABASE_URLUpdated Aug 12 by Emma CollinsSensitive value, write-onlySensitive
- FEATURE_NEW_CHECKOUTUpdated Sep 21 by Emma CollinsHidden value
- FEATURE_NEW_CHECKOUTUpdated Sep 21 by Emma CollinsHidden value
- LOG_LEVELUpdated Apr 8 by Sofia RamirezHidden value
- LOG_LEVELUpdated Apr 8 by Sofia RamirezHidden value
- NEXT_PUBLIC_SITE_URLUpdated Jun 3 by Marcus JohnsonHidden value
- NEXT_PUBLIC_SITE_URLUpdated Jun 3 by Marcus JohnsonHidden value
- NEXT_PUBLIC_SITE_URLUpdated Jun 3 by Marcus JohnsonHidden value
- REDIS_URLUpdated Sep 18 by Sofia RamirezHidden value
- REDIS_URLUpdated Sep 18 by Sofia RamirezSensitive value, write-onlySensitive
- RESEND_API_KEYUpdated Jul 19 by Jasmine BrooksHidden value
- SEARCH_ADMIN_KEYUpdated Jul 30 by Jasmine BrooksSensitive value, write-onlySensitive
- SENTRY_DSNUpdated May 27 by Marcus JohnsonHidden value
- STRIPE_SECRET_KEYUpdated Sep 2 by Ava MitchellHidden value
- STRIPE_SECRET_KEYUpdated Sep 2 by Ava MitchellSensitive value, write-onlySensitive
- STRIPE_WEBHOOK_SECRETUpdated Sep 2 by Ava MitchellSensitive value, write-onlySensitive
Overview
EnvVariables manages project configuration and secrets across Development, Preview, and Production. Each row pairs one value with the environments it covers, so a single key can hold different values per environment without overlap. Values remain masked and omitted from the DOM until revealed, and rows flagged as sensitive are write-only.
The block includes an inline row editor, an Add variable panel with single-row and Paste .env import modes, a Compare view that diffs two environments by deterministic fingerprint with one-click copy-across actions, and a sliding Redeploy banner that tracks every modified environment.
Use EnvVariables for hosting, deployment, and backend platform settings screens. For managing bring-your-own AI provider credentials, use Keys. For fixed settings that do not vary by environment, use a standard form.
Usage
'use client'
import {
EnvVariables,
type EnvName,
type EnvVariable,
} from '@uthereal/ui/env-variables'
export function ProjectEnvironment({
project,
variables,
onSave,
onTriggerDeploy,
}: {
project: string
variables: EnvVariable[]
onSave: (rows: EnvVariable[]) => void
onTriggerDeploy: (environments: EnvName[]) => Promise<void>
}) {
return (
<EnvVariables
project={project}
variables={variables}
sampleDotenv=""
onChange={onSave}
onRedeploy={onTriggerDeploy}
/>
)
}Omit variables and onRedeploy to render the interactive sample project (northwind-storefront) with a locally simulated redeploy lifecycle.
Examples
Empty onboarding state
Pass an empty defaultVariables array and sampleDotenv="" for a new project awaiting its first variable or pasted .env file.
New service environment
No variables yet
Add one, or paste a .env file to import many at once.
Sensitive values and masking
Search matches key names only and never inspects stored values. Row values follow three visibility rules:
| Row state | Rendered value in DOM | Reveal & copy | Inline editor behavior |
|---|---|---|---|
| Hidden (default) | Bullets (aria-hidden) + "Hidden value" | Reveal toggle | Pre-fills current value; requires non-empty value on save |
| Revealed | Plaintext monospace value | Copy + Hide | Opening editor hides value again automatically |
sensitive: true | Bullets (aria-hidden) + "Sensitive value" | Disabled | Starts empty ("Enter a new value to replace it"); flag cannot be unset |
Once a row is saved with sensitive: true, the flag stays locked to prevent accidental disclosure. To make a key readable again, remove the row and add it back.
.env paste importer
Opening Import .env (or pasting a multiline KEY=value block directly into the Key field in single mode) parses the text live against existing rows and target environments. The parser ignores blank lines and # comments, strips export prefixes, unquotes single- and double-quoted strings, and strips trailing inline # comments on unquoted values.
| Line status | Condition | Import outcome |
|---|---|---|
new | Valid key not yet set in any chosen environment | Imported as a new row |
replace | Valid key already set in one or more chosen environments | Imported; clears overlapping scopes from existing rows |
duplicate | Same key appears again on a later valid line | Skipped (last definition wins) |
invalid | Missing =, empty key, starts with a digit, or bad chars | Skipped with inline reason |
Compare view and fingerprints
Switching to Compare diffs any two environments (Development, Preview, Production) without exposing plaintext values. Each set variable displays a deterministic 6-character FNV-1a hex fingerprint (•••• a1b2c3) plus a lock indicator when marked sensitive.
| Diff status | Meaning | Action |
|---|---|---|
missing-target | Set in the base environment, unset in the compared one | Copy to <target> extends the source row |
missing-base | Set in the compared environment, unset in the base one | Copy to <base> extends the source row |
different | Both environments define the key with differing fingerprints | Highlighted in accent ink |
same | Both environments match | Hidden by default; toggle Show matching to view |
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
title | stringDefault: "Environment variables" | Heading text and accessible section name. |
project | stringDefault: "northwind-storefront" | Project slug shown in monospace beneath the heading. |
defaultVariables | EnvVariable[]Default: [{"id":"db-prod","key":"DATABASE_URL","value":"postgresql://storefront:Qm7vR2xKp9LwT4nZ@db-prod.northwind.internal:5432/storefront?sslmode=require","environments":["production"],"sensitive":true,"updated":"Aug 12","updatedBy":"Emma Collins"},{"id":"db-dev","key":"DATABASE_URL","value":"postgresql://storefront:preview@db-staging.northwind.internal:5432/storefront_preview","environments":["development","preview"],"sensitive":false,"updated":"Aug 12","updatedBy":"Emma Collins"},{"id":"site-prod","key":"NEXT_PUBLIC_SITE_URL","value":"https://shop.northwind.example","environments":["production"],"sensitive":false,"updated":"Jun 3","updatedBy":"Marcus Johnson"},{"id":"site-preview","key":"NEXT_PUBLIC_SITE_URL","value":"https://preview.northwind.example","environments":["preview"],"sensitive":false,"updated":"Jun 3","updatedBy":"Marcus Johnson"},{"id":"site-dev","key":"NEXT_PUBLIC_SITE_URL","value":"http://localhost:3000","environments":["development"],"sensitive":false,"updated":"Jun 3","updatedBy":"Marcus Johnson"},{"id":"stripe-live","key":"STRIPE_SECRET_KEY","value":"sk_live_51Nw8QeHv2kR9tXa7LmPq4ZsY0bUcJ3dF","environments":["production"],"sensitive":true,"updated":"Sep 2","updatedBy":"Ava Mitchell"},{"id":"stripe-test","key":"STRIPE_SECRET_KEY","value":"sk_test_51Nw8QeHv2kR9tXa7Tg6Wn1KcE5pLr8yV","environments":["development","preview"],"sensitive":false,"updated":"Sep 2","updatedBy":"Ava Mitchell"},{"id":"stripe-hook","key":"STRIPE_WEBHOOK_SECRET","value":"whsec_9f3KqL2vX8mN4pR7tY1wZ6cB5dH0jG","environments":["production"],"sensitive":true,"updated":"Sep 2","updatedBy":"Ava Mitchell"},{"id":"resend","key":"RESEND_API_KEY","value":"re_Hk4q9TzLm_8VbWcN2xPr5sJd7FgY3eA","environments":["development","preview","production"],"sensitive":false,"updated":"Jul 19","updatedBy":"Jasmine Brooks"},{"id":"sentry","key":"SENTRY_DSN","value":"https://4b7e21c9d0a34f86@errors.northwind.example/2","environments":["preview","production"],"sensitive":false,"updated":"May 27","updatedBy":"Marcus Johnson"},{"id":"redis-prod","key":"REDIS_URL","value":"rediss://default:Xt8pL3qW7nZ2@cache-prod.northwind.internal:6380","environments":["production"],"sensitive":true,"updated":"Sep 18","updatedBy":"Sofia Ramirez"},{"id":"redis-preview","key":"REDIS_URL","value":"redis://cache-staging.northwind.internal:6379","environments":["preview"],"sensitive":false,"updated":"Sep 18","updatedBy":"Sofia Ramirez"},{"id":"checkout-flag","key":"FEATURE_NEW_CHECKOUT","value":"true","environments":["development","preview"],"sensitive":false,"updated":"Sep 21","updatedBy":"Emma Collins"},{"id":"checkout-flag-prod","key":"FEATURE_NEW_CHECKOUT","value":"false","environments":["production"],"sensitive":false,"updated":"Sep 21","updatedBy":"Emma Collins"},{"id":"log-dev","key":"LOG_LEVEL","value":"debug","environments":["development"],"sensitive":false,"updated":"Apr 8","updatedBy":"Sofia Ramirez"},{"id":"log","key":"LOG_LEVEL","value":"info","environments":["preview","production"],"sensitive":false,"updated":"Apr 8","updatedBy":"Sofia Ramirez"},{"id":"search-admin","key":"SEARCH_ADMIN_KEY","value":"a1c9f4e27b8d6035e2f7a9b41c8d3e60","environments":["production"],"sensitive":true,"updated":"Jul 30","updatedBy":"Jasmine Brooks"}] | Initial environment variable rows when uncontrolled. A key may appear on multiple rows with disjoint environments; rows are sorted by key. Edits do not reset a mounted instance. |
sampleDotenv | stringDefault: "# Copied from .env.local\nNEXT_PUBLIC_POSTHOG_KEY=phc_Rk2mT8vLq4xW9nZcB7pD1sF6hJ3yG5aE\nSEARCH_ADMIN_KEY=b7e2a9c41d06f8e3a5c2b9d7e14f6a08\nexport SHIPPING_API_TOKEN=\"shippo_test_4e9c2b7a1f8d3e60c5b2\"\nLOG_LEVEL=warn\n2FA_SECRET=JBSWY3DPEHPK3PXP\nLOG_LEVEL=error" | Initial text shown in the Paste .env textarea. Pass an empty string for a blank paste area. |
redeployAction | string— | Registered host action sent when the user clicks Redeploy or Try again in the redeploy banner. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes preserve interaction behavior. |
theme | EnvVariablesThemeDefault: {} | Color mode, accent, and typed semantic token overrides. |
motion | none | subtle | expressiveDefault: "subtle" | Animation preset. System reduced-motion preferences take precedence. |
motionOptions | EnvVariablesMotionOptionsDefault: {} | Panel expansion and crossfade timing overrides in milliseconds. |
dir | ltr | rtl— | Reading direction; inherited from the page when omitted. |
EnvVariable accepts { id, key, value, environments, sensitive?, updated?, updatedBy? }, where environments is a non-empty array of unique 'development' | 'preview' | 'production' values.
React integration
| Prop | Purpose |
|---|---|
variables | Controlled variable rows in any order (sorted by key). Omit for uncontrolled state seeded by defaultVariables. |
onChange(variables) | Called with the updated sorted row array after every add, import, edit, removal, scope toggle, or copy between environments. |
onRedeploy(environments) | Called with modified EnvName[] when Redeploy is activated. Return a promise to hold the running state; reject to show retry state. |
onAction(action) | Called when redeployAction is configured and the user activates Redeploy or Try again. |
preset | Application defaults overridden by explicit instance arguments. |
tokens | CSS variables applied after the typed theme. |
ref, className, style | Applied to the root <section> element. |
| Native attributes | id, aria-*, data-*, and remaining <section> props forwarded to the root element. |
Keyboard & accessibility
| Key | Action |
|---|---|
Tab | Moves through header actions, search, view switch, and each row’s reveal, copy, scope toggle, and edit controls. |
Enter / Space | Toggles reveal, flips an environment scope, opens the inline editor, or activates a button. |
ArrowLeft / ArrowRight | Moves and selects options inside the view switcher, add-mode switcher, and compare environment pickers (RTL-aware). |
Escape | Closes the inline editor or add panel and restores focus to the button that opened it. |
Enter (in form) | Saves the edited value, adds a single variable, or imports parsed .env lines. |
Every reveal button and environment scope toggle carries aria-pressed and an explicit key-scoped accessible name (for example, "Production for DATABASE_URL"). Scope conflict warnings render as inline role="alert" notes beneath the row, and a pre-mounted polite role="status" live region announces every mutation, import, removal, and redeploy outcome.
Container queries adapt the layout to its available inline width: at 760px and wider, rows render as a 6-column matrix with per-environment counts; below 760px, each row stacks into a card with a responsive 3-column environment pill grid; below 560px, header actions, search, form buttons, and redeploy actions expand to full width and the .env preview omits the masked value column. On coarse touch pointers, icon buttons and scope toggles grow to 44px targets.
Motion & theming
The redeploy banner, add panel, inline editor, row additions/removals, and conflict alerts expand and collapse on the bounce-free smooth spring (400ms) and exit on the exit curve (180ms). Environment scope toggles fill on the snappy spring (260ms) and draw their checkmark with pathLength. View switches and redeploy state updates spring the container height smoothly without snapping, and saved or imported rows pulse briefly with --ui-accent-subtle.
Under prefers-reduced-motion: reduce, travel, scale, and row highlight loops are disabled and swaps fall back to 120ms opacity crossfades. Setting motion="none" makes every transition immediate (0ms).
theme accepts mode, accent, and typed tokens across these groups:
| Token group | CSS custom properties |
|---|---|
core | --ui-surface, --ui-surface-raised, --ui-text, --ui-text-secondary, --ui-muted, --ui-border, --ui-highlight, --ui-accent, --ui-accent-foreground, --ui-danger, --ui-focus-ring, --ui-radius, --ui-border-width, --ui-font, --ui-font-size, --ui-font-weight |
extended | --ui-surface-sunken, --ui-border-strong, --ui-border-subtle, --ui-success, --ui-warning, --ui-info |
shape | --ui-radius-sm, --ui-popup-radius, --ui-surface-radius |
accentTones | --ui-accent-strong, --ui-accent-subtle |
selectionControl | --ui-control-on, --ui-control-glyph, --ui-track, --ui-control-track-hover, --ui-control-thumb, --ui-control-thumb-on |
type | --ui-font-mono, --ui-font-display |
elevation | --ui-shadow-resting, --ui-shadow-raised |
An application-wide UtherealProvider supplies defaults.
Composition
In an agent composition, EnvVariables is a leaf. Supply non-secret placeholder values in defaultVariables and wire redeployAction to a registered host action. See Building with agents.
{
"type": "EnvVariables",
"props": {
"title": "Environment variables",
"project": "northwind-storefront",
"redeployAction": "redeploy_project"
},
"children": []
}