@compiled/react 0.17.1 → 0.17.3
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/index.d.ts +1 -0
- package/dist/browser/xcss-prop/index.js +2 -2
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/xcss-prop/index.js +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/xcss-prop/index.js +2 -2
- package/package.json +1 -1
- package/src/__tests__/browser.test.tsx +1 -1
- package/src/__tests__/jest-matcher.test.tsx +17 -1
- package/src/__tests__/ssr.test.tsx +2 -2
- package/src/create-strict-api/__tests__/__fixtures__/strict-api.ts +2 -2
- package/src/create-strict-api/__tests__/pass-through-xcss.test.tsx +95 -0
- package/src/index.ts +1 -0
- package/src/xcss-prop/index.ts +2 -2
package/dist/browser/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare const jsx: typeof createElement;
|
|
|
13
13
|
export declare namespace jsx {
|
|
14
14
|
namespace JSX {
|
|
15
15
|
type Element = CompiledJSX.Element;
|
|
16
|
+
type ElementType = CompiledJSX.ElementType;
|
|
16
17
|
type ElementClass = CompiledJSX.ElementClass;
|
|
17
18
|
type ElementAttributesProperty = CompiledJSX.ElementAttributesProperty;
|
|
18
19
|
type ElementChildrenAttribute = CompiledJSX.ElementChildrenAttribute;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ax } from '../runtime';
|
|
2
2
|
/**
|
|
3
3
|
* ## CX
|
|
4
4
|
*
|
|
@@ -21,6 +21,6 @@ export const cx = (...styles) => {
|
|
|
21
21
|
const actualStyles = styles;
|
|
22
22
|
// The output should be a union type of passed in styles. This ensures the call
|
|
23
23
|
// site of xcss prop can raise violations when disallowed styles have been passed.
|
|
24
|
-
return
|
|
24
|
+
return ax(actualStyles);
|
|
25
25
|
};
|
|
26
26
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare const jsx: typeof createElement;
|
|
|
13
13
|
export declare namespace jsx {
|
|
14
14
|
namespace JSX {
|
|
15
15
|
type Element = CompiledJSX.Element;
|
|
16
|
+
type ElementType = CompiledJSX.ElementType;
|
|
16
17
|
type ElementClass = CompiledJSX.ElementClass;
|
|
17
18
|
type ElementAttributesProperty = CompiledJSX.ElementAttributesProperty;
|
|
18
19
|
type ElementChildrenAttribute = CompiledJSX.ElementChildrenAttribute;
|
|
@@ -24,7 +24,7 @@ const cx = (...styles) => {
|
|
|
24
24
|
const actualStyles = styles;
|
|
25
25
|
// The output should be a union type of passed in styles. This ensures the call
|
|
26
26
|
// site of xcss prop can raise violations when disallowed styles have been passed.
|
|
27
|
-
return (0, runtime_1.
|
|
27
|
+
return (0, runtime_1.ax)(actualStyles);
|
|
28
28
|
};
|
|
29
29
|
exports.cx = cx;
|
|
30
30
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare const jsx: typeof createElement;
|
|
|
13
13
|
export declare namespace jsx {
|
|
14
14
|
namespace JSX {
|
|
15
15
|
type Element = CompiledJSX.Element;
|
|
16
|
+
type ElementType = CompiledJSX.ElementType;
|
|
16
17
|
type ElementClass = CompiledJSX.ElementClass;
|
|
17
18
|
type ElementAttributesProperty = CompiledJSX.ElementAttributesProperty;
|
|
18
19
|
type ElementChildrenAttribute = CompiledJSX.ElementChildrenAttribute;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ax } from '../runtime';
|
|
2
2
|
/**
|
|
3
3
|
* ## CX
|
|
4
4
|
*
|
|
@@ -21,6 +21,6 @@ export const cx = (...styles) => {
|
|
|
21
21
|
const actualStyles = styles;
|
|
22
22
|
// The output should be a union type of passed in styles. This ensures the call
|
|
23
23
|
// site of xcss prop can raise violations when disallowed styles have been passed.
|
|
24
|
-
return
|
|
24
|
+
return ax(actualStyles);
|
|
25
25
|
};
|
|
26
26
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -100,7 +100,7 @@ describe('browser', () => {
|
|
|
100
100
|
<style nonce="k0Mp1lEd">._f8pjbf54:focus{color:green}</style>
|
|
101
101
|
<style nonce="k0Mp1lEd">._30l31gy6:hover{color:yellow}</style>
|
|
102
102
|
<style nonce="k0Mp1lEd">._9h8h13q2:active{color:blue}</style>
|
|
103
|
-
<style nonce="k0Mp1lEd">@
|
|
103
|
+
<style nonce="k0Mp1lEd">@media (max-width:800px){._1o8z1gy6:focus{color:yellow}._jbabtwqo:focus-visible, ._6146twqo:hover{color:grey}._1cld11x8:active{color:black}}@supports (display:grid){._1df61gy6:focus{color:yellow}._7okp11x8:active{color:black}}</style>
|
|
104
104
|
"
|
|
105
105
|
`);
|
|
106
106
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** @jsxImportSource @compiled/react */
|
|
2
2
|
// This test belongs in @compiled/jest - but can't be placed there due to a circular dependency.
|
|
3
3
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
4
|
-
import { styled } from '@compiled/react';
|
|
4
|
+
import { cssMap, styled } from '@compiled/react';
|
|
5
5
|
import { render } from '@testing-library/react';
|
|
6
6
|
|
|
7
7
|
describe('toHaveCompliedCss', () => {
|
|
@@ -124,6 +124,22 @@ describe('toHaveCompliedCss', () => {
|
|
|
124
124
|
expect(el).toHaveCompiledCss('color', 'blue', { target: ':active' });
|
|
125
125
|
});
|
|
126
126
|
|
|
127
|
+
it('should match camelCase css vars', () => {
|
|
128
|
+
const styles = cssMap({ root: { '--myCamelVar': 'red' } });
|
|
129
|
+
|
|
130
|
+
const { getByText } = render(<div css={styles.root}>hello world</div>);
|
|
131
|
+
|
|
132
|
+
expect(getByText('hello world')).toHaveCompiledCss('--myCamelVar', 'red');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('should match kebab-case css vars', () => {
|
|
136
|
+
const styles = cssMap({ root: { '--my-kebab-var': 'green' } });
|
|
137
|
+
|
|
138
|
+
const { getByText } = render(<div css={styles.root}>hello world</div>);
|
|
139
|
+
|
|
140
|
+
expect(getByText('hello world')).toHaveCompiledCss('--my-kebab-var', 'green');
|
|
141
|
+
});
|
|
142
|
+
|
|
127
143
|
it('should match styles with media', () => {
|
|
128
144
|
const { getByText } = render(
|
|
129
145
|
<div
|
|
@@ -135,8 +135,8 @@ describe('SSR', () => {
|
|
|
135
135
|
);
|
|
136
136
|
|
|
137
137
|
expect(result.split('</style>').join('</style>\n')).toMatchInlineSnapshot(`
|
|
138
|
-
"<style data-cmpld="true" nonce="k0Mp1lEd">._1e0c1txw{display:flex}._1wyb12am{font-size:50px}._syaz1cnh{color:purple}._ysv75scu:link{color:red}._105332ev:visited{color:pink}._f8pjbf54:focus{color:green}._30l31gy6:hover{color:yellow}._9h8h13q2:active{color:blue}@
|
|
139
|
-
<a href="https://atlassian.design" class="_1e0c1txw _1wyb12am _syaz1cnh
|
|
138
|
+
"<style data-cmpld="true" nonce="k0Mp1lEd">._1e0c1txw{display:flex}._1wyb12am{font-size:50px}._syaz1cnh{color:purple}._ysv75scu:link{color:red}._105332ev:visited{color:pink}._f8pjbf54:focus{color:green}._30l31gy6:hover{color:yellow}._9h8h13q2:active{color:blue}@media (max-width:800px){._1o8z1gy6:focus{color:yellow}._1cld11x8:active{color:black}}@supports (display:grid){._1df61gy6:focus{color:yellow}._7okp11x8:active{color:black}}</style>
|
|
139
|
+
<a href="https://atlassian.design" class="_1e0c1txw _1wyb12am _syaz1cnh _ysv75scu _105332ev _f8pjbf54 _30l31gy6 _9h8h13q2 _1o8z1gy6 _1cld11x8 _1df61gy6 _7okp11x8">Atlassian Design System</a>"
|
|
140
140
|
`);
|
|
141
141
|
});
|
|
142
142
|
|
|
@@ -5,8 +5,8 @@ interface CSSPropertiesSchema {
|
|
|
5
5
|
color: 'var(--ds-text-hover)';
|
|
6
6
|
background: 'var(--ds-surface-hover)' | 'var(--ds-surface-sunken-hover)';
|
|
7
7
|
};
|
|
8
|
-
color: 'var(--ds-text)' | 'var(--ds-text-bold)';
|
|
9
|
-
background: 'var(--ds-surface)' | 'var(--ds-surface-sunken)';
|
|
8
|
+
color: 'var(--ds-text)' | 'var(--ds-text-bold)' | 'var(--ds-text-error)';
|
|
9
|
+
background: 'var(--ds-surface)' | 'var(--ds-surface-sunken)' | 'var(--ds-surface-overlay)';
|
|
10
10
|
bkgrnd: 'red' | 'green';
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/** @jsxImportSource @compiled/react */
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
|
|
4
|
+
import { cssMap, type XCSSProp, cx } from './__fixtures__/strict-api';
|
|
5
|
+
|
|
6
|
+
const styles = cssMap({
|
|
7
|
+
rootNative: {
|
|
8
|
+
color: 'var(--ds-text)',
|
|
9
|
+
background: 'var(--ds-surface)',
|
|
10
|
+
},
|
|
11
|
+
rootComponent: {
|
|
12
|
+
color: 'var(--ds-text-error)',
|
|
13
|
+
background: 'var(--ds-surface-overlay)',
|
|
14
|
+
},
|
|
15
|
+
bold: {
|
|
16
|
+
color: 'var(--ds-text-bold)',
|
|
17
|
+
},
|
|
18
|
+
sunken: {
|
|
19
|
+
background: 'var(--ds-surface-sunken)',
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
function ComponentPassThrough({
|
|
24
|
+
xcss,
|
|
25
|
+
}: {
|
|
26
|
+
xcss?: ReturnType<typeof XCSSProp<'background' | 'color', '&:hover'>>;
|
|
27
|
+
}) {
|
|
28
|
+
return <NativePassThrough xcss={cx(styles.rootComponent, xcss)} />;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function NativePassThrough({
|
|
32
|
+
xcss,
|
|
33
|
+
}: {
|
|
34
|
+
xcss?: ReturnType<typeof XCSSProp<'background' | 'color', '&:hover'>>;
|
|
35
|
+
}) {
|
|
36
|
+
return <button data-testid="button" className={xcss} css={styles.rootNative} />;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe('pass-through props.xcss directly to DOM', () => {
|
|
40
|
+
it('works with no props.xcss', () => {
|
|
41
|
+
const { getByTestId } = render(<NativePassThrough />);
|
|
42
|
+
|
|
43
|
+
expect(getByTestId('button')).toHaveCompiledCss({
|
|
44
|
+
color: 'var(--ds-text)',
|
|
45
|
+
background: 'var(--ds-surface)',
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('works with pass-through props.xcss', () => {
|
|
50
|
+
const { getByTestId } = render(<NativePassThrough xcss={styles.bold} />);
|
|
51
|
+
|
|
52
|
+
expect(getByTestId('button')).toHaveCompiledCss({
|
|
53
|
+
color: 'var(--ds-text-bold)',
|
|
54
|
+
background: 'var(--ds-surface)', // rootNative styles
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('works with pass-through multiple props.xcss via cx', () => {
|
|
59
|
+
const { getByTestId } = render(<NativePassThrough xcss={cx(styles.bold, styles.sunken)} />);
|
|
60
|
+
|
|
61
|
+
expect(getByTestId('button')).toHaveCompiledCss({
|
|
62
|
+
color: 'var(--ds-text-bold)',
|
|
63
|
+
background: 'var(--ds-surface-sunken)',
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe('pass-through props.xcss via another component', () => {
|
|
69
|
+
it('works with no props.xcss', () => {
|
|
70
|
+
const { getByTestId } = render(<ComponentPassThrough />);
|
|
71
|
+
|
|
72
|
+
expect(getByTestId('button')).toHaveCompiledCss({
|
|
73
|
+
color: 'var(--ds-text-error)',
|
|
74
|
+
background: 'var(--ds-surface-overlay)',
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('works with pass-through props.xcss', () => {
|
|
79
|
+
const { getByTestId } = render(<ComponentPassThrough xcss={styles.bold} />);
|
|
80
|
+
|
|
81
|
+
expect(getByTestId('button')).toHaveCompiledCss({
|
|
82
|
+
color: 'var(--ds-text-bold)',
|
|
83
|
+
background: 'var(--ds-surface-overlay)', // rootComponent styles
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('works with pass-through multiple props.xcss via cx', () => {
|
|
88
|
+
const { getByTestId } = render(<ComponentPassThrough xcss={cx(styles.bold, styles.sunken)} />);
|
|
89
|
+
|
|
90
|
+
expect(getByTestId('button')).toHaveCompiledCss({
|
|
91
|
+
color: 'var(--ds-text-bold)',
|
|
92
|
+
background: 'var(--ds-surface-sunken)',
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -39,6 +39,7 @@ export const jsx = createElement;
|
|
|
39
39
|
export namespace jsx {
|
|
40
40
|
export namespace JSX {
|
|
41
41
|
export type Element = CompiledJSX.Element;
|
|
42
|
+
export type ElementType = CompiledJSX.ElementType;
|
|
42
43
|
export type ElementClass = CompiledJSX.ElementClass;
|
|
43
44
|
export type ElementAttributesProperty = CompiledJSX.ElementAttributesProperty;
|
|
44
45
|
export type ElementChildrenAttribute = CompiledJSX.ElementChildrenAttribute;
|
package/src/xcss-prop/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type * as CSS from 'csstype';
|
|
2
2
|
|
|
3
3
|
import type { ApplySchemaValue } from '../create-strict-api/types';
|
|
4
|
-
import {
|
|
4
|
+
import { ax } from '../runtime';
|
|
5
5
|
import type { CSSPseudos, CSSPseudoClasses, CSSProperties, StrictCSSProperties } from '../types';
|
|
6
6
|
|
|
7
7
|
type MarkAsRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] };
|
|
@@ -208,5 +208,5 @@ export const cx = <TStyles extends [...XCSSProp<any, any>[]]>(
|
|
|
208
208
|
|
|
209
209
|
// The output should be a union type of passed in styles. This ensures the call
|
|
210
210
|
// site of xcss prop can raise violations when disallowed styles have been passed.
|
|
211
|
-
return
|
|
211
|
+
return ax(actualStyles) as TStyles[number];
|
|
212
212
|
};
|