@compiled/react 0.8.0 → 0.9.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.
Files changed (47) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/browser/css/index.d.ts +2 -2
  3. package/dist/browser/css/index.js.flow +3 -3
  4. package/dist/browser/css/index.js.map +1 -1
  5. package/dist/browser/runtime/dev-warnings.d.ts +0 -1
  6. package/dist/browser/runtime/dev-warnings.js +1 -1
  7. package/dist/browser/runtime/dev-warnings.js.flow +0 -1
  8. package/dist/browser/runtime/dev-warnings.js.map +1 -1
  9. package/dist/browser/styled/index.d.ts +3 -6
  10. package/dist/browser/styled/index.js.flow +3 -6
  11. package/dist/browser/styled/index.js.map +1 -1
  12. package/dist/browser/types.d.ts +5 -2
  13. package/dist/browser/types.js.flow +5 -2
  14. package/dist/cjs/css/index.d.ts +2 -2
  15. package/dist/cjs/css/index.js.flow +3 -3
  16. package/dist/cjs/css/index.js.map +1 -1
  17. package/dist/cjs/runtime/dev-warnings.d.ts +0 -1
  18. package/dist/cjs/runtime/dev-warnings.js +2 -3
  19. package/dist/cjs/runtime/dev-warnings.js.flow +0 -1
  20. package/dist/cjs/runtime/dev-warnings.js.map +1 -1
  21. package/dist/cjs/styled/index.d.ts +3 -6
  22. package/dist/cjs/styled/index.js.flow +3 -6
  23. package/dist/cjs/styled/index.js.map +1 -1
  24. package/dist/cjs/types.d.ts +5 -2
  25. package/dist/cjs/types.js.flow +5 -2
  26. package/dist/esm/css/index.d.ts +2 -2
  27. package/dist/esm/css/index.js.flow +3 -3
  28. package/dist/esm/css/index.js.map +1 -1
  29. package/dist/esm/runtime/dev-warnings.d.ts +0 -1
  30. package/dist/esm/runtime/dev-warnings.js +1 -1
  31. package/dist/esm/runtime/dev-warnings.js.flow +0 -1
  32. package/dist/esm/runtime/dev-warnings.js.map +1 -1
  33. package/dist/esm/styled/index.d.ts +3 -6
  34. package/dist/esm/styled/index.js.flow +3 -6
  35. package/dist/esm/styled/index.js.map +1 -1
  36. package/dist/esm/types.d.ts +5 -2
  37. package/dist/esm/types.js.flow +5 -2
  38. package/package.json +1 -1
  39. package/src/css/index.js.flow +3 -3
  40. package/src/css/index.tsx +7 -4
  41. package/src/runtime/__tests__/style.test.tsx +91 -57
  42. package/src/runtime/dev-warnings.js.flow +0 -1
  43. package/src/runtime/dev-warnings.tsx +1 -1
  44. package/src/styled/index.js.flow +3 -6
  45. package/src/styled/index.tsx +3 -7
  46. package/src/types.js.flow +5 -2
  47. package/src/types.tsx +6 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @compiled/react
2
2
 
3
+ ## 0.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 2092839: Allow inline strings and inline css mixins in conditional expressions. Fix ordering of styles in template literals.
8
+
3
9
  ## 0.8.0
4
10
 
5
11
  ### Minor Changes
@@ -1,4 +1,4 @@
1
- import type { CSSProps } from '../types';
1
+ import type { BasicTemplateInterpolations, CSSProps, FunctionInterpolation } from '../types';
2
2
  /**
3
3
  * Create styles that can be re-used between components with a template literal.
4
4
  *
@@ -12,7 +12,7 @@ import type { CSSProps } from '../types';
12
12
  * @param css
13
13
  * @param values
14
14
  */
15
- export default function css(_css: TemplateStringsArray, ..._values: (string | number)[]): CSSProps;
15
+ export default function css<T = void>(_css: TemplateStringsArray, ..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]): CSSProps;
16
16
  /**
17
17
  * Create styles that can be re-used between components with an object
18
18
  *
@@ -4,7 +4,7 @@
4
4
  * Flowgen v1.14.1
5
5
  * @flow
6
6
  */
7
- import type { CSSProps } from '../types';
7
+ import type { BasicTemplateInterpolations, CSSProps, FunctionInterpolation } from '../types';
8
8
  /**
9
9
  * Create styles that can be re-used between components with a template literal.
10
10
  *
@@ -17,9 +17,9 @@ import type { CSSProps } from '../types';
17
17
  * @param css
18
18
  * @param values
19
19
  */
20
- declare export default function css(
20
+ declare export default function css<T>(
21
21
  _css: $ReadOnlyArray<string>,
22
- ..._values: (string | number)[]
22
+ ..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
23
23
  ): CSSProps;
24
24
  /**
25
25
  * Create styles that can be re-used between components with an object
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/css/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAgClD,MAAM,CAAC,OAAO,UAAU,GAAG,CACzB,IAAqC;IACrC,iBAA+B;SAA/B,UAA+B,EAA/B,qBAA+B,EAA/B,IAA+B;QAA/B,gCAA+B;;IAE/B,MAAM,gBAAgB,EAAE,CAAC;AAC3B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/css/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAmClD,MAAM,CAAC,OAAO,UAAU,GAAG,CACzB,IAAqC;IACrC,iBAAsE;SAAtE,UAAsE,EAAtE,qBAAsE,EAAtE,IAAsE;QAAtE,gCAAsE;;IAEtE,MAAM,gBAAgB,EAAE,CAAC;AAC3B,CAAC"}
@@ -1,2 +1 @@
1
- export declare const warn: (str: string, ...args: any[]) => void;
2
1
  export declare const analyzeCssInDev: (sheet: string) => void;
@@ -5,7 +5,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
5
5
  };
6
6
  var selectorsToWarn = [':first-child', ':nth-child'];
7
7
  var hasWarned = {};
8
- export var warn = function (str) {
8
+ var warn = function (str) {
9
9
  var args = [];
10
10
  for (var _i = 1; _i < arguments.length; _i++) {
11
11
  args[_i - 1] = arguments[_i];
@@ -4,5 +4,4 @@
4
4
  * Flowgen v1.14.1
5
5
  * @flow
6
6
  */
7
- declare export var warn: (str: string, ...args: any[]) => void;
8
7
  declare export var analyzeCssInDev: (sheet: string) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"dev-warnings.js","sourceRoot":"","sources":["../../../src/runtime/dev-warnings.tsx"],"names":[],"mappings":";;;;;AAAA,IAAM,eAAe,GAAG,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;AACvD,IAAM,SAAS,GAAyB,EAAE,CAAC;AAE3C,MAAM,CAAC,IAAM,IAAI,GAAG,UAAC,GAAW;IAAE,cAAc;SAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;QAAd,6BAAc;;IAC9C,OAAA,OAAO,CAAC,KAAK,OAAb,OAAO,iBACL,q6DAUA,GAAG,OACN,GACM,IAAI;AAbT,CAcC,CAAC;AAEJ,MAAM,CAAC,IAAM,eAAe,GAAG,UAAC,KAAa;IAC3C,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE;QACpB,OAAO;KACR;IAED,IAAM,wBAAwB,GAC5B,eAAe,CAAC,GAAG,CAAC,UAAC,QAAQ,IAAK,OAAA,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAxB,CAAwB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAEzF,IAAI,wBAAwB,EAAE;QAC5B,IAAI,CACF,iBAAc,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,gPAEiC,CAC1E,CAAC;KACH;IAED,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;AAC1B,CAAC,CAAC"}
