@compiled/react 0.16.7 → 0.16.9

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>>;
@@ -41,6 +41,7 @@ type WithConditionalCSSProp<TProps> = 'className' extends keyof TProps ? string
41
41
  */
42
42
  css?: CssFunction<void> | CssFunction<void>[];
43
43
  } : {} : {};
44
+ type ReactJSXElementType = string | React.JSXElementConstructor<any>;
44
45
  type ReactJSXElement = JSX.Element;
45
46
  type ReactJSXElementClass = JSX.ElementClass;
46
47
  type ReactJSXElementAttributesProperty = JSX.ElementAttributesProperty;
@@ -50,6 +51,7 @@ type ReactJSXIntrinsicAttributes = JSX.IntrinsicAttributes;
50
51
  type ReactJSXIntrinsicClassAttributes<T> = JSX.IntrinsicClassAttributes<T>;
51
52
  type ReactJSXIntrinsicElements = JSX.IntrinsicElements;
52
53
  export declare namespace CompiledJSX {
54
+ type ElementType = ReactJSXElementType;
53
55
  type Element = ReactJSXElement;
54
56
  type ElementClass = ReactJSXElementClass;
55
57
  type ElementAttributesProperty = ReactJSXElementAttributesProperty;
@@ -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>>;
@@ -41,6 +41,7 @@ type WithConditionalCSSProp<TProps> = 'className' extends keyof TProps ? string
41
41
  */
42
42
  css?: CssFunction<void> | CssFunction<void>[];
43
43
  } : {} : {};
44
+ type ReactJSXElementType = string | React.JSXElementConstructor<any>;
44
45
  type ReactJSXElement = JSX.Element;
45
46
  type ReactJSXElementClass = JSX.ElementClass;
46
47
  type ReactJSXElementAttributesProperty = JSX.ElementAttributesProperty;
@@ -50,6 +51,7 @@ type ReactJSXIntrinsicAttributes = JSX.IntrinsicAttributes;
50
51
  type ReactJSXIntrinsicClassAttributes<T> = JSX.IntrinsicClassAttributes<T>;
51
52
  type ReactJSXIntrinsicElements = JSX.IntrinsicElements;
52
53
  export declare namespace CompiledJSX {
54
+ type ElementType = ReactJSXElementType;
53
55
  type Element = ReactJSXElement;
54
56
  type ElementClass = ReactJSXElementClass;
55
57
  type ElementAttributesProperty = ReactJSXElementAttributesProperty;
@@ -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>>;
@@ -41,6 +41,7 @@ type WithConditionalCSSProp<TProps> = 'className' extends keyof TProps ? string
41
41
  */
42
42
  css?: CssFunction<void> | CssFunction<void>[];
43
43
  } : {} : {};
44
+ type ReactJSXElementType = string | React.JSXElementConstructor<any>;
44
45
  type ReactJSXElement = JSX.Element;
45
46
  type ReactJSXElementClass = JSX.ElementClass;
46
47
  type ReactJSXElementAttributesProperty = JSX.ElementAttributesProperty;
@@ -50,6 +51,7 @@ type ReactJSXIntrinsicAttributes = JSX.IntrinsicAttributes;
50
51
  type ReactJSXIntrinsicClassAttributes<T> = JSX.IntrinsicClassAttributes<T>;
51
52
  type ReactJSXIntrinsicElements = JSX.IntrinsicElements;
52
53
  export declare namespace CompiledJSX {
54
+ type ElementType = ReactJSXElementType;
53
55
  type Element = ReactJSXElement;
54
56
  type ElementClass = ReactJSXElementClass;
55
57
  type ElementAttributesProperty = ReactJSXElementAttributesProperty;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@compiled/react",
3
- "version": "0.16.7",
3
+ "version": "0.16.9",
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({
@@ -0,0 +1,23 @@
1
+ /** @jsxImportSource @compiled/react */
2
+ // eslint-disable-next-line import/no-extraneous-dependencies
3
+ import { css } from '@compiled/react';
4
+ import { css as strictCSS } from '@fixture/strict-api-test';
5
+ import { render } from '@testing-library/react';
6
+
7
+ describe('strict api used with top level api', () => {
8
+ it('should mix styles together deterministically', () => {
9
+ const styles = strictCSS({
10
+ color: 'var(--ds-text)',
11
+ });
12
+ const otherStyles = css({
13
+ backgroundColor: 'red',
14
+ color: 'blue',
15
+ });
16
+
17
+ const { getByTestId } = render(<div css={[styles, otherStyles]} data-testid="div" />);
18
+
19
+ expect(getByTestId('div')).not.toHaveCompiledCss('color', 'var(--ds-text)');
20
+ expect(getByTestId('div')).toHaveCompiledCss('color', 'blue');
21
+ expect(getByTestId('div')).toHaveCompiledCss('backgroundColor', 'red');
22
+ });
23
+ });
@@ -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
 
@@ -49,6 +49,9 @@ type WithConditionalCSSProp<TProps> = 'className' extends keyof TProps
49
49
  {};
50
50
 
51
51
  // Unpack all here to avoid infinite self-referencing when defining our own JSX namespace
52
+ // Based on the code from @types/react@18.2.8 / @emotion-js
53
+ // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/3197efc097d522c4bf02b94e1a0766d007d6cdeb/types/react/index.d.ts#LL3204C13-L3204C13
54
+ type ReactJSXElementType = string | React.JSXElementConstructor<any>;
52
55
  type ReactJSXElement = JSX.Element;
53
56
  type ReactJSXElementClass = JSX.ElementClass;
54
57
  type ReactJSXElementAttributesProperty = JSX.ElementAttributesProperty;
@@ -59,6 +62,7 @@ type ReactJSXIntrinsicClassAttributes<T> = JSX.IntrinsicClassAttributes<T>;
59
62
  type ReactJSXIntrinsicElements = JSX.IntrinsicElements;
60
63
 
61
64
  export namespace CompiledJSX {
65
+ export type ElementType = ReactJSXElementType;
62
66
  export type Element = ReactJSXElement;
63
67
  export type ElementClass = ReactJSXElementClass;
64
68
  export type ElementAttributesProperty = ReactJSXElementAttributesProperty;