@compiled/react 0.13.0 → 0.14.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.js.flow +1 -1
- package/dist/browser/css/index.js.flow +1 -1
- package/dist/browser/css-map/index.d.ts +21 -0
- package/dist/browser/css-map/index.js +5 -0
- package/dist/browser/css-map/index.js.flow +26 -0
- package/dist/browser/css-map/index.js.map +1 -0
- package/dist/browser/index.d.ts +1 -0
- package/dist/browser/index.js +1 -0
- package/dist/browser/index.js.flow +2 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/keyframes/index.js.flow +1 -1
- package/dist/browser/runtime/ac.js.flow +1 -1
- 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 +0 -8
- package/dist/browser/runtime/index.js.flow +1 -1
- package/dist/browser/runtime/index.js.map +1 -1
- package/dist/browser/runtime/is-server-environment.js.flow +1 -1
- package/dist/browser/runtime/sheet.js.flow +1 -1
- package/dist/browser/runtime/style-cache.js.flow +1 -1
- package/dist/browser/runtime/style.js.flow +1 -1
- package/dist/browser/runtime/types.js.flow +1 -1
- package/dist/browser/runtime.js.flow +1 -1
- package/dist/browser/styled/index.js.flow +1 -1
- package/dist/browser/types.d.ts +3 -3
- package/dist/browser/types.js.flow +4 -4
- package/dist/browser/utils/error.js.flow +1 -1
- package/dist/cjs/class-names/index.js.flow +1 -1
- package/dist/cjs/css/index.js.flow +1 -1
- package/dist/cjs/css-map/index.d.ts +21 -0
- package/dist/cjs/css-map/index.js +8 -0
- package/dist/cjs/css-map/index.js.flow +26 -0
- package/dist/cjs/css-map/index.js.map +1 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.flow +2 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/keyframes/index.js.flow +1 -1
- package/dist/cjs/runtime/ac.js.flow +1 -1
- 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 +0 -8
- package/dist/cjs/runtime/index.js.flow +1 -1
- package/dist/cjs/runtime/index.js.map +1 -1
- package/dist/cjs/runtime/is-server-environment.js.flow +1 -1
- package/dist/cjs/runtime/sheet.js.flow +1 -1
- package/dist/cjs/runtime/style-cache.js.flow +1 -1
- package/dist/cjs/runtime/style.js.flow +1 -1
- package/dist/cjs/runtime/types.js.flow +1 -1
- package/dist/cjs/runtime.js.flow +1 -1
- package/dist/cjs/styled/index.js.flow +1 -1
- package/dist/cjs/types.d.ts +3 -3
- package/dist/cjs/types.js.flow +4 -4
- package/dist/cjs/utils/error.js.flow +1 -1
- package/dist/esm/class-names/index.js.flow +1 -1
- package/dist/esm/css/index.js.flow +1 -1
- package/dist/esm/css-map/index.d.ts +21 -0
- package/dist/esm/css-map/index.js +5 -0
- package/dist/esm/css-map/index.js.flow +26 -0
- package/dist/esm/css-map/index.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.flow +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/keyframes/index.js.flow +1 -1
- package/dist/esm/runtime/ac.js.flow +1 -1
- 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 +0 -8
- package/dist/esm/runtime/index.js.flow +1 -1
- package/dist/esm/runtime/index.js.map +1 -1
- package/dist/esm/runtime/is-server-environment.js.flow +1 -1
- package/dist/esm/runtime/sheet.js.flow +1 -1
- package/dist/esm/runtime/style-cache.js.flow +1 -1
- package/dist/esm/runtime/style.js.flow +1 -1
- package/dist/esm/runtime/types.js.flow +1 -1
- package/dist/esm/runtime.js.flow +1 -1
- package/dist/esm/styled/index.js.flow +1 -1
- package/dist/esm/types.d.ts +3 -3
- package/dist/esm/types.js.flow +4 -4
- package/dist/esm/utils/error.js.flow +1 -1
- package/package.json +4 -8
- package/src/class-names/index.js.flow +1 -1
- package/src/css/index.js.flow +1 -1
- package/src/css-map/__tests__/index.test.tsx +52 -0
- package/src/css-map/index.js.flow +26 -0
- package/src/css-map/index.ts +27 -0
- package/src/index.js.flow +2 -1
- package/src/index.ts +1 -0
- package/src/keyframes/index.js.flow +1 -1
- package/src/runtime/ac.js.flow +1 -1
- 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/index.ts +0 -11
- package/src/runtime/is-server-environment.js.flow +1 -1
- package/src/runtime/sheet.js.flow +1 -1
- package/src/runtime/style-cache.js.flow +1 -1
- package/src/runtime/style.js.flow +1 -1
- package/src/runtime/types.js.flow +1 -1
- package/src/runtime.js.flow +1 -1
- package/src/styled/index.js.flow +1 -1
- package/src/types.js.flow +4 -4
- package/src/types.ts +3 -3
- package/src/utils/error.js.flow +1 -1
- package/src/global.d.ts +0 -7
package/dist/cjs/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.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
7
|
import * as CSS from 'csstype';
|
|
@@ -19,11 +19,11 @@ export type CssType<TProps> = CssObject<TProps> | FunctionInterpolation<TProps>
|
|
|
19
19
|
/**
|
|
20
20
|
* These are all the CSS props that will exist.
|
|
21
21
|
*/
|
|
22
|
-
export type CSSProps<TProps> = CSS.Properties<CssFunction<TProps
|
|
23
|
-
export type CssObject<TProps> = {
|
|
22
|
+
export type CSSProps<TProps> = $ReadOnly<CSS.Properties<CssFunction<TProps>>>;
|
|
23
|
+
export type CssObject<TProps> = $ReadOnly<{
|
|
24
24
|
...CSSProps<TProps>,
|
|
25
25
|
[key: string]: CssFunction<TProps>,
|
|
26
|
-
}
|
|
26
|
+
}>;
|
|
27
27
|
export type CssFunction<TProps = mixed> =
|
|
28
28
|
| CssType<TProps>
|
|
29
29
|
| BasicTemplateInterpolations
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CSSProps, CssObject } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* ## cssMap
|
|
4
|
+
*
|
|
5
|
+
* Creates a collection of named CSS rules that are statically typed and useable with other Compiled APIs.
|
|
6
|
+
* For further details [read the documentation](https://compiledcssinjs.com/docs/api-cssmap).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```
|
|
10
|
+
* const borderStyleMap = cssMap({
|
|
11
|
+
* none: { borderStyle: 'none' },
|
|
12
|
+
* solid: { borderStyle: 'solid' },
|
|
13
|
+
* });
|
|
14
|
+
* const Component = ({ borderStyle }) => <div css={css(borderStyleMap[borderStyle])} />
|
|
15
|
+
*
|
|
16
|
+
* <Component borderStyle="solid" />
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
type returnType<T extends string, P> = Record<T, CSSProps<P>>;
|
|
20
|
+
export default function cssMap<T extends string, TProps = unknown>(_styles: Record<T, CssObject<TProps> | CssObject<TProps>[]>): Readonly<returnType<T, TProps>>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for index
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
import type { CSSProps, CssObject } from '../types';
|
|
8
|
+
/**
|
|
9
|
+
* ## cssMap
|
|
10
|
+
*
|
|
11
|
+
* Creates a collection of named CSS rules that are statically typed and useable with other Compiled APIs.
|
|
12
|
+
* For further details [read the documentation](https://compiledcssinjs.com/docs/api-cssmap).
|
|
13
|
+
* @example ```
|
|
14
|
+
* const borderStyleMap = cssMap({
|
|
15
|
+
* none: { borderStyle: 'none' },
|
|
16
|
+
* solid: { borderStyle: 'solid' },
|
|
17
|
+
* });
|
|
18
|
+
* const Component = ({ borderStyle }) => <div css={css(borderStyleMap[borderStyle])} />
|
|
19
|
+
*
|
|
20
|
+
* <Component borderStyle="solid" />
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
declare type returnType<T: string, P> = { [key: T]: CSSProps<P> };
|
|
24
|
+
declare export default function cssMap<T: string, TProps>(_styles: {
|
|
25
|
+
[key: T]: CssObject<TProps> | CssObject<TProps>[],
|
|
26
|
+
}): $ReadOnly<returnType<T, TProps>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/css-map/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAqBlD,MAAM,CAAC,OAAO,UAAU,MAAM,CAC5B,OAA2D;IAE3D,MAAM,gBAAgB,EAAE,CAAC;AAC3B,CAAC"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { keyframes } from './keyframes';
|
|
|
6
6
|
export { styled } from './styled';
|
|
7
7
|
export { ClassNames } from './class-names';
|
|
8
8
|
export { default as css } from './css';
|
|
9
|
+
export { default as cssMap } from './css-map';
|
|
9
10
|
export declare const jsx: typeof createElement;
|
|
10
11
|
export declare namespace jsx {
|
|
11
12
|
namespace JSX {
|
package/dist/esm/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { keyframes } from './keyframes';
|
|
|
3
3
|
export { styled } from './styled';
|
|
4
4
|
export { ClassNames } from './class-names';
|
|
5
5
|
export { default as css } from './css';
|
|
6
|
+
export { default as cssMap } from './css-map';
|
|
6
7
|
// Pass through the (classic) jsx runtime.
|
|
7
8
|
// Compiled currently doesn't define its own and uses this purely to enable a local jsx namespace.
|
|
8
9
|
export const jsx = createElement;
|
package/dist/esm/index.js.flow
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flowtype definitions for index
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
7
|
import type { CssFunction, CSSProps, CssType } from './types';
|
|
@@ -10,3 +10,4 @@ declare export { keyframes } from './keyframes';
|
|
|
10
10
|
declare export { styled } from './styled';
|
|
11
11
|
declare export { ClassNames } from './class-names';
|
|
12
12
|
declare export { default as css } from './css';
|
|
13
|
+
declare export { default as cssMap } from './css-map';
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAOtC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAOtC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,WAAW,CAAC;AAE9C,0CAA0C;AAC1C,kGAAkG;AAClG,MAAM,CAAC,MAAM,GAAG,GAAG,aAAa,CAAC"}
|
|
@@ -3,12 +3,4 @@ export { default as CC } from './style-cache';
|
|
|
3
3
|
export { default as ax } from './ax';
|
|
4
4
|
export { default as ac, clearCache as clearAcCache } from './ac';
|
|
5
5
|
export { default as ix } from './css-custom-property';
|
|
6
|
-
// Ensure only one `@compiled/runtime` exist in the bundle.
|
|
7
|
-
// This is because `ac` and `style-cache` need to access a singlton.
|
|
8
|
-
if (typeof window !== 'undefined') {
|
|
9
|
-
if (typeof window.__COMPILED_IMPORTED__ !== 'undefined') {
|
|
10
|
-
throw new Error('Multiple instances of Compiled Runtime have been found on the page. A likely cause is that muliple versions of `@compiled/react` exist in JS bundle.');
|
|
11
|
-
}
|
|
12
|
-
window.__COMPILED_IMPORTED__ = true;
|
|
13
|
-
}
|
|
14
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,UAAU,IAAI,YAAY,EAAE,MAAM,MAAM,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,uBAAuB,CAAC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/runtime/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,UAAU,IAAI,YAAY,EAAE,MAAM,MAAM,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/esm/runtime.js.flow
CHANGED
package/dist/esm/types.d.ts
CHANGED
|
@@ -13,8 +13,8 @@ export type CssType<TProps> = CSSProps<TProps> | CssObject<TProps> | FunctionInt
|
|
|
13
13
|
/**
|
|
14
14
|
* These are all the CSS props that will exist.
|
|
15
15
|
*/
|
|
16
|
-
export type CSSProps<TProps> = CSS.Properties<CssFunction<TProps
|
|
17
|
-
export type CssObject<TProps> = {
|
|
16
|
+
export type CSSProps<TProps> = Readonly<CSS.Properties<CssFunction<TProps>>>;
|
|
17
|
+
export type CssObject<TProps> = Readonly<{
|
|
18
18
|
[key: string]: CssFunction<TProps>;
|
|
19
|
-
}
|
|
19
|
+
}>;
|
|
20
20
|
export type CssFunction<TProps = unknown> = CssType<TProps> | BasicTemplateInterpolations | boolean | undefined;
|
package/dist/esm/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.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
7
|
import * as CSS from 'csstype';
|
|
@@ -19,11 +19,11 @@ export type CssType<TProps> = CssObject<TProps> | FunctionInterpolation<TProps>
|
|
|
19
19
|
/**
|
|
20
20
|
* These are all the CSS props that will exist.
|
|
21
21
|
*/
|
|
22
|
-
export type CSSProps<TProps> = CSS.Properties<CssFunction<TProps
|
|
23
|
-
export type CssObject<TProps> = {
|
|
22
|
+
export type CSSProps<TProps> = $ReadOnly<CSS.Properties<CssFunction<TProps>>>;
|
|
23
|
+
export type CssObject<TProps> = $ReadOnly<{
|
|
24
24
|
...CSSProps<TProps>,
|
|
25
25
|
[key: string]: CssFunction<TProps>,
|
|
26
|
-
}
|
|
26
|
+
}>;
|
|
27
27
|
export type CssFunction<TProps = mixed> =
|
|
28
28
|
| CssType<TProps>
|
|
29
29
|
| BasicTemplateInterpolations
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compiled/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "A familiar and performant compile time CSS-in-JS library for React.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compiled",
|
|
@@ -17,11 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"license": "Apache-2.0",
|
|
19
19
|
"author": "Michael Dougall",
|
|
20
|
-
"sideEffects":
|
|
21
|
-
"./dist/browser/runtime/index.js",
|
|
22
|
-
"./dist/cjs/runtime/index.js",
|
|
23
|
-
"./dist/esm/runtime/index.js"
|
|
24
|
-
],
|
|
20
|
+
"sideEffects": false,
|
|
25
21
|
"exports": {
|
|
26
22
|
".": {
|
|
27
23
|
"import": [
|
|
@@ -76,13 +72,13 @@
|
|
|
76
72
|
"jsx-dev-runtime"
|
|
77
73
|
],
|
|
78
74
|
"dependencies": {
|
|
79
|
-
"csstype": "^3.1.
|
|
75
|
+
"csstype": "^3.1.2"
|
|
80
76
|
},
|
|
81
77
|
"devDependencies": {
|
|
82
78
|
"@compiled/benchmark": "^1.1.0",
|
|
83
79
|
"@testing-library/react": "^12.1.5",
|
|
84
80
|
"@types/jsdom": "^16.2.15",
|
|
85
|
-
"@types/react-dom": "^17.0.
|
|
81
|
+
"@types/react-dom": "^17.0.20",
|
|
86
82
|
"jsdom": "^19.0.0",
|
|
87
83
|
"react": "^17.0.2",
|
|
88
84
|
"react-dom": "^17.0.2"
|
package/src/css/index.js.flow
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** @jsxImportSource @compiled/react */
|
|
2
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
3
|
+
import { css, cssMap } from '@compiled/react';
|
|
4
|
+
import { render } from '@testing-library/react';
|
|
5
|
+
|
|
6
|
+
describe('css map', () => {
|
|
7
|
+
const styles = cssMap({
|
|
8
|
+
danger: {
|
|
9
|
+
color: 'red',
|
|
10
|
+
},
|
|
11
|
+
success: {
|
|
12
|
+
color: 'green',
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should generate css based on the selected variant', () => {
|
|
17
|
+
const Foo = ({ variant }: { variant: keyof typeof styles }) => (
|
|
18
|
+
<div css={styles[variant]}>hello world</div>
|
|
19
|
+
);
|
|
20
|
+
const { getByText, rerender } = render(<Foo variant="danger" />);
|
|
21
|
+
|
|
22
|
+
expect(getByText('hello world')).toHaveCompiledCss('color', 'red');
|
|
23
|
+
|
|
24
|
+
rerender(<Foo variant="success" />);
|
|
25
|
+
expect(getByText('hello world')).toHaveCompiledCss('color', 'green');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should statically access a variant', () => {
|
|
29
|
+
const Foo = () => <div css={styles.danger}>hello world</div>;
|
|
30
|
+
const { getByText } = render(<Foo />);
|
|
31
|
+
|
|
32
|
+
expect(getByText('hello world')).toHaveCompiledCss('color', 'red');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should merge styles', () => {
|
|
36
|
+
const hover = css({ ':hover': { color: 'red' } });
|
|
37
|
+
const Foo = () => <div css={[hover, styles.success]}>hello world</div>;
|
|
38
|
+
const { getByText } = render(<Foo />);
|
|
39
|
+
|
|
40
|
+
expect(getByText('hello world')).toHaveCompiledCss('color', 'green');
|
|
41
|
+
expect(getByText('hello world')).toHaveCompiledCss('color', 'red', { target: ':hover' });
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should conditionally apply variant', () => {
|
|
45
|
+
const Foo = ({ isDanger }: { isDanger: boolean }) => (
|
|
46
|
+
<div css={isDanger && styles.danger}>hello world</div>
|
|
47
|
+
);
|
|
48
|
+
const { getByText } = render(<Foo isDanger={true} />);
|
|
49
|
+
|
|
50
|
+
expect(getByText('hello world')).toHaveCompiledCss('color', 'red');
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for index
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
import type { CSSProps, CssObject } from '../types';
|
|
8
|
+
/**
|
|
9
|
+
* ## cssMap
|
|
10
|
+
*
|
|
11
|
+
* Creates a collection of named CSS rules that are statically typed and useable with other Compiled APIs.
|
|
12
|
+
* For further details [read the documentation](https://compiledcssinjs.com/docs/api-cssmap).
|
|
13
|
+
* @example ```
|
|
14
|
+
* const borderStyleMap = cssMap({
|
|
15
|
+
* none: { borderStyle: 'none' },
|
|
16
|
+
* solid: { borderStyle: 'solid' },
|
|
17
|
+
* });
|
|
18
|
+
* const Component = ({ borderStyle }) => <div css={css(borderStyleMap[borderStyle])} />
|
|
19
|
+
*
|
|
20
|
+
* <Component borderStyle="solid" />
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
declare type returnType<T: string, P> = { [key: T]: CSSProps<P> };
|
|
24
|
+
declare export default function cssMap<T: string, TProps>(_styles: {
|
|
25
|
+
[key: T]: CssObject<TProps> | CssObject<TProps>[],
|
|
26
|
+
}): $ReadOnly<returnType<T, TProps>>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CSSProps, CssObject } from '../types';
|
|
2
|
+
import { createSetupError } from '../utils/error';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ## cssMap
|
|
6
|
+
*
|
|
7
|
+
* Creates a collection of named CSS rules that are statically typed and useable with other Compiled APIs.
|
|
8
|
+
* For further details [read the documentation](https://compiledcssinjs.com/docs/api-cssmap).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```
|
|
12
|
+
* const borderStyleMap = cssMap({
|
|
13
|
+
* none: { borderStyle: 'none' },
|
|
14
|
+
* solid: { borderStyle: 'solid' },
|
|
15
|
+
* });
|
|
16
|
+
* const Component = ({ borderStyle }) => <div css={css(borderStyleMap[borderStyle])} />
|
|
17
|
+
*
|
|
18
|
+
* <Component borderStyle="solid" />
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
type returnType<T extends string, P> = Record<T, CSSProps<P>>;
|
|
22
|
+
|
|
23
|
+
export default function cssMap<T extends string, TProps = unknown>(
|
|
24
|
+
_styles: Record<T, CssObject<TProps> | CssObject<TProps>[]>
|
|
25
|
+
): Readonly<returnType<T, TProps>> {
|
|
26
|
+
throw createSetupError();
|
|
27
|
+
}
|
package/src/index.js.flow
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Flowtype definitions for index
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
|
-
* Flowgen v1.
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
7
|
import type { CssFunction, CSSProps, CssType } from './types';
|
|
@@ -10,3 +10,4 @@ declare export { keyframes } from './keyframes';
|
|
|
10
10
|
declare export { styled } from './styled';
|
|
11
11
|
declare export { ClassNames } from './class-names';
|
|
12
12
|
declare export { default as css } from './css';
|
|
13
|
+
declare export { default as cssMap } from './css-map';
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ export { keyframes } from './keyframes';
|
|
|
9
9
|
export { styled } from './styled';
|
|
10
10
|
export { ClassNames } from './class-names';
|
|
11
11
|
export { default as css } from './css';
|
|
12
|
+
export { default as cssMap } from './css-map';
|
|
12
13
|
|
|
13
14
|
// Pass through the (classic) jsx runtime.
|
|
14
15
|
// Compiled currently doesn't define its own and uses this purely to enable a local jsx namespace.
|
package/src/runtime/ac.js.flow
CHANGED
package/src/runtime/ax.js.flow
CHANGED
package/src/runtime/index.ts
CHANGED
|
@@ -3,14 +3,3 @@ export { default as CC } from './style-cache';
|
|
|
3
3
|
export { default as ax } from './ax';
|
|
4
4
|
export { default as ac, clearCache as clearAcCache } from './ac';
|
|
5
5
|
export { default as ix } from './css-custom-property';
|
|
6
|
-
|
|
7
|
-
// Ensure only one `@compiled/runtime` exist in the bundle.
|
|
8
|
-
// This is because `ac` and `style-cache` need to access a singlton.
|
|
9
|
-
if (typeof window !== 'undefined') {
|
|
10
|
-
if (typeof window.__COMPILED_IMPORTED__ !== 'undefined') {
|
|
11
|
-
throw new Error(
|
|
12
|
-
'Multiple instances of Compiled Runtime have been found on the page. A likely cause is that muliple versions of `@compiled/react` exist in JS bundle.'
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
window.__COMPILED_IMPORTED__ = true;
|
|
16
|
-
}
|