Skip to content

Commit

Permalink
feat(rem): allow multiple values
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Dec 26, 2023
1 parent e039eea commit af59e3b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/rem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ function scaleRem(remValue: string, shouldScaleTo: string) {
}

function createConverter(units: string, shouldScaleTo: string | null = null) {
return (value: number | string) => {
return function converter(value: number | string | number[] | string[]): string {
if (Array.isArray(value)) {
return value.map((val) => converter(val)).join(' ');
}

if (value === 0 || value === '0') {
return '0';
}
Expand All @@ -15,10 +19,17 @@ function createConverter(units: string, shouldScaleTo: string | null = null) {
return (shouldScaleTo && shouldScaleTo !== SIXTEEN_PX) ? scaleRem(val, shouldScaleTo) : val;
}

if (value.includes('calc(') || value.includes('var(')) {
if (value.includes('calc(') || value.includes('var(') || value.includes('clamp(')) {
return value;
}

if (value.includes(' ')) {
return value
.split(' ')
.map((val) => converter(val))
.join(' ');
}

if (value.includes(units)) {
return (shouldScaleTo && shouldScaleTo !== SIXTEEN_PX) ? scaleRem(value, shouldScaleTo) : value;
}
Expand Down

0 comments on commit af59e3b

Please sign in to comment.