@compiled/react 0.10.0 → 0.10.3

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 (107) hide show
  1. package/dist/browser/class-names/index.d.ts +21 -15
  2. package/dist/browser/class-names/index.js +1 -27
  3. package/dist/browser/class-names/index.js.map +1 -1
  4. package/dist/browser/css/index.d.ts +22 -19
  5. package/dist/browser/css/index.js +3 -3
  6. package/dist/browser/css/index.js.map +1 -1
  7. package/dist/browser/jsx/jsx-local-namespace.d.ts +32 -6
  8. package/dist/browser/keyframes/__fixtures__/index.js +1 -0
  9. package/dist/browser/keyframes/__fixtures__/index.js.map +1 -1
  10. package/dist/browser/keyframes/index.d.ts +20 -24
  11. package/dist/browser/keyframes/index.js.map +1 -1
  12. package/dist/browser/runtime/cache.d.ts +12 -0
  13. package/dist/browser/runtime/cache.js +15 -0
  14. package/dist/browser/runtime/cache.js.flow +18 -0
  15. package/dist/browser/runtime/cache.js.map +1 -0
  16. package/dist/browser/runtime/dev-warnings.js +10 -6
  17. package/dist/browser/runtime/dev-warnings.js.map +1 -1
  18. package/dist/browser/runtime/is-node.js +1 -3
  19. package/dist/browser/runtime/is-node.js.map +1 -1
  20. package/dist/browser/runtime/sheet.js +5 -1
  21. package/dist/browser/runtime/sheet.js.map +1 -1
  22. package/dist/browser/runtime/style-cache.js +4 -0
  23. package/dist/browser/runtime/style-cache.js.map +1 -1
  24. package/dist/browser/styled/index.d.ts +35 -7
  25. package/dist/browser/styled/index.js +35 -7
  26. package/dist/browser/styled/index.js.map +1 -1
  27. package/dist/cjs/class-names/index.d.ts +21 -15
  28. package/dist/cjs/class-names/index.js +2 -28
  29. package/dist/cjs/class-names/index.js.map +1 -1
  30. package/dist/cjs/css/index.d.ts +22 -19
  31. package/dist/cjs/css/index.js +4 -4
  32. package/dist/cjs/css/index.js.map +1 -1
  33. package/dist/cjs/jsx/jsx-local-namespace.d.ts +32 -6
  34. package/dist/cjs/keyframes/__fixtures__/index.js +2 -1
  35. package/dist/cjs/keyframes/__fixtures__/index.js.map +1 -1
  36. package/dist/cjs/keyframes/index.d.ts +20 -24
  37. package/dist/cjs/keyframes/index.js +1 -1
  38. package/dist/cjs/keyframes/index.js.map +1 -1
  39. package/dist/cjs/runtime/cache.d.ts +12 -0
  40. package/dist/cjs/runtime/cache.js +19 -0
  41. package/dist/cjs/runtime/cache.js.flow +18 -0
  42. package/dist/cjs/runtime/cache.js.map +1 -0
  43. package/dist/cjs/runtime/dev-warnings.js +10 -6
  44. package/dist/cjs/runtime/dev-warnings.js.map +1 -1
  45. package/dist/cjs/runtime/is-node.js +1 -3
  46. package/dist/cjs/runtime/is-node.js.map +1 -1
  47. package/dist/cjs/runtime/sheet.js +6 -2
  48. package/dist/cjs/runtime/sheet.js.map +1 -1
  49. package/dist/cjs/runtime/style-cache.js +10 -6
  50. package/dist/cjs/runtime/style-cache.js.map +1 -1
  51. package/dist/cjs/runtime/style.js +4 -4
  52. package/dist/cjs/runtime/style.js.map +1 -1
  53. package/dist/cjs/styled/index.d.ts +35 -7
  54. package/dist/cjs/styled/index.js +36 -8
  55. package/dist/cjs/styled/index.js.map +1 -1
  56. package/dist/esm/class-names/index.d.ts +21 -15
  57. package/dist/esm/class-names/index.js +1 -27
  58. package/dist/esm/class-names/index.js.map +1 -1
  59. package/dist/esm/css/index.d.ts +22 -19
  60. package/dist/esm/css/index.js +3 -3
  61. package/dist/esm/css/index.js.map +1 -1
  62. package/dist/esm/jsx/jsx-local-namespace.d.ts +32 -6
  63. package/dist/esm/keyframes/__fixtures__/index.js +1 -0
  64. package/dist/esm/keyframes/__fixtures__/index.js.map +1 -1
  65. package/dist/esm/keyframes/index.d.ts +20 -24
  66. package/dist/esm/keyframes/index.js.map +1 -1
  67. package/dist/esm/runtime/cache.d.ts +12 -0
  68. package/dist/esm/runtime/cache.js +15 -0
  69. package/dist/esm/runtime/cache.js.flow +18 -0
  70. package/dist/esm/runtime/cache.js.map +1 -0
  71. package/dist/esm/runtime/dev-warnings.js +10 -6
  72. package/dist/esm/runtime/dev-warnings.js.map +1 -1
  73. package/dist/esm/runtime/is-node.js +1 -3
  74. package/dist/esm/runtime/is-node.js.map +1 -1
  75. package/dist/esm/runtime/sheet.js +5 -1
  76. package/dist/esm/runtime/sheet.js.map +1 -1
  77. package/dist/esm/runtime/style-cache.js +4 -0
  78. package/dist/esm/runtime/style-cache.js.map +1 -1
  79. package/dist/esm/styled/index.d.ts +35 -7
  80. package/dist/esm/styled/index.js +35 -7
  81. package/dist/esm/styled/index.js.map +1 -1
  82. package/package.json +8 -5
  83. package/src/__tests__/browser.test.tsx +1 -6
  84. package/src/__tests__/display-names.test.tsx +1 -0
  85. package/src/__tests__/jest-matcher.test.tsx +2 -0
  86. package/src/__tests__/ssr.test.tsx +3 -1
  87. package/src/class-names/__tests__/index.test.tsx +1 -0
  88. package/src/class-names/index.tsx +23 -13
  89. package/src/css/__tests__/index.test.tsx +8 -0
  90. package/src/css/index.tsx +32 -24
  91. package/src/jsx/__tests__/jsx-pragma.test.tsx +1 -0
  92. package/src/jsx/jsx-local-namespace.tsx +32 -6
  93. package/src/keyframes/__fixtures__/index.tsx +1 -0
  94. package/src/keyframes/__tests__/index.test.tsx +18 -5
  95. package/src/keyframes/index.tsx +24 -28
  96. package/src/runtime/__perf__/cs.test.tsx +137 -92
  97. package/src/runtime/__perf__/utils/cs.tsx +15 -15
  98. package/src/runtime/__tests__/style-ssr.test.tsx +4 -0
  99. package/src/runtime/__tests__/style.test.tsx +0 -4
  100. package/src/runtime/cache.js.flow +18 -0
  101. package/src/runtime/cache.tsx +14 -0
  102. package/src/runtime/is-node.tsx +1 -2
  103. package/src/runtime/sheet.tsx +7 -1
  104. package/src/runtime/style-cache.tsx +5 -0
  105. package/src/styled/__tests__/index.test.tsx +1 -0
  106. package/src/styled/index.tsx +35 -7
  107. package/CHANGELOG.md +0 -128
