@compiled/react 0.14.0 → 0.16.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/css-map/index.d.ts +94 -3
- package/dist/browser/css-map/index.js +17 -0
- package/dist/browser/css-map/index.js.map +1 -1
- package/dist/browser/css-map/pseudos.d.ts +1 -0
- package/dist/browser/css-map/pseudos.js +5 -0
- package/dist/browser/css-map/pseudos.js.map +1 -0
- package/dist/cjs/css-map/index.d.ts +94 -3
- package/dist/cjs/css-map/index.js +17 -0
- package/dist/cjs/css-map/index.js.map +1 -1
- package/dist/cjs/css-map/pseudos.d.ts +1 -0
- package/dist/cjs/css-map/pseudos.js +6 -0
- package/dist/cjs/css-map/pseudos.js.map +1 -0
- package/dist/esm/css-map/index.d.ts +94 -3
- package/dist/esm/css-map/index.js +17 -0
- package/dist/esm/css-map/index.js.map +1 -1
- package/dist/esm/css-map/pseudos.d.ts +1 -0
- package/dist/esm/css-map/pseudos.js +5 -0
- package/dist/esm/css-map/pseudos.js.map +1 -0
- package/package.json +2 -1
- package/src/css/__tests__/types.test.ts +11 -0
- package/src/css-map/index.ts +104 -5
- package/src/css-map/pseudos.ts +59 -0
- package/dist/browser/class-names/index.js.flow +0 -53
- package/dist/browser/css/index.js.flow +0 -36
- package/dist/browser/css-map/index.js.flow +0 -26
- package/dist/browser/index.js.flow +0 -13
- package/dist/browser/keyframes/index.js.flow +0 -48
- package/dist/browser/runtime/ac.js.flow +0 -56
- package/dist/browser/runtime/ax.js.flow +0 -27
- package/dist/browser/runtime/cache.js.flow +0 -18
- package/dist/browser/runtime/css-custom-property.js.flow +0 -19
- package/dist/browser/runtime/dev-warnings.js.flow +0 -7
- package/dist/browser/runtime/index.js.flow +0 -11
- package/dist/browser/runtime/is-server-environment.js.flow +0 -19
- package/dist/browser/runtime/sheet.js.flow +0 -36
- package/dist/browser/runtime/style-cache.js.flow +0 -19
- package/dist/browser/runtime/style.js.flow +0 -16
- package/dist/browser/runtime/types.js.flow +0 -23
- package/dist/browser/runtime.js.flow +0 -7
- package/dist/browser/styled/index.js.flow +0 -66
- package/dist/browser/types.js.flow +0 -31
- package/dist/browser/utils/error.js.flow +0 -7
- package/dist/cjs/class-names/index.js.flow +0 -53
- package/dist/cjs/css/index.js.flow +0 -36
- package/dist/cjs/css-map/index.js.flow +0 -26
- package/dist/cjs/index.js.flow +0 -13
- package/dist/cjs/keyframes/index.js.flow +0 -48
- package/dist/cjs/runtime/ac.js.flow +0 -56
- package/dist/cjs/runtime/ax.js.flow +0 -27
- package/dist/cjs/runtime/cache.js.flow +0 -18
- package/dist/cjs/runtime/css-custom-property.js.flow +0 -19
- package/dist/cjs/runtime/dev-warnings.js.flow +0 -7
- package/dist/cjs/runtime/index.js.flow +0 -11
- package/dist/cjs/runtime/is-server-environment.js.flow +0 -19
- package/dist/cjs/runtime/sheet.js.flow +0 -36
- package/dist/cjs/runtime/style-cache.js.flow +0 -19
- package/dist/cjs/runtime/style.js.flow +0 -16
- package/dist/cjs/runtime/types.js.flow +0 -23
- package/dist/cjs/runtime.js.flow +0 -7
- package/dist/cjs/styled/index.js.flow +0 -66
- package/dist/cjs/types.js.flow +0 -31
- package/dist/cjs/utils/error.js.flow +0 -7
- package/dist/esm/class-names/index.js.flow +0 -53
- package/dist/esm/css/index.js.flow +0 -36
- package/dist/esm/css-map/index.js.flow +0 -26
- package/dist/esm/index.js.flow +0 -13
- package/dist/esm/keyframes/index.js.flow +0 -48
- package/dist/esm/runtime/ac.js.flow +0 -56
- package/dist/esm/runtime/ax.js.flow +0 -27
- package/dist/esm/runtime/cache.js.flow +0 -18
- package/dist/esm/runtime/css-custom-property.js.flow +0 -19
- package/dist/esm/runtime/dev-warnings.js.flow +0 -7
- package/dist/esm/runtime/index.js.flow +0 -11
- package/dist/esm/runtime/is-server-environment.js.flow +0 -19
- package/dist/esm/runtime/sheet.js.flow +0 -36
- package/dist/esm/runtime/style-cache.js.flow +0 -19
- package/dist/esm/runtime/style.js.flow +0 -16
- package/dist/esm/runtime/types.js.flow +0 -23
- package/dist/esm/runtime.js.flow +0 -7
- package/dist/esm/styled/index.js.flow +0 -66
- package/dist/esm/types.js.flow +0 -31
- package/dist/esm/utils/error.js.flow +0 -7
- package/src/class-names/__tests__/types.test.js.flow +0 -35
- package/src/class-names/index.js.flow +0 -53
- package/src/css/__tests__/types.test.js.flow +0 -42
- package/src/css/index.js.flow +0 -36
- package/src/css-map/index.js.flow +0 -26
- package/src/index.js.flow +0 -13
- package/src/keyframes/__tests__/types.test.js.flow +0 -31
- package/src/keyframes/index.js.flow +0 -48
- package/src/runtime/ac.js.flow +0 -56
- package/src/runtime/ax.js.flow +0 -27
- package/src/runtime/cache.js.flow +0 -18
- package/src/runtime/css-custom-property.js.flow +0 -19
- package/src/runtime/dev-warnings.js.flow +0 -7
- package/src/runtime/index.js.flow +0 -11
- package/src/runtime/is-server-environment.js.flow +0 -19
- package/src/runtime/sheet.js.flow +0 -36
- package/src/runtime/style-cache.js.flow +0 -19
- package/src/runtime/style.js.flow +0 -16
- package/src/runtime/types.js.flow +0 -23
- package/src/runtime.js.flow +0 -7
- package/src/styled/__tests__/types.test.js.flow +0 -84
- package/src/styled/index.js.flow +0 -66
- package/src/types.js.flow +0 -31
- package/src/utils/error.js.flow +0 -7
|
@@ -1,4 +1,96 @@
|
|
|
1
|
-
import type {
|
|
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>;
|
|
2
94
|
/**
|
|
3
95
|
* ## cssMap
|
|
4
96
|
*
|
|
@@ -16,6 +108,5 @@ import type { CSSProps, CssObject } from '../types';
|
|
|
16
108
|
* <Component borderStyle="solid" />
|
|
17
109
|
* ```
|
|
18
110
|
*/
|
|
19
|
-
|
|
20
|
-
export default function cssMap<T extends string, TProps = unknown>(_styles: Record<T, CssObject<TProps> | CssObject<TProps>[]>): Readonly<returnType<T, TProps>>;
|
|
111
|
+
export default function cssMap<T extends string>(_styles: Variants<T>): Readonly<ReturnType<T>>;
|
|
21
112
|
export {};
|
|
@@ -1,4 +1,21 @@
|
|
|
1
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
|
+
*/
|
|
2
19
|
export default function cssMap(_styles) {
|
|
3
20
|
throw createSetupError();
|
|
4
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/css-map/index.ts"],"names":[],"mappings":"
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"pseudos.js","sourceRoot":"","sources":["../../../src/css-map/pseudos.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,uEAAuE;AACvE,+BAA+B"}
|
|
@@ -1,4 +1,96 @@
|
|
|
1
|
-
import type {
|
|
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>;
|
|
2
94
|
/**
|
|
3
95
|
* ## cssMap
|
|
4
96
|
*
|
|
@@ -16,6 +108,5 @@ import type { CSSProps, CssObject } from '../types';
|
|
|
16
108
|
* <Component borderStyle="solid" />
|
|
17
109
|
* ```
|
|
18
110
|
*/
|
|
19
|
-
|
|
20
|
-
export default function cssMap<T extends string, TProps = unknown>(_styles: Record<T, CssObject<TProps> | CssObject<TProps>[]>): Readonly<returnType<T, TProps>>;
|
|
111
|
+
export default function cssMap<T extends string>(_styles: Variants<T>): Readonly<ReturnType<T>>;
|
|
21
112
|
export {};
|
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const error_1 = require("../utils/error");
|
|
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
|
+
*/
|
|
4
21
|
function cssMap(_styles) {
|
|
5
22
|
throw (0, error_1.createSetupError)();
|
|
6
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/css-map/index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/css-map/index.ts"],"names":[],"mappings":";;AAEA,0CAAkD;AAuGlD;;;;;;;;;;;;;;;;GAgBG;AAEH,SAAwB,MAAM,CAAmB,OAAoB;IACnE,MAAM,IAAA,wBAAgB,GAAE,CAAC;AAC3B,CAAC;AAFD,yBAEC"}
|
|
@@ -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,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// List of pseudo-classes and pseudo-elements are from csstype
|
|
3
|
+
// but with & added in the front, so that we target the current element
|
|
4
|
+
// (instead of a child element)
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
//# sourceMappingURL=pseudos.js.map
|
|
@@ -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"}
|
|
@@ -1,4 +1,96 @@
|
|
|
1
|
-
import type {
|
|
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>;
|
|
2
94
|
/**
|
|
3
95
|
* ## cssMap
|
|
4
96
|
*
|
|
@@ -16,6 +108,5 @@ import type { CSSProps, CssObject } from '../types';
|
|
|
16
108
|
* <Component borderStyle="solid" />
|
|
17
109
|
* ```
|
|
18
110
|
*/
|
|
19
|
-
|
|
20
|
-
export default function cssMap<T extends string, TProps = unknown>(_styles: Record<T, CssObject<TProps> | CssObject<TProps>[]>): Readonly<returnType<T, TProps>>;
|
|
111
|
+
export default function cssMap<T extends string>(_styles: Variants<T>): Readonly<ReturnType<T>>;
|
|
21
112
|
export {};
|
|
@@ -1,4 +1,21 @@
|
|
|
1
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
|
+
*/
|
|
2
19
|
export default function cssMap(_styles) {
|
|
3
20
|
throw createSetupError();
|
|
4
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/css-map/index.ts"],"names":[],"mappings":"
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"pseudos.js","sourceRoot":"","sources":["../../../src/css-map/pseudos.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,uEAAuE;AACvE,+BAA+B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compiled/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "A familiar and performant compile time CSS-in-JS library for React.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compiled",
|
|
@@ -79,6 +79,7 @@
|
|
|
79
79
|
"@testing-library/react": "^12.1.5",
|
|
80
80
|
"@types/jsdom": "^16.2.15",
|
|
81
81
|
"@types/react-dom": "^17.0.20",
|
|
82
|
+
"expect-type": "^0.17.3",
|
|
82
83
|
"jsdom": "^19.0.0",
|
|
83
84
|
"react": "^17.0.2",
|
|
84
85
|
"react-dom": "^17.0.2"
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** @jsxImportSource @compiled/react */
|
|
2
|
+
import { css } from '@compiled/react';
|
|
3
|
+
import { expectTypeOf } from 'expect-type';
|
|
4
|
+
|
|
5
|
+
describe('css func tests', () => {
|
|
6
|
+
it('should type violate when given invalid types', () => {
|
|
7
|
+
const style = css({ color: 'red' });
|
|
8
|
+
|
|
9
|
+
expectTypeOf(style).not.toMatchTypeOf<string>();
|
|
10
|
+
});
|
|
11
|
+
});
|
package/src/css-map/index.ts
CHANGED
|
@@ -1,6 +1,108 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Properties, AtRules } from 'csstype';
|
|
2
|
+
|
|
2
3
|
import { createSetupError } from '../utils/error';
|
|
3
4
|
|
|
5
|
+
import type { Pseudos } from './pseudos';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* These are all the CSS props that will exist.
|
|
9
|
+
* Only 'string' and 'number' are valid CSS values.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```
|
|
13
|
+
* const style: CssProps = {
|
|
14
|
+
* color: 'red',
|
|
15
|
+
* margin: 10,
|
|
16
|
+
* };
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
type CssProps = Readonly<Properties<string | number>>;
|
|
20
|
+
|
|
21
|
+
type AllPseudos = { [key in Pseudos]?: CssProps & AllPseudos };
|
|
22
|
+
|
|
23
|
+
// The `screen and (max-width: 768px)` part of `@media screen and (max-width: 768px)`.
|
|
24
|
+
// Ideally we would do type checking to forbid this from containing the `@media` part,
|
|
25
|
+
// but TypeScript doesn't provide a good way to do this.
|
|
26
|
+
type AtRuleSecondHalf = string;
|
|
27
|
+
type WhitelistedAtRule = {
|
|
28
|
+
[atRuleFirstHalf in AtRules]?: {
|
|
29
|
+
[atRuleSecondHalf in AtRuleSecondHalf]: CssProps & AllPseudos & WhitelistedAtRule;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
type WhitelistedSelector = AllPseudos & WhitelistedAtRule;
|
|
33
|
+
|
|
34
|
+
type ExtendedSelector = { [key: string]: CssProps | ExtendedSelector } & {
|
|
35
|
+
/**
|
|
36
|
+
* Using `selectors` is not valid here - you cannot nest a `selectors` object
|
|
37
|
+
* inside another `selectors` object.
|
|
38
|
+
*/
|
|
39
|
+
selectors?: never;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type ExtendedSelectors = {
|
|
43
|
+
/**
|
|
44
|
+
* Provides a way to use selectors that have not been explicitly whitelisted
|
|
45
|
+
* in cssMap.
|
|
46
|
+
*
|
|
47
|
+
* This does not provide any type-checking for the selectors (thus allowing
|
|
48
|
+
* more expressive selectors), though this is more flexible and allows
|
|
49
|
+
* nesting selectors in other selectors.
|
|
50
|
+
*
|
|
51
|
+
* A selector defined both outside of the `selectors` object and
|
|
52
|
+
* inside the `selectors` object is a runtime error.
|
|
53
|
+
*
|
|
54
|
+
* Note that you cannot nest a `selectors` object inside another
|
|
55
|
+
* `selectors` object.
|
|
56
|
+
*
|
|
57
|
+
* Only use if absolutely necessary.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```
|
|
61
|
+
* const myMap = cssMap({
|
|
62
|
+
* danger: {
|
|
63
|
+
* color: 'red',
|
|
64
|
+
* '@media': {
|
|
65
|
+
* '(min-width: 100px)': {
|
|
66
|
+
* font-size: '1.5em',
|
|
67
|
+
* },
|
|
68
|
+
* },
|
|
69
|
+
* '&:hover': {
|
|
70
|
+
* color: 'pink',
|
|
71
|
+
* },
|
|
72
|
+
* selectors: {
|
|
73
|
+
* '&:not(:active)': {
|
|
74
|
+
* backgroundColor: 'yellow',
|
|
75
|
+
* }
|
|
76
|
+
* },
|
|
77
|
+
* },
|
|
78
|
+
* success: {
|
|
79
|
+
* color: 'green',
|
|
80
|
+
* '@media': {
|
|
81
|
+
* '(min-width: 100px)': {
|
|
82
|
+
* font-size: '1.3em',
|
|
83
|
+
* },
|
|
84
|
+
* },
|
|
85
|
+
* '&:hover': {
|
|
86
|
+
* color: '#8f8',
|
|
87
|
+
* },
|
|
88
|
+
* selectors: {
|
|
89
|
+
* '&:not(:active)': {
|
|
90
|
+
* backgroundColor: 'white',
|
|
91
|
+
* }
|
|
92
|
+
* },
|
|
93
|
+
* },
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
selectors?: ExtendedSelector;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
type Variants<VariantName extends string> = Record<
|
|
101
|
+
VariantName,
|
|
102
|
+
CssProps & WhitelistedSelector & ExtendedSelectors
|
|
103
|
+
>;
|
|
104
|
+
type ReturnType<VariantName extends string> = Record<VariantName, CssProps>;
|
|
105
|
+
|
|
4
106
|
/**
|
|
5
107
|
* ## cssMap
|
|
6
108
|
*
|
|
@@ -18,10 +120,7 @@ import { createSetupError } from '../utils/error';
|
|
|
18
120
|
* <Component borderStyle="solid" />
|
|
19
121
|
* ```
|
|
20
122
|
*/
|
|
21
|
-
type returnType<T extends string, P> = Record<T, CSSProps<P>>;
|
|
22
123
|
|
|
23
|
-
export default function cssMap<T extends string
|
|
24
|
-
_styles: Record<T, CssObject<TProps> | CssObject<TProps>[]>
|
|
25
|
-
): Readonly<returnType<T, TProps>> {
|
|
124
|
+
export default function cssMap<T extends string>(_styles: Variants<T>): Readonly<ReturnType<T>> {
|
|
26
125
|
throw createSetupError();
|
|
27
126
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
|
|
5
|
+
// We also exclude anything that requires providing an argument
|
|
6
|
+
// (e.g. &:not(...) ), and anything that uses information from elements
|
|
7
|
+
// outside of the current element (e.g. &:first-of-type)
|
|
8
|
+
|
|
9
|
+
export type Pseudos =
|
|
10
|
+
| '&::after'
|
|
11
|
+
| '&::backdrop'
|
|
12
|
+
| '&::before'
|
|
13
|
+
| '&::cue'
|
|
14
|
+
| '&::cue-region'
|
|
15
|
+
| '&::first-letter'
|
|
16
|
+
| '&::first-line'
|
|
17
|
+
| '&::grammar-error'
|
|
18
|
+
| '&::marker'
|
|
19
|
+
| '&::placeholder'
|
|
20
|
+
| '&::selection'
|
|
21
|
+
| '&::spelling-error'
|
|
22
|
+
| '&::target-text'
|
|
23
|
+
| '&::view-transition'
|
|
24
|
+
| '&:active'
|
|
25
|
+
| '&:autofill'
|
|
26
|
+
| '&:blank'
|
|
27
|
+
| '&:checked'
|
|
28
|
+
| '&:default'
|
|
29
|
+
| '&:defined'
|
|
30
|
+
| '&:disabled'
|
|
31
|
+
| '&:empty'
|
|
32
|
+
| '&:enabled'
|
|
33
|
+
| '&:first'
|
|
34
|
+
| '&:focus'
|
|
35
|
+
| '&:focus-visible'
|
|
36
|
+
| '&:focus-within'
|
|
37
|
+
| '&:fullscreen'
|
|
38
|
+
| '&:hover'
|
|
39
|
+
| '&:in-range'
|
|
40
|
+
| '&:indeterminate'
|
|
41
|
+
| '&:invalid'
|
|
42
|
+
| '&:left'
|
|
43
|
+
| '&:link'
|
|
44
|
+
| '&:local-link'
|
|
45
|
+
| '&:optional'
|
|
46
|
+
| '&:out-of-range'
|
|
47
|
+
| '&:paused'
|
|
48
|
+
| '&:picture-in-picture'
|
|
49
|
+
| '&:placeholder-shown'
|
|
50
|
+
| '&:playing'
|
|
51
|
+
| '&:read-only'
|
|
52
|
+
| '&:read-write'
|
|
53
|
+
| '&:required'
|
|
54
|
+
| '&:right'
|
|
55
|
+
| '&:target'
|
|
56
|
+
| '&:user-invalid'
|
|
57
|
+
| '&:user-valid'
|
|
58
|
+
| '&:valid'
|
|
59
|
+
| '&:visited';
|