@compiled/react 0.10.4 → 0.11.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 +11 -5
- package/dist/browser/class-names/index.js.flow +29 -20
- package/dist/browser/class-names/index.js.map +1 -1
- package/dist/browser/css/index.d.ts +3 -3
- package/dist/browser/css/index.js.flow +24 -23
- package/dist/browser/css/index.js.map +1 -1
- package/dist/browser/index.d.ts +2 -3
- package/dist/browser/index.js.flow +4 -7
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/jsx/jsx-local-namespace.d.ts +2 -2
- package/dist/browser/keyframes/index.d.ts +1 -1
- package/dist/browser/keyframes/index.js.flow +25 -31
- package/dist/browser/runtime/ax.js.flow +1 -1
- package/dist/browser/runtime/cache.js.flow +1 -1
- package/dist/browser/runtime/css-custom-property.js +1 -1
- package/dist/browser/runtime/css-custom-property.js.flow +1 -1
- package/dist/browser/runtime/css-custom-property.js.map +1 -1
- package/dist/browser/runtime/dev-warnings.js.flow +1 -1
- package/dist/browser/runtime/index.js.flow +1 -1
- package/dist/browser/runtime/{is-node.d.ts → is-server-environment.d.ts} +2 -2
- package/dist/browser/runtime/is-server-environment.js +31 -0
- package/dist/{cjs/runtime/is-node.js.flow → browser/runtime/is-server-environment.js.flow} +4 -4
- package/dist/browser/runtime/is-server-environment.js.map +1 -0
- package/dist/browser/runtime/sheet.js.flow +1 -1
- package/dist/browser/runtime/style-cache.js +1 -1
- 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 +1 -1
- 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 +2 -2
- package/dist/browser/runtime.js.flow +1 -1
- package/dist/browser/styled/index.d.ts +10 -23
- package/dist/browser/styled/index.js.flow +45 -46
- package/dist/browser/styled/index.js.map +1 -1
- package/dist/browser/types.d.ts +9 -5
- package/dist/browser/types.js.flow +13 -10
- package/dist/browser/utils/error.js.flow +1 -1
- package/dist/cjs/class-names/index.d.ts +11 -5
- package/dist/cjs/class-names/index.js.flow +29 -20
- package/dist/cjs/class-names/index.js.map +1 -1
- package/dist/cjs/css/index.d.ts +3 -3
- package/dist/cjs/css/index.js.flow +24 -23
- package/dist/cjs/css/index.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -3
- package/dist/cjs/index.js.flow +4 -7
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/jsx/jsx-local-namespace.d.ts +2 -2
- package/dist/cjs/keyframes/index.d.ts +1 -1
- package/dist/cjs/keyframes/index.js.flow +25 -31
- package/dist/cjs/runtime/ax.js.flow +1 -1
- package/dist/cjs/runtime/cache.js.flow +1 -1
- package/dist/cjs/runtime/css-custom-property.js +1 -1
- package/dist/cjs/runtime/css-custom-property.js.flow +1 -1
- package/dist/cjs/runtime/css-custom-property.js.map +1 -1
- package/dist/cjs/runtime/dev-warnings.js.flow +1 -1
- package/dist/cjs/runtime/index.js.flow +1 -1
- package/dist/{esm/runtime/is-node.d.ts → cjs/runtime/is-server-environment.d.ts} +2 -2
- package/dist/cjs/runtime/is-server-environment.js +35 -0
- package/dist/{esm/runtime/is-node.js.flow → cjs/runtime/is-server-environment.js.flow} +4 -4
- package/dist/cjs/runtime/is-server-environment.js.map +1 -0
- package/dist/cjs/runtime/sheet.js.flow +1 -1
- package/dist/cjs/runtime/style-cache.js +5 -5
- 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 +2 -2
- package/dist/cjs/runtime.js.flow +1 -1
- package/dist/cjs/styled/index.d.ts +10 -23
- package/dist/cjs/styled/index.js.flow +45 -46
- package/dist/cjs/styled/index.js.map +1 -1
- package/dist/cjs/types.d.ts +9 -5
- package/dist/cjs/types.js.flow +13 -10
- package/dist/cjs/utils/error.js.flow +1 -1
- package/dist/esm/class-names/index.d.ts +11 -5
- package/dist/esm/class-names/index.js.flow +29 -20
- package/dist/esm/class-names/index.js.map +1 -1
- package/dist/esm/css/index.d.ts +3 -3
- package/dist/esm/css/index.js.flow +24 -23
- package/dist/esm/css/index.js.map +1 -1
- package/dist/esm/index.d.ts +2 -3
- package/dist/esm/index.js.flow +4 -7
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/jsx/jsx-local-namespace.d.ts +2 -2
- package/dist/esm/keyframes/index.d.ts +1 -1
- package/dist/esm/keyframes/index.js.flow +25 -31
- package/dist/esm/runtime/ax.js.flow +1 -1
- package/dist/esm/runtime/cache.js.flow +1 -1
- package/dist/esm/runtime/css-custom-property.js +1 -1
- package/dist/esm/runtime/css-custom-property.js.flow +1 -1
- package/dist/esm/runtime/css-custom-property.js.map +1 -1
- package/dist/esm/runtime/dev-warnings.js.flow +1 -1
- package/dist/esm/runtime/index.js.flow +1 -1
- package/dist/{cjs/runtime/is-node.d.ts → esm/runtime/is-server-environment.d.ts} +2 -2
- package/dist/esm/runtime/is-server-environment.js +31 -0
- package/dist/{browser/runtime/is-node.js.flow → esm/runtime/is-server-environment.js.flow} +4 -4
- package/dist/esm/runtime/is-server-environment.js.map +1 -0
- package/dist/esm/runtime/sheet.js.flow +1 -1
- package/dist/esm/runtime/style-cache.js +5 -5
- 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 +2 -2
- package/dist/esm/runtime.js.flow +1 -1
- package/dist/esm/styled/index.d.ts +10 -23
- package/dist/esm/styled/index.js.flow +45 -46
- package/dist/esm/styled/index.js.map +1 -1
- package/dist/esm/types.d.ts +9 -5
- package/dist/esm/types.js.flow +13 -10
- package/dist/esm/utils/error.js.flow +1 -1
- package/package.json +5 -5
- package/src/__tests__/browser.test.tsx +4 -0
- package/src/__tests__/server-side-hydrate.test.tsx +2 -2
- package/src/class-names/__tests__/types.test.js.flow +10 -3
- package/src/class-names/index.js.flow +29 -20
- package/src/class-names/index.ts +15 -9
- package/src/css/__tests__/types.test.js.flow +25 -0
- package/src/css/index.js.flow +24 -23
- package/src/css/index.ts +9 -14
- package/src/index.js.flow +4 -7
- package/src/index.ts +3 -4
- package/src/jsx/jsx-local-namespace.ts +2 -2
- package/src/keyframes/__tests__/index.test.tsx +4 -0
- package/src/keyframes/index.js.flow +25 -31
- package/src/keyframes/index.ts +1 -1
- package/src/runtime/__tests__/css-custom-property.test.ts +2 -2
- package/src/runtime/__tests__/style.test.tsx +4 -0
- package/src/runtime/ax.js.flow +1 -1
- package/src/runtime/cache.js.flow +1 -1
- package/src/runtime/css-custom-property.js.flow +1 -1
- package/src/runtime/css-custom-property.ts +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 → is-server-environment.js.flow} +4 -4
- package/src/runtime/is-server-environment.ts +29 -0
- package/src/runtime/sheet.js.flow +1 -1
- package/src/runtime/style-cache.js.flow +1 -1
- package/src/runtime/style-cache.tsx +5 -5
- package/src/runtime/style.js.flow +1 -1
- package/src/runtime/style.tsx +2 -2
- package/src/runtime/types.js.flow +2 -2
- package/src/runtime.js.flow +1 -1
- package/src/styled/__tests__/index.test.tsx +1 -1
- package/src/styled/__tests__/types.test.js.flow +65 -11
- package/src/styled/index.js.flow +45 -46
- package/src/styled/index.ts +21 -39
- package/src/types.js.flow +13 -10
- package/src/types.ts +19 -11
- package/src/utils/error.js.flow +1 -1
- package/dist/browser/runtime/is-node.js +0 -16
- package/dist/browser/runtime/is-node.js.map +0 -1
- package/dist/cjs/runtime/is-node.js +0 -20
- package/dist/cjs/runtime/is-node.js.map +0 -1
- package/dist/esm/runtime/is-node.js +0 -16
- package/dist/esm/runtime/is-node.js.map +0 -1
- package/src/runtime/is-node.ts +0 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compiled/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "A familiar and performant compile time CSS-in-JS library for React.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compiled",
|
|
@@ -72,13 +72,13 @@
|
|
|
72
72
|
"jsx-dev-runtime"
|
|
73
73
|
],
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"csstype": "^3.0
|
|
75
|
+
"csstype": "^3.1.0"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@compiled/benchmark": "^1.0.1",
|
|
79
|
-
"@testing-library/react": "^12.1.
|
|
80
|
-
"@types/jsdom": "^16.2.
|
|
81
|
-
"@types/react-dom": "^17.0.
|
|
79
|
+
"@testing-library/react": "^12.1.5",
|
|
80
|
+
"@types/jsdom": "^16.2.15",
|
|
81
|
+
"@types/react-dom": "^17.0.17",
|
|
82
82
|
"jsdom": "^19.0.0",
|
|
83
83
|
"react": "^17.0.2",
|
|
84
84
|
"react-dom": "^17.0.2"
|
|
@@ -3,6 +3,10 @@ import { styled } from '@compiled/react';
|
|
|
3
3
|
import { render } from '@testing-library/react';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
|
|
6
|
+
jest.mock('../runtime/is-server-environment', () => ({
|
|
7
|
+
isServerEnvironment: () => false,
|
|
8
|
+
}));
|
|
9
|
+
|
|
6
10
|
describe('browser', () => {
|
|
7
11
|
beforeEach(() => {
|
|
8
12
|
// Reset style tags in head before each test so that it will remove styles
|
|
@@ -3,8 +3,8 @@ import { hydrate } from 'react-dom';
|
|
|
3
3
|
|
|
4
4
|
import { CC, CS } from '../runtime';
|
|
5
5
|
|
|
6
|
-
jest.mock('../runtime/is-
|
|
7
|
-
|
|
6
|
+
jest.mock('../runtime/is-server-environment', () => ({
|
|
7
|
+
isServerEnvironment: () => false,
|
|
8
8
|
}));
|
|
9
9
|
|
|
10
10
|
describe('server side hydrate', () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @flow strict-local
|
|
2
2
|
import React, { type Node } from 'react';
|
|
3
|
-
import { ClassNames, type
|
|
3
|
+
import { ClassNames, type CssType } from '@compiled/react';
|
|
4
4
|
|
|
5
5
|
// Object call expression
|
|
6
6
|
({ children }: { children: Node }): React$Element<typeof ClassNames> => (
|
|
@@ -23,6 +23,13 @@ import { ClassNames, type CssFunction } from '@compiled/react';
|
|
|
23
23
|
|
|
24
24
|
// Array
|
|
25
25
|
({ children }: { children: Node }): React$Element<typeof ClassNames> => {
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
return (
|
|
27
|
+
<ClassNames>
|
|
28
|
+
{({ css }) => (
|
|
29
|
+
<span className={css(([{ fontSize: 12 }, `font-size: 12px`]: CssType<void>[]))}>
|
|
30
|
+
{children}
|
|
31
|
+
</span>
|
|
32
|
+
)}
|
|
33
|
+
</ClassNames>
|
|
34
|
+
);
|
|
28
35
|
};
|
|
@@ -1,45 +1,54 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flowtype definitions for index
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.
|
|
4
|
+
* Flowgen v1.17.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
7
|
import type { Node } from 'react';
|
|
8
|
-
import type {
|
|
9
|
-
export type
|
|
10
|
-
export
|
|
8
|
+
import type { CssType, CssFunction } from '../types';
|
|
9
|
+
export type ObjectInterpolation<TProps> = CssType<TProps> | CssType<TProps>[];
|
|
10
|
+
export type TemplateStringsInterpolation<TProps> = CssFunction<TProps> | CssFunction<TProps>[];
|
|
11
|
+
declare interface CssSignature<TProps> {
|
|
12
|
+
(...interpolations: ObjectInterpolation<TProps>[]): string;
|
|
13
|
+
(
|
|
14
|
+
template: $ReadOnlyArray<string>,
|
|
15
|
+
...interpolations: TemplateStringsInterpolation<TProps>[]
|
|
16
|
+
): string;
|
|
17
|
+
}
|
|
18
|
+
export interface ClassNamesProps<TProps> {
|
|
11
19
|
children: (opts: {
|
|
12
|
-
css:
|
|
13
|
-
style:
|
|
14
|
-
[key: string]: string,
|
|
15
|
-
...
|
|
16
|
-
},
|
|
20
|
+
css: CssSignature<TProps>,
|
|
21
|
+
style: $Shape<CSSStyleDeclaration>,
|
|
17
22
|
...
|
|
18
23
|
}) => Node;
|
|
19
24
|
}
|
|
20
25
|
/**
|
|
21
|
-
*
|
|
26
|
+
* ## Class names
|
|
22
27
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
28
|
+
* Use a component where styles are not necessarily used on a JSX element.
|
|
29
|
+
* For further details [read the documentation](https://compiledcssinjs.com/docs/api-class-names).
|
|
30
|
+
*
|
|
31
|
+
* ### Style with objects
|
|
32
|
+
* @example ```
|
|
25
33
|
* <ClassNames>
|
|
26
34
|
* {({ css, style }) => children({ className: css({ fontSize: 12 }) })}
|
|
27
35
|
* </ClassNames>
|
|
36
|
+
* ```
|
|
28
37
|
*
|
|
29
|
-
*
|
|
38
|
+
* ### Style with template literals
|
|
39
|
+
* @example ```
|
|
30
40
|
* <ClassNames>
|
|
31
41
|
* {({ css, style }) => children({ className: css`font-size: 12px;` })}
|
|
32
42
|
* </ClassNames>
|
|
43
|
+
* ```
|
|
33
44
|
*
|
|
34
|
-
*
|
|
45
|
+
* ### Compose styles with arrays
|
|
46
|
+
* @example ```
|
|
35
47
|
* <ClassNames>
|
|
36
48
|
* {({ css, style }) =>
|
|
37
|
-
* children({ className: css([{ fontSize: 12 }, `font-size: 12px`]) })}
|
|
49
|
+
* children({ className: css([{ fontSize: 12 }, css`font-size: 12px`]) })}
|
|
38
50
|
* </ClassNames>
|
|
39
51
|
* ```
|
|
40
|
-
*
|
|
41
|
-
* For more help, read the docs:
|
|
42
|
-
* https://compiledcssinjs.com/docs/api-class-names
|
|
43
|
-
* @param props
|
|
44
52
|
*/
|
|
45
|
-
declare export function ClassNames(
|
|
53
|
+
declare export function ClassNames<TProps>(x: ClassNamesProps<TProps>): React$Node;
|
|
54
|
+
declare export {};
|
package/src/class-names/index.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import type { ReactNode, CSSProperties } from 'react';
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { CssType, CssFunction } from '../types';
|
|
4
4
|
import { createSetupError } from '../utils/error';
|
|
5
5
|
|
|
6
|
-
export type
|
|
6
|
+
export type ObjectInterpolation<TProps> = CssType<TProps> | CssType<TProps>[];
|
|
7
|
+
export type TemplateStringsInterpolation<TProps> = CssFunction<TProps> | CssFunction<TProps>[];
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
interface CssSignature<TProps> {
|
|
10
|
+
(...interpolations: ObjectInterpolation<TProps>[]): string;
|
|
11
|
+
(
|
|
12
|
+
template: TemplateStringsArray,
|
|
13
|
+
...interpolations: TemplateStringsInterpolation<TProps>[]
|
|
14
|
+
): string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface ClassNamesProps<TProps> {
|
|
18
|
+
children: (opts: { css: CssSignature<TProps>; style: CSSProperties }) => ReactNode;
|
|
13
19
|
}
|
|
14
20
|
|
|
15
21
|
/**
|
|
@@ -46,8 +52,8 @@ export interface ClassNamesProps {
|
|
|
46
52
|
* </ClassNames>
|
|
47
53
|
* ```
|
|
48
54
|
*/
|
|
49
|
-
export function ClassNames({ children }: ClassNamesProps): JSX.Element;
|
|
55
|
+
export function ClassNames<TProps = void>({ children }: ClassNamesProps<TProps>): JSX.Element;
|
|
50
56
|
|
|
51
|
-
export function ClassNames(_props: ClassNamesProps): JSX.Element {
|
|
57
|
+
export function ClassNames<TProps = void>(_props: ClassNamesProps<TProps>): JSX.Element {
|
|
52
58
|
throw createSetupError();
|
|
53
59
|
}
|
|
@@ -15,3 +15,28 @@ import { css } from '@compiled/react';
|
|
|
15
15
|
const styles = css({ color: 'red' });
|
|
16
16
|
return <div css={styles}>red text</div>;
|
|
17
17
|
};
|
|
18
|
+
|
|
19
|
+
// Object call with function call
|
|
20
|
+
(): React$Element<'div'> => {
|
|
21
|
+
const styles = css({
|
|
22
|
+
backgroundColor: token('elevation.surface', 'white'),
|
|
23
|
+
zIndex: layers.modal(),
|
|
24
|
+
});
|
|
25
|
+
return <div css={styles}>red text</div>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// Media query selector
|
|
29
|
+
css({
|
|
30
|
+
/* Style only for Google Chrome */
|
|
31
|
+
'@media screen and (-webkit-min-device-pixel-ratio: 0)': {
|
|
32
|
+
wordBreak: 'break-word',
|
|
33
|
+
},
|
|
34
|
+
/* Style only for Safari */
|
|
35
|
+
'@media screen and (-webkit-transition)': {
|
|
36
|
+
wordBreak: 'break-word',
|
|
37
|
+
},
|
|
38
|
+
/* Style only for Mozilla Firefox */
|
|
39
|
+
'@-moz-document url-prefix()': {
|
|
40
|
+
overflowWrap: 'anywhere',
|
|
41
|
+
},
|
|
42
|
+
});
|
package/src/css/index.js.flow
CHANGED
|
@@ -1,35 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flowtype definitions for index
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.
|
|
4
|
+
* Flowgen v1.17.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
|
-
import type {
|
|
7
|
+
import type { CSSProps, CssObject, CssFunction } from '../types';
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* ## CSS
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
* css
|
|
13
|
-
* ```
|
|
11
|
+
* Define styles that are statically typed and useable with other Compiled APIs.
|
|
12
|
+
* For further details [read the documentation](https://compiledcssinjs.com/docs/api-css).
|
|
14
13
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
declare export default function css<T>(
|
|
21
|
-
_css: $ReadOnlyArray<string>,
|
|
22
|
-
..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
|
|
23
|
-
): CSSProps;
|
|
24
|
-
/**
|
|
25
|
-
* Create styles that can be re-used between components with an object
|
|
14
|
+
* ### Style with objects
|
|
15
|
+
* @example ```
|
|
16
|
+
* const redText = css({
|
|
17
|
+
* color: 'red',
|
|
18
|
+
* });
|
|
26
19
|
*
|
|
20
|
+
* <div css={redText} />
|
|
27
21
|
* ```
|
|
28
|
-
* css({ color: 'red' });
|
|
29
|
-
* ```
|
|
30
22
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
23
|
+
* ### Style with template literals
|
|
24
|
+
* @example ```
|
|
25
|
+
* const redText = css`
|
|
26
|
+
* color: red;
|
|
27
|
+
* `;
|
|
28
|
+
*
|
|
29
|
+
* <div css={redText} />
|
|
30
|
+
* ```
|
|
34
31
|
*/
|
|
35
|
-
declare export default function css(
|
|
32
|
+
declare export default function css<TProps>(
|
|
33
|
+
styles: $ReadOnlyArray<string>,
|
|
34
|
+
...interpolations: CssFunction<TProps>[]
|
|
35
|
+
): CSSProps<TProps>;
|
|
36
|
+
declare export default function css<T>(styles: CssObject<T> | CssObject<T>[]): CSSProps<T>;
|
package/src/css/index.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
/* eslint-disable import/export */
|
|
2
2
|
|
|
3
|
-
import type {
|
|
4
|
-
AnyKeyCssProps,
|
|
5
|
-
BasicTemplateInterpolations,
|
|
6
|
-
CSSProps,
|
|
7
|
-
FunctionInterpolation,
|
|
8
|
-
} from '../types';
|
|
3
|
+
import type { CSSProps, CssObject, CssFunction } from '../types';
|
|
9
4
|
import { createSetupError } from '../utils/error';
|
|
10
5
|
|
|
11
6
|
/**
|
|
@@ -36,16 +31,16 @@ import { createSetupError } from '../utils/error';
|
|
|
36
31
|
* <div css={redText} />
|
|
37
32
|
* ```
|
|
38
33
|
*/
|
|
39
|
-
export default function css<
|
|
34
|
+
export default function css<TProps = unknown>(
|
|
40
35
|
styles: TemplateStringsArray,
|
|
41
|
-
...interpolations:
|
|
42
|
-
): CSSProps
|
|
36
|
+
...interpolations: CssFunction<TProps>[]
|
|
37
|
+
): CSSProps<TProps>;
|
|
43
38
|
|
|
44
|
-
export default function css(styles:
|
|
39
|
+
export default function css<T = unknown>(styles: CssObject<T> | CssObject<T>[]): CSSProps<T>;
|
|
45
40
|
|
|
46
|
-
export default function css<T =
|
|
47
|
-
_styles: TemplateStringsArray |
|
|
48
|
-
..._interpolations:
|
|
49
|
-
): CSSProps {
|
|
41
|
+
export default function css<T = unknown>(
|
|
42
|
+
_styles: TemplateStringsArray | CssObject<T> | CssObject<T>[],
|
|
43
|
+
..._interpolations: CssFunction[]
|
|
44
|
+
): CSSProps<T> {
|
|
50
45
|
throw createSetupError();
|
|
51
46
|
}
|
package/src/index.js.flow
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Flowtype definitions for runtime
|
|
2
|
+
* Flowtype definitions for index
|
|
5
3
|
* Generated by Flowgen from a Typescript Definition
|
|
6
|
-
* Flowgen v1.
|
|
4
|
+
* Flowgen v1.17.0
|
|
7
5
|
* @flow
|
|
8
6
|
*/
|
|
9
|
-
import type { CSSProps,
|
|
7
|
+
import type { CssFunction, CSSProps, CssType } from './types';
|
|
8
|
+
export type { CSSProps, CssFunction, CssType };
|
|
10
9
|
declare export { keyframes } from './keyframes';
|
|
11
10
|
declare export { styled } from './styled';
|
|
12
11
|
declare export { ClassNames } from './class-names';
|
|
13
12
|
declare export { default as css } from './css';
|
|
14
|
-
export type { CssFunction, CSSProps };
|
|
15
|
-
export type { CssObject } from './styled';
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { createElement } from 'react';
|
|
2
2
|
|
|
3
3
|
import type { CompiledJSX } from './jsx/jsx-local-namespace';
|
|
4
|
-
import type { CssFunction, CSSProps } from './types';
|
|
4
|
+
import type { CssFunction, CSSProps, CssType } from './types';
|
|
5
|
+
|
|
6
|
+
export type { CSSProps, CssFunction, CssType };
|
|
5
7
|
|
|
6
8
|
export { keyframes } from './keyframes';
|
|
7
9
|
export { styled } from './styled';
|
|
@@ -12,9 +14,6 @@ export { default as css } from './css';
|
|
|
12
14
|
// Compiled currently doesn't define its own and uses this purely to enable a local jsx namespace.
|
|
13
15
|
export const jsx = createElement;
|
|
14
16
|
|
|
15
|
-
export type { CssFunction, CSSProps };
|
|
16
|
-
export type { CssObject } from './styled';
|
|
17
|
-
|
|
18
17
|
export namespace jsx {
|
|
19
18
|
export namespace JSX {
|
|
20
19
|
export type Element = CompiledJSX.Element;
|
|
@@ -41,7 +41,7 @@ type WithConditionalCSSProp<TProps> = 'className' extends keyof TProps
|
|
|
41
41
|
* />
|
|
42
42
|
* ```
|
|
43
43
|
*/
|
|
44
|
-
css?: CssFunction | CssFunction[];
|
|
44
|
+
css?: CssFunction<void> | CssFunction<void>[];
|
|
45
45
|
}
|
|
46
46
|
: // eslint-disable-next-line @typescript-eslint/ban-types
|
|
47
47
|
{}
|
|
@@ -69,7 +69,7 @@ export namespace CompiledJSX {
|
|
|
69
69
|
export type IntrinsicClassAttributes<T> = ReactJSXIntrinsicClassAttributes<T>;
|
|
70
70
|
export type IntrinsicElements = {
|
|
71
71
|
[K in keyof ReactJSXIntrinsicElements]: ReactJSXIntrinsicElements[K] & {
|
|
72
|
-
css?: CssFunction | CssFunction[];
|
|
72
|
+
css?: CssFunction<void> | CssFunction<void>[];
|
|
73
73
|
};
|
|
74
74
|
};
|
|
75
75
|
}
|
|
@@ -16,6 +16,10 @@ const getKeyframe = (name: string) => {
|
|
|
16
16
|
.join('\n');
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
+
jest.mock('../../runtime/is-server-environment', () => ({
|
|
20
|
+
isServerEnvironment: () => false,
|
|
21
|
+
}));
|
|
22
|
+
|
|
19
23
|
describe('keyframes', () => {
|
|
20
24
|
beforeAll(() => {
|
|
21
25
|
process.env.CACHE = 'false';
|
|
@@ -1,33 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flowtype definitions for index
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.
|
|
4
|
+
* Flowgen v1.17.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
7
|
import type { BasicTemplateInterpolations, CSSProps } from '../types';
|
|
8
|
-
export type KeyframeSteps = string | { [key: string]: CSSProps
|
|
8
|
+
export type KeyframeSteps = string | { [key: string]: CSSProps<void> };
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* ## Keyframes
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
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:
|
|
12
|
+
* Define keyframes to be used in a [CSS animation](https://developer.mozilla.org/en-US/docs/Web/CSS/animation).
|
|
13
|
+
* For further details [read the API documentation](https://compiledcssinjs.com/docs/api-keyframes).
|
|
27
14
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* ```
|
|
15
|
+
* ### Style with objects
|
|
16
|
+
* @example ```
|
|
31
17
|
* const fadeOut = keyframes({
|
|
32
18
|
* from: {
|
|
33
19
|
* opacity: 1,
|
|
@@ -36,19 +22,27 @@ declare export function keyframes(
|
|
|
36
22
|
* opacity: 0,
|
|
37
23
|
* },
|
|
38
24
|
* });
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* 2. A string
|
|
42
25
|
*
|
|
43
|
-
*
|
|
44
|
-
* const fadeOut = keyframes('from { opacity: 1; } to { opacity: 0; }');
|
|
26
|
+
* <div css={{ animation: `${fadeOut} 2s` }} />
|
|
45
27
|
* ```
|
|
46
28
|
*
|
|
47
|
-
*
|
|
29
|
+
* ### Style with template literals
|
|
30
|
+
* @example ```
|
|
31
|
+
* const fadeOut = keyframes`
|
|
32
|
+
* from {
|
|
33
|
+
* opacity: 1;
|
|
34
|
+
* }
|
|
48
35
|
*
|
|
36
|
+
* to {
|
|
37
|
+
* opacity: 0;
|
|
38
|
+
* }
|
|
39
|
+
* `;
|
|
40
|
+
*
|
|
41
|
+
* <div css={{ animation: `${fadeOut} 2s` }} />
|
|
49
42
|
* ```
|
|
50
|
-
* const fadeOut = keyframes(`from { opacity: 1; } to { opacity: 0; }`);
|
|
51
|
-
* ```
|
|
52
|
-
* @param _steps The waypoints along the animation sequence
|
|
53
43
|
*/
|
|
54
|
-
declare export function keyframes(
|
|
44
|
+
declare export function keyframes(steps: KeyframeSteps): string;
|
|
45
|
+
declare export function keyframes(
|
|
46
|
+
strings: $ReadOnlyArray<string>,
|
|
47
|
+
...interpolations: BasicTemplateInterpolations[]
|
|
48
|
+
): string;
|
package/src/keyframes/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BasicTemplateInterpolations, CSSProps } from '../types';
|
|
2
2
|
import { createSetupError } from '../utils/error';
|
|
3
3
|
|
|
4
|
-
export type KeyframeSteps = string | Record<string, CSSProps
|
|
4
|
+
export type KeyframeSteps = string | Record<string, CSSProps<void>>;
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* ## Keyframes
|
|
@@ -4,13 +4,13 @@ describe('interpolation', () => {
|
|
|
4
4
|
it('should return an empty CSS comment when undefined', () => {
|
|
5
5
|
const actual = interpolation(undefined, undefined, undefined);
|
|
6
6
|
|
|
7
|
-
expect(actual).toEqual('var(
|
|
7
|
+
expect(actual).toEqual('var(--c-, )');
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
it('should return an empty CSS comment when null', () => {
|
|
11
11
|
const actual = interpolation(null, undefined, undefined);
|
|
12
12
|
|
|
13
|
-
expect(actual).toEqual('var(
|
|
13
|
+
expect(actual).toEqual('var(--c-, )');
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
it('should pass through the value if there are no suffix prefix', () => {
|
|
@@ -2,6 +2,10 @@ import { render } from '@testing-library/react';
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import type { ComponentType } from 'react';
|
|
4
4
|
|
|
5
|
+
jest.mock('../is-server-environment', () => ({
|
|
6
|
+
isServerEnvironment: () => false,
|
|
7
|
+
}));
|
|
8
|
+
|
|
5
9
|
describe('<Style />', () => {
|
|
6
10
|
let consoleErrorSpy: jest.SpyInstance;
|
|
7
11
|
|
package/src/runtime/ax.js.flow
CHANGED
|
@@ -27,5 +27,5 @@ export default function cssCustomPropertyValue(
|
|
|
27
27
|
// Currently React trims these values so we can't use a space " " to block the value.
|
|
28
28
|
// Instead we use a CSS variable that doesn't exist which falls back to " ".
|
|
29
29
|
// Bug raised here: https://github.com/facebook/react/issues/20497
|
|
30
|
-
return 'var(
|
|
30
|
+
return 'var(--c-, )';
|
|
31
31
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Flowtype definitions for is-
|
|
2
|
+
* Flowtype definitions for is-server-environment
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.
|
|
4
|
+
* Flowgen v1.17.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
* When using this it will remove any node code from the browser bundle - for example:
|
|
12
12
|
*
|
|
13
13
|
* ```js
|
|
14
|
-
* if (
|
|
14
|
+
* if (isServerEnvironment()) {
|
|
15
15
|
* // This code will be removed from the browser bundle
|
|
16
16
|
* }
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
|
-
declare export var
|
|
19
|
+
declare export var isServerEnvironment: () => boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @see https://github.com/jsdom/jsdom/releases/tag/12.0.0
|
|
3
|
+
* @see https://github.com/jsdom/jsdom/issues/1537
|
|
4
|
+
*/
|
|
5
|
+
const isJsDomEnvironment = () =>
|
|
6
|
+
window.name === 'nodejs' ||
|
|
7
|
+
navigator.userAgent.includes('Node.js') ||
|
|
8
|
+
navigator.userAgent.includes('jsdom');
|
|
9
|
+
/**
|
|
10
|
+
* Returns `true` when inside a node environment,
|
|
11
|
+
* else `false`.
|
|
12
|
+
*
|
|
13
|
+
* When using this it will remove any node code from the browser bundle - for example:
|
|
14
|
+
*
|
|
15
|
+
* ```js
|
|
16
|
+
* if (isServerEnvironment()) {
|
|
17
|
+
* // This code will be removed from the browser bundle
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export const isServerEnvironment = (): boolean => {
|
|
22
|
+
if (typeof process !== 'undefined' && process.versions != null && process.versions.node != null) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (isJsDomEnvironment()) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
};
|