@compiled/react 0.16.0 → 0.16.1
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 +15 -26
- package/dist/browser/css-map/index.js +5 -4
- package/dist/browser/css-map/index.js.map +1 -1
- package/dist/browser/index.d.ts +1 -0
- package/dist/browser/index.js +1 -0
- package/dist/browser/index.js.map +1 -1
- package/dist/browser/jsx/jsx-local-namespace.d.ts +5 -1
- package/dist/browser/runtime/ac.d.ts +2 -2
- package/dist/browser/runtime/ac.js.map +1 -1
- package/dist/browser/runtime/ax.d.ts +1 -1
- package/dist/browser/runtime/ax.js.map +1 -1
- package/dist/browser/types.d.ts +9 -1
- package/dist/browser/xcss-prop/index.d.ts +130 -0
- package/dist/browser/xcss-prop/index.js +26 -0
- package/dist/browser/xcss-prop/index.js.map +1 -0
- package/dist/cjs/css-map/index.d.ts +15 -26
- package/dist/cjs/css-map/index.js +5 -4
- package/dist/cjs/css-map/index.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/jsx/jsx-local-namespace.d.ts +5 -1
- package/dist/cjs/runtime/ac.d.ts +2 -2
- package/dist/cjs/runtime/ac.js.map +1 -1
- package/dist/cjs/runtime/ax.d.ts +1 -1
- package/dist/cjs/runtime/ax.js.map +1 -1
- package/dist/cjs/types.d.ts +9 -1
- package/dist/cjs/xcss-prop/index.d.ts +130 -0
- package/dist/cjs/xcss-prop/index.js +30 -0
- package/dist/cjs/xcss-prop/index.js.map +1 -0
- package/dist/esm/css-map/index.d.ts +15 -26
- package/dist/esm/css-map/index.js +5 -4
- package/dist/esm/css-map/index.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/jsx/jsx-local-namespace.d.ts +5 -1
- package/dist/esm/runtime/ac.d.ts +2 -2
- package/dist/esm/runtime/ac.js.map +1 -1
- package/dist/esm/runtime/ax.d.ts +1 -1
- package/dist/esm/runtime/ax.js.map +1 -1
- package/dist/esm/types.d.ts +9 -1
- package/dist/esm/xcss-prop/index.d.ts +130 -0
- package/dist/esm/xcss-prop/index.js +26 -0
- package/dist/esm/xcss-prop/index.js.map +1 -0
- package/package.json +2 -2
- package/src/css/__tests__/types.test.ts +1 -0
- package/src/css-map/index.ts +19 -33
- package/src/index.ts +1 -0
- package/src/jsx/jsx-local-namespace.ts +8 -1
- package/src/runtime/ac.ts +1 -1
- package/src/runtime/ax.ts +1 -1
- package/src/types.ts +68 -0
- package/src/xcss-prop/__tests__/xcss-prop.test.tsx +294 -0
- package/src/xcss-prop/index.ts +174 -0
- package/dist/browser/css-map/pseudos.d.ts +0 -1
- package/dist/browser/css-map/pseudos.js +0 -5
- package/dist/browser/css-map/pseudos.js.map +0 -1
- package/dist/cjs/css-map/pseudos.d.ts +0 -1
- package/dist/cjs/css-map/pseudos.js +0 -6
- package/dist/cjs/css-map/pseudos.js.map +0 -1
- package/dist/esm/css-map/pseudos.d.ts +0 -1
- package/dist/esm/css-map/pseudos.js +0 -5
- package/dist/esm/css-map/pseudos.js.map +0 -1
- package/src/css-map/pseudos.ts +0 -59
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type * as CSS from 'csstype';
|
|
2
|
+
import type { CSSPseudos, CSSProperties } from '../types';
|
|
3
|
+
type XCSSItem<TStyleDecl extends keyof CSSProperties> = {
|
|
4
|
+
[Q in keyof CSSProperties]: Q extends TStyleDecl ? CompiledPropertyDeclarationReference | string | number : never;
|
|
5
|
+
};
|
|
6
|
+
type XCSSPseudos<TAllowedProperties extends keyof CSSProperties, TAllowedPseudos extends CSSPseudos, TRequiredProperties extends {
|
|
7
|
+
requiredProperties: TAllowedProperties;
|
|
8
|
+
}> = {
|
|
9
|
+
[Q in CSSPseudos]?: Q extends TAllowedPseudos ? MarkAsRequired<XCSSItem<TAllowedProperties>, TRequiredProperties['requiredProperties']> : never;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* These APIs we don't want to allow to be passed through the `xcss` prop but we also
|
|
13
|
+
* must declare them so the (lack-of a) excess property check doesn't bite us and allow
|
|
14
|
+
* unexpected values through.
|
|
15
|
+
*/
|
|
16
|
+
type BlockedRules = {
|
|
17
|
+
selectors?: never;
|
|
18
|
+
} & {
|
|
19
|
+
[Q in CSS.AtRules]?: never;
|
|
20
|
+
};
|
|
21
|
+
type CompiledPropertyDeclarationReference = {
|
|
22
|
+
['__COMPILED_PROPERTY_DECLARATION_REFERENCE_DO_NOT_WRITE_DIRECTLY__']: true;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Used to mark styles that have been flushed through an API as being generated
|
|
26
|
+
* from Compiled. This is useful when you want other ends of the API to ensure they
|
|
27
|
+
* take Compiled generated styles and not some arbitrary object.
|
|
28
|
+
*/
|
|
29
|
+
export type CompiledStyles<TObject> = {
|
|
30
|
+
[Q in keyof TObject]: TObject[Q] extends Record<string, unknown> ? CompiledStyles<TObject[Q]> : CompiledPropertyDeclarationReference;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Please think twice before using this type, you're better off declaring explicitly
|
|
34
|
+
* what your API should be, for example only defining `"color"`.
|
|
35
|
+
*
|
|
36
|
+
* Use in conjunction with {@link XCSSProp} to allow all properties to be given to
|
|
37
|
+
* your component.
|
|
38
|
+
*/
|
|
39
|
+
export type XCSSAllProperties = keyof CSSProperties;
|
|
40
|
+
/**
|
|
41
|
+
* Please think twice before using this type, you're better off declaring explicitly
|
|
42
|
+
* what your API should be, for example not allowing any pseudos at all using the
|
|
43
|
+
* `never` type.
|
|
44
|
+
*
|
|
45
|
+
* Use in conjunction with {@link XCSSProp} to allow all pseudos to be given to
|
|
46
|
+
* your component.
|
|
47
|
+
*/
|
|
48
|
+
export type XCSSAllPseudos = CSSPseudos;
|
|
49
|
+
/**
|
|
50
|
+
* ## xcss prop
|
|
51
|
+
*
|
|
52
|
+
* Declare styles your component takes with all other styles marked as violations
|
|
53
|
+
* by the TypeScript compiler. There are two primary use cases for xcss prop:
|
|
54
|
+
*
|
|
55
|
+
* - safe style overrides
|
|
56
|
+
* - inverting style declarations
|
|
57
|
+
*
|
|
58
|
+
* Interverting style declarations is interesting for platform teams as
|
|
59
|
+
* it means products only pay for styles they use as they're now the ones who declare
|
|
60
|
+
* the styles!
|
|
61
|
+
*
|
|
62
|
+
* The {@link XCSSProp} type has generics two of which must be defined — use to explicitly
|
|
63
|
+
* set want you to maintain as API. Use {@link XCSSAllProperties} and {@link XCSSAllPseudos}
|
|
64
|
+
* to enable all properties and pseudos.
|
|
65
|
+
*
|
|
66
|
+
* The third generic is used to declare what properties and pseudos should be required.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```
|
|
70
|
+
* interface MyComponentProps {
|
|
71
|
+
* // Color is accepted, all other properties / pseudos are considered violations.
|
|
72
|
+
* xcss?: XCSSProp<'color', never>;
|
|
73
|
+
*
|
|
74
|
+
* // Only backgrond color and hover pseudo is accepted.
|
|
75
|
+
* xcss?: XCSSProp<'backgroundColor', '&:hover'>;
|
|
76
|
+
*
|
|
77
|
+
* // All properties are accepted, all pseudos are considered violations.
|
|
78
|
+
* xcss?: XCSSProp<XCSSAllProperties, never>;
|
|
79
|
+
*
|
|
80
|
+
* // All properties are accepted, only the hover pseudo is accepted.
|
|
81
|
+
* xcss?: XCSSProp<XCSSAllProperties, '&:hover'>;
|
|
82
|
+
*
|
|
83
|
+
* // The xcss prop is required as well as the color property. No pseudos are required.
|
|
84
|
+
* xcss: XCSSProp<XCSSAllProperties, '&:hover', { requiredProperties: 'color', requiredPseudos: never }>;
|
|
85
|
+
* }
|
|
86
|
+
*
|
|
87
|
+
* function MyComponent({ xcss }: MyComponentProps) {
|
|
88
|
+
* return <div css={{ color: 'var(--ds-text-danger)' }} className={xcss} />
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* The xcss prop works with static inline objects and the [cssMap](https://compiledcssinjs.com/docs/api-cssmap) API.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```
|
|
96
|
+
* // Declared as an inline object
|
|
97
|
+
* <Component xcss={{ color: 'var(--ds-text)' }} />
|
|
98
|
+
*
|
|
99
|
+
* // Declared with the cssMap API
|
|
100
|
+
* const styles = cssMap({ text: { color: 'var(--ds-text)' } });
|
|
101
|
+
* <Component xcss={styles.text} />
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* To concatenate and conditonally apply styles use the {@link cssMap} {@link cx} functions.
|
|
105
|
+
*/
|
|
106
|
+
export type XCSSProp<TAllowedProperties extends keyof CSSProperties, TAllowedPseudos extends CSSPseudos, TRequiredProperties extends {
|
|
107
|
+
requiredProperties: TAllowedProperties;
|
|
108
|
+
requiredPseudos: TAllowedPseudos;
|
|
109
|
+
} = never> = (MarkAsRequired<XCSSItem<TAllowedProperties>, TRequiredProperties['requiredProperties']> & MarkAsRequired<XCSSPseudos<TAllowedProperties, TAllowedPseudos, TRequiredProperties>, TRequiredProperties['requiredPseudos']> & BlockedRules) | false | null | undefined;
|
|
110
|
+
type MarkAsRequired<T, K extends keyof T> = T & {
|
|
111
|
+
[P in K]-?: T[P];
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* ## cx
|
|
115
|
+
*
|
|
116
|
+
* Use in conjunction with the {@link XCSSProp} to concatenate and conditionally apply
|
|
117
|
+
* declared styles. Can only be used with the `cssMap()` and {@link XCSSProp} APIs.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```
|
|
121
|
+
* const styles = cssMap({
|
|
122
|
+
* text: { color: 'var(--ds-text)' },
|
|
123
|
+
* primary: { color: 'var(--ds-text-brand)' },
|
|
124
|
+
* });
|
|
125
|
+
*
|
|
126
|
+
* <Component xcss={cx(isPrimary && styles.text, !isPrimary && styles.primary)} />
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export declare const cx: <TStyles extends XCSSProp<any, any, never>[]>(...styles: TStyles) => TStyles[number];
|
|
130
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cx = void 0;
|
|
4
|
+
const runtime_1 = require("../runtime");
|
|
5
|
+
/**
|
|
6
|
+
* ## cx
|
|
7
|
+
*
|
|
8
|
+
* Use in conjunction with the {@link XCSSProp} to concatenate and conditionally apply
|
|
9
|
+
* declared styles. Can only be used with the `cssMap()` and {@link XCSSProp} APIs.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```
|
|
13
|
+
* const styles = cssMap({
|
|
14
|
+
* text: { color: 'var(--ds-text)' },
|
|
15
|
+
* primary: { color: 'var(--ds-text-brand)' },
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* <Component xcss={cx(isPrimary && styles.text, !isPrimary && styles.primary)} />
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
const cx = (...styles) => {
|
|
22
|
+
// At runtime TStyles is resolved down to strings, but not at compile time.
|
|
23
|
+
// We circumvent the type system here because of that.
|
|
24
|
+
const actualStyles = styles;
|
|
25
|
+
// The output should be a union type of passed in styles. This ensures the call
|
|
26
|
+
// site of xcss prop can raise violations when disallowed styles have been passed.
|
|
27
|
+
return (0, runtime_1.ac)(actualStyles);
|
|
28
|
+
};
|
|
29
|
+
exports.cx = cx;
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/xcss-prop/index.ts"],"names":[],"mappings":";;;AAEA,wCAAgC;AAiJhC;;;;;;;;;;;;;;;GAeG;AACI,MAAM,EAAE,GAAG,CAChB,GAAG,MAAe,EACD,EAAE;IACnB,2EAA2E;IAC3E,sDAAsD;IACtD,MAAM,YAAY,GAAG,MAA6B,CAAC;IAEnD,+EAA+E;IAC/E,kFAAkF;IAClF,OAAO,IAAA,YAAE,EAAC,YAAY,CAAoB,CAAC;AAC7C,CAAC,CAAC;AAVW,QAAA,EAAE,MAUb"}
|
|
@@ -1,30 +1,18 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type {
|
|
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>>;
|
|
1
|
+
import type * as CSS from 'csstype';
|
|
2
|
+
import type { CSSPseudos, CSSProperties } from '../types';
|
|
3
|
+
import type { CompiledStyles } from '../xcss-prop';
|
|
16
4
|
type AllPseudos = {
|
|
17
|
-
[key in
|
|
5
|
+
[key in CSSPseudos]?: CSSProperties & AllPseudos;
|
|
18
6
|
};
|
|
19
7
|
type AtRuleSecondHalf = string;
|
|
20
8
|
type WhitelistedAtRule = {
|
|
21
|
-
[atRuleFirstHalf in AtRules]?: {
|
|
22
|
-
[atRuleSecondHalf in AtRuleSecondHalf]:
|
|
9
|
+
[atRuleFirstHalf in CSS.AtRules]?: {
|
|
10
|
+
[atRuleSecondHalf in AtRuleSecondHalf]: CSSProperties & AllPseudos & WhitelistedAtRule;
|
|
23
11
|
};
|
|
24
12
|
};
|
|
25
13
|
type WhitelistedSelector = AllPseudos & WhitelistedAtRule;
|
|
26
14
|
type ExtendedSelector = {
|
|
27
|
-
[key: string]:
|
|
15
|
+
[key: string]: CSSProperties | ExtendedSelector;
|
|
28
16
|
} & {
|
|
29
17
|
/**
|
|
30
18
|
* Using `selectors` is not valid here - you cannot nest a `selectors` object
|
|
@@ -89,8 +77,6 @@ type ExtendedSelectors = {
|
|
|
89
77
|
*/
|
|
90
78
|
selectors?: ExtendedSelector;
|
|
91
79
|
};
|
|
92
|
-
type Variants<VariantName extends string> = Record<VariantName, CssProps & WhitelistedSelector & ExtendedSelectors>;
|
|
93
|
-
type ReturnType<VariantName extends string> = Record<VariantName, CssProps>;
|
|
94
80
|
/**
|
|
95
81
|
* ## cssMap
|
|
96
82
|
*
|
|
@@ -99,14 +85,17 @@ type ReturnType<VariantName extends string> = Record<VariantName, CssProps>;
|
|
|
99
85
|
*
|
|
100
86
|
* @example
|
|
101
87
|
* ```
|
|
102
|
-
* const
|
|
103
|
-
*
|
|
104
|
-
*
|
|
88
|
+
* const styles = cssMap({
|
|
89
|
+
* none: { borderStyle: 'none' },
|
|
90
|
+
* solid: { borderStyle: 'solid' },
|
|
105
91
|
* });
|
|
106
|
-
*
|
|
92
|
+
*
|
|
93
|
+
* const Component = ({ borderStyle }) => <div css={styles[borderStyle]} />
|
|
107
94
|
*
|
|
108
95
|
* <Component borderStyle="solid" />
|
|
109
96
|
* ```
|
|
110
97
|
*/
|
|
111
|
-
export default function cssMap<
|
|
98
|
+
export default function cssMap<TStyles extends Record<string, CSSProperties & WhitelistedSelector & ExtendedSelectors>>(_styles: TStyles): {
|
|
99
|
+
readonly [P in keyof TStyles]: CompiledStyles<TStyles[P]>;
|
|
100
|
+
};
|
|
112
101
|
export {};
|
|
@@ -7,11 +7,12 @@ import { createSetupError } from '../utils/error';
|
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
9
|
* ```
|
|
10
|
-
* const
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* const styles = cssMap({
|
|
11
|
+
* none: { borderStyle: 'none' },
|
|
12
|
+
* solid: { borderStyle: 'solid' },
|
|
13
13
|
* });
|
|
14
|
-
*
|
|
14
|
+
*
|
|
15
|
+
* const Component = ({ borderStyle }) => <div css={styles[borderStyle]} />
|
|
15
16
|
*
|
|
16
17
|
* <Component borderStyle="solid" />
|
|
17
18
|
* ```
|
|
@@ -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":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAkFlD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAG5B,OAAgB;IAIhB,MAAM,gBAAgB,EAAE,CAAC;AAC3B,CAAC"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { styled } from './styled';
|
|
|
7
7
|
export { ClassNames } from './class-names';
|
|
8
8
|
export { default as css } from './css';
|
|
9
9
|
export { default as cssMap } from './css-map';
|
|
10
|
+
export { type XCSSAllProperties, type XCSSAllPseudos, type XCSSProp, cx } from './xcss-prop';
|
|
10
11
|
export declare const jsx: typeof createElement;
|
|
11
12
|
export declare namespace jsx {
|
|
12
13
|
namespace JSX {
|
package/dist/esm/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export { styled } from './styled';
|
|
|
4
4
|
export { ClassNames } from './class-names';
|
|
5
5
|
export { default as css } from './css';
|
|
6
6
|
export { default as cssMap } from './css-map';
|
|
7
|
+
export { cx } from './xcss-prop';
|
|
7
8
|
// Pass through the (classic) jsx runtime.
|
|
8
9
|
// Compiled currently doesn't define its own and uses this purely to enable a local jsx namespace.
|
|
9
10
|
export const jsx = createElement;
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAOtC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,WAAW,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;AAC9C,OAAO,EAA8D,EAAE,EAAE,MAAM,aAAa,CAAC;AAE7F,0CAA0C;AAC1C,kGAAkG;AAClG,MAAM,CAAC,MAAM,GAAG,GAAG,aAAa,CAAC"}
|
|
@@ -58,7 +58,11 @@ export declare namespace CompiledJSX {
|
|
|
58
58
|
type IntrinsicAttributes = ReactJSXIntrinsicAttributes;
|
|
59
59
|
type IntrinsicClassAttributes<T> = ReactJSXIntrinsicClassAttributes<T>;
|
|
60
60
|
type IntrinsicElements = {
|
|
61
|
-
[K in keyof ReactJSXIntrinsicElements]: ReactJSXIntrinsicElements[K] & {
|
|
61
|
+
[K in keyof ReactJSXIntrinsicElements]: Omit<ReactJSXIntrinsicElements[K], 'className'> & {
|
|
62
|
+
/**
|
|
63
|
+
* The class name prop now can be given the output of xcss prop from `@compiled/react`.
|
|
64
|
+
*/
|
|
65
|
+
className?: string | Record<string, any> | null | false;
|
|
62
66
|
css?: CssFunction<void> | CssFunction<void>[];
|
|
63
67
|
};
|
|
64
68
|
};
|
package/dist/esm/runtime/ac.d.ts
CHANGED
|
@@ -33,9 +33,9 @@ declare class AtomicGroups {
|
|
|
33
33
|
*
|
|
34
34
|
* @param classes
|
|
35
35
|
*/
|
|
36
|
-
export declare function ac(classNames: (AtomicGroups | string | undefined | false)[]): AtomicGroups | undefined;
|
|
36
|
+
export declare function ac(classNames: (AtomicGroups | string | null | undefined | false)[]): AtomicGroups | undefined;
|
|
37
37
|
export declare function memoizedAc(classNames: (AtomicGroups | string | undefined | false)[]): AtomicGroups | undefined;
|
|
38
|
-
declare const _default: typeof
|
|
38
|
+
declare const _default: typeof memoizedAc;
|
|
39
39
|
export default _default;
|
|
40
40
|
/**
|
|
41
41
|
* Provide an opportunity to clear the cache to prevent memory leak.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ac.js","sourceRoot":"","sources":["../../../src/runtime/ac.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE9D,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAE9B;;;GAGG;AACH,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAE9B;;;GAGG;AACH,MAAM,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;AAExB;;;GAGG;AACH,MAAM,YAAY;IAEhB,YAAY,MAA2B;QACrC,2EAA2E;QAC3E,mFAAmF;QACnF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IACD,QAAQ;QACN,IAAI,GAAG,GAAG,EAAE,CAAC;QAEb,KAAK,MAAM,CAAC,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE;YACnC,GAAG,IAAI,KAAK,GAAG,GAAG,CAAC;SACpB;QAED,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC1B,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,EAAE,CAChB,
|
|
1
|
+
{"version":3,"file":"ac.js","sourceRoot":"","sources":["../../../src/runtime/ac.ts"],"names":[],"mappings":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vB,QAAQ,IAAI,OAAO,GAAG,GAAG,CAAC;KAC3B;IAED,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAEjC,IAAI,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEpD,MAAM,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC;IAE9B,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAE5B,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,+EAA+E;AAC/E,oGAAoG;AACpG,eAAe,mBAAmB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;AAEvD;;GAEG;AACH,MAAM,UAAU,UAAU;IACxB,KAAK,CAAC,KAAK,EAAE,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,QAAQ;IACtB,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/esm/runtime/ax.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ax.js","sourceRoot":"","sources":["../../../src/runtime/ax.ts"],"names":[],"mappings":"AAAA,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAE9B;;;GAGG;AACH,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,OAAO,UAAU,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"ax.js","sourceRoot":"","sources":["../../../src/runtime/ax.ts"],"names":[],"mappings":"AAAA,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAE9B;;;GAGG;AACH,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,OAAO,UAAU,EAAE,CAAC,UAAiD;IAC1E,IAAI,UAAU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export type CSSProps<TProps> = Readonly<CSS.Properties<CssFunction<TProps>>>;
|
|
|
17
17
|
export type CssObject<TProps> = Readonly<{
|
|
18
18
|
[key: string]: CssFunction<TProps>;
|
|
19
19
|
}>;
|
|
20
|
-
export type CssFunction<TProps = unknown> = CssType<TProps> | BasicTemplateInterpolations | boolean | undefined;
|
|
20
|
+
export type CssFunction<TProps = unknown> = CssType<TProps> | BasicTemplateInterpolations | null | boolean | undefined;
|
|
21
|
+
export type CSSPseudos = '&::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';
|
|
22
|
+
/**
|
|
23
|
+
* The xcss prop must be given all known available properties even
|
|
24
|
+
* if it takes a subset of them. This is ensure the (lack-of an)
|
|
25
|
+
* excess property check doesn't enable makers to circumvent the
|
|
26
|
+
* system and pass in values they shouldn't.
|
|
27
|
+
*/
|
|
28
|
+
export type CSSProperties = Readonly<CSS.Properties<string | number>>;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type * as CSS from 'csstype';
|
|
2
|
+
import type { CSSPseudos, CSSProperties } from '../types';
|
|
3
|
+
type XCSSItem<TStyleDecl extends keyof CSSProperties> = {
|
|
4
|
+
[Q in keyof CSSProperties]: Q extends TStyleDecl ? CompiledPropertyDeclarationReference | string | number : never;
|
|
5
|
+
};
|
|
6
|
+
type XCSSPseudos<TAllowedProperties extends keyof CSSProperties, TAllowedPseudos extends CSSPseudos, TRequiredProperties extends {
|
|
7
|
+
requiredProperties: TAllowedProperties;
|
|
8
|
+
}> = {
|
|
9
|
+
[Q in CSSPseudos]?: Q extends TAllowedPseudos ? MarkAsRequired<XCSSItem<TAllowedProperties>, TRequiredProperties['requiredProperties']> : never;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* These APIs we don't want to allow to be passed through the `xcss` prop but we also
|
|
13
|
+
* must declare them so the (lack-of a) excess property check doesn't bite us and allow
|
|
14
|
+
* unexpected values through.
|
|
15
|
+
*/
|
|
16
|
+
type BlockedRules = {
|
|
17
|
+
selectors?: never;
|
|
18
|
+
} & {
|
|
19
|
+
[Q in CSS.AtRules]?: never;
|
|
20
|
+
};
|
|
21
|
+
type CompiledPropertyDeclarationReference = {
|
|
22
|
+
['__COMPILED_PROPERTY_DECLARATION_REFERENCE_DO_NOT_WRITE_DIRECTLY__']: true;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Used to mark styles that have been flushed through an API as being generated
|
|
26
|
+
* from Compiled. This is useful when you want other ends of the API to ensure they
|
|
27
|
+
* take Compiled generated styles and not some arbitrary object.
|
|
28
|
+
*/
|
|
29
|
+
export type CompiledStyles<TObject> = {
|
|
30
|
+
[Q in keyof TObject]: TObject[Q] extends Record<string, unknown> ? CompiledStyles<TObject[Q]> : CompiledPropertyDeclarationReference;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Please think twice before using this type, you're better off declaring explicitly
|
|
34
|
+
* what your API should be, for example only defining `"color"`.
|
|
35
|
+
*
|
|
36
|
+
* Use in conjunction with {@link XCSSProp} to allow all properties to be given to
|
|
37
|
+
* your component.
|
|
38
|
+
*/
|
|
39
|
+
export type XCSSAllProperties = keyof CSSProperties;
|
|
40
|
+
/**
|
|
41
|
+
* Please think twice before using this type, you're better off declaring explicitly
|
|
42
|
+
* what your API should be, for example not allowing any pseudos at all using the
|
|
43
|
+
* `never` type.
|
|
44
|
+
*
|
|
45
|
+
* Use in conjunction with {@link XCSSProp} to allow all pseudos to be given to
|
|
46
|
+
* your component.
|
|
47
|
+
*/
|
|
48
|
+
export type XCSSAllPseudos = CSSPseudos;
|
|
49
|
+
/**
|
|
50
|
+
* ## xcss prop
|
|
51
|
+
*
|
|
52
|
+
* Declare styles your component takes with all other styles marked as violations
|
|
53
|
+
* by the TypeScript compiler. There are two primary use cases for xcss prop:
|
|
54
|
+
*
|
|
55
|
+
* - safe style overrides
|
|
56
|
+
* - inverting style declarations
|
|
57
|
+
*
|
|
58
|
+
* Interverting style declarations is interesting for platform teams as
|
|
59
|
+
* it means products only pay for styles they use as they're now the ones who declare
|
|
60
|
+
* the styles!
|
|
61
|
+
*
|
|
62
|
+
* The {@link XCSSProp} type has generics two of which must be defined — use to explicitly
|
|
63
|
+
* set want you to maintain as API. Use {@link XCSSAllProperties} and {@link XCSSAllPseudos}
|
|
64
|
+
* to enable all properties and pseudos.
|
|
65
|
+
*
|
|
66
|
+
* The third generic is used to declare what properties and pseudos should be required.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```
|
|
70
|
+
* interface MyComponentProps {
|
|
71
|
+
* // Color is accepted, all other properties / pseudos are considered violations.
|
|
72
|
+
* xcss?: XCSSProp<'color', never>;
|
|
73
|
+
*
|
|
74
|
+
* // Only backgrond color and hover pseudo is accepted.
|
|
75
|
+
* xcss?: XCSSProp<'backgroundColor', '&:hover'>;
|
|
76
|
+
*
|
|
77
|
+
* // All properties are accepted, all pseudos are considered violations.
|
|
78
|
+
* xcss?: XCSSProp<XCSSAllProperties, never>;
|
|
79
|
+
*
|
|
80
|
+
* // All properties are accepted, only the hover pseudo is accepted.
|
|
81
|
+
* xcss?: XCSSProp<XCSSAllProperties, '&:hover'>;
|
|
82
|
+
*
|
|
83
|
+
* // The xcss prop is required as well as the color property. No pseudos are required.
|
|
84
|
+
* xcss: XCSSProp<XCSSAllProperties, '&:hover', { requiredProperties: 'color', requiredPseudos: never }>;
|
|
85
|
+
* }
|
|
86
|
+
*
|
|
87
|
+
* function MyComponent({ xcss }: MyComponentProps) {
|
|
88
|
+
* return <div css={{ color: 'var(--ds-text-danger)' }} className={xcss} />
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* The xcss prop works with static inline objects and the [cssMap](https://compiledcssinjs.com/docs/api-cssmap) API.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```
|
|
96
|
+
* // Declared as an inline object
|
|
97
|
+
* <Component xcss={{ color: 'var(--ds-text)' }} />
|
|
98
|
+
*
|
|
99
|
+
* // Declared with the cssMap API
|
|
100
|
+
* const styles = cssMap({ text: { color: 'var(--ds-text)' } });
|
|
101
|
+
* <Component xcss={styles.text} />
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* To concatenate and conditonally apply styles use the {@link cssMap} {@link cx} functions.
|
|
105
|
+
*/
|
|
106
|
+
export type XCSSProp<TAllowedProperties extends keyof CSSProperties, TAllowedPseudos extends CSSPseudos, TRequiredProperties extends {
|
|
107
|
+
requiredProperties: TAllowedProperties;
|
|
108
|
+
requiredPseudos: TAllowedPseudos;
|
|
109
|
+
} = never> = (MarkAsRequired<XCSSItem<TAllowedProperties>, TRequiredProperties['requiredProperties']> & MarkAsRequired<XCSSPseudos<TAllowedProperties, TAllowedPseudos, TRequiredProperties>, TRequiredProperties['requiredPseudos']> & BlockedRules) | false | null | undefined;
|
|
110
|
+
type MarkAsRequired<T, K extends keyof T> = T & {
|
|
111
|
+
[P in K]-?: T[P];
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* ## cx
|
|
115
|
+
*
|
|
116
|
+
* Use in conjunction with the {@link XCSSProp} to concatenate and conditionally apply
|
|
117
|
+
* declared styles. Can only be used with the `cssMap()` and {@link XCSSProp} APIs.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```
|
|
121
|
+
* const styles = cssMap({
|
|
122
|
+
* text: { color: 'var(--ds-text)' },
|
|
123
|
+
* primary: { color: 'var(--ds-text-brand)' },
|
|
124
|
+
* });
|
|
125
|
+
*
|
|
126
|
+
* <Component xcss={cx(isPrimary && styles.text, !isPrimary && styles.primary)} />
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export declare const cx: <TStyles extends XCSSProp<any, any, never>[]>(...styles: TStyles) => TStyles[number];
|
|
130
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ac } from '../runtime';
|
|
2
|
+
/**
|
|
3
|
+
* ## cx
|
|
4
|
+
*
|
|
5
|
+
* Use in conjunction with the {@link XCSSProp} to concatenate and conditionally apply
|
|
6
|
+
* declared styles. Can only be used with the `cssMap()` and {@link XCSSProp} APIs.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```
|
|
10
|
+
* const styles = cssMap({
|
|
11
|
+
* text: { color: 'var(--ds-text)' },
|
|
12
|
+
* primary: { color: 'var(--ds-text-brand)' },
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* <Component xcss={cx(isPrimary && styles.text, !isPrimary && styles.primary)} />
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export const cx = (...styles) => {
|
|
19
|
+
// At runtime TStyles is resolved down to strings, but not at compile time.
|
|
20
|
+
// We circumvent the type system here because of that.
|
|
21
|
+
const actualStyles = styles;
|
|
22
|
+
// The output should be a union type of passed in styles. This ensures the call
|
|
23
|
+
// site of xcss prop can raise violations when disallowed styles have been passed.
|
|
24
|
+
return ac(actualStyles);
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/xcss-prop/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAiJhC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG,CAChB,GAAG,MAAe,EACD,EAAE;IACnB,2EAA2E;IAC3E,sDAAsD;IACtD,MAAM,YAAY,GAAG,MAA6B,CAAC;IAEnD,+EAA+E;IAC/E,kFAAkF;IAClF,OAAO,EAAE,CAAC,YAAY,CAAoB,CAAC;AAC7C,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compiled/react",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"description": "A familiar and performant compile time CSS-in-JS library for React.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"compiled",
|
|
@@ -78,7 +78,7 @@
|
|
|
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.
|
|
81
|
+
"@types/react-dom": "^17.0.22",
|
|
82
82
|
"expect-type": "^0.17.3",
|
|
83
83
|
"jsdom": "^19.0.0",
|
|
84
84
|
"react": "^17.0.2",
|
package/src/css-map/index.ts
CHANGED
|
@@ -1,37 +1,23 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type * as CSS from 'csstype';
|
|
2
2
|
|
|
3
|
+
import type { CSSPseudos, CSSProperties } from '../types';
|
|
3
4
|
import { createSetupError } from '../utils/error';
|
|
5
|
+
import type { CompiledStyles } from '../xcss-prop';
|
|
4
6
|
|
|
5
|
-
|
|
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 };
|
|
7
|
+
type AllPseudos = { [key in CSSPseudos]?: CSSProperties & AllPseudos };
|
|
22
8
|
|
|
23
9
|
// The `screen and (max-width: 768px)` part of `@media screen and (max-width: 768px)`.
|
|
24
10
|
// Ideally we would do type checking to forbid this from containing the `@media` part,
|
|
25
11
|
// but TypeScript doesn't provide a good way to do this.
|
|
26
12
|
type AtRuleSecondHalf = string;
|
|
27
13
|
type WhitelistedAtRule = {
|
|
28
|
-
[atRuleFirstHalf in AtRules]?: {
|
|
29
|
-
[atRuleSecondHalf in AtRuleSecondHalf]:
|
|
14
|
+
[atRuleFirstHalf in CSS.AtRules]?: {
|
|
15
|
+
[atRuleSecondHalf in AtRuleSecondHalf]: CSSProperties & AllPseudos & WhitelistedAtRule;
|
|
30
16
|
};
|
|
31
17
|
};
|
|
32
18
|
type WhitelistedSelector = AllPseudos & WhitelistedAtRule;
|
|
33
19
|
|
|
34
|
-
type ExtendedSelector = { [key: string]:
|
|
20
|
+
type ExtendedSelector = { [key: string]: CSSProperties | ExtendedSelector } & {
|
|
35
21
|
/**
|
|
36
22
|
* Using `selectors` is not valid here - you cannot nest a `selectors` object
|
|
37
23
|
* inside another `selectors` object.
|
|
@@ -97,12 +83,6 @@ type ExtendedSelectors = {
|
|
|
97
83
|
selectors?: ExtendedSelector;
|
|
98
84
|
};
|
|
99
85
|
|
|
100
|
-
type Variants<VariantName extends string> = Record<
|
|
101
|
-
VariantName,
|
|
102
|
-
CssProps & WhitelistedSelector & ExtendedSelectors
|
|
103
|
-
>;
|
|
104
|
-
type ReturnType<VariantName extends string> = Record<VariantName, CssProps>;
|
|
105
|
-
|
|
106
86
|
/**
|
|
107
87
|
* ## cssMap
|
|
108
88
|
*
|
|
@@ -111,16 +91,22 @@ type ReturnType<VariantName extends string> = Record<VariantName, CssProps>;
|
|
|
111
91
|
*
|
|
112
92
|
* @example
|
|
113
93
|
* ```
|
|
114
|
-
* const
|
|
115
|
-
*
|
|
116
|
-
*
|
|
94
|
+
* const styles = cssMap({
|
|
95
|
+
* none: { borderStyle: 'none' },
|
|
96
|
+
* solid: { borderStyle: 'solid' },
|
|
117
97
|
* });
|
|
118
|
-
*
|
|
98
|
+
*
|
|
99
|
+
* const Component = ({ borderStyle }) => <div css={styles[borderStyle]} />
|
|
119
100
|
*
|
|
120
101
|
* <Component borderStyle="solid" />
|
|
121
102
|
* ```
|
|
122
103
|
*/
|
|
123
|
-
|
|
124
|
-
|
|
104
|
+
export default function cssMap<
|
|
105
|
+
TStyles extends Record<string, CSSProperties & WhitelistedSelector & ExtendedSelectors>
|
|
106
|
+
>(
|
|
107
|
+
_styles: TStyles
|
|
108
|
+
): {
|
|
109
|
+
readonly [P in keyof TStyles]: CompiledStyles<TStyles[P]>;
|
|
110
|
+
} {
|
|
125
111
|
throw createSetupError();
|
|
126
112
|
}
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { styled } from './styled';
|
|
|
10
10
|
export { ClassNames } from './class-names';
|
|
11
11
|
export { default as css } from './css';
|
|
12
12
|
export { default as cssMap } from './css-map';
|
|
13
|
+
export { type XCSSAllProperties, type XCSSAllPseudos, type XCSSProp, cx } from './xcss-prop';
|
|
13
14
|
|
|
14
15
|
// Pass through the (classic) jsx runtime.
|
|
15
16
|
// Compiled currently doesn't define its own and uses this purely to enable a local jsx namespace.
|