@compiled/react 0.10.2 → 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-dev-runtime.js.map +1 -1
- package/dist/browser/jsx/jsx-local-namespace.d.ts +2 -2
- package/dist/browser/jsx/jsx-local-namespace.js.map +1 -1
- package/dist/browser/jsx/jsx-runtime.js.map +1 -1
- package/dist/browser/keyframes/__fixtures__/index.js.map +1 -1
- package/dist/browser/keyframes/index.d.ts +1 -1
- package/dist/browser/keyframes/index.js.flow +25 -31
- package/dist/browser/keyframes/index.js.map +1 -1
- package/dist/browser/runtime/ax.js.flow +1 -1
- package/dist/browser/runtime/ax.js.map +1 -1
- package/dist/browser/runtime/cache.js.flow +1 -1
- package/dist/browser/runtime/cache.js.map +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/dev-warnings.js.map +1 -1
- package/dist/browser/runtime/index.js.flow +1 -1
- package/dist/browser/runtime/index.js.map +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/sheet.js.map +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/types.js.map +1 -1
- package/dist/browser/runtime.js.flow +1 -1
- package/dist/browser/runtime.js.map +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/types.js.map +1 -1
- package/dist/browser/utils/error.js.flow +1 -1
- package/dist/browser/utils/error.js.map +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-dev-runtime.js +5 -1
- package/dist/cjs/jsx/jsx-dev-runtime.js.map +1 -1
- package/dist/cjs/jsx/jsx-local-namespace.d.ts +2 -2
- package/dist/cjs/jsx/jsx-local-namespace.js.map +1 -1
- package/dist/cjs/jsx/jsx-runtime.js +5 -1
- package/dist/cjs/jsx/jsx-runtime.js.map +1 -1
- package/dist/cjs/keyframes/__fixtures__/index.js.map +1 -1
- package/dist/cjs/keyframes/index.d.ts +1 -1
- package/dist/cjs/keyframes/index.js.flow +25 -31
- package/dist/cjs/keyframes/index.js.map +1 -1
- package/dist/cjs/runtime/ax.js.flow +1 -1
- package/dist/cjs/runtime/ax.js.map +1 -1
- package/dist/cjs/runtime/cache.js.flow +1 -1
- package/dist/cjs/runtime/cache.js.map +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/dev-warnings.js.map +1 -1
- package/dist/cjs/runtime/index.js.flow +1 -1
- package/dist/cjs/runtime/index.js.map +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/sheet.js.map +1 -1
- package/dist/cjs/runtime/style-cache.js +10 -6
- package/dist/cjs/runtime/style-cache.js.flow +1 -1
- package/dist/cjs/runtime/style-cache.js.map +1 -1
- package/dist/cjs/runtime/style.js +7 -3
- 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/types.js.map +1 -1
- package/dist/cjs/runtime.js.flow +1 -1
- package/dist/cjs/runtime.js.map +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/types.js.map +1 -1
- package/dist/cjs/utils/error.js.flow +1 -1
- package/dist/cjs/utils/error.js.map +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-dev-runtime.js.map +1 -1
- package/dist/esm/jsx/jsx-local-namespace.d.ts +2 -2
- package/dist/esm/jsx/jsx-local-namespace.js.map +1 -1
- package/dist/esm/jsx/jsx-runtime.js.map +1 -1
- package/dist/esm/keyframes/__fixtures__/index.js.map +1 -1
- package/dist/esm/keyframes/index.d.ts +1 -1
- package/dist/esm/keyframes/index.js.flow +25 -31
- package/dist/esm/keyframes/index.js.map +1 -1
- package/dist/esm/runtime/ax.js.flow +1 -1
- package/dist/esm/runtime/ax.js.map +1 -1
- package/dist/esm/runtime/cache.js.flow +1 -1
- package/dist/esm/runtime/cache.js.map +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/dev-warnings.js.map +1 -1
- package/dist/esm/runtime/index.js.flow +1 -1
- package/dist/esm/runtime/index.js.map +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/sheet.js.map +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/types.js.map +1 -1
- package/dist/esm/runtime.js.flow +1 -1
- package/dist/esm/runtime.js.map +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/types.js.map +1 -1
- package/dist/esm/utils/error.js.flow +1 -1
- package/dist/esm/utils/error.js.map +1 -1
- package/package.json +14 -12
- package/src/__tests__/browser.test.tsx +4 -0
- package/src/__tests__/{display-names.test.tsx → display-names.test.ts} +0 -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.tsx → 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.tsx → index.ts} +9 -14
- package/src/index.js.flow +4 -7
- package/src/{index.tsx → index.ts} +3 -4
- package/src/jsx/{jsx-dev-runtime.tsx → jsx-dev-runtime.ts} +0 -0
- package/src/jsx/{jsx-local-namespace.tsx → jsx-local-namespace.ts} +2 -2
- package/src/jsx/{jsx-runtime.tsx → jsx-runtime.ts} +0 -0
- package/src/keyframes/__fixtures__/{index.tsx → index.ts} +0 -0
- package/src/keyframes/__tests__/index.test.tsx +4 -0
- package/src/keyframes/index.js.flow +25 -31
- package/src/keyframes/{index.tsx → index.ts} +1 -1
- package/src/runtime/__perf__/cs.test.tsx +137 -92
- package/src/runtime/__perf__/utils/cs.tsx +15 -15
- package/src/runtime/__perf__/utils/{sheet.tsx → sheet.ts} +0 -0
- package/src/runtime/__tests__/{ax.test.tsx → ax.test.ts} +0 -0
- package/src/runtime/__tests__/{css-custom-property.test.tsx → css-custom-property.test.ts} +0 -0
- package/src/runtime/__tests__/style.test.tsx +4 -0
- package/src/runtime/ax.js.flow +1 -1
- package/src/runtime/{ax.tsx → ax.ts} +0 -0
- package/src/runtime/cache.js.flow +1 -1
- package/src/runtime/{cache.tsx → cache.ts} +0 -0
- package/src/runtime/css-custom-property.js.flow +1 -1
- package/src/runtime/{css-custom-property.tsx → css-custom-property.ts} +0 -0
- package/src/runtime/dev-warnings.js.flow +1 -1
- package/src/runtime/{dev-warnings.tsx → dev-warnings.ts} +0 -0
- package/src/runtime/index.js.flow +1 -1
- package/src/runtime/{index.tsx → index.ts} +0 -0
- 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/{sheet.tsx → sheet.ts} +0 -0
- 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/{types.tsx → types.ts} +0 -0
- package/src/runtime.js.flow +1 -1
- package/src/{runtime.tsx → runtime.ts} +0 -0
- 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 +94 -0
- package/src/types.js.flow +13 -10
- package/src/types.ts +35 -0
- package/src/utils/error.js.flow +1 -1
- package/src/utils/{error.tsx → error.ts} +0 -0
- 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.tsx +0 -15
- package/src/styled/index.tsx +0 -112
- package/src/types.tsx +0 -27
|
File without changes
|
|
File without changes
|
|
@@ -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
|
+
};
|
|
File without changes
|
|
@@ -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
|
...
|
|
File without changes
|
package/src/runtime.js.flow
CHANGED
|
File without changes
|
|
@@ -188,7 +188,7 @@ describe('styled component', () => {
|
|
|
188
188
|
expect(ref).toHaveProperty('tagName', 'A');
|
|
189
189
|
});
|
|
190
190
|
|
|
191
|
-
it('should
|
|
191
|
+
it('should override the underlying markup with a span', () => {
|
|
192
192
|
const Heading = styled.h1`
|
|
193
193
|
color: red;
|
|
194
194
|
`;
|
|
@@ -1,30 +1,84 @@
|
|
|
1
1
|
// @flow strict-local
|
|
2
|
-
import React, { type Node } from 'react';
|
|
3
|
-
import { styled, type
|
|
2
|
+
import React, { type Node, type Element } from 'react';
|
|
3
|
+
import { styled, type CssType } from '@compiled/react';
|
|
4
4
|
|
|
5
5
|
// Tagged template expression
|
|
6
6
|
() => {
|
|
7
|
-
const
|
|
7
|
+
const StyledComponent = styled.div`
|
|
8
8
|
font-size: 12px;
|
|
9
9
|
`;
|
|
10
|
-
return <
|
|
10
|
+
return <StyledComponent>red text</StyledComponent>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// Tagged template expression with conditional
|
|
14
|
+
() => {
|
|
15
|
+
const StyledComponent = styled.div`
|
|
16
|
+
font-size: ${({ big }) => (big ? big : 12)}px;
|
|
17
|
+
`;
|
|
18
|
+
return <StyledComponent big>red text</StyledComponent>;
|
|
11
19
|
};
|
|
12
20
|
|
|
13
21
|
// Object call expression
|
|
14
22
|
() => {
|
|
15
|
-
const
|
|
16
|
-
|
|
23
|
+
const StyledComponent = styled.div<{ big: number, children: Node }>({
|
|
24
|
+
fontSize: (props: { big: number, children: Node }): number => (props.big == 5 ? 50 : 10),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return <StyledComponent big={5}>red text</StyledComponent>;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Object call expression with no props
|
|
31
|
+
() => {
|
|
32
|
+
const StyledComponent = styled.div({
|
|
33
|
+
wordBreak: 'break-word',
|
|
34
|
+
position: 'relative',
|
|
35
|
+
left: `${2 - 2}px`,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return <StyledComponent>red text</StyledComponent>;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Object call expression with conditional
|
|
42
|
+
() => {
|
|
43
|
+
const StyledComponent = styled.div<{ big: number, children: Node }>({
|
|
44
|
+
fontSize: ({ big }) => `${big ? 50 : 12}px`,
|
|
45
|
+
width: ({ big }) => (big ? 500 : 120),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return <StyledComponent big={5}>red text</StyledComponent>;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// Object call expression with logical operator expression
|
|
52
|
+
() => {
|
|
53
|
+
// Type defined as constant so we test the type without sketchy null check errors
|
|
54
|
+
const StyledComponent = styled.div<{ big?: 5000, children: Node }>(
|
|
55
|
+
{
|
|
56
|
+
fontSize: ({ big }) => `${big || 50}px`,
|
|
57
|
+
width: ({ big }) => big && 500,
|
|
58
|
+
},
|
|
59
|
+
({ big }) => big && { height: '100px' }
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return <StyledComponent big={5000}>red text</StyledComponent>;
|
|
17
63
|
};
|
|
18
64
|
|
|
19
65
|
// Array
|
|
20
66
|
() => {
|
|
21
|
-
const styles:
|
|
22
|
-
const
|
|
23
|
-
return <
|
|
67
|
+
const styles: CssType<{ fontSize: number, children: Node }>[] = [{ fontSize: '12px' }];
|
|
68
|
+
const StyledComponent = styled.div(styles);
|
|
69
|
+
return <StyledComponent fontSize={50}>red text</StyledComponent>;
|
|
24
70
|
};
|
|
25
71
|
|
|
26
72
|
// Multiple arguments
|
|
27
73
|
() => {
|
|
28
|
-
const
|
|
29
|
-
return <
|
|
74
|
+
const StyledComponent = styled.div({ fontSize: 12 }, `font-size: 12px`);
|
|
75
|
+
return <StyledComponent>red text</StyledComponent>;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// Dynamic function calls
|
|
79
|
+
() => {
|
|
80
|
+
const StyledComponent = styled.div({
|
|
81
|
+
backgroundColor: token('elevation.surface', 'black'),
|
|
82
|
+
zIndex: layers.modal(),
|
|
83
|
+
});
|
|
30
84
|
};
|
package/src/styled/index.js.flow
CHANGED
|
@@ -1,69 +1,68 @@
|
|
|
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 { ComponentType } from 'react';
|
|
8
|
-
import type {
|
|
9
|
-
/**
|
|
10
|
-
* Typing for the CSS object.
|
|
11
|
-
*/
|
|
12
|
-
export type CssObject<TProps> = CssFunction<FunctionInterpolation<TProps>>;
|
|
8
|
+
import type { CssType, CssFunction } from '../types';
|
|
13
9
|
/**
|
|
14
10
|
* Extra props added to the output Styled Component.
|
|
15
11
|
*/
|
|
16
12
|
export type StyledProps = {
|
|
17
13
|
as?: $Keys<$JSXIntrinsics>,
|
|
18
14
|
};
|
|
19
|
-
export type
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
*/
|
|
30
|
-
export interface StyledFunctionFromTag<TTag: $Keys<$JSXIntrinsics>> {
|
|
31
|
-
<TProps: mixed>(
|
|
32
|
-
css: CssObject<TProps> | $ReadOnlyArray<CssObject<TProps>>,
|
|
33
|
-
...interpolations: Interpolations<TProps>
|
|
34
|
-
): React$ComponentType<{
|
|
35
|
-
...TProps,
|
|
36
|
-
...$Exact<$ElementType<$JSXIntrinsics, TTag>>,
|
|
37
|
-
...StyledProps,
|
|
38
|
-
}>;
|
|
39
|
-
}
|
|
40
|
-
export interface StyledFunctionFromComponent<TInheritedProps: mixed> {
|
|
41
|
-
<TProps: mixed>(
|
|
42
|
-
css: CssObject<TProps> | $ReadOnlyArray<string>,
|
|
43
|
-
...interpolations: Interpolations<TProps>
|
|
44
|
-
): React$ComponentType<{ ...TProps, ...StyledProps, ...TInheritedProps }>;
|
|
15
|
+
export type ObjectInterpolation<TProps> = CssType<TProps> | CssType<TProps>[];
|
|
16
|
+
export type TemplateStringsInterpolation<TProps> = CssFunction<TProps> | CssFunction<TProps>[];
|
|
17
|
+
export interface StyledComponent<ComponentProps: mixed> {
|
|
18
|
+
<TProps>(
|
|
19
|
+
...css: ObjectInterpolation<TProps>[]
|
|
20
|
+
): React$ComponentType<{ ...TProps, ...ComponentProps, ...StyledProps }>;
|
|
21
|
+
<TProps>(
|
|
22
|
+
template: $ReadOnlyArray<string>,
|
|
23
|
+
...interpolations: TemplateStringsInterpolation<TProps>[]
|
|
24
|
+
): React$ComponentType<{ ...TProps, ...ComponentProps, ...StyledProps }>;
|
|
45
25
|
}
|
|
46
|
-
export type StyledComponentMap = $ObjMapi<$JSXIntrinsics, <Tag>(Tag) =>
|
|
47
|
-
export type
|
|
48
|
-
/**
|
|
49
|
-
* Typing to enable consumers to compose components, e.g: `styled(Component)`
|
|
50
|
-
*/
|
|
26
|
+
export type StyledComponentMap = $ObjMapi<$JSXIntrinsics, <Tag>(Tag) => StyledComponent<mixed>>;
|
|
27
|
+
export type CreateStyledComponent = {
|
|
51
28
|
<TInheritedProps: mixed>(
|
|
52
29
|
Component: ComponentType<TInheritedProps>
|
|
53
|
-
):
|
|
30
|
+
): StyledComponent<TInheritedProps>,
|
|
54
31
|
...
|
|
55
32
|
} & StyledComponentMap;
|
|
56
33
|
/**
|
|
57
|
-
*
|
|
34
|
+
* ## Styled component
|
|
58
35
|
*
|
|
36
|
+
* Create a component that styles a JSX element which comes with built-in behavior such as `ref` and `as` prop support.
|
|
37
|
+
* For further details [read the documentation](https://compiledcssinjs.com/docs/api-styled).
|
|
38
|
+
*
|
|
39
|
+
* ### Style with objects
|
|
40
|
+
* @example ```
|
|
41
|
+
* styled.div({
|
|
42
|
+
* fontSize: 12,
|
|
43
|
+
* });
|
|
59
44
|
* ```
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* styled.div
|
|
45
|
+
*
|
|
46
|
+
* ### Style with template literals
|
|
47
|
+
* @example ```
|
|
48
|
+
* styled.div`
|
|
49
|
+
* font-size: 12px
|
|
50
|
+
* `;
|
|
64
51
|
* ```
|
|
65
52
|
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
53
|
+
* ### Compose styles with arrays
|
|
54
|
+
* @example ```
|
|
55
|
+
* import type { css } from '@compiled/react';
|
|
56
|
+
*
|
|
57
|
+
* styled.div([
|
|
58
|
+
* { fontSize: 12 },
|
|
59
|
+
* css`font-size: 12px;`
|
|
60
|
+
* ]);
|
|
61
|
+
*
|
|
62
|
+
* styled.div(
|
|
63
|
+
* { fontSize: 12 },
|
|
64
|
+
* css`font-size: 12px`
|
|
65
|
+
* );
|
|
66
|
+
* ```
|
|
68
67
|
*/
|
|
69
|
-
declare export var styled:
|
|
68
|
+
declare export var styled: CreateStyledComponent;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { CssType, CssFunction } from '../types';
|
|
4
|
+
import { createSetupError } from '../utils/error';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Extra props added to the output Styled Component.
|
|
8
|
+
*/
|
|
9
|
+
export interface StyledProps {
|
|
10
|
+
as?: keyof JSX.IntrinsicElements;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type ObjectInterpolation<TProps> = CssType<TProps> | CssType<TProps>[];
|
|
14
|
+
export type TemplateStringsInterpolation<TProps> = CssFunction<TProps> | CssFunction<TProps>[];
|
|
15
|
+
|
|
16
|
+
export interface StyledComponent<ComponentProps extends unknown> {
|
|
17
|
+
// Allows either string or object (`` or ({}))
|
|
18
|
+
// We disable the ban types rule here as we need to join the empty object default with other props
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
20
|
+
<TProps = {}>(...css: ObjectInterpolation<TProps>[]): React.ComponentType<
|
|
21
|
+
TProps & ComponentProps & StyledProps
|
|
22
|
+
>;
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
24
|
+
<TProps = {}>(
|
|
25
|
+
template: TemplateStringsArray,
|
|
26
|
+
...interpolations: TemplateStringsInterpolation<TProps>[]
|
|
27
|
+
): React.ComponentType<TProps & ComponentProps & StyledProps>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// This creates the DOM element types for `styled.tag`, e.g. `span`, `div`, `h1`, etc.
|
|
31
|
+
export type StyledComponentMap = {
|
|
32
|
+
[Tag in keyof JSX.IntrinsicElements]: StyledComponent<JSX.IntrinsicElements[Tag]>;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export interface CreateStyledComponent extends StyledComponentMap {
|
|
36
|
+
// Typing to enable consumers to compose components, e.g: `styled(Component)`
|
|
37
|
+
<TInheritedProps extends unknown>(
|
|
38
|
+
Component: ComponentType<TInheritedProps>
|
|
39
|
+
): StyledComponent<TInheritedProps>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* ## Styled component
|
|
44
|
+
*
|
|
45
|
+
* Create a component that styles a JSX element which comes with built-in behavior such as `ref` and `as` prop support.
|
|
46
|
+
* For further details [read the documentation](https://compiledcssinjs.com/docs/api-styled).
|
|
47
|
+
*
|
|
48
|
+
* ### Style with objects
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```
|
|
52
|
+
* styled.div({
|
|
53
|
+
* fontSize: 12,
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* ### Style with template literals
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```
|
|
61
|
+
* styled.div`
|
|
62
|
+
* font-size: 12px
|
|
63
|
+
* `;
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* ### Compose styles with arrays
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```
|
|
70
|
+
* import { css } from '@compiled/react';
|
|
71
|
+
*
|
|
72
|
+
* styled.div([
|
|
73
|
+
* { fontSize: 12 },
|
|
74
|
+
* css`font-size: 12px;`
|
|
75
|
+
* ]);
|
|
76
|
+
*
|
|
77
|
+
* styled.div(
|
|
78
|
+
* { fontSize: 12 },
|
|
79
|
+
* css`font-size: 12px`
|
|
80
|
+
* );
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export const styled: CreateStyledComponent = new Proxy(
|
|
84
|
+
{},
|
|
85
|
+
{
|
|
86
|
+
get() {
|
|
87
|
+
return () => {
|
|
88
|
+
// Blow up if the transformer isn't turned on.
|
|
89
|
+
// This code won't ever be executed when setup correctly.
|
|
90
|
+
throw createSetupError();
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
) as any;
|
package/src/types.js.flow
CHANGED
|
@@ -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
|
import * as CSS from 'csstype';
|
|
@@ -10,20 +10,23 @@ import * as CSS from 'csstype';
|
|
|
10
10
|
*/
|
|
11
11
|
export type BasicTemplateInterpolations = string | number;
|
|
12
12
|
export interface FunctionInterpolation<TProps> {
|
|
13
|
-
(props: TProps):
|
|
13
|
+
(props: TProps): CssFunction<TProps>;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Possible types for a CSS value
|
|
17
|
+
*/
|
|
18
|
+
export type CssType<TProps> = CssObject<TProps> | FunctionInterpolation<TProps> | string;
|
|
15
19
|
/**
|
|
16
20
|
* These are all the CSS props that will exist.
|
|
17
21
|
*/
|
|
18
|
-
export type CSSProps = CSS.Properties<
|
|
19
|
-
export type
|
|
20
|
-
|
|
22
|
+
export type CSSProps<TProps> = CSS.Properties<CssFunction<TProps>>;
|
|
23
|
+
export type CssObject<TProps> = {
|
|
24
|
+
...CSSProps<TProps>,
|
|
25
|
+
[key: string]: CssFunction<TProps>,
|
|
21
26
|
...
|
|
22
27
|
};
|
|
23
|
-
export type CssFunction<
|
|
24
|
-
|
|
|
25
|
-
|
|
|
26
|
-
| $ReadOnlyArray<string>
|
|
27
|
-
| string
|
|
28
|
+
export type CssFunction<TProps = mixed> =
|
|
29
|
+
| CssType<TProps>
|
|
30
|
+
| BasicTemplateInterpolations
|
|
28
31
|
| boolean
|
|
29
32
|
| void;
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type * as CSS from 'csstype';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Typing for the interpolations.
|
|
5
|
+
*/
|
|
6
|
+
export type BasicTemplateInterpolations = string | number;
|
|
7
|
+
|
|
8
|
+
export interface FunctionInterpolation<TProps> {
|
|
9
|
+
(props: TProps): CssFunction<TProps>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Possible types for a CSS value
|
|
14
|
+
*/
|
|
15
|
+
export type CssType<TProps> =
|
|
16
|
+
| CSSProps<TProps> // Typed CSS properties
|
|
17
|
+
| CssObject<TProps> // CSS object
|
|
18
|
+
| FunctionInterpolation<TProps> // Props provider usage
|
|
19
|
+
| string; // Plain css string
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* These are all the CSS props that will exist.
|
|
23
|
+
*/
|
|
24
|
+
export type CSSProps<TProps> = CSS.Properties<CssFunction<TProps>>;
|
|
25
|
+
|
|
26
|
+
export type CssObject<TProps> = {
|
|
27
|
+
[key: string]: CssFunction<TProps>;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// CSS inside of a CSS expression
|
|
31
|
+
export type CssFunction<TProps = unknown> =
|
|
32
|
+
| CssType<TProps>
|
|
33
|
+
| BasicTemplateInterpolations // CSS values in tagged template expression
|
|
34
|
+
| boolean // Something like `false && styles`
|
|
35
|
+
| undefined; // Something like `undefined && styles`
|
package/src/utils/error.js.flow
CHANGED
|
File without changes
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns `true` when inside a node environment,
|
|
3
|
-
* else `false`.
|
|
4
|
-
*
|
|
5
|
-
* When using this it will remove any node code from the browser bundle - for example:
|
|
6
|
-
*
|
|
7
|
-
* ```js
|
|
8
|
-
* if (isNodeEnvironment()) {
|
|
9
|
-
* // This code will be removed from the browser bundle
|
|
10
|
-
* }
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
export var isNodeEnvironment = function () {
|
|
14
|
-
return typeof window === 'undefined';
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=is-node.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-node.js","sourceRoot":"","sources":["../../../src/runtime/is-node.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,IAAM,iBAAiB,GAAG;IAC/B,OAAO,OAAO,MAAM,KAAK,WAAW,CAAC;AACvC,CAAC,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isNodeEnvironment = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Returns `true` when inside a node environment,
|
|
6
|
-
* else `false`.
|
|
7
|
-
*
|
|
8
|
-
* When using this it will remove any node code from the browser bundle - for example:
|
|
9
|
-
*
|
|
10
|
-
* ```js
|
|
11
|
-
* if (isNodeEnvironment()) {
|
|
12
|
-
* // This code will be removed from the browser bundle
|
|
13
|
-
* }
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
var isNodeEnvironment = function () {
|
|
17
|
-
return typeof window === 'undefined';
|
|
18
|
-
};
|
|
19
|
-
exports.isNodeEnvironment = isNodeEnvironment;
|
|
20
|
-
//# sourceMappingURL=is-node.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-node.js","sourceRoot":"","sources":["../../../src/runtime/is-node.tsx"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;GAWG;AACI,IAAM,iBAAiB,GAAG;IAC/B,OAAO,OAAO,MAAM,KAAK,WAAW,CAAC;AACvC,CAAC,CAAC;AAFW,QAAA,iBAAiB,qBAE5B"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns `true` when inside a node environment,
|
|
3
|
-
* else `false`.
|
|
4
|
-
*
|
|
5
|
-
* When using this it will remove any node code from the browser bundle - for example:
|
|
6
|
-
*
|
|
7
|
-
* ```js
|
|
8
|
-
* if (isNodeEnvironment()) {
|
|
9
|
-
* // This code will be removed from the browser bundle
|
|
10
|
-
* }
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
export var isNodeEnvironment = function () {
|
|
14
|
-
return typeof window === 'undefined';
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=is-node.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-node.js","sourceRoot":"","sources":["../../../src/runtime/is-node.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,IAAM,iBAAiB,GAAG;IAC/B,OAAO,OAAO,MAAM,KAAK,WAAW,CAAC;AACvC,CAAC,CAAC"}
|