diff --git a/packages/pigment-css-react/src/processors/styled.ts b/packages/pigment-css-react/src/processors/styled.ts index fa2021df..5b029f68 100644 --- a/packages/pigment-css-react/src/processors/styled.ts +++ b/packages/pigment-css-react/src/processors/styled.ts @@ -26,6 +26,7 @@ import type { PluginCustomOptions } from '../utils/cssFnValueToVariable'; import { cssFnValueToVariable } from '../utils/cssFnValueToVariable'; import { processCssObject } from '../utils/processCssObject'; import { valueToLiteral } from '../utils/valueToLiteral'; +import { lowercaseFirstLetter } from '../utils/lowercaseFirstLetter'; import BaseProcessor from './base-processor'; import { Primitive, TemplateCallback } from './keyframes'; import { cache, css } from '../utils/emotion'; @@ -470,9 +471,8 @@ export class StyledProcessor extends BaseProcessor { if (!overrides) { return; } - const overrideStyle = (overrides[value.slot.toLowerCase()] || overrides[value.slot]) as - | string - | CSSObject; + const overrideStyle = (overrides[lowercaseFirstLetter(value.slot)] || + overrides[value.slot]) as string | CSSObject; const className = this.getClassName(); if (typeof overrideStyle === 'string') { this.collectedStyles.push([className, overrideStyle, null]); @@ -490,7 +490,7 @@ export class StyledProcessor extends BaseProcessor { if ( 'variants' in componentData && componentData.variants && - value.slot.toLowerCase() === 'root' + lowercaseFirstLetter(value.slot) === 'root' ) { variantsAccumulator.push(...(componentData.variants as unknown as VariantData[])); } diff --git a/packages/pigment-css-react/src/utils/lowercaseFirstLetter.ts b/packages/pigment-css-react/src/utils/lowercaseFirstLetter.ts new file mode 100644 index 00000000..2c0b3c70 --- /dev/null +++ b/packages/pigment-css-react/src/utils/lowercaseFirstLetter.ts @@ -0,0 +1,6 @@ +export const lowercaseFirstLetter = (string: string) => { + if (!string) { + return string; + } + return string.charAt(0).toLowerCase() + string.slice(1); +}; diff --git a/packages/pigment-css-react/tests/styled/fixtures/styled-theme-styleOverrides.input.js b/packages/pigment-css-react/tests/styled/fixtures/styled-theme-styleOverrides.input.js new file mode 100644 index 00000000..50e55f91 --- /dev/null +++ b/packages/pigment-css-react/tests/styled/fixtures/styled-theme-styleOverrides.input.js @@ -0,0 +1,9 @@ +import { styled } from '@pigment-css/react'; + +const NotchedOutlineRoot = styled('fieldset', { + name: 'MuiOutlinedInput', + slot: 'NotchedOutline', + overridesResolver: (props, styles) => styles.notchedOutline, +})({ + borderColor: 'red', +}); diff --git a/packages/pigment-css-react/tests/styled/fixtures/styled-theme-styleOverrides.output.css b/packages/pigment-css-react/tests/styled/fixtures/styled-theme-styleOverrides.output.css new file mode 100644 index 00000000..0414e662 --- /dev/null +++ b/packages/pigment-css-react/tests/styled/fixtures/styled-theme-styleOverrides.output.css @@ -0,0 +1,6 @@ +.njazm0b { + border-color: red; +} +.njazm0b-1 { + border: none; +} diff --git a/packages/pigment-css-react/tests/styled/fixtures/styled-theme-styleOverrides.output.js b/packages/pigment-css-react/tests/styled/fixtures/styled-theme-styleOverrides.output.js new file mode 100644 index 00000000..b109577a --- /dev/null +++ b/packages/pigment-css-react/tests/styled/fixtures/styled-theme-styleOverrides.output.js @@ -0,0 +1,9 @@ +import { styled as _styled } from '@pigment-css/react'; +import _theme from '@pigment-css/react/theme'; +const NotchedOutlineRoot = /*#__PURE__*/ _styled('fieldset', { + name: 'MuiOutlinedInput', + slot: 'NotchedOutline', + overridesResolver: (props, styles) => styles.notchedOutline, +})({ + classes: ['njazm0b', 'njazm0b-1'], +}); diff --git a/packages/pigment-css-react/tests/styled/styled.test.tsx b/packages/pigment-css-react/tests/styled/styled.test.tsx index 4e555d74..01db740d 100644 --- a/packages/pigment-css-react/tests/styled/styled.test.tsx +++ b/packages/pigment-css-react/tests/styled/styled.test.tsx @@ -81,4 +81,28 @@ describe('Pigment CSS - styled', () => { expect(output.js).to.equal(fixture.js); expect(output.css).to.equal(fixture.css); }); + + it('should work with theme styleOverrides', async () => { + const { output, fixture } = await runTransformation( + path.join(__dirname, 'fixtures/styled-theme-styleOverrides.input.js'), + { + themeArgs: { + theme: { + components: { + MuiOutlinedInput: { + styleOverrides: { + notchedOutline: { + border: 'none', + }, + }, + }, + }, + }, + }, + }, + ); + + expect(output.js).to.equal(fixture.js); + expect(output.css).to.equal(fixture.css); + }); });