@compiled/react 0.18.3 → 0.18.5

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/src/types.ts CHANGED
@@ -51,6 +51,16 @@ export type CSSPseudoElements =
51
51
  | '&::target-text'
52
52
  | '&::view-transition';
53
53
 
54
+ export type FlattenedChainedCSSPseudosClasses =
55
+ | '&:visited:active'
56
+ | '&:visited:hover'
57
+ | '&:active:visited'
58
+ | '&:hover::before'
59
+ | '&:hover::after'
60
+ | '&:focus-visible::before'
61
+ | '&:focus-visible::after'
62
+ | '&:focus:not(:focus-visible)';
63
+
54
64
  export type CSSPseudoClasses =
55
65
  | '&:active'
56
66
  | '&:autofill'
@@ -89,14 +99,16 @@ export type CSSPseudoClasses =
89
99
  | '&:valid'
90
100
  | '&:visited';
91
101
 
102
+ export type AllCSSPseudoClasses = CSSPseudoClasses | FlattenedChainedCSSPseudosClasses;
103
+
92
104
  /*
93
- * This list of pseudo-classes and pseudo-elements are from csstype
105
+ * This list of pseudo-classes, chained pseudo-classes, and pseudo-elements are from csstype
94
106
  * but with & added to the front. Compiled supports both &-ful
95
107
  * and &-less forms and both will target the current element
96
108
  * (`&:hover` <==> `:hover`), however we force the use of the
97
109
  * &-ful form for consistency with the nested spec for new APIs.
98
110
  */
99
- export type CSSPseudos = CSSPseudoElements | CSSPseudoClasses;
111
+ export type CSSPseudos = CSSPseudoElements | AllCSSPseudoClasses;
100
112
 
101
113
  /**
102
114
  * The XCSSProp must be given all known available properties even
@@ -260,4 +260,35 @@ describe('xcss prop', () => {
260
260
  />
261
261
  ).toBeObject();
262
262
  });
263
+
264
+ it('should allow chained pseudo elements', () => {
265
+ function CSSPropComponent({ xcss }: { xcss: XCSSProp<XCSSAllProperties, '&:hover::after'> }) {
266
+ return <div className={xcss}>foo</div>;
267
+ }
268
+
269
+ const styles = cssMap({
270
+ redColor: { color: 'red', '&:hover::after': { backgroundColor: 'green' } },
271
+ });
272
+
273
+ const { getByText } = render(<CSSPropComponent xcss={styles.redColor} />);
274
+
275
+ expect(getByText('foo')).toHaveCompiledCss('color', 'red');
276
+ });
277
+
278
+ it('should type error when given a chained pseudo element and none are allowed', () => {
279
+ function CSSPropComponent({ xcss }: { xcss: XCSSProp<XCSSAllProperties, '&:hover'> }) {
280
+ return <div className={xcss}>foo</div>;
281
+ }
282
+
283
+ const styles = cssMap({
284
+ redColor: { color: 'red', '&:hover::after': { backgroundColor: 'green' } },
285
+ });
286
+
287
+ expectTypeOf(
288
+ <CSSPropComponent
289
+ // @ts-expect-error — Types of property '"&:hover::after"' are incompatible.
290
+ xcss={styles.redColor}
291
+ />
292
+ ).toBeObject();
293
+ });
263
294
  });
@@ -2,14 +2,14 @@ import type * as CSS from 'csstype';
2
2
 
3
3
  import type { ApplySchemaValue } from '../create-strict-api/types';
4
4
  import { ax } from '../runtime';
5
- import type { CSSPseudos, CSSPseudoClasses, CSSProperties, StrictCSSProperties } from '../types';
5
+ import type { CSSPseudos, CSSProperties, StrictCSSProperties, AllCSSPseudoClasses } from '../types';
6
6
 
7
7
  type MarkAsRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] };
8
8
 
9
9
  type XCSSValue<
10
10
  TStyleDecl extends keyof CSSProperties,
11
11
  TSchema,
12
- TPseudoKey extends CSSPseudoClasses | ''
12
+ TPseudoKey extends AllCSSPseudoClasses | ''
13
13
  > = {
14
14
  [Q in keyof StrictCSSProperties]: Q extends TStyleDecl
15
15
  ? ApplySchemaValue<TSchema, Q, TPseudoKey>
@@ -24,7 +24,7 @@ type XCSSPseudo<
24
24
  > = {
25
25
  [Q in CSSPseudos]?: Q extends TAllowedPseudos
26
26
  ? MarkAsRequired<
27
- XCSSValue<TAllowedProperties, TSchema, Q extends CSSPseudoClasses ? Q : ''>,
27
+ XCSSValue<TAllowedProperties, TSchema, Q extends AllCSSPseudoClasses ? Q : ''>,
28
28
  TRequiredProperties['requiredProperties']
29
29
  >
30
30
  : never;