1
+ {"version":3,"file":"dev-warnings.js","sourceRoot":"","sources":["../../../src/runtime/dev-warnings.tsx"],"names":[],"mappings":";;;;;AAAA,IAAM,eAAe,GAAG,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;AACvD,IAAM,SAAS,GAAyB,EAAE,CAAC;AAE3C,IAAM,IAAI,GAAG,UAAC,GAAW;IAAE,cAAc;SAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;QAAd,6BAAc;;IACvC,OAAA,OAAO,CAAC,KAAK,OAAb,OAAO,iBACL,q6DAUA,GAAG,OACN,GACM,IAAI;AAbT,CAcC,CAAC;AAEJ,MAAM,CAAC,IAAM,eAAe,GAAG,UAAC,KAAa;IAC3C,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE;QACpB,OAAO;KACR;IAED,IAAM,wBAAwB,GAC5B,eAAe,CAAC,GAAG,CAAC,UAAC,QAAQ,IAAK,OAAA,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAxB,CAAwB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAEzF,IAAI,wBAAwB,EAAE;QAC5B,IAAI,CACF,iBAAc,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,gPAEiC,CAC1E,CAAC;KACH;IAED,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;AAC1B,CAAC,CAAC"}
@@ -1,19 +1,16 @@
1
1
  import type { ComponentType } from 'react';
2
- import type { BasicTemplateInterpolations, CssFunction, CSSProps } from '../types';
3
- export interface FunctionIterpolation<TProps> {
4
- (props: TProps): CSSProps | string | number | boolean | undefined;
5
- }
2
+ import type { BasicTemplateInterpolations, CssFunction, FunctionInterpolation } from '../types';
6
3
  /**
7
4
  * Typing for the CSS object.
8
5
  */
9
- export declare type CssObject<TProps> = CssFunction<FunctionIterpolation<TProps>>;
6
+ export declare type CssObject<TProps> = CssFunction<FunctionInterpolation<TProps>>;
10
7
  /**
11
8
  * Extra props added to the output Styled Component.
12
9
  */
13
10
  export interface StyledProps {
14
11
  as?: keyof JSX.IntrinsicElements;
15
12
  }
16
- export declare type Interpolations<TProps extends unknown> = (BasicTemplateInterpolations | FunctionIterpolation<TProps> | CssObject<TProps> | CssObject<TProps>[])[];
13
+ export declare type Interpolations<TProps extends unknown> = (BasicTemplateInterpolations | FunctionInterpolation<TProps> | CssObject<TProps> | CssObject<TProps>[])[];
17
14
  /**
18
15
  * This allows us to take the generic `TTag` (that will be a valid `DOM` tag) and then use it to
19
16
  * define correct props based on it from `JSX.IntrinsicElements`, while also injecting our own
@@ -5,14 +5,11 @@
5
5
  * @flow
6
6
  */
7
7
  import type { ComponentType } from 'react';
8
- import type { BasicTemplateInterpolations, CssFunction, CSSProps } from '../types';
9
- export interface FunctionIterpolation<TProps> {
10
- (props: TProps): CSSProps | string | number | boolean | void;
11
- }
8
+ import type { BasicTemplateInterpolations, CssFunction, FunctionInterpolation } from '../types';
12
9
  /**
13
10
  * Typing for the CSS object.
14
11
  */
15
- export type CssObject<TProps> = CssFunction<FunctionIterpolation<TProps>>;
12
+ export type CssObject<TProps> = CssFunction<FunctionInterpolation<TProps>>;
16
13
  /**
17
14
  * Extra props added to the output Styled Component.
18
15
  */
@@ -21,7 +18,7 @@ export type StyledProps = {
21
18
  };
22
19
  export type Interpolations<TProps: mixed> = (
23
20
  | BasicTemplateInterpolations
24
- | FunctionIterpolation<TProps>
21
+ | FunctionInterpolation<TProps>
25
22
  | CssObject<TProps>
26
23
  | CssObject<TProps>[]
27
24
  )[];
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/styled/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AA6DlD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,IAAM,MAAM,GAAgC,IAAI,KAAK,CAC1D,EAAE,EACF;IACE,GAAG;QACD,OAAO;YACL,8CAA8C;YAC9C,yDAAyD;YACzD,MAAM,gBAAgB,EAAE,CAAC;QAC3B,CAAC,CAAC;IACJ,CAAC;CACF,CACK,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/styled/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAyDlD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,IAAM,MAAM,GAAgC,IAAI,KAAK,CAC1D,EAAE,EACF;IACE,GAAG;QACD,OAAO;YACL,8CAA8C;YAC9C,yDAAyD;YACzD,MAAM,gBAAgB,EAAE,CAAC;QAC3B,CAAC,CAAC;IACJ,CAAC;CACF,CACK,CAAC"}
@@ -3,11 +3,14 @@ import type * as CSS from 'csstype';
3
3
  * Typing for the interpolations.
4
4
  */
5
5
  export declare type BasicTemplateInterpolations = string | number;
6
+ export interface FunctionInterpolation<TProps> {
7
+ (props: TProps): CSSProps | BasicTemplateInterpolations | boolean | undefined;
8
+ }
6
9
  /**
7
10
  * These are all the CSS props that will exist.
8
11
  */
9
- export declare type CSSProps = CSS.Properties<string | number>;
12
+ export declare type CSSProps = CSS.Properties<BasicTemplateInterpolations>;
10
13
  export declare type AnyKeyCssProps<TValue> = {
11
- [key: string]: AnyKeyCssProps<TValue> | CSSProps | string | number | TValue;
14
+ [key: string]: AnyKeyCssProps<TValue> | CSSProps | BasicTemplateInterpolations | TValue;
12
15
  };
13
16
  export declare type CssFunction<TValue = void> = CSSProps | AnyKeyCssProps<TValue> | TemplateStringsArray | string | boolean | undefined;
@@ -9,12 +9,15 @@ import * as CSS from 'csstype';
9
9
  * Typing for the interpolations.
10
10
  */
11
11
  export type BasicTemplateInterpolations = string | number;
12
+ export interface FunctionInterpolation<TProps> {
13
+ (props: TProps): CSSProps | BasicTemplateInterpolations | boolean | void;
14
+ }
12
15
  /**
13
16
  * These are all the CSS props that will exist.
14
17
  */
