Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[react] Add createExtendSxProp for Material UI integration #112

Merged
merged 7 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/pigment-css-react/exports/createExtendSxProp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Object.defineProperty(exports, '__esModule', {
value: true,
});

exports.default = require('../processors/createExtendSxProp').CreateExtendSxPropProcessor;
3 changes: 2 additions & 1 deletion packages/pigment-css-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
"keyframes": "./exports/keyframes.js",
"generateAtomics": "./exports/generateAtomics.js",
"css": "./exports/css.js",
"createUseThemeProps": "./exports/createUseThemeProps.js"
"createUseThemeProps": "./exports/createUseThemeProps.js",
"createExtendSxProp": "./exports/createExtendSxProp.js"
}
},
"files": [
Expand Down
1 change: 1 addition & 0 deletions packages/pigment-css-react/src/createExtendSxProp.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function createExtendSxProp(): <T extends Record<string, any>>(props: T) => T;
12 changes: 12 additions & 0 deletions packages/pigment-css-react/src/createExtendSxProp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Runtime function for creating `extendSxProp`.
*
* This is a placeholder for the runtime function for replacing the `extendSxProp` in Material UI
* to reduce bundle size only. DO NOT use it in your codebase.
*/
function extendSxProp(props) {
return props;
}
export default function createExtendSxProp() {
siriwatknp marked this conversation as resolved.
Show resolved Hide resolved
return extendSxProp;
}
1 change: 1 addition & 0 deletions packages/pigment-css-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export { default as keyframes } from './keyframes';
export { generateAtomics, atomics } from './generateAtomics';
export { default as css } from './css';
export { default as createUseThemeProps } from './createUseThemeProps';
export { default as createExtendSxProp } from './createExtendSxProp';
export { default as Box } from './Box';
35 changes: 35 additions & 0 deletions packages/pigment-css-react/src/processors/createExtendSxProp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { Expression, Params, TailProcessorParams } from '@wyw-in-js/processor-utils';
import BaseProcessor from './base-processor';

export class CreateExtendSxPropProcessor extends BaseProcessor {
constructor(params: Params, ...args: TailProcessorParams) {
super([params[0]], ...args);
}

// eslint-disable-next-line class-methods-use-this
build(): void {}

doEvaltimeReplacement(): void {
this.replacer(this.value, false);
}

get value(): Expression {
return this.astService.nullLiteral();
}

doRuntimeReplacement(): void {
const t = this.astService;

const extendSxPropImportIdentifier = t.addNamedImport(
this.tagSource.imported,
process.env.PACKAGE_NAME as string,
);

this.replacer(t.callExpression(extendSxPropImportIdentifier, []), true);
}

public override get asSelector(): string {
// For completeness, this is not intended to be used.
return `.${this.className}`;
}
}
10 changes: 9 additions & 1 deletion packages/pigment-css-react/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { Options, defineConfig } from 'tsup';
import config from '../../tsup.config';

const processors = ['styled', 'sx', 'keyframes', 'generateAtomics', 'css', 'createUseThemeProps'];
const processors = [
'styled',
'sx',
'keyframes',
'generateAtomics',
'css',
'createUseThemeProps',
'createExtendSxProp',
];
const external = ['react', 'react-is', 'prop-types'];

const baseConfig: Options = {
Expand Down
Loading