@compiled/react 0.7.0 → 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 +68 -1
- package/dist/browser/class-names/index.d.ts +2 -2
- package/dist/browser/class-names/index.js.flow +45 -0
- package/dist/browser/class-names/index.js.map +1 -1
- package/dist/browser/css/index.d.ts +16 -3
- package/dist/browser/css/index.js +1 -13
- package/dist/browser/css/index.js.flow +35 -0
- package/dist/browser/css/index.js.map +1 -1
- package/dist/browser/index.d.ts +15 -23
- package/dist/browser/index.js +4 -0
- package/dist/browser/index.js.flow +15 -0
- 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/keyframes/index.js.flow +54 -0
- package/dist/browser/runtime/ax.js.flow +27 -0
- package/dist/browser/runtime/css-custom-property.d.ts +1 -1
- package/dist/browser/runtime/css-custom-property.js.flow +19 -0
- package/dist/browser/runtime/css-custom-property.js.map +1 -1
- package/dist/browser/runtime/dev-warnings.d.ts +0 -1
- package/dist/browser/runtime/dev-warnings.js +1 -1
- package/dist/browser/runtime/dev-warnings.js.flow +7 -0
- package/dist/browser/runtime/dev-warnings.js.map +1 -1
- package/dist/browser/runtime/index.js.flow +10 -0
- package/dist/browser/runtime/is-node.js.flow +19 -0
- package/dist/browser/runtime/sheet.d.ts +1 -1
- package/dist/browser/runtime/sheet.js.flow +36 -0
- package/dist/browser/runtime/style-cache.d.ts +1 -1
- package/dist/browser/runtime/style-cache.js.flow +19 -0
- package/dist/browser/runtime/style-cache.js.map +1 -1
- package/dist/browser/runtime/style.d.ts +1 -1
- package/dist/browser/runtime/style.js +2 -2
- package/dist/browser/runtime/style.js.flow +17 -0
- package/dist/browser/runtime/style.js.map +1 -1
- package/dist/browser/runtime/types.js.flow +23 -0
- package/dist/browser/runtime.js.flow +7 -0
- package/dist/browser/styled/index.d.ts +6 -9
- package/dist/browser/styled/index.js.flow +69 -0
- package/dist/browser/styled/index.js.map +1 -1
- package/dist/browser/types.d.ts +6 -3
- package/dist/browser/types.js.flow +29 -0
- package/dist/browser/utils/error.js.flow +7 -0
- package/dist/cjs/class-names/index.d.ts +2 -2
- package/dist/cjs/class-names/index.js.flow +45 -0
- package/dist/cjs/class-names/index.js.map +1 -1
- package/dist/cjs/css/index.d.ts +16 -3
- package/dist/cjs/css/index.js +1 -13
- package/dist/cjs/css/index.js.flow +35 -0
- package/dist/cjs/css/index.js.map +1 -1
- package/dist/cjs/index.d.ts +15 -23
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/index.js.flow +15 -0
- 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/keyframes/index.js.flow +54 -0
- package/dist/cjs/runtime/ax.js.flow +27 -0
- package/dist/cjs/runtime/css-custom-property.d.ts +1 -1
- package/dist/cjs/runtime/css-custom-property.js.flow +19 -0
- package/dist/cjs/runtime/css-custom-property.js.map +1 -1
- package/dist/cjs/runtime/dev-warnings.d.ts +0 -1
- package/dist/cjs/runtime/dev-warnings.js +2 -3
- package/dist/cjs/runtime/dev-warnings.js.flow +7 -0
- package/dist/cjs/runtime/dev-warnings.js.map +1 -1
- package/dist/cjs/runtime/index.js.flow +10 -0
- package/dist/cjs/runtime/is-node.js.flow +19 -0
- package/dist/cjs/runtime/sheet.d.ts +1 -1
- package/dist/cjs/runtime/sheet.js.flow +36 -0
- package/dist/cjs/runtime/style-cache.d.ts +1 -1
- package/dist/cjs/runtime/style-cache.js.flow +19 -0
- package/dist/cjs/runtime/style-cache.js.map +1 -1
- package/dist/cjs/runtime/style.d.ts +1 -1
- package/dist/cjs/runtime/style.js +2 -2
- package/dist/cjs/runtime/style.js.flow +17 -0
- package/dist/cjs/runtime/style.js.map +1 -1
- package/dist/cjs/runtime/types.js.flow +23 -0
- package/dist/cjs/runtime.js.flow +7 -0
- package/dist/cjs/styled/index.d.ts +6 -9
- package/dist/cjs/styled/index.js.flow +69 -0
- package/dist/cjs/styled/index.js.map +1 -1
- package/dist/cjs/types.d.ts +6 -3
- package/dist/cjs/types.js.flow +29 -0
- package/dist/cjs/utils/error.js.flow +7 -0
- package/dist/esm/class-names/index.d.ts +2 -2
- package/dist/esm/class-names/index.js.flow +45 -0
- package/dist/esm/class-names/index.js.map +1 -1
- package/dist/esm/css/index.d.ts +16 -3
- package/dist/esm/css/index.js +1 -13
- package/dist/esm/css/index.js.flow +35 -0
- package/dist/esm/css/index.js.map +1 -1
- package/dist/esm/index.d.ts +15 -23
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.flow +15 -0
- 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/keyframes/index.js.flow +54 -0
- package/dist/esm/runtime/ax.js.flow +27 -0
- package/dist/esm/runtime/css-custom-property.d.ts +1 -1
- package/dist/esm/runtime/css-custom-property.js.flow +19 -0
- package/dist/esm/runtime/css-custom-property.js.map +1 -1
- package/dist/esm/runtime/dev-warnings.d.ts +0 -1
- package/dist/esm/runtime/dev-warnings.js +1 -1
- package/dist/esm/runtime/dev-warnings.js.flow +7 -0
- package/dist/esm/runtime/dev-warnings.js.map +1 -1
- package/dist/esm/runtime/index.js.flow +10 -0
- package/dist/esm/runtime/is-node.js.flow +19 -0
- package/dist/esm/runtime/sheet.d.ts +1 -1
- package/dist/esm/runtime/sheet.js.flow +36 -0
- package/dist/esm/runtime/style-cache.d.ts +1 -1
- package/dist/esm/runtime/style-cache.js.flow +19 -0
- package/dist/esm/runtime/style-cache.js.map +1 -1
- package/dist/esm/runtime/style.d.ts +1 -1
- package/dist/esm/runtime/style.js +2 -2
- package/dist/esm/runtime/style.js.flow +17 -0
- package/dist/esm/runtime/style.js.map +1 -1
- package/dist/esm/runtime/types.js.flow +23 -0
- package/dist/esm/runtime.js.flow +7 -0
- package/dist/esm/styled/index.d.ts +6 -9
- package/dist/esm/styled/index.js.flow +69 -0
- package/dist/esm/styled/index.js.map +1 -1
- package/dist/esm/types.d.ts +6 -3
- package/dist/esm/types.js.flow +29 -0
- package/dist/esm/utils/error.js.flow +7 -0
- package/jsx-dev-runtime/package.json +6 -0
- package/jsx-runtime/package.json +6 -0
- package/package.json +41 -15
- 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/__tests__/types.test.js.flow +28 -0
- package/src/class-names/index.js.flow +45 -0
- package/src/class-names/index.tsx +3 -2
- package/src/css/__tests__/index.test.tsx +40 -0
- package/src/css/__tests__/types.test.js.flow +17 -0
- package/src/css/index.js.flow +35 -0
- package/src/css/index.tsx +27 -3
- package/src/index.js.flow +15 -0
- package/src/index.tsx +20 -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/keyframes/__tests__/types.test.js.flow +31 -0
- package/src/keyframes/index.js.flow +54 -0
- 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 +92 -58
- package/src/runtime/ax.js.flow +27 -0
- package/src/runtime/css-custom-property.js.flow +19 -0
- package/src/runtime/css-custom-property.tsx +1 -1
- package/src/runtime/dev-warnings.js.flow +7 -0
- package/src/runtime/dev-warnings.tsx +1 -1
- package/src/runtime/index.js.flow +10 -0
- package/src/runtime/is-node.js.flow +19 -0
- package/src/runtime/sheet.js.flow +36 -0
- package/src/runtime/sheet.tsx +1 -1
- package/src/runtime/style-cache.js.flow +19 -0
- package/src/runtime/style-cache.tsx +2 -1
- package/src/runtime/style.js.flow +17 -0
- package/src/runtime/style.tsx +4 -3
- package/src/runtime/types.js.flow +23 -0
- package/src/runtime.js.flow +7 -0
- package/src/styled/__tests__/index.test.tsx +3 -3
- package/src/styled/__tests__/types.test.js.flow +30 -0
- package/src/styled/index.js.flow +69 -0
- package/src/styled/index.tsx +7 -10
- package/src/types.js.flow +29 -0
- package/src/types.tsx +7 -3
- package/src/utils/error.js.flow +7 -0
- package/dist/browser/codemods/codemods-helpers.d.ts +0 -60
- package/dist/browser/codemods/codemods-helpers.js +0 -201
- package/dist/browser/codemods/codemods-helpers.js.map +0 -1
- package/dist/browser/codemods/constants.d.ts +0 -3
- package/dist/browser/codemods/constants.js +0 -4
- package/dist/browser/codemods/constants.js.map +0 -1
- package/dist/browser/codemods/emotion-to-compiled/emotion-to-compiled.d.ts +0 -3
- package/dist/browser/codemods/emotion-to-compiled/emotion-to-compiled.js +0 -178
- package/dist/browser/codemods/emotion-to-compiled/emotion-to-compiled.js.map +0 -1
- package/dist/browser/codemods/emotion-to-compiled/index.d.ts +0 -1
- package/dist/browser/codemods/emotion-to-compiled/index.js +0 -2
- package/dist/browser/codemods/emotion-to-compiled/index.js.map +0 -1
- package/dist/browser/codemods/styled-components-to-compiled/index.d.ts +0 -1
- package/dist/browser/codemods/styled-components-to-compiled/index.js +0 -2
- package/dist/browser/codemods/styled-components-to-compiled/index.js.map +0 -1
- package/dist/browser/codemods/styled-components-to-compiled/styled-components-to-compiled.d.ts +0 -3
- package/dist/browser/codemods/styled-components-to-compiled/styled-components-to-compiled.js +0 -33
- package/dist/browser/codemods/styled-components-to-compiled/styled-components-to-compiled.js.map +0 -1
- package/dist/cjs/codemods/codemods-helpers.d.ts +0 -60
- package/dist/cjs/codemods/codemods-helpers.js +0 -217
- package/dist/cjs/codemods/codemods-helpers.js.map +0 -1
- package/dist/cjs/codemods/constants.d.ts +0 -3
- package/dist/cjs/codemods/constants.js +0 -7
- package/dist/cjs/codemods/constants.js.map +0 -1
- package/dist/cjs/codemods/emotion-to-compiled/emotion-to-compiled.d.ts +0 -3
- package/dist/cjs/codemods/emotion-to-compiled/emotion-to-compiled.js +0 -180
- package/dist/cjs/codemods/emotion-to-compiled/emotion-to-compiled.js.map +0 -1
- package/dist/cjs/codemods/emotion-to-compiled/index.d.ts +0 -1
- package/dist/cjs/codemods/emotion-to-compiled/index.js +0 -9
- package/dist/cjs/codemods/emotion-to-compiled/index.js.map +0 -1
- package/dist/cjs/codemods/styled-components-to-compiled/index.d.ts +0 -1
- package/dist/cjs/codemods/styled-components-to-compiled/index.js +0 -9
- package/dist/cjs/codemods/styled-components-to-compiled/index.js.map +0 -1
- package/dist/cjs/codemods/styled-components-to-compiled/styled-components-to-compiled.d.ts +0 -3
- package/dist/cjs/codemods/styled-components-to-compiled/styled-components-to-compiled.js +0 -35
- package/dist/cjs/codemods/styled-components-to-compiled/styled-components-to-compiled.js.map +0 -1
- package/dist/esm/codemods/codemods-helpers.d.ts +0 -60
- package/dist/esm/codemods/codemods-helpers.js +0 -201
- package/dist/esm/codemods/codemods-helpers.js.map +0 -1
- package/dist/esm/codemods/constants.d.ts +0 -3
- package/dist/esm/codemods/constants.js +0 -4
- package/dist/esm/codemods/constants.js.map +0 -1
- package/dist/esm/codemods/emotion-to-compiled/emotion-to-compiled.d.ts +0 -3
- package/dist/esm/codemods/emotion-to-compiled/emotion-to-compiled.js +0 -178
- package/dist/esm/codemods/emotion-to-compiled/emotion-to-compiled.js.map +0 -1
- package/dist/esm/codemods/emotion-to-compiled/index.d.ts +0 -1
- package/dist/esm/codemods/emotion-to-compiled/index.js +0 -2
- package/dist/esm/codemods/emotion-to-compiled/index.js.map +0 -1
- package/dist/esm/codemods/styled-components-to-compiled/index.d.ts +0 -1
- package/dist/esm/codemods/styled-components-to-compiled/index.js +0 -2
- package/dist/esm/codemods/styled-components-to-compiled/index.js.map +0 -1
- package/dist/esm/codemods/styled-components-to-compiled/styled-components-to-compiled.d.ts +0 -3
- package/dist/esm/codemods/styled-components-to-compiled/styled-components-to-compiled.js +0 -33
- package/dist/esm/codemods/styled-components-to-compiled/styled-components-to-compiled.js.map +0 -1
- package/src/codemods/README.md +0 -8
- package/src/codemods/codemods-helpers.tsx +0 -369
- package/src/codemods/constants.tsx +0 -3
- package/src/codemods/emotion-to-compiled/README.md +0 -71
- package/src/codemods/emotion-to-compiled/__tests__/emotion-to-compiled.test.tsx +0 -526
- package/src/codemods/emotion-to-compiled/emotion-to-compiled.tsx +0 -249
- package/src/codemods/emotion-to-compiled/index.tsx +0 -1
- package/src/codemods/styled-components-to-compiled/README.md +0 -37
- package/src/codemods/styled-components-to-compiled/__tests__/styled-components-to-compiled.test.tsx +0 -109
- package/src/codemods/styled-components-to-compiled/index.tsx +0 -1
- package/src/codemods/styled-components-to-compiled/styled-components-to-compiled.tsx +0 -45
package/src/css/index.tsx
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
/* eslint-disable import/export */
|
|
2
|
+
|
|
3
|
+
import type { BasicTemplateInterpolations, CSSProps, FunctionInterpolation } from '../types';
|
|
1
4
|
import { createSetupError } from '../utils/error';
|
|
2
|
-
import type { CSSProps } from '../types';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
|
-
* Create styles that can be re-used between components.
|
|
7
|
+
* Create styles that can be re-used between components with a template literal.
|
|
6
8
|
*
|
|
7
9
|
* ```
|
|
8
10
|
* css`color: red;`;
|
|
@@ -14,6 +16,28 @@ import type { CSSProps } from '../types';
|
|
|
14
16
|
* @param css
|
|
15
17
|
* @param values
|
|
16
18
|
*/
|
|
17
|
-
export default function css
|
|
19
|
+
export default function css<T = void>(
|
|
20
|
+
_css: TemplateStringsArray,
|
|
21
|
+
..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
|
|
22
|
+
): CSSProps;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Create styles that can be re-used between components with an object
|
|
26
|
+
*
|
|
27
|
+
* ```
|
|
28
|
+
* css({ color: 'red' });
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* For more help, read the docs:
|
|
32
|
+
* https://compiledcssinjs.com/docs/api-css
|
|
33
|
+
*
|
|
34
|
+
* @param css
|
|
35
|
+
*/
|
|
36
|
+
export default function css(_css: CSSProps): CSSProps;
|
|
37
|
+
|
|
38
|
+
export default function css<T = void>(
|
|
39
|
+
_css: TemplateStringsArray | CSSProps,
|
|
40
|
+
..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
|
|
41
|
+
): CSSProps {
|
|
18
42
|
throw createSetupError();
|
|
19
43
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THIS IS A MANUALLY CURATED FLOW FILE.
|
|
3
|
+
*
|
|
4
|
+
* Flowtype definitions for runtime
|
|
5
|
+
* Generated by Flowgen from a Typescript Definition
|
|
6
|
+
* Flowgen v1.15.0
|
|
7
|
+
* @flow
|
|
8
|
+
*/
|
|
9
|
+
import type { CSSProps, CssFunction } from './types';
|
|
10
|
+
declare export { keyframes } from './keyframes';
|
|
11
|
+
declare export { styled } from './styled';
|
|
12
|
+
declare export { ClassNames } from './class-names';
|
|
13
|
+
declare export { default as css } from './css';
|
|
14
|
+
export type { CssFunction, CSSProps };
|
|
15
|
+
export type { CssObject } from './styled';
|
package/src/index.tsx
CHANGED
|
@@ -1,35 +1,29 @@
|
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { CompiledJSX } from './jsx/jsx-local-namespace';
|
|
4
|
+
import type { CssFunction, CSSProps } from './types';
|
|
5
|
+
|
|
1
6
|
export { keyframes } from './keyframes';
|
|
2
7
|
export { styled } from './styled';
|
|
3
8
|
export { ClassNames } from './class-names';
|
|
4
9
|
export { default as css } from './css';
|
|
5
10
|
|
|
6
|
-
|
|
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;
|
|
7
14
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
11
|
-
interface DOMAttributes<T> {
|
|
12
|
-
css?: CssFunction | CssFunction[];
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
+
export type { CssFunction, CSSProps };
|
|
16
|
+
export type { CssObject } from './styled';
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
namespace JSX {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* css={[{ fontSize: 12 }, `font-size: 12px;`]} // Array CSS
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* For more help, read the docs:
|
|
30
|
-
* https://compiledcssinjs.com/docs/api-css-prop
|
|
31
|
-
*/
|
|
32
|
-
css?: CssFunction | CssFunction[];
|
|
33
|
-
}
|
|
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;
|
|
34
28
|
}
|
|
35
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,31 @@
|
|
|
1
|
+
// @flow strict-local
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { css, ClassNames, styled, keyframes } from '@compiled/react';
|
|
4
|
+
|
|
5
|
+
// Tagged template expression
|
|
6
|
+
(): React$Element<'div'> => {
|
|
7
|
+
const fadeOut = keyframes`
|
|
8
|
+
from { opacity: 1; }
|
|
9
|
+
to { opacity: 0; }
|
|
10
|
+
`;
|
|
11
|
+
return <div css={{ animationName: fadeOut }}>hello world</div>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// Object call expression
|
|
15
|
+
(): React$Element<'div'> => {
|
|
16
|
+
const fadeOut = keyframes({
|
|
17
|
+
from: {
|
|
18
|
+
opacity: 1,
|
|
19
|
+
},
|
|
20
|
+
to: {
|
|
21
|
+
opacity: 0,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
return <div css={{ animationName: fadeOut }}>hello world</div>;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// String call expression
|
|
28
|
+
(): React$Element<'div'> => {
|
|
29
|
+
const fadeOut = keyframes('from { opacity: 1; } to { opacity: 0; }');
|
|
30
|
+
return <div css={{ animationName: fadeOut }}>hello world</div>;
|
|
31
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for index
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.15.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
import type { BasicTemplateInterpolations, CSSProps } from '../types';
|
|
8
|
+
export type KeyframeSteps = string | { [key: string]: CSSProps, ... };
|
|
9
|
+
/**
|
|
10
|
+
* Create keyframes using a tagged template expression:
|
|
11
|
+
*
|
|
12
|
+
* ```
|
|
13
|
+
* const fadeOut = keyframes`
|
|
14
|
+
* from { opacity: 1; }
|
|
15
|
+
* to { opacity: 0; }
|
|
16
|
+
* `;
|
|
17
|
+
* ```
|
|
18
|
+
* @param _strings The input string values
|
|
19
|
+
* @param _interpolations The arguments used in the expression
|
|
20
|
+
*/
|
|
21
|
+
declare export function keyframes(
|
|
22
|
+
_strings: $ReadOnlyArray<string>,
|
|
23
|
+
..._interpolations: BasicTemplateInterpolations[]
|
|
24
|
+
): string;
|
|
25
|
+
/**
|
|
26
|
+
* Create keyframes using:
|
|
27
|
+
*
|
|
28
|
+
* 1. An object expression
|
|
29
|
+
*
|
|
30
|
+
* ```
|
|
31
|
+
* const fadeOut = keyframes({
|
|
32
|
+
* from: {
|
|
33
|
+
* opacity: 1,
|
|
34
|
+
* },
|
|
35
|
+
* to: {
|
|
36
|
+
* opacity: 0,
|
|
37
|
+
* },
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* 2. A string
|
|
42
|
+
*
|
|
43
|
+
* ```
|
|
44
|
+
* const fadeOut = keyframes('from { opacity: 1; } to { opacity: 0; }');
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* 3. A template literal
|
|
48
|
+
*
|
|
49
|
+
* ```
|
|
50
|
+
* const fadeOut = keyframes(`from { opacity: 1; } to { opacity: 0; }`);
|
|
51
|
+
* ```
|
|
52
|
+
* @param _steps The waypoints along the animation sequence
|
|
53
|
+
*/
|
|
54
|
+
declare export function keyframes(_steps: KeyframeSteps): string;
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { runBenchmark } from '@compiled/benchmark';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { renderToString } from 'react-dom/server';
|
|
4
|
+
|
|
5
|
+
import { CC, CS } from '../index';
|
|
6
|
+
|
|
7
|
+
import { StyleArr, StyleStr } from './utils/cs';
|
|
8
|
+
|
|
9
|
+
describe('CS benchmark', () => {
|
|
10
|
+
it('completes with CS (1 array element) or StyleArr as the fastest', async () => {
|
|
11
|
+
const stylesArr = [
|
|
12
|
+
'._s7n4jp4b{vertical-align:top}',
|
|
13
|
+
'._1reo15vq{overflow-x:hidden}',
|
|
14
|
+
'._18m915vq{overflow-y:hidden}',
|
|
15
|
+
'._1bto1l2s{text-overflow:ellipsis}',
|
|
16
|
+
'._o5721q9c{white-space:nowrap}',
|
|
17
|
+
'._ca0qidpf{padding-top:0}',
|
|
18
|
+
'._u5f31y44{padding-right:4px}',
|
|
19
|
+
'._n3tdidpf{padding-bottom:0}',
|
|
20
|
+
'._19bv1y44{padding-left:4px}',
|
|
21
|
+
'._p12f12xx{max-width:100px}',
|
|
22
|
+
'._1bsb1osq{width:100%}',
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const stylesStr = stylesArr.join('');
|
|
26
|
+
|
|
27
|
+
const className = [
|
|
28
|
+
'_bfhk1jys',
|
|
29
|
+
'_2rko1l7b',
|
|
30
|
+
'_vchhusvi',
|
|
31
|
+
'_syaz4rde',
|
|
32
|
+
'_1e0c1o8l',
|
|
33
|
+
'_1wyb1skh',
|
|
34
|
+
'_k48p1fw0',
|
|
35
|
+
'_vwz4kb7n',
|
|
36
|
+
'_p12f1osq',
|
|
37
|
+
'_ca0qyh40',
|
|
38
|
+
'_u5f3idpf',
|
|
39
|
+
'_n3td1l7b',
|
|
40
|
+
'_19bvidpf',
|
|
41
|
+
'_1p1dangw',
|
|
42
|
+
'_s7n41q9y',
|
|
43
|
+
].join(' ');
|
|
44
|
+
|
|
45
|
+
const style = {
|
|
46
|
+
'--_16owtcm': 'rgb(227, 252, 239)',
|
|
47
|
+
'--_kmurgp': 'rgb(0, 102, 68)',
|
|
48
|
+
} as any;
|
|
49
|
+
|
|
50
|
+
const nonce = 'k0Mp1lEd';
|
|
51
|
+
|
|
52
|
+
const benchmark = await runBenchmark('CS', [
|
|
53
|
+
{
|
|
54
|
+
name: 'CS (1 array element)',
|
|
55
|
+
fn: () => {
|
|
56
|
+
renderToString(
|
|
57
|
+
<CC>
|
|
58
|
+
<CS nonce={nonce}>{[stylesStr]}</CS>
|
|
59
|
+
<span className={className} style={style}>
|
|
60
|
+
hello world
|
|
61
|
+
</span>
|
|
62
|
+
</CC>
|
|
63
|
+
);
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'CS (n array elements)',
|
|
68
|
+
fn: () => {
|
|
69
|
+
renderToString(
|
|
70
|
+
<CC>
|
|
71
|
+
<CS nonce={nonce}>{stylesArr}</CS>
|
|
72
|
+
<span className={className} style={style}>
|
|
73
|
+
hello world
|
|
74
|
+
</span>
|
|
75
|
+
</CC>
|
|
76
|
+
);
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: 'StyleArr',
|
|
81
|
+
fn: () => {
|
|
82
|
+
renderToString(
|
|
83
|
+
<CC>
|
|
84
|
+
<StyleArr nonce={nonce}>{stylesArr}</StyleArr>
|
|
85
|
+
<span className={className} style={style}>
|
|
86
|
+
hello world
|
|
87
|
+
</span>
|
|
88
|
+
</CC>
|
|
89
|
+
);
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: 'StyleStr',
|
|
94
|
+
fn: () => {
|
|
95
|
+
renderToString(
|
|
96
|
+
<CC>
|
|
97
|
+
<StyleStr nonce={nonce}>{stylesStr}</StyleStr>
|
|
98
|
+
<span className={className} style={style}>
|
|
99
|
+
hello world
|
|
100
|
+
</span>
|
|
101
|
+
</CC>
|
|
102
|
+
);
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
]);
|
|
106
|
+
|
|
107
|
+
expect(benchmark).toMatchObject({
|
|
108
|
+
fastest: expect.not.arrayContaining(['StyleStr', 'CS (n array elements)']),
|
|
109
|
+
});
|
|
110
|
+
}, 30000);
|
|
111
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { runBenchmark } from '@compiled/benchmark';
|
|
2
|
+
|
|
3
|
+
import insertRule from '../sheet';
|
|
4
|
+
|
|
5
|
+
import { createStyleSheet } from './utils/sheet';
|
|
6
|
+
|
|
7
|
+
global.document = {
|
|
8
|
+
// @ts-expect-error
|
|
9
|
+
createTextNode: () => {},
|
|
10
|
+
head: {
|
|
11
|
+
// @ts-expect-error
|
|
12
|
+
insertBefore: () => {},
|
|
13
|
+
},
|
|
14
|
+
// @ts-expect-error
|
|
15
|
+
createElement: () => ({
|
|
16
|
+
appendChild: () => {},
|
|
17
|
+
}),
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe('sheet benchmark', () => {
|
|
21
|
+
it('completes with insertRule as the fastest', async () => {
|
|
22
|
+
const rules = [
|
|
23
|
+
'._s7n4jp4b{vertical-align:top}',
|
|
24
|
+
'._1reo15vq{overflow-x:hidden}',
|
|
25
|
+
'._18m915vq{overflow-y:hidden}',
|
|
26
|
+
'._1bto1l2s{text-overflow:ellipsis}',
|
|
27
|
+
'._o5721q9c{white-space:nowrap}',
|
|
28
|
+
'._ca0qidpf{padding-top:0}',
|
|
29
|
+
'._u5f31y44{padding-right:4px}',
|
|
30
|
+
'._n3tdidpf{padding-bottom:0}',
|
|
31
|
+
'._19bv1y44{padding-left:4px}',
|
|
32
|
+
'._p12f12xx{max-width:100px}',
|
|
33
|
+
'._1bsb1osq{width:100%}',
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
const benchmark = await runBenchmark('sheet', [
|
|
37
|
+
{
|
|
38
|
+
name: 'insertRule',
|
|
39
|
+
fn: () => {
|
|
40
|
+
for (const rule of rules) {
|
|
41
|
+
insertRule(rule, {});
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: 'createStyleSheet',
|
|
47
|
+
fn: () => {
|
|
48
|
+
const sheet = createStyleSheet({});
|
|
49
|
+
|
|
50
|
+
for (const rule of rules) {
|
|
51
|
+
sheet(rule);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
expect(benchmark).toMatchObject({
|
|
58
|
+
fastest: expect.arrayContaining(['insertRule']),
|
|
59
|
+
});
|
|
60
|
+
}, 30000);
|
|
61
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React, { createContext, useContext } from 'react';
|
|
2
|
+
|
|
3
|
+
const Cache = createContext<Record<string, true> | null>(null);
|
|
4
|
+
|
|
5
|
+
export const useCache = (): Record<string, true> => {
|
|
6
|
+
return useContext(Cache) || {};
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type StyleStrProps = {
|
|
10
|
+
children: string;
|
|
11
|
+
nonce: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function StyleStr({ children, nonce }: StyleStrProps): JSX.Element | null {
|
|
15
|
+
const inserted = useCache();
|
|
16
|
+
|
|
17
|
+
// The following code will not exist in the browser bundle.
|
|
18
|
+
const sheets = children.split('.');
|
|
19
|
+
let toInsert = '';
|
|
20
|
+
|
|
21
|
+
for (let i = 0; i < sheets.length; i++) {
|
|
22
|
+
const sheet = sheets[i];
|
|
23
|
+
if (inserted[sheet]) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
toInsert += sheet;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!toInsert) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return <style nonce={nonce}>{toInsert}</style>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type StyleArrProps = {
|
|
37
|
+
children: string[];
|
|
38
|
+
nonce: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export function StyleArr({ children: sheets, nonce }: StyleArrProps): JSX.Element | null {
|
|
42
|
+
const inserted = useCache();
|
|
43
|
+
|
|
44
|
+
// The following code will not exist in the browser bundle.
|
|
45
|
+
let toInsert = '';
|
|
46
|
+
|
|
47
|
+
for (let i = 0; i < sheets.length; i++) {
|
|
48
|
+
const sheet = sheets[i];
|
|
49
|
+
if (inserted[sheet]) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
toInsert += sheet;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!toInsert) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return <style nonce={nonce}>{toInsert}</style>;
|
|
60
|
+
}
|