Skip to content

Commit

Permalink
fix keyframe implementation to close block correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
cometkim committed Sep 10, 2020
1 parent e173fae commit 451e6e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ const createThemeToString = (classPrefix: string, variablesSheet: ISheet) =>
const createKeyframesToString = (sheet: ISheet) =>
function toString(this: IKeyframesAtom) {
if (this._cssRuleString) {
sheet.insertRule(`${this._cssRuleString}}`);
sheet.insertRule(this._cssRuleString);
}

this.toString = () => this.id;
Expand Down Expand Up @@ -623,6 +623,7 @@ export const createCss = <T extends TConfig>(
tokens
)};`;
});
cssRule += `}`;

const hash = hashString(cssRule);
// Check if an atom exist with the same hash and return it if so
Expand Down
24 changes: 12 additions & 12 deletions packages/core/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -891,10 +891,10 @@ describe('createCss: mixed(SSR & Client)', () => {
}) as any;

expect(keyFrame._cssRuleString).toBe(
'@keyframes dmyJCr {0% {background-color: red;}100% {background-color: green;}}'
'@keyframes keYeiS {0% {background-color: red;}100% {background-color: green;}}'
);

expect(keyFrame.toString()).toMatchInlineSnapshot(`"dmyJCr"`);
expect(keyFrame.toString()).toMatchInlineSnapshot(`"keYeiS"`);
});

test('should support utils inside keyframes', () => {
Expand All @@ -915,10 +915,10 @@ describe('createCss: mixed(SSR & Client)', () => {
}) as any;

expect(keyFrame._cssRuleString).toBe(
'@keyframes bFeLcH {0% {margin-left: 1px;margin-right: 1px;}100% {margin-left: 10px;margin-right: 10px;}}'
'@keyframes jxILgC {0% {margin-left: 1px;margin-right: 1px;}100% {margin-left: 10px;margin-right: 10px;}}'
);

expect(keyFrame.toString()).toMatchInlineSnapshot(`"bFeLcH"`);
expect(keyFrame.toString()).toMatchInlineSnapshot(`"jxILgC"`);
});

test('should support specificity props inside keyframes', () => {
Expand All @@ -929,10 +929,10 @@ describe('createCss: mixed(SSR & Client)', () => {
}) as any;

expect(keyFrame._cssRuleString).toMatchInlineSnapshot(
`"@keyframes bivLJn {0% {padding-top: 1px;padding-right: 1px;padding-bottom: 1px;padding-left: 1px;}100% {padding-top: 10px;padding-right: 10px;padding-bottom: 10px;padding-left: 10px;}}"`
`"@keyframes hOBUdi {0% {padding-top: 1px;padding-right: 1px;padding-bottom: 1px;padding-left: 1px;}100% {padding-top: 10px;padding-right: 10px;padding-bottom: 10px;padding-left: 10px;}}"`
);

expect(keyFrame.toString()).toMatchInlineSnapshot(`"bivLJn"`);
expect(keyFrame.toString()).toMatchInlineSnapshot(`"hOBUdi"`);
});
test('should allow keyframes atom to be used as a direct object value', () => {
const css = createCss({}, null);
Expand All @@ -943,14 +943,14 @@ describe('createCss: mixed(SSR & Client)', () => {
let atom: any;
const { styles } = css.getStyles(() => {
expect(() => (atom = css({ animationName: keyFrame }))).not.toThrow();
expect(atom.toString()).toMatchInlineSnapshot(`"_gDSlRG"`);
expect(atom.toString()).toMatchInlineSnapshot(`"_iGYUIN"`);
return '';
});
expect(styles.length).toBe(2);
expect(styles[1].trim()).toMatchInlineSnapshot(`
"/* STITCHES */
./*X*/_gDSlRG/*X*/{animation-name:dmyJCr;}
@keyframes dmyJCr {0% {background-color: red;}100% {background-color: green;}"
./*X*/_iGYUIN/*X*/{animation-name:keYeiS;}
@keyframes keYeiS {0% {background-color: red;}100% {background-color: green;}}"
`);
});
test('should inject styles for animations into sheet', () => {
Expand All @@ -961,14 +961,14 @@ describe('createCss: mixed(SSR & Client)', () => {
}) as any;
const atom = css({ animationName: keyFrame }) as any;
const { styles } = css.getStyles(() => {
expect(atom.toString()).toMatchInlineSnapshot(`"_gDSlRG"`);
expect(atom.toString()).toMatchInlineSnapshot(`"_iGYUIN"`);
return '';
});
expect(styles.length).toBe(2);
expect(styles[1].trim()).toMatchInlineSnapshot(`
"/* STITCHES */
./*X*/_gDSlRG/*X*/{animation-name:dmyJCr;}
@keyframes dmyJCr {0% {background-color: red;}100% {background-color: green;}"
./*X*/_iGYUIN/*X*/{animation-name:keYeiS;}
@keyframes keYeiS {0% {background-color: red;}100% {background-color: green;}}"
`);
});
test('should handle margin shorthand', () => {
Expand Down

0 comments on commit 451e6e2

Please sign in to comment.