@compiled/react 0.6.13 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/dist/browser/class-names/index.d.ts +2 -2
  3. package/dist/browser/class-names/index.js.flow +45 -0
  4. package/dist/browser/css/index.d.ts +16 -3
  5. package/dist/browser/css/index.js +0 -13
  6. package/dist/browser/css/index.js.flow +35 -0
  7. package/dist/browser/css/index.js.map +1 -1
  8. package/dist/browser/index.d.ts +4 -1
  9. package/dist/browser/index.js +1 -0
  10. package/dist/browser/index.js.flow +40 -0
  11. package/dist/browser/index.js.map +1 -1
  12. package/dist/browser/keyframes/__fixtures__/index.d.ts +3 -0
  13. package/dist/browser/keyframes/__fixtures__/index.js +12 -0
  14. package/dist/browser/keyframes/__fixtures__/index.js.map +1 -0
  15. package/dist/browser/keyframes/index.d.ts +47 -0
  16. package/dist/browser/keyframes/index.js +9 -0
  17. package/dist/browser/keyframes/index.js.flow +54 -0
  18. package/dist/browser/keyframes/index.js.map +1 -0
  19. package/dist/browser/runtime/ax.js.flow +27 -0
  20. package/dist/browser/runtime/css-custom-property.js.flow +19 -0
  21. package/dist/browser/runtime/dev-warnings.d.ts +0 -1
  22. package/dist/browser/runtime/dev-warnings.js +1 -1
  23. package/dist/browser/runtime/dev-warnings.js.flow +7 -0
  24. package/dist/browser/runtime/dev-warnings.js.map +1 -1
  25. package/dist/browser/runtime/index.js.flow +10 -0
  26. package/dist/browser/runtime/is-node.js.flow +19 -0
  27. package/dist/browser/runtime/sheet.d.ts +1 -1
  28. package/dist/browser/runtime/sheet.js.flow +36 -0
  29. package/dist/browser/runtime/style-cache.d.ts +1 -1
  30. package/dist/browser/runtime/style-cache.js.flow +19 -0
  31. package/dist/browser/runtime/style.d.ts +1 -1
  32. package/dist/browser/runtime/style.js.flow +17 -0
  33. package/dist/browser/runtime/types.js.flow +23 -0
  34. package/dist/browser/runtime.js.flow +7 -0
  35. package/dist/browser/styled/index.d.ts +6 -9
  36. package/dist/browser/styled/index.js.flow +69 -0
  37. package/dist/browser/styled/index.js.map +1 -1
  38. package/dist/browser/types.d.ts +6 -3
  39. package/dist/browser/types.js.flow +29 -0
  40. package/dist/browser/utils/error.js.flow +7 -0
  41. package/dist/cjs/class-names/index.d.ts +2 -2
  42. package/dist/cjs/class-names/index.js.flow +45 -0
  43. package/dist/cjs/css/index.d.ts +16 -3
  44. package/dist/cjs/css/index.js +0 -13
  45. package/dist/cjs/css/index.js.flow +35 -0
  46. package/dist/cjs/css/index.js.map +1 -1
  47. package/dist/cjs/index.d.ts +4 -1
  48. package/dist/cjs/index.js +3 -1
  49. package/dist/cjs/index.js.flow +40 -0
  50. package/dist/cjs/index.js.map +1 -1
  51. package/dist/cjs/keyframes/__fixtures__/index.d.ts +3 -0
  52. package/dist/cjs/keyframes/__fixtures__/index.js +15 -0
  53. package/dist/cjs/keyframes/__fixtures__/index.js.map +1 -0
  54. package/dist/cjs/keyframes/index.d.ts +47 -0
  55. package/dist/cjs/keyframes/index.js +13 -0
  56. package/dist/cjs/keyframes/index.js.flow +54 -0
  57. package/dist/cjs/keyframes/index.js.map +1 -0
  58. package/dist/cjs/runtime/ax.js.flow +27 -0
  59. package/dist/cjs/runtime/css-custom-property.js.flow +19 -0
  60. package/dist/cjs/runtime/dev-warnings.d.ts +0 -1
  61. package/dist/cjs/runtime/dev-warnings.js +2 -3
  62. package/dist/cjs/runtime/dev-warnings.js.flow +7 -0
  63. package/dist/cjs/runtime/dev-warnings.js.map +1 -1
  64. package/dist/cjs/runtime/index.js.flow +10 -0
  65. package/dist/cjs/runtime/is-node.js.flow +19 -0
  66. package/dist/cjs/runtime/sheet.d.ts +1 -1
  67. package/dist/cjs/runtime/sheet.js.flow +36 -0
  68. package/dist/cjs/runtime/style-cache.d.ts +1 -1
  69. package/dist/cjs/runtime/style-cache.js.flow +19 -0
  70. package/dist/cjs/runtime/style.d.ts +1 -1
  71. package/dist/cjs/runtime/style.js.flow +17 -0
  72. package/dist/cjs/runtime/types.js.flow +23 -0
  73. package/dist/cjs/runtime.js.flow +7 -0
  74. package/dist/cjs/styled/index.d.ts +6 -9
  75. package/dist/cjs/styled/index.js.flow +69 -0
  76. package/dist/cjs/styled/index.js.map +1 -1
  77. package/dist/cjs/types.d.ts +6 -3
  78. package/dist/cjs/types.js.flow +29 -0
  79. package/dist/cjs/utils/error.js.flow +7 -0
  80. package/dist/esm/class-names/index.d.ts +2 -2
  81. package/dist/esm/class-names/index.js.flow +45 -0
  82. package/dist/esm/css/index.d.ts +16 -3
  83. package/dist/esm/css/index.js +0 -13
  84. package/dist/esm/css/index.js.flow +35 -0
  85. package/dist/esm/css/index.js.map +1 -1
  86. package/dist/esm/index.d.ts +4 -1
  87. package/dist/esm/index.js +1 -0
  88. package/dist/esm/index.js.flow +40 -0
  89. package/dist/esm/index.js.map +1 -1
  90. package/dist/esm/keyframes/__fixtures__/index.d.ts +3 -0
  91. package/dist/esm/keyframes/__fixtures__/index.js +12 -0
  92. package/dist/esm/keyframes/__fixtures__/index.js.map +1 -0
  93. package/dist/esm/keyframes/index.d.ts +47 -0
  94. package/dist/esm/keyframes/index.js +9 -0
  95. package/dist/esm/keyframes/index.js.flow +54 -0
  96. package/dist/esm/keyframes/index.js.map +1 -0
  97. package/dist/esm/runtime/ax.js.flow +27 -0
  98. package/dist/esm/runtime/css-custom-property.js.flow +19 -0
  99. package/dist/esm/runtime/dev-warnings.d.ts +0 -1
  100. package/dist/esm/runtime/dev-warnings.js +1 -1
  101. package/dist/esm/runtime/dev-warnings.js.flow +7 -0
  102. package/dist/esm/runtime/dev-warnings.js.map +1 -1
  103. package/dist/esm/runtime/index.js.flow +10 -0
  104. package/dist/esm/runtime/is-node.js.flow +19 -0
  105. package/dist/esm/runtime/sheet.d.ts +1 -1
  106. package/dist/esm/runtime/sheet.js.flow +36 -0
  107. package/dist/esm/runtime/style-cache.d.ts +1 -1
  108. package/dist/esm/runtime/style-cache.js.flow +19 -0
  109. package/dist/esm/runtime/style.d.ts +1 -1
  110. package/dist/esm/runtime/style.js.flow +17 -0
  111. package/dist/esm/runtime/types.js.flow +23 -0
  112. package/dist/esm/runtime.js.flow +7 -0
  113. package/dist/esm/styled/index.d.ts +6 -9
  114. package/dist/esm/styled/index.js.flow +69 -0
  115. package/dist/esm/styled/index.js.map +1 -1
  116. package/dist/esm/types.d.ts +6 -3
  117. package/dist/esm/types.js.flow +29 -0
  118. package/dist/esm/utils/error.js.flow +7 -0
  119. package/package.json +18 -20
  120. package/src/class-names/__tests__/types.test.js.flow +28 -0
  121. package/src/class-names/index.js.flow +45 -0
  122. package/src/class-names/index.tsx +2 -2
  123. package/src/css/__tests__/index.test.tsx +41 -0
  124. package/src/css/__tests__/types.test.js.flow +17 -0
  125. package/src/css/index.js.flow +35 -0
  126. package/src/css/index.tsx +25 -3
  127. package/src/index.js.flow +40 -0
  128. package/src/index.tsx +5 -2
  129. package/src/keyframes/__fixtures__/index.tsx +14 -0
  130. package/src/keyframes/__tests__/index.test.tsx +324 -0
  131. package/src/keyframes/__tests__/types.test.js.flow +31 -0
  132. package/src/keyframes/index.js.flow +54 -0
  133. package/src/keyframes/index.tsx +61 -0
  134. package/src/runtime/__tests__/style.test.tsx +91 -57
  135. package/src/runtime/ax.js.flow +27 -0
  136. package/src/runtime/css-custom-property.js.flow +19 -0
  137. package/src/runtime/dev-warnings.js.flow +7 -0
  138. package/src/runtime/dev-warnings.tsx +1 -1
  139. package/src/runtime/index.js.flow +10 -0
  140. package/src/runtime/is-node.js.flow +19 -0
  141. package/src/runtime/sheet.js.flow +36 -0
  142. package/src/runtime/sheet.tsx +1 -1
  143. package/src/runtime/style-cache.js.flow +19 -0
  144. package/src/runtime/style-cache.tsx +1 -1
  145. package/src/runtime/style.js.flow +17 -0
  146. package/src/runtime/style.tsx +1 -1
  147. package/src/runtime/types.js.flow +23 -0
  148. package/src/runtime.js.flow +7 -0
  149. package/src/styled/__tests__/types.test.js.flow +30 -0
  150. package/src/styled/index.js.flow +69 -0
  151. package/src/styled/index.tsx +6 -10
  152. package/src/types.js.flow +29 -0
  153. package/src/types.tsx +7 -3
  154. package/src/utils/error.js.flow +7 -0
  155. package/dist/browser/codemods/codemods-helpers.d.ts +0 -60
  156. package/dist/browser/codemods/codemods-helpers.js +0 -201
  157. package/dist/browser/codemods/codemods-helpers.js.map +0 -1
  158. package/dist/browser/codemods/constants.d.ts +0 -3
  159. package/dist/browser/codemods/constants.js +0 -4
  160. package/dist/browser/codemods/constants.js.map +0 -1
  161. package/dist/browser/codemods/emotion-to-compiled/emotion-to-compiled.d.ts +0 -3
  162. package/dist/browser/codemods/emotion-to-compiled/emotion-to-compiled.js +0 -178
  163. package/dist/browser/codemods/emotion-to-compiled/emotion-to-compiled.js.map +0 -1
  164. package/dist/browser/codemods/emotion-to-compiled/index.d.ts +0 -1
  165. package/dist/browser/codemods/emotion-to-compiled/index.js +0 -2
  166. package/dist/browser/codemods/emotion-to-compiled/index.js.map +0 -1
  167. package/dist/browser/codemods/styled-components-to-compiled/index.d.ts +0 -1
  168. package/dist/browser/codemods/styled-components-to-compiled/index.js +0 -2
  169. package/dist/browser/codemods/styled-components-to-compiled/index.js.map +0 -1
  170. package/dist/browser/codemods/styled-components-to-compiled/styled-components-to-compiled.d.ts +0 -3
  171. package/dist/browser/codemods/styled-components-to-compiled/styled-components-to-compiled.js +0 -33
  172. package/dist/browser/codemods/styled-components-to-compiled/styled-components-to-compiled.js.map +0 -1
  173. package/dist/cjs/codemods/codemods-helpers.d.ts +0 -60
  174. package/dist/cjs/codemods/codemods-helpers.js +0 -217
  175. package/dist/cjs/codemods/codemods-helpers.js.map +0 -1
  176. package/dist/cjs/codemods/constants.d.ts +0 -3
  177. package/dist/cjs/codemods/constants.js +0 -7
  178. package/dist/cjs/codemods/constants.js.map +0 -1
  179. package/dist/cjs/codemods/emotion-to-compiled/emotion-to-compiled.d.ts +0 -3
  180. package/dist/cjs/codemods/emotion-to-compiled/emotion-to-compiled.js +0 -180
  181. package/dist/cjs/codemods/emotion-to-compiled/emotion-to-compiled.js.map +0 -1
  182. package/dist/cjs/codemods/emotion-to-compiled/index.d.ts +0 -1
  183. package/dist/cjs/codemods/emotion-to-compiled/index.js +0 -9
  184. package/dist/cjs/codemods/emotion-to-compiled/index.js.map +0 -1
  185. package/dist/cjs/codemods/styled-components-to-compiled/index.d.ts +0 -1
  186. package/dist/cjs/codemods/styled-components-to-compiled/index.js +0 -9
  187. package/dist/cjs/codemods/styled-components-to-compiled/index.js.map +0 -1
  188. package/dist/cjs/codemods/styled-components-to-compiled/styled-components-to-compiled.d.ts +0 -3
  189. package/dist/cjs/codemods/styled-components-to-compiled/styled-components-to-compiled.js +0 -35
  190. package/dist/cjs/codemods/styled-components-to-compiled/styled-components-to-compiled.js.map +0 -1
  191. package/dist/esm/codemods/codemods-helpers.d.ts +0 -60
  192. package/dist/esm/codemods/codemods-helpers.js +0 -201
  193. package/dist/esm/codemods/codemods-helpers.js.map +0 -1
  194. package/dist/esm/codemods/constants.d.ts +0 -3
  195. package/dist/esm/codemods/constants.js +0 -4
  196. package/dist/esm/codemods/constants.js.map +0 -1
  197. package/dist/esm/codemods/emotion-to-compiled/emotion-to-compiled.d.ts +0 -3
  198. package/dist/esm/codemods/emotion-to-compiled/emotion-to-compiled.js +0 -178
  199. package/dist/esm/codemods/emotion-to-compiled/emotion-to-compiled.js.map +0 -1
  200. package/dist/esm/codemods/emotion-to-compiled/index.d.ts +0 -1
  201. package/dist/esm/codemods/emotion-to-compiled/index.js +0 -2
  202. package/dist/esm/codemods/emotion-to-compiled/index.js.map +0 -1
  203. package/dist/esm/codemods/styled-components-to-compiled/index.d.ts +0 -1
  204. package/dist/esm/codemods/styled-components-to-compiled/index.js +0 -2
  205. package/dist/esm/codemods/styled-components-to-compiled/index.js.map +0 -1
  206. package/dist/esm/codemods/styled-components-to-compiled/styled-components-to-compiled.d.ts +0 -3
  207. package/dist/esm/codemods/styled-components-to-compiled/styled-components-to-compiled.js +0 -33
  208. package/dist/esm/codemods/styled-components-to-compiled/styled-components-to-compiled.js.map +0 -1
  209. package/src/codemods/README.md +0 -8
  210. package/src/codemods/codemods-helpers.tsx +0 -369
  211. package/src/codemods/constants.tsx +0 -3
  212. package/src/codemods/emotion-to-compiled/README.md +0 -71
  213. package/src/codemods/emotion-to-compiled/__tests__/emotion-to-compiled.test.tsx +0 -526
  214. package/src/codemods/emotion-to-compiled/emotion-to-compiled.tsx +0 -249
  215. package/src/codemods/emotion-to-compiled/index.tsx +0 -1
  216. package/src/codemods/styled-components-to-compiled/README.md +0 -37
  217. package/src/codemods/styled-components-to-compiled/__tests__/styled-components-to-compiled.test.tsx +0 -109
  218. package/src/codemods/styled-components-to-compiled/index.tsx +0 -1
  219. package/src/codemods/styled-components-to-compiled/styled-components-to-compiled.tsx +0 -45
