fix numbers being interpreted as colors

master
Brad Cornes 2020-05-03 20:52:14 +01:00
parent f809595659
commit 7978c9e6dc
2 changed files with 6 additions and 5 deletions

View File

@ -9,7 +9,7 @@ import {
} from 'vscode-languageserver'
const dlv = require('dlv')
import removeMeta from '../util/removeMeta'
import { getColor, getColorFromString } from '../util/color'
import { getColor, getColorFromValue } from '../util/color'
import { isHtmlContext } from '../util/html'
import { isCssContext } from '../util/css'
import { findLast, findJsxStrings, arrFindLast } from '../util/find'
@ -269,7 +269,7 @@ function provideCssHelperCompletions(
return {
isIncomplete: false,
items: Object.keys(obj).map((item, index) => {
let color = getColorFromString(obj[item])
let color = getColorFromValue(obj[item])
const replaceDot: boolean =
item.indexOf('.') !== -1 && separator && separator.endsWith('.')
const insertClosingBrace: boolean =

View File

@ -61,11 +61,12 @@ export function getColor(
return { documentation: colorStrings[0] }
}
export function getColorFromString(str: string): string {
if (str === 'transparent') {
export function getColorFromValue(value: unknown): string {
if (typeof value !== 'string') return null
if (value === 'transparent') {
return 'rgba(0, 0, 0, 0.01)'
}
const color = new TinyColor(str)
const color = new TinyColor(value)
if (color.isValid) {
return color.toRgbString()
}