Skip to content

Commit

Permalink
fix: guard border utils against uncommon values
Browse files Browse the repository at this point in the history
  • Loading branch information
rajasegar committed Jun 6, 2021
1 parent 7c8a268 commit e60fd28
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/border-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,27 @@ function getBorderUtils(decl) {
if (decl.value === 'none') return '';
if (decl.value === 'transparent') return '';
if (decl.value === '0') return 'border-0';
const [width, style, color] = decl.value.split(' ');

const borderWidth = TAILWIND_CLASSES['border-width'];
const borderStyle = TAILWIND_CLASSES['border-style'];
const borderColor = TAILWIND_CLASSES['border-color'];
const borderOpacity = TAILWIND_CLASSES['border-opacity'];

const _width = borderWidth[width] || 'border';
const _style = borderStyle[style] || '';
const _color = borderColor[color] || getColorUtils(decl);
let result = _width + ' ' + _style + ' ' + _color;
if (color.includes('rgba')) {
const [, , , opacity] = chroma(color)._rgb;
const proximateKey = getProximateKey(borderOpacity, opacity);
const _opacity = borderOpacity[opacity] || borderOpacity[proximateKey];
result += ' ' + _opacity;
}
return result;
const borderValues = decl.value.split(' ');
if (borderValues.length === 3) {
const [width, style, color] = borderValues;

const borderWidth = TAILWIND_CLASSES['border-width'];
const borderStyle = TAILWIND_CLASSES['border-style'];
const borderColor = TAILWIND_CLASSES['border-color'];
const borderOpacity = TAILWIND_CLASSES['border-opacity'];

const _width = borderWidth[width] || 'border';
const _style = borderStyle[style] || '';
const _color = borderColor[color] || getColorUtils(decl);
let result = _width + ' ' + _style + ' ' + _color;
if (color.includes('rgba')) {
const [, , , opacity] = chroma(color)._rgb;
const proximateKey = getProximateKey(borderOpacity, opacity);
const _opacity = borderOpacity[opacity] || borderOpacity[proximateKey];
result += ' ' + _opacity;
}
return result;
} else return '';
}

module.exports = getBorderUtils;

0 comments on commit e60fd28

Please sign in to comment.