@@ -0,0 +1,41 @@
1
+ import { render } from '@testing-library/react';
2
+ import React from 'react';
3
+ import '@compiled/react';
4
+ import { css } from '@compiled/react';
5
+
6
+ describe('css prop', () => {
7
+ it('should create css from object literal', () => {
8
+ const { getByText } = render(<div css={css({ fontSize: '13px' })}>hello world</div>);
9
+
10
+ expect(getByText('hello world')).toHaveCompiledCss('font-size', '13px');
11
+ });
12
+
13
+ it('should create css from object literal call expression', () => {
14
+ const style = css({ fontSize: '13px' });
15
+ const { getByText } = render(<div css={style}>hello world</div>);
16
+
17
+ expect(getByText('hello world')).toHaveCompiledCss('font-size', '13px');
18
+ });
19
+
20
+ it('should create css from tagged template expression', () => {
21
+ const { getByText } = render(
22
+ <div
23
+ css={css`
24
+ font-size: 13px;
25
+ `}>
26
+ hello world
27
+ </div>
28
+ );
29
+
30
+ expect(getByText('hello world')).toHaveCompiledCss('font-size', '13px');
31
+ });
32
+
33
+ it('should create css from tagged template expression variable', () => {
34
+ const style = css`
35
+ font-size: 13px;
36
+ `;
37
+ const { getByText } = render(<div css={style}>hello world</div>);
38
+
39
+ expect(getByText('hello world')).toHaveCompiledCss('font-size', '13px');
40
+ });
41
+ });
@@ -0,0 +1,17 @@
1
+ // @flow strict-local
2
+ import React from 'react';
3
+ import { css } from '@compiled/react';
4
+
5
+ // Tagged template expression
6
+ (): React$Element<'div'> => {
7
+ const styles = css`
8
+ color: red;
9
+ `;
10
+ return <div css={styles}>red text</div>;
11
+ };
12
+
13
+ // Object call expression
14
+ (): React$Element<'div'> => {
15
+ const styles = css({ color: 'red' });
16
+ return <div css={styles}>red text</div>;
17
+ };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Flowtype definitions for index
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.15.0
5
+ * @flow
6
+ */
7
+ import type { BasicTemplateInterpolations, CSSProps, FunctionInterpolation } from '../types';
8
+ /**
9
+ * Create styles that can be re-used between components with a template literal.
10
+ *
11
+ * ```
12
+ * css`color: red;`;
13
+ * ```
14
+ *
15
+ * For more help, read the docs:
16
+ * https://compiledcssinjs.com/docs/api-css
17
+ * @param css
18
+ * @param values
19
+ */
20
+ declare export default function css<T>(
21
+ _css: $ReadOnlyArray<string>,
22
+ ..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
23
+ ): CSSProps;
24
+ /**
25
+ * Create styles that can be re-used between components with an object
26
+ *
27
+ * ```
28
+ * css({ color: 'red' });
29
+ * ```
30
+ *
31
+ * For more help, read the docs:
32
+ * https://compiledcssinjs.com/docs/api-css
33
+ * @param css
34
+ */
35
+ declare export default function css(_css: CSSProps): CSSProps;
package/src/css/index.tsx CHANGED
@@ -1,8 +1,8 @@
1
1
  import { createSetupError } from '../utils/error';
