Skip to content

Commit

Permalink
[Dialog] Add xl maxWidth and demo component (#13694)
Browse files Browse the repository at this point in the history
* [Dialog] Add xl maxWidth and demo component

* let's merge
  • Loading branch information
dispix authored and oliviertassinari committed Nov 26, 2018
1 parent d9c790f commit 072959c
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 4 deletions.
121 changes: 121 additions & 0 deletions docs/src/pages/demos/dialogs/MaxWidthDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';
import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
import DialogContentText from '@material-ui/core/DialogContentText';
import DialogTitle from '@material-ui/core/DialogTitle';
import FormControl from '@material-ui/core/FormControl';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import InputLabel from '@material-ui/core/InputLabel';
import MenuItem from '@material-ui/core/MenuItem';
import Select from '@material-ui/core/Select';
import Switch from '@material-ui/core/Switch';

const styles = theme => ({
form: {
display: 'flex',
flexDirection: 'column',
margin: 'auto',
width: 'fit-content',
},
formControl: {
marginTop: theme.spacing.unit * 2,
minWidth: 120,
},
formControlLabel: {
marginTop: theme.spacing.unit,
},
});

class FullScreenDialog extends React.Component {
state = {
open: false,
fullWidth: true,
maxWidth: 'sm',
};

handleClickOpen = () => {
this.setState({ open: true });
};

handleClose = () => {
this.setState({ open: false });
};

handleMaxWidthChange = event => {
this.setState({ maxWidth: event.target.value });
};

handleFullWidthChange = event => {
this.setState({ fullWidth: event.target.checked });
};

render() {
const { classes } = this.props;

return (
<React.Fragment>
<Button onClick={this.handleClickOpen}>Open max-width dialog</Button>
<Dialog
fullWidth={this.state.fullWidth}
maxWidth={this.state.maxWidth}
open={this.state.open}
onClose={this.handleClose}
aria-labelledby="max-width-dialog-title"
>
<DialogTitle id="max-width-dialog-title">Optional sizes</DialogTitle>
<DialogContent>
<DialogContentText>
You can set my maximum width and whether to adapt or not.
</DialogContentText>
<form className={classes.form} noValidate>
<FormControl className={classes.formControl}>
<InputLabel htmlFor="max-width">maxWidth</InputLabel>
<Select
value={this.state.maxWidth}
onChange={this.handleMaxWidthChange}
inputProps={{
name: 'max-width',
id: 'max-width',
}}
>
<MenuItem value={false}>false</MenuItem>
<MenuItem value="xs">xs</MenuItem>
<MenuItem value="sm">sm</MenuItem>
<MenuItem value="md">md</MenuItem>
<MenuItem value="lg">lg</MenuItem>
<MenuItem value="xl">xl</MenuItem>
</Select>
</FormControl>
<FormControlLabel
className={classes.formControlLabel}
control={
<Switch
checked={this.state.fullWidth}
onChange={this.handleFullWidthChange}
value="fullWidth"
/>
}
label="Full width"
/>
</form>
</DialogContent>
<DialogActions>
<Button onClick={this.handleClose} color="primary">
Close
</Button>
</DialogActions>
</Dialog>
</React.Fragment>
);
}
}

FullScreenDialog.propTypes = {
classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(FullScreenDialog);
9 changes: 8 additions & 1 deletion docs/src/pages/demos/dialogs/dialogs.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,16 @@ For example, if your site prompts for potential subscribers to fill in their ema

{{"demo": "pages/demos/dialogs/FullScreenDialog.js"}}

## Optional sizes

You can set a dialog maximum width by using the `maxWidth` enumerable in combination with the `fullWidth` boolean.
When the `fullWidth` property is true, the dialog will adapt based on the `maxWidth` value.

{{"demo": "pages/demos/dialogs/MaxWidthDialog.js"}}

## Responsive full-screen

You may make a `Dialog` responsively full screen the dialog using `withMobileDialog`. By default, `withMobileDialog()(Dialog)` responsively full screens *at or below* the `sm` [screen size](/layout/basics/). You can choose your own breakpoint for example `xs` by passing the `breakpoint` argument: `withMobileDialog({breakpoint: 'xs'})(Dialog)`.
You may make a dialog responsively full screen the dialog using `withMobileDialog`. By default, `withMobileDialog()(Dialog)` responsively full screens *at or below* the `sm` [screen size](/layout/basics/). You can choose your own breakpoint for example `xs` by passing the `breakpoint` argument: `withMobileDialog({breakpoint: 'xs'})(Dialog)`.

{{"demo": "pages/demos/dialogs/ResponsiveDialog.js"}}

Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Dialog/Dialog.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface DialogProps
children?: React.ReactNode;
fullScreen?: boolean;
fullWidth?: boolean;
maxWidth?: 'xs' | 'sm' | 'md' | 'lg' | false;
maxWidth?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | false;
PaperProps?: Partial<PaperProps>;
scroll?: 'body' | 'paper';
TransitionComponent?: React.ReactType;
Expand Down
11 changes: 10 additions & 1 deletion packages/material-ui/src/Dialog/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ export const styles = theme => ({
},
},
},
/* Styles applied to the `Paper` component if `maxWidth="xl"`. */
paperWidthXl: {
maxWidth: theme.breakpoints.values.xl,
'&$paperScrollBody': {
[theme.breakpoints.down(theme.breakpoints.values.xl + 48 * 2)]: {
margin: 48,
},
},
},
/* Styles applied to the `Paper` component if `fullWidth={true}`. */
paperFullWidth: {
width: '100%',
Expand Down Expand Up @@ -241,7 +250,7 @@ Dialog.propTypes = {
* on the desktop where you might need some coherent different width size across your
* application. Set to `false` to disable `maxWidth`.
*/
maxWidth: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', false]),
maxWidth: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl', false]),
/**
* Callback fired when the backdrop is clicked.
*/
Expand Down
3 changes: 2 additions & 1 deletion pages/api/dialog.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Dialogs are overlaid modal paper based components with a backdrop.
| <span class="prop-name">disableEscapeKeyDown</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, hitting escape will not fire the `onClose` callback. |
| <span class="prop-name">fullScreen</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the dialog will be full-screen |
| <span class="prop-name">fullWidth</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the dialog stretches to `maxWidth`. |
| <span class="prop-name">maxWidth</span> | <span class="prop-type">enum:&nbsp;'xs', 'sm', 'md', 'lg', false<br></span> | <span class="prop-default">'sm'</span> | Determine the max width of the dialog. The dialog width grows with the size of the screen, this property is useful on the desktop where you might need some coherent different width size across your application. Set to `false` to disable `maxWidth`. |
| <span class="prop-name">maxWidth</span> | <span class="prop-type">enum:&nbsp;'xs', 'sm', 'md', 'lg', 'xl', false<br></span> | <span class="prop-default">'sm'</span> | Determine the max width of the dialog. The dialog width grows with the size of the screen, this property is useful on the desktop where you might need some coherent different width size across your application. Set to `false` to disable `maxWidth`. |
| <span class="prop-name">onBackdropClick</span> | <span class="prop-type">func</span> |   | Callback fired when the backdrop is clicked. |
| <span class="prop-name">onClose</span> | <span class="prop-type">func</span> |   | Callback fired when the component requests to be closed.<br><br>**Signature:**<br>`function(event: object) => void`<br>*event:* The event source of the callback |
| <span class="prop-name">onEnter</span> | <span class="prop-type">func</span> |   | Callback fired before the dialog enters. |
Expand Down Expand Up @@ -62,6 +62,7 @@ This property accepts the following keys:
| <span class="prop-name">paperWidthSm</span> | Styles applied to the `Paper` component if `maxWidth="sm"`.
| <span class="prop-name">paperWidthMd</span> | Styles applied to the `Paper` component if `maxWidth="md"`.
| <span class="prop-name">paperWidthLg</span> | Styles applied to the `Paper` component if `maxWidth="lg"`.
| <span class="prop-name">paperWidthXl</span> | Styles applied to the `Paper` component if `maxWidth="xl"`.
| <span class="prop-name">paperFullWidth</span> | Styles applied to the `Paper` component if `fullWidth={true}`.
| <span class="prop-name">paperFullScreen</span> | Styles applied to the `Paper` component if `fullScreen={true}`.

Expand Down
7 changes: 7 additions & 0 deletions pages/demos/dialogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ module.exports = require('fs')
raw: preval`
module.exports = require('fs')
.readFileSync(require.resolve('docs/src/pages/demos/dialogs/FullScreenDialog'), 'utf8')
`,
},
'pages/demos/dialogs/MaxWidthDialog.js': {
js: require('docs/src/pages/demos/dialogs/MaxWidthDialog').default,
raw: preval`
module.exports = require('fs')
.readFileSync(require.resolve('docs/src/pages/demos/dialogs/MaxWidthDialog'), 'utf8')
`,
},
'pages/demos/dialogs/FormDialog.js': {
Expand Down

0 comments on commit 072959c

Please sign in to comment.