"use client" import { CheckIcon, CopyIcon, EyeIcon, EyeOffIcon } from "lucide-react" import { type ComponentProps, createContext, type HTMLAttributes, useContext, useState, } from "react" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Switch } from "@/components/ui/switch" import { cn } from "@/lib/utils" interface EnvironmentVariablesContextType { showValues: boolean setShowValues: (show: boolean) => void } const EnvironmentVariablesContext = createContext({ showValues: false, setShowValues: () => undefined, }) export type EnvironmentVariablesProps = HTMLAttributes & { showValues?: boolean defaultShowValues?: boolean onShowValuesChange?: (show: boolean) => void } export const EnvironmentVariables = ({ showValues: controlledShowValues, defaultShowValues = false, onShowValuesChange, className, children, ...props }: EnvironmentVariablesProps) => { const [internalShowValues, setInternalShowValues] = useState(defaultShowValues) const showValues = controlledShowValues ?? internalShowValues const setShowValues = (show: boolean) => { setInternalShowValues(show) onShowValuesChange?.(show) } return (
{children}
) } export type EnvironmentVariablesHeaderProps = HTMLAttributes export const EnvironmentVariablesHeader = ({ className, children, ...props }: EnvironmentVariablesHeaderProps) => (
{children}
) export type EnvironmentVariablesTitleProps = HTMLAttributes export const EnvironmentVariablesTitle = ({ className, children, ...props }: EnvironmentVariablesTitleProps) => (

{children ?? "Environment Variables"}

) export type EnvironmentVariablesToggleProps = ComponentProps export const EnvironmentVariablesToggle = ({ className, ...props }: EnvironmentVariablesToggleProps) => { const { showValues, setShowValues } = useContext(EnvironmentVariablesContext) return (
{showValues ? : }
) } export type EnvironmentVariablesContentProps = HTMLAttributes export const EnvironmentVariablesContent = ({ className, children, ...props }: EnvironmentVariablesContentProps) => (
{children}
) interface EnvironmentVariableContextType { name: string value: string } const EnvironmentVariableContext = createContext({ name: "", value: "", }) export type EnvironmentVariableProps = HTMLAttributes & { name: string value: string } export const EnvironmentVariable = ({ name, value, className, children, ...props }: EnvironmentVariableProps) => (
{children ?? ( <>
)}
) export type EnvironmentVariableGroupProps = HTMLAttributes export const EnvironmentVariableGroup = ({ className, children, ...props }: EnvironmentVariableGroupProps) => (
{children}
) export type EnvironmentVariableNameProps = HTMLAttributes export const EnvironmentVariableName = ({ className, children, ...props }: EnvironmentVariableNameProps) => { const { name } = useContext(EnvironmentVariableContext) return ( {children ?? name} ) } export type EnvironmentVariableValueProps = HTMLAttributes export const EnvironmentVariableValue = ({ className, children, ...props }: EnvironmentVariableValueProps) => { const { value } = useContext(EnvironmentVariableContext) const { showValues } = useContext(EnvironmentVariablesContext) const displayValue = showValues ? value : "•".repeat(Math.min(value.length, 20)) return ( {children ?? displayValue} ) } export type EnvironmentVariableCopyButtonProps = ComponentProps & { onCopy?: () => void onError?: (error: Error) => void timeout?: number copyFormat?: "name" | "value" | "export" } export const EnvironmentVariableCopyButton = ({ onCopy, onError, timeout = 2000, copyFormat = "value", children, className, ...props }: EnvironmentVariableCopyButtonProps) => { const [isCopied, setIsCopied] = useState(false) const { name, value } = useContext(EnvironmentVariableContext) const copyToClipboard = async () => { if (typeof window === "undefined" || !navigator?.clipboard?.writeText) { onError?.(new Error("Clipboard API not available")) return } let textToCopy = value if (copyFormat === "name") { textToCopy = name } else if (copyFormat === "export") { textToCopy = `export ${name}="${value}"` } try { await navigator.clipboard.writeText(textToCopy) setIsCopied(true) onCopy?.() setTimeout(() => setIsCopied(false), timeout) } catch (error) { onError?.(error as Error) } } const Icon = isCopied ? CheckIcon : CopyIcon return ( ) } export type EnvironmentVariableRequiredProps = ComponentProps export const EnvironmentVariableRequired = ({ className, children, ...props }: EnvironmentVariableRequiredProps) => ( {children ?? "Required"} ) /** Demo component for preview */ export default function EnvironmentVariablesDemo() { return (
) }