2
- import type { CSSProps } from '../types';
2
+ import type { BasicTemplateInterpolations, CSSProps, FunctionInterpolation } from '../types';
3
3
 
4
4
  /**
5
- * Create styles that can be re-used between components.
5
+ * Create styles that can be re-used between components with a template literal.
6
6
  *
7
7
  * ```
8
8
  * css`color: red;`;
@@ -14,6 +14,28 @@ import type { CSSProps } from '../types';
14
14
  * @param css
15
15
  * @param values
16
16
  */
17
- export default function css(_css: TemplateStringsArray, ..._values:(string|number)[]): CSSProps {
17
+ export default function css<T = void>(
18
+ _css: TemplateStringsArray,
19
+ ..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
20
+ ): CSSProps;
21
+
22
+ /**
23
+ * Create styles that can be re-used between components with an object
24
+ *
25
+ * ```
26
+ * css({ color: 'red' });
27
+ * ```
28
+ *
29
+ * For more help, read the docs:
30
+ * https://compiledcssinjs.com/docs/api-css
31
+ *
32
+ * @param css
33
+ */
34
+ export default function css(_css: CSSProps): CSSProps;
35
+
36
+ export default function css<T = void>(
37
+ _css: TemplateStringsArray | CSSProps,
38
+ ..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
39
+ ): CSSProps {
18
40
  throw createSetupError();
19
41
  }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Flowtype definitions for index
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.15.0
5
+ * @flow
6
+ */
7
+ import type { CssFunction, CSSProps } from './types';
8
+ declare export { keyframes } from './keyframes';
9
+ declare export { styled } from './styled';
10
+ declare export { ClassNames } from './class-names';
11
+ declare export { default as css } from './css';
12
+ export type { CssFunction, CSSProps };
13
+ export type { CssObject } from './styled';
14
+ declare module 'react' {
15
+ declare interface DOMAttributes<T> {
16
+ css?: CssFunction<> | CssFunction<>[];
17
+ }
18
+ }
19
+ declare module 'global' {
20
+ declare var JSX: typeof npm$namespace$JSX;
21
+ declare var npm$namespace$JSX: {|
22
+ IntrinsicAttributes: Class<JSX$IntrinsicAttributes>,
23
+ |};
24
+ declare interface JSX$IntrinsicAttributes {
25
+ /**
26
+ * Tie styles to an element.
27
+ * It is available when the `@compiled/react` module is in scope.
28
+ *
29
+ * ```
30
+ * css={{ fontSize: 12 }} // Object CSS
31
+ * css={`font-size: 12px;`} // Template literal CSS
32
+ * css={[{ fontSize: 12 }, `font-size: 12px;`]} // Array CSS
33
+ * ```
34
+ *
35
+ * For more help, read the docs:
36
+ * https://compiledcssinjs.com/docs/api-css-prop
37
+ */
38
+ css?: CssFunction<> | CssFunction<>[];
39
+ }
40
+ }
package/src/index.tsx CHANGED
@@ -1,8 +1,11 @@
1
+ import type { CssFunction, CSSProps } from './types';
2
+
3
+ export { keyframes } from './keyframes';
1
4
  export { styled } from './styled';
2
5
  export { ClassNames } from './class-names';
3
6
  export { default as css } from './css';
4
-
5
- import { CssFunction } from './types';
7
+ export type { CssFunction, CSSProps };
8
+ export type { CssObject } from './styled';
6
9
 
7
10
  declare module 'react' {
8
11
  // We must match the same type signature so the generic needs to stay.
@@ -0,0 +1,14 @@
1
+ import { keyframes } from '@compiled/react';
2
+
3
+ export const fadeOut = keyframes({
4
+ from: {
5
+ opacity: 1,
6
+ },
7
+ to: {
8
+ opacity: 0,
9
+ },
10
+ });
11
+
12
+ export const namedFadeOut = fadeOut;
13
+
14
+ export default fadeOut;
@@ -0,0 +1,324 @@
1
+ import { keyframes, styled } from '@compiled/react';
2
+ import { render } from '@testing-library/react';
3
+
4
+ import defaultFadeOut, { fadeOut as shadowedFadeOut, namedFadeOut } from '../__fixtures__';
5
+
6
+ const getOpacity = (str: string | number) => str;
7
+
8
+ const getKeyframe = (name: string) => {
9
+ const styles = Array.from(
10
+ document.body.querySelectorAll('style'),
11
+ (style) => style.innerHTML
12
+ ).join('\n');
13
+
14
+ return styles.substring(styles.indexOf(`@keyframes ${name}`));
15
+ };
16
+
17
+ describe('keyframes', () => {
18
+ describe('referenced through a css prop', () => {
19
+ describe('render an animation', () => {
20
+ it('given an object call expression argument', () => {
21
+ const fadeOut = keyframes({
22
+ from: {
23
+ opacity: 1,
24
+ },
25
+ to: {
26
+ opacity: 0,
27
+ },
28
+ });
29
+
30
+ const { getByText } = render(<div css={{ animationName: fadeOut }}>hello world</div>);
31
+
32
+ expect(getByText('hello world')).toHaveCompiledCss('animation-name', 'k1m8j3od');
33
+ expect(getKeyframe('k1m8j3od')).toMatchInlineSnapshot(
34
+ `"@keyframes k1m8j3od{0%{opacity:1}to{opacity:0}}"`
35
+ );
36
+ });
37
+
38
+ it('given a template literal call expression argument', () => {
39
+ const fadeOut = keyframes(`from { opacity: 1; } to { opacity: 0; }`);
40
+ const { getByText } = render(<div css={{ animationName: fadeOut }}>hello world</div>);
41
+
42
+ expect(getByText('hello world')).toHaveCompiledCss('animation-name', 'klmf72q');
43
+ expect(getKeyframe('klmf72q')).toMatchInlineSnapshot(
44
+ `"@keyframes klmf72q{0%{opacity:1}to{opacity:0}}"`
45
+ );
46
+ });
47
+
48
+ it('given a string call expression argument', () => {
49
+ const fadeOut = keyframes('from { opacity: 1; } to { opacity: 0; }');
50
+ const { getByText } = render(<div css={{ animationName: fadeOut }}>hello world</div>);
51
+
52
+ expect(getByText('hello world')).toHaveCompiledCss('animation-name', 'k1b0zjii');
53
+ expect(getKeyframe('k1b0zjii')).toMatchInlineSnapshot(
54
+ `"@keyframes k1b0zjii{0%{opacity:1}to{opacity:0}}"`
55
+ );
56
+ });
57
+
58
+ it('given a tagged template expression', () => {
59
+ const fadeOut = keyframes`
60
+ from { opacity: 1; }
61
+ to { opacity: 0; }
62
+ `;
63
+
64
+ const { getByText } = render(<div css={{ animationName: fadeOut }}>hello world</div>);
65
+
66
+ expect(getByText('hello world')).toHaveCompiledCss('animation-name', 'k1vk0ha6');
67
+ expect(getKeyframe('k1vk0ha6')).toMatchInlineSnapshot(
68
+ `"@keyframes k1vk0ha6{0%{opacity:1}to{opacity:0}}"`
69
+ );
70
+ });
71
+
72
+ it('defined in a default import', () => {
73
+ const { getByText } = render(
74
+ <div css={{ animationName: defaultFadeOut }}>hello world</div>
75
+ );
76
+
77
+ expect(getByText('hello world')).toHaveCompiledCss('animation-name', 'k1m8j3od');
78
+ expect(getKeyframe('k1m8j3od')).toMatchInlineSnapshot(
79
+ `"@keyframes k1m8j3od{0%{opacity:1}to{opacity:0}}"`
80
+ );
81
+ });
82
+
83
+ it('defined in an imported named import', () => {
84
+ const { getByText } = render(<div css={{ animationName: namedFadeOut }}>hello world</div>);
85
+
86
+ expect(getByText('hello world')).toHaveCompiledCss('animation-name', 'k1m8j3od');
87
+ expect(getKeyframe('k1m8j3od')).toMatchInlineSnapshot(
88
+ `"@keyframes k1m8j3od{0%{opacity:1}to{opacity:0}}"`
89
+ );
90
+ });
91
+
92
+ it('defined in a local named import', () => {
93
+ const { getByText } = render(
94
+ <div css={{ animationName: shadowedFadeOut }}>hello world</div>
95
+ );
96
+
97
+ expect(getByText('hello world')).toHaveCompiledCss('animation-name', 'k1m8j3od');
98
+ expect(getKeyframe('k1m8j3od')).toMatchInlineSnapshot(
99
+ `"@keyframes k1m8j3od{0%{opacity:1}to{opacity:0}}"`
100
+ );
101
+ });
102
+
103
+ it('containing a call expression', () => {
104
+ const from = 1;
105
+ const to = 0;
106
+
107
+ const fadeOut = keyframes({
108
+ from: {
109
+ opacity: getOpacity(from),
110
+ },
111
+ to: {
112
+ opacity: getOpacity(to),
113
+ },
114
+ });
115
+
116
+ const { getByText } = render(<div css={{ animationName: fadeOut }}>hello world</div>);
117
+
118
+ expect(getByText('hello world')).toHaveCompiledCss('animation-name', 'kbrsk95');
119
+ expect(getKeyframe('kbrsk95')).toMatchInlineSnapshot(
120
+ `"@keyframes kbrsk95{0%{opacity:1}to{opacity:0}}"`
121
+ );
122
+ });
123
+
124
+ it('containing an identifier referencing a constant numeric literal', () => {
125
+ const fromOpacity = 1;
126
+ const toOpacity = 0;
127
+
128
+ const fadeOut = keyframes({
129
+ from: {
130
+ opacity: fromOpacity,
131
+ },
132
+ to: {
133
+ opacity: toOpacity,
134
+ },
135
+ });
136
+
137
+ const { getByText } = render(<div css={{ animationName: fadeOut }}>hello world</div>);
138
+
139
+ expect(getByText('hello world')).toHaveCompiledCss('animation-name', 'korwhog');
140
+ expect(getKeyframe('korwhog')).toMatchInlineSnapshot(
141
+ `"@keyframes korwhog{0%{opacity:1}to{opacity:0}}"`
142
+ );
143
+ });
144
+
145
+ it('containing an identifier referencing a call expression', () => {
146
+ const fromOpacity = getOpacity(1);
147
+ const toOpacity = getOpacity(0);
148
+
149
+ const fadeOut = keyframes({
150
+ from: {
151
+ opacity: fromOpacity,
152
+ },
153
+ to: {
154
+ opacity: toOpacity,
155
+ },
156
+ });
157
+
158
+ const { getByText } = render(<div css={{ animationName: fadeOut }}>hello world</div>);
159
+
160
+ expect(getByText('hello world')).toHaveCompiledCss('animation-name', 'korwhog');
161
+ expect(getKeyframe('korwhog')).toMatchInlineSnapshot(
162
+ `"@keyframes korwhog{0%{opacity:1}to{opacity:0}}"`
163
+ );
164
+ });
165
+ });
166
+ });
167
+
168
+ describe('referenced through a styled component', () => {
169
+ describe('render an animation', () => {
170
+ it('given an object call expression argument', () => {
171
+ const fadeOut = keyframes({
172
+ from: {
173
+ opacity: 1,
174
+ },
175
+ to: {
176
+ opacity: 0,
177
+ },
178
+ });
179
+
180
+ const Component = styled.div({ animationName: fadeOut });
181
+
182
+ const { getByText } = render(<Component>hello world</Component>);
183
+
184
+ expect(getByText('hello world')).toHaveCompiledCss('animation-name', 'k1m8j3od');
185
+ expect(getKeyframe('k1m8j3od')).toMatchInlineSnapshot(
186
+ `"@keyframes k1m8j3od{0%{opacity:1}to{opacity:0}}"`
187
+ );
188
+ });
189
+
190
+ it('given a template literal call expression argument', () => {
191
+ const fadeOut = keyframes(`from { opacity: 1; } to { opacity: 0; }`);
192
+ const Component = styled.div({ animationName: fadeOut });
193
+ const { getByText } = render(<Component>hello world</Component>);
194
+
195
+ expect(getByText('hello world')).toHaveCompiledCss('animation-name', 'klmf72q');
196
+ expect(getKeyframe('klmf72q')).toMatchInlineSnapshot(
197
+ `"@keyframes klmf72q{0%{opacity:1}to{opacity:0}}"`
198
+ );
199
+ });
200
+
201
+ it('given a string call expression argument', () => {
202
+ const fadeOut = keyframes('from { opacity: 1; } to { opacity: 0; }');
203
+ const Component = styled.div({ animationName: fadeOut });
204
+ const { getByText } = render(<Component>hello world</Component>);
205
+
206
+ expect(getByText('hello world')).toHaveCompiledCss('animation-name', 'k1b0zjii');
207
+ expect(getKeyframe('k1b0zjii')).toMatchInlineSnapshot(
208
+ `"@keyframes k1b0zjii{0%{opacity:1}to{opacity:0}}"`
209
+ );
210
+ });
211
+
212
+ it('given a tagged template expression', () => {
213
+ const fadeOut = keyframes`
214
+ from { opacity: 1; }
215
+ to { opacity: 0; }
216
+ `;
217
+
218
+ const Component = styled.div({ animationName: fadeOut });
219
+ const { getByText } = render(<Component>hello world</Component>);
220
+
221
+ expect(getByText('hello world')).toHaveCompiledCss('animation-name', 'k1vk0ha6');
222
+ expect(getKeyframe('k1vk0ha6')).toMatchInlineSnapshot(
223
+ `"@keyframes k1vk0ha6{0%{opacity:1}to{opacity:0}}"`
224
+ );
225
+ });
226
+
227
+ it('defined in a default export', () => {
228
+ const Component = styled.div({ animationName: defaultFadeOut });
229
+ const { getByText } = render(<Component>hello world</Component>);
230
+
231
+ expect(getByText('hello world')).toHaveCompiledCss('animation-name', 'k1m8j3od');
232
+ expect(getKeyframe('k1m8j3od')).toMatchInlineSnapshot(
233
+ `"@keyframes k1m8j3od{0%{opacity:1}to{opacity:0}}"`
234
+ );
235
+ });
236
+
237
+ it('defined in an imported named import', () => {
238
+ const Component = styled.div({ animationName: namedFadeOut });
239
+ const { getByText } = render(<Component>hello world</Component>);
240
+
241
+ expect(getByText('hello world')).toHaveCompiledCss('animation-name', 'k1m8j3od');
242
+ expect(getKeyframe('k1m8j3od')).toMatchInlineSnapshot(
243
+ `"@keyframes k1m8j3od{0%{opacity:1}to{opacity:0}}"`
244
+ );
245
+ });
246
+
247
+ it('defined in a local named import', () => {
248
+ const Component = styled.div({ animationName: shadowedFadeOut });
249
+ const { getByText } = render(<Component>hello world</Component>);
250
+
251
+ expect(getByText('hello world')).toHaveCompiledCss('animation-name', 'k1m8j3od');
252
+ expect(getKeyframe('k1m8j3od')).toMatchInlineSnapshot(
253
+ `"@keyframes k1m8j3od{0%{opacity:1}to{opacity:0}}"`
254
+ );
255
+ });
256
+
257
+ it('containing a call expression', () => {
258
+ const from = 1;
259
+ const to = 0;
260
+
261
+ const fadeOut = keyframes({
262
+ from: {
263
+ opacity: getOpacity(from),
264
+ },
265
+ to: {
266
+ opacity: getOpacity(to),
267
+ },
268
+ });
269
+
270
+ const Component = styled.div({ animationName: fadeOut });
271
+ const { getByText } = render(<Component>hello world</Component>);
272
+
273
+ expect(getByText('hello world')).toHaveCompiledCss('animation-name', 'kbrsk95');
274
+ expect(getKeyframe('kbrsk95')).toMatchInlineSnapshot(
275
+ `"@keyframes kbrsk95{0%{opacity:1}to{opacity:0}}"`
276
+ );
277
+ });
278
+
279
+ it('containing an identifier referencing a constant numeric literal', () => {
280
+ const fromOpacity = 1;
281
+ const toOpacity = 0;
282
+
283
+ const fadeOut = keyframes({
284
+ from: {
285
+ opacity: fromOpacity,
286
+ },
287
+ to: {
288
+ opacity: toOpacity,
289
+ },
290
+ });
291
+
292
+ const Component = styled.div({ animationName: fadeOut });
293
+ const { getByText } = render(<Component>hello world</Component>);
294
+
295
+ expect(getByText('hello world')).toHaveCompiledCss('animation-name', 'korwhog');
296
+ expect(getKeyframe('korwhog')).toMatchInlineSnapshot(
297
+ `"@keyframes korwhog{0%{opacity:1}to{opacity:0}}"`
298
+ );
299
+ });
300
+
301
+ it('containing an identifier referencing a call expression', () => {
302
+ const fromOpacity = getOpacity(1);
303
+ const toOpacity = getOpacity(0);
304
+
305
+ const fadeOut = keyframes({
306
+ from: {
307
+ opacity: fromOpacity,
308
+ },
309
+ to: {
310
+ opacity: toOpacity,
311
+ },
312
+ });
313
+
314
+ const Component = styled.div({ animationName: fadeOut });
315
+ const { getByText } = render(<Component>hello world</Component>);
316
+
317
+ expect(getByText('hello world')).toHaveCompiledCss('animation-name', 'korwhog');
318
+ expect(getKeyframe('korwhog')).toMatchInlineSnapshot(
319
+ `"@keyframes korwhog{0%{opacity:1}to{opacity:0}}"`
320
+ );
321
+ });
322
+ });
323
+ });
324
+ });
@@ -0,0 +1,31 @@
1
+ // @flow strict-local
2
+ import React from 'react';
3
+ import { css, ClassNames, styled, keyframes } from '@compiled/react';
4
+
5
+ // Tagged template expression
6
+ (): React$Element<'div'> => {
7
+ const fadeOut = keyframes`
8
+ from { opacity: 1; }
9
+ to { opacity: 0; }
10
+ `;
11
+ return <div css={{ animationName: fadeOut }}>hello world</div>;
12
+ };
13
+
14
+ // Object call expression
15
+ (): React$Element<'div'> => {
16
+ const fadeOut = keyframes({
17
+ from: {
18
+ opacity: 1,
19
+ },
20
+ to: {
21
+ opacity: 0,
22
+ },
23
+ });
24
+ return <div css={{ animationName: fadeOut }}>hello world</div>;
25
+ };
26
+
27
+ // String call expression
28
+ (): React$Element<'div'> => {
29
+ const fadeOut = keyframes('from { opacity: 1; } to { opacity: 0; }');
30
+ return <div css={{ animationName: fadeOut }}>hello world</div>;
31
+ };
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Flowtype definitions for index
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.15.0
5
+ * @flow
6
+ */
7
+ import type { BasicTemplateInterpolations, CSSProps } from '../types';
8
+ export type KeyframeSteps = string | { [key: string]: CSSProps, ... };
9
+ /**
10
+ * Create keyframes using a tagged template expression:
11
+ *
12
+ * ```
13
+ * const fadeOut = keyframes`
14
+ * from { opacity: 1; }
15
+ * to { opacity: 0; }
16
+ * `;
17
+ * ```
18
+ * @param _strings The input string values
19
+ * @param _interpolations The arguments used in the expression
20
+ */
21
+ declare export function keyframes(
22
+ _strings: $ReadOnlyArray<string>,
23
+ ..._interpolations: BasicTemplateInterpolations[]
24
+ ): string;
25
+ /**
26
+ * Create keyframes using:
27
+ *
28
+ * 1. An object expression
29
+ *
30
+ * ```
31
+ * const fadeOut = keyframes({
32
+ * from: {
33
+ * opacity: 1,
34
+ * },
35
+ * to: {
36
+ * opacity: 0,
37
+ * },
38
+ * });
39
+ * ```
40
+ *
41
+ * 2. A string
42
+ *
43
+ * ```
44
+ * const fadeOut = keyframes('from { opacity: 1; } to { opacity: 0; }');
45
+ * ```
46
+ *
47
+ * 3. A template literal
48
+ *
49
+ * ```
50
+ * const fadeOut = keyframes(`from { opacity: 1; } to { opacity: 0; }`);
51
+ * ```
52
+ * @param _steps The waypoints along the animation sequence
53
+ */
54
+ declare export function keyframes(_steps: KeyframeSteps): string;
@@ -0,0 +1,61 @@
1
+ import type { BasicTemplateInterpolations, CSSProps } from '../types';
2
+ import { createSetupError } from '../utils/error';
3
+
4
+ export type KeyframeSteps = string | Record<string, CSSProps>;
5
+
6
+ /**
7
+ * Create keyframes using a tagged template expression:
8
+ *
9
+ * ```
10
+ * const fadeOut = keyframes`
11
+ * from { opacity: 1; }
12
+ * to { opacity: 0; }
13
+ * `;
14
+ * ```
15
+ *
16
+ * @param _strings The input string values
17
+ * @param _interpolations The arguments used in the expression
18
+ */
19
+ export function keyframes(
20
+ _strings: TemplateStringsArray,
21
+ ..._interpolations: BasicTemplateInterpolations[]
22
+ ): string;
23
+
24
+ /**
25
+ * Create keyframes using:
26
+ *
27
+ * 1. An object expression
28
+ *
29
+ * ```
30
+ * const fadeOut = keyframes({
31
+ * from: {
32
+ * opacity: 1,
33
+ * },
34
+ * to: {
35
+ * opacity: 0,
36
+ * },
37
+ * });
38
+ * ```
39
+ *
40
+ * 2. A string
41
+ *
42
+ * ```
43
+ * const fadeOut = keyframes('from { opacity: 1; } to { opacity: 0; }');
44
+ * ```
45
+ *
46
+ * 3. A template literal
47
+ *
48
+ * ```
49
+ * const fadeOut = keyframes(`from { opacity: 1; } to { opacity: 0; }`);
50
+ * ```
51
+ *
52
+ * @param _steps The waypoints along the animation sequence
53
+ */
54
+ export function keyframes(_steps: KeyframeSteps): string;
55
+
56
+ export function keyframes(
57
+ _stringsOrSteps: TemplateStringsArray | KeyframeSteps,
58
+ ..._interpolations: BasicTemplateInterpolations[]
59
+ ): string {
60
+ throw createSetupError();
61
+ }