@compiled/react 0.16.7 → 0.16.8

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.
@@ -3,8 +3,8 @@ import { type CompiledStyles, cx, type Internal$XCSSProp } from '../xcss-prop';
3
3
  type PseudosDeclarations = {
4
4
  [Q in CSSPseudos]?: StrictCSSProperties;
5
5
  };
6
- type EnforceSchema<TObject> = {
7
- [P in keyof TObject]?: P extends keyof CompiledSchema ? TObject[P] extends Record<string, unknown> ? EnforceSchema<TObject[P]> : TObject[P] : never;
6
+ type EnforceSchema<TSchema> = {
7
+ [P in keyof TSchema]?: P extends keyof CompiledSchema ? TSchema[P] extends Record<string, any> ? EnforceSchema<TSchema[P]> : TSchema[P] : never;
8
8
  };
9
9
  type CSSStyles<TSchema extends CompiledSchema> = StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>;
10
10
  type CSSMapStyles<TSchema extends CompiledSchema> = Record<string, CSSStyles<TSchema>>;
@@ -3,8 +3,8 @@ import { type CompiledStyles, cx, type Internal$XCSSProp } from '../xcss-prop';
3
3
  type PseudosDeclarations = {
4
4
  [Q in CSSPseudos]?: StrictCSSProperties;
5
5
  };
6
- type EnforceSchema<TObject> = {
7
- [P in keyof TObject]?: P extends keyof CompiledSchema ? TObject[P] extends Record<string, unknown> ? EnforceSchema<TObject[P]> : TObject[P] : never;
6
+ type EnforceSchema<TSchema> = {
7
+ [P in keyof TSchema]?: P extends keyof CompiledSchema ? TSchema[P] extends Record<string, any> ? EnforceSchema<TSchema[P]> : TSchema[P] : never;
8
8
  };
9
9
  type CSSStyles<TSchema extends CompiledSchema> = StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>;
10
10
  type CSSMapStyles<TSchema extends CompiledSchema> = Record<string, CSSStyles<TSchema>>;
@@ -3,8 +3,8 @@ import { type CompiledStyles, cx, type Internal$XCSSProp } from '../xcss-prop';
3
3
  type PseudosDeclarations = {
4
4
  [Q in CSSPseudos]?: StrictCSSProperties;
5
5
  };
6
- type EnforceSchema<TObject> = {
7
- [P in keyof TObject]?: P extends keyof CompiledSchema ? TObject[P] extends Record<string, unknown> ? EnforceSchema<TObject[P]> : TObject[P] : never;
6
+ type EnforceSchema<TSchema> = {
7
+ [P in keyof TSchema]?: P extends keyof CompiledSchema ? TSchema[P] extends Record<string, any> ? EnforceSchema<TSchema[P]> : TSchema[P] : never;
8
8
  };
9
9
  type CSSStyles<TSchema extends CompiledSchema> = StrictCSSProperties & PseudosDeclarations & EnforceSchema<TSchema>;
10
10
  type CSSMapStyles<TSchema extends CompiledSchema> = Record<string, CSSStyles<TSchema>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compiled/react",
3
- "version": "0.16.7",
3
+ "version": "0.16.8",
4
4
  "description": "A familiar and performant compile time CSS-in-JS library for React.",
5
5
  "keywords": [
6
6
  "compiled",
@@ -5,6 +5,58 @@ import type { XCSSProp } from './__fixtures__/strict-api-recursive';
5
5
  import { css, cssMap } from './__fixtures__/strict-api-recursive';
6
6
 
7
7
  describe('createStrictAPI()', () => {
8
+ it('should mark all styles as optional in css()', () => {
9
+ const styles = css({
10
+ '&:hover': {},
11
+ '&:active': {},
12
+ '&::before': {},
13
+ '&::after': {},
14
+ });
15
+
16
+ const { getByTestId } = render(<div css={styles} data-testid="div" />);
17
+
18
+ expect(getByTestId('div')).toBeDefined();
19
+ });
20
+
21
+ it('should mark all styles as optional in cssMap()', () => {
22
+ const styles = cssMap({
23
+ nested: {
24
+ '&:hover': {},
25
+ '&:active': {},
26
+ '&::before': {},
27
+ '&::after': {},
28
+ },
29
+ });
30
+
31
+ const { getByTestId } = render(<div css={styles.nested} data-testid="div" />);
32
+
33
+ expect(getByTestId('div')).toBeDefined();
34
+ });
35
+
36
+ it('should mark all styles as optional in xcss prop', () => {
37
+ function Component({
38
+ xcss,
39
+ }: {
40
+ xcss: ReturnType<
41
+ typeof XCSSProp<
42
+ 'backgroundColor' | 'color',
43
+ '&:hover' | '&:active' | '&::before' | '&::after'
44
+ >
45
+ >;
46
+ }) {
47
+ return <div data-testid="div" className={xcss} />;
48
+ }
49
+
50
+ const { getByTestId } = render(
51
+ <Component
52
+ xcss={{ '&:hover': {}, '&:active': {}, '&::before': {}, '&::after': {} }}
53
+ data-testid="div"
54
+ />
55
+ );
56
+
57
+ expect(getByTestId('div')).toBeDefined();
58
+ });
59
+
8
60
  describe('type violations', () => {
9
61
  it('should violate types for css()', () => {
10
62
  const styles = css({
@@ -6,11 +6,11 @@ type PseudosDeclarations = {
6
6
  [Q in CSSPseudos]?: StrictCSSProperties;
7
7
  };
8
8
 
9
- type EnforceSchema<TObject> = {
10
- [P in keyof TObject]?: P extends keyof CompiledSchema
11
- ? TObject[P] extends Record<string, unknown>
12
- ? EnforceSchema<TObject[P]>
13
- : TObject[P]
9
+ type EnforceSchema<TSchema> = {
10
+ [P in keyof TSchema]?: P extends keyof CompiledSchema
11
+ ? TSchema[P] extends Record<string, any>
12
+ ? EnforceSchema<TSchema[P]>
13
+ : TSchema[P]
14
14
  : never;
15
15
  };
16
16