diff --git a/packages/pigment-css-react/exports/createExtendSxProp.js b/packages/pigment-css-react/exports/createExtendSxProp.js new file mode 100644 index 00000000..b459d9d7 --- /dev/null +++ b/packages/pigment-css-react/exports/createExtendSxProp.js @@ -0,0 +1,5 @@ +Object.defineProperty(exports, '__esModule', { + value: true, +}); + +exports.default = require('../processors/createExtendSxProp').CreateExtendSxPropProcessor; diff --git a/packages/pigment-css-react/package.json b/packages/pigment-css-react/package.json index 4c5b47ed..f6dde337 100644 --- a/packages/pigment-css-react/package.json +++ b/packages/pigment-css-react/package.json @@ -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": [ diff --git a/packages/pigment-css-react/src/createExtendSxProp.d.ts b/packages/pigment-css-react/src/createExtendSxProp.d.ts new file mode 100644 index 00000000..11c2b7ff --- /dev/null +++ b/packages/pigment-css-react/src/createExtendSxProp.d.ts @@ -0,0 +1 @@ +export default function createExtendSxProp(): >(props: T) => T; diff --git a/packages/pigment-css-react/src/createExtendSxProp.js b/packages/pigment-css-react/src/createExtendSxProp.js new file mode 100644 index 00000000..eefca5b3 --- /dev/null +++ b/packages/pigment-css-react/src/createExtendSxProp.js @@ -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() { + return extendSxProp; +} diff --git a/packages/pigment-css-react/src/index.ts b/packages/pigment-css-react/src/index.ts index 2b27d96f..b2766401 100644 --- a/packages/pigment-css-react/src/index.ts +++ b/packages/pigment-css-react/src/index.ts @@ -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'; diff --git a/packages/pigment-css-react/src/processors/createExtendSxProp.ts b/packages/pigment-css-react/src/processors/createExtendSxProp.ts new file mode 100644 index 00000000..9767bf12 --- /dev/null +++ b/packages/pigment-css-react/src/processors/createExtendSxProp.ts @@ -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}`; + } +} diff --git a/packages/pigment-css-react/tsup.config.ts b/packages/pigment-css-react/tsup.config.ts index 5fd52716..272fbc45 100644 --- a/packages/pigment-css-react/tsup.config.ts +++ b/packages/pigment-css-react/tsup.config.ts @@ -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 = {