All files / features/admin/components/global-settings VariableRow.tsx

100% Statements 4/4
100% Branches 8/8
100% Functions 1/1
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56                              1x               109x 109x   109x                                                          
import { Input } from '@core/components/ui/input'
import { Label } from '@core/components/ui/label'
import { useFormContext } from 'react-hook-form'
import { VariablePreview } from './VariablePreview'
import type { VariableType } from '../../utils/theme-utils'
 
interface VariableRowProps {
    label: string
    name: string
    type?: VariableType
    hideLabel?: boolean
    className?: string
    variableKey?: string
}
 
export const VariableRow = ({
    label,
    name,
    type = 'color',
    hideLabel = false,
    className,
    variableKey,
}: VariableRowProps) => {
    const { register, watch } = useFormContext()
    const value = watch(name)
 
    return (
        <div
            data-testid="variable-row"
            className={`group flex items-center gap-4 mb-2 ${className || ''}`}
        >
            {!hideLabel && (
                <div className="w-40 shrink-0 text-right flex flex-col items-end justify-center">
                    <Label className="font-medium text-sm text-muted-foreground leading-tight">
                        {label}
                    </Label>
                    {variableKey && (
                        <span
                            className="text-[10px] text-muted-foreground/60 font-mono transition-all"
                            title={variableKey}
                        >
                            {variableKey}
                        </span>
                    )}
                </div>
            )}
 
            <div className="flex-1 relative group/input">
                <Input {...register(name)} className="font-mono h-9 text-xs" title={variableKey} />
            </div>
 
            <VariablePreview value={value} type={type} />
        </div>
    )
}