Skip to content

Commit 2321cf6

Browse files
authored
[zero] Migrate to use wyw-in-js instead of linaria (#40866)
1 parent af92b52 commit 2321cf6

File tree

22 files changed

+285
-252
lines changed

22 files changed

+285
-252
lines changed

apps/zero-runtime-vite-app/src/App.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import * as React from 'react';
2-
import { styled, generateAtomics, css } from '@mui/zero-runtime';
2+
import { styled, generateAtomics } from '@mui/zero-runtime';
33
import type { Breakpoint } from '@mui/system';
44
import { Button, bounceAnim } from 'local-ui-lib';
55
import Slider from './Slider/ZeroSlider';
6+
import { Box } from './Box';
67

78
const ShowCaseDiv = styled('div')({
89
[`.${Button}`]: {
@@ -57,11 +58,7 @@ export function App({ isRed }: AppProps) {
5758
const [isHorizontal, setIsHorizontal] = React.useState(true);
5859

5960
return (
60-
<div
61-
className={css`
62-
color: red;
63-
`}
64-
>
61+
<div>
6562
<ShowCaseDiv>
6663
<Button>This button&apos;s text color has been overridden.</Button>
6764
</ShowCaseDiv>
@@ -171,6 +168,7 @@ export function App({ isRed }: AppProps) {
171168
<span>Hello2</span>
172169
</div>
173170
</div>
171+
<Box as="div">Hello</Box>
174172
</div>
175173
);
176174
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { generateAtomics } from '@mui/zero-runtime';
2+
3+
const atomics = generateAtomics(({ theme }) => ({
4+
conditions: Object.keys(theme.breakpoints.values).reduce((acc, breakpoint) => {
5+
acc[breakpoint] = `@media (min-width: ${theme.breakpoints.values[breakpoint]}${
6+
theme.breakpoints.unit ?? 'px'
7+
})`;
8+
return acc;
9+
}, {}),
10+
defaultCondition: 'xs',
11+
properties: {
12+
display: [
13+
'block',
14+
'inline-flex',
15+
'contents',
16+
'none',
17+
'flex',
18+
'inline-flex',
19+
'grid',
20+
'inline-grid',
21+
],
22+
flexDirection: ['row', 'row-reverse', 'column', 'column-reverse'],
23+
justifyContent: [
24+
'center',
25+
'end',
26+
'flex-end',
27+
'flex-start',
28+
'left',
29+
'right',
30+
'space-around',
31+
'space-between',
32+
'space-evenly',
33+
'start',
34+
],
35+
alignItems: [
36+
'baseline',
37+
'center',
38+
'end',
39+
'flex-end',
40+
'flex-start',
41+
'self-end',
42+
'self-start',
43+
'start',
44+
'stretch',
45+
],
46+
position: ['relative', 'absolute', 'static', 'sticky', 'fixed'],
47+
},
48+
shorthands: {
49+
direction: ['flexDirection'],
50+
},
51+
}));
52+
53+
// eslint-disable-next-line react/prop-types
54+
export function Box({ children, as = 'div', className = '', style = undefined, ...rest }) {
55+
const Component = as;
56+
const atomicsResult = atomics(rest);
57+
const componentClass = `${atomicsResult.className} ${className ?? ''}`.trim();
58+
const finalStyles = {
59+
...(atomicsResult.style ?? {}),
60+
...style,
61+
};
62+
return (
63+
// eslint-disable-next-line react/jsx-filename-extension
64+
<Component className={componentClass} style={finalStyles}>
65+
{children}
66+
</Component>
67+
);
68+
}

apps/zero-runtime-vite-app/vite.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,12 @@ export default defineConfig({
2222
reactPlugin(),
2323
splitVendorChunkPlugin(),
2424
],
25+
resolve: {
26+
alias: [
27+
{
28+
find: /^@mui\/system\/(.*)/,
29+
replacement: '@mui/system/esm/$1',
30+
},
31+
],
32+
},
2533
});

packages/mui-material/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"@mui/system": "workspace:^",
4949
"@mui/types": "workspace:^",
5050
"@mui/utils": "workspace:^",
51+
"@mui/zero-runtime": "workspace:^",
5152
"@types/react-transition-group": "^4.4.10",
5253
"clsx": "^2.1.0",
5354
"csstype": "^3.1.2",

packages/zero-next-plugin/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { NextConfig } from 'next';
33
import { findPagesDir } from 'next/dist/lib/find-pages-dir';
44
import {
55
webpack as zeroWebpackPlugin,
6-
PluginOptions as BaseZeroPluginConfig,
6+
type PluginOptions as BaseZeroPluginConfig,
77
} from '@mui/zero-unplugin';
88

99
export type ZeroPluginConfig = BaseZeroPluginConfig & {

packages/zero-runtime/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"typecheck": "tsc --noEmit -p ."
1313
},
1414
"dependencies": {
15-
"csstype": "^3.1.2",
15+
"csstype": "^3.1.3",
1616
"cssesc": "^3.0.0",
1717
"clsx": "^2.1.0",
1818
"@babel/core": "^7.23.9",
@@ -22,12 +22,12 @@
2222
"@babel/types": "^7.23.9",
2323
"@emotion/css": "^11.11.2",
2424
"@emotion/serialize": "^1.1.3",
25-
"@emotion/styled": "^11.11.0",
26-
"@linaria/tags": "^5.0.2",
27-
"@linaria/utils": "^5.0.2",
25+
"@wyw-in-js/processor-utils": "^0.3.0",
26+
"@wyw-in-js/shared": "^0.3.0",
27+
"@wyw-in-js/transform": "^0.3.0",
2828
"@mui/system": "workspace:^",
2929
"lodash": "^4.17.21",
30-
"stylis": "^4.2.0"
30+
"stylis": "^4.3.1"
3131
},
3232
"devDependencies": {
3333
"@types/babel__core": "^7.20.5",
@@ -37,7 +37,7 @@
3737
"@types/lodash": "^4.14.202",
3838
"@types/node": "^18.19.14",
3939
"@types/react": "^18.2.55",
40-
"@types/stylis": "^4.2.0",
40+
"@types/stylis": "^4.2.5",
4141
"react": "^18.2.0"
4242
},
4343
"peerDependencies": {
@@ -47,7 +47,7 @@
4747
"publishConfig": {
4848
"access": "public"
4949
},
50-
"linaria": {
50+
"wyw-in-js": {
5151
"tags": {
5252
"styled": "./exports/styled.js",
5353
"default": "./exports/styled.js",

packages/zero-runtime/src/processors/base-processor.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import { slugify, IVariableContext } from '@wyw-in-js/shared';
12
import {
2-
BaseProcessor as LinariaBaseProcessor,
3-
toValidCSSIdentifier,
43
buildSlug,
5-
} from '@linaria/tags';
6-
import { slugify, type IVariableContext } from '@linaria/utils';
4+
BaseProcessor as WywBaseProcessor,
5+
toValidCSSIdentifier,
6+
} from '@wyw-in-js/processor-utils';
77

8-
export default abstract class BaseProcessor extends LinariaBaseProcessor {
8+
export default abstract class BaseProcessor extends WywBaseProcessor {
99
variableIdx = 0;
1010

1111
// Implementation taken from Linaria - https://github.com/callstack/linaria/blob/master/packages/react/src/processors/styled.ts#L284

packages/zero-runtime/src/processors/createUseThemeProps.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { validateParams, IOptions as IBaseOptions } from '@linaria/tags';
2-
import type { Expression, Params, TailProcessorParams } from '@linaria/tags';
1+
import { validateParams, IOptions as IBaseOptions } from '@wyw-in-js/processor-utils';
2+
import type { Expression, Params, TailProcessorParams } from '@wyw-in-js/processor-utils';
33
import BaseProcessor from './base-processor';
44
import { valueToLiteral } from '../utils/valueToLiteral';
55

@@ -13,12 +13,13 @@ export class CreateUseThemePropsProcessor extends BaseProcessor {
1313
componentName: string;
1414

1515
constructor(params: Params, ...args: TailProcessorParams) {
16-
super(params, ...args);
16+
// this is already transformed if there is an extra argument
1717
if (params.length > 2) {
18-
// no need to do any processing if it is an already transformed call or just a reference.
1918
throw BaseProcessor.SKIP;
2019
}
21-
validateParams(params, ['callee', 'call'], `Invalid use of ${this.tagSource.imported} tag.`);
20+
validateParams(params, ['callee', 'call'], 'Invalid use of createUseThemeProps tag.');
21+
22+
super([params[0]], ...args);
2223
const [, callParam] = params;
2324
const [, callArg] = callParam;
2425
if (!callArg || callArg.ex.type !== 'StringLiteral') {

packages/zero-runtime/src/processors/css.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import type { Expression } from '@babel/types';
2-
import { validateParams } from '@linaria/tags';
2+
import { validateParams } from '@wyw-in-js/processor-utils';
33
import type {
44
CallParam,
55
TemplateParam,
66
Params,
77
TailProcessorParams,
88
ValueCache,
9-
} from '@linaria/tags';
10-
import type { Replacements, Rules } from '@linaria/utils';
11-
import { ValueType } from '@linaria/utils';
9+
} from '@wyw-in-js/processor-utils';
10+
import type { Replacements, Rules } from '@wyw-in-js/shared';
11+
import { ValueType } from '@wyw-in-js/shared';
1212
import type { CSSInterpolation } from '@emotion/css';
1313
import deepMerge from 'lodash/merge';
1414
import BaseProcessor from './base-processor';
@@ -34,10 +34,10 @@ export class CssProcessor extends BaseProcessor {
3434
callParam: CallParam | TemplateParam;
3535

3636
constructor(params: Params, ...args: TailProcessorParams) {
37-
super(params, ...args);
3837
if (params.length < 2) {
3938
throw BaseProcessor.SKIP;
4039
}
40+
super([params[0]], ...args);
4141
validateParams(
4242
params,
4343
['callee', ['call', 'template']],

packages/zero-runtime/src/processors/generateAtomics.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import {
44
type TailProcessorParams,
55
type ValueCache,
66
validateParams,
7-
} from '@linaria/tags';
8-
import { ValueType } from '@linaria/utils';
9-
import type { ExpressionValue, Replacements, Rules } from '@linaria/utils';
7+
} from '@wyw-in-js/processor-utils';
8+
import { ValueType, type ExpressionValue, type Replacements, type Rules } from '@wyw-in-js/shared';
109

1110
import { CSSInterpolation } from '@emotion/css';
1211
import BaseProcessor from './base-processor';
@@ -25,8 +24,7 @@ export class GenerateAtomicsProcessor extends BaseProcessor {
2524
runtimeConfig?: RuntimeConfig;
2625

2726
constructor(params: Params, ...args: TailProcessorParams) {
28-
super(params, ...args);
29-
27+
super([params[0]], ...args);
3028
validateParams(params, ['callee', ['call']], `Invalid use of ${this.tagSource.imported} tag.`);
3129
const [, callParam] = params;
3230
const [, callParamArgument] = callParam;

0 commit comments

Comments
 (0)