Completely updated React, fixed #11, (hopefully)

This commit is contained in:
2018-03-04 19:11:49 -05:00
parent 6e0afd6e2a
commit 34e5f5139a
13674 changed files with 333464 additions and 473223 deletions

View File

@@ -1,24 +1,18 @@
import * as React from 'react';
import { StandardProps } from '..';
import { ModalProps, ModalClassKey } from '../internal/Modal';
import { TransitionDuration } from '../internal/transition';
import { PaperProps } from '../Paper';
import { ModalProps, ModalClassKey } from '../Modal';
import { TransitionHandlerProps, TransitionProps } from '../transitions/transition';
export interface DialogProps extends StandardProps<
ModalProps,
DialogClassKey,
'onBackdropClick' | 'onEscapeKeyUp'
> {
export interface DialogProps
extends StandardProps<ModalProps & Partial<TransitionHandlerProps>, DialogClassKey, 'children'> {
children?: React.ReactNode;
fullScreen?: boolean;
ignoreBackdropClick?: boolean;
ignoreEscapeKeyUp?: boolean;
transitionDuration?: TransitionDuration;
maxWidth?: 'xs' | 'sm' | 'md';
fullWidth?: boolean;
onBackdropClick?: Function;
onEscapeKeyUp?: Function;
onRequestClose?: React.EventHandler<any>;
open?: boolean;
maxWidth?: 'xs' | 'sm' | 'md' | false;
PaperProps?: Partial<PaperProps>;
transition?: React.ReactType;
transitionDuration?: TransitionProps['timeout'];
}
export type DialogClassKey =
@@ -29,8 +23,7 @@ export type DialogClassKey =
| 'paperWidthSm'
| 'paperWidthMd'
| 'fullWidth'
| 'fullScreen'
;
| 'fullScreen';
declare const Dialog: React.ComponentType<DialogProps>;

View File

@@ -1,18 +1,17 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
import _extends from 'babel-runtime/helpers/extends';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
// @inheritedComponent Modal
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import { capitalizeFirstLetter } from '../utils/helpers';
import Modal from '../internal/Modal';
import { capitalize } from '../utils/helpers';
import Modal from '../Modal';
import Fade from '../transitions/Fade';
import { duration } from '../styles/transitions';
import Paper from '../Paper';
export const styles = theme => ({
root: {
justifyContent: 'center',
@@ -31,7 +30,7 @@ export const styles = theme => ({
}
},
paperWidthXs: {
maxWidth: theme.breakpoints.values.xs
maxWidth: Math.max(theme.breakpoints.values.xs, 360)
},
paperWidthSm: {
maxWidth: theme.breakpoints.values.sm
@@ -61,36 +60,40 @@ function Dialog(props) {
classes,
className,
fullScreen,
ignoreBackdropClick,
ignoreEscapeKeyUp,
transitionDuration,
maxWidth,
fullWidth,
open,
disableBackdropClick,
disableEscapeKeyDown,
maxWidth,
onBackdropClick,
onEscapeKeyUp,
onClose,
onEnter,
onEntering,
onEntered,
onEntering,
onEscapeKeyDown,
onExit,
onExiting,
onExited,
onRequestClose,
transition: TransitionProp
onExiting,
open,
PaperProps,
transition: TransitionProp,
transitionDuration
} = props,
other = _objectWithoutProperties(props, ['children', 'classes', 'className', 'fullScreen', 'ignoreBackdropClick', 'ignoreEscapeKeyUp', 'transitionDuration', 'maxWidth', 'fullWidth', 'open', 'onBackdropClick', 'onEscapeKeyUp', 'onEnter', 'onEntering', 'onEntered', 'onExit', 'onExiting', 'onExited', 'onRequestClose', 'transition']);
other = _objectWithoutProperties(props, ['children', 'classes', 'className', 'fullScreen', 'fullWidth', 'disableBackdropClick', 'disableEscapeKeyDown', 'maxWidth', 'onBackdropClick', 'onClose', 'onEnter', 'onEntered', 'onEntering', 'onEscapeKeyDown', 'onExit', 'onExited', 'onExiting', 'open', 'PaperProps', 'transition', 'transitionDuration']);
return React.createElement(
Modal,
_extends({
className: classNames(classes.root, className),
BackdropTransitionDuration: transitionDuration,
ignoreBackdropClick: ignoreBackdropClick,
ignoreEscapeKeyUp: ignoreEscapeKeyUp,
BackdropProps: {
transitionDuration
},
disableBackdropClick: disableBackdropClick,
disableEscapeKeyDown: disableEscapeKeyDown,
onBackdropClick: onBackdropClick,
onEscapeKeyUp: onEscapeKeyUp,
onRequestClose: onRequestClose,
show: open
onEscapeKeyDown: onEscapeKeyDown,
onClose: onClose,
open: open,
role: 'dialog'
}, other),
React.createElement(
TransitionProp,
@@ -107,32 +110,122 @@ function Dialog(props) {
},
React.createElement(
Paper,
{
'data-mui-test': 'Dialog',
_extends({
elevation: 24,
className: classNames(classes.paper, classes[`paperWidth${capitalizeFirstLetter(maxWidth)}`], {
className: classNames(classes.paper, {
[classes[`paperWidth${maxWidth ? capitalize(maxWidth) : ''}`]]: maxWidth,
[classes.fullScreen]: fullScreen,
[classes.fullWidth]: fullWidth
})
},
}, PaperProps),
children
)
)
);
}
Dialog.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* Dialog children, usually the included sub-components.
*/
children: PropTypes.node.isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* If `true`, clicking the backdrop will not fire the `onClose` callback.
*/
disableBackdropClick: PropTypes.bool,
/**
* If `true`, hitting escape will not fire the `onClose` callback.
*/
disableEscapeKeyDown: PropTypes.bool,
/**
* If `true`, the dialog will be full-screen
*/
fullScreen: PropTypes.bool,
/**
* If `true`, the dialog stretches to `maxWidth`.
*/
fullWidth: PropTypes.bool,
/**
* 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`.
*/
maxWidth: PropTypes.oneOf(['xs', 'sm', 'md', false]),
/**
* Callback fired when the backdrop is clicked.
*/
onBackdropClick: PropTypes.func,
/**
* Callback fired when the component requests to be closed.
*
* @param {object} event The event source of the callback
*/
onClose: PropTypes.func,
/**
* Callback fired before the dialog enters.
*/
onEnter: PropTypes.func,
/**
* Callback fired when the dialog has entered.
*/
onEntered: PropTypes.func,
/**
* Callback fired when the dialog is entering.
*/
onEntering: PropTypes.func,
/**
* Callback fired when the escape key is pressed,
* `disableKeyboard` is false and the modal is in focus.
*/
onEscapeKeyDown: PropTypes.func,
/**
* Callback fired before the dialog exits.
*/
onExit: PropTypes.func,
/**
* Callback fired when the dialog has exited.
*/
onExited: PropTypes.func,
/**
* Callback fired when the dialog is exiting.
*/
onExiting: PropTypes.func,
/**
* If `true`, the Dialog is open.
*/
open: PropTypes.bool.isRequired,
/**
* Properties applied to the `Paper` element.
*/
PaperProps: PropTypes.object,
/**
* Transition component.
*/
transition: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
/**
* The duration for the transition, in milliseconds.
* You may specify a single timeout for all transitions, or individually with an object.
*/
transitionDuration: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({ enter: PropTypes.number, exit: PropTypes.number })])
} : {};
Dialog.defaultProps = {
fullScreen: false,
ignoreBackdropClick: false,
ignoreEscapeKeyUp: false,
transitionDuration: {
enter: duration.enteringScreen,
exit: duration.leavingScreen
},
maxWidth: 'sm',
fullWidth: false,
open: false,
transition: Fade
disableBackdropClick: false,
disableEscapeKeyDown: false,
maxWidth: 'sm',
transition: Fade,
transitionDuration: { enter: duration.enteringScreen, exit: duration.leavingScreen }
};
export default withStyles(styles, { name: 'MuiDialog' })(Dialog);

View File

@@ -1,16 +1,10 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface DialogActionsProps extends StandardProps<
React.HTMLAttributes<HTMLDivElement>,
DialogActionsClassKey
> {}
export interface DialogActionsProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, DialogActionsClassKey> {}
export type DialogActionsClassKey =
| 'root'
| 'action'
| 'button'
;
export type DialogActionsClassKey = 'root' | 'action' | 'button';
declare const DialogActions: React.ComponentType<DialogActionsProps>;

View File

@@ -1,9 +1,7 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
import _extends from 'babel-runtime/helpers/extends';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import '../Button'; // So we don't have any override priority issue.
@@ -30,15 +28,36 @@ function DialogActions(props) {
return React.createElement(
'div',
_extends({ 'data-mui-test': 'DialogActions', className: classNames(classes.root, className) }, other),
React.Children.map(children, button => React.isValidElement(button) && React.createElement(
'div',
{ className: classes.action },
React.cloneElement(button, {
className: classNames(classes.button, button.props.className)
})
))
_extends({ className: classNames(classes.root, className) }, other),
React.Children.map(children, child => {
if (!React.isValidElement(child)) {
return null;
}
return React.createElement(
'div',
{ className: classes.action },
React.cloneElement(child, {
className: classNames(classes.button, child.props.className)
})
);
})
);
}
DialogActions.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the component.
*/
children: PropTypes.node,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string
} : {};
export default withStyles(styles, { name: 'MuiDialogActions' })(DialogActions);

View File

@@ -1,14 +1,10 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface DialogContentProps extends StandardProps<
React.HTMLAttributes<HTMLDivElement>,
DialogContentClassKey
> {}
export interface DialogContentProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, DialogContentClassKey> {}
export type DialogContentClassKey =
| 'root'
;
export type DialogContentClassKey = 'root';
declare const DialogContent: React.ComponentType<DialogContentProps>;

View File

@@ -1,9 +1,7 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
import _extends from 'babel-runtime/helpers/extends';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
@@ -32,4 +30,19 @@ function DialogContent(props) {
);
}
DialogContent.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the component.
*/
children: PropTypes.node,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string
} : {};
export default withStyles(styles, { name: 'MuiDialogContent' })(DialogContent);

