Skip to content

Commit

Permalink
some refactorization
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Dec 12, 2018
1 parent bc2b63e commit 7cc9403
Show file tree
Hide file tree
Showing 46 changed files with 120 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = [
name: 'The size of the @material-ui/core modules',
webpack: true,
path: 'packages/material-ui/build/index.js',
limit: '95.2 KB',
limit: '95.3 KB',
},
{
name: 'The size of the @material-ui/styles modules',
Expand Down
4 changes: 2 additions & 2 deletions docs/src/modules/components/AppContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ const styles = theme => ({
[theme.breakpoints.up('sm')]: {
paddingLeft: theme.spacing.unit * 4,
paddingRight: theme.spacing.unit * 4,
maxWidth: 'calc(100% - 162px)',
maxWidth: 'calc(100% - 167px)',
},
[theme.breakpoints.up('lg')]: {
paddingLeft: theme.spacing.unit * 5,
paddingRight: theme.spacing.unit * 9,
maxWidth: 'calc(100% - 240px - 162px)',
maxWidth: 'calc(100% - 240px - 167px)',
},
},
});
Expand Down
4 changes: 2 additions & 2 deletions docs/src/modules/components/AppTableOfContents.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ const styles = theme => ({
top: 70,
// Fix IE 11 position sticky issue.
marginTop: 70,
width: 162,
width: 167,
flexShrink: 0,
order: 2,
position: 'sticky',
wordBreak: 'break-word',
height: 'calc(100vh - 70px)',
overflowY: 'auto',
padding: `${theme.spacing.unit * 2}px ${theme.spacing.unit * 2}px ${theme.spacing.unit *
2}px 0`,
2}px 5px`,
display: 'none',
[theme.breakpoints.up('sm')]: {
display: 'block',
Expand Down
68 changes: 34 additions & 34 deletions docs/src/pages/demos/dialogs/DraggableDialog.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import React from 'react';
import Button from '@material-ui/core/Button';
import TextField from '@material-ui/core/TextField';
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 Paper from '@material-ui/core/Paper';
import Draggable from 'react-draggable';

export default class DraggableDialog extends React.Component {
function PaperComponent(props) {
return (
<Draggable>
<Paper {...props} />
</Draggable>
);
}

class DraggableDialog extends React.Component {
state = {
open: false,
};
Expand All @@ -27,39 +35,31 @@ export default class DraggableDialog extends React.Component {
<Button variant="outlined" color="primary" onClick={this.handleClickOpen}>
Open form dialog
</Button>
{this.state.open && (
<Dialog
open={this.state.open}
onClose={this.handleClose}
TransitionComponent={Draggable}
aria-labelledby="form-dialog-title"
>
<DialogTitle id="form-dialog-title">Subscribe</DialogTitle>
<DialogContent>
<DialogContentText>
To subscribe to this website, please enter your email address here. We will send
updates occasionally.
</DialogContentText>
<TextField
autoFocus
margin="dense"
id="name"
label="Email Address"
type="email"
fullWidth
/>
</DialogContent>
<DialogActions>
<Button onClick={this.handleClose} color="primary">
Cancel
</Button>
<Button onClick={this.handleClose} color="primary">
Subscribe
</Button>
</DialogActions>
</Dialog>
)}
<Dialog
open={this.state.open}
onClose={this.handleClose}
PaperComponent={PaperComponent}
aria-labelledby="draggable-dialog-title"
>
<DialogTitle id="draggable-dialog-title">Subscribe</DialogTitle>
<DialogContent>
<DialogContentText>
To subscribe to this website, please enter your email address here. We will send
updates occasionally.
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={this.handleClose} color="primary">
Cancel
</Button>
<Button onClick={this.handleClose} color="primary">
Subscribe
</Button>
</DialogActions>
</Dialog>
</div>
);
}
}

export default DraggableDialog;
14 changes: 8 additions & 6 deletions docs/src/pages/demos/dialogs/dialogs.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ here is one example of how you can customize the `DialogTitle` to support a clos

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

## Draggable dialog

You can create a draggable dialog by using [react-draggable](https://github.com/mzabriskie/react-draggable) together with material-ui. To do so, you can pass the the imported `Draggable` component as the `TransitionComponent` of the `Dialog` component. This will make the entire dialog draggable.

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

## Full-screen dialogs

{{"demo": "pages/demos/dialogs/FullScreenDialog.js"}}
Expand Down Expand Up @@ -110,3 +104,11 @@ When dialogs become too long for the user’s viewport or device, they scroll.
Try the demo below to see what we mean:

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

## Draggable dialog

You can create a draggable dialog by using [react-draggable](https://github.com/mzabriskie/react-draggable).
To do so, you can pass the the imported `Draggable` component as the `PaperComponent` of the `Dialog` component.
This will make the entire dialog draggable.

{{"demo": "pages/demos/dialogs/DraggableDialog.js"}}
1 change: 1 addition & 0 deletions packages/material-ui-lab/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
},
"dependencies": {
"@babel/runtime": "7.1.2",
"@material-ui/utils": "^3.0.0-alpha.0",
"classnames": "^2.2.5",
"keycode": "^2.1.9"
},
Expand Down
5 changes: 3 additions & 2 deletions packages/material-ui-lab/src/SpeedDial/SpeedDial.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import classNames from 'classnames';
import keycode from 'keycode';
import warning from 'warning';
import { componentPropType } from '@material-ui/utils';
import { withStyles } from '@material-ui/core/styles';
import Zoom from '@material-ui/core/Zoom';
import { duration } from '@material-ui/core/styles/transitions';
Expand Down Expand Up @@ -340,9 +341,9 @@ SpeedDial.propTypes = {
*/
openIcon: PropTypes.node,
/**
* Transition component.
* The component used for the transition.
*/
TransitionComponent: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object]),
TransitionComponent: componentPropType,
/**
* The duration for the transition, in milliseconds.
* You may specify a single timeout for all transitions, or individually with an object.
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui-utils/src/componentPropType.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as ReactIs from 'react-is';
const ReactIs = require('react-is');

/**
* A factory that returns a propTypes validator that only accepts values that
Expand Down
15 changes: 11 additions & 4 deletions packages/material-ui/src/Dialog/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { componentPropType } from '@material-ui/utils';
import withStyles from '../styles/withStyles';
import { capitalize } from '../utils/helpers';
import Modal from '../Modal';
Expand Down Expand Up @@ -152,6 +153,7 @@ class Dialog extends React.Component {
onExited,
onExiting,
open,
PaperComponent,
PaperProps,
scroll,
TransitionComponent,
Expand Down Expand Up @@ -193,7 +195,7 @@ class Dialog extends React.Component {
onClick={this.handleBackdropClick}
role="document"
>
<Paper
<PaperComponent
elevation={24}
className={classNames(classes.paper, classes[`paperScroll${capitalize(scroll)}`], {
[classes[`paperWidth${maxWidth ? capitalize(maxWidth) : ''}`]]: maxWidth,
Expand All @@ -203,7 +205,7 @@ class Dialog extends React.Component {
{...PaperProps}
>
{children}
</Paper>
</PaperComponent>
</div>
</TransitionComponent>
</Modal>
Expand Down Expand Up @@ -296,6 +298,10 @@ Dialog.propTypes = {
* If `true`, the Dialog is open.
*/
open: PropTypes.bool.isRequired,
/**
* The component used to render the body of the dialog.
*/
PaperComponent: componentPropType,
/**
* Properties applied to the [`Paper`](/api/paper/) element.
* If you want to add a class to the `Paper` component use
Expand All @@ -318,9 +324,9 @@ Dialog.propTypes = {
*/
scroll: PropTypes.oneOf(['body', 'paper']),
/**
* Transition component.
* The component used for the transition.
*/
TransitionComponent: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object]),
TransitionComponent: componentPropType,
/**
* The duration for the transition, in milliseconds.
* You may specify a single timeout for all transitions, or individually with an object.
Expand All @@ -341,6 +347,7 @@ Dialog.defaultProps = {
fullScreen: false,
fullWidth: false,
maxWidth: 'sm',
PaperComponent: Paper,
scroll: 'paper',
TransitionComponent: Fade,
transitionDuration: { enter: duration.enteringScreen, exit: duration.leavingScreen },
Expand Down
3 changes: 2 additions & 1 deletion packages/material-ui/src/FilledInput/FilledInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { componentPropType } from '@material-ui/utils';
import InputBase from '../InputBase';
import withStyles from '../styles/withStyles';

Expand Down Expand Up @@ -202,7 +203,7 @@ FilledInput.propTypes = {
* The component used for the native input.
* Either a string to use a DOM element or a component.
*/
inputComponent: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object]),
inputComponent: componentPropType,
/**
* Attributes applied to the `input` element.
*/
Expand Down
3 changes: 2 additions & 1 deletion packages/material-ui/src/Input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { componentPropType } from '@material-ui/utils';
import InputBase from '../InputBase';
import withStyles from '../styles/withStyles';

Expand Down Expand Up @@ -171,7 +172,7 @@ Input.propTypes = {
* The component used for the native input.
* Either a string to use a DOM element or a component.
*/
inputComponent: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object]),
inputComponent: componentPropType,
/**
* Attributes applied to the `input` element.
*/
Expand Down
3 changes: 2 additions & 1 deletion packages/material-ui/src/InputBase/InputBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { componentPropType } from '@material-ui/utils';
import formControlState from '../FormControl/formControlState';
import FormControlContext from '../FormControl/FormControlContext';
import withFormControlContext from '../FormControl/withFormControlContext';
Expand Down Expand Up @@ -477,7 +478,7 @@ InputBase.propTypes = {
* The component used for the native input.
* Either a string to use a DOM element or a component.
*/
inputComponent: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object]),
inputComponent: componentPropType,
/**
* Attributes applied to the `input` element.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/ListItem/ListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ ListItem.propTypes = {
/**
* The container component used when a `ListItemSecondaryAction` is rendered.
*/
ContainerComponent: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object]),
ContainerComponent: componentPropType,
/**
* Properties applied to the container element when the component
* is used to display a `ListItemSecondaryAction`.
Expand Down
3 changes: 2 additions & 1 deletion packages/material-ui/src/Modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
import classNames from 'classnames';
import warning from 'warning';
import keycode from 'keycode';
import { componentPropType } from '@material-ui/utils';
import ownerDocument from '../utils/ownerDocument';
import RootRef from '../RootRef';
import Portal from '../Portal';
Expand Down Expand Up @@ -318,7 +319,7 @@ Modal.propTypes = {
/**
* A backdrop component. This property enables custom backdrop rendering.
*/
BackdropComponent: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object]),
BackdropComponent: componentPropType,
/**
* Properties applied to the [`Backdrop`](/api/backdrop/) element.
*/
Expand Down
3 changes: 2 additions & 1 deletion packages/material-ui/src/NativeSelect/NativeSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import React from 'react';
import PropTypes from 'prop-types';
import { componentPropType } from '@material-ui/utils';
import NativeSelectInput from './NativeSelectInput';
import withStyles from '../styles/withStyles';
import formControlState from '../FormControl/formControlState';
Expand Down Expand Up @@ -128,7 +129,7 @@ NativeSelect.propTypes = {
/**
* The icon that displays the arrow.
*/
IconComponent: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object]),
IconComponent: componentPropType,
/**
* An `Input` element; does not have to be a material-ui specific `Input`.
*/
Expand Down
3 changes: 2 additions & 1 deletion packages/material-ui/src/NativeSelect/NativeSelectInput.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { componentPropType } from '@material-ui/utils';

/**
* @ignore - internal component.
Expand Down Expand Up @@ -68,7 +69,7 @@ NativeSelectInput.propTypes = {
/**
* The icon that displays the arrow.
*/
IconComponent: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object]),
IconComponent: componentPropType,
/**
* Use that property to pass a ref callback to the native select element.
*/
Expand Down
3 changes: 2 additions & 1 deletion packages/material-ui/src/OutlinedInput/OutlinedInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { componentPropType } from '@material-ui/utils';
import InputBase from '../InputBase';
import NotchedOutline from './NotchedOutline';
import withStyles from '../styles/withStyles';
Expand Down Expand Up @@ -165,7 +166,7 @@ OutlinedInput.propTypes = {
* The component used for the native input.
* Either a string to use a DOM element or a component.
*/
inputComponent: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.object]),
inputComponent: componentPropType,
/**
* Attributes applied to the `input` element.
*/
Expand Down
Loading

0 comments on commit 7cc9403

Please sign in to comment.