-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds a keyframes map to StyleCollector and exports a new keyframes function. The keyframes function parses the animation object and generates a hashed name based on the input. Then it passes the generated style and hash to the StyleCollector. The StyleCollector reports back if the animation already exists. If it does not exists and we are in the browser, the function appends the animation to the SX stylesheet definitions.
- Loading branch information
1 parent
6fc66cf
commit cd71541
Showing
15 changed files
with
394 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// @flow | ||
|
||
import create from './src/create'; | ||
import keyframes from './src/keyframes'; | ||
import renderPageWithSX from './src/renderPageWithSX'; | ||
|
||
export { create, renderPageWithSX }; | ||
export { create, keyframes, renderPageWithSX }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// @flow | ||
|
||
import type { SheetDefinitions } from '../../create'; | ||
import keyframes from '../../keyframes'; | ||
|
||
const animation = keyframes({ | ||
from: { | ||
opacity: 0, | ||
}, | ||
to: { | ||
opacity: 1, | ||
}, | ||
}); | ||
|
||
export default ({ | ||
aaa: { | ||
animationName: animation, | ||
}, | ||
}: SheetDefinitions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// @flow | ||
|
||
import type { SheetDefinitions } from '../../create'; | ||
import keyframes from '../../keyframes'; | ||
|
||
const animation = keyframes({ | ||
'0%': { | ||
opacity: 0, | ||
}, | ||
'25%': { | ||
opacity: 0.7, | ||
}, | ||
'100%': { | ||
opacity: 1, | ||
}, | ||
}); | ||
|
||
export default ({ | ||
aaa: { | ||
animationName: animation, | ||
}, | ||
}: SheetDefinitions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// @flow | ||
|
||
import keyframes from '../keyframes'; | ||
import styleCollector from '../StyleCollector'; | ||
|
||
it('returns hashed name of the keyframe', () => { | ||
const spy = jest.spyOn(styleCollector, 'addKeyframe'); | ||
const hashedName = keyframes({ | ||
from: { | ||
opacity: 0, | ||
transform: 'translateX(-300px)', | ||
}, | ||
to: { | ||
opacity: 1, | ||
transform: 'translateX(0)', | ||
}, | ||
}); | ||
expect(spy).toHaveBeenCalledWith( | ||
hashedName, | ||
'@keyframes wOIjT {from {opacity:0;transform:translateX(-300px);}to {opacity:1;transform:translateX(0);}}', | ||
); | ||
const hashedName2 = keyframes({ | ||
from: { | ||
transform: 'translateX(-300px)', | ||
}, | ||
to: { | ||
transform: 'translateX(0)', | ||
}, | ||
}); | ||
expect(spy).toHaveBeenNthCalledWith( | ||
2, | ||
hashedName2, | ||
'@keyframes _1kFWtB {from {transform:translateX(-300px);}to {transform:translateX(0);}}', | ||
); | ||
expect(hashedName).toMatchInlineSnapshot(`"wOIjT"`); | ||
expect(hashedName2).toMatchInlineSnapshot(`"_1kFWtB"`); | ||
spy.mockReset(); | ||
}); | ||
|
||
it('works with percentages', () => { | ||
const spy = jest.spyOn(styleCollector, 'addKeyframe'); | ||
|
||
const hashedName = keyframes({ | ||
'0%': { | ||
transform: 'translateX(-300px)', | ||
}, | ||
'75%, 80%': { | ||
transform: 'translateX(50px)', | ||
}, | ||
'100%': { | ||
transform: 'translateX(0)', | ||
}, | ||
}); | ||
expect(spy).toHaveBeenCalledWith( | ||
hashedName, | ||
'@keyframes _3B4dOq {0% {transform:translateX(-300px);}100% {transform:translateX(0);}75%,80% {transform:translateX(50px);}}', | ||
); | ||
spy.mockReset(); | ||
}); | ||
|
||
it('generates same hash for similar object', () => { | ||
const hashedName = keyframes({ | ||
from: { | ||
opacity: 0, | ||
transform: 'translateX(-300px)', | ||
}, | ||
to: { | ||
opacity: 1, | ||
transform: 'translateX(0)', | ||
}, | ||
}); | ||
const hashedName2 = keyframes({ | ||
from: { | ||
opacity: 0, | ||
transform: 'translateX(-300px)', | ||
}, | ||
to: { | ||
opacity: 1, | ||
transform: 'translateX(0)', | ||
}, | ||
}); | ||
const hashedName3 = keyframes({ | ||
from: { | ||
transform: 'translateX(-300px)', | ||
opacity: 0, | ||
}, | ||
to: { | ||
transform: 'translateX(0)', | ||
opacity: 1, | ||
}, | ||
}); | ||
expect(hashedName).toEqual(hashedName2); | ||
expect(hashedName2).toEqual(hashedName3); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.