@compiled/react 0.9.0 → 0.10.2

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 (234) hide show
  1. package/dist/browser/class-names/index.d.ts +22 -16
  2. package/dist/browser/class-names/index.js +1 -27
  3. package/dist/browser/class-names/index.js.flow +2 -2
  4. package/dist/browser/class-names/index.js.map +1 -1
  5. package/dist/browser/css/index.d.ts +22 -19
  6. package/dist/browser/css/index.js +4 -3
  7. package/dist/browser/css/index.js.flow +1 -1
  8. package/dist/browser/css/index.js.map +1 -1
  9. package/dist/browser/index.d.ts +12 -22
  10. package/dist/browser/index.js +4 -0
  11. package/dist/browser/index.js.flow +5 -30
  12. package/dist/browser/index.js.map +1 -1
  13. package/dist/browser/jsx/jsx-dev-runtime.d.ts +2 -0
  14. package/dist/browser/jsx/jsx-dev-runtime.js +4 -0
  15. package/dist/browser/jsx/jsx-dev-runtime.js.map +1 -0
  16. package/dist/browser/jsx/jsx-local-namespace.d.ts +66 -0
  17. package/dist/browser/jsx/jsx-local-namespace.js +2 -0
  18. package/dist/browser/jsx/jsx-local-namespace.js.map +1 -0
  19. package/dist/browser/jsx/jsx-runtime.d.ts +2 -0
  20. package/dist/browser/jsx/jsx-runtime.js +4 -0
  21. package/dist/browser/jsx/jsx-runtime.js.map +1 -0
  22. package/dist/browser/keyframes/__fixtures__/index.js +1 -0
  23. package/dist/browser/keyframes/__fixtures__/index.js.map +1 -1
  24. package/dist/browser/keyframes/index.d.ts +20 -24
  25. package/dist/browser/keyframes/index.js.flow +1 -1
  26. package/dist/browser/keyframes/index.js.map +1 -1
  27. package/dist/browser/runtime/ax.js.flow +1 -1
  28. package/dist/browser/runtime/cache.d.ts +12 -0
  29. package/dist/browser/runtime/cache.js +15 -0
  30. package/dist/browser/runtime/cache.js.flow +18 -0
  31. package/dist/browser/runtime/cache.js.map +1 -0
  32. package/dist/browser/runtime/css-custom-property.d.ts +1 -1
  33. package/dist/browser/runtime/css-custom-property.js.flow +2 -2
  34. package/dist/browser/runtime/css-custom-property.js.map +1 -1
  35. package/dist/browser/runtime/dev-warnings.js +10 -6
  36. package/dist/browser/runtime/dev-warnings.js.flow +1 -1
  37. package/dist/browser/runtime/dev-warnings.js.map +1 -1
  38. package/dist/browser/runtime/index.js.flow +1 -1
  39. package/dist/browser/runtime/is-node.js +1 -3
  40. package/dist/browser/runtime/is-node.js.flow +1 -1
  41. package/dist/browser/runtime/is-node.js.map +1 -1
  42. package/dist/browser/runtime/sheet.d.ts +1 -1
  43. package/dist/browser/runtime/sheet.js +5 -1
  44. package/dist/browser/runtime/sheet.js.flow +2 -2
  45. package/dist/browser/runtime/sheet.js.map +1 -1
  46. package/dist/browser/runtime/style-cache.js +4 -0
  47. package/dist/browser/runtime/style-cache.js.flow +1 -1
  48. package/dist/browser/runtime/style-cache.js.map +1 -1
  49. package/dist/browser/runtime/style.js +2 -2
  50. package/dist/browser/runtime/style.js.flow +1 -1
  51. package/dist/browser/runtime/style.js.map +1 -1
  52. package/dist/browser/runtime/types.js.flow +1 -1
  53. package/dist/browser/runtime.js.flow +1 -1
  54. package/dist/browser/styled/index.d.ts +35 -7
  55. package/dist/browser/styled/index.js +35 -7
  56. package/dist/browser/styled/index.js.flow +2 -2
  57. package/dist/browser/styled/index.js.map +1 -1
  58. package/dist/browser/types.js.flow +1 -1
  59. package/dist/browser/utils/error.js.flow +1 -1
  60. package/dist/cjs/class-names/index.d.ts +22 -16
  61. package/dist/cjs/class-names/index.js +2 -28
  62. package/dist/cjs/class-names/index.js.flow +2 -2
  63. package/dist/cjs/class-names/index.js.map +1 -1
  64. package/dist/cjs/css/index.d.ts +22 -19
  65. package/dist/cjs/css/index.js +5 -4
  66. package/dist/cjs/css/index.js.flow +1 -1
  67. package/dist/cjs/css/index.js.map +1 -1
  68. package/dist/cjs/index.d.ts +12 -22
  69. package/dist/cjs/index.js +5 -1
  70. package/dist/cjs/index.js.flow +5 -30
  71. package/dist/cjs/index.js.map +1 -1
  72. package/dist/cjs/jsx/jsx-dev-runtime.d.ts +2 -0
  73. package/dist/cjs/jsx/jsx-dev-runtime.js +16 -0
  74. package/dist/cjs/jsx/jsx-dev-runtime.js.map +1 -0
  75. package/dist/cjs/jsx/jsx-local-namespace.d.ts +66 -0
  76. package/dist/cjs/jsx/jsx-local-namespace.js +3 -0
  77. package/dist/cjs/jsx/jsx-local-namespace.js.map +1 -0
  78. package/dist/cjs/jsx/jsx-runtime.d.ts +2 -0
  79. package/dist/cjs/jsx/jsx-runtime.js +16 -0
  80. package/dist/cjs/jsx/jsx-runtime.js.map +1 -0
  81. package/dist/cjs/keyframes/__fixtures__/index.js +2 -1
  82. package/dist/cjs/keyframes/__fixtures__/index.js.map +1 -1
  83. package/dist/cjs/keyframes/index.d.ts +20 -24
  84. package/dist/cjs/keyframes/index.js +1 -1
  85. package/dist/cjs/keyframes/index.js.flow +1 -1
  86. package/dist/cjs/keyframes/index.js.map +1 -1
  87. package/dist/cjs/runtime/ax.js.flow +1 -1
  88. package/dist/cjs/runtime/cache.d.ts +12 -0
  89. package/dist/cjs/runtime/cache.js +19 -0
  90. package/dist/cjs/runtime/cache.js.flow +18 -0
  91. package/dist/cjs/runtime/cache.js.map +1 -0
  92. package/dist/cjs/runtime/css-custom-property.d.ts +1 -1
  93. package/dist/cjs/runtime/css-custom-property.js.flow +2 -2
  94. package/dist/cjs/runtime/css-custom-property.js.map +1 -1
  95. package/dist/cjs/runtime/dev-warnings.js +10 -6
  96. package/dist/cjs/runtime/dev-warnings.js.flow +1 -1
  97. package/dist/cjs/runtime/dev-warnings.js.map +1 -1
  98. package/dist/cjs/runtime/index.js.flow +1 -1
  99. package/dist/cjs/runtime/is-node.js +1 -3
  100. package/dist/cjs/runtime/is-node.js.flow +1 -1
  101. package/dist/cjs/runtime/is-node.js.map +1 -1
  102. package/dist/cjs/runtime/sheet.d.ts +1 -1
  103. package/dist/cjs/runtime/sheet.js +6 -2
  104. package/dist/cjs/runtime/sheet.js.flow +2 -2
  105. package/dist/cjs/runtime/sheet.js.map +1 -1
  106. package/dist/cjs/runtime/style-cache.js +10 -6
  107. package/dist/cjs/runtime/style-cache.js.flow +1 -1
  108. package/dist/cjs/runtime/style-cache.js.map +1 -1
  109. package/dist/cjs/runtime/style.js +6 -6
  110. package/dist/cjs/runtime/style.js.flow +1 -1
  111. package/dist/cjs/runtime/style.js.map +1 -1
  112. package/dist/cjs/runtime/types.js.flow +1 -1
  113. package/dist/cjs/runtime.js.flow +1 -1
  114. package/dist/cjs/styled/index.d.ts +35 -7
  115. package/dist/cjs/styled/index.js +36 -8
  116. package/dist/cjs/styled/index.js.flow +2 -2
  117. package/dist/cjs/styled/index.js.map +1 -1
  118. package/dist/cjs/types.js.flow +1 -1
  119. package/dist/cjs/utils/error.js.flow +1 -1
  120. package/dist/esm/class-names/index.d.ts +22 -16
  121. package/dist/esm/class-names/index.js +1 -27
  122. package/dist/esm/class-names/index.js.flow +2 -2
  123. package/dist/esm/class-names/index.js.map +1 -1
  124. package/dist/esm/css/index.d.ts +22 -19
  125. package/dist/esm/css/index.js +4 -3
  126. package/dist/esm/css/index.js.flow +1 -1
  127. package/dist/esm/css/index.js.map +1 -1
  128. package/dist/esm/index.d.ts +12 -22
  129. package/dist/esm/index.js +4 -0
  130. package/dist/esm/index.js.flow +5 -30
  131. package/dist/esm/index.js.map +1 -1
  132. package/dist/esm/jsx/jsx-dev-runtime.d.ts +2 -0
  133. package/dist/esm/jsx/jsx-dev-runtime.js +4 -0
  134. package/dist/esm/jsx/jsx-dev-runtime.js.map +1 -0
  135. package/dist/esm/jsx/jsx-local-namespace.d.ts +66 -0
  136. package/dist/esm/jsx/jsx-local-namespace.js +2 -0
  137. package/dist/esm/jsx/jsx-local-namespace.js.map +1 -0
  138. package/dist/esm/jsx/jsx-runtime.d.ts +2 -0
  139. package/dist/esm/jsx/jsx-runtime.js +4 -0
  140. package/dist/esm/jsx/jsx-runtime.js.map +1 -0
  141. package/dist/esm/keyframes/__fixtures__/index.js +1 -0
  142. package/dist/esm/keyframes/__fixtures__/index.js.map +1 -1
  143. package/dist/esm/keyframes/index.d.ts +20 -24
  144. package/dist/esm/keyframes/index.js.flow +1 -1
  145. package/dist/esm/keyframes/index.js.map +1 -1
  146. package/dist/esm/runtime/ax.js.flow +1 -1
  147. package/dist/esm/runtime/cache.d.ts +12 -0
  148. package/dist/esm/runtime/cache.js +15 -0
  149. package/dist/esm/runtime/cache.js.flow +18 -0
  150. package/dist/esm/runtime/cache.js.map +1 -0
  151. package/dist/esm/runtime/css-custom-property.d.ts +1 -1
  152. package/dist/esm/runtime/css-custom-property.js.flow +2 -2
  153. package/dist/esm/runtime/css-custom-property.js.map +1 -1
  154. package/dist/esm/runtime/dev-warnings.js +10 -6
  155. package/dist/esm/runtime/dev-warnings.js.flow +1 -1
  156. package/dist/esm/runtime/dev-warnings.js.map +1 -1
  157. package/dist/esm/runtime/index.js.flow +1 -1
  158. package/dist/esm/runtime/is-node.js +1 -3
  159. package/dist/esm/runtime/is-node.js.flow +1 -1
  160. package/dist/esm/runtime/is-node.js.map +1 -1
  161. package/dist/esm/runtime/sheet.d.ts +1 -1
  162. package/dist/esm/runtime/sheet.js +5 -1
  163. package/dist/esm/runtime/sheet.js.flow +2 -2
  164. package/dist/esm/runtime/sheet.js.map +1 -1
  165. package/dist/esm/runtime/style-cache.js +4 -0
  166. package/dist/esm/runtime/style-cache.js.flow +1 -1
  167. package/dist/esm/runtime/style-cache.js.map +1 -1
  168. package/dist/esm/runtime/style.js +2 -2
  169. package/dist/esm/runtime/style.js.flow +1 -1
  170. package/dist/esm/runtime/style.js.map +1 -1
  171. package/dist/esm/runtime/types.js.flow +1 -1
  172. package/dist/esm/runtime.js.flow +1 -1
  173. package/dist/esm/styled/index.d.ts +35 -7
  174. package/dist/esm/styled/index.js +35 -7
  175. package/dist/esm/styled/index.js.flow +2 -2
  176. package/dist/esm/styled/index.js.map +1 -1
  177. package/dist/esm/types.js.flow +1 -1
  178. package/dist/esm/utils/error.js.flow +1 -1
  179. package/jsx-dev-runtime/package.json +6 -0
  180. package/jsx-runtime/package.json +6 -0
  181. package/package.json +43 -14
  182. package/src/__tests__/browser.test.tsx +3 -8
  183. package/src/__tests__/display-names.test.tsx +1 -0
  184. package/src/__tests__/jest-matcher.test.tsx +199 -0
  185. package/src/__tests__/server-side-hydrate.test.tsx +1 -0
  186. package/src/__tests__/ssr.test.tsx +5 -3
  187. package/src/class-names/__tests__/index.test.tsx +2 -1
  188. package/src/class-names/index.js.flow +2 -2
  189. package/src/class-names/index.tsx +25 -14
  190. package/src/css/__tests__/index.test.tsx +10 -3
  191. package/src/css/index.js.flow +1 -1
  192. package/src/css/index.tsx +34 -24
  193. package/src/index.js.flow +5 -30
  194. package/src/index.tsx +18 -26
  195. package/src/jsx/__tests__/index.test.tsx +1 -2
  196. package/src/jsx/__tests__/jsx-import-source-pragma.test.tsx +37 -0
  197. package/src/jsx/__tests__/jsx-pragma.test.tsx +40 -0
  198. package/src/jsx/jsx-dev-runtime.tsx +5 -0
  199. package/src/jsx/jsx-local-namespace.tsx +75 -0
  200. package/src/jsx/jsx-runtime.tsx +5 -0
  201. package/src/keyframes/__fixtures__/index.tsx +1 -0
  202. package/src/keyframes/__tests__/index.test.tsx +20 -6
  203. package/src/keyframes/index.js.flow +1 -1
  204. package/src/keyframes/index.tsx +24 -28
  205. package/src/runtime/__perf__/ax.test.ts +42 -0
  206. package/src/runtime/__perf__/cs.test.tsx +111 -0
  207. package/src/runtime/__perf__/sheet.test.ts +61 -0
  208. package/src/runtime/__perf__/utils/cs.tsx +60 -0
  209. package/src/runtime/__perf__/utils/sheet.tsx +151 -0
  210. package/src/runtime/__tests__/style-ssr.test.tsx +5 -0
  211. package/src/runtime/__tests__/style.test.tsx +1 -5
  212. package/src/runtime/ax.js.flow +1 -1
  213. package/src/runtime/cache.js.flow +18 -0
  214. package/src/runtime/cache.tsx +14 -0
  215. package/src/runtime/css-custom-property.js.flow +2 -2
  216. package/src/runtime/css-custom-property.tsx +1 -1
  217. package/src/runtime/dev-warnings.js.flow +1 -1
  218. package/src/runtime/index.js.flow +1 -1
  219. package/src/runtime/is-node.js.flow +1 -1
  220. package/src/runtime/is-node.tsx +1 -2
  221. package/src/runtime/sheet.js.flow +2 -2
  222. package/src/runtime/sheet.tsx +8 -2
  223. package/src/runtime/style-cache.js.flow +1 -1
  224. package/src/runtime/style-cache.tsx +6 -0
  225. package/src/runtime/style.js.flow +1 -1
  226. package/src/runtime/style.tsx +4 -3
  227. package/src/runtime/types.js.flow +1 -1
  228. package/src/runtime.js.flow +1 -1
  229. package/src/styled/__tests__/index.test.tsx +4 -3
  230. package/src/styled/index.js.flow +2 -2
  231. package/src/styled/index.tsx +37 -8
  232. package/src/types.js.flow +1 -1
  233. package/src/utils/error.js.flow +1 -1
  234. package/CHANGELOG.md +0 -74