View File

@@ -1,14 +1,10 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface DialogContentTextProps extends StandardProps<
React.HTMLAttributes<HTMLParagraphElement>,
DialogContentTextClassKey
> {}
export interface DialogContentTextProps
extends StandardProps<React.HTMLAttributes<HTMLParagraphElement>, DialogContentTextClassKey> {}
export type DialogContentTextClassKey =
| 'root'
;
export type DialogContentTextClassKey = 'root';
declare const DialogContentText: React.ComponentType<DialogContentTextProps>;

View File

@@ -1,9 +1,7 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
import _extends from 'babel-runtime/helpers/extends';
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
@@ -25,4 +23,19 @@ function DialogContentText(props) {
);
}
DialogContentText.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the component.
*/
children: PropTypes.node,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string
} : {};
export default withStyles(styles, { name: 'MuiDialogContentText' })(DialogContentText);

View File

@@ -1,16 +1,12 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface DialogTitleProps extends StandardProps<
React.HTMLAttributes<HTMLDivElement>,
DialogTitleClassKey
> {
export interface DialogTitleProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, DialogTitleClassKey> {
disableTypography?: boolean;
}
export type DialogTitleClassKey =
| 'root'
;
export type DialogTitleClassKey = 'root';
declare const DialogTitle: React.ComponentType<DialogTitleProps>;

View File

@@ -1,9 +1,7 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
import _extends from 'babel-runtime/helpers/extends';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import Typography from '../Typography';
@@ -23,15 +21,35 @@ function DialogTitle(props) {
return React.createElement(
'div',
_extends({ 'data-mui-test': 'DialogTitle', className: classNames(classes.root, className) }, other),
_extends({ className: classNames(classes.root, className) }, other),
disableTypography ? children : React.createElement(
Typography,
{ type: 'title' },
{ variant: 'title' },
children
)
);
}
DialogTitle.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the component.
*/
children: PropTypes.node.isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* If `true`, the children won't be wrapped by a typography component.
* For instance, this can be useful to render an h4 instead of the default h2.
*/
disableTypography: PropTypes.bool
} : {};
DialogTitle.defaultProps = {
disableTypography: false
};