@@ -32,16 +32,44 @@ export interface StyledComponentInstantiator extends StyledComponentMap {
32
32
  <TInheritedProps extends unknown>(Component: ComponentType<TInheritedProps>): StyledFunctionFromComponent<TInheritedProps>;
33
33
  }
34
34
  /**
35
- * Create a component that ties styles to an element which comes with built-in behavior such as `ref` and `as` prop support.
35
+ * ## Styled component
36
36
  *
37
+ * Create a component that styles a JSX element which comes with built-in behavior such as `ref` and `as` prop support.
38
+ * For further details [read the documentation](https://compiledcssinjs.com/docs/api-styled).
39
+ *
40
+ * ### Style with objects
41
+ *
42
+ * @example
43
+ * ```
44
+ * styled.div({
45
+ * fontSize: 12,
46
+ * });
47
+ * ```
48
+ *
49
+ * ### Style with template literals
50
+ *
51
+ * @example
37
52
  * ```
38
- * styled.div`font-size: 12px`; // Template literal CSS
39
- * styled.div({ fontSize: 12 }); // Object CSS
40
- * styled.div([{ fontSize: 12 }, `font-size: 12px;`]) // Array CSS
41
- * styled.div({ fontSize: 12 }, `font-size: 12px`) Multi arguments CSS
53
+ * styled.div`
54
+ * font-size: 12px
55
+ * `;
42
56
  * ```
43
57
  *
44
- * For more help, read the docs:
45
- * https://compiledcssinjs.com/docs/api-styled
58
+ * ### Compose styles with arrays
59
+ *
60
+ * @example
61
+ * ```
62
+ * import { css } from '@compiled/react';
63
+ *
64
+ * styled.div([
65
+ * { fontSize: 12 },
66
+ * css`font-size: 12px;`
67
+ * ]);
68
+ *
69
+ * styled.div(
70
+ * { fontSize: 12 },
71
+ * css`font-size: 12px`
72
+ * );
73
+ * ```
46
74
  */
