@compiled/react 0.13.1 → 0.15.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 (120) hide show
  1. package/dist/browser/class-names/index.js.flow +1 -1
  2. package/dist/browser/css/index.js.flow +1 -1
  3. package/dist/browser/css-map/index.d.ts +112 -0
  4. package/dist/browser/css-map/index.js +22 -0
  5. package/dist/browser/css-map/index.js.flow +125 -0
  6. package/dist/browser/css-map/index.js.map +1 -0
  7. package/dist/browser/css-map/pseudos.d.ts +1 -0
  8. package/dist/browser/css-map/pseudos.js +5 -0
  9. package/dist/browser/css-map/pseudos.js.flow +57 -0
  10. package/dist/browser/css-map/pseudos.js.map +1 -0
  11. package/dist/browser/index.d.ts +1 -0
  12. package/dist/browser/index.js +1 -0
  13. package/dist/browser/index.js.flow +2 -1
  14. package/dist/browser/index.js.map +1 -1
  15. package/dist/browser/keyframes/index.js.flow +1 -1
  16. package/dist/browser/runtime/ac.js.flow +1 -1
  17. package/dist/browser/runtime/ax.js.flow +1 -1
  18. package/dist/browser/runtime/cache.js.flow +1 -1
  19. package/dist/browser/runtime/css-custom-property.js.flow +1 -1
  20. package/dist/browser/runtime/dev-warnings.js.flow +1 -1
  21. package/dist/browser/runtime/index.js.flow +1 -1
  22. package/dist/browser/runtime/is-server-environment.js.flow +1 -1
  23. package/dist/browser/runtime/sheet.js.flow +1 -1
  24. package/dist/browser/runtime/style-cache.js.flow +1 -1
  25. package/dist/browser/runtime/style.js.flow +1 -1
  26. package/dist/browser/runtime/types.js.flow +1 -1
  27. package/dist/browser/runtime.js.flow +1 -1
  28. package/dist/browser/styled/index.js.flow +1 -1
  29. package/dist/browser/types.d.ts +3 -3
  30. package/dist/browser/types.js.flow +4 -4
  31. package/dist/browser/utils/error.js.flow +1 -1
  32. package/dist/cjs/class-names/index.js.flow +1 -1
  33. package/dist/cjs/css/index.js.flow +1 -1
  34. package/dist/cjs/css-map/index.d.ts +112 -0
  35. package/dist/cjs/css-map/index.js +25 -0
  36. package/dist/cjs/css-map/index.js.flow +125 -0
  37. package/dist/cjs/css-map/index.js.map +1 -0
  38. package/dist/cjs/css-map/pseudos.d.ts +1 -0
  39. package/dist/cjs/css-map/pseudos.js +6 -0
  40. package/dist/cjs/css-map/pseudos.js.flow +57 -0
  41. package/dist/cjs/css-map/pseudos.js.map +1 -0
  42. package/dist/cjs/index.d.ts +1 -0
  43. package/dist/cjs/index.js +3 -1
  44. package/dist/cjs/index.js.flow +2 -1
  45. package/dist/cjs/index.js.map +1 -1
  46. package/dist/cjs/keyframes/index.js.flow +1 -1
  47. package/dist/cjs/runtime/ac.js.flow +1 -1
  48. package/dist/cjs/runtime/ax.js.flow +1 -1
  49. package/dist/cjs/runtime/cache.js.flow +1 -1
  50. package/dist/cjs/runtime/css-custom-property.js.flow +1 -1
  51. package/dist/cjs/runtime/dev-warnings.js.flow +1 -1
  52. package/dist/cjs/runtime/index.js.flow +1 -1
  53. package/dist/cjs/runtime/is-server-environment.js.flow +1 -1
  54. package/dist/cjs/runtime/sheet.js.flow +1 -1
  55. package/dist/cjs/runtime/style-cache.js.flow +1 -1
  56. package/dist/cjs/runtime/style.js.flow +1 -1
  57. package/dist/cjs/runtime/types.js.flow +1 -1
  58. package/dist/cjs/runtime.js.flow +1 -1
  59. package/dist/cjs/styled/index.js.flow +1 -1
  60. package/dist/cjs/types.d.ts +3 -3
  61. package/dist/cjs/types.js.flow +4 -4
  62. package/dist/cjs/utils/error.js.flow +1 -1
  63. package/dist/esm/class-names/index.js.flow +1 -1
  64. package/dist/esm/css/index.js.flow +1 -1
  65. package/dist/esm/css-map/index.d.ts +112 -0
  66. package/dist/esm/css-map/index.js +22 -0
  67. package/dist/esm/css-map/index.js.flow +125 -0
  68. package/dist/esm/css-map/index.js.map +1 -0
  69. package/dist/esm/css-map/pseudos.d.ts +1 -0
  70. package/dist/esm/css-map/pseudos.js +5 -0
  71. package/dist/esm/css-map/pseudos.js.flow +57 -0
  72. package/dist/esm/css-map/pseudos.js.map +1 -0
  73. package/dist/esm/index.d.ts +1 -0
  74. package/dist/esm/index.js +1 -0
  75. package/dist/esm/index.js.flow +2 -1
  76. package/dist/esm/index.js.map +1 -1
  77. package/dist/esm/keyframes/index.js.flow +1 -1
  78. package/dist/esm/runtime/ac.js.flow +1 -1
  79. package/dist/esm/runtime/ax.js.flow +1 -1
  80. package/dist/esm/runtime/cache.js.flow +1 -1
  81. package/dist/esm/runtime/css-custom-property.js.flow +1 -1
  82. package/dist/esm/runtime/dev-warnings.js.flow +1 -1
  83. package/dist/esm/runtime/index.js.flow +1 -1
  84. package/dist/esm/runtime/is-server-environment.js.flow +1 -1
  85. package/dist/esm/runtime/sheet.js.flow +1 -1
  86. package/dist/esm/runtime/style-cache.js.flow +1 -1
  87. package/dist/esm/runtime/style.js.flow +1 -1
  88. package/dist/esm/runtime/types.js.flow +1 -1
  89. package/dist/esm/runtime.js.flow +1 -1
  90. package/dist/esm/styled/index.js.flow +1 -1
  91. package/dist/esm/types.d.ts +3 -3
  92. package/dist/esm/types.js.flow +4 -4
  93. package/dist/esm/utils/error.js.flow +1 -1
  94. package/package.json +3 -3
  95. package/src/class-names/index.js.flow +1 -1
  96. package/src/css/index.js.flow +1 -1
  97. package/src/css-map/__tests__/index.test.tsx +52 -0
  98. package/src/css-map/index.js.flow +125 -0
  99. package/src/css-map/index.ts +126 -0
  100. package/src/css-map/pseudos.js.flow +57 -0
  101. package/src/css-map/pseudos.ts +59 -0
  102. package/src/index.js.flow +2 -1
  103. package/src/index.ts +1 -0
  104. package/src/keyframes/index.js.flow +1 -1
  105. package/src/runtime/ac.js.flow +1 -1
  106. package/src/runtime/ax.js.flow +1 -1
  107. package/src/runtime/cache.js.flow +1 -1
  108. package/src/runtime/css-custom-property.js.flow +1 -1
  109. package/src/runtime/dev-warnings.js.flow +1 -1
  110. package/src/runtime/index.js.flow +1 -1
  111. package/src/runtime/is-server-environment.js.flow +1 -1
  112. package/src/runtime/sheet.js.flow +1 -1
  113. package/src/runtime/style-cache.js.flow +1 -1
  114. package/src/runtime/style.js.flow +1 -1
  115. package/src/runtime/types.js.flow +1 -1
  116. package/src/runtime.js.flow +1 -1
  117. package/src/styled/index.js.flow +1 -1
  118. package/src/types.js.flow +4 -4
  119. package/src/types.ts +3 -3
  120. package/src/utils/error.js.flow +1 -1