15
- export type CSSProps = CSS.Properties<string | number>;
18
+ export type CSSProps = CSS.Properties<BasicTemplateInterpolations>;
16
19
  export type AnyKeyCssProps<TValue> = {
17
- [key: string]: AnyKeyCssProps<TValue> | CSSProps | string | number | TValue,
20
+ [key: string]: AnyKeyCssProps<TValue> | CSSProps | BasicTemplateInterpolations | TValue,
18
21
  ...
19
22
  };
20
23
  export type CssFunction<TValue = void> =
@@ -1,4 +1,4 @@
1
- import type { CSSProps } from '../types';
1
+ import type { BasicTemplateInterpolations, CSSProps, FunctionInterpolation } from '../types';
2
2
  /**
3
3
  * Create styles that can be re-used between components with a template literal.
4
4
  *
@@ -12,7 +12,7 @@ import type { CSSProps } from '../types';
12
12
  * @param css
13
13
  * @param values
14
14
  */
15
- export default function css(_css: TemplateStringsArray, ..._values: (string | number)[]): CSSProps;
15
+ export default function css<T = void>(_css: TemplateStringsArray, ..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]): CSSProps;
16
16
  /**
17
17
  * Create styles that can be re-used between components with an object
18
18
  *
@@ -4,7 +4,7 @@
4
4
  * Flowgen v1.14.1
5
5
  * @flow
6
6
  */
7
- import type { CSSProps } from '../types';
7
+ import type { BasicTemplateInterpolations, CSSProps, FunctionInterpolation } from '../types';
8
8
  /**
9
9
  * Create styles that can be re-used between components with a template literal.
10
10
  *
@@ -17,9 +17,9 @@ import type { CSSProps } from '../types';
17
17
  * @param css
18
18
  * @param values
19
19
  */
20
- declare export default function css(
20
+ declare export default function css<T>(
21
21
  _css: $ReadOnlyArray<string>,
22
- ..._values: (string | number)[]
22
+ ..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
23
23
  ): CSSProps;
24
24
  /**
25
25
  * Create styles that can be re-used between components with an object
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/css/index.tsx"],"names":[],"mappings":";;AAAA,wCAAkD;AAgClD,SAAwB,GAAG,CACzB,IAAqC;IACrC,iBAA+B;SAA/B,UAA+B,EAA/B,qBAA+B,EAA/B,IAA+B;QAA/B,gCAA+B;;IAE/B,MAAM,wBAAgB,EAAE,CAAC;AAC3B,CAAC;AALD,sBAKC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/css/index.tsx"],"names":[],"mappings":";;AAAA,wCAAkD;AAmClD,SAAwB,GAAG,CACzB,IAAqC;IACrC,iBAAsE;SAAtE,UAAsE,EAAtE,qBAAsE,EAAtE,IAAsE;QAAtE,gCAAsE;;IAEtE,MAAM,wBAAgB,EAAE,CAAC;AAC3B,CAAC;AALD,sBAKC"}
@@ -1,2 +1 @@
1
- export declare const warn: (str: string, ...args: any[]) => void;
2
1
  export declare const analyzeCssInDev: (sheet: string) => void;
@@ -5,7 +5,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
5
5
  return to;
6
6
  };
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.analyzeCssInDev = exports.warn = void 0;
8
+ exports.analyzeCssInDev = void 0;
9
9
  var selectorsToWarn = [':first-child', ':nth-child'];
10
10
  var hasWarned = {};
11
11
  var warn = function (str) {
@@ -15,14 +15,13 @@ var warn = function (str) {
15
15
  }
16
16
  return console.error.apply(console, __spreadArray(["\n \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557\n\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\n\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2551\n\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u255D \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2551 \u2588\u2588\u2551\n\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u255A\u2550\u255D \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\n \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u255D\n\n @compiled/react/runtime - DEV WARNING\n\n " + str + "\n"], args));
17
17
  };
18
- exports.warn = warn;
19
18
  var analyzeCssInDev = function (sheet) {
20
19
  if (hasWarned[sheet]) {
21
20
  return;
22
21
  }
23
22
  var shouldWarnAboutSelectors = selectorsToWarn.map(function (selector) { return sheet.includes(selector); }).filter(Boolean).length > 0;
24
23
  if (shouldWarnAboutSelectors) {
25
- exports.warn("Selectors \"" + selectorsToWarn.join(', ') + "\" are dangerous to use when server side rendering.\n Alternatively try and use \":nth-of-type\", or placing data attributes and targetting those instead.\n Read https://compiledcssinjs.com/docs/server-side-rendering for more advice.");
24
+ warn("Selectors \"" + selectorsToWarn.join(', ') + "\" are dangerous to use when server side rendering.\n Alternatively try and use \":nth-of-type\", or placing data attributes and targetting those instead.\n Read https://compiledcssinjs.com/docs/server-side-rendering for more advice.");
26
25
  }
27
26
  hasWarned[sheet] = true;
28
27
  };
@@ -4,5 +4,4 @@
4
4
  * Flowgen v1.14.1
5
5
  * @flow
6
6
  */
7
- declare export var warn: (str: string, ...args: any[]) => void;
8
7
  declare export var analyzeCssInDev: (sheet: string) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"dev-warnings.js","sourceRoot":"","sources":["../../../src/runtime/dev-warnings.tsx"],"names":[],"mappings":";;;;;;;;AAAA,IAAM,eAAe,GAAG,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;AACvD,IAAM,SAAS,GAAyB,EAAE,CAAC;AAEpC,IAAM,IAAI,GAAG,UAAC,GAAW;IAAE,cAAc;SAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;QAAd,6BAAc;;IAC9C,OAAA,OAAO,CAAC,KAAK,OAAb,OAAO,iBACL,q6DAUA,GAAG,OACN,GACM,IAAI;AAbT,CAcC,CAAC;AAfS,QAAA,IAAI,QAeb;AAEG,IAAM,eAAe,GAAG,UAAC,KAAa;IAC3C,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE;QACpB,OAAO;KACR;IAED,IAAM,wBAAwB,GAC5B,eAAe,CAAC,GAAG,CAAC,UAAC,QAAQ,IAAK,OAAA,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAxB,CAAwB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAEzF,IAAI,wBAAwB,EAAE;QAC5B,YAAI,CACF,iBAAc,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,gPAEiC,CAC1E,CAAC;KACH;IAED,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;AAC1B,CAAC,CAAC;AAjBW,QAAA,eAAe,mBAiB1B"}
