@compiled/react 0.9.1 → 0.10.0

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 (118) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dist/browser/class-names/index.d.ts +1 -1
  3. package/dist/browser/class-names/index.js.flow +1 -1
  4. package/dist/browser/class-names/index.js.map +1 -1
  5. package/dist/browser/css/index.js +1 -0
  6. package/dist/browser/css/index.js.map +1 -1
  7. package/dist/browser/index.d.ts +12 -22
  8. package/dist/browser/index.js +4 -0
  9. package/dist/browser/index.js.flow +4 -29
  10. package/dist/browser/index.js.map +1 -1
  11. package/dist/browser/jsx/jsx-dev-runtime.d.ts +2 -0
  12. package/dist/browser/jsx/jsx-dev-runtime.js +4 -0
  13. package/dist/browser/jsx/jsx-dev-runtime.js.map +1 -0
  14. package/dist/browser/jsx/jsx-local-namespace.d.ts +40 -0
  15. package/dist/browser/jsx/jsx-local-namespace.js +2 -0
  16. package/dist/browser/jsx/jsx-local-namespace.js.map +1 -0
  17. package/dist/browser/jsx/jsx-runtime.d.ts +2 -0
  18. package/dist/browser/jsx/jsx-runtime.js +4 -0
  19. package/dist/browser/jsx/jsx-runtime.js.map +1 -0
  20. package/dist/browser/runtime/css-custom-property.d.ts +1 -1
  21. package/dist/browser/runtime/css-custom-property.js.flow +1 -1
  22. package/dist/browser/runtime/css-custom-property.js.map +1 -1
  23. package/dist/browser/runtime/sheet.d.ts +1 -1
  24. package/dist/browser/runtime/sheet.js.flow +1 -1
  25. package/dist/browser/runtime/style-cache.js.map +1 -1
  26. package/dist/browser/runtime/style.js +2 -2
  27. package/dist/browser/runtime/style.js.map +1 -1
  28. package/dist/browser/styled/index.js.map +1 -1
  29. package/dist/cjs/class-names/index.d.ts +1 -1
  30. package/dist/cjs/class-names/index.js.flow +1 -1
  31. package/dist/cjs/class-names/index.js.map +1 -1
  32. package/dist/cjs/css/index.js +1 -0
  33. package/dist/cjs/css/index.js.map +1 -1
  34. package/dist/cjs/index.d.ts +12 -22
  35. package/dist/cjs/index.js +5 -1
  36. package/dist/cjs/index.js.flow +4 -29
  37. package/dist/cjs/index.js.map +1 -1
  38. package/dist/cjs/jsx/jsx-dev-runtime.d.ts +2 -0
  39. package/dist/cjs/jsx/jsx-dev-runtime.js +16 -0
  40. package/dist/cjs/jsx/jsx-dev-runtime.js.map +1 -0
  41. package/dist/cjs/jsx/jsx-local-namespace.d.ts +40 -0
  42. package/dist/cjs/jsx/jsx-local-namespace.js +3 -0
  43. package/dist/cjs/jsx/jsx-local-namespace.js.map +1 -0
  44. package/dist/cjs/jsx/jsx-runtime.d.ts +2 -0
  45. package/dist/cjs/jsx/jsx-runtime.js +16 -0
  46. package/dist/cjs/jsx/jsx-runtime.js.map +1 -0
  47. package/dist/cjs/runtime/css-custom-property.d.ts +1 -1
  48. package/dist/cjs/runtime/css-custom-property.js.flow +1 -1
  49. package/dist/cjs/runtime/css-custom-property.js.map +1 -1
  50. package/dist/cjs/runtime/sheet.d.ts +1 -1
  51. package/dist/cjs/runtime/sheet.js.flow +1 -1
  52. package/dist/cjs/runtime/style-cache.js.map +1 -1
  53. package/dist/cjs/runtime/style.js +2 -2
  54. package/dist/cjs/runtime/style.js.map +1 -1
  55. package/dist/cjs/styled/index.js.map +1 -1
  56. package/dist/esm/class-names/index.d.ts +1 -1
  57. package/dist/esm/class-names/index.js.flow +1 -1
  58. package/dist/esm/class-names/index.js.map +1 -1
  59. package/dist/esm/css/index.js +1 -0
  60. package/dist/esm/css/index.js.map +1 -1
  61. package/dist/esm/index.d.ts +12 -22
  62. package/dist/esm/index.js +4 -0
  63. package/dist/esm/index.js.flow +4 -29
  64. package/dist/esm/index.js.map +1 -1
  65. package/dist/esm/jsx/jsx-dev-runtime.d.ts +2 -0
  66. package/dist/esm/jsx/jsx-dev-runtime.js +4 -0
  67. package/dist/esm/jsx/jsx-dev-runtime.js.map +1 -0
  68. package/dist/esm/jsx/jsx-local-namespace.d.ts +40 -0
  69. package/dist/esm/jsx/jsx-local-namespace.js +2 -0
  70. package/dist/esm/jsx/jsx-local-namespace.js.map +1 -0
  71. package/dist/esm/jsx/jsx-runtime.d.ts +2 -0
  72. package/dist/esm/jsx/jsx-runtime.js +4 -0
  73. package/dist/esm/jsx/jsx-runtime.js.map +1 -0
  74. package/dist/esm/runtime/css-custom-property.d.ts +1 -1
  75. package/dist/esm/runtime/css-custom-property.js.flow +1 -1
  76. package/dist/esm/runtime/css-custom-property.js.map +1 -1
  77. package/dist/esm/runtime/sheet.d.ts +1 -1
  78. package/dist/esm/runtime/sheet.js.flow +1 -1
  79. package/dist/esm/runtime/style-cache.js.map +1 -1
  80. package/dist/esm/runtime/style.js +2 -2
  81. package/dist/esm/runtime/style.js.map +1 -1
  82. package/dist/esm/styled/index.js.map +1 -1
  83. package/jsx-dev-runtime/package.json +6 -0
  84. package/jsx-runtime/package.json +6 -0
  85. package/package.json +40 -12
  86. package/src/__tests__/browser.test.tsx +5 -5
  87. package/src/__tests__/jest-matcher.test.tsx +197 -0
  88. package/src/__tests__/server-side-hydrate.test.tsx +1 -0
  89. package/src/__tests__/ssr.test.tsx +2 -2
  90. package/src/class-names/__tests__/index.test.tsx +1 -1
  91. package/src/class-names/index.js.flow +1 -1
  92. package/src/class-names/index.tsx +2 -1
  93. package/src/css/__tests__/index.test.tsx +2 -3
  94. package/src/css/index.tsx +3 -1
  95. package/src/index.js.flow +4 -29
  96. package/src/index.tsx +18 -26
  97. package/src/jsx/__tests__/index.test.tsx +1 -2
  98. package/src/jsx/__tests__/jsx-import-source-pragma.test.tsx +37 -0
  99. package/src/jsx/__tests__/jsx-pragma.test.tsx +39 -0
  100. package/src/jsx/jsx-dev-runtime.tsx +5 -0
  101. package/src/jsx/jsx-local-namespace.tsx +49 -0
  102. package/src/jsx/jsx-runtime.tsx +5 -0
  103. package/src/keyframes/__tests__/index.test.tsx +2 -1
  104. package/src/runtime/__perf__/ax.test.ts +42 -0
  105. package/src/runtime/__perf__/cs.test.tsx +111 -0
  106. package/src/runtime/__perf__/sheet.test.ts +61 -0
  107. package/src/runtime/__perf__/utils/cs.tsx +60 -0
  108. package/src/runtime/__perf__/utils/sheet.tsx +151 -0
  109. package/src/runtime/__tests__/style-ssr.test.tsx +1 -0
  110. package/src/runtime/__tests__/style.test.tsx +1 -1
  111. package/src/runtime/css-custom-property.js.flow +1 -1
  112. package/src/runtime/css-custom-property.tsx +1 -1
  113. package/src/runtime/sheet.js.flow +1 -1
  114. package/src/runtime/sheet.tsx +1 -1
  115. package/src/runtime/style-cache.tsx +1 -0
  116. package/src/runtime/style.tsx +4 -3
  117. package/src/styled/__tests__/index.test.tsx +3 -3
  118. package/src/styled/index.tsx +2 -1
