-
Notifications
You must be signed in to change notification settings - Fork 55
Implement keyframes function and add animation prop support #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
brandongregoryscott
merged 1 commit into
segmentio:master
from
brandongregoryscott:add-keyframes
Nov 15, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -93,6 +93,15 @@ All of these CSS properties are supported. You can pass either a string or a num | |
| - `alignContent` | ||
| - `alignItems` | ||
| - `alignSelf` | ||
| - `animation` | ||
| - `animationDelay` | ||
| - `animationDirection` | ||
| - `animationDuration` | ||
| - `animationFillMode` | ||
| - `animationIterationCount` | ||
| - `animationName` | ||
| - `animationPlayState` | ||
| - `animationTimingFunction` | ||
| - `background` | ||
| - `backgroundBlendMode` | ||
| - `backgroundClip` | ||
|
|
@@ -133,6 +142,7 @@ All of these CSS properties are supported. You can pass either a string or a num | |
| - `clear` | ||
| - `color` | ||
| - `columnGap` | ||
| - `content` | ||
| - `cursor` | ||
| - `display` | ||
| - `flex` | ||
|
|
@@ -269,6 +279,35 @@ Utility function for filtering out `Box` props. Returns an `{ matchedProps, rema | |
|
|
||
| Type: `object` | ||
|
|
||
| #### keyframes(name, timeline) | ||
|
|
||
| Function for generating an animation keyframe name and injecting the provided styles into the stylesheet. The `timeline` object is in the shape of `{ 'from' | 'to' | [0-100]: CssProps }` which define the styles to apply at each position of the animation. Returns the generated name for use with the `animation` or `animationName` props. | ||
|
|
||
| ```tsx | ||
| import Box, { keyframes } from 'ui-box' | ||
|
|
||
| const openAnimation = keyframes('openAnimation', { | ||
| from: { | ||
| opacity: 0, | ||
| transform: 'translateY(-120%)' | ||
| }, | ||
| to: { | ||
| transform: 'translateY(0)' | ||
| } | ||
| }) | ||
|
|
||
| const AnimatedBox = () => <Box animation={`${openAnimation} 240ms cubic-bezier(0.175, 0.885, 0.320, 1.175)`} /> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔥 |
||
|
|
||
| // Equivalent using individual props: | ||
| const AnimatedBox = () => ( | ||
| <Box | ||
| animationName={openAnimation} | ||
| animationDuration={240} | ||
| animationTimingFunction="cubic-bezier(0.175, 0.885, 0.320, 1.175)" | ||
| /> | ||
| ) | ||
| ``` | ||
|
|
||
| #### propTypes | ||
|
|
||
| Object of all the `Box` CSS property `propTypes`. | ||
|
|
@@ -289,6 +328,7 @@ Object of all the CSS property enhancers (the methods that generate the class na | |
|
|
||
| These enhancer groups are also exported. They're all objects with `{ propTypes, propAliases, propEnhancers }` properties. They're mainly useful for if you want to inherit a subset of the `Box` CSS propTypes in your own components. | ||
|
|
||
| - `animation` | ||
| - `background` | ||
| - `borderRadius` | ||
| - `borders` | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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,95 @@ | ||
| import PropTypes from 'prop-types' | ||
| import getCss from '../get-css' | ||
| import { PropValidators, PropTypesMapping, PropEnhancerValueType, PropAliases, PropEnhancers } from '../types/enhancers' | ||
|
|
||
| export const propTypes: PropTypesMapping = { | ||
| animation: PropTypes.string, | ||
| animationDelay: PropTypes.string, | ||
| animationDirection: PropTypes.string, | ||
| animationDuration: PropTypes.string, | ||
| animationFillMode: PropTypes.string, | ||
| animationIterationCount: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
| animationName: PropTypes.string, | ||
| animationPlayState: PropTypes.string, | ||
| animationTimingFunction: PropTypes.string | ||
| } | ||
|
|
||
| export const propAliases: PropAliases = {} | ||
|
|
||
| export const propValidators: PropValidators = {} | ||
|
|
||
| const animation = { | ||
| className: 'a', | ||
| cssName: 'animation', | ||
| jsName: 'animation', | ||
| complexValue: true | ||
| } | ||
|
|
||
| const animationDelay = { | ||
| className: 'a-dly', | ||
| cssName: 'animation-delay', | ||
| jsName: 'animationDelay', | ||
| defaultUnit: 'ms' | ||
| } | ||
|
|
||
| const animationDirection = { | ||
| className: 'a-dir', | ||
| cssName: 'animation-direction', | ||
| jsName: 'animationDirection', | ||
| safeValue: true | ||
| } | ||
|
|
||
| const animationDuration = { | ||
| className: 'a-dur', | ||
| cssName: 'animation-duration', | ||
| jsName: 'animationDuration', | ||
| defaultUnit: 'ms' | ||
| } | ||
|
|
||
| const animationFillMode = { | ||
| className: 'a-fill-md', | ||
| cssName: 'animation-fill-mode', | ||
| jsName: 'animationFillMode', | ||
| safeValue: true | ||
| } | ||
|
|
||
| const animationIterationCount = { | ||
| className: 'a-itr-ct', | ||
| cssName: 'animation-iteration-count', | ||
| jsName: 'animationIterationCount', | ||
| defaultUnit: '' | ||
| } | ||
|
|
||
| const animationName = { | ||
| className: 'a-nm', | ||
| cssName: 'animation-name', | ||
| jsName: 'animationName' | ||
| } | ||
|
|
||
| const animationPlayState = { | ||
| className: 'a-ply-ste', | ||
| cssName: 'animation-play-state', | ||
| jsName: 'animationPlayState', | ||
| safeValue: true | ||
| } | ||
|
|
||
| const animationTimingFunction = { | ||
| className: 'a-tmng-fn', | ||
| cssName: 'animation-timing-function', | ||
| jsName: 'animationTimingFunction', | ||
| complexValue: true | ||
| } | ||
|
|
||
| export const propEnhancers: PropEnhancers = { | ||
| animation: (value: PropEnhancerValueType, selector: string) => getCss(animation, value, selector), | ||
| animationDelay: (value: PropEnhancerValueType, selector: string) => getCss(animationDelay, value, selector), | ||
| animationDirection: (value: PropEnhancerValueType, selector: string) => getCss(animationDirection, value, selector), | ||
| animationDuration: (value: PropEnhancerValueType, selector: string) => getCss(animationDuration, value, selector), | ||
| animationFillMode: (value: PropEnhancerValueType, selector: string) => getCss(animationFillMode, value, selector), | ||
| animationIterationCount: (value: PropEnhancerValueType, selector: string) => | ||
| getCss(animationIterationCount, value, selector), | ||
| animationName: (value: PropEnhancerValueType, selector: string) => getCss(animationName, value, selector), | ||
| animationPlayState: (value: PropEnhancerValueType, selector: string) => getCss(animationPlayState, value, selector), | ||
| animationTimingFunction: (value: PropEnhancerValueType, selector: string) => | ||
| getCss(animationTimingFunction, value, selector) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After pulling in this change to Evergreen locally and swapping out glamor, the Overlay component wasn't showing the transparent grey background due to the missing
content: "";rule (https://github.com/segmentio/evergreen/blob/master/src/overlay/src/Overlay.js#L54). Since this isn't directly related to animations/keyframes, I can revert this change and make a separate PR for it if desired.