1
+ {"version":3,"file":"dev-warnings.js","sourceRoot":"","sources":["../../../src/runtime/dev-warnings.tsx"],"names":[],"mappings":";;;;;;;;AAAA,IAAM,eAAe,GAAG,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;AACvD,IAAM,SAAS,GAAyB,EAAE,CAAC;AAE3C,IAAM,IAAI,GAAG,UAAC,GAAW;IAAE,cAAc;SAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;QAAd,6BAAc;;IACvC,OAAA,OAAO,CAAC,KAAK,OAAb,OAAO,iBACL,q6DAUA,GAAG,OACN,GACM,IAAI;AAbT,CAcC,CAAC;AAEG,IAAM,eAAe,GAAG,UAAC,KAAa;IAC3C,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE;QACpB,OAAO;KACR;IAED,IAAM,wBAAwB,GAC5B,eAAe,CAAC,GAAG,CAAC,UAAC,QAAQ,IAAK,OAAA,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAxB,CAAwB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAEzF,IAAI,wBAAwB,EAAE;QAC5B,IAAI,CACF,iBAAc,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,gPAEiC,CAC1E,CAAC;KACH;IAED,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;AAC1B,CAAC,CAAC;AAjBW,QAAA,eAAe,mBAiB1B"}
@@ -1,19 +1,16 @@
1
1
  import type { ComponentType } from 'react';
2
- import type { BasicTemplateInterpolations, CssFunction, CSSProps } from '../types';
3
- export interface FunctionIterpolation<TProps> {
4
- (props: TProps): CSSProps | string | number | boolean | undefined;
5
- }
2
+ import type { BasicTemplateInterpolations, CssFunction, FunctionInterpolation } from '../types';
6
3
  /**
7
4
  * Typing for the CSS object.
8
5
  */
9
- export declare type CssObject<TProps> = CssFunction<FunctionIterpolation<TProps>>;
6
+ export declare type CssObject<TProps> = CssFunction<FunctionInterpolation<TProps>>;
10
7
  /**
11
8
  * Extra props added to the output Styled Component.
12
9
  */
13
10
  export interface StyledProps {
14
11
  as?: keyof JSX.IntrinsicElements;
15
12
  }
16
- export declare type Interpolations<TProps extends unknown> = (BasicTemplateInterpolations | FunctionIterpolation<TProps> | CssObject<TProps> | CssObject<TProps>[])[];
13
+ export declare type Interpolations<TProps extends unknown> = (BasicTemplateInterpolations | FunctionInterpolation<TProps> | CssObject<TProps> | CssObject<TProps>[])[];
17
14
  /**
18
15
  * This allows us to take the generic `TTag` (that will be a valid `DOM` tag) and then use it to
19
16
  * define correct props based on it from `JSX.IntrinsicElements`, while also injecting our own
@@ -5,14 +5,11 @@
5
5
  * @flow
6
6
  */
7
7
  import type { ComponentType } from 'react';
8
- import type { BasicTemplateInterpolations, CssFunction, CSSProps } from '../types';
9
- export interface FunctionIterpolation<TProps> {
10
- (props: TProps): CSSProps | string | number | boolean | void;
11
- }
8
+ import type { BasicTemplateInterpolations, CssFunction, FunctionInterpolation } from '../types';
12
9
  /**
13
10
  * Typing for the CSS object.
14
11
  */
15
- export type CssObject<TProps> = CssFunction<FunctionIterpolation<TProps>>;
12
+ export type CssObject<TProps> = CssFunction<FunctionInterpolation<TProps>>;
16
13
  /**
17
14
  * Extra props added to the output Styled Component.
18
15
  */
@@ -21,7 +18,7 @@ export type StyledProps = {
21
18
  };
22
19
  export type Interpolations<TProps: mixed> = (
23
20
  | BasicTemplateInterpolations
24
- | FunctionIterpolation<TProps>
21
+ | FunctionInterpolation<TProps>
25
22
  | CssObject<TProps>
26
23
  | CssObject<TProps>[]
27
24
  )[];
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/styled/index.tsx"],"names":[],"mappings":";;;AACA,wCAAkD;AA6DlD;;;;;;;;;;;;GAYG;AACU,QAAA,MAAM,GAAgC,IAAI,KAAK,CAC1D,EAAE,EACF;IACE,GAAG;QACD,OAAO;YACL,8CAA8C;YAC9C,yDAAyD;YACzD,MAAM,wBAAgB,EAAE,CAAC;QAC3B,CAAC,CAAC;IACJ,CAAC;CACF,CACK,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/styled/index.tsx"],"names":[],"mappings":";;;AACA,wCAAkD;AAyDlD;;;;;;;;;;;;GAYG;AACU,QAAA,MAAM,GAAgC,IAAI,KAAK,CAC1D,EAAE,EACF;IACE,GAAG;QACD,OAAO;YACL,8CAA8C;YAC9C,yDAAyD;YACzD,MAAM,wBAAgB,EAAE,CAAC;QAC3B,CAAC,CAAC;IACJ,CAAC;CACF,CACK,CAAC"}
@@ -3,11 +3,14 @@ import type * as CSS from 'csstype';
3
3
  * Typing for the interpolations.
4
4
  */
5
5
  export declare type BasicTemplateInterpolations = string | number;
6
+ export interface FunctionInterpolation<TProps> {
7
+ (props: TProps): CSSProps | BasicTemplateInterpolations | boolean | undefined;
8
+ }
6
9
  /**
7
10
  * These are all the CSS props that will exist.
8
11
  */
9
- export declare type CSSProps = CSS.Properties<string | number>;
12
+ export declare type CSSProps = CSS.Properties<BasicTemplateInterpolations>;
10
13
  export declare type AnyKeyCssProps<TValue> = {
11
- [key: string]: AnyKeyCssProps<TValue> | CSSProps | string | number | TValue;
14
+ [key: string]: AnyKeyCssProps<TValue> | CSSProps | BasicTemplateInterpolations | TValue;
12
15
  };
13
16
  export declare type CssFunction<TValue = void> = CSSProps | AnyKeyCssProps<TValue> | TemplateStringsArray | string | boolean | undefined;
@@ -9,12 +9,15 @@ import * as CSS from 'csstype';
9
9
  * Typing for the interpolations.
10
10
  */
11
11
  export type BasicTemplateInterpolations = string | number;
12
+ export interface FunctionInterpolation<TProps> {
13
+ (props: TProps): CSSProps | BasicTemplateInterpolations | boolean | void;
14
+ }
12
15
  /**
13
16
  * These are all the CSS props that will exist.
14
17
  */
15
- export type CSSProps = CSS.Properties<string | number>;
18
+ export type CSSProps = CSS.Properties<BasicTemplateInterpolations>;
16
19
  export type AnyKeyCssProps<TValue> = {
17
- [key: string]: AnyKeyCssProps<TValue> | CSSProps | string | number | TValue,
20
+ [key: string]: AnyKeyCssProps<TValue> | CSSProps | BasicTemplateInterpolations | TValue,
18
21
  ...
19
22
  };
20
23
  export type CssFunction<TValue = void> =
