Skip to content

Commit

Permalink
[core] Normalize rest / other to match the most common used
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Jul 15, 2024
1 parent 3bd6616 commit 44c3c9a
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions apps/pigment-css-vite-app/src/Box.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ const atomics = generateAtomics(({ theme }) => ({
}));

// eslint-disable-next-line react/prop-types
export function Box({ children, as = 'div', className = '', style = undefined, ...rest }) {
export function Box({ children, as = 'div', className = '', style = undefined, ...other }) {
const Component = as;
const atomicsResult = atomics(rest);
const atomicsResult = atomics(other);
const componentClass = `${atomicsResult.className} ${className ?? ''}`.trim();
const finalStyles = {
...(atomicsResult.style ?? {}),
Expand Down
4 changes: 2 additions & 2 deletions packages/pigment-css-nextjs-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const extractionFile = path.join(
);

export function withPigment(nextConfig: NextConfig, pigmentConfig?: PigmentOptions) {
const { babelOptions = {}, asyncResolve, ...rest } = pigmentConfig ?? {};
const { babelOptions = {}, asyncResolve, ...other } = pigmentConfig ?? {};
if (process.env.TURBOPACK === '1') {
// eslint-disable-next-line no-console
console.log(
Expand Down Expand Up @@ -46,7 +46,7 @@ export function withPigment(nextConfig: NextConfig, pigmentConfig?: PigmentOptio
});
config.plugins.push(
webpackPlugin({
...rest,
...other,
meta: {
type: 'next',
dev,
Expand Down
4 changes: 2 additions & 2 deletions packages/pigment-css-react/src/Box.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const Box = React.forwardRef(
sx,
className,
style,
...rest
...other
},
ref,
) => {
Expand Down Expand Up @@ -48,7 +48,7 @@ const Box = React.forwardRef(
};

// eslint-disable-next-line react/jsx-filename-extension
return <Component ref={ref} className={classes} style={styles} {...rest} />;
return <Component ref={ref} className={classes} style={styles} {...other} />;
},
);

Expand Down
4 changes: 2 additions & 2 deletions packages/pigment-css-react/src/Grid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const Grid = React.forwardRef(function Grid(
// eslint-disable-next-line react/prop-types
unstable_parent_row_spacing,
wrap = 'wrap',
...rest
...other
},
ref,
) {
Expand Down Expand Up @@ -205,7 +205,7 @@ const Grid = React.forwardRef(function Grid(
ref={ref}
className={clsx(gridClasses.className, className)}
style={{ ...style, ...gridClasses.style }}
{...rest}
{...other}
ownerState={ownerState}
>
{React.Children.map(children, (child) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/pigment-css-react/src/Hidden.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Hidden = React.forwardRef(function Hidden(
{ className, component = 'div', style, ...props },
ref,
) {
const rest = {};
const other = {};
const breakpointProps = {};
Object.keys(props).forEach((key) => {
if (key.endsWith('Up') || key.endsWith('Down')) {
Expand All @@ -41,7 +41,7 @@ const Hidden = React.forwardRef(function Hidden(
});
}
} else {
rest[key] = props[key];
other[key] = props[key];
}
});
const stackClasses = hiddenAtomics({ display: breakpointProps });
Expand All @@ -51,7 +51,7 @@ const Hidden = React.forwardRef(function Hidden(
ref={ref}
className={clsx(stackClasses.className, className)}
style={{ ...style, ...stackClasses.style }}
{...rest}
{...other}
/>
);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/pigment-css-react/src/Stack.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const Stack = React.forwardRef(function Stack(
divider,
component = 'div',
direction = 'column',
...rest
...other
},
ref,
) {
Expand All @@ -84,7 +84,7 @@ const Stack = React.forwardRef(function Stack(
className,
)}
style={{ ...style, ...stackClasses.style }}
{...rest}
{...other}
>
{divider ? joinChildren(children, divider) : children}
</Component>
Expand Down
4 changes: 2 additions & 2 deletions packages/pigment-css-react/tests/Grid/fixtures/Grid.output.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ const Grid = React.forwardRef(function Grid(
// eslint-disable-next-line react/prop-types
unstable_parent_row_spacing,
wrap = 'wrap',
...rest
...other
},
ref,
) {
Expand Down Expand Up @@ -301,7 +301,7 @@ const Grid = React.forwardRef(function Grid(
...style,
...gridClasses.style,
}}
{...rest}
{...other}
ownerState={ownerState}
>
{React.Children.map(children, (child) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const Hidden = React.forwardRef(function Hidden(
{ className, component = 'div', style, ...props },
ref,
) {
const rest = {};
const other = {};
const breakpointProps = {};
Object.keys(props).forEach((key) => {
if (key.endsWith('Up') || key.endsWith('Down')) {
Expand Down Expand Up @@ -82,7 +82,7 @@ const Hidden = React.forwardRef(function Hidden(
...style,
...stackClasses.style,
}}
{...rest}
{...other}
/>
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('props filtering', () => {
const Link = styled('a')`
color: green;
`;
const rest = { m: [3], pt: [4] };
const other = { m: [3], pt: [4] };

const { container } = render(
<Link
Expand All @@ -64,7 +64,7 @@ describe('props filtering', () => {
aria-label="some label"
data-wow="value"
href="link"
{...rest}
{...other}
>
hello world
</Link>,
Expand Down
10 changes: 5 additions & 5 deletions packages/pigment-css-unplugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const plugin = createUnplugin<PigmentOptions, true>((options) => {
overrideContext,
tagResolver,
css,
...rest
...other
} = options;
const finalTransformLibraries = transformLibraries
.concat([process.env.RUNTIME_PACKAGE_NAME as string, '@mui/material-pigment-css'])
Expand Down Expand Up @@ -227,7 +227,7 @@ export const plugin = createUnplugin<PigmentOptions, true>((options) => {
root: projectPath,
preprocessor: preprocessor ?? withRtl,
pluginOptions: {
...rest,
...other,
themeArgs: {
theme,
},
Expand All @@ -241,7 +241,7 @@ export const plugin = createUnplugin<PigmentOptions, true>((options) => {
features: {
useWeakRefInEval: false,
// If users know what they are doing, let them override to true
...rest.features,
...other.features,
},
overrideContext(context: Record<string, unknown>, filename: string) {
if (!context.$RefreshSig$) {
Expand All @@ -264,13 +264,13 @@ export const plugin = createUnplugin<PigmentOptions, true>((options) => {
return null;
},
babelOptions: {
...rest.babelOptions,
...other.babelOptions,
plugins: [
require.resolve(
`${process.env.RUNTIME_PACKAGE_NAME}/exports/remove-prop-types-plugin`,
),
'babel-plugin-define-var', // A fix for undefined variables in the eval phase of wyw-in-js, more details on https://github.com/siriwatknp/babel-plugin-define-var?tab=readme-ov-file#problem
...(rest.babelOptions?.plugins ?? []),
...(other.babelOptions?.plugins ?? []),
],
},
},
Expand Down
4 changes: 2 additions & 2 deletions packages/pigment-css-vite-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function pigment(options: PigmentOptions) {
transformLibraries = [],
transformSx = true,
css,
...rest
...other
} = options ?? {};
const defaultLibs = [process.env.RUNTIME_PACKAGE_NAME as string, MATERIAL_WRAPPER_LIB];
const allLibs = transformLibraries.concat(defaultLibs);
Expand Down Expand Up @@ -169,7 +169,7 @@ export function pigment(options: PigmentOptions) {
...babelOptions,
plugins: ['@babel/plugin-syntax-typescript', ...(babelOptions.plugins ?? [])],
},
...rest,
...other,
});

return [
Expand Down
12 changes: 6 additions & 6 deletions packages/pigment-css-vite-plugin/src/vite-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default function wywVitePlugin({
overrideContext,
tagResolver,
css: cssConfig,
...rest
...other
}: VitePluginOptions = {}): Plugin {
const filter = createFilter(include, exclude);
const cssLookup = new Map<string, string>();
Expand Down Expand Up @@ -191,7 +191,7 @@ export default function wywVitePlugin({
};

const presets = new Set(
Array.isArray(rest.babelOptions?.presets) ? rest.babelOptions?.presets : [],
Array.isArray(other.babelOptions?.presets) ? other.babelOptions?.presets : [],
);
presets.add('@babel/preset-typescript');

Expand All @@ -203,20 +203,20 @@ export default function wywVitePlugin({
root: process.cwd(),
preprocessor,
pluginOptions: {
...rest,
...other,
features: {
useWeakRefInEval: false,
// If users know what they are doing, let them override to true
...rest.features,
...other.features,
},
babelOptions: {
...rest.babelOptions,
...other.babelOptions,
plugins: [
require.resolve(
`${process.env.RUNTIME_PACKAGE_NAME}/exports/remove-prop-types-plugin`,
),
'babel-plugin-define-var', // A fix for undefined variables in the eval phase of wyw-in-js, more details on https://github.com/siriwatknp/babel-plugin-define-var?tab=readme-ov-file#problem
...(rest.babelOptions?.plugins ?? []),
...(other.babelOptions?.plugins ?? []),
],
presets: Array.from(presets),
},
Expand Down

0 comments on commit 44c3c9a

Please sign in to comment.