Skip to content

Commit c6b4fd3

Browse files
authored
feat: add keyframe support (#108)
1 parent 1a6b3a0 commit c6b4fd3

File tree

7 files changed

+47
-3
lines changed

7 files changed

+47
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"lodash.camelcase": "^4.3.0",
7272
"postcss": "^7.0.27",
7373
"postcss-filter-plugins": "^3.0.1",
74+
"postcss-icss-keyframes": "^0.2.1",
7475
"postcss-icss-selectors": "^2.0.3",
7576
"postcss-load-config": "^2.1.0",
7677
"reserved-words": "^0.1.2",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
declare module 'postcss-icss-keyframes' {
2+
import { Plugin } from 'postcss';
3+
const plugin: Plugin<{
4+
generateScopeName: (
5+
keyframesName: string,
6+
filepath: string,
7+
css: string,
8+
) => void;
9+
}>;
10+
export = plugin;
11+
}

src/helpers/__tests__/__snapshots__/getDtsSnapshot.test.ts.snap

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ exports[`utils / cssSnapshots with file 'import.module.css' createExports should
111111
'childA': string;
112112
'childB': string;
113113
'nestedChild': string;
114+
'fadeIn': string;
114115
};
115116
export default classes;
116117
export let classA: string;
@@ -119,6 +120,7 @@ export let parent: string;
119120
export let childA: string;
120121
export let childB: string;
121122
export let nestedChild: string;
123+
export let fadeIn: string;
122124
"
123125
`;
124126

@@ -130,6 +132,7 @@ Object {
130132
"class-c": "import-module__class-c---2JDAJ",
131133
"classA": "import-module__classA---2fO5r",
132134
"class_d": "import-module__class_d---2Dims",
135+
"fadeIn": "__import_module_css__fadeIn",
133136
"nestedChild": "import-module__nestedChild---1ZDxw",
134137
"parent": "import-module__parent---2kdvO",
135138
}
@@ -146,6 +149,7 @@ declare let classes: {
146149
'childA': string;
147150
'childB': string;
148151
'nestedChild': string;
152+
'fadeIn': string;
149153
};
150154
export default classes;
151155
export let classA: string;
@@ -154,9 +158,10 @@ export let parent: string;
154158
export let childA: string;
155159
export let childB: string;
156160
export let nestedChild: string;
161+
export let fadeIn: string;
157162
158163
export const __cssModule: true;
159-
export type AllClassNames = 'classA' | 'ClassB' | 'class-c' | 'class_d' | 'parent' | 'childA' | 'childB' | 'nestedChild';"
164+
export type AllClassNames = 'classA' | 'ClassB' | 'class-c' | 'class_d' | 'parent' | 'childA' | 'childB' | 'nestedChild' | 'fadeIn';"
160165
`;
161166

162167
exports[`utils / cssSnapshots with file 'import.module.less' createExports should create an exports file 1`] = `
@@ -279,6 +284,7 @@ exports[`utils / cssSnapshots with file 'test.module.css' createExports should c
279284
'childA': string;
280285
'childB': string;
281286
'nestedChild': string;
287+
'fadeIn': string;
282288
};
283289
export default classes;
284290
export let classA: string;
@@ -287,6 +293,7 @@ export let parent: string;
287293
export let childA: string;
288294
export let childB: string;
289295
export let nestedChild: string;
296+
export let fadeIn: string;
290297
"
291298
`;
292299

@@ -298,6 +305,7 @@ Object {
298305
"class-c": "test-module__class-c---3Ouzp",
299306
"classA": "test-module__classA---KAOw8",
300307
"class_d": "test-module__class_d---3pjDe",
308+
"fadeIn": "__test_module_css__fadeIn",
301309
"nestedChild": "test-module__nestedChild---v7rOR",
302310
"parent": "test-module__parent---2tsUX",
303311
}
@@ -314,6 +322,7 @@ declare let classes: {
314322
'childA': string;
315323
'childB': string;
316324
'nestedChild': string;
325+
'fadeIn': string;
317326
};
318327
export default classes;
319328
export let classA: string;
@@ -322,9 +331,10 @@ export let parent: string;
322331
export let childA: string;
323332
export let childB: string;
324333
export let nestedChild: string;
334+
export let fadeIn: string;
325335
326336
export const __cssModule: true;
327-
export type AllClassNames = 'classA' | 'ClassB' | 'class-c' | 'class_d' | 'parent' | 'childA' | 'childB' | 'nestedChild';"
337+
export type AllClassNames = 'classA' | 'ClassB' | 'class-c' | 'class_d' | 'parent' | 'childA' | 'childB' | 'nestedChild' | 'fadeIn';"
328338
`;
329339

330340
exports[`utils / cssSnapshots with file 'test.module.less' createExports should create an exports file 1`] = `

src/helpers/__tests__/fixtures/test.module.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,12 @@
2525
}
2626
}
2727
}
28+
29+
@keyframes fadeIn {
30+
from {
31+
opacity: 0;
32+
}
33+
to {
34+
opacity: 1;
35+
}
36+
}

