Skip to content

Commit 9fe989d

Browse files
committed
Add container queries support
1 parent 2002040 commit 9fe989d

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

src/postcss-rem-em.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ module.exports = () => {
2222
)
2323
.replace(emRegExp, (value) => converters.em(value.replace(/em\((.*?)\)/g, '$1')));
2424
},
25+
container: (atRule: AtRule) => {
26+
atRule.params = atRule.params
27+
.replace(remRegExp, (value) =>
28+
converters.remNoScale(value.replace(/rem\((.*?)\)/g, '$1'))
29+
)
30+
.replace(emRegExp, (value) => converters.em(value.replace(/em\((.*?)\)/g, '$1')));
31+
},
2532
},
2633
};
2734
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`@container transforms em 1`] = `
4+
"
5+
@container (min-width: 2em) {
6+
.card {
7+
background: red
8+
}
9+
}
10+
"
11+
`;
12+
13+
exports[`@container transforms rem 1`] = `
14+
"
15+
@container (min-width: 2rem) {
16+
.card {
17+
background: red
18+
}
19+
}
20+
"
21+
`;

src/tests/containers.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { testTransform } from './utils';
2+
3+
const rem = `
4+
.card {
5+
@container (min-width: rem(32px)) {
6+
background: red;
7+
}
8+
}
9+
`;
10+
11+
const em = `
12+
.card {
13+
@container (min-width: em(32px)) {
14+
background: red;
15+
}
16+
}
17+
`;
18+
19+
describe('@container', () => {
20+
it('transforms rem', async () => {
21+
const res = await testTransform(rem);
22+
expect(res.css).toMatchSnapshot();
23+
});
24+
25+
it('transforms em', async () => {
26+
const res = await testTransform(em);
27+
expect(res.css).toMatchSnapshot();
28+
});
29+
});

0 commit comments

Comments
 (0)