Names and values such as API keys and URLs, one row each: secrets hidden, a pasted .env file split into rows, mistakes marked.
- 5.6 kB JS 4.7 kB CSS gzipped
- No serious axe issues
- Server-rendered, hydrates
- 44px touch targets
- Right-to-left
- 11 tests
Production
5 variables · 2 secretsPaste a .env file into a name to add every line.
import type { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { EnvEditor, type EnvVar } from "./ui/uicontext/components/EnvEditor.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const styles = stylex.create({ wrap: { inlineSize: "min(100%, 44rem)" } })const production: ReadonlyArray<EnvVar> = [ { key: "DATABASE_URL", value: "postgres://app:[email protected]:5432/invoices", secret: true }, { key: "STRIPE_SECRET_KEY", value: "sk_live_51NbX0aExampleOnly", secret: true }, { key: "LOG_LEVEL", value: "info" }, { key: "FEATURE_NEW_BILLING", value: "true" }, { key: "PUBLIC_APP_URL", value: "https://app.example.com" },]// a project's production settings: secrets hidden until their eye is pressedexport const ProductionEnv = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.wrap)).children( EnvEditor(h, { key: "prod", props: { label: "Production", value: production } }), )When to use
Names and values such as API keys and URLs, one row each: secrets hidden, a pasted .env file split into rows, mistakes marked. Use Secrets instead when the values are credentials no one should read again after saving.
Usage
import { EnvEditor, type EnvVar } from "./ui/uicontext/components/EnvEditor.ts"export const Settings = <M>(h: Html.H<M>, env: ReadonlyArray<EnvVar>, onChange: (vars: ReadonlyArray<EnvVar>, valid: boolean) => M) => EnvEditor(h, { props: { label: "Environment variables", value: env }, onEmit: { RequestedChange: ({ value, valid }) => onChange(value, valid) } })Examples
Pasting a .env file
Copy the file and paste it into the name field. The dash in ALLOWED-ORIGINS is marked, and Save waits until it's fixed.
# an MCP server's settings export GITHUB_TOKEN="ghp_exampleOnly000" SEARCH_INDEX=issues-v2 # the index to query MAX_RESULTS=25 ALLOWED-ORIGINS=*
Tool settings
0 variablesPaste a .env file into a name to add every line.
This example also uses Button. Install it too:
npx shadcn@latest add checkfu/uicontext/buttonimport { UiSchema } from "effect/ui"import { Html } from "effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { Button } from "./ui/uicontext/components/Button.ts"import { EnvEditor } from "./ui/uicontext/components/EnvEditor.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, corner, font, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ wrap: { display: "grid", gap: space.lg, inlineSize: "min(100%, 44rem)" }, file: { margin: 0, padding: space.md, borderRadius: corner.control, backgroundColor: color.app, fontFamily: font.mono, fontSize: font.xs, lineHeight: 1.6, whiteSpace: "pre-wrap", overflowWrap: "anywhere", color: color.fg }, foot: { display: "flex", flexWrap: "wrap", alignItems: "center", gap: space.md }, note: { margin: 0, fontSize: font.sm, color: color.muted },})// copy this, then paste it into the empty name field belowconst dotenv = `# an MCP server's settingsexport GITHUB_TOKEN="ghp_exampleOnly000"SEARCH_INDEX=issues-v2 # the index to queryMAX_RESULTS=25ALLOWED-ORIGINS=*`const Message = UiSchema.TaggedEnum({ Edited: { valid: Schema.Boolean, count: Schema.Number }, ClickedSave: {} })export const ToolSettings = Html.component({ name: "ToolSettings", model: Schema.Struct({ valid: Schema.Boolean, count: Schema.Number, saved: Schema.Boolean }), message: Message,}).make({ init: () => ({ valid: true, count: 0, saved: false }), update: { Edited: ($, { valid, count }) => $.evolve({ valid, count, saved: false }), ClickedSave: ($) => ($.model.valid ? $.evolve({ saved: true }) : $.model), }, view: (h, model) => h.div.attrs(sx(styles.wrap)).children( h.pre.attrs({ "aria-label": "A .env file to paste", tabindex: "0", ...sx(styles.file) }).children(dotenv), EnvEditor(h, { key: "tool", props: { id: "tool", label: "Tool settings", value: [] }, onEmit: { RequestedChange: ({ value, valid }) => Message.Edited({ valid, count: value.length }) }, }), h.div.attrs(sx(styles.foot)).children( Button(h, { tone: "primary" }).disabled(!model.valid).on("click", Message.ClickedSave()).children("Save settings"), h.p.attrs({ role: "status", ...sx(styles.note) }).children(model.saved ? "Saved. The tool restarts with them." : model.valid ? "" : "Fix the marked rows to save."), ), ),})API reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
labelrequired | string | — | What the variables are for: "Production environment". |
valuerequired | EnvVar[] | — | The variables to start with. |
id | string | "env" | Starts the ids inside it, unique on the page; "env" by default. |
locale | string | — | For the counts; the browser's by default. |
Events
| Event | Payload | Description |
|---|---|---|
RequestedChange | { value: EnvVar[]; valid: boolean } | The set changed: the named variables, in order, and whether every row is fine to save. |
Installation
pnpm dlx shadcn@latest add checkfu/uicontext/env-editor