@@ -1,4 +1,4 @@
1
- import type { CSSProps } from '../types';
1
+ import type { BasicTemplateInterpolations, CSSProps, FunctionInterpolation } from '../types';
2
2
  /**
3
3
  * Create styles that can be re-used between components with a template literal.
4
4
  *
@@ -12,7 +12,7 @@ import type { CSSProps } from '../types';
12
12
  * @param css
13
13
  * @param values
14
14
  */
15
- export default function css(_css: TemplateStringsArray, ..._values: (string | number)[]): CSSProps;
15
+ export default function css<T = void>(_css: TemplateStringsArray, ..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]): CSSProps;
16
16
  /**
17
17
  * Create styles that can be re-used between components with an object
18
18
  *
@@ -4,7 +4,7 @@
4
4
  * Flowgen v1.14.1
5
5
  * @flow
6
6
  */
7
- import type { CSSProps } from '../types';
7
+ import type { BasicTemplateInterpolations, CSSProps, FunctionInterpolation } from '../types';
8
8
  /**
9
9
  * Create styles that can be re-used between components with a template literal.
10
10
  *
@@ -17,9 +17,9 @@ import type { CSSProps } from '../types';
17
17
  * @param css
18
18
  * @param values
19
19
  */
20
- declare export default function css(
20
+ declare export default function css<T>(
21
21
  _css: $ReadOnlyArray<string>,
22
- ..._values: (string | number)[]
22
+ ..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
23
23
  ): CSSProps;
24
24
  /**
25
25
  * Create styles that can be re-used between components with an object
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/css/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAgClD,MAAM,CAAC,OAAO,UAAU,GAAG,CACzB,IAAqC;IACrC,iBAA+B;SAA/B,UAA+B,EAA/B,qBAA+B,EAA/B,IAA+B;QAA/B,gCAA+B;;IAE/B,MAAM,gBAAgB,EAAE,CAAC;AAC3B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/css/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAmClD,MAAM,CAAC,OAAO,UAAU,GAAG,CACzB,IAAqC;IACrC,iBAAsE;SAAtE,UAAsE,EAAtE,qBAAsE,EAAtE,IAAsE;QAAtE,gCAAsE;;IAEtE,MAAM,gBAAgB,EAAE,CAAC;AAC3B,CAAC"}
@@ -1,2 +1 @@
1
- export declare const warn: (str: string, ...args: any[]) => void;
2
1
  export declare const analyzeCssInDev: (sheet: string) => void;
@@ -5,7 +5,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from) {
5
5
  };
6
6
  var selectorsToWarn = [':first-child', ':nth-child'];
7
7
  var hasWarned = {};
8
- export var warn = function (str) {
8
+ var warn = function (str) {
9
9
  var args = [];
10
10
  for (var _i = 1; _i < arguments.length; _i++) {
11
11
  args[_i - 1] = arguments[_i];
@@ -4,5 +4,4 @@
4
4
  * Flowgen v1.14.1
5
5
  * @flow
6
6
  */
7
- declare export var warn: (str: string, ...args: any[]) => void;
8
7
  declare export var analyzeCssInDev: (sheet: string) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"dev-warnings.js","sourceRoot":"","sources":["../../../src/runtime/dev-warnings.tsx"],"names":[],"mappings":";;;;;AAAA,IAAM,eAAe,GAAG,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;AACvD,IAAM,SAAS,GAAyB,EAAE,CAAC;AAE3C,MAAM,CAAC,IAAM,IAAI,GAAG,UAAC,GAAW;IAAE,cAAc;SAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;QAAd,6BAAc;;IAC9C,OAAA,OAAO,CAAC,KAAK,OAAb,OAAO,iBACL,q6DAUA,GAAG,OACN,GACM,IAAI;AAbT,CAcC,CAAC;AAEJ,MAAM,CAAC,IAAM,eAAe,GAAG,UAAC,KAAa;IAC3C,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE;QACpB,OAAO;KACR;IAED,IAAM,wBAAwB,GAC5B,eAAe,CAAC,GAAG,CAAC,UAAC,QAAQ,IAAK,OAAA,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAxB,CAAwB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAEzF,IAAI,wBAAwB,EAAE;QAC5B,IAAI,CACF,iBAAc,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,gPAEiC,CAC1E,CAAC;KACH;IAED,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;AAC1B,CAAC,CAAC"}
1
+ {"version":3,"file":"dev-warnings.js","sourceRoot":"","sources":["../../../src/runtime/dev-warnings.tsx"],"names":[],"mappings":";;;;;AAAA,IAAM,eAAe,GAAG,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;AACvD,IAAM,SAAS,GAAyB,EAAE,CAAC;AAE3C,IAAM,IAAI,GAAG,UAAC,GAAW;IAAE,cAAc;SAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;QAAd,6BAAc;;IACvC,OAAA,OAAO,CAAC,KAAK,OAAb,OAAO,iBACL,q6DAUA,GAAG,OACN,GACM,IAAI;AAbT,CAcC,CAAC;AAEJ,MAAM,CAAC,IAAM,eAAe,GAAG,UAAC,KAAa;IAC3C,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE;QACpB,OAAO;KACR;IAED,IAAM,wBAAwB,GAC5B,eAAe,CAAC,GAAG,CAAC,UAAC,QAAQ,IAAK,OAAA,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAxB,CAAwB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAEzF,IAAI,wBAAwB,EAAE;QAC5B,IAAI,CACF,iBAAc,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,gPAEiC,CAC1E,CAAC;KACH;IAED,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;AAC1B,CAAC,CAAC"}
@@ -1,19 +1,16 @@
1
1
  import type { ComponentType } from 'react';
2
- import type { BasicTemplateInterpolations, CssFunction, CSSProps } from '../types';
3
- export interface FunctionIterpolation<TProps> {
4
- (props: TProps): CSSProps | string | number | boolean | undefined;
5
- }
2
+ import type { BasicTemplateInterpolations, CssFunction, FunctionInterpolation } from '../types';
6
3
  /**
7
4
  * Typing for the CSS object.
8
5
  */
9
- export declare type CssObject<TProps> = CssFunction<FunctionIterpolation<TProps>>;
6
+ export declare type CssObject<TProps> = CssFunction<FunctionInterpolation<TProps>>;
10
7
  /**
11
8
  * Extra props added to the output Styled Component.
12
9
  */
13
10
  export interface StyledProps {
14
11
  as?: keyof JSX.IntrinsicElements;
15
12
  }
16
- export declare type Interpolations<TProps extends unknown> = (BasicTemplateInterpolations | FunctionIterpolation<TProps> | CssObject<TProps> | CssObject<TProps>[])[];
13
+ export declare type Interpolations<TProps extends unknown> = (BasicTemplateInterpolations | FunctionInterpolation<TProps> | CssObject<TProps> | CssObject<TProps>[])[];
17
14
  /**
18
15
  * This allows us to take the generic `TTag` (that will be a valid `DOM` tag) and then use it to
19
16
  * define correct props based on it from `JSX.IntrinsicElements`, while also injecting our own
@@ -5,14 +5,11 @@
5
5
  * @flow
6
6
  */
