Skip to content

Commit

Permalink
feat: add unitless support
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Burel committed Aug 21, 2023
1 parent ba2456d commit c9390f5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions _rem.scss
Expand Up @@ -23,8 +23,8 @@ $px-only: false !default;
@each $value in $values {
@if meta.type-of($value) == "number" and math.unit($value) == "rem" and $to == "px" {
$result: list.append($result, _divide($value, 1rem) * $baseline, $separator);
} @else if meta.type-of($value) == "number" and math.unit($value) == "px" and $to == "rem" {
$result: list.append($result, _divide($value, $baseline) * 1rem, $separator);
} @else if meta.type-of($value) == "number" and (math.unit($value) == "px" or math.unit($value) == '') and $value != 0 and $to == "rem" {
$result: list.append($result, _divide(if(math.unit($value) == 'px', $value, $value * 1px), $baseline) * 1rem, $separator);
} @else if meta.type-of($value) == "list" {
$result: list.append($result, _convert($to, $value...), $separator);
} @else {
Expand Down
9 changes: 7 additions & 2 deletions index.test.js
Expand Up @@ -15,14 +15,19 @@ async function run(input, output, config = `@use "." as rem;`) {
expect(a).toEqual(b);
};

it('Unitless', () => run(
'.simple { font-size: rem.convert(24); }',
'.simple { font-size: 1.5rem; }'
));

it('Simple', () => run(
'.simple { font-size: rem.convert(24px); }',
'.simple { font-size: 1.5rem; }'
));

it('Multiple values', () => run(
'.multiple { padding: rem.convert(5px 10px); }',
'.multiple { padding: 0.3125rem 0.625rem; }'
'.multiple { padding: rem.convert(5px 10px 0 24); }',
'.multiple { padding: 0.3125rem 0.625rem 0 1.5rem; }'
));

it('Multiple mixed values', () => run(
Expand Down

0 comments on commit c9390f5

Please sign in to comment.