Environment Variables

Display environment variables with masking and copy functionality.

The EnvironmentVariables component displays environment variables with value masking, visibility toggle, and copy functionality.

Install using CLI

AI Elements Vue
shadcn-vue CLI
npx ai-elements-vue@latest add environment-variables

Install Manually

Copy and paste the following files into the same folder.

EnvironmentVariables.vue
EnvironmentVariablesHeader.vue
EnvironmentVariablesTitle.vue
EnvironmentVariablesToggle.vue
EnvironmentVariablesContent.vue
EnvironmentVariable.vue
EnvironmentVariableGroup.vue
EnvironmentVariableName.vue
EnvironmentVariableValue.vue
EnvironmentVariableCopyButton.vue
EnvironmentVariableRequired.vue
context.ts
index.ts
<script setup lang="ts">
import type { HTMLAttributes } from 'vue'
import { cn } from '@repo/shadcn-vue/lib/utils'
import { provide, ref, watch } from 'vue'
import { EnvironmentVariablesKey } from './context'

interface Props extends /* @vue-ignore */ HTMLAttributes {
  showValues?: boolean
  defaultShowValues?: boolean
  class?: HTMLAttributes['class']
}

const props = withDefaults(defineProps<Props>(), {
  showValues: undefined,
  defaultShowValues: false,
})

const emit = defineEmits<{
  (e: 'update:showValues', value: boolean): void
}>()

const internalShowValues = ref(props.defaultShowValues)

// Use controlled prop if present, otherwise use internal state
const showValues = ref(props.showValues !== undefined ? props.showValues : internalShowValues.value)

watch(
  () => props.showValues,
  (newVal) => {
    if (newVal !== undefined) {
      showValues.value = newVal
    }
  },
)

function setShowValues(show: boolean) {
  if (props.showValues === undefined) {
    internalShowValues.value = show
    showValues.value = show
  }
  emit('update:showValues', show)
}

provide(EnvironmentVariablesKey, {
  showValues,
  setShowValues,
})
</script>

<template>
  <div
    :class="cn('rounded-lg border bg-background', props.class)"
    v-bind="$attrs"
  >
    <slot />
  </div>
</template>

Features

  • Value masking by default
  • Toggle visibility switch
  • Copy individual values
  • Export format support (export KEY="value")
  • Required badge indicator

Props

<EnvironmentVariables />

showValuesboolean
Controlled visibility state.
defaultShowValuesboolean
Default visibility state.
@update:showValues(show: boolean) => void
Callback when visibility changes.
...propsHTMLAttributes
Spread to the container div.

<EnvironmentVariablesHeader />

...propsHTMLAttributes
Spread to the header div.

<EnvironmentVariablesTitle />

defaultSlot
Custom title text. Defaults to "Environment Variables".
...propsHTMLAttributes
Spread to the h3 element.

<EnvironmentVariablesToggle />

...propsSwitchProps
Spread to the Switch component.

<EnvironmentVariablesContent />

...propsHTMLAttributes
Spread to the content div.

<EnvironmentVariable />

namerequiredstring
Variable name.
valuerequiredstring
Variable value.
...propsHTMLAttributes
Spread to the row div.

<EnvironmentVariableGroup />

...propsHTMLAttributes
Spread to the group div.

<EnvironmentVariableName />

defaultSlot
Custom name content. Defaults to the name from context.
...propsHTMLAttributes
Spread to the span element.

<EnvironmentVariableValue />

defaultSlot
Custom value content. Defaults to the masked/unmasked value from context.
...propsHTMLAttributes
Spread to the span element.

<EnvironmentVariableCopyButton />

copyFormat"name" | "value" | "export"
Format to copy.
@copy() => void
Callback after successful copy.
@error(error: Error) => void
Callback if copying fails.
timeoutnumber
Duration to show copied state (ms).
...propsButtonProps
Spread to the Button component.

<EnvironmentVariableRequired />

defaultSlot
Custom badge text. Defaults to "Required".
...propsBadgeProps
Spread to the Badge component.