7
7
  import type { ComponentType } from 'react';
8
- import type { BasicTemplateInterpolations, CssFunction, CSSProps } from '../types';
9
- export interface FunctionIterpolation<TProps> {
10
- (props: TProps): CSSProps | string | number | boolean | void;
11
- }
8
+ import type { BasicTemplateInterpolations, CssFunction, FunctionInterpolation } from '../types';
12
9
  /**
13
10
  * Typing for the CSS object.
14
11
  */
15
- export type CssObject<TProps> = CssFunction<FunctionIterpolation<TProps>>;
12
+ export type CssObject<TProps> = CssFunction<FunctionInterpolation<TProps>>;
16
13
  /**
17
14
  * Extra props added to the output Styled Component.
18
15
  */
@@ -21,7 +18,7 @@ export type StyledProps = {
21
18
  };
22
19
  export type Interpolations<TProps: mixed> = (
23
20
  | BasicTemplateInterpolations
24
- | FunctionIterpolation<TProps>
21
+ | FunctionInterpolation<TProps>
25
22
  | CssObject<TProps>
26
23
  | CssObject<TProps>[]
27
24
  )[];
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/styled/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AA6DlD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,IAAM,MAAM,GAAgC,IAAI,KAAK,CAC1D,EAAE,EACF;IACE,GAAG;QACD,OAAO;YACL,8CAA8C;YAC9C,yDAAyD;YACzD,MAAM,gBAAgB,EAAE,CAAC;QAC3B,CAAC,CAAC;IACJ,CAAC;CACF,CACK,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/styled/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAyDlD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,IAAM,MAAM,GAAgC,IAAI,KAAK,CAC1D,EAAE,EACF;IACE,GAAG;QACD,OAAO;YACL,8CAA8C;YAC9C,yDAAyD;YACzD,MAAM,gBAAgB,EAAE,CAAC;QAC3B,CAAC,CAAC;IACJ,CAAC;CACF,CACK,CAAC"}
@@ -3,11 +3,14 @@ import type * as CSS from 'csstype';
3
3
  * Typing for the interpolations.
4
4
  */
5
5
  export declare type BasicTemplateInterpolations = string | number;
6
+ export interface FunctionInterpolation<TProps> {
7
+ (props: TProps): CSSProps | BasicTemplateInterpolations | boolean | undefined;
8
+ }
6
9
  /**
7
10
  * These are all the CSS props that will exist.
8
11
  */
9
- export declare type CSSProps = CSS.Properties<string | number>;
12
+ export declare type CSSProps = CSS.Properties<BasicTemplateInterpolations>;
10
13
  export declare type AnyKeyCssProps<TValue> = {
11
- [key: string]: AnyKeyCssProps<TValue> | CSSProps | string | number | TValue;
14
+ [key: string]: AnyKeyCssProps<TValue> | CSSProps | BasicTemplateInterpolations | TValue;
12
15
  };
13
16
  export declare type CssFunction<TValue = void> = CSSProps | AnyKeyCssProps<TValue> | TemplateStringsArray | string | boolean | undefined;
@@ -9,12 +9,15 @@ import * as CSS from 'csstype';
9
9
  * Typing for the interpolations.
10
10
  */
11
11
  export type BasicTemplateInterpolations = string | number;
12
+ export interface FunctionInterpolation<TProps> {
13
+ (props: TProps): CSSProps | BasicTemplateInterpolations | boolean | void;
14
+ }
12
15
  /**
13
16
  * These are all the CSS props that will exist.
14
17
  */
15
- export type CSSProps = CSS.Properties<string | number>;
18
+ export type CSSProps = CSS.Properties<BasicTemplateInterpolations>;
16
19
  export type AnyKeyCssProps<TValue> = {
17
- [key: string]: AnyKeyCssProps<TValue> | CSSProps | string | number | TValue,
20
+ [key: string]: AnyKeyCssProps<TValue> | CSSProps | BasicTemplateInterpolations | TValue,
18
21
  ...
19
22
  };
20
23
  export type CssFunction<TValue = void> =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compiled/react",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "A familiar and performant compile time CSS-in-JS library for React.",
