Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Container] Fix support for custom breakpoints #26328

Merged
merged 7 commits into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/pages/api-docs/container.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"fixed": { "type": { "name": "bool" } },
"maxWidth": {
"type": {
"name": "enum",
"description": "'lg'<br>&#124;&nbsp;'md'<br>&#124;&nbsp;'sm'<br>&#124;&nbsp;'xl'<br>&#124;&nbsp;'xs'<br>&#124;&nbsp;false"
"name": "union",
"description": "'xs'<br>&#124;&nbsp;'sm'<br>&#124;&nbsp;'md'<br>&#124;&nbsp;'lg'<br>&#124;&nbsp;'xl'<br>&#124;&nbsp;false<br>&#124;&nbsp;string"
},
"default": "'lg'"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/material-ui/src/Container/Container.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import { SxProps } from '@material-ui/system';
import { Theme } from '../styles';
import { OverridableComponent, OverrideProps } from '../OverridableComponent';
import { Breakpoint } from '../styles/createBreakpoints';
import { ContainerClasses } from './containerClasses';

export interface ContainerTypeMap<P = {}, D extends React.ElementType = 'div'> {
Expand Down Expand Up @@ -30,7 +31,7 @@ export interface ContainerTypeMap<P = {}, D extends React.ElementType = 'div'> {
* Set to `false` to disable `maxWidth`.
* @default 'lg'
*/
maxWidth?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | false;
maxWidth?: Breakpoint | false;
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
Expand Down
5 changes: 4 additions & 1 deletion packages/material-ui/src/Container/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ Container.propTypes /* remove-proptypes */ = {
* Set to `false` to disable `maxWidth`.
* @default 'lg'
*/
maxWidth: PropTypes.oneOf(['lg', 'md', 'sm', 'xl', 'xs', false]),
maxWidth: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([
PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl', false]),
PropTypes.string,
]),
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { createTheme } from '@material-ui/core/styles';
import * as React from 'react';
import Container from '@material-ui/core/Container';
import { createTheme, ThemeProvider } from '@material-ui/core/styles';

// testing docs/src/pages/customization/breakpoints/breakpoints.md

Expand All @@ -16,7 +18,7 @@ declare module '@material-ui/core/styles' {
}
}

createTheme({
const theme = createTheme({
breakpoints: {
values: {
mobile: 0,
Expand All @@ -25,4 +27,20 @@ createTheme({
desktop: 1280,
},
},
components: {
MuiContainer: {
defaultProps: {
maxWidth: 'laptop',
},
},
},
});

function MyContainer() {
return (
<ThemeProvider theme={theme}>
hello
<Container maxWidth="tablet">yooo</Container>
</ThemeProvider>
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "../../../../../tsconfig",
"files": ["breakpointsOverrides.spec.ts"]
"files": ["breakpointsOverrides.spec.tsx"]
}