@@ -0,0 +1,112 @@
1
+ import type { Properties, AtRules } from 'csstype';
2
+ import type { Pseudos } from './pseudos';
3
+ /**
4
+ * These are all the CSS props that will exist.
5
+ * Only 'string' and 'number' are valid CSS values.
6
+ *
7
+ * @example
8
+ * ```
9
+ * const style: CssProps = {
10
+ * color: 'red',
11
+ * margin: 10,
12
+ * };
13
+ * ```
14
+ */
15
+ type CssProps = Readonly<Properties<string | number>>;
16
+ type AllPseudos = {
17
+ [key in Pseudos]?: CssProps & AllPseudos;
18
+ };
19
+ type AtRuleSecondHalf = string;
20
+ type WhitelistedAtRule = {
21
+ [atRuleFirstHalf in AtRules]?: {
22
+ [atRuleSecondHalf in AtRuleSecondHalf]: CssProps & AllPseudos & WhitelistedAtRule;
23
+ };
24
+ };
25
+ type WhitelistedSelector = AllPseudos & WhitelistedAtRule;
26
+ type ExtendedSelector = {
27
+ [key: string]: CssProps | ExtendedSelector;
28
+ } & {
29
+ /**
30
+ * Using `selectors` is not valid here - you cannot nest a `selectors` object
31
+ * inside another `selectors` object.
32
+ */
33
+ selectors?: never;
34
+ };
35
+ type ExtendedSelectors = {
36
+ /**
37
+ * Provides a way to use selectors that have not been explicitly whitelisted
38
+ * in cssMap.
39
+ *
40
+ * This does not provide any type-checking for the selectors (thus allowing
41
+ * more expressive selectors), though this is more flexible and allows
42
+ * nesting selectors in other selectors.
43
+ *
44
+ * A selector defined both outside of the `selectors` object and
45
+ * inside the `selectors` object is a runtime error.
46
+ *
47
+ * Note that you cannot nest a `selectors` object inside another
48
+ * `selectors` object.
49
+ *
50
+ * Only use if absolutely necessary.
51
+ *
52
+ * @example
53
+ * ```
54
+ * const myMap = cssMap({
55
+ * danger: {
56
+ * color: 'red',
57
+ * '@media': {
58
+ * '(min-width: 100px)': {
59
+ * font-size: '1.5em',
60
+ * },
61
+ * },
62
+ * '&:hover': {
63
+ * color: 'pink',
64
+ * },
65
+ * selectors: {
66
+ * '&:not(:active)': {
67
+ * backgroundColor: 'yellow',
68
+ * }
69
+ * },
70
+ * },
71
+ * success: {
72
+ * color: 'green',
73
+ * '@media': {
74
+ * '(min-width: 100px)': {
75
+ * font-size: '1.3em',
76
+ * },
77
+ * },
78
+ * '&:hover': {
79
+ * color: '#8f8',
80
+ * },
81
+ * selectors: {
82
+ * '&:not(:active)': {
83
+ * backgroundColor: 'white',
84
+ * }
85
+ * },
86
+ * },
87
+ * });
88
+ * ```
89
+ */
90
+ selectors?: ExtendedSelector;
91
+ };
92
+ type Variants<VariantName extends string> = Record<VariantName, CssProps & WhitelistedSelector & ExtendedSelectors>;
93
+ type ReturnType<VariantName extends string> = Record<VariantName, CssProps>;
94
+ /**
95
+ * ## cssMap
96
+ *
97
+ * Creates a collection of named CSS rules that are statically typed and useable with other Compiled APIs.
98
+ * For further details [read the documentation](https://compiledcssinjs.com/docs/api-cssmap).
99
+ *
100
+ * @example
101
+ * ```
102
+ * const borderStyleMap = cssMap({
103
+ * none: { borderStyle: 'none' },
104
+ * solid: { borderStyle: 'solid' },
105
+ * });
106
+ * const Component = ({ borderStyle }) => <div css={css(borderStyleMap[borderStyle])} />
107
+ *
108
+ * <Component borderStyle="solid" />
109
+ * ```
110
+ */
111
+ export default function cssMap<T extends string>(_styles: Variants<T>): Readonly<ReturnType<T>>;
112
+ export {};
@@ -0,0 +1,22 @@
1
+ import { createSetupError } from '../utils/error';
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
+ export default function cssMap(_styles) {
20
+ throw createSetupError();
21
+ }
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,125 @@
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 { Properties, AtRules } from 'csstype';
8
+ import type { Pseudos } from './pseudos';
9
+ /**
10
+ * These are all the CSS props that will exist.
11
+ * Only 'string' and 'number' are valid CSS values.
12
+ * @example ```
13
+ * const style: CssProps = {
14
+ * color: 'red',
15
+ * margin: 10,
16
+ * };
17
+ * ```
18
+ */
19
+ declare type CssProps = $ReadOnly<Properties<string | number>>;
20
+ declare type AllPseudos = $ObjMapi<
21
+ { [k: Pseudos]: any },
22
+ <key>(key) => { ...CssProps, ...AllPseudos }
23
+ >;
24
+ declare type AtRuleSecondHalf = string;
25
+ declare type WhitelistedAtRule = $ObjMapi<
26
+ { [k: AtRules]: any },
27
+ <atRuleFirstHalf>(atRuleFirstHalf) => $ObjMapi<
28
+ { [k: AtRuleSecondHalf]: any },
29
+ <atRuleSecondHalf>(atRuleSecondHalf) => {
30
+ ...CssProps,
31
+ ...AllPseudos,
32
+ ...WhitelistedAtRule,
33
+ }
34
+ >
35
+ >;
36
+ declare type WhitelistedSelector = { ...AllPseudos, ...WhitelistedAtRule };
37
+ declare type ExtendedSelector = {
38
+ ...{
39
+ [key: string]: CssProps | ExtendedSelector,
40
+ },
41
+ ...{
42
+ /**
43
+ * Using `selectors` is not valid here - you cannot nest a `selectors` object
44
+ * inside another `selectors` object.
45
+ */
46
+ selectors?: empty,
47
+ ...
48
+ },
49
+ };
50
+ declare type ExtendedSelectors = {
51
+ /**
52
+ * Provides a way to use selectors that have not been explicitly whitelisted
53
+ * in cssMap.
54
+ *
55
+ * This does not provide any type-checking for the selectors (thus allowing
56
+ * more expressive selectors), though this is more flexible and allows
57
+ * nesting selectors in other selectors.
58
+ *
59
+ * A selector defined both outside of the `selectors` object and
60
+ * inside the `selectors` object is a runtime error.
61
+ *
62
+ * Note that you cannot nest a `selectors` object inside another
63
+ * `selectors` object.
64
+ *
65
+ * Only use if absolutely necessary.
66
+ * @example ```
67
+ * const myMap = cssMap({
68
+ * danger: {
69
+ * color: 'red',
70
+ * '@media': {
71
+ * '(min-width: 100px)': {
72
+ * font-size: '1.5em',
73
+ * },
74
+ * },
75
+ * '&:hover': {
76
+ * color: 'pink',
77
+ * },
78
+ * selectors: {
79
+ * '&:not(:active)': {
80
+ * backgroundColor: 'yellow',
81
+ * }
82
+ * },
83
+ * },
84
+ * success: {
85
+ * color: 'green',
86
+ * '@media': {
87
+ * '(min-width: 100px)': {
88
+ * font-size: '1.3em',
89
+ * },
90
+ * },
91
+ * '&:hover': {
92
+ * color: '#8f8',
93
+ * },
94
+ * selectors: {
95
+ * '&:not(:active)': {
96
+ * backgroundColor: 'white',
97
+ * }
98
+ * },
99
+ * },
100
+ * });
101
+ * ```
102
+ */
103
+ selectors?: ExtendedSelector,
104
+ ...
105
+ };
106
+ declare type Variants<VariantName: string> = {
107
+ [key: VariantName]: { ...CssProps, ...WhitelistedSelector, ...ExtendedSelectors },
108
+ };
109
+ declare type ReturnType<VariantName: string> = { [key: VariantName]: CssProps };
110
+ /**
111
+ * ## cssMap
112
+ *
113
+ * Creates a collection of named CSS rules that are statically typed and useable with other Compiled APIs.
114
+ * For further details [read the documentation](https://compiledcssinjs.com/docs/api-cssmap).
115
+ * @example ```
116
+ * const borderStyleMap = cssMap({
117
+ * none: { borderStyle: 'none' },
118
+ * solid: { borderStyle: 'solid' },
119
+ * });
120
+ * const Component = ({ borderStyle }) => <div css={css(borderStyleMap[borderStyle])} />
121
+ *
122
+ * <Component borderStyle="solid" />
123
+ * ```
124
+ */
125
+ declare export default function cssMap<T: string>(_styles: Variants<T>): $ReadOnly<ReturnType<T>>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/css-map/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAuGlD;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,CAAC,OAAO,UAAU,MAAM,CAAmB,OAAoB;IACnE,MAAM,gBAAgB,EAAE,CAAC;AAC3B,CAAC"}
@@ -0,0 +1 @@
1
+ export type Pseudos = '&::after' | '&::backdrop' | '&::before' | '&::cue' | '&::cue-region' | '&::first-letter' | '&::first-line' | '&::grammar-error' | '&::marker' | '&::placeholder' | '&::selection' | '&::spelling-error' | '&::target-text' | '&::view-transition' | '&:active' | '&:autofill' | '&:blank' | '&:checked' | '&:default' | '&:defined' | '&:disabled' | '&:empty' | '&:enabled' | '&:first' | '&:focus' | '&:focus-visible' | '&:focus-within' | '&:fullscreen' | '&:hover' | '&:in-range' | '&:indeterminate' | '&:invalid' | '&:left' | '&:link' | '&:local-link' | '&:optional' | '&:out-of-range' | '&:paused' | '&:picture-in-picture' | '&:placeholder-shown' | '&:playing' | '&:read-only' | '&:read-write' | '&:required' | '&:right' | '&:target' | '&:user-invalid' | '&:user-valid' | '&:valid' | '&:visited';
@@ -0,0 +1,5 @@
1
+ // List of pseudo-classes and pseudo-elements are from csstype
2
+ // but with & added in the front, so that we target the current element
3
+ // (instead of a child element)
4
+ export {};
5
+ //# sourceMappingURL=pseudos.js.map
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Flowtype definitions for pseudos
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+ export type Pseudos =
8
+ | '&::after'
9
+ | '&::backdrop'
10
+ | '&::before'
11
+ | '&::cue'
12
+ | '&::cue-region'
13
+ | '&::first-letter'
14
+ | '&::first-line'
15
+ | '&::grammar-error'
16
+ | '&::marker'
17
+ | '&::placeholder'
18
+ | '&::selection'
19
+ | '&::spelling-error'
20
+ | '&::target-text'
21
+ | '&::view-transition'
22
+ | '&:active'
23
+ | '&:autofill'
24
+ | '&:blank'
25
+ | '&:checked'
26
+ | '&:default'
27
+ | '&:defined'
28
+ | '&:disabled'
29
+ | '&:empty'
30
+ | '&:enabled'
31
+ | '&:first'
32
+ | '&:focus'
33
+ | '&:focus-visible'
34
+ | '&:focus-within'
35
+ | '&:fullscreen'
36
+ | '&:hover'
37
+ | '&:in-range'
38
+ | '&:indeterminate'
39
+ | '&:invalid'
40
+ | '&:left'
41
+ | '&:link'
42
+ | '&:local-link'
43
+ | '&:optional'
44
+ | '&:out-of-range'
45
+ | '&:paused'
46
+ | '&:picture-in-picture'
47
+ | '&:placeholder-shown'
48
+ | '&:playing'
49
+ | '&:read-only'
50
+ | '&:read-write'
51
+ | '&:required'
52
+ | '&:right'
53
+ | '&:target'
54
+ | '&:user-invalid'
55
+ | '&:user-valid'
56
+ | '&:valid'
57
+ | '&:visited';
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pseudos.js","sourceRoot":"","sources":["../../../src/css-map/pseudos.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,uEAAuE;AACvE,+BAA+B"}
@@ -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;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for index
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.1
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';
@@ -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;AAEvC,0CAA0C;AAC1C,kGAAkG;AAClG,MAAM,CAAC,MAAM,GAAG,GAAG,aAAa,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"}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for index
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.1
4
+ * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
7
  import type { BasicTemplateInterpolations, CSSProps } from '../types';
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for ac
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.1
4
+ * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
7
  /**
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for ax
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.1
4
+ * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
7
  /**
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for cache
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.1
4
+ * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
7
  /**
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for css-custom-property
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.1
4
+ * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
7
  /**
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for dev-warnings
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.1
4
+ * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
7
  declare export var analyzeCssInDev: (sheet: string) => void;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for index
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.1
4
+ * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
7
  declare export { default as CS } from './style';
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for is-server-environment
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.1
4
+ * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
7
  /**
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for sheet
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.1
4
+ * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
7
  import type { Bucket, StyleSheetOpts } from './types';
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for style-cache
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.1
4
+ * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
7
  import type { ProviderComponent, UseCacheHook } from './types';
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for style
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.1
4
+ * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
7
  import type { StyleSheetOpts } from './types';
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for types
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.1
4
+ * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
7
  export interface StyleSheetOpts {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for runtime
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.1
4
+ * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
7
  declare export { CC, CS, ax, ac, clearAcCache, ix } from './runtime/index';
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for index
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.1
4
+ * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
7
  import type { ComponentType } from 'react';
@@ -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;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for types
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.1
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
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for error
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.1
4
+ * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
7
  declare export var createSetupError: () => Error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compiled/react",
3
- "version": "0.13.1",
3
+ "version": "0.15.0",
4
4
  "description": "A familiar and performant compile time CSS-in-JS library for React.",
5
5
  "keywords": [
6
6
  "compiled",
@@ -72,13 +72,13 @@
72
72
  "jsx-dev-runtime"
73
73
  ],
74
74
  "dependencies": {
75
- "csstype": "^3.1.1"
75
+ "csstype": "^3.1.2"
76
76
  },
77
77
  "devDependencies": {
78
78
  "@compiled/benchmark": "^1.1.0",
79
79
  "@testing-library/react": "^12.1.5",
80
80
  "@types/jsdom": "^16.2.15",
81
- "@types/react-dom": "^17.0.19",
81
+ "@types/react-dom": "^17.0.20",
82
82
  "jsdom": "^19.0.0",
83
83
  "react": "^17.0.2",
84
84
  "react-dom": "^17.0.2"
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for index
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.1
4
+ * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
7
  import type { Node } from 'react';
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Flowtype definitions for index
3
3
  * Generated by Flowgen from a Typescript Definition
4
- * Flowgen v1.20.1
4
+ * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
7
  import type { CSSProps, CssObject, CssFunction } from '../types';
@@ -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
+ });