All files / features/admin/utils theme-utils.ts

100% Statements 11/11
100% Branches 10/10
100% Functions 1/1
100% Lines 10/10

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    2x 22x   21x       21x 2x     19x 2x       17x       11x       6x    
export type VariableType = 'color' | 'radius' | 'text' | 'none'
 
export const getVariableType = (key?: string, value?: string): VariableType => {
    if (!key) return 'text'
 
    const lowerKey = key.toLowerCase()
 
    // Explicit padding/margin/height/width should typically not show a text preview (like "Aa" at 20px)
    // unless specifically font-size.
    if (lowerKey.includes('font-size')) {
        return 'text'
    }
 
    if (lowerKey.includes('radius')) {
        return 'radius'
    }
 
    // Color detection
    if (
        /color|bg|background|foreground|border|ring|shadow|stroke|fill/i.test(lowerKey) ||
        value?.match(/^#|rgb|hsl/i)
    ) {
        return 'color'
    }
 
    // Default to none for things like padding, margin, width, height to avoid misleading previews
    return 'none'
}