View File

@@ -8,7 +8,5 @@ export { default as DialogContent } from './DialogContent';
export * from './DialogContent';
export { default as DialogContentText } from './DialogContentText';
export * from './DialogContentText';
export {
default as withMobileDialog,
} from './withMobileDialog';
export { default as withMobileDialog } from './withMobileDialog';
export * from './withMobileDialog';

View File

@@ -5,8 +5,12 @@ export interface WithMobileDialogOptions {
breakpoint: Breakpoint;
}
export interface InjectedProps {
fullScreen?: boolean;
}
export default function withMobileDialog<P = {}>(
options: WithMobileDialogOptions
options?: WithMobileDialogOptions,
): (
component: React.ComponentType<P & Partial<WithWidthProps>>
) => React.ComponentClass<P & Partial<WithWidthProps>>;
component: React.ComponentType<P & InjectedProps & Partial<WithWidthProps>>,
) => React.ComponentType<P & Partial<WithWidthProps>>;

View File

@@ -1,26 +1,23 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
import _extends from 'babel-runtime/helpers/extends';
import React from 'react';
import wrapDisplayName from 'recompose/wrapDisplayName';
import PropTypes from 'prop-types';
import withWidth, { isWidthDown } from '../utils/withWidth';
/**
* Dialog will responsively be full screen *at or below* the given breakpoint
* (defaults to 'sm' for mobile devices).
* Notice that this Higher-order Component is incompatible with server side rendering.
*/
const withMobileDialog = (options = { breakpoint: 'sm' }) => Component => {
const { breakpoint } = options;
const withMobileDialog = (options = {}) => Component => {
const { breakpoint = 'sm' } = options;
function WithMobileDialog(props) {
return React.createElement(Component, _extends({ fullScreen: isWidthDown(breakpoint, props.width) }, props));
}
if (process.env.NODE_ENV !== 'production') {
WithMobileDialog.displayName = wrapDisplayName(Component, 'withMobileDialog');
}
WithMobileDialog.propTypes = process.env.NODE_ENV !== "production" ? {
width: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']).isRequired
} : {};
return withWidth()(WithMobileDialog);
};