@compiled/react 0.8.0 → 0.10.1
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 +4 -4
- 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/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/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.d.ts +0 -1
- package/dist/browser/runtime/dev-warnings.js +1 -1
- package/dist/browser/runtime/dev-warnings.js.flow +1 -2
- 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.flow +1 -1
- package/dist/browser/runtime/sheet.d.ts +1 -1
- package/dist/browser/runtime/sheet.js.flow +2 -2
- 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 +38 -13
- package/dist/browser/styled/index.js +35 -7
- package/dist/browser/styled/index.js.flow +5 -8
- package/dist/browser/styled/index.js.map +1 -1
- package/dist/browser/types.d.ts +5 -2
- package/dist/browser/types.js.flow +6 -3
- 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 +1 -27
- 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 +4 -3
- package/dist/cjs/css/index.js.flow +4 -4
- 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/index.d.ts +20 -24
- 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/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.d.ts +0 -1
- package/dist/cjs/runtime/dev-warnings.js +2 -3
- package/dist/cjs/runtime/dev-warnings.js.flow +1 -2
- 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.flow +1 -1
- package/dist/cjs/runtime/sheet.d.ts +1 -1
- package/dist/cjs/runtime/sheet.js.flow +2 -2
- 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 +2 -2
- 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 +38 -13
- package/dist/cjs/styled/index.js +35 -7
- package/dist/cjs/styled/index.js.flow +5 -8
- package/dist/cjs/styled/index.js.map +1 -1
- package/dist/cjs/types.d.ts +5 -2
- package/dist/cjs/types.js.flow +6 -3
- 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 +4 -4
- 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/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/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.d.ts +0 -1
- package/dist/esm/runtime/dev-warnings.js +1 -1
- package/dist/esm/runtime/dev-warnings.js.flow +1 -2
- 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.flow +1 -1
- package/dist/esm/runtime/sheet.d.ts +1 -1
- package/dist/esm/runtime/sheet.js.flow +2 -2
- 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 +38 -13
- package/dist/esm/styled/index.js +35 -7
- package/dist/esm/styled/index.js.flow +5 -8
- package/dist/esm/styled/index.js.map +1 -1
- package/dist/esm/types.d.ts +5 -2
- package/dist/esm/types.js.flow +6 -3
- 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 +42 -14
- 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 +3 -3
- package/src/class-names/__tests__/index.test.tsx +1 -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 +9 -3
- package/src/css/index.js.flow +4 -4
- package/src/css/index.tsx +36 -23
- 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 +39 -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/__tests__/index.test.tsx +2 -1
- 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 +1 -0
- package/src/runtime/__tests__/style.test.tsx +92 -58
- package/src/runtime/ax.js.flow +1 -1
- 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 -2
- package/src/runtime/dev-warnings.tsx +1 -1
- package/src/runtime/index.js.flow +1 -1
- package/src/runtime/is-node.js.flow +1 -1
- package/src/runtime/sheet.js.flow +2 -2
- package/src/runtime/sheet.tsx +1 -1
- package/src/runtime/style-cache.js.flow +1 -1
- package/src/runtime/style-cache.tsx +1 -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 +3 -3
- package/src/styled/index.js.flow +5 -8
- package/src/styled/index.tsx +39 -14
- package/src/types.js.flow +6 -3
- package/src/types.tsx +6 -2
- package/src/utils/error.js.flow +1 -1
- package/CHANGELOG.md +0 -68
|
@@ -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,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', () => {
|
|
@@ -30,6 +29,13 @@ describe('css prop', () => {
|
|
|
30
29
|
expect(getByText('hello world')).toHaveCompiledCss('font-size', '13px');
|
|
31
30
|
});
|
|
32
31
|
|
|
32
|
+
it('should create hover styles', () => {
|
|
33
|
+
const styles = css({ ':hover': { color: 'red' } });
|
|
34
|
+
const { getByText } = render(<div css={styles}>hello world</div>);
|
|
35
|
+
|
|
36
|
+
expect(getByText('hello world')).toHaveCompiledCss('color', 'red', { target: ':hover' });
|
|
37
|
+
});
|
|
38
|
+
|
|
33
39
|
it('should create css from tagged template expression variable', () => {
|
|
34
40
|
const style = css`
|
|
35
41
|
font-size: 13px;
|
package/src/css/index.js.flow
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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
|
-
import type { CSSProps } from '../types';
|
|
7
|
+
import type { BasicTemplateInterpolations, CSSProps, FunctionInterpolation } from '../types';
|
|
8
8
|
/**
|
|
9
9
|
* Create styles that can be re-used between components with a template literal.
|
|
10
10
|
*
|
|
@@ -17,9 +17,9 @@ import type { CSSProps } from '../types';
|
|
|
17
17
|
* @param css
|
|
18
18
|
* @param values
|
|
19
19
|
*/
|
|
20
|
-
declare export default function css(
|
|
20
|
+
declare export default function css<T>(
|
|
21
21
|
_css: $ReadOnlyArray<string>,
|
|
22
|
-
..._values: (
|
|
22
|
+
..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
|
|
23
23
|
): CSSProps;
|
|
24
24
|
/**
|
|
25
25
|
* Create styles that can be re-used between components with an object
|
package/src/css/index.tsx
CHANGED
|
@@ -1,38 +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 { CSSProps } from '../types';
|
|
3
10
|
|
|
4
11
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* ```
|
|
8
|
-
* css`color: red;`;
|
|
9
|
-
* ```
|
|
12
|
+
* ## CSS
|
|
10
13
|
*
|
|
11
|
-
*
|
|
12
|
-
* https://compiledcssinjs.com/docs/api-css
|
|
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).
|
|
13
16
|
*
|
|
14
|
-
*
|
|
15
|
-
* @param values
|
|
16
|
-
*/
|
|
17
|
-
export default function css(_css: TemplateStringsArray, ..._values: (string | number)[]): CSSProps;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Create styles that can be re-used between components with an object
|
|
17
|
+
* ### Style with objects
|
|
21
18
|
*
|
|
19
|
+
* @example
|
|
22
20
|
* ```
|
|
23
|
-
* css({
|
|
21
|
+
* const redText = css({
|
|
22
|
+
* color: 'red',
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* <div css={redText} />
|
|
24
26
|
* ```
|
|
25
27
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
+
* ### Style with template literals
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```
|
|
32
|
+
* const redText = css`
|
|
33
|
+
* color: red;
|
|
34
|
+
* `;
|
|
28
35
|
*
|
|
29
|
-
*
|
|
36
|
+
* <div css={redText} />
|
|
37
|
+
* ```
|
|
30
38
|
*/
|
|
31
|
-
export default function css
|
|
39
|
+
export default function css<T = void>(
|
|
40
|
+
styles: TemplateStringsArray,
|
|
41
|
+
...interpolations: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
|
|
42
|
+
): CSSProps;
|
|
43
|
+
|
|
44
|
+
export default function css(styles: AnyKeyCssProps<void> | CSSProps): CSSProps;
|
|
32
45
|
|
|
33
|
-
export default function css(
|
|
34
|
-
|
|
35
|
-
...
|
|
46
|
+
export default function css<T = void>(
|
|
47
|
+
_styles: TemplateStringsArray | CSSProps,
|
|
48
|
+
..._interpolations: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
|
|
36
49
|
): CSSProps {
|
|
37
50
|
throw createSetupError();
|
|
38
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
|
}
|
|
@@ -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,75 @@
|
|
|
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
|
+
* ## CSS prop
|
|
8
|
+
*
|
|
9
|
+
* Style a JSX element.
|
|
10
|
+
* For further details [read the API documentation](https://compiledcssinjs.com/docs/api-css-prop).
|
|
11
|
+
*
|
|
12
|
+
* ### Style with objects
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```
|
|
16
|
+
* import { css } from '@compiled/react';
|
|
17
|
+
*
|
|
18
|
+
* <div css={css({ fontSize: 12 })} />
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* ### Style with template literals
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```
|
|
25
|
+
* import { css } from '@compiled/react';
|
|
26
|
+
*
|
|
27
|
+
* <div css={css`color: red;`} />
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* ### Compose styles with arrays
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```
|
|
34
|
+
* import { css } from '@compiled/react';
|
|
35
|
+
*
|
|
36
|
+
* <div
|
|
37
|
+
* css={[
|
|
38
|
+
* css({ fontSize: 12 }),
|
|
39
|
+
* css`color: red;`,
|
|
40
|
+
* ]}
|
|
41
|
+
* />
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
css?: CssFunction | CssFunction[];
|
|
45
|
+
}
|
|
46
|
+
: // eslint-disable-next-line @typescript-eslint/ban-types
|
|
47
|
+
{}
|
|
48
|
+
: // eslint-disable-next-line @typescript-eslint/ban-types
|
|
49
|
+
{};
|
|
50
|
+
|
|
51
|
+
// Unpack all here to avoid infinite self-referencing when defining our own JSX namespace
|
|
52
|
+
type ReactJSXElement = JSX.Element;
|
|
53
|
+
type ReactJSXElementClass = JSX.ElementClass;
|
|
54
|
+
type ReactJSXElementAttributesProperty = JSX.ElementAttributesProperty;
|
|
55
|
+
type ReactJSXElementChildrenAttribute = JSX.ElementChildrenAttribute;
|
|
56
|
+
type ReactJSXLibraryManagedAttributes<C, P> = JSX.LibraryManagedAttributes<C, P>;
|
|
57
|
+
type ReactJSXIntrinsicAttributes = JSX.IntrinsicAttributes;
|
|
58
|
+
type ReactJSXIntrinsicClassAttributes<T> = JSX.IntrinsicClassAttributes<T>;
|
|
59
|
+
type ReactJSXIntrinsicElements = JSX.IntrinsicElements;
|
|
60
|
+
|
|
61
|
+
export namespace CompiledJSX {
|
|
62
|
+
export type Element = ReactJSXElement;
|
|
63
|
+
export type ElementClass = ReactJSXElementClass;
|
|
64
|
+
export type ElementAttributesProperty = ReactJSXElementAttributesProperty;
|
|
65
|
+
export type ElementChildrenAttribute = ReactJSXElementChildrenAttribute;
|
|
66
|
+
export type LibraryManagedAttributes<C, P> = WithConditionalCSSProp<P> &
|
|
67
|
+
ReactJSXLibraryManagedAttributes<C, P>;
|
|
68
|
+
export type IntrinsicAttributes = ReactJSXIntrinsicAttributes;
|
|
69
|
+
export type IntrinsicClassAttributes<T> = ReactJSXIntrinsicClassAttributes<T>;
|
|
70
|
+
export type IntrinsicElements = {
|
|
71
|
+
[K in keyof ReactJSXIntrinsicElements]: ReactJSXIntrinsicElements[K] & {
|
|
72
|
+
css?: CssFunction | CssFunction[];
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
}
|
|
@@ -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
|
|
package/src/keyframes/index.tsx
CHANGED
|
@@ -4,28 +4,14 @@ import { createSetupError } from '../utils/error';
|
|
|
4
4
|
export type KeyframeSteps = string | Record<string, CSSProps>;
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* ## Keyframes
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* from { opacity: 1; }
|
|
12
|
-
* to { opacity: 0; }
|
|
13
|
-
* `;
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* @param _strings The input string values
|
|
17
|
-
* @param _interpolations The arguments used in the expression
|
|
18
|
-
*/
|
|
19
|
-
export function keyframes(
|
|
20
|
-
_strings: TemplateStringsArray,
|
|
21
|
-
..._interpolations: BasicTemplateInterpolations[]
|
|
22
|
-
): string;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Create keyframes using:
|
|
9
|
+
* Define keyframes to be used in a [CSS animation](https://developer.mozilla.org/en-US/docs/Web/CSS/animation).
|
|
10
|
+
* For further details [read the API documentation](https://compiledcssinjs.com/docs/api-keyframes).
|
|
26
11
|
*
|
|
27
|
-
*
|
|
12
|
+
* ### Style with objects
|
|
28
13
|
*
|
|
14
|
+
* @example
|
|
29
15
|
* ```
|
|
30
16
|
* const fadeOut = keyframes({
|
|
31
17
|
* from: {
|
|
@@ -35,23 +21,33 @@ export function keyframes(
|
|
|
35
21
|
* opacity: 0,
|
|
36
22
|
* },
|
|
37
23
|
* });
|
|
24
|
+
*
|
|
25
|
+
* <div css={{ animation: `${fadeOut} 2s` }} />
|
|
38
26
|
* ```
|
|
39
27
|
*
|
|
40
|
-
*
|
|
28
|
+
* ### Style with template literals
|
|
41
29
|
*
|
|
30
|
+
* @example
|
|
42
31
|
* ```
|
|
43
|
-
* const fadeOut = keyframes
|
|
44
|
-
*
|
|
32
|
+
* const fadeOut = keyframes`
|
|
33
|
+
* from {
|
|
34
|
+
* opacity: 1;
|
|
35
|
+
* }
|
|
45
36
|
*
|
|
46
|
-
*
|
|
37
|
+
* to {
|
|
38
|
+
* opacity: 0;
|
|
39
|
+
* }
|
|
40
|
+
* `;
|
|
47
41
|
*
|
|
42
|
+
* <div css={{ animation: `${fadeOut} 2s` }} />
|
|
48
43
|
* ```
|
|
49
|
-
* const fadeOut = keyframes(`from { opacity: 1; } to { opacity: 0; }`);
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* @param _steps The waypoints along the animation sequence
|
|
53
44
|
*/
|
|
54
|
-
export function keyframes(
|
|
45
|
+
export function keyframes(steps: KeyframeSteps): string;
|
|
46
|
+
|
|
47
|
+
export function keyframes(
|
|
48
|
+
strings: TemplateStringsArray,
|
|
49
|
+
...interpolations: BasicTemplateInterpolations[]
|
|
50
|
+
): string;
|
|
55
51
|
|
|
56
52
|
export function keyframes(
|
|
57
53
|
_stringsOrSteps: TemplateStringsArray | KeyframeSteps,
|
|
@@ -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
|
+
});
|