Skip to content

Commit

Permalink
[styled] Replace lowercase with lowerFirst (mui#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp authored May 8, 2024
1 parent bfca706 commit 306d703
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/pigment-css-react/src/processors/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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]);
Expand All @@ -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[]));
}
Expand Down
6 changes: 6 additions & 0 deletions packages/pigment-css-react/src/utils/lowercaseFirstLetter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const lowercaseFirstLetter = (string: string) => {
if (!string) {
return string;
}
return string.charAt(0).toLowerCase() + string.slice(1);
};
Original file line number Diff line number Diff line change
@@ -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',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.njazm0b {
border-color: red;
}
.njazm0b-1 {
border: none;
}
Original file line number Diff line number Diff line change
@@ -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'],
});
24 changes: 24 additions & 0 deletions packages/pigment-css-react/tests/styled/styled.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 306d703

Please sign in to comment.