@@ -0,0 +1,197 @@
1
+ /** @jsxImportSource @compiled/react */
2
+ import { styled } from '@compiled/react';
3
+ import { render } from '@testing-library/react';
4
+
5
+ describe('toHaveCompliedCss', () => {
6
+ it('should detect styles', () => {
7
+ const { getByText } = render(
8
+ <div
9
+ css={{
10
+ fontSize: '12px',
11
+ }}>
12
+ hello world
13
+ </div>
14
+ );
15
+
16
+ expect(getByText('hello world')).toHaveCompiledCss('font-size', '12px');
17
+ });
18
+
19
+ it('should detect missing styles', () => {
20
+ const { getByText } = render(<div css={{ fontSize: '12px' }}>hello world</div>);
21
+
22
+ expect(getByText('hello world')).not.toHaveCompiledCss('color', 'blue');
23
+ });
24
+
25
+ it('should detect multiple styles', () => {
26
+ const { getByText } = render(<div css={{ fontSize: '12px', color: 'blue' }}>hello world</div>);
27
+
28
+ expect(getByText('hello world')).toHaveCompiledCss({
29
+ fontSize: '12px',
30
+ color: 'blue',
31
+ });
32
+ });
33
+
34
+ it('should detect single missing styles', () => {
35
+ const { getByText } = render(<div css={{ fontSize: '12px', color: 'blue' }}>hello world</div>);
36
+
37
+ expect(getByText('hello world')).not.toHaveCompiledCss({
38
+ zindex: '9999',
39
+ });
40
+ });
41
+
42
+ it('should detect multiple missing styles', () => {
43
+ const { getByText } = render(<div css={{ fontSize: '12px', color: 'blue' }}>hello world</div>);
44
+
45
+ expect(getByText('hello world')).not.toHaveCompiledCss({
46
+ backgroundColor: 'yellow',
47
+ zindex: '9999',
48
+ });
49
+ });
50
+
51
+ it('should detect evaluated rule from array styles', () => {
52
+ const base = { color: 'blue' };
53
+ const next = ` font-size: 15px; `;
54
+
55
+ const { getByText } = render(<div css={[base, next]}>hello world</div>);
56
+
57
+ expect(getByText('hello world')).toHaveCompiledCss('font-size', '15px');
58
+ expect(getByText('hello world')).toHaveCompiledCss('color', 'blue');
59
+ });
60
+
61
+ it('should find styles composed from multiple sources', () => {
62
+ const StyledDiv = styled.div`
63
+ font-size: 12px;
64
+ `;
65
+
66
+ const { getByText } = render(<StyledDiv css={{ fontSize: 14 }}>Hello world</StyledDiv>);
67
+
68
+ expect(getByText('Hello world')).toHaveCompiledCss('font-size', '14px');
69
+ });
70
+
71
+ it('should find multiple styles composed from multiple sources', () => {
72
+ const StyledDiv = styled.div`
73
+ color: yellow;
74
+ background-color: red;
75
+ `;
76
+
77
+ const { getByText } = render(<StyledDiv css={{ color: 'blue' }}>Hello world</StyledDiv>);
78
+
79
+ expect(getByText('Hello world')).toHaveCompiledCss({
80
+ backgroundColor: 'red',
81
+ color: 'blue',
82
+ });
83
+ });
84
+
85
+ it('should match styles with target:hover', () => {
86
+ const { getByText } = render(
87
+ <div
88
+ css={{
89
+ fontSize: '12px',
90
+ ':hover': {
91
+ transform: 'scale(2)',
92
+ },
93
+ }}>
94
+ hello world
95
+ </div>
96
+ );
97
+ const el = getByText('hello world');
98
+ expect(el).toHaveCompiledCss('transform', 'scale(2)', { target: ':hover' });
99
+ expect(el).not.toHaveCompiledCss('transform', 'scale(2)');
100
+ });
101
+
102
+ it('should match styles with target', () => {
103
+ const { getByText } = render(
104
+ <div
105
+ css={{
106
+ fontSize: '12px',
107
+ ':hover': {
108
+ transform: 'scale(2)',
109
+ },
110
+ ':active': {
111
+ color: 'blue',
112
+ },
113
+ }}>
114
+ hello world
115
+ </div>
116
+ );
117
+ const el = getByText('hello world');
118
+ expect(el).not.toHaveCompiledCss('color', 'blue', { target: ':hover' });
119
+ expect(el).not.toHaveCompiledCss('transform', 'scale(2)');
120
+ expect(el).not.toHaveCompiledCss('transform', 'scale(2)', { target: ':active' });
121
+ expect(el).toHaveCompiledCss('transform', 'scale(2)', { target: ':hover' });
122
+ expect(el).toHaveCompiledCss('color', 'blue', { target: ':active' });
123
+ });
124
+
125
+ it('should match styles with media', () => {
126
+ const { getByText } = render(
127
+ <div
128
+ css={{
129
+ color: 'green',
130
+ '@media screen': {
131
+ color: 'yellow',
132
+ },
133
+ }}>
134
+ hello world
135
+ </div>
136
+ );
137
+ const el = getByText('hello world');
138
+ expect(el).toHaveCompiledCss('color', 'green');
139
+ expect(el).toHaveCompiledCss('color', 'yellow', { media: 'screen' });
140
+ // without narrowing to media -> screen
141
+ expect(el).not.toHaveCompiledCss('color', 'yellow');
142
+ });
143
+
144
+ it('should match styles with media and target', () => {
145
+ const { getByText } = render(
146
+ <div
147
+ css={{
148
+ color: 'green',
149
+ '@media screen': {
150
+ color: 'yellow',
151
+ ':hover': {
152
+ background: 'red',
153
+ },
154
+ },
155
+ }}>
156
+ hello world
157
+ </div>
158
+ );
159
+ const el = getByText('hello world');
160
+ expect(el).toHaveCompiledCss('background-color', 'red', { media: 'screen', target: ':hover' });
161
+ });
162
+
163
+ it('should match styles with media nested inside class', () => {
164
+ const { getByText } = render(
165
+ <div
166
+ css={{
167
+ '@media (min-width: 2px)': {
168
+ color: 'blue',
169
+ '@media (min-width: 1px)': {
170
+ color: 'red',
171
+ },
172
+ },
173
+ }}>
174
+ hello world
175
+ </div>
176
+ );
177
+ const el = getByText('hello world');
178
+ expect(el).toHaveCompiledCss('color', 'blue', { media: '(min-width: 2px)' });
179
+ expect(el).toHaveCompiledCss('color', 'red', { media: '(min-width: 1px)' });
180
+ });
181
+
182
+ it('should match complicated direct ancestors', () => {
183
+ const { getByText } = render(
184
+ <div
185
+ css={`
186
+ > :first-child {
187
+ color: red;
188
+ }
189
+ `}>
190
+ hello world
191
+ </div>
192
+ );
193
+
194
+ const el = getByText('hello world');
195
+ expect(el).toHaveCompiledCss('color', 'red', { target: '> :first-child' });
196
+ });
197
+ });
@@ -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,10 @@
1
1
  /**
2
2
  * @jest-environment node
3
3
  */
