@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.
- package/dist/browser/class-names/index.d.ts +22 -16
- package/dist/browser/class-names/index.js +1 -27
- package/dist/browser/class-names/index.js.flow +2 -2
- package/dist/browser/class-names/index.js.map +1 -1
- package/dist/browser/css/index.d.ts +22 -19
- package/dist/browser/css/index.js +4 -3
- package/dist/browser/css/index.js.flow +1 -1
- 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 +5 -30
- 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 +66 -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/keyframes/__fixtures__/index.js +1 -0
- package/dist/browser/keyframes/__fixtures__/index.js.map +1 -1
- package/dist/browser/keyframes/index.d.ts +20 -24
- package/dist/browser/keyframes/index.js.flow +1 -1
- package/dist/browser/keyframes/index.js.map +1 -1
- package/dist/browser/runtime/ax.js.flow +1 -1
- package/dist/browser/runtime/cache.d.ts +12 -0
- package/dist/browser/runtime/cache.js +15 -0
- package/dist/browser/runtime/cache.js.flow +18 -0
- package/dist/browser/runtime/cache.js.map +1 -0
- package/dist/browser/runtime/css-custom-property.d.ts +1 -1
- package/dist/browser/runtime/css-custom-property.js.flow +2 -2
- package/dist/browser/runtime/css-custom-property.js.map +1 -1
- package/dist/browser/runtime/dev-warnings.js +10 -6
- package/dist/browser/runtime/dev-warnings.js.flow +1 -1
- package/dist/browser/runtime/dev-warnings.js.map +1 -1
- package/dist/browser/runtime/index.js.flow +1 -1
- package/dist/browser/runtime/is-node.js +1 -3
- package/dist/browser/runtime/is-node.js.flow +1 -1
- package/dist/browser/runtime/is-node.js.map +1 -1
- package/dist/browser/runtime/sheet.d.ts +1 -1
- package/dist/browser/runtime/sheet.js +5 -1
- package/dist/browser/runtime/sheet.js.flow +2 -2
- package/dist/browser/runtime/sheet.js.map +1 -1
- package/dist/browser/runtime/style-cache.js +4 -0
- package/dist/browser/runtime/style-cache.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.flow +1 -1
- package/dist/browser/runtime/style.js.map +1 -1
- package/dist/browser/runtime/types.js.flow +1 -1
- package/dist/browser/runtime.js.flow +1 -1
- package/dist/browser/styled/index.d.ts +35 -7
- package/dist/browser/styled/index.js +35 -7
- package/dist/browser/styled/index.js.flow +2 -2
- package/dist/browser/styled/index.js.map +1 -1
- package/dist/browser/types.js.flow +1 -1
- package/dist/browser/utils/error.js.flow +1 -1
- package/dist/cjs/class-names/index.d.ts +22 -16
- package/dist/cjs/class-names/index.js +2 -28
- package/dist/cjs/class-names/index.js.flow +2 -2
- package/dist/cjs/class-names/index.js.map +1 -1
- package/dist/cjs/css/index.d.ts +22 -19
- package/dist/cjs/css/index.js +5 -4
- package/dist/cjs/css/index.js.flow +1 -1
- 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 +5 -30
- 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 +66 -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/keyframes/__fixtures__/index.js +2 -1
- package/dist/cjs/keyframes/__fixtures__/index.js.map +1 -1
- package/dist/cjs/keyframes/index.d.ts +20 -24
- package/dist/cjs/keyframes/index.js +1 -1
- package/dist/cjs/keyframes/index.js.flow +1 -1
- package/dist/cjs/keyframes/index.js.map +1 -1
- package/dist/cjs/runtime/ax.js.flow +1 -1
- package/dist/cjs/runtime/cache.d.ts +12 -0
- package/dist/cjs/runtime/cache.js +19 -0
- package/dist/cjs/runtime/cache.js.flow +18 -0
- package/dist/cjs/runtime/cache.js.map +1 -0
- package/dist/cjs/runtime/css-custom-property.d.ts +1 -1
- package/dist/cjs/runtime/css-custom-property.js.flow +2 -2
- package/dist/cjs/runtime/css-custom-property.js.map +1 -1
- package/dist/cjs/runtime/dev-warnings.js +10 -6
- package/dist/cjs/runtime/dev-warnings.js.flow +1 -1
- package/dist/cjs/runtime/dev-warnings.js.map +1 -1
- package/dist/cjs/runtime/index.js.flow +1 -1
- package/dist/cjs/runtime/is-node.js +1 -3
- package/dist/cjs/runtime/is-node.js.flow +1 -1
- package/dist/cjs/runtime/is-node.js.map +1 -1
- package/dist/cjs/runtime/sheet.d.ts +1 -1
- package/dist/cjs/runtime/sheet.js +6 -2
- package/dist/cjs/runtime/sheet.js.flow +2 -2
- package/dist/cjs/runtime/sheet.js.map +1 -1
- package/dist/cjs/runtime/style-cache.js +10 -6
- package/dist/cjs/runtime/style-cache.js.flow +1 -1
- package/dist/cjs/runtime/style-cache.js.map +1 -1
- package/dist/cjs/runtime/style.js +6 -6
- package/dist/cjs/runtime/style.js.flow +1 -1
- package/dist/cjs/runtime/style.js.map +1 -1
- package/dist/cjs/runtime/types.js.flow +1 -1
- package/dist/cjs/runtime.js.flow +1 -1
- package/dist/cjs/styled/index.d.ts +35 -7
- package/dist/cjs/styled/index.js +36 -8
- package/dist/cjs/styled/index.js.flow +2 -2
- package/dist/cjs/styled/index.js.map +1 -1
- package/dist/cjs/types.js.flow +1 -1
- package/dist/cjs/utils/error.js.flow +1 -1
- package/dist/esm/class-names/index.d.ts +22 -16
- package/dist/esm/class-names/index.js +1 -27
- package/dist/esm/class-names/index.js.flow +2 -2
- package/dist/esm/class-names/index.js.map +1 -1
- package/dist/esm/css/index.d.ts +22 -19
- package/dist/esm/css/index.js +4 -3
- package/dist/esm/css/index.js.flow +1 -1
- 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 +5 -30
- 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 +66 -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/keyframes/__fixtures__/index.js +1 -0
- package/dist/esm/keyframes/__fixtures__/index.js.map +1 -1
- package/dist/esm/keyframes/index.d.ts +20 -24
- package/dist/esm/keyframes/index.js.flow +1 -1
- package/dist/esm/keyframes/index.js.map +1 -1
- package/dist/esm/runtime/ax.js.flow +1 -1
- package/dist/esm/runtime/cache.d.ts +12 -0
- package/dist/esm/runtime/cache.js +15 -0
- package/dist/esm/runtime/cache.js.flow +18 -0
- package/dist/esm/runtime/cache.js.map +1 -0
- package/dist/esm/runtime/css-custom-property.d.ts +1 -1
- package/dist/esm/runtime/css-custom-property.js.flow +2 -2
- package/dist/esm/runtime/css-custom-property.js.map +1 -1
- package/dist/esm/runtime/dev-warnings.js +10 -6
- package/dist/esm/runtime/dev-warnings.js.flow +1 -1
- package/dist/esm/runtime/dev-warnings.js.map +1 -1
- package/dist/esm/runtime/index.js.flow +1 -1
- package/dist/esm/runtime/is-node.js +1 -3
- package/dist/esm/runtime/is-node.js.flow +1 -1
- package/dist/esm/runtime/is-node.js.map +1 -1
- package/dist/esm/runtime/sheet.d.ts +1 -1
- package/dist/esm/runtime/sheet.js +5 -1
- package/dist/esm/runtime/sheet.js.flow +2 -2
- package/dist/esm/runtime/sheet.js.map +1 -1
- package/dist/esm/runtime/style-cache.js +4 -0
- package/dist/esm/runtime/style-cache.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.flow +1 -1
- package/dist/esm/runtime/style.js.map +1 -1
- package/dist/esm/runtime/types.js.flow +1 -1
- package/dist/esm/runtime.js.flow +1 -1
- package/dist/esm/styled/index.d.ts +35 -7
- package/dist/esm/styled/index.js +35 -7
- package/dist/esm/styled/index.js.flow +2 -2
- package/dist/esm/styled/index.js.map +1 -1
- package/dist/esm/types.js.flow +1 -1
- package/dist/esm/utils/error.js.flow +1 -1
- package/jsx-dev-runtime/package.json +6 -0
- package/jsx-runtime/package.json +6 -0
- package/package.json +43 -14
- package/src/__tests__/browser.test.tsx +3 -8
- package/src/__tests__/display-names.test.tsx +1 -0
- package/src/__tests__/jest-matcher.test.tsx +199 -0
- package/src/__tests__/server-side-hydrate.test.tsx +1 -0
- package/src/__tests__/ssr.test.tsx +5 -3
- package/src/class-names/__tests__/index.test.tsx +2 -1
- package/src/class-names/index.js.flow +2 -2
- package/src/class-names/index.tsx +25 -14
- package/src/css/__tests__/index.test.tsx +10 -3
- package/src/css/index.js.flow +1 -1
- package/src/css/index.tsx +34 -24
- package/src/index.js.flow +5 -30
- 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 +40 -0
- package/src/jsx/jsx-dev-runtime.tsx +5 -0
- package/src/jsx/jsx-local-namespace.tsx +75 -0
- package/src/jsx/jsx-runtime.tsx +5 -0
- package/src/keyframes/__fixtures__/index.tsx +1 -0
- package/src/keyframes/__tests__/index.test.tsx +20 -6
- package/src/keyframes/index.js.flow +1 -1
- package/src/keyframes/index.tsx +24 -28
- 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 +5 -0
- package/src/runtime/__tests__/style.test.tsx +1 -5
- package/src/runtime/ax.js.flow +1 -1
- package/src/runtime/cache.js.flow +18 -0
- package/src/runtime/cache.tsx +14 -0
- package/src/runtime/css-custom-property.js.flow +2 -2
- package/src/runtime/css-custom-property.tsx +1 -1
- package/src/runtime/dev-warnings.js.flow +1 -1
- package/src/runtime/index.js.flow +1 -1
- package/src/runtime/is-node.js.flow +1 -1
- package/src/runtime/is-node.tsx +1 -2
- package/src/runtime/sheet.js.flow +2 -2
- package/src/runtime/sheet.tsx +8 -2
- package/src/runtime/style-cache.js.flow +1 -1
- package/src/runtime/style-cache.tsx +6 -0
- package/src/runtime/style.js.flow +1 -1
- package/src/runtime/style.tsx +4 -3
- package/src/runtime/types.js.flow +1 -1
- package/src/runtime.js.flow +1 -1
- package/src/styled/__tests__/index.test.tsx +4 -3
- package/src/styled/index.js.flow +2 -2
- package/src/styled/index.tsx +37 -8
- package/src/types.js.flow +1 -1
- package/src/utils/error.js.flow +1 -1
- package/CHANGELOG.md +0 -74
package/package.json
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compiled/react",
|
|
3
|
-
"version": "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":
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
|
|
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":
|
|
33
|
-
|
|
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
|
-
"
|
|
71
|
+
"jsx-runtime",
|
|
72
|
+
"jsx-dev-runtime"
|
|
46
73
|
],
|
|
47
74
|
"dependencies": {
|
|
48
|
-
"csstype": "^3.0.
|
|
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
|
-
|
|
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
|
-
|
|
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(() => {
|
|
@@ -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,10 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @jest-environment node
|
|
3
3
|
*/
|
|
4
|
-
|
|
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
|
|
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.
|
|
4
|
+
* Flowgen v1.15.0
|
|
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,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:
|
|
11
|
+
style: CSSProperties;
|
|
11
12
|
}) => ReactNode;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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(
|
|
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
|
-
|
|
2
|
-
|
|
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;
|
package/src/css/index.js.flow
CHANGED
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
|
-
*
|
|
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
|
|
21
|
+
* const redText = css({
|
|
22
|
+
* color: 'red',
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* <div css={redText} />
|
|
9
26
|
* ```
|
|
10
27
|
*
|
|
11
|
-
*
|
|
12
|
-
* https://compiledcssinjs.com/docs/api-css
|
|
28
|
+
* ### Style with template literals
|
|
13
29
|
*
|
|
14
|
-
* @
|
|
15
|
-
*
|
|
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
|
-
|
|
19
|
-
...
|
|
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
|
-
|
|
38
|
-
...
|
|
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
|
-
*
|
|
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.
|
|
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
|
}
|