47
75
  export declare const styled: StyledComponentInstantiator;
@@ -1,16 +1,44 @@
1
1
  import { createSetupError } from '../utils/error';
2
2
  /**
3
- * Create a component that ties styles to an element which comes with built-in behavior such as `ref` and `as` prop support.
3
+ * ## Styled component
4
4
  *
5
+ * Create a component that styles a JSX element which comes with built-in behavior such as `ref` and `as` prop support.
6
+ * For further details [read the documentation](https://compiledcssinjs.com/docs/api-styled).
7
+ *
8
+ * ### Style with objects
9
+ *
10
+ * @example
11
+ * ```
12
+ * styled.div({
13
+ * fontSize: 12,
14
+ * });
15
+ * ```
16
+ *
17
+ * ### Style with template literals
18
+ *
19
+ * @example
5
20
  * ```
6
- * styled.div`font-size: 12px`; // Template literal CSS
7
- * styled.div({ fontSize: 12 }); // Object CSS
8
- * styled.div([{ fontSize: 12 }, `font-size: 12px;`]) // Array CSS
9
- * styled.div({ fontSize: 12 }, `font-size: 12px`) Multi arguments CSS
21
+ * styled.div`
22
+ * font-size: 12px
23
+ * `;
10
24
  * ```
11
25
  *
12
- * For more help, read the docs:
13
- * https://compiledcssinjs.com/docs/api-styled
26
+ * ### Compose styles with arrays
27
+ *
28
+ * @example
29
+ * ```
30
+ * import { css } from '@compiled/react';
31
+ *
32
+ * styled.div([
33
+ * { fontSize: 12 },
34
+ * css`font-size: 12px;`
35
+ * ]);
36
+ *
37
+ * styled.div(
38
+ * { fontSize: 12 },
39
+ * css`font-size: 12px`
40
+ * );
41
+ * ```
14
42
  */