src/helpers/__tests__/getDtsSnapshot.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { join } from 'path';
44
import postcss from 'postcss';
55
import postcssIcssSelectors from 'postcss-icss-selectors';
66
import postcssImportSync from 'postcss-import-sync2';
7+
import postcssIcssKeyframes from 'postcss-icss-keyframes';
78
import tsModule from 'typescript/lib/tsserverlibrary';
89
import { getClasses } from '../getClasses';
910
import { createExports } from '../createExports';
@@ -37,6 +38,7 @@ const compilerOptions: tsModule.CompilerOptions = {};
3738
const processor = postcss([
3839
postcssImportSync(),
3940
postcssIcssSelectors({ mode: 'local' }),
41+
postcssIcssKeyframes(),
4042
]);
4143

4244
describe('utils / cssSnapshots', () => {

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'path';
33
import dotenv from 'dotenv';
44
import postcss, { AcceptedPlugin } from 'postcss';
55
import postcssIcssSelectors from 'postcss-icss-selectors';
6+
import postcssIcssKeyframes from 'postcss-icss-keyframes';
67
import postcssrc from 'postcss-load-config';
78
import filter from 'postcss-filter-plugins';
89
import tsModule from 'typescript/lib/tsserverlibrary';
@@ -99,6 +100,7 @@ function init({ typescript: ts }: { typescript: typeof tsModule }) {
99100
const processor = postcss([
100101
...userPlugins,
101102
postcssIcssSelectors({ mode: 'local' }),
103+
postcssIcssKeyframes(),
102104
]);
103105

104106
// Create matchers using options object.

yarn.lock

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3788,6 +3788,15 @@ postcss-filter-plugins@^3.0.1:
37883788
dependencies:
37893789
postcss "^6.0.14"
37903790

3791+
postcss-icss-keyframes@^0.2.1:
3792+
version "0.2.1"
3793+
resolved "https://registry.yarnpkg.com/postcss-icss-keyframes/-/postcss-icss-keyframes-0.2.1.tgz#80c4455e0112b0f2f9c3c05ac7515062bb9ff295"
3794+
integrity sha1-gMRFXgESsPL5w8Bax1FQYruf8pU=
3795+
dependencies:
3796+
icss-utils "^3.0.1"
3797+
postcss "^6.0.2"
3798+
postcss-value-parser "^3.3.0"
3799+
37913800
postcss-icss-selectors@^2.0.3:
37923801
version "2.0.3"
37933802
resolved "https://registry.yarnpkg.com/postcss-icss-selectors/-/postcss-icss-selectors-2.0.3.tgz#27fa1afcaab6c602c866cbb298f3218e9bc1c9b3"
@@ -3817,7 +3826,7 @@ postcss-load-config@^2.1.0:
38173826
cosmiconfig "^5.0.0"
38183827
import-cwd "^2.0.0"
38193828

3820-
postcss-value-parser@^3.3.1:
3829+
postcss-value-parser@^3.3.0, postcss-value-parser@^3.3.1:
38213830
version "3.3.1"
38223831
resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-3.3.1.tgz#9ff822547e2893213cf1c30efa51ac5fd1ba8281"
38233832
integrity sha512-pISE66AbVkp4fDQ7VHBwRNXzAAKJjw4Vw7nWI/+Q3vuly7SNfgYXvm6i5IgFylHGK5sP/xHAbB7N49OS4gWNyQ==

0 commit comments

Comments
 (0)