Skip to content

Commit

Permalink
refactor: lints & less arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
romgrk committed Aug 23, 2024
1 parent 2cf0557 commit ea7b780
Show file tree
Hide file tree
Showing 21 changed files with 42 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const AutocompleteListboxRoot = styled(StyledAutocompleteListbox, {
name: 'JoyAutocompleteListbox',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
})({});
})();
/**
*
* Demos:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const AutocompleteOptionRoot = styled(StyledAutocompleteOption, {
name: 'JoyAutocompleteOption',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
})({});
})();
/**
*
* Demos:
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-joy/src/IconButton/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const IconButtonRoot = styled(StyledIconButton, {
name: 'JoyIconButton',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
})({});
})();

const ButtonLoading = styled('span', {
name: 'JoyIconButton',
Expand Down
8 changes: 4 additions & 4 deletions packages/mui-joy/src/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,25 +212,25 @@ const InputRoot = styled(StyledInputRoot, {
name: 'JoyInput',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
})({});
})();

const InputInput = styled(StyledInputHtml, {
name: 'JoyInput',
slot: 'Input',
overridesResolver: (props, styles) => styles.input,
})({});
})();

const InputStartDecorator = styled(StyledInputStartDecorator, {
name: 'JoyInput',
slot: 'StartDecorator',
overridesResolver: (props, styles) => styles.startDecorator,
})({});
})();

const InputEndDecorator = styled(StyledInputEndDecorator, {
name: 'JoyInput',
slot: 'EndDecorator',
overridesResolver: (props, styles) => styles.endDecorator,
})({});
})();
/**
*
* Demos:
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-joy/src/List/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const ListRoot = styled(StyledList, {
name: 'JoyList',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
})({});
})();
/**
*
* Demos:
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/Breadcrumbs/Breadcrumbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const BreadcrumbsRoot = styled(Typography, {
overridesResolver: (props, styles) => {
return [{ [`& .${breadcrumbsClasses.li}`]: styles.li }, styles.root];
},
})({});
})();

const BreadcrumbsOl = styled('ol', {
name: 'MuiBreadcrumbs',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const DialogContentTextRoot = styled(Typography, {
name: 'MuiDialogContentText',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
})({});
})();

const DialogContentText = React.forwardRef(function DialogContentText(inProps, ref) {
const props = useDefaultProps({ props: inProps, name: 'MuiDialogContentText' });
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/Input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const InputInput = styled(InputBaseInput, {
name: 'MuiInput',
slot: 'Input',
overridesResolver: inputBaseInputOverridesResolver,
})({});
})();

const Input = React.forwardRef(function Input(inProps, ref) {
const props = useDefaultProps({ props: inProps, name: 'MuiInput' });
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/Menu/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const MenuRoot = styled(Popover, {
name: 'MuiMenu',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
})({});
})();

export const MenuPaper = styled(PopoverPaper, {
name: 'MuiMenu',
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-material/src/NativeSelect/NativeSelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const NativeSelectSelect = styled(StyledSelectSelect, {
{ [`&.${nativeSelectClasses.multiple}`]: styles.multiple },
];
},
})({});
})();

export const StyledSelectIcon = styled('svg')(({ theme }) => ({
// We use a position absolute over a flexbox in order to forward the pointer events
Expand Down Expand Up @@ -149,7 +149,7 @@ const NativeSelectIcon = styled(StyledSelectIcon, {
ownerState.open && styles.iconOpen,
];
},
})({});
})();

/**
* @ignore - internal component.
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/Pagination/Pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const PaginationRoot = styled('nav', {

return [styles.root, styles[ownerState.variant]];
},
})({});
})();

const PaginationUl = styled('ul', {
name: 'MuiPagination',
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/Popover/Popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const PopoverRoot = styled(Modal, {
name: 'MuiPopover',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
})({});
})();

export const PopoverPaper = styled(PaperBase, {
name: 'MuiPopover',
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/Popper/Popper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const PopperRoot = styled(BasePopper, {
name: 'MuiPopper',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
})({});
})();

/**
*
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/Select/SelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const SelectIcon = styled(StyledSelectIcon, {
ownerState.open && styles.iconOpen,
];
},
})({});
})();

const SelectNativeInput = styled('input', {
shouldForwardProp: (prop) => slotShouldForwardProp(prop) && prop !== 'classes',
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/StepContent/StepContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const StepContentTransition = styled(Collapse, {
name: 'MuiStepContent',
slot: 'Transition',
overridesResolver: (props, styles) => styles.transition,
})({});
})();

const StepContent = React.forwardRef(function StepContent(inProps, ref) {
const props = useDefaultProps({ props: inProps, name: 'MuiStepContent' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const TablePaginationMenuItem = styled(MenuItem, {
name: 'MuiTablePagination',
slot: 'MenuItem',
overridesResolver: (props, styles) => styles.menuItem,
})({});
})();

const TablePaginationDisplayedRows = styled('p', {
name: 'MuiTablePagination',
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/TextField/TextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const TextFieldRoot = styled(FormControl, {
name: 'MuiTextField',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
})({});
})();

/**
* The `TextField` is a convenience wrapper for the most common cases (80%).
Expand Down
26 changes: 13 additions & 13 deletions packages/mui-system/src/createStyled/createStyled.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ export default function createStyled(input = {}) {
return style;
};

const muiStyledResolver = (expressionFirst, ...expressionsMiddle) => {
expressionFirst = transformStyle(expressionFirst)

const muiStyledResolver = (...expressionsMiddle) => {
const expressionsHead = []
const expressionsTail = []

Expand Down Expand Up @@ -210,23 +208,25 @@ export default function createStyled(input = {}) {
expressionsTail.push(styleFunctionSx);
}

// This function can be called as a tagged template, so `style` would contain CSS
// `string[]` values and `expressions` would contain the interpolated values.
if (Array.isArray(expressionFirst)) {
// This function can be called as a tagged template, so the first argument would contain
// CSS `string[]` values.
if (Array.isArray(expressionsMiddle[0])) {
const inputStrings = expressionsMiddle.shift();

// We need to add placeholders in the tagged template for the custom functions we have
// possibly added (attachTheme, overrides, variants, and sx).
const placeholdersHead = new Array(expressionsHead.length).fill('');
const placeholdersTail = new Array(expressionsTail.length).fill('');

let taggedStrings;
taggedStrings = [...placeholdersHead, ...expressionFirst, ...placeholdersTail];
taggedStrings.raw = [...placeholdersHead, ...expressionFirst.raw, ...placeholdersTail];
let outputStrings;
// prettier-ignore
{
outputStrings = [...placeholdersHead, ...inputStrings, ...placeholdersTail];
outputStrings.raw = [...placeholdersHead, ...inputStrings.raw, ...placeholdersTail];
}

// The only case where we put something before `attachTheme`
expressionsHead.unshift(taggedStrings)
} else {
// But otherwise, we always want attachTheme to stay first.
expressionsHead.push(expressionFirst)
expressionsHead.unshift(outputStrings)
}

const expressions = [
Expand Down
3 changes: 1 addition & 2 deletions packages/mui-system/src/memoTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export default function memoTheme<T>(styleFn: ThemeStyleFunction<T>) {
if (value === undefined || props.theme !== lastTheme) {
arg.theme = props.theme;

value = styleFn(arg);
value = preprocessStyles(value);
value = preprocessStyles(styleFn(arg));

lastValue = value;
lastTheme = props.theme;
Expand Down
10 changes: 4 additions & 6 deletions packages/mui-system/src/preprocessStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ export default function preprocessStyles(styles: any) {
const variants = styles.variants

// Avoid passing `style.variants` to emotion, it will pollute the styles.
styles.variants = undefined
if (variants) { styles.variants = undefined }
const serialized = internal_serializeStyles(styles) as any
styles.variants = variants
if (variants) { styles.variants = variants }

// Not supported on styled-components
if (serialized === styles) {
Expand All @@ -15,11 +15,9 @@ export default function preprocessStyles(styles: any) {

if (variants) {
variants.forEach((variant: any) => {
if (typeof variant.style === 'function') {
return variant
if (typeof variant.style !== 'function') {
variant.style = internal_serializeStyles(variant.style)
}

variant.style = internal_serializeStyles(variant.style)
})

serialized.variants = variants
Expand Down
6 changes: 3 additions & 3 deletions test/integration/mui-system/createStyled.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('createStyled', () => {
const styled = createStyled({});
const SomeMuiComponent = styled(function SomeMuiComponent() {
return null;
})({});
})();

expect(SomeMuiComponent).to.have.property('displayName', 'Styled(SomeMuiComponent)');
});
Expand Down Expand Up @@ -185,12 +185,12 @@ describe('createStyled', () => {
styles.root,
{ [`& .MuiButton-avatar`]: styles.avatar },
],
})({});
})();
const ButtonIcon = styled('span', {
name: 'MuiButton',
slot: 'Icon',
overridesResolver: (props, styles) => styles.icon,
})({});
})();
function Button({ children, startIcon, endIcon, color = 'primary', ...props }) {
const ownerState = { startIcon, endIcon, color, ...props };
return (
Expand Down

0 comments on commit ea7b780

Please sign in to comment.