package/package.json CHANGED
@@ -1,15 +1,14 @@
1
1
  {
2
2
  "name": "@compiled/react",
3
- "version": "0.9.0",
3
+ "version": "0.10.2",
4
4
  "description": "A familiar and performant compile time CSS-in-JS library for React.",
5
5
  "keywords": [
6
6
  "compiled",
7
7
  "css-in-js",
8
8
  "styled-components",
9
- "emotion-js",
10
9
  "typescript"
11
10
  ],
12
- "homepage": "https://compiledcssinjs.com",
11
+ "homepage": "https://compiledcssinjs.com/docs/pkg-react",
13
12
  "bugs": "https://github.com/atlassian-labs/compiled/issues/new?assignees=&labels=bug&template=bug_report.md",
14
13
  "repository": {
15
14
  "type": "git",
@@ -21,16 +20,44 @@
21
20
  "sideEffects": false,
22
21
  "exports": {
23
22
  ".": {
24
- "import": "./dist/esm/index.js",
25
- "require": "./dist/cjs/index.js"
26
- },
27
- "./babel-plugin": {
28
- "import": "./dist/esm/babel-plugin.js",
29
- "require": "./dist/cjs/babel-plugin.js"
23
+ "import": [
24
+ "./dist/esm/index.js",
25
+ "./src/index.tsx"
26
+ ],
27
+ "require": [
28
+ "./dist/cjs/index.js",
29
+ "./src/index.tsx"
30
+ ]
30
31
  },
31
32
  "./runtime": {
32
- "import": "./dist/esm/runtime.js",
33
- "require": "./dist/cjs/runtime.js"
33
+ "import": [
34
+ "./dist/esm/runtime.js",
35
+ "./src/runtime.tsx"
36
+ ],
37
+ "require": [
38
+ "./dist/cjs/runtime.js",
39
+ "./src/runtime.tsx"
40
+ ]
41
+ },
42
+ "./jsx-runtime": {
43
+ "import": [
44
+ "./dist/esm/jsx/jsx-runtime.js",
45
+ "./src/jsx/jsx-runtime.tsx"
46
+ ],
47
+ "require": [
48
+ "./dist/cjs/jsx/jsx-runtime.js",
49
+ "./src/jsx/jsx-runtime.tsx"
50
+ ]
51
+ },
52
+ "./jsx-dev-runtime": {
53
+ "import": [
54
+ "./dist/esm/jsx/jsx-dev-runtime.js",
55
+ "./src/jsx/jsx-dev-runtime.tsx"
56
+ ],
57
+ "require": [
58
+ "./dist/cjs/jsx/jsx-dev-runtime.js",
59
+ "./src/jsx/jsx-dev-runtime.tsx"
60
+ ]
34
61
  }
35
62
  },
36
63
  "main": "./dist/cjs/index.js",
@@ -40,15 +67,17 @@
40
67
  "files": [
41
68
  "dist",
42
69
  "src",
43
- "babel-plugin",
44
70
  "runtime",
45
- "README.md"
71
+ "jsx-runtime",
72
+ "jsx-dev-runtime"
46
73
  ],
47
74
  "dependencies": {
48
- "csstype": "^3.0.9"
75
+ "csstype": "^3.0.10"
49
76
  },
50
77
  "devDependencies": {
78
+ "@compiled/benchmark": "^1.0.1",
51
79
  "@testing-library/react": "^11.2.7",
80
+ "@types/react-dom": "^17.0.11",
52
81
  "react": "^17.0.2",
53
82
  "react-dom": "^17.0.2"
54
83
  },
@@ -1,12 +1,7 @@
1
- import React from 'react';
2
- import { render } from '@testing-library/react';
1
+ // eslint-disable-next-line import/no-extraneous-dependencies
3
2
  import { styled } from '@compiled/react';
4
-
5
- // Because of the babel transform these tests are using dist instead of src.
6
- // Anything we can do to use src instead?
7
- jest.mock('../../dist/cjs/runtime/is-node', () => ({
8
- isNodeEnvironment: () => false,
9
- }));
3
+ import { render } from '@testing-library/react';
4
+ import React from 'react';
10
5
 
11
6
  describe('browser', () => {
12
7
  beforeEach(() => {
@@ -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', () => {
@@ -0,0 +1,199 @@
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
4
+ import { styled } from '@compiled/react';
5
+ import { render } from '@testing-library/react';
6
+
7
+ describe('toHaveCompliedCss', () => {
8
+ it('should detect styles', () => {
9
+ const { getByText } = render(
10
+ <div
11
+ css={{
12
+ fontSize: '12px',
13
+ }}>
14
+ hello world
15
+ </div>
16
+ );
17
+
18
+ expect(getByText('hello world')).toHaveCompiledCss('font-size', '12px');
19
+ });
20
+
21
+ it('should detect missing styles', () => {
22
+ const { getByText } = render(<div css={{ fontSize: '12px' }}>hello world</div>);
23
+
24
+ expect(getByText('hello world')).not.toHaveCompiledCss('color', 'blue');
25
+ });
26
+
27
+ it('should detect multiple styles', () => {
28
+ const { getByText } = render(<div css={{ fontSize: '12px', color: 'blue' }}>hello world</div>);
29
+
30
+ expect(getByText('hello world')).toHaveCompiledCss({
31
+ fontSize: '12px',
32
+ color: 'blue',
33
+ });
34
+ });
35
+
36
+ it('should detect single missing styles', () => {
37
+ const { getByText } = render(<div css={{ fontSize: '12px', color: 'blue' }}>hello world</div>);
38
+
39
+ expect(getByText('hello world')).not.toHaveCompiledCss({
40
+ zindex: '9999',
41
+ });
42
+ });
43
+
44
+ it('should detect multiple missing styles', () => {
45
+ const { getByText } = render(<div css={{ fontSize: '12px', color: 'blue' }}>hello world</div>);
46
+
47
+ expect(getByText('hello world')).not.toHaveCompiledCss({
48
+ backgroundColor: 'yellow',
49
+ zindex: '9999',
50
+ });
51
+ });
52
+
53
+ it('should detect evaluated rule from array styles', () => {
54
+ const base = { color: 'blue' };
55
+ const next = ` font-size: 15px; `;
56
+
57
+ const { getByText } = render(<div css={[base, next]}>hello world</div>);
58
+
59
+ expect(getByText('hello world')).toHaveCompiledCss('font-size', '15px');
60
+ expect(getByText('hello world')).toHaveCompiledCss('color', 'blue');
61
+ });
62
+
63
+ it('should find styles composed from multiple sources', () => {
64
+ const StyledDiv = styled.div`
65
+ font-size: 12px;
66
+ `;
67
+
68
+ const { getByText } = render(<StyledDiv css={{ fontSize: 14 }}>Hello world</StyledDiv>);
69
+
70
+ expect(getByText('Hello world')).toHaveCompiledCss('font-size', '14px');
71
+ });
72
+
73
+ it('should find multiple styles composed from multiple sources', () => {
74
+ const StyledDiv = styled.div`
75
+ color: yellow;
76
+ background-color: red;
77
+ `;
78
+
79
+ const { getByText } = render(<StyledDiv css={{ color: 'blue' }}>Hello world</StyledDiv>);
80
+
81
+ expect(getByText('Hello world')).toHaveCompiledCss({
82
+ backgroundColor: 'red',
83
+ color: 'blue',
84
+ });
85
+ });
86
+
87
+ it('should match styles with target:hover', () => {
88
+ const { getByText } = render(
89
+ <div
90
+ css={{
91
+ fontSize: '12px',
92
+ ':hover': {
93
+ transform: 'scale(2)',
94
+ },
95
+ }}>
96
+ hello world
97
+ </div>
98
+ );
99
+ const el = getByText('hello world');
100
+ expect(el).toHaveCompiledCss('transform', 'scale(2)', { target: ':hover' });
101
+ expect(el).not.toHaveCompiledCss('transform', 'scale(2)');
102
+ });
103
+
104
+ it('should match styles with target', () => {
105
+ const { getByText } = render(
106
+ <div
107
+ css={{
108
+ fontSize: '12px',
109
+ ':hover': {
110
+ transform: 'scale(2)',
111
+ },
112
+ ':active': {
113
+ color: 'blue',
114
+ },
115
+ }}>
116
+ hello world
117
+ </div>
118
+ );
119
+ const el = getByText('hello world');
120
+ expect(el).not.toHaveCompiledCss('color', 'blue', { target: ':hover' });
121
+ expect(el).not.toHaveCompiledCss('transform', 'scale(2)');
122
+ expect(el).not.toHaveCompiledCss('transform', 'scale(2)', { target: ':active' });
123
+ expect(el).toHaveCompiledCss('transform', 'scale(2)', { target: ':hover' });
124
+ expect(el).toHaveCompiledCss('color', 'blue', { target: ':active' });
125
+ });
126
+
127
+ it('should match styles with media', () => {
128
+ const { getByText } = render(
129
+ <div
130
+ css={{
131
+ color: 'green',
132
+ '@media screen': {
133
+ color: 'yellow',
134
+ },
135
+ }}>
136
+ hello world
137
+ </div>
138
+ );
139
+ const el = getByText('hello world');
140
+ expect(el).toHaveCompiledCss('color', 'green');
141
+ expect(el).toHaveCompiledCss('color', 'yellow', { media: 'screen' });
142
+ // without narrowing to media -> screen
143
+ expect(el).not.toHaveCompiledCss('color', 'yellow');
144
+ });
145
+
146
+ it('should match styles with media and target', () => {
147
+ const { getByText } = render(
148
+ <div
149
+ css={{
150
+ color: 'green',
151
+ '@media screen': {
152
+ color: 'yellow',
153
+ ':hover': {
154
+ background: 'red',
155
+ },
156
+ },
157
+ }}>
158
+ hello world
159
+ </div>
160
+ );
161
+ const el = getByText('hello world');
162
+ expect(el).toHaveCompiledCss('background-color', 'red', { media: 'screen', target: ':hover' });
163
+ });
164
+
165
+ it('should match styles with media nested inside class', () => {
166
+ const { getByText } = render(
167
+ <div
168
+ css={{
169
+ '@media (min-width: 2px)': {
170
+ color: 'blue',
171
+ '@media (min-width: 1px)': {
172
+ color: 'red',
173
+ },
174
+ },
175
+ }}>
176
+ hello world
177
+ </div>
178
+ );
179
+ const el = getByText('hello world');
180
+ expect(el).toHaveCompiledCss('color', 'blue', { media: '(min-width: 2px)' });
181
+ expect(el).toHaveCompiledCss('color', 'red', { media: '(min-width: 1px)' });
182
+ });
183
+
184
+ it('should match complicated direct ancestors', () => {
185
+ const { getByText } = render(
186
+ <div
187
+ css={`
188
+ > :first-child {
189
+ color: red;
190
+ }
191
+ `}>
192
+ hello world
193
+ </div>
194
+ );
195
+
196
+ const el = getByText('hello world');
197
+ expect(el).toHaveCompiledCss('color', 'red', { target: '> :first-child' });
198
+ });
199
+ });
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { hydrate } from 'react-dom';
3
+
3
4
  import { CC, CS } from '../runtime';
4
5
 
5
6
  jest.mock('../runtime/is-node', () => ({
@@ -1,10 +1,12 @@
1
1
  /**
2
2
  * @jest-environment node
3
3
  */
4
- import React from 'react';
5
- import { renderToStaticMarkup } from 'react-dom/server';
4
+ // eslint-disable-next-line import/no-extraneous-dependencies
6
5
  import { styled } from '@compiled/react';
6
+ // eslint-disable-next-line import/no-extraneous-dependencies
7
7
  import { CC as CompiledRoot } from '@compiled/react/runtime';
8
+ import React from 'react';
9
+ import { renderToStaticMarkup } from 'react-dom/server';
8
10
 
9
11
  describe('SSR', () => {
10
12
  it('should render styles inline', () => {
@@ -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,6 +1,7 @@
1
+ // eslint-disable-next-line import/no-extraneous-dependencies
2
+ import { ClassNames } from '@compiled/react';
1
3
  import { render } from '@testing-library/react';
2
4
  import React from 'react';
3
- import { ClassNames } from '@compiled/react';
4
5
 
5
6
  describe('class names component', () => {
6
7
  it('should create css from object literal', () => {
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Flowtype definitions for index
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.14.1
4
+ * Flowgen v1.15.0
5
5
  * @flow
6
6
  */
7
7
  import type { Node } from 'react';
8
- import type { CssFunction, BasicTemplateInterpolations } from '../types';
8
+ import type { BasicTemplateInterpolations, CssFunction } from '../types';
9
9
  export type Interpolations = (BasicTemplateInterpolations | CssFunction<> | CssFunction<>[])[];
10
10
  export interface ClassNamesProps {
11
11
  children: (opts: {
@@ -1,42 +1,53 @@
1
- import type { ReactNode } from 'react';
1
+ import type { ReactNode, CSSProperties } from 'react';
2
+
3
+ import type { BasicTemplateInterpolations, CssFunction } from '../types';
2
4
  import { createSetupError } from '../utils/error';
3
- import type { CssFunction, BasicTemplateInterpolations } from '../types';
4
5
 
5
6
  export type Interpolations = (BasicTemplateInterpolations | CssFunction | CssFunction[])[];
6
7
 
7
8
  export interface ClassNamesProps {
8
9
  children: (opts: {
9
10
  css: (css: CssFunction | CssFunction[], ...interpolations: Interpolations) => string;
10
- style: { [key: string]: string };
11
+ style: CSSProperties;
11
12
  }) => ReactNode;
12
13
  }
13
14
 
14
15
  /**
15
- * Use a component where styles are not necessarily tied to an element.
16
+ * ## Class names
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
16
22
  *
23
+ * @example
17
24
  * ```
18
- * // Object CSS
19
25
  * <ClassNames>
20
26
  * {({ css, style }) => children({ className: css({ fontSize: 12 }) })}
21
27
  * </ClassNames>
28
+ * ```
29
+ *
30
+ * ### Style with template literals
22
31
  *
23
- * // Template literal CSS
32
+ * @example
33
+ * ```
24
34
  * <ClassNames>
25
35
  * {({ css, style }) => children({ className: css`font-size: 12px;` })}
26
36
  * </ClassNames>
37
+ * ```
38
+ *
39
+ * ### Compose styles with arrays
27
40
  *
28
- * // Array CSS
41
+ * @example
42
+ * ```
29
43
  * <ClassNames>
30
44
  * {({ css, style }) =>
31
- * children({ className: css([{ fontSize: 12 }, `font-size: 12px`]) })}
45
+ * children({ className: css([{ fontSize: 12 }, css`font-size: 12px`]) })}
32
46
  * </ClassNames>
33
47
  * ```
34
- *
35
- * For more help, read the docs:
36
- * https://compiledcssinjs.com/docs/api-class-names
37
- *
38
- * @param props
39
48
  */
40
- export function ClassNames(_: ClassNamesProps): JSX.Element {
49
+ export function ClassNames({ children }: ClassNamesProps): JSX.Element;
50
+
51
+ export function ClassNames(_props: ClassNamesProps): JSX.Element {
41
52
  throw createSetupError();
42
53
  }
@@ -1,7 +1,7 @@
1
- import { render } from '@testing-library/react';
2
- import React from 'react';
3
- import '@compiled/react';
1
+ /** @jsxImportSource @compiled/react */
2
+ // eslint-disable-next-line import/no-extraneous-dependencies
4
3
  import { css } from '@compiled/react';
4
+ import { render } from '@testing-library/react';
5
5
 
6
6
  describe('css prop', () => {
7
7
  it('should create css from object literal', () => {
@@ -30,6 +30,13 @@ describe('css prop', () => {
30
30
  expect(getByText('hello world')).toHaveCompiledCss('font-size', '13px');
31
31
  });
32
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
+
33
40
  it('should create css from tagged template expression variable', () => {
34
41
  const style = css`
35
42
  font-size: 13px;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for index
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.14.1
4
+ * Flowgen v1.15.0
5
5
  * @flow
6
6
  */
7
7
  import type { BasicTemplateInterpolations, CSSProps, FunctionInterpolation } from '../types';
package/src/css/index.tsx CHANGED
@@ -1,41 +1,51 @@
1
+ /* eslint-disable import/export */
2
+
3
+ import type {
4
+ AnyKeyCssProps,
5
+ BasicTemplateInterpolations,
6
+ CSSProps,
7
+ FunctionInterpolation,
8
+ } from '../types';
1
9
  import { createSetupError } from '../utils/error';
2
- import type { BasicTemplateInterpolations, CSSProps, FunctionInterpolation } from '../types';
3
10
 
4
11
  /**
5
- * Create styles that can be re-used between components with a template literal.
12
+ * ## CSS
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).
6
16
  *
17
+ * ### Style with objects
18
+ *
19
+ * @example
7
20
  * ```
8
- * css`color: red;`;
21
+ * const redText = css({
22
+ * color: 'red',
23
+ * });
24
+ *
25
+ * <div css={redText} />
9
26
  * ```
10
27
  *
11
- * For more help, read the docs:
12
- * https://compiledcssinjs.com/docs/api-css
28
+ * ### Style with template literals
13
29
  *
14
- * @param css
15
- * @param values
30
+ * @example
31
+ * ```
32
+ * const redText = css`
33
+ * color: red;
34
+ * `;
35
+ *
36
+ * <div css={redText} />
37
+ * ```
16
38
  */
17
39
  export default function css<T = void>(
18
- _css: TemplateStringsArray,
19
- ..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
40
+ styles: TemplateStringsArray,
41
+ ...interpolations: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
20
42
  ): CSSProps;
21
43
 
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;
44
+ export default function css(styles: AnyKeyCssProps<void> | CSSProps): CSSProps;
35
45
 
36
46
  export default function css<T = void>(
37
- _css: TemplateStringsArray | CSSProps,
38
- ..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
47
+ _styles: TemplateStringsArray | CSSProps,
48
+ ..._interpolations: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
39
49
  ): CSSProps {
40
50
  throw createSetupError();
41
51
  }
package/src/index.js.flow CHANGED
@@ -1,40 +1,15 @@
1
1
  /**
2
- * Flowtype definitions for index
2
+ * THIS IS A MANUALLY CURATED FLOW FILE.
3
+ *
4
+ * Flowtype definitions for runtime
3
5
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.14.1
6
+ * Flowgen v1.15.0
5
7
  * @flow
6
8
  */
7
- import type { CssFunction, CSSProps } from './types';
9
+ import type { CSSProps, CssFunction } from './types';
8
10
  declare export { keyframes } from './keyframes';
9
11
  declare export { styled } from './styled';
10
12
  declare export { ClassNames } from './class-names';
11
13
  declare export { default as css } from './css';
12
14
  export type { CssFunction, CSSProps };
13
15
  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,37 +1,29 @@
1
+ import { createElement } from 'react';
2
+
3
+ import type { CompiledJSX } from './jsx/jsx-local-namespace';
1
4
  import type { CssFunction, CSSProps } from './types';
2
5
 
3
6
  export { keyframes } from './keyframes';
4
7
  export { styled } from './styled';
5
8
  export { ClassNames } from './class-names';
6
9
  export { default as css } from './css';
10
+
11
+ // Pass through the (classic) jsx runtime.
12
+ // Compiled currently doesn't define its own and uses this purely to enable a local jsx namespace.
13
+ export const jsx = createElement;
14
+
7
15
  export type { CssFunction, CSSProps };
8
16
  export type { CssObject } from './styled';
9
17
 
10
- declare module 'react' {
11
- // We must match the same type signature so the generic needs to stay.
12
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
13
- interface DOMAttributes<T> {
14
- css?: CssFunction | CssFunction[];
15
- }
16
- }
17
-
18
- declare global {
19
- namespace JSX {
20
- interface IntrinsicAttributes {
21
- /**
22
- * Tie styles to an element.
23
- * It is available when the `@compiled/react` module is in scope.
24
- *
25
- * ```
26
- * css={{ fontSize: 12 }} // Object CSS
27
- * css={`font-size: 12px;`} // Template literal CSS
28
- * css={[{ fontSize: 12 }, `font-size: 12px;`]} // Array CSS
29
- * ```
30
- *
31
- * For more help, read the docs:
32
- * https://compiledcssinjs.com/docs/api-css-prop
33
- */
34
- css?: CssFunction | CssFunction[];
35
- }
18
+ export namespace jsx {
19
+ export namespace JSX {
20
+ export type Element = CompiledJSX.Element;
21
+ export type ElementClass = CompiledJSX.ElementClass;
22
+ export type ElementAttributesProperty = CompiledJSX.ElementAttributesProperty;
23
+ export type ElementChildrenAttribute = CompiledJSX.ElementChildrenAttribute;
24
+ export type LibraryManagedAttributes<C, P> = CompiledJSX.LibraryManagedAttributes<C, P>;
25
+ export type IntrinsicAttributes = CompiledJSX.IntrinsicAttributes;
26
+ export type IntrinsicClassAttributes<T> = CompiledJSX.IntrinsicClassAttributes<T>;
27
+ export type IntrinsicElements = CompiledJSX.IntrinsicElements;
36
28
  }
37
29
  }
@@ -1,5 +1,4 @@
1
- import '@compiled/react';
2
- import React from 'react';
1
+ /** @jsxImportSource @compiled/react */
3
2
  import { render } from '@testing-library/react';
4
3
 
5
4
  describe('css prop', () => {