@compiled/react 0.10.4 → 0.11.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/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.flow +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.flow +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.flow +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 +4 -4
- 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__/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/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
|
@@ -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
|
|
@@ -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
|
@@ -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
|
+
};
|
|
@@ -2,16 +2,16 @@ import * as React from 'react';
|
|
|
2
2
|
import { createContext, useContext } from 'react';
|
|
3
3
|
|
|
4
4
|
import { isCacheDisabled } from './cache';
|
|
5
|
-
import {
|
|
5
|
+
import { isServerEnvironment } from './is-server-environment';
|
|
6
6
|
import type { ProviderComponent, UseCacheHook } from './types';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Cache to hold already used styles.
|
|
10
10
|
* React Context on the server - singleton object on the client.
|
|
11
11
|
*/
|
|
12
|
-
const Cache: any =
|
|
12
|
+
const Cache: any = isServerEnvironment() ? createContext<Record<string, true> | null>(null) : {};
|
|
13
13
|
|
|
14
|
-
if (!
|
|
14
|
+
if (!isServerEnvironment()) {
|
|
15
15
|
/**
|
|
16
16
|
* Iterates through all found style elements generated when server side rendering.
|
|
17
17
|
*
|
|
@@ -32,7 +32,7 @@ export const useCache: UseCacheHook = () => {
|
|
|
32
32
|
return {};
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
if (
|
|
35
|
+
if (isServerEnvironment()) {
|
|
36
36
|
// On the server we use React Context to we don't leak the cache between SSR calls.
|
|
37
37
|
// During runtime this hook isn't conditionally called - it is at build time that the flow gets decided.
|
|
38
38
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
@@ -50,7 +50,7 @@ export const useCache: UseCacheHook = () => {
|
|
|
50
50
|
* On the browser this turns into a fragment with no React Context.
|
|
51
51
|
*/
|
|
52
52
|
const StyleCacheProvider: ProviderComponent = (props) => {
|
|
53
|
-
if (
|
|
53
|
+
if (isServerEnvironment()) {
|
|
54
54
|
// This code path isn't conditionally called at build time - safe to ignore.
|
|
55
55
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
56
56
|
const inserted = useCache();
|
package/src/runtime/style.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
3
|
import { analyzeCssInDev } from './dev-warnings';
|
|
4
|
-
import {
|
|
4
|
+
import { isServerEnvironment } from './is-server-environment';
|
|
5
5
|
import insertRule, { getStyleBucketName, styleBucketOrdering } from './sheet';
|
|
6
6
|
import { useCache } from './style-cache';
|
|
7
7
|
import type { Bucket, StyleSheetOpts } from './types';
|
|
@@ -22,7 +22,7 @@ export default function Style(props: StyleProps): JSX.Element | null {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
if (props.children.length) {
|
|
25
|
-
if (
|
|
25
|
+
if (isServerEnvironment()) {
|
|
26
26
|
const bucketedSheets: Partial<Record<Bucket, string>> = {};
|
|
27
27
|
let hasSheets = false;
|
|
28
28
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flowtype definitions for types
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.
|
|
4
|
+
* Flowgen v1.17.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
7
|
export interface StyleSheetOpts {
|
|
@@ -16,7 +16,7 @@ export interface StyleSheetOpts {
|
|
|
16
16
|
* Buckets under which we will group our stylesheets
|
|
17
17
|
*/
|
|
18
18
|
export type Bucket = '' | 'l' | 'v' | 'w' | 'f' | 'i' | 'h' | 'a' | 'm';
|
|
19
|
-
export type UseCacheHook = () => { [key: string]: true
|
|
19
|
+
export type UseCacheHook = () => { [key: string]: true };
|
|
20
20
|
export type ProviderComponent = (props: {
|
|
21
21
|
children: React$Node[] | React$Node,
|
|
22
22
|
...
|