5
5
  "keywords": [
6
6
  "compiled",
@@ -4,7 +4,7 @@
4
4
  * Flowgen v1.14.1
5
5
  * @flow
6
6
  */
7
- import type { CSSProps } from '../types';
7
+ import type { BasicTemplateInterpolations, CSSProps, FunctionInterpolation } from '../types';
8
8
  /**
9
9
  * Create styles that can be re-used between components with a template literal.
10
10
  *
@@ -17,9 +17,9 @@ import type { CSSProps } from '../types';
17
17
  * @param css
18
18
  * @param values
19
19
  */
20
- declare export default function css(
20
+ declare export default function css<T>(
21
21
  _css: $ReadOnlyArray<string>,
22
- ..._values: (string | number)[]
22
+ ..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
23
23
  ): CSSProps;
24
24
  /**
25
25
  * Create styles that can be re-used between components with an object
package/src/css/index.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createSetupError } from '../utils/error';
2
- import type { CSSProps } from '../types';
2
+ import type { BasicTemplateInterpolations, CSSProps, FunctionInterpolation } from '../types';
3
3
 
4
4
  /**
5
5
  * Create styles that can be re-used between components with a template literal.
@@ -14,7 +14,10 @@ import type { CSSProps } from '../types';
14
14
  * @param css
15
15
  * @param values
16
16
  */
17
- export default function css(_css: TemplateStringsArray, ..._values: (string | number)[]): CSSProps;
17
+ export default function css<T = void>(
18
+ _css: TemplateStringsArray,
19
+ ..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
20
+ ): CSSProps;
18
21
 
19
22
  /**
20
23
  * Create styles that can be re-used between components with an object
@@ -30,9 +33,9 @@ export default function css(_css: TemplateStringsArray, ..._values: (string | nu
30
33
  */
31
34
  export default function css(_css: CSSProps): CSSProps;
32
35
 
33
- export default function css(
36
+ export default function css<T = void>(
34
37
  _css: TemplateStringsArray | CSSProps,
35
- ..._values: (string | number)[]
38
+ ..._values: (BasicTemplateInterpolations | FunctionInterpolation<T>)[]
36
39
  ): CSSProps {
37
40
  throw createSetupError();
38
41
  }
@@ -1,103 +1,137 @@
1
1
  import React from 'react';
2
+ import type { ComponentType } from 'react';
2
3
  import { render } from '@testing-library/react';
3
- import Style from '../style';
4
4
 
5
5
  jest.mock('../is-node', () => ({
6
6
  isNodeEnvironment: () => false,
7
7
  }));
8
8
 
9
9
  describe('<Style />', () => {
10
+ let consoleErrorSpy: jest.SpyInstance;
11
+
10
12
  beforeEach(() => {
11
- // Reset style tags in head before each test so that it will remove styles
12
- // injected by test
13
- document.head.querySelectorAll('style').forEach((styleElement) => {
14
- styleElement.textContent = '';
15
- });
13
+ consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
14
+ });
15
+
16
+ afterEach(() => {
17
+ consoleErrorSpy.mockRestore();
18
+ document.head.innerHTML = '';
16
19
  });
17
20
 
21
+ // We want to isolate the test to correctly mimic the environment being loaded in once
22
+ const createIsolatedTest = (callback: (Style: ComponentType) => void) => {
23
+ jest.isolateModules(() => {
24
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
25
+ const Style = require('../style');
26
+
27
+ callback(Style.default);
28
+ });
29
+ };
30
+
18
31
  it('should render nothing on the client', () => {
19
- const { baseElement } = render(<Style>{[`.a { display: block; }`]}</Style>);
32
+ createIsolatedTest((Style) => {
33
+ const { baseElement } = render(<Style>{[`.a { display: block; }`]}</Style>);
20
34
 
21
- expect(baseElement.getElementsByTagName('style')).toHaveLength(0);
35
+ expect(baseElement.getElementsByTagName('style')).toHaveLength(0);
36
+ expect(console.error).not.toHaveBeenCalled();
37
+ });
22
38
  });
23
39
 
24
40
  it('should add style to the head on the client', () => {
25
- render(<Style>{[`.b { display: block; }`]}</Style>);
41
+ createIsolatedTest((Style) => {
42
+ render(<Style>{[`.b { display: block; }`]}</Style>);
26
43
 
27
- expect(document.head.innerHTML).toInclude('<style>.b { display: block; }</style>');
44
+ expect(document.head.innerHTML).toInclude('<style>.b { display: block; }</style>');
45
+ expect(console.error).not.toHaveBeenCalled();
46
+ });
28
47
  });
29
48
 
30
49
  it('should only add one style if it was already added', () => {
31
- render(<Style>{[`.c { display: block; }`]}</Style>);
32
- render(<Style>{[`.c { display: block; }`]}</Style>);
50
+ createIsolatedTest((Style) => {
51
+ render(<Style>{[`.c { display: block; }`]}</Style>);
52
+ render(<Style>{[`.c { display: block; }`]}</Style>);
33
53
 
34
- expect(document.head.innerHTML).toIncludeRepeated('<style>.c { display: block; }</style>', 1);
54
+ expect(document.head.innerHTML).toIncludeRepeated('<style>.c { display: block; }</style>', 1);
55
+ expect(console.error).not.toHaveBeenCalled();
56
+ });
35
57
  });
36
58
 
37
59
  it('should noop in prod', () => {
38
- jest.spyOn(console, 'error');
39
- process.env.NODE_ENV = 'production';
60
+ createIsolatedTest((Style) => {
61
+ process.env.NODE_ENV = 'production';
40
62
 
41
- render(<Style>{[`.c:first-child { display: block; }`]}</Style>);
63
+ render(<Style>{[`.c:first-child { display: block; }`]}</Style>);
42
64
 
43
- expect(console.error).not.toHaveBeenCalled();
65
+ expect(console.error).not.toHaveBeenCalled();
66
+ });
44
67
  });
45
68
 
46
69
  it('should warn in dev when using a dangerous pseduo selector', () => {
47
- jest.spyOn(console, 'error');
48
- process.env.NODE_ENV = 'development';
70
+ createIsolatedTest((Style) => {
71
+ process.env.NODE_ENV = 'development';
49
72
 
50
- render(<Style>{[`.c:first-child { display: block; }`]}</Style>);
73
+ render(<Style>{[`.c:first-child { display: block; }`]}</Style>);
51
74
 
52
- expect(console.error).toHaveBeenCalled();
75
+ expect(console.error).toHaveBeenCalledTimes(1);
76
+ });
53
77
  });
54
78
 
55
79
  it('should warn in dev only once', () => {
56
- jest.spyOn(console, 'error');
57
- process.env.NODE_ENV = 'development';
80
+ createIsolatedTest((Style) => {
81
+ process.env.NODE_ENV = 'development';
58
82
 
59
- render(<Style>{[`.c:first-child { display: block; }`]}</Style>);
60
- render(<Style>{[`.c:first-child { display: block; }`]}</Style>);
83
+ render(<Style>{[`.c:first-child { display: block; }`]}</Style>);
84
+ render(<Style>{[`.c:first-child { display: block; }`]}</Style>);
61
85
 
62
- expect(console.error).toHaveBeenCalledTimes(1);
86
+ expect(console.error).toHaveBeenCalledTimes(1);
87
+ expect(console.error).toHaveBeenCalledWith(
88
+ expect.stringMatching('Selectors ":first-child, :nth-child" are dangerous to use')
89
+ );
90
+ });
63
91
  });
64
92
 
65
93
  it('should render style tags in buckets', () => {
66
- render(
67
- <Style>
68
- {[
69
- `._a1234567:hover{ color: red; }`,
70
- `._b1234567:active{ color: blue; }`,
71
- `._c1234567:link{ color: green; }`,
72
- `._d1234567{ display: block; }`,
73
- `@media (max-width: 800px){ ._e1234567{ color: yellow; } }`,
74
- `._f1234567:focus{ color: pink; }`,
75
- `._g1234567:visited{ color: grey; }`,
76
- `._h1234567:focus-visible{ color: white; }`,
77
- `._i1234567:focus-within{ color: black; }`,
78
- ]}
79
- </Style>
80
- );
81
-
82
- expect(document.head.innerHTML.split('</style>').join('</style>\n')).toMatchInlineSnapshot(`
83
- "<style>._d1234567{ display: block; }</style>
84
- <style>._c1234567:link{ color: green; }</style>
85
- <style>._g1234567:visited{ color: grey; }</style>
86
- <style>._i1234567:focus-within{ color: black; }</style>
87
- <style>._f1234567:focus{ color: pink; }</style>
88
- <style>._h1234567:focus-visible{ color: white; }</style>
89
- <style>._a1234567:hover{ color: red; }</style>
90
- <style>._b1234567:active{ color: blue; }</style>
91
- <style>@media (max-width: 800px){ ._e1234567{ color: yellow; } }</style>
92
- "
93
- `);
94
+ createIsolatedTest((Style) => {
95
+ render(
96
+ <Style>
97
+ {[
98
+ `._a1234567:hover{ color: red; }`,
99
+ `._b1234567:active{ color: blue; }`,
100
+ `._c1234567:link{ color: green; }`,
101
+ `._d1234567{ display: block; }`,
102
+ `@media (max-width: 800px){ ._e1234567{ color: yellow; } }`,
103
+ `._f1234567:focus{ color: pink; }`,
104
+ `._g1234567:visited{ color: grey; }`,
105
+ `._h1234567:focus-visible{ color: white; }`,
106
+ `._i1234567:focus-within{ color: black; }`,
107
+ ]}
108
+ </Style>
109
+ );
110
+
111
+ expect(document.head.innerHTML.split('</style>').join('</style>\n')).toMatchInlineSnapshot(`
112
+ "<style>._d1234567{ display: block; }</style>
113
+ <style>._c1234567:link{ color: green; }</style>
114
+ <style>._g1234567:visited{ color: grey; }</style>
115
+ <style>._i1234567:focus-within{ color: black; }</style>
116
+ <style>._f1234567:focus{ color: pink; }</style>
117
+ <style>._h1234567:focus-visible{ color: white; }</style>
118
+ <style>._a1234567:hover{ color: red; }</style>
119
+ <style>._b1234567:active{ color: blue; }</style>
120
+ <style>@media (max-width: 800px){ ._e1234567{ color: yellow; } }</style>
121
+ "
122
+ `);
123
+ expect(console.error).not.toHaveBeenCalled();
124
+ });
94
125
  });
95
126
 
96
127
  it('should update styles', () => {
97
- const { rerender } = render(<Style>{[`.first-render { display: block; }`]}</Style>);
128
+ createIsolatedTest((Style) => {
129
+ const { rerender } = render(<Style>{[`.first-render { display: block; }`]}</Style>);
98
130
 
99
- rerender(<Style>{[`.second-render { display: block; }`]}</Style>);
131
+ rerender(<Style>{[`.second-render { display: block; }`]}</Style>);
100
132
 
101
- expect(document.head.innerHTML).toInclude('.second-render { display: block; }');
133
+ expect(document.head.innerHTML).toInclude('.second-render { display: block; }');
134
+ expect(console.error).not.toHaveBeenCalled();
135
+ });
102
136
  });
103
137
  });
@@ -4,5 +4,4 @@
4
4
  * Flowgen v1.14.1
5
5
  * @flow
6
6
  */
7
- declare export var warn: (str: string, ...args: any[]) => void;
8
7
  declare export var analyzeCssInDev: (sheet: string) => void;
@@ -1,7 +1,7 @@
1
1
  const selectorsToWarn = [':first-child', ':nth-child'];
2
2
  const hasWarned: Record<string, true> = {};
3
3
 
4
- export const warn = (str: string, ...args: any[]): void =>
4
+ const warn = (str: string, ...args: any[]): void =>
5
5
  console.error(
6
6
  `
7
7
  ██████╗ ██████╗ ███╗ ███╗██████╗ ██╗██╗ ███████╗██████╗
@@ -5,14 +5,11 @@
5
5
  * @flow
6
6
  */
7
7
  import type { ComponentType } from 'react';
8
- import type { BasicTemplateInterpolations, CssFunction, CSSProps } from '../types';
9
- export interface FunctionIterpolation<TProps> {
10
- (props: TProps): CSSProps | string | number | boolean | void;
11
- }
8
+ import type { BasicTemplateInterpolations, CssFunction, FunctionInterpolation } from '../types';
12
9
  /**
13
10
  * Typing for the CSS object.
14
11
  */
15
- export type CssObject<TProps> = CssFunction<FunctionIterpolation<TProps>>;
12
+ export type CssObject<TProps> = CssFunction<FunctionInterpolation<TProps>>;
16
13
  /**
17
14
  * Extra props added to the output Styled Component.
18
15
  */
@@ -21,7 +18,7 @@ export type StyledProps = {
21
18
  };
22
19
  export type Interpolations<TProps: mixed> = (
23
20
  | BasicTemplateInterpolations
24
- | FunctionIterpolation<TProps>
21
+ | FunctionInterpolation<TProps>
25
22
  | CssObject<TProps>
26
23
  | CssObject<TProps>[]
27
24
  )[];
@@ -1,15 +1,11 @@
1
1
  import type { ComponentType } from 'react';
2
2
  import { createSetupError } from '../utils/error';
3
- import type { BasicTemplateInterpolations, CssFunction, CSSProps } from '../types';
4
-
5
- export interface FunctionIterpolation<TProps> {
6
- (props: TProps): CSSProps | string | number | boolean | undefined;
7
- }
3
+ import type { BasicTemplateInterpolations, CssFunction, FunctionInterpolation } from '../types';
8
4
 
9
5
  /**
10
6
  * Typing for the CSS object.
11
7
  */
12
- export type CssObject<TProps> = CssFunction<FunctionIterpolation<TProps>>;
8
+ export type CssObject<TProps> = CssFunction<FunctionInterpolation<TProps>>;
13
9
 
14
10
  /**
15
11
  * Extra props added to the output Styled Component.
@@ -20,7 +16,7 @@ export interface StyledProps {
20
16
 
21
17
  export type Interpolations<TProps extends unknown> = (
22
18
  | BasicTemplateInterpolations
23
- | FunctionIterpolation<TProps>
19
+ | FunctionInterpolation<TProps>
24
20
  | CssObject<TProps>
25
21
  | CssObject<TProps>[]
26
22
  )[];
package/src/types.js.flow CHANGED
@@ -9,12 +9,15 @@ import * as CSS from 'csstype';
9
9
  * Typing for the interpolations.
10
10
  */
11
11
  export type BasicTemplateInterpolations = string | number;
12
+ export interface FunctionInterpolation<TProps> {
13
+ (props: TProps): CSSProps | BasicTemplateInterpolations | boolean | void;
14
+ }
12
15
  /**
13
16
  * These are all the CSS props that will exist.
14
17
  */
15
- export type CSSProps = CSS.Properties<string | number>;
18
+ export type CSSProps = CSS.Properties<BasicTemplateInterpolations>;
16
19
  export type AnyKeyCssProps<TValue> = {
17
- [key: string]: AnyKeyCssProps<TValue> | CSSProps | string | number | TValue,
20
+ [key: string]: AnyKeyCssProps<TValue> | CSSProps | BasicTemplateInterpolations | TValue,
18
21
  ...
19
22
  };
20
23
  export type CssFunction<TValue = void> =
package/src/types.tsx CHANGED
@@ -5,13 +5,17 @@ import type * as CSS from 'csstype';
5
5
  */
6
6
  export type BasicTemplateInterpolations = string | number;
7
7
 
8
+ export interface FunctionInterpolation<TProps> {
9
+ (props: TProps): CSSProps | BasicTemplateInterpolations | boolean | undefined;
10
+ }
11
+
8
12
  /**
9
13
  * These are all the CSS props that will exist.
10
14
  */
11
- export type CSSProps = CSS.Properties<string | number>;
15
+ export type CSSProps = CSS.Properties<BasicTemplateInterpolations>;
12
16
 
13
17
  export type AnyKeyCssProps<TValue> = {
14
- [key: string]: AnyKeyCssProps<TValue> | CSSProps | string | number | TValue;
18
+ [key: string]: AnyKeyCssProps<TValue> | CSSProps | BasicTemplateInterpolations | TValue;
15
19
  };
16
20
 
17
21
  export type CssFunction<TValue = void> =