File tree 3 files changed +41
-2
lines changed
packages/react/src/keyframes
3 files changed +41
-2
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @compiled/react ' : patch
3
+ ---
4
+
5
+ Improve the types to the ` keyframes() ` function to handle CSS variables.
Original file line number Diff line number Diff line change 1
1
/** @jsxImportSource @compiled /react */
2
2
// eslint-disable-next-line import/no-extraneous-dependencies
3
- import { keyframes , styled } from '@compiled/react' ;
3
+ import { keyframes , styled , css } from '@compiled/react' ;
4
4
import { render } from '@testing-library/react' ;
5
5
6
6
import defaultFadeOut , { namedFadeOut , fadeOut as shadowedFadeOut } from '../__fixtures__' ;
@@ -180,6 +180,32 @@ describe('keyframes', () => {
180
180
`"@keyframes korwhog{0%{opacity:1}to{opacity:0}}"`
181
181
) ;
182
182
} ) ;
183
+
184
+ it ( 'containing css variables' , ( ) => {
185
+ const variable = '--opacity' ;
186
+ const fadeOut = keyframes ( {
187
+ from : {
188
+ [ variable ] : 1 ,
189
+ } ,
190
+ to : {
191
+ '--opacity' : 0 ,
192
+ } ,
193
+ } ) ;
194
+ const styles = css ( {
195
+ animationName : fadeOut ,
196
+ opacity : `var(${ variable } )` ,
197
+ } ) ;
198
+
199
+ const { getByText } = render ( < div css = { styles } > hello world</ div > ) ;
200
+
201
+ expect ( getByText ( 'hello world' ) ) . toHaveCompiledCss ( {
202
+ animationName : 'k1sm7npi' ,
203
+ opacity : 'var(--opacity)' ,
204
+ } ) ;
205
+ expect ( getKeyframe ( 'k1sm7npi' ) ) . toMatchInlineSnapshot (
206
+ `"@keyframes k1sm7npi{0%{--opacity:1px}to{--opacity:0}}"`
207
+ ) ;
208
+ } ) ;
183
209
} ) ;
184
210
} ) ;
185
211
Original file line number Diff line number Diff line change 1
1
import type { BasicTemplateInterpolations , CSSProps } from '../types' ;
2
2
import { createSetupError } from '../utils/error' ;
3
3
4
- export type KeyframeSteps = string | Record < string , CSSProps < void > > ;
4
+ export type KeyframeSteps =
5
+ // `string` would just be an arbitrary CSS-like string such as `keyframes('from{opacity:1;}to{opacity:0;}')`
6
+ | string
7
+ | Record <
8
+ 'from' | 'to' | string ,
9
+ // We allow basically all CSSProperties here and CSS Variables mapping to their values.
10
+ // eg. `{ display: 'block', '--var': 'block' }` — but likely it just becomes `'--var': any`
11
+ CSSProps < void > | { [ key : `--${string } `] : CSSProps < void > [ keyof CSSProps < void > ] }
12
+ > ;
5
13
6
14
/**
7
15
* ## Keyframes
You can’t perform that action at this time.
0 commit comments