Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/next' into docs/demo-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Jun 25, 2021
2 parents c37b6ec + 583c802 commit 8ab8bec
Show file tree
Hide file tree
Showing 97 changed files with 887 additions and 954 deletions.
68 changes: 32 additions & 36 deletions TYPESCRIPT_CONVENTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
### `Props Interface`

- export interface `{ComponentName}classes` and add comment for generating api docs (for internal components, may or may not expose classes but don't need comment)
- export interface `{ComponentName}classes` from `{component}Classes.ts` and add comment for generating api docs (for internal components, may or may not expose classes but don't need comment)
- export interface `{ComponentName}Props`
- always export props interface (use `interface` over `type`) from the component file
- provide `sx` only for public component
Expand All @@ -17,7 +17,7 @@
<summary>Public component</summary>

```ts
// Foo.tsx
// fooClasses.tsx

export interface FooClasses {
/** Styles applied to the root element. */
Expand All @@ -28,6 +28,15 @@ export interface FooClasses {
disabled: string;
}

const fooClasses: FooClasses = generateUtilityClasses('MuiFoo', ['root', 'foo', 'disabled']);

export default fooClasses;
```

```ts
// Foo.tsx
import { FooClasses } from './fooClasses';

export interface FooProps {
/**
* Override or extend the styles applied to the component.
Expand Down Expand Up @@ -63,33 +72,33 @@ export interface BarProps {
### `ClassKey`

- naming as `{ComponentName}ClassKey`
- export if `classes` exists in props interface using `keyof`
- export if `classes` exists in props interface using `keyof` from `{component}Classes.ts`

```ts
// Foo.tsx
// fooClasses.ts
export interface FooClasses {
...
}

export type FooClassKey = keyof FooClasses;
// verify that FooClassKey is union of string literal
```

### `Classes generator & Utility`

- export if `classes` exist in props interface from the component file
- export if `classes` exists in props interface from the component file
- use `{Component}Classes` as type to preventing typo and missing classes
- use `Private` prefix for internal component

<details>
<summary>Public component</summary>

```ts
// Foo.tsx
// fooClasses.ts
export function getFooUtilityClass(slot: string) {
return generateUtilityClass('MuiFoo', slot);
}

// make sure it has ClassKey as arg in generic
export const fooClasses: FooClasses = generateUtilityClasses('MuiFoo', ['root', 'foo', 'disabled']);

const useUtilityClasses = (styleProps: FooProps & { extraProp: boolean }) => {
// extraProp might be the key/value from react context that this component access
const { foo, disabled, classes } = styleProps;
Expand Down Expand Up @@ -125,15 +134,11 @@ const classes = generateUtilityClasses('PrivateBar', ['root', 'bar']);
<summary>public component</summary>

```ts
const FooRoot = styled(
Typography,
{},
{
name: 'MuiFoo',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
},
)({
const FooRoot = styled(Typography, {
name: 'MuiFoo',
slot: 'Root',
overridesResolver: (props, styles) => styles.root,
})({
// styling
});
```
Expand All @@ -143,11 +148,7 @@ const FooRoot = styled(
<summary>internal component</summary>

```ts
const BarRoot = styled(
Typography,
{},
{ skipSx: true },
)({
const BarRoot = styled(Typography, { skipSx: true })({
// styling
});
```
Expand All @@ -157,15 +158,14 @@ const BarRoot = styled(
<summary>extends interface</summary>

```ts
const BarRoot = styled(
Typography,
{},
{ skipSx: true },
)<{ component?: React.ElementType }>({
const BarRoot = styled(Typography, { skipSx: true })<{
component?: React.ElementType;
styleProps: BarProps;
}>(({ theme, styleProps }) => ({
// styling
});
// passing `component` to BarRoot is safe
// <BarRoot component="span" />
}));
// passing `component` to BarRoot is safe and we don't forget to pass styleProps
// <BarRoot component="span" styleProps={styleProps} />
```

</details>
Expand Down Expand Up @@ -215,11 +215,7 @@ const Foo = React.forwardRef<HTMLSpanElement, FooProps>(function Foo(inProps, re
```ts
const classes = generateUtilityClasses('PrivateBar', ['selected']);

const BarRoot = styled(
'div',
{},
{ skipSx: true },
)(({ theme }) => ({
const BarRoot = styled('div', { skipSx: true })(({ theme }) => ({
[`&.${classes.selected}`]: {
color: theme.palette.text.primary,
},
Expand Down
22 changes: 11 additions & 11 deletions packages/material-ui-lab/src/LoadingButton/LoadingButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ const LoadingButtonRoot = styled(Button, {
name: 'MuiLoadingButton',
slot: 'Root',
overridesResolver: (props, styles) => {
return {
...styles.root,
...(styles.startIconLoadingStart && {
return [
styles.root,
styles.startIconLoadingStart && {
[`& .${loadingButtonClasses.startIconLoadingStart}`]: styles.startIconLoadingStart,
}),
...(styles.endIconLoadingEnd && {
},
styles.endIconLoadingEnd && {
[`& .${loadingButtonClasses.endIconLoadingEnd}`]: styles.endIconLoadingEnd,
}),
};
},
];
},
})(({ styleProps, theme }) => ({
[`& .${loadingButtonClasses.startIconLoadingStart}, & .${loadingButtonClasses.endIconLoadingEnd}`]:
Expand All @@ -70,10 +70,10 @@ const LoadingButtonLoadingIndicator = styled('div', {
slot: 'LoadingIndicator',
overridesResolver: (props, styles) => {
const { styleProps } = props;
return {
...styles.loadingIndicator,
...styles[`loadingIndicator${capitalize(styleProps.loadingPosition)}`],
};
return [
styles.loadingIndicator,
styles[`loadingIndicator${capitalize(styleProps.loadingPosition)}`],
];
},
})(({ theme, styleProps }) => ({
position: 'absolute',
Expand Down
18 changes: 9 additions & 9 deletions packages/material-ui-lab/src/PickersDay/PickersDay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,17 @@ const overridesResolver = (
styles: Record<PickersDayClassKey, object>,
) => {
const { styleProps } = props;
return {
...styles.root,
...(!styleProps.disableMargin && styles.dayWithMargin),
...(!styleProps.disableHighlightToday && styleProps.today && styles.today),
...(!styleProps.outsideCurrentMonth &&
return [
styles.root,
!styleProps.disableMargin && styles.dayWithMargin,
!styleProps.disableHighlightToday && styleProps.today && styles.today,
!styleProps.outsideCurrentMonth &&
styleProps.showDaysOutsideCurrentMonth &&
styles.dayOutsideMonth),
...(styleProps.outsideCurrentMonth &&
styles.dayOutsideMonth,
styleProps.outsideCurrentMonth &&
!styleProps.showDaysOutsideCurrentMonth &&
styles.hiddenDaySpacingFiller),
};
styles.hiddenDaySpacingFiller,
];
};

const PickersDayRoot = styled(ButtonBase, {
Expand Down
10 changes: 5 additions & 5 deletions packages/material-ui-lab/src/Timeline/Timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ const TimelineRoot = styled('ul' as const, {
slot: 'Root',
overridesResolver: (props, styles) => {
const { styleProps } = props;
return {
...styles.root,
...(styleProps.position &&
styles[`position${capitalize(styleProps.position)}` as TimelineClassKey]),
};
return [
styles.root,
styleProps.position &&
styles[`position${capitalize(styleProps.position)}` as TimelineClassKey],
];
},
})<{ styleProps: StyleProps }>({
display: 'flex',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ const TimelineContentRoot = styled(Typography, {
slot: 'Root',
overridesResolver: (props, styles) => {
const { styleProps } = props;
return {
...styles.root,
...styles[`position${capitalize(styleProps.position)}`],
};
return [styles.root, styles[`position${capitalize(styleProps.position)}`]];
},
})(({ styleProps }) => ({
/* Styles applied to the root element. */
Expand Down
10 changes: 5 additions & 5 deletions packages/material-ui-lab/src/TimelineDot/TimelineDot.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ const TimelineDotRoot = styled('span', {
overridesResolver: (props, styles) => {
const { styleProps } = props;

return {
...styles.root,
...styles[
return [
styles.root,
styles[
styleProps.color !== 'inherit' && `${styleProps.variant}${capitalize(styleProps.color)}`
],
...styles[styleProps.variant],
};
styles[styleProps.variant],
];
},
})(({ styleProps, theme }) => ({
/* Styles applied to the root element. */
Expand Down
5 changes: 1 addition & 4 deletions packages/material-ui-lab/src/TimelineItem/TimelineItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ const TimelineItemRoot = styled('li', {
overridesResolver: (props, styles) => {
const { styleProps } = props;

return {
...styles.root,
...styles[`position${capitalize(styleProps.position)}`],
};
return [styles.root, styles[`position${capitalize(styleProps.position)}`]];
},
})(({ styleProps }) => ({
listStyle: 'none',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ const TimelineOppositeContentRoot = styled(Typography, {
slot: 'Root',
overridesResolver: (props, styles) => {
const { styleProps } = props;
return {
...styles.root,
...styles[`position${capitalize(styleProps.position)}`],
};
return [styles.root, styles[`position${capitalize(styleProps.position)}`]];
},
})(({ styleProps }) => ({
/* Styles applied to the root element. */
Expand Down
14 changes: 7 additions & 7 deletions packages/material-ui-lab/src/TreeItem/TreeItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ const StyledTreeItemContent = styled(TreeItemContent, {
name: 'MuiTreeItem',
slot: 'Content',
overridesResolver: (props, styles) => {
return {
...styles.content,
...(styles.iconContainer && {
return [
styles.content,
styles.iconContainer && {
[`& .${treeItemClasses.iconContainer}`]: styles.iconContainer,
}),
...(styles.label && {
},
styles.label && {
[`& .${treeItemClasses.label}`]: styles.label,
}),
};
},
];
},
})(({ theme }) => ({
padding: '0 8px',
Expand Down
12 changes: 6 additions & 6 deletions packages/material-ui/src/Accordion/Accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ const AccordionRoot = styled(Paper, {
overridesResolver: (props, styles) => {
const { styleProps } = props;

return {
[`& .${accordionClasses.region}`]: styles.region,
...styles.root,
...(!styleProps.square && styles.rounded),
...(!styleProps.disableGutters && styles.gutters),
};
return [
{ [`& .${accordionClasses.region}`]: styles.region },
styles.root,
!styleProps.square && styles.rounded,
!styleProps.disableGutters && styles.gutters,
];
},
})(
({ theme }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ const AccordionActionsRoot = styled('div', {
overridesResolver: (props, styles) => {
const { styleProps } = props;

return {
...styles.root,
...(!styleProps.disableSpacing && styles.spacing),
};
return [styles.root, !styleProps.disableSpacing && styles.spacing];
},
})(({ styleProps }) => ({
/* Styles applied to the root element. */
Expand Down
10 changes: 5 additions & 5 deletions packages/material-ui/src/Alert/Alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ const AlertRoot = styled(Paper, {
overridesResolver: (props, styles) => {
const { styleProps } = props;

return {
...styles.root,
...styles[styleProps.variant],
...styles[`${styleProps.variant}${capitalize(styleProps.color || styleProps.severity)}`],
};
return [
styles.root,
styles[styleProps.variant],
styles[`${styleProps.variant}${capitalize(styleProps.color || styleProps.severity)}`],
];
},
})(({ theme, styleProps }) => {
const getColor = theme.palette.mode === 'light' ? darken : lighten;
Expand Down
10 changes: 5 additions & 5 deletions packages/material-ui/src/AppBar/AppBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ const AppBarRoot = styled(Paper, {
overridesResolver: (props, styles) => {
const { styleProps } = props;

return {
...styles.root,
...styles[`position${capitalize(styleProps.position)}`],
...styles[`color${capitalize(styleProps.color)}`],
};
return [
styles.root,
styles[`position${capitalize(styleProps.position)}`],
styles[`color${capitalize(styleProps.color)}`],
];
},
})(({ theme, styleProps }) => {
const backgroundColorDefault =
Expand Down
Loading

0 comments on commit 8ab8bec

Please sign in to comment.