Skip to content

Commit

Permalink
Renamed em to em-convert
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Burel committed Nov 10, 2023
1 parent c511fa2 commit 037184d
Show file tree
Hide file tree
Showing 6 changed files with 1,609 additions and 1,319 deletions.
31 changes: 19 additions & 12 deletions README.md
Expand Up @@ -2,13 +2,11 @@

Sass function and mixin to convert px in em.

**Breaking change in 2.0**: now using [Sass Modules](https://sass-lang.com/blog/the-module-system-is-launched), using `@use` and `em` is renamed to `em.convert`. You could still use `@import` with no changes (see usage below), but **if you need LibSass/node-sass and Ruby Sass support (both deprecated), you should stay on 1.0** (which works fine) or use the [PostCSS](https://github.com/pierreburel/postcss-em) version.
## Breaking changes

Compatibility: [Dart Sass](https://sass-lang.com/dart-sass) only (**use v1.x for LibSass/node-sass and Ruby Sass**).
- **3.0**: changed default function name when imported globally (`@use "rem" as *;` or `@import "sass-rem";`) to `em-convert` to match [sass-rem](https://github.com/pierreburel/sass-rem), as [CSS now use `rem()` for calculating the remainder](https://developer.mozilla.org/en-US/docs/Web/CSS/rem). It shouldn't change anything if you used Sass Modules introduced in 3.0 (`em.convert`).

PostCSS version: https://github.com/pierreburel/postcss-em

See also: https://github.com/pierreburel/sass-rem
- **2.0**: now using [Sass Modules](https://sass-lang.com/blog/the-module-system-is-launched), using `@use` and `em` is renamed to `em.convert`. You could still use `@import` with no changes (see usage below), but **if you need LibSass/node-sass and Ruby Sass support (both deprecated), you should stay on 1.0** (which works fine) or use the [PostCSS](https://github.com/pierreburel/postcss-em) version.

---

Expand Down Expand Up @@ -62,11 +60,9 @@ Will output :
}
```

## *But it was shorter before!*

It was.
## Namespace

But You can change the namespace to something shorter and use `em` function and mixin instead of `convert`:
You can change the namespace when importing and use `em` function and mixin instead of `convert`:

```scss
@use "em" as to; // Because why not?
Expand All @@ -82,16 +78,27 @@ Or you can even load the library globally (but beware of conflicts, avoided by t
@use "em" as *;

.demo {
font-size: em(24px, 16px);
font-size: em-convert(24px, 16px);
}
```

And if you just don't want to use Sass Modules, you can still use `@import` with `em` function and mixin as before:
---

## Legacy import

If you don't want to use Sass Modules, you can still use `@import` with `em-convert` function and mixin:

```scss
@import "sass-em";

.demo {
font-size: em(24px, 16px);
font-size: em-convert(24px);
}
```

---

## See also

- PostCSS version: https://github.com/pierreburel/postcss-em
- `sass-rem`: https://github.com/pierreburel/sass-rem
10 changes: 10 additions & 0 deletions _em.scss
Expand Up @@ -37,10 +37,20 @@
}
}

// Proxy when used with a different namespace
@function em($values...) {
@return convert($values...);
}

@mixin em($properties, $context) {
@include convert($properties, $context);
}

// Proxy when imported globally
@function em-convert($values...) {
@return convert($values...);
}

@mixin em-convert($properties, $context) {
@include convert($properties, $context);
}
10 changes: 1 addition & 9 deletions index.import.scss
@@ -1,11 +1,3 @@
@use "em";

@forward "em" as em-* hide em-em;

@function em($values...) {
@return em.convert($values...);
}

@mixin em($properties, $context) {
@include em.convert($properties, $context);
}
@forward "em" as em-* hide em-em, em-em-convert;
4 changes: 2 additions & 2 deletions index.test.js
Expand Up @@ -52,13 +52,13 @@ it('Changing namespace', () => run(
));

it('Global namespace', () => run(
'.global-namespace { font-size: em(24px, 16px); }',
'.global-namespace { font-size: em-convert(24px, 16px); }',
'.global-namespace { font-size: 1.5em; }',
'@use "." as *;',
));

it('Legacy import', () => run(
'.legacy-import { @include em((font-size: 24px), 16px); margin: em(10px 1.5em, 16px); }',
'.legacy-import { @include em-convert((font-size: 24px), 16px); margin: em-convert(10px 1.5em, 16px); }',
'.legacy-import { font-size: 1.5em; margin: 0.625em 1.5em; }',
'@import ".";',
));
Expand Down

0 comments on commit 037184d

Please sign in to comment.