@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.
- package/CHANGELOG.md +47 -0
- package/dist/browser/class-names/index.d.ts +1 -1
- package/dist/browser/class-names/index.js.flow +1 -1
- package/dist/browser/class-names/index.js.map +1 -1
- package/dist/browser/css/index.js +1 -0
- package/dist/browser/css/index.js.map +1 -1
- package/dist/browser/index.d.ts +12 -22
- package/dist/browser/index.js +4 -0
- package/dist/browser/index.js.flow +4 -29
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/jsx/jsx-dev-runtime.d.ts +2 -0
- package/dist/browser/jsx/jsx-dev-runtime.js +4 -0
- package/dist/browser/jsx/jsx-dev-runtime.js.map +1 -0
- package/dist/browser/jsx/jsx-local-namespace.d.ts +40 -0
- package/dist/browser/jsx/jsx-local-namespace.js +2 -0
- package/dist/browser/jsx/jsx-local-namespace.js.map +1 -0
- package/dist/browser/jsx/jsx-runtime.d.ts +2 -0
- package/dist/browser/jsx/jsx-runtime.js +4 -0
- package/dist/browser/jsx/jsx-runtime.js.map +1 -0
- package/dist/browser/runtime/css-custom-property.d.ts +1 -1
- package/dist/browser/runtime/css-custom-property.js.flow +1 -1
- package/dist/browser/runtime/css-custom-property.js.map +1 -1
- package/dist/browser/runtime/sheet.d.ts +1 -1
- package/dist/browser/runtime/sheet.js.flow +1 -1
- package/dist/browser/runtime/style-cache.js.map +1 -1
- package/dist/browser/runtime/style.js +2 -2
- package/dist/browser/runtime/style.js.map +1 -1
- package/dist/browser/styled/index.js.map +1 -1
- package/dist/cjs/class-names/index.d.ts +1 -1
- package/dist/cjs/class-names/index.js.flow +1 -1
- package/dist/cjs/class-names/index.js.map +1 -1
- package/dist/cjs/css/index.js +1 -0
- package/dist/cjs/css/index.js.map +1 -1
- package/dist/cjs/index.d.ts +12 -22
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/index.js.flow +4 -29
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/jsx/jsx-dev-runtime.d.ts +2 -0
- package/dist/cjs/jsx/jsx-dev-runtime.js +16 -0
- package/dist/cjs/jsx/jsx-dev-runtime.js.map +1 -0
- package/dist/cjs/jsx/jsx-local-namespace.d.ts +40 -0
- package/dist/cjs/jsx/jsx-local-namespace.js +3 -0
- package/dist/cjs/jsx/jsx-local-namespace.js.map +1 -0
- package/dist/cjs/jsx/jsx-runtime.d.ts +2 -0
- package/dist/cjs/jsx/jsx-runtime.js +16 -0
- package/dist/cjs/jsx/jsx-runtime.js.map +1 -0
- package/dist/cjs/runtime/css-custom-property.d.ts +1 -1
- package/dist/cjs/runtime/css-custom-property.js.flow +1 -1
- package/dist/cjs/runtime/css-custom-property.js.map +1 -1
- package/dist/cjs/runtime/sheet.d.ts +1 -1
- package/dist/cjs/runtime/sheet.js.flow +1 -1
- package/dist/cjs/runtime/style-cache.js.map +1 -1
- package/dist/cjs/runtime/style.js +2 -2
- package/dist/cjs/runtime/style.js.map +1 -1
- package/dist/cjs/styled/index.js.map +1 -1
- package/dist/esm/class-names/index.d.ts +1 -1
- package/dist/esm/class-names/index.js.flow +1 -1
- package/dist/esm/class-names/index.js.map +1 -1
- package/dist/esm/css/index.js +1 -0
- package/dist/esm/css/index.js.map +1 -1
- package/dist/esm/index.d.ts +12 -22
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.flow +4 -29
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/jsx/jsx-dev-runtime.d.ts +2 -0
- package/dist/esm/jsx/jsx-dev-runtime.js +4 -0
- package/dist/esm/jsx/jsx-dev-runtime.js.map +1 -0
- package/dist/esm/jsx/jsx-local-namespace.d.ts +40 -0
- package/dist/esm/jsx/jsx-local-namespace.js +2 -0
- package/dist/esm/jsx/jsx-local-namespace.js.map +1 -0
- package/dist/esm/jsx/jsx-runtime.d.ts +2 -0
- package/dist/esm/jsx/jsx-runtime.js +4 -0
- package/dist/esm/jsx/jsx-runtime.js.map +1 -0
- package/dist/esm/runtime/css-custom-property.d.ts +1 -1
- package/dist/esm/runtime/css-custom-property.js.flow +1 -1
- package/dist/esm/runtime/css-custom-property.js.map +1 -1
- package/dist/esm/runtime/sheet.d.ts +1 -1
- package/dist/esm/runtime/sheet.js.flow +1 -1
- package/dist/esm/runtime/style-cache.js.map +1 -1
- package/dist/esm/runtime/style.js +2 -2
- package/dist/esm/runtime/style.js.map +1 -1
- package/dist/esm/styled/index.js.map +1 -1
- package/jsx-dev-runtime/package.json +6 -0
- package/jsx-runtime/package.json +6 -0
- package/package.json +40 -12
- package/src/__tests__/browser.test.tsx +5 -5
- package/src/__tests__/jest-matcher.test.tsx +197 -0
- package/src/__tests__/server-side-hydrate.test.tsx +1 -0
- package/src/__tests__/ssr.test.tsx +2 -2
- package/src/class-names/__tests__/index.test.tsx +1 -1
- package/src/class-names/index.js.flow +1 -1
- package/src/class-names/index.tsx +2 -1
- package/src/css/__tests__/index.test.tsx +2 -3
- package/src/css/index.tsx +3 -1
- package/src/index.js.flow +4 -29
- package/src/index.tsx +18 -26
- package/src/jsx/__tests__/index.test.tsx +1 -2
- package/src/jsx/__tests__/jsx-import-source-pragma.test.tsx +37 -0
- package/src/jsx/__tests__/jsx-pragma.test.tsx +39 -0
- package/src/jsx/jsx-dev-runtime.tsx +5 -0
- package/src/jsx/jsx-local-namespace.tsx +49 -0
- package/src/jsx/jsx-runtime.tsx +5 -0
- package/src/keyframes/__tests__/index.test.tsx +2 -1
- package/src/runtime/__perf__/ax.test.ts +42 -0
- package/src/runtime/__perf__/cs.test.tsx +111 -0
- package/src/runtime/__perf__/sheet.test.ts +61 -0
- package/src/runtime/__perf__/utils/cs.tsx +60 -0
- package/src/runtime/__perf__/utils/sheet.tsx +151 -0
- package/src/runtime/__tests__/style-ssr.test.tsx +1 -0
- package/src/runtime/__tests__/style.test.tsx +1 -1
- package/src/runtime/css-custom-property.js.flow +1 -1
- package/src/runtime/css-custom-property.tsx +1 -1
- package/src/runtime/sheet.js.flow +1 -1
- package/src/runtime/sheet.tsx +1 -1
- package/src/runtime/style-cache.tsx +1 -0
- package/src/runtime/style.tsx +4 -3
- package/src/styled/__tests__/index.test.tsx +3 -3
- 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,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 {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
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 {
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
}
|
|
@@ -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,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
|
+
}
|
|
@@ -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
|
|
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
|
+
});
|