4
- import React from 'react';
5
- import { renderToStaticMarkup } from 'react-dom/server';
6
4
  import { styled } from '@compiled/react';
7
5
  import { CC as CompiledRoot } from '@compiled/react/runtime';
6
+ import React from 'react';
7
+ import { renderToStaticMarkup } from 'react-dom/server';
8
8
 
9
9
  describe('SSR', () => {
10
10
  it('should render styles inline', () => {
@@ -1,6 +1,6 @@
1
+ import { ClassNames } from '@compiled/react';
1
2
  import { render } from '@testing-library/react';
2
3
  import React from 'react';
3
- import { ClassNames } from '@compiled/react';
4
4
 
5
5
  describe('class names component', () => {
6
6
  it('should create css from object literal', () => {
@@ -5,7 +5,7 @@
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,6 +1,7 @@
1
1
  import type { ReactNode } 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
 
@@ -1,7 +1,6 @@
1
- import { render } from '@testing-library/react';
2
- import React from 'react';
3
- import '@compiled/react';
1
+ /** @jsxImportSource @compiled/react */
4
2
  import { css } from '@compiled/react';
3
+ import { render } from '@testing-library/react';
5
4
 
6
5
  describe('css prop', () => {
7
6
  it('should create css from object literal', () => {
package/src/css/index.tsx CHANGED
@@ -1,5 +1,7 @@
1
- import { createSetupError } from '../utils/error';
1
+ /* eslint-disable import/export */
2
+
2
3
  import type { BasicTemplateInterpolations, CSSProps, FunctionInterpolation } from '../types';
4
+ import { createSetupError } from '../utils/error';
3
5
 
4
6
  /**
5
7
  * Create styles that can be re-used between components with a template literal.
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
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', () => {
@@ -0,0 +1,37 @@
1
+ /** @jsxImportSource @compiled/react */
2
+ import { render } from '@testing-library/react';
3
+
4
+ describe('local jsx namespace', () => {
5
+ it('should create css from object literal', () => {
6
+ const { getByText } = render(<div css={{ fontSize: '15px' }}>hello world</div>);
7
+
8
+ expect(getByText('hello world')).toHaveCompiledCss('font-size', '15px');
9
+ });
10
+
11
+ it('should allow css prop when class name is a declared prop', () => {
12
+ function Component({ className, children }: { className?: string; children: string }) {
13
+ return <div className={className}>{children}</div>;
14
+ }
15
+
16
+ const { getByText } = render(<Component css={{ fontSize: '15px' }}>hello world</Component>);
17
+
18
+ expect(getByText('hello world')).toHaveCompiledCss('font-size', '15px');
19
+ });
20
+
21
+ it('should type error css prop when class name is not a declared prop', () => {
22
+ function Component({ children }: { children: string }) {
23
+ return <div>{children}</div>;
24
+ }
25
+
26
+ const { getByText } = render(
27
+ <Component
28
+ // CSS prop is not allowed when class name is not a declared prop
29
+ // @ts-expect-error
30
+ css={{ fontSize: '15px' }}>
31
+ hello world
32
+ </Component>
33
+ );
34
+
35
+ expect(getByText('hello world')).not.toHaveCompiledCss('font-size', '15px');
36
+ });
37
+ });
@@ -0,0 +1,39 @@
1
+ /** @jsxRuntime classic */
2
+ /** @jsx jsx */
3
+ import { jsx } from '@compiled/react';
4
+ import { render } from '@testing-library/react';
5
+
6
+ describe('local jsx namespace', () => {
7
+ it('should create css from object literal', () => {
8
+ const { getByText } = render(<div css={{ fontSize: '15px' }}>hello world</div>);
9
+
10
+ expect(getByText('hello world')).toHaveCompiledCss('font-size', '15px');
11
+ });
12
+
13
+ it('should allow css prop when class name is a declared prop', () => {
14
+ function Component({ className, children }: { className?: string; children: string }) {
15
+ return <div className={className}>{children}</div>;
16
+ }
17
+
18
+ const { getByText } = render(<Component css={{ fontSize: '15px' }}>hello world</Component>);
19
+
20
+ expect(getByText('hello world')).toHaveCompiledCss('font-size', '15px');
21
+ });
22
+
23
+ it('should type error css prop when class name is not a declared prop', () => {
24
+ function Component({ children }: { children: string }) {
25
+ return <div>{children}</div>;
26
+ }
27
+
28
+ const { getByText } = render(
29
+ <Component
30
+ // CSS prop is not allowed when class name is not a declared prop
31
+ // @ts-expect-error
32
+ css={{ fontSize: '15px' }}>
33
+ hello world
34
+ </Component>
35
+ );
36
+
37
+ expect(getByText('hello world')).not.toHaveCompiledCss('font-size', '15px');
38
+ });
39
+ });
@@ -0,0 +1,5 @@
1
+ export type { CompiledJSX as JSX } from './jsx-local-namespace';
2
+
3
+ // Pass through the (automatic) jsx dev runtime.
4
+ // Compiled currently doesn't define its own and uses this purely to enable a local jsx namespace.
5
+ export * from 'react/jsx-dev-runtime';
@@ -0,0 +1,49 @@
1
+ import type { CssFunction } from '../types';
2
+
3
+ type WithConditionalCSSProp<TProps> = 'className' extends keyof TProps
4
+ ? string extends TProps['className' & keyof TProps]
5
+ ? {
6
+ /**
7
+ * Tie styles to an element.
8
+ *
9
+ * ```
10
+ * css={{ fontSize: 12 }} // Object CSS
11
+ * css={`font-size: 12px;`} // Template literal CSS
12
+ * css={[{ fontSize: 12 }, `font-size: 12px;`]} // Array CSS
13
+ * ```
14
+ *
15
+ * For more help, read the docs:
16
+ * https://compiledcssinjs.com/docs/api-css-prop
17
+ */
18
+ css?: CssFunction | CssFunction[];
19
+ }
20
+ : // eslint-disable-next-line @typescript-eslint/ban-types
21
+ {}
22
+ : // eslint-disable-next-line @typescript-eslint/ban-types
23
+ {};
24
+
25
+ // Unpack all here to avoid infinite self-referencing when defining our own JSX namespace
26
+ type ReactJSXElement = JSX.Element;
27
+ type ReactJSXElementClass = JSX.ElementClass;
28
+ type ReactJSXElementAttributesProperty = JSX.ElementAttributesProperty;
29
+ type ReactJSXElementChildrenAttribute = JSX.ElementChildrenAttribute;
30
+ type ReactJSXLibraryManagedAttributes<C, P> = JSX.LibraryManagedAttributes<C, P>;
31
+ type ReactJSXIntrinsicAttributes = JSX.IntrinsicAttributes;
32
+ type ReactJSXIntrinsicClassAttributes<T> = JSX.IntrinsicClassAttributes<T>;
33
+ type ReactJSXIntrinsicElements = JSX.IntrinsicElements;
34
+
35
+ export namespace CompiledJSX {
36
+ export type Element = ReactJSXElement;
37
+ export type ElementClass = ReactJSXElementClass;
38
+ export type ElementAttributesProperty = ReactJSXElementAttributesProperty;
39
+ export type ElementChildrenAttribute = ReactJSXElementChildrenAttribute;
40
+ export type LibraryManagedAttributes<C, P> = WithConditionalCSSProp<P> &
41
+ ReactJSXLibraryManagedAttributes<C, P>;
42
+ export type IntrinsicAttributes = ReactJSXIntrinsicAttributes;
43
+ export type IntrinsicClassAttributes<T> = ReactJSXIntrinsicClassAttributes<T>;
44
+ export type IntrinsicElements = {
45
+ [K in keyof ReactJSXIntrinsicElements]: ReactJSXIntrinsicElements[K] & {
46
+ css?: CssFunction | CssFunction[];
47
+ };
48
+ };
49
+ }
@@ -0,0 +1,5 @@
1
+ export type { CompiledJSX as JSX } from './jsx-local-namespace';
2
+
3
+ // Pass through the (automatic) jsx runtime.
4
+ // Compiled currently doesn't define its own and uses this purely to enable a local jsx namespace.
5
+ export * from 'react/jsx-runtime';
@@ -1,7 +1,8 @@
1
+ /** @jsxImportSource @compiled/react */
1
2
  import { keyframes, styled } from '@compiled/react';
2
3
  import { render } from '@testing-library/react';
3
4
 
4
- import defaultFadeOut, { fadeOut as shadowedFadeOut, namedFadeOut } from '../__fixtures__';
5
+ import defaultFadeOut, { namedFadeOut, fadeOut as shadowedFadeOut } from '../__fixtures__';
5
6
 
6
7
  const getOpacity = (str: string | number) => str;
7
8
 
@@ -0,0 +1,42 @@
1
+ import { runBenchmark } from '@compiled/benchmark';
2
+
3
+ import { ax } from '../index';
4
+
5
+ describe('ax benchmark', () => {
6
+ it('completes with ax() string as the fastest', async () => {
7
+ const arr = [
8
+ '_19itglyw',
9
+ '_2rko1l7b',
10
+ '_ca0qftgi',
11
+ '_u5f319bv',
12
+ '_n3tdftgi',
13
+ '_19bv19bv',
14
+ '_bfhk1mzw',
15
+ '_syazu67f',
16
+ '_k48p1nn1',
17
+ '_ect41kw7',
18
+ '_1wybdlk8',
19
+ '_irr3mlcl',
20
+ '_1di6vctu',
21
+ undefined,
22
+ ];
23
+
24
+ // Remove undefined and join the strings
25
+ const str = arr.slice(0, -1).join(' ');
26
+
27
+ const benchmark = await runBenchmark('ax', [
28
+ {
29
+ name: 'ax() array',
30
+ fn: () => ax(arr),
31
+ },
32
+ {
33
+ name: 'ax() string',
34
+ fn: () => ax([str, undefined]),
35
+ },
36
+ ]);
37
+
38
+ expect(benchmark).toMatchObject({
39
+ fastest: ['ax() string'],
40
+ });
41
+ }, 30000);
42
+ });