CSS Keyframes
Using keyframes with Theme UI is fully supported, but not part of the Theme UI
library itself. Instead, use the keyframes
helper from Emotion.
Usage
import { keyframes } from '@emotion/core'
- Create a variable using
keyframes
for your animation (examples below) - Use the variable as the animation name, in an
animation
oranimationName
declaration
Examples
Using object syntax:
import { Box } from 'theme-ui'import { keyframes } from '@emotion/core'const fadeIn = keyframes({ from: { opacity: 0 }, to: { opacity: 1 } })export default props => (<Box{...props}sx={{animationName: fadeIn,animationDuration: '1s',animationFillMode: 'backwards',}}/>)
Using template literal syntax:
Edit the page on GitHub/** @jsx jsx */import { jsx } from 'theme-ui'import { keyframes } from '@emotion/core'const wave = keyframes``export default props => (<div{...props}sx={{ animation: `${wave} 0.5s linear infinite alternate` }}/>)