15
43
  export var styled = new Proxy({}, {
16
44
  get: function () {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/styled/index.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAwDlD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,IAAM,MAAM,GAAgC,IAAI,KAAK,CAC1D,EAAE,EACF;IACE,GAAG;QACD,OAAO;YACL,8CAA8C;YAC9C,yDAAyD;YACzD,MAAM,gBAAgB,EAAE,CAAC;QAC3B,CAAC,CAAC;IACJ,CAAC;CACF,CACK,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/styled/index.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAwDlD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,CAAC,IAAM,MAAM,GAAgC,IAAI,KAAK,CAC1D,EAAE,EACF;IACE,GAAG;QACD,OAAO;YACL,8CAA8C;YAC9C,yDAAyD;YACzD,MAAM,gBAAgB,EAAE,CAAC;QAC3B,CAAC,CAAC;IACJ,CAAC;CACF,CACK,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compiled/react",
3
- "version": "0.10.0",
3
+ "version": "0.10.3",
4
4
  "description": "A familiar and performant compile time CSS-in-JS library for React.",
5
5
  "keywords": [
6
6
  "compiled",
@@ -8,7 +8,7 @@
8
8
  "styled-components",
9
9
  "typescript"
10
10
  ],
11
- "homepage": "https://compiledcssinjs.com",
11
+ "homepage": "https://compiledcssinjs.com/docs/pkg-react",
12
12
  "bugs": "https://github.com/atlassian-labs/compiled/issues/new?assignees=&labels=bug&template=bug_report.md",
13
13
  "repository": {
14
14
  "type": "git",
@@ -72,11 +72,14 @@
72
72
  "jsx-dev-runtime"
73
73
  ],
74
74
  "dependencies": {
75
- "csstype": "^3.0.9"
75
+ "csstype": "^3.0.10"
76
76
  },
77
77
  "devDependencies": {
78
- "@testing-library/react": "^11.2.7",
79
- "@types/react-dom": "^17.0.10",
78
+ "@compiled/benchmark": "^1.0.1",
79
+ "@testing-library/react": "^12.1.3",
80
+ "@types/jsdom": "^16.2.14",
81
+ "@types/react-dom": "^17.0.11",
82
+ "jsdom": "^19.0.0",
80
83
  "react": "^17.0.2",
81
84
  "react-dom": "^17.0.2"
82
85
  },
@@ -1,13 +1,8 @@
1
+ // eslint-disable-next-line import/no-extraneous-dependencies
1
2
  import { styled } from '@compiled/react';
2
3
  import { render } from '@testing-library/react';
3
4
  import React from 'react';
4
5
 
5
- // TODO: When we move back to browser checking (window vs. process) we can remove
6
- // this and replace with the "jest-environment node" pragma.
7
- jest.mock('../../src/runtime/is-node', () => ({
8
- isNodeEnvironment: () => false,
9
- }));
10
-
11
6
  describe('browser', () => {
12
7
  beforeEach(() => {
13
8
  // Reset style tags in head before each test so that it will remove styles
@@ -1,3 +1,4 @@
1
+ // eslint-disable-next-line import/no-extraneous-dependencies
1
2
  import { styled } from '@compiled/react';
2
3
 
3
4
  describe('display names', () => {
@@ -1,4 +1,6 @@
1
1
  /** @jsxImportSource @compiled/react */
2
+ // This test belongs in @compiled/jest - but can't be placed there due to a circular dependency.
3
+ // eslint-disable-next-line import/no-extraneous-dependencies
2
4
  import { styled } from '@compiled/react';
3
5
  import { render } from '@testing-library/react';
4
6
 
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * @jest-environment node
3
3
  */
4
+ // eslint-disable-next-line import/no-extraneous-dependencies
4
5
  import { styled } from '@compiled/react';
6
+ // eslint-disable-next-line import/no-extraneous-dependencies
5
7
  import { CC as CompiledRoot } from '@compiled/react/runtime';
6
8
  import React from 'react';
7
9
  import { renderToStaticMarkup } from 'react-dom/server';
@@ -134,7 +136,7 @@ describe('SSR', () => {
134
136
 
135
137
  expect(result.split('</style>').join('</style>\n')).toMatchInlineSnapshot(`
136
138
  "<style data-cmpld=\\"true\\" nonce=\\"k0Mp1lEd\\">._1e0c1txw{display:flex}._1wyb12am{font-size:50px}._syaz1cnh{color:purple}._ysv75scu:link{color:red}._105332ev:visited{color:pink}._f8pjbf54:focus{color:green}._30l31gy6:hover{color:yellow}._9h8h13q2:active{color:blue}@supports (display:grid){._1df61gy6:focus{color:yellow}._7okp11x8:active{color:black}}@media (max-width:800px){._1o8z1gy6:focus{color:yellow}._1cld11x8:active{color:black}}</style>
137
- <a href=\\"https://atlassian.design\\" class=\\"_1e0c1txw _1wyb12am _syaz1cnh _30l31gy6 _9h8h13q2 _ysv75scu _7okp11x8 _1df61gy6 _f8pjbf54 _105332ev _1cld11x8 _1o8z1gy6\\">Atlassian Design System</a>"
139
+ <a href=\\"https://atlassian.design\\" class=\\"_1e0c1txw _1wyb12am _syaz1cnh _30l31gy6 _9h8h13q2 _ysv75scu _1df61gy6 _7okp11x8 _f8pjbf54 _105332ev _1o8z1gy6 _1cld11x8\\">Atlassian Design System</a>"
138
140
  `);
139
141
  });
140
142
 
@@ -1,3 +1,4 @@
1
+ // eslint-disable-next-line import/no-extraneous-dependencies
1
2
  import { ClassNames } from '@compiled/react';
2
3
  import { render } from '@testing-library/react';
3
4
  import React from 'react';
@@ -1,4 +1,4 @@
1
- import type { ReactNode } from 'react';
1
+ import type { ReactNode, CSSProperties } from 'react';
2
2
 
3
3
  import type { BasicTemplateInterpolations, CssFunction } from '../types';
4
4
  import { createSetupError } from '../utils/error';
@@ -8,36 +8,46 @@ export type Interpolations = (BasicTemplateInterpolations | CssFunction | CssFun
8
8
  export interface ClassNamesProps {
9
9
  children: (opts: {
10
10
  css: (css: CssFunction | CssFunction[], ...interpolations: Interpolations) => string;
11
- style: { [key: string]: string };
11
+ style: CSSProperties;
12
12
  }) => ReactNode;
13
13
  }
14
14
 
15
15
  /**
16
- * Use a component where styles are not necessarily tied to an element.
16
+ * ## Class names
17
17
  *
18
+ * Use a component where styles are not necessarily used on a JSX element.
19
+ * For further details [read the documentation](https://compiledcssinjs.com/docs/api-class-names).
20
+ *
21
+ * ### Style with objects
22
+ *
23
+ * @example
18
24
  * ```
19
- * // Object CSS
20
25
  * <ClassNames>
21
26
  * {({ css, style }) => children({ className: css({ fontSize: 12 }) })}
22
27
  * </ClassNames>
28
+ * ```
23
29
  *
24
- * // Template literal CSS
30
+ * ### Style with template literals
31
+ *
32
+ * @example
33
+ * ```
25
34
  * <ClassNames>
26
35
  * {({ css, style }) => children({ className: css`font-size: 12px;` })}
27
36
  * </ClassNames>
37
+ * ```
28
38
  *
29
- * // Array CSS
39
+ * ### Compose styles with arrays
40
+ *
41
+ * @example
42
+ * ```
30
43
  * <ClassNames>
31
44
  * {({ css, style }) =>
32
- * children({ className: css([{ fontSize: 12 }, `font-size: 12px`]) })}
45
+ * children({ className: css([{ fontSize: 12 }, css`font-size: 12px`]) })}
33
46
  * </ClassNames>
34
47
  * ```
35
- *
36
- * For more help, read the docs:
37
- * https://compiledcssinjs.com/docs/api-class-names
38
- *
39
- * @param props
40
48
  */
41
- export function ClassNames(_: ClassNamesProps): JSX.Element {
49
+ export function ClassNames({ children }: ClassNamesProps): JSX.Element;
50
+
51
+ export function ClassNames(_props: ClassNamesProps): JSX.Element {
42
52
  throw createSetupError();
43
53
  }
@@ -1,4 +1,5 @@
1
1
  /** @jsxImportSource @compiled/react */
2
+ // eslint-disable-next-line import/no-extraneous-dependencies
2
3
  import { css } from '@compiled/react';
3
4
  import { render } from '@testing-library/react';
4
5
 
@@ -29,6 +30,13 @@ describe('css prop', () => {
29
30
  expect(getByText('hello world')).toHaveCompiledCss('font-size', '13px');
30
31
  });
31
32
 
33
+ it('should create hover styles', () => {
34
+ const styles = css({ ':hover': { color: 'red' } });
35
+ const { getByText } = render(<div css={styles}>hello world</div>);
36
+
37
+ expect(getByText('hello world')).toHaveCompiledCss('color', 'red', { target: ':hover' });
38
+ });
39
+
32
40
  it('should create css from tagged template expression variable', () => {
33
41
  const style = css`
34
42
  font-size: 13px;
package/src/css/index.tsx CHANGED
@@ -1,43 +1,51 @@
1
1
  /* eslint-disable import/export */
2
2
 
3
- import type { BasicTemplateInterpolations, CSSProps, FunctionInterpolation } from '../types';
3
+ import type {
4
+ AnyKeyCssProps,
5
+ BasicTemplateInterpolations,
6
+ CSSProps,
7
+ FunctionInterpolation,
8
+ } from '../types';
4
9
  import { createSetupError } from '../utils/error';
5
10
 
6
11
  /**
7
- * Create styles that can be re-used between components with a template literal.
12
+ * ## CSS
8
13
  *
14
+ * Define styles that are statically typed and useable with other Compiled APIs.
15
+ * For further details [read the documentation](https://compiledcssinjs.com/docs/api-css).
16
+ *
17
+ * ### Style with objects
18
+ *
19
+ * @example
9
20
  * ```
10
- * css`color: red;`;
21
+ * const redText = css({
22
+ * color: 'red',
23
+ * });
24
+ *
25
+ * <div css={redText} />
11
26
  * ```
12
27
  *
13
- * For more help, read the docs:
14
- * https://compiledcssinjs.com/docs/api-css
28
+ * ### Style with template literals
15
29
  *
16
- * @param css
17
- * @param values
30
+ * @example
31
+ * ```
32
+ * const redText = css`
33
+ * color: red;
34
+ * `;
35
+ *
36
+ * <div css={redText} />
37
+ * ```
18
38
  */
19
39
  export default function css<T = void>(
20
- _css: TemplateStringsArray,
21
- ..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
40
+ styles: TemplateStringsArray,
41
+ ...interpolations: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
22
42
  ): CSSProps;
23
43
 
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
- *
34
- * @param css
35
- */
36
- export default function css(_css: CSSProps): CSSProps;
44
+ export default function css(styles: AnyKeyCssProps<void> | CSSProps): CSSProps;
37
45
 
38
46
  export default function css<T = void>(
39
- _css: TemplateStringsArray | CSSProps,
40
- ..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
47
+ _styles: TemplateStringsArray | CSSProps,
48
+ ..._interpolations: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
41
49
  ): CSSProps {
42
50
  throw createSetupError();
43
51
  }
@@ -1,5 +1,6 @@
1
1
  /** @jsxRuntime classic */
2
2
  /** @jsx jsx */
3
+ // eslint-disable-next-line import/no-extraneous-dependencies
3
4
  import { jsx } from '@compiled/react';
4
5
  import { render } from '@testing-library/react';
5
6
 
@@ -4,16 +4,42 @@ type WithConditionalCSSProp<TProps> = 'className' extends keyof TProps
4
4
  ? string extends TProps['className' & keyof TProps]
5
5
  ? {
6
6
  /**
7
- * Tie styles to an element.
7
+ * ## CSS prop
8
8
  *
9
+ * Style a JSX element.
10
+ * For further details [read the API documentation](https://compiledcssinjs.com/docs/api-css-prop).
11
+ *
12
+ * ### Style with objects
13
+ *
14
+ * @example
15
+ * ```
16
+ * import { css } from '@compiled/react';
17
+ *
18
+ * <div css={css({ fontSize: 12 })} />
19
+ * ```
20
+ *
21
+ * ### Style with template literals
22
+ *
23
+ * @example
24
+ * ```
25
+ * import { css } from '@compiled/react';
26
+ *
27
+ * <div css={css`color: red;`} />
9
28
  * ```
10
- * css={{ fontSize: 12 }} // Object CSS
11
- * css={`font-size: 12px;`} // Template literal CSS
12
- * css={[{ fontSize: 12 }, `font-size: 12px;`]} // Array CSS
29
+ *
30
+ * ### Compose styles with arrays
31
+ *
32
+ * @example
13
33
  * ```
34
+ * import { css } from '@compiled/react';
14
35
  *
15
- * For more help, read the docs:
16
- * https://compiledcssinjs.com/docs/api-css-prop
36
+ * <div
37
+ * css={[
38
+ * css({ fontSize: 12 }),
39
+ * css`color: red;`,
40
+ * ]}
41
+ * />
42
+ * ```
17
43
  */
18
44
  css?: CssFunction | CssFunction[];
19
45
  }
@@ -1,3 +1,4 @@
1
+ // eslint-disable-next-line import/no-extraneous-dependencies
1
2
  import { keyframes } from '@compiled/react';
2
3
 
3
4
  export const fadeOut = keyframes({
@@ -1,4 +1,5 @@
1
1
  /** @jsxImportSource @compiled/react */
2
+ // eslint-disable-next-line import/no-extraneous-dependencies
2
3
  import { keyframes, styled } from '@compiled/react';
3
4
  import { render } from '@testing-library/react';
4
5
 
@@ -7,15 +8,27 @@ import defaultFadeOut, { namedFadeOut, fadeOut as shadowedFadeOut } from '../__f
7
8
  const getOpacity = (str: string | number) => str;
8
9
 
9
10
  const getKeyframe = (name: string) => {
10
- const styles = Array.from(
11
- document.body.querySelectorAll('style'),
12
- (style) => style.innerHTML
13
- ).join('\n');
11
+ const searchStr = `@keyframes ${name}`;
14
12
 
15
- return styles.substring(styles.indexOf(`@keyframes ${name}`));
13
+ return Array.from(document.head.querySelectorAll('style'), (style) => style.innerHTML)
14
+ .filter((style) => style.indexOf(searchStr) >= 0)
15
+ .map((style) => style.substring(style.indexOf(searchStr)))
16
+ .join('\n');
16
17
  };
17
18
 
18
19
  describe('keyframes', () => {
20
+ beforeAll(() => {
21
+ process.env.CACHE = 'false';
22
+ });
23
+
24
+ afterAll(() => {
25
+ delete process.env.CACHE;
26
+ });
27
+
28
+ afterEach(() => {
29
+ document.head.innerHTML = '';
30
+ });
31
+
19
32
  describe('referenced through a css prop', () => {
20
33
  describe('render an animation', () => {
21
34
  it('given an object call expression argument', () => {
@@ -4,28 +4,14 @@ import { createSetupError } from '../utils/error';
4
4
  export type KeyframeSteps = string | Record<string, CSSProps>;
5
5
 
6
6
  /**
7
- * Create keyframes using a tagged template expression:
7
+ * ## Keyframes
8
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:
9
+ * Define keyframes to be used in a [CSS animation](https://developer.mozilla.org/en-US/docs/Web/CSS/animation).
10
+ * For further details [read the API documentation](https://compiledcssinjs.com/docs/api-keyframes).
26
11
  *
27
- * 1. An object expression
12
+ * ### Style with objects
28
13
  *
14
+ * @example
29
15
  * ```
30
16
  * const fadeOut = keyframes({
31
17
  * from: {
@@ -35,23 +21,33 @@ export function keyframes(
35
21
  * opacity: 0,
36
22
  * },
37
23
  * });
24
+ *
25
+ * <div css={{ animation: `${fadeOut} 2s` }} />
38
26
  * ```
39
27
  *
40
- * 2. A string
28
+ * ### Style with template literals
41
29
  *
30
+ * @example
42
31
  * ```
43
- * const fadeOut = keyframes('from { opacity: 1; } to { opacity: 0; }');
44
- * ```
32
+ * const fadeOut = keyframes`
33
+ * from {
34
+ * opacity: 1;
35
+ * }
45
36
  *
46
- * 3. A template literal
37
+ * to {
38
+ * opacity: 0;
39
+ * }
40
+ * `;
47
41
  *
42
+ * <div css={{ animation: `${fadeOut} 2s` }} />
48
43
  * ```
49
- * const fadeOut = keyframes(`from { opacity: 1; } to { opacity: 0; }`);
50
- * ```
51
- *
52
- * @param _steps The waypoints along the animation sequence
53
44
  */
54
- export function keyframes(_steps: KeyframeSteps): string;
45
+ export function keyframes(steps: KeyframeSteps): string;
46
+
47
+ export function keyframes(
48
+ strings: TemplateStringsArray,
49
+ ...interpolations: BasicTemplateInterpolations[]
50
+ ): string;
55
51
 
56
52
  export function keyframes(
57
53
  _stringsOrSteps: TemplateStringsArray | KeyframeSteps,