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,23 +1,20 @@
import { PropTypes, StandardProps } from '..';
import { PaperProps, PaperClassKey } from '../Paper/Paper';
import { PaperProps, PaperClassKey } from '../Paper';
export interface AppBarProps extends StandardProps<
PaperProps,
AppBarClassKey
> {
export interface AppBarProps extends StandardProps<PaperProps, AppBarClassKey> {
color?: PropTypes.Color;
position?: 'static' | 'fixed' | 'absolute';
position?: 'fixed' | 'absolute' | 'sticky' | 'static';
}
export type AppBarClassKey =
| PaperClassKey
| 'positionFixed'
| 'positionAbsolute'
| 'positionSticky'
| 'positionStatic'
| 'colorDefault'
| 'colorPrimary'
| 'colorAccent'
;
| 'colorSecondary';
declare const AppBar: React.ComponentType<AppBarProps>;

View File

@@ -17,13 +17,14 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref;
// @inheritedComponent Paper
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
@@ -40,9 +41,11 @@ var _Paper2 = _interopRequireDefault(_Paper);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
// @inheritedComponent Paper
var styles = exports.styles = function styles(theme) {
var backgroundColorDefault = theme.palette.type === 'light' ? theme.palette.grey[100] : theme.palette.grey[900];
return {
root: {
display: 'flex',
@@ -64,57 +67,30 @@ var styles = exports.styles = function styles(theme) {
left: 'auto',
right: 0
},
positionSticky: {
position: 'sticky',
top: 0,
left: 'auto',
right: 0
},
positionStatic: {
position: 'static',
flexShrink: 0
position: 'static'
},
colorDefault: {
backgroundColor: theme.palette.background.appBar,
color: theme.palette.getContrastText(theme.palette.background.appBar)
backgroundColor: backgroundColorDefault,
color: theme.palette.getContrastText(backgroundColorDefault)
},
colorPrimary: {
backgroundColor: theme.palette.primary[500],
color: theme.palette.getContrastText(theme.palette.primary[500])
backgroundColor: theme.palette.primary.main,
color: theme.palette.primary.contrastText
},
colorAccent: {
backgroundColor: theme.palette.secondary.A200,
color: theme.palette.getContrastText(theme.palette.secondary.A200)
colorSecondary: {
backgroundColor: theme.palette.secondary.main,
color: theme.palette.secondary.contrastText
}
};
};
var babelPluginFlowReactPropTypes_proptype_Color = require('prop-types').oneOf(['inherit', 'primary', 'accent', 'default']);
var babelPluginFlowReactPropTypes_proptype_Position = require('prop-types').oneOf(['static', 'fixed', 'absolute']);
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The content of the component.
*/
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* The color of the component. It's using the theme palette when that makes sense.
*/
color: require('prop-types').oneOf(['inherit', 'primary', 'accent', 'default']),
/**
* The positioning type.
*/
position: require('prop-types').oneOf(['static', 'fixed', 'absolute'])
};
function AppBar(props) {
var _classNames;
@@ -126,7 +102,7 @@ function AppBar(props) {
other = (0, _objectWithoutProperties3.default)(props, ['children', 'classes', 'className', 'color', 'position']);
var className = (0, _classnames2.default)(classes.root, classes['position' + (0, _helpers.capitalizeFirstLetter)(position)], (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes['color' + (0, _helpers.capitalizeFirstLetter)(color)], color !== 'inherit'), (0, _defineProperty3.default)(_classNames, 'mui-fixed', position === 'fixed'), _classNames), classNameProp);
var className = (0, _classnames2.default)(classes.root, classes['position' + (0, _helpers.capitalize)(position)], (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes['color' + (0, _helpers.capitalize)(color)], color !== 'inherit'), (0, _defineProperty3.default)(_classNames, 'mui-fixed', position === 'fixed'), _classNames), classNameProp);
return _react2.default.createElement(
_Paper2.default,
@@ -135,12 +111,31 @@ function AppBar(props) {
);
}
AppBar.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
color: require('prop-types').oneOf(['inherit', 'primary', 'accent', 'default']).isRequired,
position: require('prop-types').oneOf(['static', 'fixed', 'absolute']).isRequired,
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'color', require('prop-types').oneOf(['inherit', 'primary', 'accent', 'default'])), (0, _defineProperty3.default)(_ref, 'position', require('prop-types').oneOf(['static', 'fixed', 'absolute'])), _ref) : {};
AppBar.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the component.
*/
children: _propTypes2.default.node.isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* The color of the component. It supports those theme colors that make sense for this component.
*/
color: _propTypes2.default.oneOf(['inherit', 'primary', 'secondary', 'default']),
/**
* The positioning type. The behavior of the different options is described
* [here](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Positioning).
* Note: `sticky` is not universally supported and will fall back to `static` when unavailable.
*/
position: _propTypes2.default.oneOf(['fixed', 'absolute', 'sticky', 'static'])
} : {};
AppBar.defaultProps = {
color: 'primary',
position: 'fixed'

View File

@@ -1,92 +1,69 @@
// @flow
// @inheritedComponent Paper
import React from 'react';
import type { Node } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import { capitalizeFirstLetter } from '../utils/helpers';
import { capitalize } from '../utils/helpers';
import Paper from '../Paper';
export const styles = (theme: Object) => ({
root: {
display: 'flex',
flexDirection: 'column',
width: '100%',
boxSizing: 'border-box', // Prevent padding issue with the Modal and fixed positioned AppBar.
zIndex: theme.zIndex.appBar,
flexShrink: 0,
},
positionFixed: {
position: 'fixed',
top: 0,
left: 'auto',
right: 0,
},
positionAbsolute: {
position: 'absolute',
top: 0,
left: 'auto',
right: 0,
},
positionStatic: {
position: 'static',
flexShrink: 0,
},
colorDefault: {
backgroundColor: theme.palette.background.appBar,
color: theme.palette.getContrastText(theme.palette.background.appBar),
},
colorPrimary: {
backgroundColor: theme.palette.primary[500],
color: theme.palette.getContrastText(theme.palette.primary[500]),
},
colorAccent: {
backgroundColor: theme.palette.secondary.A200,
color: theme.palette.getContrastText(theme.palette.secondary.A200),
},
});
export const styles = theme => {
const backgroundColorDefault =
theme.palette.type === 'light' ? theme.palette.grey[100] : theme.palette.grey[900];
export type Color = 'inherit' | 'primary' | 'accent' | 'default';
export type Position = 'static' | 'fixed' | 'absolute';
type ProvidedProps = {
classes: Object,
color: Color,
position: Position,
return {
root: {
display: 'flex',
flexDirection: 'column',
width: '100%',
boxSizing: 'border-box', // Prevent padding issue with the Modal and fixed positioned AppBar.
zIndex: theme.zIndex.appBar,
flexShrink: 0,
},
positionFixed: {
position: 'fixed',
top: 0,
left: 'auto',
right: 0,
},
positionAbsolute: {
position: 'absolute',
top: 0,
left: 'auto',
right: 0,
},
positionSticky: {
position: 'sticky',
top: 0,
left: 'auto',
right: 0,
},
positionStatic: {
position: 'static',
},
colorDefault: {
backgroundColor: backgroundColorDefault,
color: theme.palette.getContrastText(backgroundColorDefault),
},
colorPrimary: {
backgroundColor: theme.palette.primary.main,
color: theme.palette.primary.contrastText,
},
colorSecondary: {
backgroundColor: theme.palette.secondary.main,
color: theme.palette.secondary.contrastText,
},
};
};
export type Props = {
/**
* The content of the component.
*/
children?: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* The color of the component. It's using the theme palette when that makes sense.
*/
color?: Color,
/**
* The positioning type.
*/
position?: Position,
};
function AppBar(props: ProvidedProps & Props) {
function AppBar(props) {
const { children, classes, className: classNameProp, color, position, ...other } = props;
const className = classNames(
classes.root,
classes[`position${capitalizeFirstLetter(position)}`],
classes[`position${capitalize(position)}`],
{
[classes[`color${capitalizeFirstLetter(color)}`]]: color !== 'inherit',
[classes[`color${capitalize(color)}`]]: color !== 'inherit',
'mui-fixed': position === 'fixed', // Useful for the Dialog
},
classNameProp,
@@ -99,6 +76,31 @@ function AppBar(props: ProvidedProps & Props) {
);
}
AppBar.propTypes = {
/**
* 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,
/**
* The color of the component. It supports those theme colors that make sense for this component.
*/
color: PropTypes.oneOf(['inherit', 'primary', 'secondary', 'default']),
/**
* The positioning type. The behavior of the different options is described
* [here](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Positioning).
* Note: `sticky` is not universally supported and will fall back to `static` when unavailable.
*/
position: PropTypes.oneOf(['fixed', 'absolute', 'sticky', 'static']),
};
AppBar.defaultProps = {
color: 'primary',
position: 'fixed',

View File

@@ -1,3 +1 @@
// @flow
export { default } from './AppBar';

View File

@@ -1,24 +1,18 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface AvatarProps extends StandardProps<
React.HTMLAttributes<HTMLDivElement>,
AvatarClassKey
> {
export interface AvatarProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, AvatarClassKey> {
alt?: string;
childrenClassName?: string;
component?: React.ReactType;
imgProps?: Object;
component?: React.ReactType<AvatarProps>;
imgProps?: React.HtmlHTMLAttributes<HTMLImageElement>;
sizes?: string;
src?: string;
srcSet?: string;
}
export type AvatarClassKey =
| 'root'
| 'colorDefault'
| 'img'
;
export type AvatarClassKey = 'root' | 'colorDefault' | 'img';
declare const Avatar: React.ComponentType<AvatarProps>;

View File

@@ -17,12 +17,14 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
@@ -31,14 +33,8 @@ var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
var _colorManipulator = require('../styles/colorManipulator');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Element = require('react').babelPluginFlowReactPropTypes_proptype_Element || require('prop-types').any;
var babelPluginFlowReactPropTypes_proptype_ElementType = require('react').babelPluginFlowReactPropTypes_proptype_ElementType || require('prop-types').any;
var styles = exports.styles = function styles(theme) {
return {
root: {
@@ -47,8 +43,8 @@ var styles = exports.styles = function styles(theme) {
alignItems: 'center',
justifyContent: 'center',
flexShrink: 0,
width: 40,
height: 40,
width: theme.spacing.unit * 5,
height: theme.spacing.unit * 5,
fontFamily: theme.typography.fontFamily,
fontSize: theme.typography.pxToRem(20),
borderRadius: '50%',
@@ -57,90 +53,30 @@ var styles = exports.styles = function styles(theme) {
},
colorDefault: {
color: theme.palette.background.default,
backgroundColor: (0, _colorManipulator.emphasize)(theme.palette.background.default, 0.26)
backgroundColor: theme.palette.type === 'light' ? theme.palette.grey[400] : theme.palette.grey[600]
},
img: {
maxWidth: '100%',
width: '100%',
height: 'auto'
height: '100%',
textAlign: 'center',
// Handle non-square image. The property isn't supported by IE11.
objectFit: 'cover'
}
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* Used in combination with `src` or `srcSet` to
* provide an alt attribute for the rendered `img` element.
*/
alt: require('prop-types').string,
/**
* Used to render icon or text elements inside the Avatar.
* `src` and `alt` props will not be used and no `img` will
* be rendered by default.
*
* This can be an element, or just a string.
*/
children: require('prop-types').oneOfType([require('prop-types').string, typeof babelPluginFlowReactPropTypes_proptype_Element === 'function' ? babelPluginFlowReactPropTypes_proptype_Element : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Element)]),
/**
* @ignore
* The className of the child element.
* Used by Chip and ListItemIcon to style the Avatar icon.
*/
childrenClassName: require('prop-types').string,
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType),
/**
* Properties applied to the `img` element when the component
* is used to display an image.
*/
imgProps: require('prop-types').object,
/**
* The `sizes` attribute for the `img` element.
*/
sizes: require('prop-types').string,
/**
* The `src` attribute for the `img` element.
*/
src: require('prop-types').string,
/**
* The `srcSet` attribute for the `img` element.
*/
srcSet: require('prop-types').string
};
function Avatar(props) {
var alt = props.alt,
classes = props.classes,
classNameProp = props.className,
childrenProp = props.children,
childrenClassNameProp = props.childrenClassName,
ComponentProp = props.component,
classes = props.classes,
classNameProp = props.className,
Component = props.component,
imgProps = props.imgProps,
sizes = props.sizes,
src = props.src,
srcSet = props.srcSet,
other = (0, _objectWithoutProperties3.default)(props, ['alt', 'classes', 'className', 'children', 'childrenClassName', 'component', 'imgProps', 'sizes', 'src', 'srcSet']);
other = (0, _objectWithoutProperties3.default)(props, ['alt', 'children', 'childrenClassName', 'classes', 'className', 'component', 'imgProps', 'sizes', 'src', 'srcSet']);
var className = (0, _classnames2.default)(classes.root, (0, _defineProperty3.default)({}, classes.colorDefault, childrenProp && !src && !srcSet), classNameProp);
@@ -148,8 +84,8 @@ function Avatar(props) {
if (childrenProp) {
if (childrenClassNameProp && typeof childrenProp !== 'string' && _react2.default.isValidElement(childrenProp)) {
var _childrenClassName = (0, _classnames2.default)(childrenClassNameProp, childrenProp.props.className);
children = _react2.default.cloneElement(childrenProp, { className: _childrenClassName });
var childrenClassName = (0, _classnames2.default)(childrenClassNameProp, childrenProp.props.className);
children = _react2.default.cloneElement(childrenProp, { className: childrenClassName });
} else {
children = childrenProp;
}
@@ -164,19 +100,64 @@ function Avatar(props) {
}
return _react2.default.createElement(
ComponentProp,
Component,
(0, _extends3.default)({ className: className }, other),
children
);
}
Avatar.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
component: typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType.isRequired ? babelPluginFlowReactPropTypes_proptype_ElementType.isRequired : babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType).isRequired,
alt: require('prop-types').string,
children: require('prop-types').oneOfType([require('prop-types').string, typeof babelPluginFlowReactPropTypes_proptype_Element === 'function' ? babelPluginFlowReactPropTypes_proptype_Element : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Element)]),
childrenClassName: require('prop-types').string
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'component', typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType)), (0, _defineProperty3.default)(_ref, 'imgProps', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'sizes', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'src', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'srcSet', require('prop-types').string), _ref) : {};
Avatar.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* Used in combination with `src` or `srcSet` to
* provide an alt attribute for the rendered `img` element.
*/
alt: _propTypes2.default.string,
/**
* Used to render icon or text elements inside the Avatar.
* `src` and `alt` props will not be used and no `img` will
* be rendered by default.
*
* This can be an element, or just a string.
*/
children: _propTypes2.default.node,
/**
* @ignore
* The className of the child element.
* Used by Chip and ListItemIcon to style the Avatar icon.
*/
childrenClassName: _propTypes2.default.string,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func]),
/**
* Properties applied to the `img` element when the component
* is used to display an image.
*/
imgProps: _propTypes2.default.object,
/**
* The `sizes` attribute for the `img` element.
*/
sizes: _propTypes2.default.string,
/**
* The `src` attribute for the `img` element.
*/
src: _propTypes2.default.string,
/**
* The `srcSet` attribute for the `img` element.
*/
srcSet: _propTypes2.default.string
} : {};
Avatar.defaultProps = {
component: 'div'
};

View File

@@ -1,20 +1,17 @@
// @flow
import React from 'react';
import type { ElementType, Element } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import { emphasize } from '../styles/colorManipulator';
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
position: 'relative',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
flexShrink: 0,
width: 40,
height: 40,
width: theme.spacing.unit * 5,
height: theme.spacing.unit * 5,
fontFamily: theme.typography.fontFamily,
fontSize: theme.typography.pxToRem(20),
borderRadius: '50%',
@@ -23,80 +20,26 @@ export const styles = (theme: Object) => ({
},
colorDefault: {
color: theme.palette.background.default,
backgroundColor: emphasize(theme.palette.background.default, 0.26),
backgroundColor:
theme.palette.type === 'light' ? theme.palette.grey[400] : theme.palette.grey[600],
},
img: {
maxWidth: '100%',
width: '100%',
height: 'auto',
height: '100%',
textAlign: 'center',
// Handle non-square image. The property isn't supported by IE11.
objectFit: 'cover',
},
});
type ProvidedProps = {
classes: Object,
component: ElementType,
};
export type Props = {
/**
* Used in combination with `src` or `srcSet` to
* provide an alt attribute for the rendered `img` element.
*/
alt?: string,
/**
* Used to render icon or text elements inside the Avatar.
* `src` and `alt` props will not be used and no `img` will
* be rendered by default.
*
* This can be an element, or just a string.
*/
children?: string | Element<any>,
/**
* @ignore
* The className of the child element.
* Used by Chip and ListItemIcon to style the Avatar icon.
*/
childrenClassName?: string,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component?: ElementType,
/**
* Properties applied to the `img` element when the component
* is used to display an image.
*/
imgProps?: Object,
/**
* The `sizes` attribute for the `img` element.
*/
sizes?: string,
/**
* The `src` attribute for the `img` element.
*/
src?: string,
/**
* The `srcSet` attribute for the `img` element.
*/
srcSet?: string,
};
function Avatar(props: ProvidedProps & Props) {
function Avatar(props) {
const {
alt,
classes,
className: classNameProp,
children: childrenProp,
childrenClassName: childrenClassNameProp,
component: ComponentProp,
classes,
className: classNameProp,
component: Component,
imgProps,
sizes,
src,
@@ -138,12 +81,64 @@ function Avatar(props: ProvidedProps & Props) {
}
return (
<ComponentProp className={className} {...other}>
<Component className={className} {...other}>
{children}
</ComponentProp>
</Component>
);
}
Avatar.propTypes = {
/**
* Used in combination with `src` or `srcSet` to
* provide an alt attribute for the rendered `img` element.
*/
alt: PropTypes.string,
/**
* Used to render icon or text elements inside the Avatar.
* `src` and `alt` props will not be used and no `img` will
* be rendered by default.
*
* This can be an element, or just a string.
*/
children: PropTypes.node,
/**
* @ignore
* The className of the child element.
* Used by Chip and ListItemIcon to style the Avatar icon.
*/
childrenClassName: PropTypes.string,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
/**
* Properties applied to the `img` element when the component
* is used to display an image.
*/
imgProps: PropTypes.object,
/**
* The `sizes` attribute for the `img` element.
*/
sizes: PropTypes.string,
/**
* The `src` attribute for the `img` element.
*/
src: PropTypes.string,
/**
* The `srcSet` attribute for the `img` element.
*/
srcSet: PropTypes.string,
};
Avatar.defaultProps = {
component: 'div',
};

View File

@@ -1,3 +1 @@
// @flow
export { default } from './Avatar';

View File

@@ -1,21 +1,15 @@
import * as React from 'react';
import { StandardProps, PropTypes } from '..';
export interface BadgeProps extends StandardProps<
React.HTMLAttributes<HTMLDivElement>,
BadgeClassKey
> {
export interface BadgeProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, BadgeClassKey> {
badgeContent: React.ReactNode;
children: React.ReactNode;
color?: PropTypes.Color;
color?: PropTypes.Color | 'error';
component?: React.ReactType<BadgeProps>;
}
export type BadgeClassKey =
| 'root'
| 'badge'
| 'colorPrimary'
| 'colorAccent'
;
export type BadgeClassKey = 'root' | 'badge' | 'colorPrimary' | 'colorSecondary';
declare const Badge: React.ComponentType<BadgeProps>;

View File

@@ -17,12 +17,14 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref; // weak
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
@@ -35,15 +37,15 @@ var _helpers = require('../utils/helpers');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var RADIUS = 12;
var styles = exports.styles = function styles(theme) {
return {
root: {
position: 'relative',
display: 'inline-flex'
display: 'inline-flex',
// For correct alignment with the text.
verticalAlign: 'middle'
},
badge: {
display: 'flex',
@@ -66,58 +68,35 @@ var styles = exports.styles = function styles(theme) {
zIndex: 1 // Render the badge on top of potential ripples.
},
colorPrimary: {
backgroundColor: theme.palette.primary[500],
color: theme.palette.getContrastText(theme.palette.primary[500])
backgroundColor: theme.palette.primary.main,
color: theme.palette.primary.contrastText
},
colorAccent: {
backgroundColor: theme.palette.secondary.A200,
color: theme.palette.getContrastText(theme.palette.secondary.A200)
colorSecondary: {
backgroundColor: theme.palette.secondary.main,
color: theme.palette.secondary.contrastText
},
colorError: {
backgroundColor: theme.palette.error.main,
color: theme.palette.error.contrastText
}
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The content rendered within the badge.
*/
badgeContent: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node.isRequired ? babelPluginFlowReactPropTypes_proptype_Node.isRequired : babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node).isRequired,
/**
* The badge will be added relative to this node.
*/
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node.isRequired ? babelPluginFlowReactPropTypes_proptype_Node.isRequired : babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node).isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* The color of the component. It's using the theme palette when that makes sense.
*/
color: require('prop-types').oneOf(['default', 'primary', 'accent'])
};
function Badge(props) {
var badgeContent = props.badgeContent,
children = props.children,
classes = props.classes,
classNameProp = props.className,
color = props.color,
children = props.children,
other = (0, _objectWithoutProperties3.default)(props, ['badgeContent', 'classes', 'className', 'color', 'children']);
ComponentProp = props.component,
other = (0, _objectWithoutProperties3.default)(props, ['badgeContent', 'children', 'classes', 'className', 'color', 'component']);
var className = (0, _classnames2.default)(classes.root, classNameProp);
var badgeClassName = (0, _classnames2.default)(classes.badge, (0, _defineProperty3.default)({}, classes['color' + (0, _helpers.capitalizeFirstLetter)(color)], color !== 'default'));
var badgeClassName = (0, _classnames2.default)(classes.badge, (0, _defineProperty3.default)({}, classes['color' + (0, _helpers.capitalize)(color)], color !== 'default'));
return _react2.default.createElement(
'div',
(0, _extends3.default)({ className: className }, other),
ComponentProp,
(0, _extends3.default)({ className: (0, _classnames2.default)(classes.root, classNameProp) }, other),
children,
_react2.default.createElement(
'span',
@@ -127,13 +106,37 @@ function Badge(props) {
);
}
Badge.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
badgeContent: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node.isRequired ? babelPluginFlowReactPropTypes_proptype_Node.isRequired : babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node).isRequired,
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node.isRequired ? babelPluginFlowReactPropTypes_proptype_Node.isRequired : babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node).isRequired
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'color', require('prop-types').oneOf(['default', 'primary', 'accent'])), _ref) : {};
Badge.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content rendered within the badge.
*/
badgeContent: _propTypes2.default.node.isRequired,
/**
* The badge will be added relative to this node.
*/
children: _propTypes2.default.node.isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* The color of the component. It supports those theme colors that make sense for this component.
*/
color: _propTypes2.default.oneOf(['default', 'primary', 'secondary', 'error']),
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func])
} : {};
Badge.defaultProps = {
color: 'default'
color: 'default',
component: 'span'
};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiBadge' })(Badge);

View File

@@ -1,17 +1,17 @@
// @flow weak
import React from 'react';
import type { Node } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import { capitalizeFirstLetter } from '../utils/helpers';
import { capitalize } from '../utils/helpers';
const RADIUS = 12;
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
position: 'relative',
display: 'inline-flex',
// For correct alignment with the text.
verticalAlign: 'middle',
},
badge: {
display: 'flex',
@@ -34,59 +34,73 @@ export const styles = (theme: Object) => ({
zIndex: 1, // Render the badge on top of potential ripples.
},
colorPrimary: {
backgroundColor: theme.palette.primary[500],
color: theme.palette.getContrastText(theme.palette.primary[500]),
backgroundColor: theme.palette.primary.main,
color: theme.palette.primary.contrastText,
},
colorAccent: {
backgroundColor: theme.palette.secondary.A200,
color: theme.palette.getContrastText(theme.palette.secondary.A200),
colorSecondary: {
backgroundColor: theme.palette.secondary.main,
color: theme.palette.secondary.contrastText,
},
colorError: {
backgroundColor: theme.palette.error.main,
color: theme.palette.error.contrastText,
},
});
type ProvidedProps = {
classes: Object,
};
function Badge(props) {
const {
badgeContent,
children,
classes,
className: classNameProp,
color,
component: ComponentProp,
...other
} = props;
export type Props = {
/**
* The content rendered within the badge.
*/
badgeContent: Node,
/**
* The badge will be added relative to this node.
*/
children: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* The color of the component. It's using the theme palette when that makes sense.
*/
color?: 'default' | 'primary' | 'accent',
};
function Badge(props: ProvidedProps & Props) {
const { badgeContent, classes, className: classNameProp, color, children, ...other } = props;
const className = classNames(classes.root, classNameProp);
const badgeClassName = classNames(classes.badge, {
[classes[`color${capitalizeFirstLetter(color)}`]]: color !== 'default',
[classes[`color${capitalize(color)}`]]: color !== 'default',
});
return (
<div className={className} {...other}>
<ComponentProp className={classNames(classes.root, classNameProp)} {...other}>
{children}
<span className={badgeClassName}>{badgeContent}</span>
</div>
</ComponentProp>
);
}
Badge.propTypes = {
/**
* The content rendered within the badge.
*/
badgeContent: PropTypes.node.isRequired,
/**
* The badge will be added relative to this node.
*/
children: PropTypes.node.isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The color of the component. It supports those theme colors that make sense for this component.
*/
color: PropTypes.oneOf(['default', 'primary', 'secondary', 'error']),
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
};
Badge.defaultProps = {
color: 'default',
component: 'span',
};
export default withStyles(styles, { name: 'MuiBadge' })(Badge);

View File

@@ -1,3 +1 @@
// @flow
export { default } from './Badge';

View File

@@ -1,20 +1,19 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface BottomNavigationProps extends StandardProps<
React.HTMLAttributes<HTMLDivElement>,
BottomNavigationClassKey,
'onChange'
> {
export interface BottomNavigationProps
extends StandardProps<
React.HTMLAttributes<HTMLDivElement>,
BottomNavigationClassKey,
'onChange'
> {
children: React.ReactNode;
onChange?: (event: React.ChangeEvent<{}>, value: any) => void;
showLabels?: boolean;
value?: any;
}
export type BottomNavigationClassKey =
| 'root'
;
export type BottomNavigationClassKey = 'root';
declare const BottomNavigation: React.ComponentType<BottomNavigationProps>;

View File

@@ -5,10 +5,6 @@ Object.defineProperty(exports, "__esModule", {
});
exports.styles = undefined;
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
@@ -17,12 +13,14 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref; // weak
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
@@ -33,8 +31,6 @@ var _withStyles2 = _interopRequireDefault(_withStyles);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var styles = exports.styles = function styles(theme) {
return {
root: {
@@ -46,43 +42,6 @@ var styles = exports.styles = function styles(theme) {
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The content of the component.
*/
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node.isRequired ? babelPluginFlowReactPropTypes_proptype_Node.isRequired : babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node).isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* Callback fired when the value changes.
*
* @param {object} event The event source of the callback
* @param {any} value We default to the index of the child
*/
onChange: require('prop-types').func,
/**
* If `true`, all `BottomNavigationButton`s will show their labels.
* By default only the selected `BottomNavigationButton` will show its label.
*/
showLabels: require('prop-types').bool,
/**
* The value of the currently selected `BottomNavigationButton`.
*/
value: require('prop-types').any.isRequired
};
function BottomNavigation(props) {
var childrenProp = props.children,
classes = props.classes,
@@ -96,6 +55,10 @@ function BottomNavigation(props) {
var className = (0, _classnames2.default)(classes.root, classNameProp);
var children = _react2.default.Children.map(childrenProp, function (child, childIndex) {
if (!_react2.default.isValidElement(child)) {
return null;
}
var childValue = child.props.value || childIndex;
return _react2.default.cloneElement(child, {
selected: childValue === value,
@@ -112,11 +75,37 @@ function BottomNavigation(props) {
);
}
BottomNavigation.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
showLabels: require('prop-types').bool.isRequired,
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node.isRequired ? babelPluginFlowReactPropTypes_proptype_Node.isRequired : babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node).isRequired
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'onChange', require('prop-types').func), (0, _defineProperty3.default)(_ref, 'showLabels', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'value', require('prop-types').any.isRequired), _ref) : {};
BottomNavigation.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the component.
*/
children: _propTypes2.default.node.isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* Callback fired when the value changes.
*
* @param {object} event The event source of the callback
* @param {any} value We default to the index of the child
*/
onChange: _propTypes2.default.func,
/**
* If `true`, all `BottomNavigationAction`s will show their labels.
* By default, only the selected `BottomNavigationAction` will show its label.
*/
showLabels: _propTypes2.default.bool,
/**
* The value of the currently selected `BottomNavigationAction`.
*/
value: _propTypes2.default.any
} : {};
BottomNavigation.defaultProps = {
showLabels: false
};

View File

@@ -1,11 +1,9 @@
// @flow weak
import React from 'react';
import type { Node } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
display: 'flex',
justifyContent: 'center',
@@ -14,43 +12,7 @@ export const styles = (theme: Object) => ({
},
});
type ProvidedProps = {
classes: Object,
showLabels: boolean,
};
export type Props = {
/**
* The content of the component.
*/
children: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* Callback fired when the value changes.
*
* @param {object} event The event source of the callback
* @param {any} value We default to the index of the child
*/
onChange?: Function,
/**
* If `true`, all `BottomNavigationButton`s will show their labels.
* By default only the selected `BottomNavigationButton` will show its label.
*/
showLabels?: boolean,
/**
* The value of the currently selected `BottomNavigationButton`.
*/
value: any,
};
function BottomNavigation(props: ProvidedProps & Props) {
function BottomNavigation(props) {
const {
children: childrenProp,
classes,
@@ -64,6 +26,10 @@ function BottomNavigation(props: ProvidedProps & Props) {
const className = classNames(classes.root, classNameProp);
const children = React.Children.map(childrenProp, (child, childIndex) => {
if (!React.isValidElement(child)) {
return null;
}
const childValue = child.props.value || childIndex;
return React.cloneElement(child, {
selected: childValue === value,
@@ -80,6 +46,37 @@ function BottomNavigation(props: ProvidedProps & Props) {
);
}
BottomNavigation.propTypes = {
/**
* 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,
/**
* Callback fired when the value changes.
*
* @param {object} event The event source of the callback
* @param {any} value We default to the index of the child
*/
onChange: PropTypes.func,
/**
* If `true`, all `BottomNavigationAction`s will show their labels.
* By default, only the selected `BottomNavigationAction` will show its label.
*/
showLabels: PropTypes.bool,
/**
* The value of the currently selected `BottomNavigationAction`.
*/
value: PropTypes.any,
};
BottomNavigation.defaultProps = {
showLabels: false,
};

View File

@@ -2,11 +2,8 @@ import * as React from 'react';
import { StandardProps } from '..';
import { ButtonBaseProps, ButtonBaseClassKey } from '../ButtonBase';
export interface BottomNavigationButtonProps extends StandardProps<
ButtonBaseProps,
BottomNavigationButtonClassKey,
'onChange'
> {
export interface BottomNavigationActionProps
extends StandardProps<ButtonBaseProps, BottomNavigationActionClassKey, 'onChange'> {
icon?: string | React.ReactElement<any>;
label?: React.ReactNode;
onChange?: (event: React.ChangeEvent<{}>, value: any) => void;
@@ -16,17 +13,15 @@ export interface BottomNavigationButtonProps extends StandardProps<
value?: any;
}
export type BottomNavigationButtonClassKey =
export type BottomNavigationActionClassKey =
| ButtonBaseClassKey
| 'selected'
| 'selectedIconOnly'
| 'wrapper'
| 'label'
| 'selectedLabel'
| 'hiddenLabel'
| 'icon'
;
| 'hiddenLabel';
declare const BottomNavigationButton: React.ComponentType<BottomNavigationButtonProps>;
declare const BottomNavigationAction: React.ComponentType<BottomNavigationActionProps>;
export default BottomNavigationButton;
export default BottomNavigationAction;

View File

@@ -41,6 +41,10 @@ var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
@@ -53,24 +57,15 @@ var _ButtonBase = require('../ButtonBase');
var _ButtonBase2 = _interopRequireDefault(_ButtonBase);
var _Icon = require('../Icon');
var _Icon2 = _interopRequireDefault(_Icon);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Element = require('react').babelPluginFlowReactPropTypes_proptype_Element || require('prop-types').any;
// @inheritedComponent ButtonBase
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var styles = exports.styles = function styles(theme) {
return {
root: {
transition: theme.transitions.create(['color', 'padding-top'], {
duration: theme.transitions.duration.short
}),
paddingTop: 8,
paddingTop: theme.spacing.unit,
paddingBottom: 10,
paddingLeft: 12,
paddingRight: 12,
@@ -81,7 +76,7 @@ var styles = exports.styles = function styles(theme) {
},
selected: {
paddingTop: 6,
color: theme.palette.primary[500]
color: theme.palette.primary.main
},
selectedIconOnly: {
paddingTop: theme.spacing.unit * 2
@@ -106,76 +101,25 @@ var styles = exports.styles = function styles(theme) {
hiddenLabel: {
opacity: 0,
transitionDelay: '0s'
},
icon: {
display: 'block',
margin: 'auto'
}
};
};
}; // @inheritedComponent ButtonBase
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
var BottomNavigationAction = function (_React$Component) {
(0, _inherits3.default)(BottomNavigationAction, _React$Component);
/**
* @ignore
*/
className: require('prop-types').string,
/**
* The icon element. If a string is provided, it will be used as a font ligature.
*/
icon: require('prop-types').oneOfType([require('prop-types').string, typeof babelPluginFlowReactPropTypes_proptype_Element === 'function' ? babelPluginFlowReactPropTypes_proptype_Element : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Element)]),
/**
* The label element.
*/
label: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* @ignore
*/
onChange: require('prop-types').func,
/**
* @ignore
*/
onClick: require('prop-types').func,
/**
* @ignore
*/
selected: require('prop-types').bool,
/**
* If `true`, the BottomNavigationButton will show its label.
*/
showLabel: require('prop-types').bool,
/**
* You can provide your own value. Otherwise, we fallback to the child position index.
*/
value: require('prop-types').any
};
var BottomNavigationButton = function (_React$Component) {
(0, _inherits3.default)(BottomNavigationButton, _React$Component);
function BottomNavigationButton() {
function BottomNavigationAction() {
var _ref;
var _temp, _this, _ret;
(0, _classCallCheck3.default)(this, BottomNavigationButton);
(0, _classCallCheck3.default)(this, BottomNavigationAction);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = BottomNavigationButton.__proto__ || (0, _getPrototypeOf2.default)(BottomNavigationButton)).call.apply(_ref, [this].concat(args))), _this), _this.handleChange = function (event) {
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = BottomNavigationAction.__proto__ || (0, _getPrototypeOf2.default)(BottomNavigationAction)).call.apply(_ref, [this].concat(args))), _this), _this.handleChange = function (event) {
var _this$props = _this.props,
onChange = _this$props.onChange,
value = _this$props.value,
@@ -192,46 +136,31 @@ var BottomNavigationButton = function (_React$Component) {
}, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
}
(0, _createClass3.default)(BottomNavigationButton, [{
(0, _createClass3.default)(BottomNavigationAction, [{
key: 'render',
value: function render() {
var _classNames, _classNames2;
var _props = this.props,
label = _props.label,
iconProp = _props.icon,
selected = _props.selected,
classes = _props.classes,
classNameProp = _props.className,
showLabelProp = _props.showLabel,
icon = _props.icon,
label = _props.label,
onChange = _props.onChange,
onClick = _props.onClick,
selected = _props.selected,
showLabelProp = _props.showLabel,
value = _props.value,
other = (0, _objectWithoutProperties3.default)(_props, ['label', 'icon', 'selected', 'classes', 'className', 'showLabel', 'onChange', 'value']);
other = (0, _objectWithoutProperties3.default)(_props, ['classes', 'className', 'icon', 'label', 'onChange', 'onClick', 'selected', 'showLabel', 'value']);
var className = (0, _classnames2.default)(classes.root, (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes.selected, selected), (0, _defineProperty3.default)(_classNames, classes.selectedIconOnly, !showLabelProp && !selected), _classNames), classNameProp);
var icon = null;
if (iconProp) {
if (_react2.default.isValidElement(iconProp) && typeof iconProp !== 'string') {
icon = _react2.default.cloneElement(iconProp, {
className: (0, _classnames2.default)(classes.icon, iconProp.props.className)
});
} else {
icon = _react2.default.createElement(
_Icon2.default,
null,
iconProp
);
}
}
var labelClassName = (0, _classnames2.default)(classes.label, (_classNames2 = {}, (0, _defineProperty3.default)(_classNames2, classes.selectedLabel, selected), (0, _defineProperty3.default)(_classNames2, classes.hiddenLabel, !showLabelProp && !selected), _classNames2));
return _react2.default.createElement(
_ButtonBase2.default,
(0, _extends3.default)({ className: className, focusRipple: true }, other, { onClick: this.handleChange }),
(0, _extends3.default)({ className: className, focusRipple: true, onClick: this.handleChange }, other),
_react2.default.createElement(
'span',
{ className: classes.wrapper },
@@ -245,7 +174,46 @@ var BottomNavigationButton = function (_React$Component) {
);
}
}]);
return BottomNavigationButton;
return BottomNavigationAction;
}(_react2.default.Component);
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiBottomNavigationButton' })(BottomNavigationButton);
BottomNavigationAction.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* The icon element.
*/
icon: _propTypes2.default.node,
/**
* The label element.
*/
label: _propTypes2.default.node,
/**
* @ignore
*/
onChange: _propTypes2.default.func,
/**
* @ignore
*/
onClick: _propTypes2.default.func,
/**
* @ignore
*/
selected: _propTypes2.default.bool,
/**
* If `true`, the BottomNavigationAction will show its label.
*/
showLabel: _propTypes2.default.bool,
/**
* You can provide your own value. Otherwise, we fallback to the child position index.
*/
value: _propTypes2.default.any
} : {};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiBottomNavigationAction' })(BottomNavigationAction);

View File

@@ -1,19 +1,17 @@
// @flow
// @inheritedComponent ButtonBase
import React from 'react';
import type { Node, Element } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import ButtonBase from '../ButtonBase';
import Icon from '../Icon';
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
transition: theme.transitions.create(['color', 'padding-top'], {
duration: theme.transitions.duration.short,
}),
paddingTop: 8,
paddingTop: theme.spacing.unit,
paddingBottom: 10,
paddingLeft: 12,
paddingRight: 12,
@@ -24,7 +22,7 @@ export const styles = (theme: Object) => ({
},
selected: {
paddingTop: 6,
color: theme.palette.primary[500],
color: theme.palette.primary.main,
},
selectedIconOnly: {
paddingTop: theme.spacing.unit * 2,
@@ -50,56 +48,9 @@ export const styles = (theme: Object) => ({
opacity: 0,
transitionDelay: '0s',
},
icon: {
display: 'block',
margin: 'auto',
},
});
type ProvidedProps = {
classes: Object,
};
export type Props = {
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* The icon element. If a string is provided, it will be used as a font ligature.
*/
icon?: string | Element<any>,
/**
* The label element.
*/
label?: Node,
/**
* @ignore
*/
onChange?: Function,
/**
* @ignore
*/
onClick?: Function,
/**
* @ignore
*/
selected?: boolean,
/**
* If `true`, the BottomNavigationButton will show its label.
*/
showLabel?: boolean,
/**
* You can provide your own value. Otherwise, we fallback to the child position index.
*/
value?: any,
};
class BottomNavigationButton extends React.Component<ProvidedProps & Props> {
class BottomNavigationAction extends React.Component {
handleChange = event => {
const { onChange, value, onClick } = this.props;
@@ -114,13 +65,14 @@ class BottomNavigationButton extends React.Component<ProvidedProps & Props> {
render() {
const {
label,
icon: iconProp,
selected,
classes,
className: classNameProp,
showLabel: showLabelProp,
icon,
label,
onChange,
onClick,
selected,
showLabel: showLabelProp,
value,
...other
} = this.props;
@@ -134,25 +86,13 @@ class BottomNavigationButton extends React.Component<ProvidedProps & Props> {
classNameProp,
);
let icon = null;
if (iconProp) {
if (React.isValidElement(iconProp) && typeof iconProp !== 'string') {
icon = React.cloneElement(iconProp, {
className: classNames(classes.icon, iconProp.props.className),
});
} else {
icon = <Icon>{iconProp}</Icon>;
}
}
const labelClassName = classNames(classes.label, {
[classes.selectedLabel]: selected,
[classes.hiddenLabel]: !showLabelProp && !selected,
});
return (
<ButtonBase className={className} focusRipple {...other} onClick={this.handleChange}>
<ButtonBase className={className} focusRipple onClick={this.handleChange} {...other}>
<span className={classes.wrapper}>
{icon}
<span className={labelClassName}>{label}</span>
@@ -162,4 +102,43 @@ class BottomNavigationButton extends React.Component<ProvidedProps & Props> {
}
}
export default withStyles(styles, { name: 'MuiBottomNavigationButton' })(BottomNavigationButton);
BottomNavigationAction.propTypes = {
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The icon element.
*/
icon: PropTypes.node,
/**
* The label element.
*/
label: PropTypes.node,
/**
* @ignore
*/
onChange: PropTypes.func,
/**
* @ignore
*/
onClick: PropTypes.func,
/**
* @ignore
*/
selected: PropTypes.bool,
/**
* If `true`, the BottomNavigationAction will show its label.
*/
showLabel: PropTypes.bool,
/**
* You can provide your own value. Otherwise, we fallback to the child position index.
*/
value: PropTypes.any,
};
export default withStyles(styles, { name: 'MuiBottomNavigationAction' })(BottomNavigationAction);

View File

@@ -1,4 +1,4 @@
export { default } from './BottomNavigation';
export * from './BottomNavigation';
export { default as BottomNavigationButton } from './BottomNavigationButton';
export * from './BottomNavigationButton';
export { default as BottomNavigationAction } from './BottomNavigationAction';
export * from './BottomNavigationAction';

View File

@@ -13,12 +13,12 @@ Object.defineProperty(exports, 'default', {
}
});
var _BottomNavigationButton = require('./BottomNavigationButton');
var _BottomNavigationAction = require('./BottomNavigationAction');
Object.defineProperty(exports, 'BottomNavigationButton', {
Object.defineProperty(exports, 'BottomNavigationAction', {
enumerable: true,
get: function get() {
return _interopRequireDefault(_BottomNavigationButton).default;
return _interopRequireDefault(_BottomNavigationAction).default;
}
});

View File

@@ -1,4 +1,2 @@
// @flow
export { default } from './BottomNavigation';
export { default as BottomNavigationButton } from './BottomNavigationButton';
export { default as BottomNavigationAction } from './BottomNavigationAction';

View File

@@ -2,20 +2,18 @@ import * as React from 'react';
import { StandardProps, PropTypes } from '..';
import { ButtonBaseProps, ButtonBaseClassKey } from '../ButtonBase';
export interface ButtonProps extends StandardProps<
ButtonBaseProps,
ButtonClassKey
> {
color?: PropTypes.Color | 'contrast';
component?: React.ReactType;
dense?: boolean;
export interface ButtonProps extends StandardProps<ButtonBaseProps, ButtonClassKey, 'component'> {
color?: PropTypes.Color;
component?: React.ReactType<ButtonProps>;
disabled?: boolean;
disableFocusRipple?: boolean;
disableRipple?: boolean;
fab?: boolean;
fullWidth?: boolean;
href?: string;
raised?: boolean;
mini?: boolean;
size?: 'small' | 'medium' | 'large';
type?: string;
variant?: 'flat' | 'raised' | 'fab';
}
export type ButtonClassKey =
@@ -23,17 +21,15 @@ export type ButtonClassKey =
| 'dense'
| 'label'
| 'flatPrimary'
| 'flatAccent'
| 'flatContrast'
| 'flatSecondary'
| 'colorInherit'
| 'raised'
| 'keyboardFocused'
| 'raisedPrimary'
| 'raisedAccent'
| 'raisedContrast'
| 'raisedSecondary'
| 'fab'
;
| 'fullWidth';
declare const Button: React.ComponentType<ButtonProps>;
export default Button
export default Button;

View File

@@ -17,13 +17,14 @@ var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _ref;
// @inheritedComponent ButtonBase
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
@@ -38,18 +39,20 @@ var _ButtonBase = require('../ButtonBase');
var _ButtonBase2 = _interopRequireDefault(_ButtonBase);
var _helpers = require('../utils/helpers');
var _reactHelpers = require('../utils/reactHelpers');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var babelPluginFlowReactPropTypes_proptype_ElementType = require('react').babelPluginFlowReactPropTypes_proptype_ElementType || require('prop-types').any;
// @inheritedComponent ButtonBase
var styles = exports.styles = function styles(theme) {
return {
root: (0, _extends3.default)({}, theme.typography.button, {
lineHeight: '1.4em', // Improve readability for multiline button.
boxSizing: 'border-box',
minWidth: 88,
minWidth: theme.spacing.unit * 11,
minHeight: 36,
padding: theme.spacing.unit + 'px ' + theme.spacing.unit * 2 + 'px',
borderRadius: 2,
@@ -69,12 +72,6 @@ var styles = exports.styles = function styles(theme) {
}
}
}),
dense: {
padding: theme.spacing.unit - 1 + 'px ' + theme.spacing.unit + 'px',
minWidth: 64,
minHeight: 32,
fontSize: theme.typography.pxToRem(theme.typography.fontSize - 1)
},
label: {
width: '100%',
display: 'inherit',
@@ -82,29 +79,19 @@ var styles = exports.styles = function styles(theme) {
justifyContent: 'inherit'
},
flatPrimary: {
color: theme.palette.primary[500],
color: theme.palette.primary.main,
'&:hover': {
backgroundColor: (0, _colorManipulator.fade)(theme.palette.primary[500], 0.12),
backgroundColor: (0, _colorManipulator.fade)(theme.palette.primary.main, 0.12),
// Reset on mouse devices
'@media (hover: none)': {
backgroundColor: 'transparent'
}
}
},
flatAccent: {
color: theme.palette.secondary.A200,
flatSecondary: {
color: theme.palette.secondary.main,
'&:hover': {
backgroundColor: (0, _colorManipulator.fade)(theme.palette.secondary.A200, 0.12),
// Reset on mouse devices
'@media (hover: none)': {
backgroundColor: 'transparent'
}
}
},
flatContrast: {
color: theme.palette.getContrastText(theme.palette.primary[500]),
'&:hover': {
backgroundColor: (0, _colorManipulator.fade)(theme.palette.getContrastText(theme.palette.primary[500]), 0.12),
backgroundColor: (0, _colorManipulator.fade)(theme.palette.secondary.main, 0.12),
// Reset on mouse devices
'@media (hover: none)': {
backgroundColor: 'transparent'
@@ -126,7 +113,7 @@ var styles = exports.styles = function styles(theme) {
},
'&$disabled': {
boxShadow: theme.shadows[0],
backgroundColor: theme.palette.text.divider
backgroundColor: theme.palette.action.disabledBackground
},
'&:hover': {
backgroundColor: theme.palette.grey.A100,
@@ -135,40 +122,33 @@ var styles = exports.styles = function styles(theme) {
backgroundColor: theme.palette.grey[300]
},
'&$disabled': {
backgroundColor: theme.palette.text.divider,
// Reset on mouse devices
'@media (hover: none)': {
backgroundColor: theme.palette.grey[300]
}
backgroundColor: theme.palette.action.disabledBackground
}
}
},
keyboardFocused: {},
raisedPrimary: {
color: theme.palette.getContrastText(theme.palette.primary[500]),
backgroundColor: theme.palette.primary[500],
color: theme.palette.primary.contrastText,
backgroundColor: theme.palette.primary.main,
'&:hover': {
backgroundColor: theme.palette.primary[700],
backgroundColor: theme.palette.primary.dark,
// Reset on mouse devices
'@media (hover: none)': {
backgroundColor: theme.palette.primary[500]
backgroundColor: theme.palette.primary.main
}
}
},
raisedAccent: {
color: theme.palette.getContrastText(theme.palette.secondary.A200),
backgroundColor: theme.palette.secondary.A200,
raisedSecondary: {
color: theme.palette.secondary.contrastText,
backgroundColor: theme.palette.secondary.main,
'&:hover': {
backgroundColor: theme.palette.secondary.A400,
backgroundColor: theme.palette.secondary.dark,
// Reset on mouse devices
'@media (hover: none)': {
backgroundColor: theme.palette.secondary.A200
backgroundColor: theme.palette.secondary.main
}
}
},
raisedContrast: {
color: theme.palette.getContrastText(theme.palette.primary[500])
},
disabled: {
color: theme.palette.action.disabled
},
@@ -177,106 +157,66 @@ var styles = exports.styles = function styles(theme) {
padding: 0,
minWidth: 0,
width: 56,
fontSize: 24,
height: 56,
boxShadow: theme.shadows[6],
'&:active': {
boxShadow: theme.shadows[12]
}
},
mini: {
width: 40,
height: 40
},
sizeSmall: {
padding: theme.spacing.unit - 1 + 'px ' + theme.spacing.unit + 'px',
minWidth: theme.spacing.unit * 8,
minHeight: 32,
fontSize: theme.typography.pxToRem(theme.typography.fontSize - 1)
},
sizeLarge: {
padding: theme.spacing.unit + 'px ' + theme.spacing.unit * 3 + 'px',
minWidth: theme.spacing.unit * 14,
minHeight: 40,
fontSize: theme.typography.pxToRem(theme.typography.fontSize + 1)
},
fullWidth: {
width: '100%'
}
};
};
var babelPluginFlowReactPropTypes_proptype_Color = require('prop-types').oneOf(['default', 'inherit', 'primary', 'accent', 'contrast']);
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The content of the button.
*/
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node.isRequired ? babelPluginFlowReactPropTypes_proptype_Node.isRequired : babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node).isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* The color of the component. It's using the theme palette when that makes sense.
*/
color: require('prop-types').oneOf(['default', 'inherit', 'primary', 'accent', 'contrast']),
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
* The default value is a `button`.
*/
component: typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType),
/**
* Uses a smaller minWidth, ideal for things like card actions.
*/
dense: require('prop-types').bool,
/**
* If `true`, the button will be disabled.
*/
disabled: require('prop-types').bool,
/**
* If `true`, the keyboard focus ripple will be disabled.
* `disableRipple` must also be true.
*/
disableFocusRipple: require('prop-types').bool,
/**
* If `true`, the ripple effect will be disabled.
*/
disableRipple: require('prop-types').bool,
/**
* If `true`, will use floating action button styling.
*/
fab: require('prop-types').bool,
/**
* The URL to link to when the button is clicked.
* If defined, an `a` element will be used as the root node.
*/
href: require('prop-types').string,
/**
* If `true`, the button will use raised styling.
*/
raised: require('prop-types').bool,
/**
* @ignore
*/
type: require('prop-types').string
};
function Button(props) {
var _classNames;
var children = props.children,
var childrenProp = props.children,
classes = props.classes,
classNameProp = props.className,
color = props.color,
dense = props.dense,
disabled = props.disabled,
disableFocusRipple = props.disableFocusRipple,
fab = props.fab,
raised = props.raised,
other = (0, _objectWithoutProperties3.default)(props, ['children', 'classes', 'className', 'color', 'dense', 'disabled', 'disableFocusRipple', 'fab', 'raised']);
fullWidth = props.fullWidth,
mini = props.mini,
size = props.size,
variant = props.variant,
other = (0, _objectWithoutProperties3.default)(props, ['children', 'classes', 'className', 'color', 'disabled', 'disableFocusRipple', 'fullWidth', 'mini', 'size', 'variant']);
var fab = variant === 'fab';
var raised = variant === 'raised';
var flat = !raised && !fab;
var className = (0, _classnames2.default)((_classNames = {}, (0, _defineProperty3.default)(_classNames, classes.root, true), (0, _defineProperty3.default)(_classNames, classes.raised, raised || fab), (0, _defineProperty3.default)(_classNames, classes.fab, fab), (0, _defineProperty3.default)(_classNames, classes.colorInherit, color === 'inherit'), (0, _defineProperty3.default)(_classNames, classes.flatPrimary, flat && color === 'primary'), (0, _defineProperty3.default)(_classNames, classes.flatAccent, flat && color === 'accent'), (0, _defineProperty3.default)(_classNames, classes.flatContrast, flat && color === 'contrast'), (0, _defineProperty3.default)(_classNames, classes.raisedPrimary, !flat && color === 'primary'), (0, _defineProperty3.default)(_classNames, classes.raisedAccent, !flat && color === 'accent'), (0, _defineProperty3.default)(_classNames, classes.raisedContrast, !flat && color === 'contrast'), (0, _defineProperty3.default)(_classNames, classes.dense, dense), (0, _defineProperty3.default)(_classNames, classes.disabled, disabled), _classNames), classNameProp);
var className = (0, _classnames2.default)(classes.root, (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes.raised, raised || fab), (0, _defineProperty3.default)(_classNames, classes.fab, fab), (0, _defineProperty3.default)(_classNames, classes.mini, fab && mini), (0, _defineProperty3.default)(_classNames, classes.colorInherit, color === 'inherit'), (0, _defineProperty3.default)(_classNames, classes.flatPrimary, flat && color === 'primary'), (0, _defineProperty3.default)(_classNames, classes.flatSecondary, flat && color === 'secondary'), (0, _defineProperty3.default)(_classNames, classes.raisedPrimary, !flat && color === 'primary'), (0, _defineProperty3.default)(_classNames, classes.raisedSecondary, !flat && color === 'secondary'), (0, _defineProperty3.default)(_classNames, classes['size' + (0, _helpers.capitalize)(size)], size !== 'medium'), (0, _defineProperty3.default)(_classNames, classes.disabled, disabled), (0, _defineProperty3.default)(_classNames, classes.fullWidth, fullWidth), _classNames), classNameProp);
var children = childrenProp;
if (fab) {
children = _react2.default.Children.map(children, function (child) {
if ((0, _reactHelpers.isMuiElement)(child, ['Icon', 'SvgIcon'])) {
return _react2.default.cloneElement(child, { fontSize: true });
}
return child;
});
}
return _react2.default.createElement(
_ButtonBase2.default,
@@ -294,27 +234,80 @@ function Button(props) {
);
}
Button.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
color: require('prop-types').oneOf(['default', 'inherit', 'primary', 'accent', 'contrast']).isRequired,
dense: require('prop-types').bool.isRequired,
disabled: require('prop-types').bool.isRequired,
fab: require('prop-types').bool.isRequired,
disableFocusRipple: require('prop-types').bool.isRequired,
raised: require('prop-types').bool.isRequired,
disableRipple: require('prop-types').bool.isRequired,
type: require('prop-types').string.isRequired,
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node.isRequired ? babelPluginFlowReactPropTypes_proptype_Node.isRequired : babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node).isRequired
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'color', require('prop-types').oneOf(['default', 'inherit', 'primary', 'accent', 'contrast'])), (0, _defineProperty3.default)(_ref, 'component', typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType)), (0, _defineProperty3.default)(_ref, 'dense', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'disabled', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'disableFocusRipple', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'disableRipple', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'fab', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'href', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'raised', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'type', require('prop-types').string), _ref) : {};
Button.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the button.
*/
children: _propTypes2.default.node.isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* The color of the component. It supports those theme colors that make sense for this component.
*/
color: _propTypes2.default.oneOf(['default', 'inherit', 'primary', 'secondary']),
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
* The default value is a `button`.
*/
component: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func]),
/**
* If `true`, the button will be disabled.
*/
disabled: _propTypes2.default.bool,
/**
* If `true`, the keyboard focus ripple will be disabled.
* `disableRipple` must also be true.
*/
disableFocusRipple: _propTypes2.default.bool,
/**
* If `true`, the ripple effect will be disabled.
*/
disableRipple: _propTypes2.default.bool,
/**
* If `true`, the button will take up the full width of its container.
*/
fullWidth: _propTypes2.default.bool,
/**
* The URL to link to when the button is clicked.
* If defined, an `a` element will be used as the root node.
*/
href: _propTypes2.default.string,
/**
* If `true`, and `variant` is `'fab'`, will use mini floating action button styling.
*/
mini: _propTypes2.default.bool,
/**
* The size of the button.
* `small` is equivalent to the dense button styling.
*/
size: _propTypes2.default.oneOf(['small', 'medium', 'large']),
/**
* @ignore
*/
type: _propTypes2.default.string,
/**
* The color of the component. It supports those theme colors that make sense for this component.
*/
variant: _propTypes2.default.oneOf(['flat', 'raised', 'fab'])
} : {};
Button.defaultProps = {
color: 'default',
dense: false,
disabled: false,
fab: false,
disableFocusRipple: false,
raised: false,
disableRipple: false,
type: 'button'
fullWidth: false,
mini: false,
size: 'medium',
type: 'button',
variant: 'flat'
};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiButton' })(Button);

View File

@@ -1,19 +1,20 @@
// @flow
// @inheritedComponent ButtonBase
import React from 'react';
import type { ElementType, Node } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import { fade } from '../styles/colorManipulator';
import ButtonBase from '../ButtonBase';
import { capitalize } from '../utils/helpers';
import { isMuiElement } from '../utils/reactHelpers';
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
...theme.typography.button,
lineHeight: '1.4em', // Improve readability for multiline button.
boxSizing: 'border-box',
minWidth: 88,
minWidth: theme.spacing.unit * 11,
minHeight: 36,
padding: `${theme.spacing.unit}px ${theme.spacing.unit * 2}px`,
borderRadius: 2,
@@ -33,12 +34,6 @@ export const styles = (theme: Object) => ({
},
},
},
dense: {
padding: `${theme.spacing.unit - 1}px ${theme.spacing.unit}px`,
minWidth: 64,
minHeight: 32,
fontSize: theme.typography.pxToRem(theme.typography.fontSize - 1),
},
label: {
width: '100%',
display: 'inherit',
@@ -46,29 +41,19 @@ export const styles = (theme: Object) => ({
justifyContent: 'inherit',
},
flatPrimary: {
color: theme.palette.primary[500],
color: theme.palette.primary.main,
'&:hover': {
backgroundColor: fade(theme.palette.primary[500], 0.12),
backgroundColor: fade(theme.palette.primary.main, 0.12),
// Reset on mouse devices
'@media (hover: none)': {
backgroundColor: 'transparent',
},
},
},
flatAccent: {
color: theme.palette.secondary.A200,
flatSecondary: {
color: theme.palette.secondary.main,
'&:hover': {
backgroundColor: fade(theme.palette.secondary.A200, 0.12),
// Reset on mouse devices
'@media (hover: none)': {
backgroundColor: 'transparent',
},
},
},
flatContrast: {
color: theme.palette.getContrastText(theme.palette.primary[500]),
'&:hover': {
backgroundColor: fade(theme.palette.getContrastText(theme.palette.primary[500]), 0.12),
backgroundColor: fade(theme.palette.secondary.main, 0.12),
// Reset on mouse devices
'@media (hover: none)': {
backgroundColor: 'transparent',
@@ -90,7 +75,7 @@ export const styles = (theme: Object) => ({
},
'&$disabled': {
boxShadow: theme.shadows[0],
backgroundColor: theme.palette.text.divider,
backgroundColor: theme.palette.action.disabledBackground,
},
'&:hover': {
backgroundColor: theme.palette.grey.A100,
@@ -99,40 +84,33 @@ export const styles = (theme: Object) => ({
backgroundColor: theme.palette.grey[300],
},
'&$disabled': {
backgroundColor: theme.palette.text.divider,
// Reset on mouse devices
'@media (hover: none)': {
backgroundColor: theme.palette.grey[300],
},
backgroundColor: theme.palette.action.disabledBackground,
},
},
},
keyboardFocused: {},
raisedPrimary: {
color: theme.palette.getContrastText(theme.palette.primary[500]),
backgroundColor: theme.palette.primary[500],
color: theme.palette.primary.contrastText,
backgroundColor: theme.palette.primary.main,
'&:hover': {
backgroundColor: theme.palette.primary[700],
backgroundColor: theme.palette.primary.dark,
// Reset on mouse devices
'@media (hover: none)': {
backgroundColor: theme.palette.primary[500],
backgroundColor: theme.palette.primary.main,
},
},
},
raisedAccent: {
color: theme.palette.getContrastText(theme.palette.secondary.A200),
backgroundColor: theme.palette.secondary.A200,
raisedSecondary: {
color: theme.palette.secondary.contrastText,
backgroundColor: theme.palette.secondary.main,
'&:hover': {
backgroundColor: theme.palette.secondary.A400,
backgroundColor: theme.palette.secondary.dark,
// Reset on mouse devices
'@media (hover: none)': {
backgroundColor: theme.palette.secondary.A200,
backgroundColor: theme.palette.secondary.main,
},
},
},
raisedContrast: {
color: theme.palette.getContrastText(theme.palette.primary[500]),
},
disabled: {
color: theme.palette.action.disabled,
},
@@ -141,120 +119,81 @@ export const styles = (theme: Object) => ({
padding: 0,
minWidth: 0,
width: 56,
fontSize: 24,
height: 56,
boxShadow: theme.shadows[6],
'&:active': {
boxShadow: theme.shadows[12],
},
},
mini: {
width: 40,
height: 40,
},
sizeSmall: {
padding: `${theme.spacing.unit - 1}px ${theme.spacing.unit}px`,
minWidth: theme.spacing.unit * 8,
minHeight: 32,
fontSize: theme.typography.pxToRem(theme.typography.fontSize - 1),
},
sizeLarge: {
padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
minWidth: theme.spacing.unit * 14,
minHeight: 40,
fontSize: theme.typography.pxToRem(theme.typography.fontSize + 1),
},
fullWidth: {
width: '100%',
},
});
export type Color = 'default' | 'inherit' | 'primary' | 'accent' | 'contrast';
type ProvidedProps = {
classes: Object,
color: Color,
dense: boolean,
disabled: boolean,
fab: boolean,
disableFocusRipple: boolean,
raised: boolean,
disableRipple: boolean,
type: string,
};
export type Props = {
/**
* The content of the button.
*/
children: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* The color of the component. It's using the theme palette when that makes sense.
*/
color?: Color,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
* The default value is a `button`.
*/
component?: ElementType,
/**
* Uses a smaller minWidth, ideal for things like card actions.
*/
dense?: boolean,
/**
* If `true`, the button will be disabled.
*/
disabled?: boolean,
/**
* If `true`, the keyboard focus ripple will be disabled.
* `disableRipple` must also be true.
*/
disableFocusRipple?: boolean,
/**
* If `true`, the ripple effect will be disabled.
*/
disableRipple?: boolean,
/**
* If `true`, will use floating action button styling.
*/
fab?: boolean,
/**
* The URL to link to when the button is clicked.
* If defined, an `a` element will be used as the root node.
*/
href?: string,
/**
* If `true`, the button will use raised styling.
*/
raised?: boolean,
/**
* @ignore
*/
type?: string,
};
function Button(props: ProvidedProps & Props) {
function Button(props) {
const {
children,
children: childrenProp,
classes,
className: classNameProp,
color,
dense,
disabled,
disableFocusRipple,
fab,
raised,
fullWidth,
mini,
size,
variant,
...other
} = props;
const fab = variant === 'fab';
const raised = variant === 'raised';
const flat = !raised && !fab;
const className = classNames(
classes.root,
{
[classes.root]: true,
[classes.raised]: raised || fab,
[classes.fab]: fab,
[classes.mini]: fab && mini,
[classes.colorInherit]: color === 'inherit',
[classes.flatPrimary]: flat && color === 'primary',
[classes.flatAccent]: flat && color === 'accent',
[classes.flatContrast]: flat && color === 'contrast',
[classes.flatSecondary]: flat && color === 'secondary',
[classes.raisedPrimary]: !flat && color === 'primary',
[classes.raisedAccent]: !flat && color === 'accent',
[classes.raisedContrast]: !flat && color === 'contrast',
[classes.dense]: dense,
[classes.raisedSecondary]: !flat && color === 'secondary',
[classes[`size${capitalize(size)}`]]: size !== 'medium',
[classes.disabled]: disabled,
[classes.fullWidth]: fullWidth,
},
classNameProp,
);
let children = childrenProp;
if (fab) {
children = React.Children.map(children, child => {
if (isMuiElement(child, ['Icon', 'SvgIcon'])) {
return React.cloneElement(child, { fontSize: true });
}
return child;
});
}
return (
<ButtonBase
className={className}
@@ -268,15 +207,80 @@ function Button(props: ProvidedProps & Props) {
);
}
Button.propTypes = {
/**
* The content of the button.
*/
children: PropTypes.node.isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The color of the component. It supports those theme colors that make sense for this component.
*/
color: PropTypes.oneOf(['default', 'inherit', 'primary', 'secondary']),
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
* The default value is a `button`.
*/
component: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
/**
* If `true`, the button will be disabled.
*/
disabled: PropTypes.bool,
/**
* If `true`, the keyboard focus ripple will be disabled.
* `disableRipple` must also be true.
*/
disableFocusRipple: PropTypes.bool,
/**
* If `true`, the ripple effect will be disabled.
*/
disableRipple: PropTypes.bool,
/**
* If `true`, the button will take up the full width of its container.
*/
fullWidth: PropTypes.bool,
/**
* The URL to link to when the button is clicked.
* If defined, an `a` element will be used as the root node.
*/
href: PropTypes.string,
/**
* If `true`, and `variant` is `'fab'`, will use mini floating action button styling.
*/
mini: PropTypes.bool,
/**
* The size of the button.
* `small` is equivalent to the dense button styling.
*/
size: PropTypes.oneOf(['small', 'medium', 'large']),
/**
* @ignore
*/
type: PropTypes.string,
/**
* The color of the component. It supports those theme colors that make sense for this component.
*/
variant: PropTypes.oneOf(['flat', 'raised', 'fab']),
};
Button.defaultProps = {
color: 'default',
dense: false,
disabled: false,
fab: false,
disableFocusRipple: false,
raised: false,
disableRipple: false,
fullWidth: false,
mini: false,
size: 'medium',
type: 'button',
variant: 'flat',
};
export default withStyles(styles, { name: 'MuiButton' })(Button);

View File

@@ -1,3 +1 @@
// @flow
export { default } from './Button';

View File

@@ -1,23 +1,21 @@
import * as React from 'react';
import { StandardProps, Replace } from '..';
import { StandardProps } from '..';
export interface ButtonBaseProps extends StandardProps<
Replace<React.AnchorHTMLAttributes<HTMLAnchorElement>, React.ButtonHTMLAttributes<HTMLButtonElement>>,
ButtonBaseClassKey
> {
export interface ButtonBaseProps
extends StandardProps<
React.AnchorHTMLAttributes<HTMLElement> & React.ButtonHTMLAttributes<HTMLElement>,
ButtonBaseClassKey
> {
buttonRef?: React.Ref<any>;
centerRipple?: boolean;
component?: React.ReactType;
component?: React.ReactType<ButtonBaseProps>;
disableRipple?: boolean;
focusRipple?: boolean;
keyboardFocusedClassName?: string;
onKeyboardFocus?: React.FocusEventHandler<any>;
rootRef?: React.Ref<any>;
}
export type ButtonBaseClassKey =
| 'root'
| 'disabled'
;
export type ButtonBaseClassKey = 'root' | 'disabled';
declare const ButtonBase: React.ComponentType<ButtonBaseProps>;

View File

@@ -41,6 +41,10 @@ var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _reactDom = require('react-dom');
var _classnames = require('classnames');
@@ -51,6 +55,10 @@ var _keycode = require('keycode');
var _keycode2 = _interopRequireDefault(_keycode);
var _ownerWindow = require('dom-helpers/ownerWindow');
var _ownerWindow2 = _interopRequireDefault(_ownerWindow);
var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
@@ -67,171 +75,43 @@ var _createRippleHandler2 = _interopRequireDefault(_createRippleHandler);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any; // weak
var babelPluginFlowReactPropTypes_proptype_ElementType = require('react').babelPluginFlowReactPropTypes_proptype_ElementType || require('prop-types').any;
var styles = exports.styles = function styles(theme) {
return {
root: {
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
position: 'relative',
// Remove grey highlight
WebkitTapHighlightColor: theme.palette.common.transparent,
backgroundColor: 'transparent', // Reset default value
outline: 'none',
border: 0,
borderRadius: 0,
cursor: 'pointer',
userSelect: 'none',
appearance: 'none',
textDecoration: 'none',
// So we take precedent over the style of a native <a /> element.
color: 'inherit',
'&::-moz-focus-inner': {
borderStyle: 'none' // Remove Firefox dotted outline.
}
},
disabled: {
pointerEvents: 'none', // Disable link interactions
cursor: 'default'
var styles = exports.styles = {
root: {
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
position: 'relative',
// Remove grey highlight
WebkitTapHighlightColor: 'transparent',
backgroundColor: 'transparent', // Reset default value
outline: 'none',
border: 0,
margin: 0, // Remove the margin in Safari
borderRadius: 0,
padding: 0, // Remove the padding in Firefox
cursor: 'pointer',
userSelect: 'none',
verticalAlign: 'middle',
'-moz-appearance': 'none', // Reset
'-webkit-appearance': 'none', // Reset
textDecoration: 'none',
// So we take precedent over the style of a native <a /> element.
color: 'inherit',
'&::-moz-focus-inner': {
borderStyle: 'none' // Remove Firefox dotted outline.
}
};
},
disabled: {
pointerEvents: 'none', // Disable link interactions
cursor: 'default'
}
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* If `true`, the ripples will be centered.
* They won't start at the cursor interaction position.
*/
centerRipple: require('prop-types').bool,
/**
* The content of the component.
*/
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
* The default value is a `button`.
*/
component: typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType),
/**
* If `true`, the base button will be disabled.
*/
disabled: require('prop-types').bool,
/**
* If `true`, the ripple effect will be disabled.
*/
disableRipple: require('prop-types').bool,
/**
* If `true`, the base button will have a keyboard focus ripple.
* `disableRipple` must also be `false`.
*/
focusRipple: require('prop-types').bool,
/**
* The CSS class applied while the component is keyboard focused.
*/
keyboardFocusedClassName: require('prop-types').string,
/**
* @ignore
*/
onBlur: require('prop-types').func,
/**
* @ignore
*/
onClick: require('prop-types').func,
/**
* @ignore
*/
onFocus: require('prop-types').func,
/**
* Callback fired when the component is focused with a keyboard.
* We trigger a `onFocus` callback too.
*/
onKeyboardFocus: require('prop-types').func,
/**
* @ignore
*/
onKeyDown: require('prop-types').func,
/**
* @ignore
*/
onKeyUp: require('prop-types').func,
/**
* @ignore
*/
onMouseDown: require('prop-types').func,
/**
* @ignore
*/
onMouseLeave: require('prop-types').func,
/**
* @ignore
*/
onMouseUp: require('prop-types').func,
/**
* @ignore
*/
onTouchEnd: require('prop-types').func,
/**
* @ignore
*/
onTouchMove: require('prop-types').func,
/**
* @ignore
*/
onTouchStart: require('prop-types').func,
/**
* @ignore
*/
role: require('prop-types').string,
/**
* Use that property to pass a ref callback to the root component.
*/
rootRef: require('prop-types').func,
/**
* @ignore
*/
tabIndex: require('prop-types').oneOfType([require('prop-types').number, require('prop-types').string]),
/**
* @ignore
*/
type: require('prop-types').string.isRequired
};
/**
* `ButtonBase` contains as few styles as possible.
* It aims to be a simple building block for creating a button.
* It contains a load of style reset and some focus/ripple logic.
*/
var ButtonBase = function (_React$Component) {
(0, _inherits3.default)(ButtonBase, _React$Component);
@@ -256,7 +136,9 @@ var ButtonBase = function (_React$Component) {
if (_this.props.onKeyboardFocus) {
_this.props.onKeyboardFocus(event);
}
}, _this.ripple = null, _this.keyDown = false, _this.button = null, _this.keyboardFocusTimeout = null, _this.keyboardFocusCheckTime = 30, _this.keyboardFocusMaxCheckTimes = 5, _this.handleKeyDown = function (event) {
}, _this.onRippleRef = function (node) {
_this.ripple = node;
}, _this.ripple = null, _this.keyDown = false, _this.button = null, _this.keyboardFocusTimeout = null, _this.keyboardFocusCheckTime = 50, _this.keyboardFocusMaxCheckTimes = 5, _this.handleKeyDown = function (event) {
var _this$props = _this.props,
component = _this$props.component,
focusRipple = _this$props.focusRipple,
@@ -266,7 +148,7 @@ var ButtonBase = function (_React$Component) {
var key = (0, _keycode2.default)(event);
// Check if key is already down to avoid repeats being counted as multiple activations
if (focusRipple && !_this.keyDown && _this.state.keyboardFocused && key === 'space') {
if (focusRipple && !_this.keyDown && _this.state.keyboardFocused && _this.ripple && key === 'space') {
_this.keyDown = true;
event.persist();
_this.ripple.stop(event, function () {
@@ -279,12 +161,14 @@ var ButtonBase = function (_React$Component) {
}
// Keyboard accessibility for non interactive elements
if (event.target === _this.button && onClick && component && component !== 'a' && component !== 'button' && (key === 'space' || key === 'enter')) {
if (event.target === event.currentTarget && component && component !== 'button' && (key === 'space' || key === 'enter')) {
event.preventDefault();
onClick(event);
if (onClick) {
onClick(event);
}
}
}, _this.handleKeyUp = function (event) {
if (_this.props.focusRipple && (0, _keycode2.default)(event) === 'space' && _this.state.keyboardFocused) {
if (_this.props.focusRipple && (0, _keycode2.default)(event) === 'space' && _this.ripple && _this.state.keyboardFocused) {
_this.keyDown = false;
event.persist();
_this.ripple.stop(event, function () {
@@ -319,8 +203,9 @@ var ButtonBase = function (_React$Component) {
}
event.persist();
var keyboardFocusCallback = _this.onKeyboardFocusHandler.bind(_this, event);
(0, _keyboardFocus.detectKeyboardFocus)(_this, _this.button, keyboardFocusCallback);
(0, _keyboardFocus.detectKeyboardFocus)(_this, _this.button, function () {
_this.onKeyboardFocusHandler(event);
});
if (_this.props.onFocus) {
_this.props.onFocus(event);
@@ -332,7 +217,18 @@ var ButtonBase = function (_React$Component) {
key: 'componentDidMount',
value: function componentDidMount() {
this.button = (0, _reactDom.findDOMNode)(this);
(0, _keyboardFocus.listenForFocusKeys)();
(0, _keyboardFocus.listenForFocusKeys)((0, _ownerWindow2.default)(this.button));
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
// The blur won't fire when the disabled state is set on a focused input.
// We need to book keep the focused state manually.
if (!this.props.disabled && nextProps.disabled && this.state.keyboardFocused) {
this.setState({
keyboardFocused: false
});
}
}
}, {
key: 'componentWillUpdate',
@@ -348,28 +244,13 @@ var ButtonBase = function (_React$Component) {
clearTimeout(this.keyboardFocusTimeout);
} // Used to help track keyboard activation keyDown
}, {
key: 'renderRipple',
value: function renderRipple() {
var _this2 = this;
if (!this.props.disableRipple && !this.props.disabled) {
return _react2.default.createElement(_TouchRipple2.default, {
innerRef: function innerRef(node) {
_this2.ripple = node;
},
center: this.props.centerRipple
});
}
return null;
}
}, {
key: 'render',
value: function render() {
var _classNames;
var _props = this.props,
buttonRef = _props.buttonRef,
centerRipple = _props.centerRipple,
children = _props.children,
classes = _props.classes,
@@ -390,10 +271,9 @@ var ButtonBase = function (_React$Component) {
onTouchEnd = _props.onTouchEnd,
onTouchMove = _props.onTouchMove,
onTouchStart = _props.onTouchStart,
rootRef = _props.rootRef,
tabIndex = _props.tabIndex,
type = _props.type,
other = (0, _objectWithoutProperties3.default)(_props, ['centerRipple', 'children', 'classes', 'className', 'component', 'disabled', 'disableRipple', 'focusRipple', 'keyboardFocusedClassName', 'onBlur', 'onFocus', 'onKeyboardFocus', 'onKeyDown', 'onKeyUp', 'onMouseDown', 'onMouseLeave', 'onMouseUp', 'onTouchEnd', 'onTouchMove', 'onTouchStart', 'rootRef', 'tabIndex', 'type']);
other = (0, _objectWithoutProperties3.default)(_props, ['buttonRef', 'centerRipple', 'children', 'classes', 'className', 'component', 'disabled', 'disableRipple', 'focusRipple', 'keyboardFocusedClassName', 'onBlur', 'onFocus', 'onKeyboardFocus', 'onKeyDown', 'onKeyUp', 'onMouseDown', 'onMouseLeave', 'onMouseUp', 'onTouchEnd', 'onTouchMove', 'onTouchStart', 'tabIndex', 'type']);
var className = (0, _classnames2.default)(classes.root, (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes.disabled, disabled), (0, _defineProperty3.default)(_classNames, keyboardFocusedClassName || '', this.state.keyboardFocused), _classNames), classNameProp);
@@ -412,11 +292,9 @@ var ButtonBase = function (_React$Component) {
if (ComponentProp === 'button') {
buttonProps.type = type || 'button';
}
if (ComponentProp !== 'a') {
buttonProps.role = buttonProps.role || 'button';
buttonProps.disabled = disabled;
} else {
buttonProps.role = 'button';
}
return _react2.default.createElement(
@@ -432,24 +310,132 @@ var ButtonBase = function (_React$Component) {
onTouchEnd: this.handleTouchEnd,
onTouchMove: this.handleTouchMove,
onTouchStart: this.handleTouchStart,
tabIndex: disabled ? -1 : tabIndex,
className: className
}, buttonProps, other, {
ref: rootRef
}),
tabIndex: disabled ? '-1' : tabIndex,
className: className,
ref: buttonRef
}, buttonProps, other),
children,
this.renderRipple()
!disableRipple && !disabled ? _react2.default.createElement(_TouchRipple2.default, { innerRef: this.onRippleRef, center: centerRipple }) : null
);
}
}]);
return ButtonBase;
}(_react2.default.Component);
ButtonBase.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* Use that property to pass a ref callback to the native button component.
*/
buttonRef: _propTypes2.default.func,
/**
* If `true`, the ripples will be centered.
* They won't start at the cursor interaction position.
*/
centerRipple: _propTypes2.default.bool,
/**
* The content of the component.
*/
children: _propTypes2.default.node,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
* The default value is a `button`.
*/
component: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func]),
/**
* If `true`, the base button will be disabled.
*/
disabled: _propTypes2.default.bool,
/**
* If `true`, the ripple effect will be disabled.
*/
disableRipple: _propTypes2.default.bool,
/**
* If `true`, the base button will have a keyboard focus ripple.
* `disableRipple` must also be `false`.
*/
focusRipple: _propTypes2.default.bool,
/**
* The CSS class applied while the component is keyboard focused.
*/
keyboardFocusedClassName: _propTypes2.default.string,
/**
* @ignore
*/
onBlur: _propTypes2.default.func,
/**
* @ignore
*/
onClick: _propTypes2.default.func,
/**
* @ignore
*/
onFocus: _propTypes2.default.func,
/**
* Callback fired when the component is focused with a keyboard.
* We trigger a `onFocus` callback too.
*/
onKeyboardFocus: _propTypes2.default.func,
/**
* @ignore
*/
onKeyDown: _propTypes2.default.func,
/**
* @ignore
*/
onKeyUp: _propTypes2.default.func,
/**
* @ignore
*/
onMouseDown: _propTypes2.default.func,
/**
* @ignore
*/
onMouseLeave: _propTypes2.default.func,
/**
* @ignore
*/
onMouseUp: _propTypes2.default.func,
/**
* @ignore
*/
onTouchEnd: _propTypes2.default.func,
/**
* @ignore
*/
onTouchMove: _propTypes2.default.func,
/**
* @ignore
*/
onTouchStart: _propTypes2.default.func,
/**
* @ignore
*/
role: _propTypes2.default.string,
/**
* @ignore
*/
tabIndex: _propTypes2.default.oneOfType([_propTypes2.default.number, _propTypes2.default.string]),
/**
* @ignore
*/
type: _propTypes2.default.string
} : {};
ButtonBase.defaultProps = {
centerRipple: false,
focusRipple: false,
disableRipple: false,
tabIndex: 0,
focusRipple: false,
tabIndex: '0',
type: 'button'
};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiButtonBase' })(ButtonBase);

View File

@@ -1,30 +1,33 @@
// @flow weak
import React from 'react';
import type { ElementType, Node } from 'react';
import PropTypes from 'prop-types';
import { findDOMNode } from 'react-dom';
import classNames from 'classnames';
import keycode from 'keycode';
import ownerWindow from 'dom-helpers/ownerWindow';
import withStyles from '../styles/withStyles';
import { listenForFocusKeys, detectKeyboardFocus, focusKeyPressed } from '../utils/keyboardFocus';
import TouchRipple from './TouchRipple';
import createRippleHandler from './createRippleHandler';
export const styles = (theme: Object) => ({
export const styles = {
root: {
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
position: 'relative',
// Remove grey highlight
WebkitTapHighlightColor: theme.palette.common.transparent,
WebkitTapHighlightColor: 'transparent',
backgroundColor: 'transparent', // Reset default value
outline: 'none',
border: 0,
margin: 0, // Remove the margin in Safari
borderRadius: 0,
padding: 0, // Remove the padding in Firefox
cursor: 'pointer',
userSelect: 'none',
appearance: 'none',
verticalAlign: 'middle',
'-moz-appearance': 'none', // Reset
'-webkit-appearance': 'none', // Reset
textDecoration: 'none',
// So we take precedent over the style of a native <a /> element.
color: 'inherit',
@@ -36,140 +39,31 @@ export const styles = (theme: Object) => ({
pointerEvents: 'none', // Disable link interactions
cursor: 'default',
},
});
type ProvidedProps = {
classes: Object,
};
export type Props = {
/**
* If `true`, the ripples will be centered.
* They won't start at the cursor interaction position.
*/
centerRipple?: boolean,
/**
* The content of the component.
*/
children?: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
* The default value is a `button`.
*/
component?: ElementType,
/**
* If `true`, the base button will be disabled.
*/
disabled?: boolean,
/**
* If `true`, the ripple effect will be disabled.
*/
disableRipple?: boolean,
/**
* If `true`, the base button will have a keyboard focus ripple.
* `disableRipple` must also be `false`.
*/
focusRipple?: boolean,
/**
* The CSS class applied while the component is keyboard focused.
*/
keyboardFocusedClassName?: string,
/**
* @ignore
*/
onBlur?: Function,
/**
* @ignore
*/
onClick?: Function,
/**
* @ignore
*/
onFocus?: Function,
/**
* Callback fired when the component is focused with a keyboard.
* We trigger a `onFocus` callback too.
*/
onKeyboardFocus?: (event: SyntheticEvent<>) => void,
/**
* @ignore
*/
onKeyDown?: Function,
/**
* @ignore
*/
onKeyUp?: Function,
/**
* @ignore
*/
onMouseDown?: Function,
/**
* @ignore
*/
onMouseLeave?: Function,
/**
* @ignore
*/
onMouseUp?: Function,
/**
* @ignore
*/
onTouchEnd?: Function,
/**
* @ignore
*/
onTouchMove?: Function,
/**
* @ignore
*/
onTouchStart?: Function,
/**
* @ignore
*/
role?: string,
/**
* Use that property to pass a ref callback to the root component.
*/
rootRef?: Function,
/**
* @ignore
*/
tabIndex?: number | string,
/**
* @ignore
*/
type: string,
};
type State = {
keyboardFocused: boolean,
};
class ButtonBase extends React.Component<ProvidedProps & Props, State> {
static defaultProps = {
centerRipple: false,
focusRipple: false,
disableRipple: false,
tabIndex: 0,
type: 'button',
};
/**
* `ButtonBase` contains as few styles as possible.
* It aims to be a simple building block for creating a button.
* It contains a load of style reset and some focus/ripple logic.
*/
class ButtonBase extends React.Component {
state = {
keyboardFocused: false,
};
componentDidMount() {
this.button = findDOMNode(this);
listenForFocusKeys();
listenForFocusKeys(ownerWindow(this.button));
}
componentWillReceiveProps(nextProps) {
// The blur won't fire when the disabled state is set on a focused input.
// We need to book keep the focused state manually.
if (!this.props.disabled && nextProps.disabled && this.state.keyboardFocused) {
this.setState({
keyboardFocused: false,
});
}
}
componentWillUpdate(nextProps, nextState) {
@@ -197,11 +91,15 @@ class ButtonBase extends React.Component<ProvidedProps & Props, State> {
}
};
onRippleRef = node => {
this.ripple = node;
};
ripple = null;
keyDown = false; // Used to help track keyboard activation keyDown
button = null;
keyboardFocusTimeout = null;
keyboardFocusCheckTime = 30;
keyboardFocusCheckTime = 50;
keyboardFocusMaxCheckTimes = 5;
handleKeyDown = event => {
@@ -209,7 +107,13 @@ class ButtonBase extends React.Component<ProvidedProps & Props, State> {
const key = keycode(event);
// Check if key is already down to avoid repeats being counted as multiple activations
if (focusRipple && !this.keyDown && this.state.keyboardFocused && key === 'space') {
if (
focusRipple &&
!this.keyDown &&
this.state.keyboardFocused &&
this.ripple &&
key === 'space'
) {
this.keyDown = true;
event.persist();
this.ripple.stop(event, () => {
@@ -223,20 +127,25 @@ class ButtonBase extends React.Component<ProvidedProps & Props, State> {
// Keyboard accessibility for non interactive elements
if (
event.target === this.button &&
onClick &&
event.target === event.currentTarget &&
component &&
component !== 'a' &&
component !== 'button' &&
(key === 'space' || key === 'enter')
) {
event.preventDefault();
onClick(event);
if (onClick) {
onClick(event);
}
}
};
handleKeyUp = event => {
if (this.props.focusRipple && keycode(event) === 'space' && this.state.keyboardFocused) {
if (
this.props.focusRipple &&
keycode(event) === 'space' &&
this.ripple &&
this.state.keyboardFocused
) {
this.keyDown = false;
event.persist();
this.ripple.stop(event, () => this.ripple.pulsate(event));
@@ -285,31 +194,18 @@ class ButtonBase extends React.Component<ProvidedProps & Props, State> {
}
event.persist();
const keyboardFocusCallback = this.onKeyboardFocusHandler.bind(this, event);
detectKeyboardFocus(this, this.button, keyboardFocusCallback);
detectKeyboardFocus(this, this.button, () => {
this.onKeyboardFocusHandler(event);
});
if (this.props.onFocus) {
this.props.onFocus(event);
}
};
renderRipple() {
if (!this.props.disableRipple && !this.props.disabled) {
return (
<TouchRipple
innerRef={node => {
this.ripple = node;
}}
center={this.props.centerRipple}
/>
);
}
return null;
}
render() {
const {
buttonRef,
centerRipple,
children,
classes,
@@ -330,7 +226,6 @@ class ButtonBase extends React.Component<ProvidedProps & Props, State> {
onTouchEnd,
onTouchMove,
onTouchStart,
rootRef,
tabIndex,
type,
...other
@@ -359,11 +254,9 @@ class ButtonBase extends React.Component<ProvidedProps & Props, State> {
if (ComponentProp === 'button') {
buttonProps.type = type || 'button';
}
if (ComponentProp !== 'a') {
buttonProps.role = buttonProps.role || 'button';
buttonProps.disabled = disabled;
} else {
buttonProps.role = 'button';
}
return (
@@ -378,17 +271,135 @@ class ButtonBase extends React.Component<ProvidedProps & Props, State> {
onTouchEnd={this.handleTouchEnd}
onTouchMove={this.handleTouchMove}
onTouchStart={this.handleTouchStart}
tabIndex={disabled ? -1 : tabIndex}
tabIndex={disabled ? '-1' : tabIndex}
className={className}
ref={buttonRef}
{...buttonProps}
{...other}
ref={rootRef}
>
{children}
{this.renderRipple()}
{!disableRipple && !disabled ? (
<TouchRipple innerRef={this.onRippleRef} center={centerRipple} />
) : null}
</ComponentProp>
);
}
}
ButtonBase.propTypes = {
/**
* Use that property to pass a ref callback to the native button component.
*/
buttonRef: PropTypes.func,
/**
* If `true`, the ripples will be centered.
* They won't start at the cursor interaction position.
*/
centerRipple: PropTypes.bool,
/**
* The content of the component.
*/
children: PropTypes.node,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
* The default value is a `button`.
*/
component: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
/**
* If `true`, the base button will be disabled.
*/
disabled: PropTypes.bool,
/**
* If `true`, the ripple effect will be disabled.
*/
disableRipple: PropTypes.bool,
/**
* If `true`, the base button will have a keyboard focus ripple.
* `disableRipple` must also be `false`.
*/
focusRipple: PropTypes.bool,
/**
* The CSS class applied while the component is keyboard focused.
*/
keyboardFocusedClassName: PropTypes.string,
/**
* @ignore
*/
onBlur: PropTypes.func,
/**
* @ignore
*/
onClick: PropTypes.func,
/**
* @ignore
*/
onFocus: PropTypes.func,
/**
* Callback fired when the component is focused with a keyboard.
* We trigger a `onFocus` callback too.
*/
onKeyboardFocus: PropTypes.func,
/**
* @ignore
*/
onKeyDown: PropTypes.func,
/**
* @ignore
*/
onKeyUp: PropTypes.func,
/**
* @ignore
*/
onMouseDown: PropTypes.func,
/**
* @ignore
*/
onMouseLeave: PropTypes.func,
/**
* @ignore
*/
onMouseUp: PropTypes.func,
/**
* @ignore
*/
onTouchEnd: PropTypes.func,
/**
* @ignore
*/
onTouchMove: PropTypes.func,
/**
* @ignore
*/
onTouchStart: PropTypes.func,
/**
* @ignore
*/
role: PropTypes.string,
/**
* @ignore
*/
tabIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
/**
* @ignore
*/
type: PropTypes.string,
};
ButtonBase.defaultProps = {
centerRipple: false,
disableRipple: false,
focusRipple: false,
tabIndex: '0',
type: 'button',
};
export default withStyles(styles, { name: 'MuiButtonBase' })(ButtonBase);

View File

@@ -40,6 +40,10 @@ var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
@@ -50,38 +54,6 @@ var _Transition2 = _interopRequireDefault(_Transition);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* If `true`, the ripple pulsates, typically indicating the keyboard focus state of an element.
*/
pulsate: require('prop-types').bool,
/**
* Diameter of the ripple.
*/
rippleSize: require('prop-types').number.isRequired,
/**
* Horizontal position of the ripple center.
*/
rippleX: require('prop-types').number.isRequired,
/**
* Vertical position of the ripple center.
*/
rippleY: require('prop-types').number.isRequired
}; // weak
/**
* @ignore - internal component.
*/
@@ -102,18 +74,6 @@ var Ripple = function (_React$Component) {
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = Ripple.__proto__ || (0, _getPrototypeOf2.default)(Ripple)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
rippleVisible: false,
rippleLeaving: false
}, _this.getRippleStyles = function (props) {
var rippleSize = props.rippleSize,
rippleX = props.rippleX,
rippleY = props.rippleY;
return {
width: rippleSize,
height: rippleSize,
top: -(rippleSize / 2) + rippleY,
left: -(rippleSize / 2) + rippleX
};
}, _this.handleEnter = function () {
_this.setState({
rippleVisible: true
@@ -147,13 +107,20 @@ var Ripple = function (_React$Component) {
var rippleClassName = (0, _classnames2.default)(classes.ripple, (_classNames2 = {}, (0, _defineProperty3.default)(_classNames2, classes.rippleVisible, rippleVisible), (0, _defineProperty3.default)(_classNames2, classes.rippleFast, pulsate), _classNames2));
var rippleStyles = {
width: rippleSize,
height: rippleSize,
top: -(rippleSize / 2) + rippleY,
left: -(rippleSize / 2) + rippleX
};
return _react2.default.createElement(
_Transition2.default,
(0, _extends3.default)({ onEnter: this.handleEnter, onExit: this.handleExit }, other),
_react2.default.createElement(
'span',
{ className: className },
_react2.default.createElement('span', { className: rippleClassName, style: this.getRippleStyles(this.props) })
_react2.default.createElement('span', { className: rippleClassName, style: rippleStyles })
)
);
}
@@ -161,7 +128,35 @@ var Ripple = function (_React$Component) {
return Ripple;
}(_react2.default.Component);
Ripple.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* If `true`, the ripple pulsates, typically indicating the keyboard focus state of an element.
*/
pulsate: _propTypes2.default.bool,
/**
* Diameter of the ripple.
*/
rippleSize: _propTypes2.default.number,
/**
* Horizontal position of the ripple center.
*/
rippleX: _propTypes2.default.number,
/**
* Vertical position of the ripple center.
*/
rippleY: _propTypes2.default.number
} : {};
Ripple.defaultProps = {
pulsate: false
};
exports.default = Ripple;

View File

@@ -1,66 +1,17 @@
// @flow weak
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Transition from 'react-transition-group/Transition';
type ProvidedProps = {
classes: Object,
};
export type Props = {
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* If `true`, the ripple pulsates, typically indicating the keyboard focus state of an element.
*/
pulsate?: boolean,
/**
* Diameter of the ripple.
*/
rippleSize: number,
/**
* Horizontal position of the ripple center.
*/
rippleX: number,
/**
* Vertical position of the ripple center.
*/
rippleY: number,
};
type State = { rippleVisible: boolean, rippleLeaving: boolean };
/**
* @ignore - internal component.
*/
class Ripple extends React.Component<ProvidedProps & Props, State> {
static defaultProps = {
pulsate: false,
};
class Ripple extends React.Component {
state = {
rippleVisible: false,
rippleLeaving: false,
};
getRippleStyles = props => {
const { rippleSize, rippleX, rippleY } = props;
return {
width: rippleSize,
height: rippleSize,
top: -(rippleSize / 2) + rippleY,
left: -(rippleSize / 2) + rippleX,
};
};
handleEnter = () => {
this.setState({
rippleVisible: true,
@@ -99,14 +50,52 @@ class Ripple extends React.Component<ProvidedProps & Props, State> {
[classes.rippleFast]: pulsate,
});
const rippleStyles = {
width: rippleSize,
height: rippleSize,
top: -(rippleSize / 2) + rippleY,
left: -(rippleSize / 2) + rippleX,
};
return (
<Transition onEnter={this.handleEnter} onExit={this.handleExit} {...other}>
<span className={className}>
<span className={rippleClassName} style={this.getRippleStyles(this.props)} />
<span className={rippleClassName} style={rippleStyles} />
</span>
</Transition>
);
}
}
Ripple.propTypes = {
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* If `true`, the ripple pulsates, typically indicating the keyboard focus state of an element.
*/
pulsate: PropTypes.bool,
/**
* Diameter of the ripple.
*/
rippleSize: PropTypes.number,
/**
* Horizontal position of the ripple center.
*/
rippleX: PropTypes.number,
/**
* Vertical position of the ripple center.
*/
rippleY: PropTypes.number,
};
Ripple.defaultProps = {
pulsate: false,
};
export default Ripple;

View File

@@ -0,0 +1,21 @@
import * as React from 'react';
import { TransitionGroup } from 'react-transition-group';
import { StandardProps } from '..';
export interface TouchRippleProps
extends StandardProps<TransitionGroup.TransitionGroupProps, TouchRippleClassKey> {
center?: boolean;
}
export type TouchRippleClassKey =
| 'root'
| 'wrapper'
| 'wrapperLeaving'
| 'wrapperPulsating'
| 'ripple'
| 'rippleVisible'
| 'rippleFast';
declare const TouchRipple: React.ComponentType<TouchRippleProps>;
export default TouchRipple;

View File

@@ -41,6 +41,10 @@ var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _reactDom = require('react-dom');
var _reactDom2 = _interopRequireDefault(_reactDom);
@@ -63,8 +67,6 @@ var _Ripple2 = _interopRequireDefault(_Ripple);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// weak
var DURATION = 550;
var DELAY_RIPPLE = exports.DELAY_RIPPLE = 80;
@@ -96,10 +98,7 @@ var styles = exports.styles = function styles(theme) {
display: 'block',
width: '100%',
height: '100%',
animation: 'mui-ripple-pulsate 1500ms ' + theme.transitions.easing.easeInOut + ' 200ms infinite',
rippleVisible: {
opacity: 0.2
}
animation: 'mui-ripple-pulsate 2500ms ' + theme.transitions.easing.easeInOut + ' 200ms infinite'
},
'@keyframes mui-ripple-enter': {
'0%': {
@@ -122,7 +121,7 @@ var styles = exports.styles = function styles(theme) {
transform: 'scale(1)'
},
'50%': {
transform: 'scale(0.9)'
transform: 'scale(0.92)'
},
'100%': {
transform: 'scale(1)'
@@ -149,27 +148,10 @@ var styles = exports.styles = function styles(theme) {
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* If `true`, the ripple starts at the center of the component
* rather than at the point of interaction.
*/
center: require('prop-types').bool,
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string
};
/**
* @ignore - internal component.
*/
var TouchRipple = function (_React$Component) {
(0, _inherits3.default)(TouchRipple, _React$Component);
@@ -211,8 +193,7 @@ var TouchRipple = function (_React$Component) {
}
var element = fakeElement ? null : _reactDom2.default.findDOMNode(_this);
var rect = element ? // $FlowFixMe
element.getBoundingClientRect() : {
var rect = element ? element.getBoundingClientRect() : {
width: 0,
height: 0,
left: 0,
@@ -242,12 +223,8 @@ var TouchRipple = function (_React$Component) {
rippleSize += 1;
}
} else {
var sizeX = Math.max(
// $FlowFixMe
Math.abs((element ? element.clientWidth : 0) - rippleX), rippleX) * 2 + 2;
var sizeY = Math.max(
// $FlowFixMe
Math.abs((element ? element.clientHeight : 0) - rippleY), rippleY) * 2 + 2;
var sizeX = Math.max(Math.abs((element ? element.clientWidth : 0) - rippleX), rippleX) * 2 + 2;
var sizeY = Math.max(Math.abs((element ? element.clientHeight : 0) - rippleY), rippleY) * 2 + 2;
rippleSize = Math.sqrt(Math.pow(sizeX, 2) + Math.pow(sizeY, 2));
}
@@ -274,7 +251,7 @@ var TouchRipple = function (_React$Component) {
var ripples = _this.state.ripples;
// Add a ripple to the ripples array
// Add a ripple to the ripples array.
ripples = [].concat((0, _toConsumableArray3.default)(ripples), [_react2.default.createElement(_Ripple2.default, {
key: _this.state.nextKey,
classes: _this.props.classes,
@@ -357,7 +334,24 @@ var TouchRipple = function (_React$Component) {
return TouchRipple;
}(_react2.default.Component);
TouchRipple.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* If `true`, the ripple starts at the center of the component
* rather than at the point of interaction.
*/
center: _propTypes2.default.bool,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string
} : {};
TouchRipple.defaultProps = {
center: false
};
exports.default = (0, _withStyles2.default)(styles, { flip: false, name: 'MuiTouchRipple' })(TouchRipple);

View File

@@ -1,6 +1,5 @@
// @flow weak
import React from 'react';
import PropTypes from 'prop-types';
import ReactDOM from 'react-dom';
import TransitionGroup from 'react-transition-group/TransitionGroup';
import classNames from 'classnames';
@@ -10,7 +9,7 @@ import Ripple from './Ripple';
const DURATION = 550;
export const DELAY_RIPPLE = 80;
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
display: 'block',
position: 'absolute',
@@ -37,10 +36,7 @@ export const styles = (theme: Object) => ({
display: 'block',
width: '100%',
height: '100%',
animation: `mui-ripple-pulsate 1500ms ${theme.transitions.easing.easeInOut} 200ms infinite`,
rippleVisible: {
opacity: 0.2,
},
animation: `mui-ripple-pulsate 2500ms ${theme.transitions.easing.easeInOut} 200ms infinite`,
},
'@keyframes mui-ripple-enter': {
'0%': {
@@ -63,7 +59,7 @@ export const styles = (theme: Object) => ({
transform: 'scale(1)',
},
'50%': {
transform: 'scale(0.9)',
transform: 'scale(0.92)',
},
'100%': {
transform: 'scale(1)',
@@ -89,36 +85,10 @@ export const styles = (theme: Object) => ({
},
});
type ProvidedProps = {
classes: Object,
};
export type Props = {
/**
* If `true`, the ripple starts at the center of the component
* rather than at the point of interaction.
*/
center?: boolean,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
};
type State = { nextKey: number, ripples: Array<*> };
/**
* @ignore - internal component.
*/
class TouchRipple extends React.Component<ProvidedProps & Props, State> {
static defaultProps = {
center: false,
};
class TouchRipple extends React.Component {
state = {
nextKey: 0,
ripples: [],
@@ -158,8 +128,7 @@ class TouchRipple extends React.Component<ProvidedProps & Props, State> {
const element = fakeElement ? null : ReactDOM.findDOMNode(this);
const rect = element
? // $FlowFixMe
element.getBoundingClientRect()
? element.getBoundingClientRect()
: {
width: 0,
height: 0,
@@ -195,21 +164,9 @@ class TouchRipple extends React.Component<ProvidedProps & Props, State> {
}
} else {
const sizeX =
Math.max(
// $FlowFixMe
Math.abs((element ? element.clientWidth : 0) - rippleX),
rippleX,
) *
2 +
2;
Math.max(Math.abs((element ? element.clientWidth : 0) - rippleX), rippleX) * 2 + 2;
const sizeY =
Math.max(
// $FlowFixMe
Math.abs((element ? element.clientHeight : 0) - rippleY),
rippleY,
) *
2 +
2;
Math.max(Math.abs((element ? element.clientHeight : 0) - rippleY), rippleY) * 2 + 2;
rippleSize = Math.sqrt(Math.pow(sizeX, 2) + Math.pow(sizeY, 2));
}
@@ -233,7 +190,7 @@ class TouchRipple extends React.Component<ProvidedProps & Props, State> {
const { pulsate, rippleX, rippleY, rippleSize, cb } = params;
let ripples = this.state.ripples;
// Add a ripple to the ripples array
// Add a ripple to the ripples array.
ripples = [
...ripples,
<Ripple
@@ -304,4 +261,24 @@ class TouchRipple extends React.Component<ProvidedProps & Props, State> {
}
}
TouchRipple.propTypes = {
/**
* If `true`, the ripple starts at the center of the component
* rather than at the point of interaction.
*/
center: PropTypes.bool,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
};
TouchRipple.defaultProps = {
center: false,
};
export default withStyles(styles, { flip: false, name: 'MuiTouchRipple' })(TouchRipple);

View File

@@ -1,7 +1,5 @@
// @flow
function createRippleHandler(instance: Object, eventName: string, action: string, cb: ?Function) {
return function handleEvent(event: SyntheticUIEvent<>) {
function createRippleHandler(instance, eventName, action, cb) {
return function handleEvent(event) {
if (cb) {
cb.call(instance, event);
}

View File

@@ -1,3 +1 @@
// @flow
export { default } from './ButtonBase';

File diff suppressed because it is too large Load Diff

View File

@@ -2,16 +2,11 @@ import * as React from 'react';
import { StandardProps } from '..';
import { PaperProps, PaperClassKey } from '../Paper';
export interface CardProps extends StandardProps<
PaperProps,
CardClassKey
> {
export interface CardProps extends StandardProps<PaperProps, CardClassKey> {
raised?: boolean;
}
export type CardClassKey =
| PaperClassKey
;
export type CardClassKey = PaperClassKey;
declare const Card: React.ComponentType<CardProps>;

View File

@@ -4,10 +4,6 @@ Object.defineProperty(exports, "__esModule", {
value: true
});
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
@@ -20,39 +16,35 @@ var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _Paper = require('../Paper');
var _Paper2 = _interopRequireDefault(_Paper);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// @inheritedComponent Paper
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* @ignore
*/
className: require('prop-types').string,
/**
* If `true`, the card will use raised styling.
*/
raised: require('prop-types').bool
};
function Card(props) {
var raised = props.raised,
other = (0, _objectWithoutProperties3.default)(props, ['raised']);
return _react2.default.createElement(_Paper2.default, (0, _extends3.default)({ elevation: raised ? 8 : 2 }, other));
}
} // @inheritedComponent Paper
Card.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* If `true`, the card will use raised styling.
*/
raised: _propTypes2.default.bool
} : {};
Card.propTypes = process.env.NODE_ENV !== "production" ? (0, _defineProperty3.default)({
raised: require('prop-types').bool.isRequired,
className: require('prop-types').string
}, 'raised', require('prop-types').bool) : {};
Card.defaultProps = {
raised: false
};

View File

@@ -1,30 +1,26 @@
// @flow
// @inheritedComponent Paper
import React from 'react';
import PropTypes from 'prop-types';
import Paper from '../Paper';
type ProvidedProps = {
raised: boolean,
};
export type Props = {
/**
* @ignore
*/
className?: string,
/**
* If `true`, the card will use raised styling.
*/
raised?: boolean,
};
function Card(props: ProvidedProps & Props) {
function Card(props) {
const { raised, ...other } = props;
return <Paper elevation={raised ? 8 : 2} {...other} />;
}
Card.propTypes = {
/**
* @ignore
*/
className: PropTypes.string,
/**
* If `true`, the card will use raised styling.
*/
raised: PropTypes.bool,
};
Card.defaultProps = {
raised: false,
};

View File

@@ -1,17 +1,12 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface CardActionsProps extends StandardProps<
React.HTMLAttributes<HTMLDivElement>,
CardActionClassKey
> {
export interface CardActionsProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, CardActionsClassKey> {
disableActionSpacing?: boolean;
}
export type CardActionClassKey =
| 'root'
| 'actionSpacing'
;
export type CardActionsClassKey = 'root' | 'action';
declare const CardActions: React.ComponentType<CardActionsProps>;

View File

@@ -5,10 +5,6 @@ Object.defineProperty(exports, "__esModule", {
});
exports.styles = undefined;
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
@@ -17,12 +13,14 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
@@ -35,43 +33,19 @@ var _reactHelpers = require('../utils/reactHelpers');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var styles = exports.styles = {
root: {
height: 52,
display: 'flex',
alignItems: 'center',
padding: '2px 4px'
padding: '2px 4px',
boxSizing: 'border-box'
},
actionSpacing: {
action: {
margin: '0 4px'
}
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The content of the component.
*/
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* If `true`, the card actions do not have additional margin.
*/
disableActionSpacing: require('prop-types').bool
};
function CardActions(props) {
var disableActionSpacing = props.disableActionSpacing,
children = props.children,
@@ -83,15 +57,29 @@ function CardActions(props) {
return _react2.default.createElement(
'div',
(0, _extends3.default)({ className: (0, _classnames2.default)(classes.root, className) }, other),
disableActionSpacing ? children : (0, _reactHelpers.cloneChildrenWithClassName)(children, classes.actionSpacing)
disableActionSpacing ? children : (0, _reactHelpers.cloneChildrenWithClassName)(children, classes.action)
);
}
CardActions.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
disableActionSpacing: require('prop-types').bool.isRequired,
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'disableActionSpacing', require('prop-types').bool), _ref) : {};
CardActions.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the component.
*/
children: _propTypes2.default.node,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* If `true`, the card actions do not have additional margin.
*/
disableActionSpacing: _propTypes2.default.bool
} : {};
CardActions.defaultProps = {
disableActionSpacing: false
};

View File

@@ -1,7 +1,5 @@
// @flow
import React from 'react';
import type { Node } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import { cloneChildrenWithClassName } from '../utils/reactHelpers';
@@ -12,48 +10,42 @@ export const styles = {
display: 'flex',
alignItems: 'center',
padding: '2px 4px',
boxSizing: 'border-box',
},
actionSpacing: {
action: {
margin: '0 4px',
},
};
type ProvidedProps = {
classes: Object,
disableActionSpacing: boolean,
};
export type Props = {
/**
* The content of the component.
*/
children?: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* If `true`, the card actions do not have additional margin.
*/
disableActionSpacing?: boolean,
};
function CardActions(props: ProvidedProps & Props) {
function CardActions(props) {
const { disableActionSpacing, children, classes, className, ...other } = props;
return (
<div className={classNames(classes.root, className)} {...other}>
{disableActionSpacing
? children
: cloneChildrenWithClassName(children, classes.actionSpacing)}
{disableActionSpacing ? children : cloneChildrenWithClassName(children, classes.action)}
</div>
);
}
CardActions.propTypes = {
/**
* The content of the component.
*/
children: PropTypes.node,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* If `true`, the card actions do not have additional margin.
*/
disableActionSpacing: PropTypes.bool,
};
CardActions.defaultProps = {
disableActionSpacing: false,
};

View File

@@ -1,14 +1,12 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface CardContentProps extends StandardProps<
React.HTMLAttributes<HTMLDivElement>,
CardContentClassKey
> {}
export interface CardContentProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, CardContentClassKey> {
component?: React.ReactType<CardContentProps>;
}
export type CardContentClassKey =
| 'root'
;
export type CardContentClassKey = 'root';
declare const CardContent: React.ComponentType<CardContentProps>;

View File

@@ -5,10 +5,6 @@ Object.defineProperty(exports, "__esModule", {
});
exports.styles = undefined;
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
@@ -17,12 +13,14 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
@@ -44,29 +42,34 @@ var styles = exports.styles = function styles(theme) {
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string
};
function CardContent(props) {
var classes = props.classes,
className = props.className,
other = (0, _objectWithoutProperties3.default)(props, ['classes', 'className']);
Component = props.component,
other = (0, _objectWithoutProperties3.default)(props, ['classes', 'className', 'component']);
return _react2.default.createElement('div', (0, _extends3.default)({ className: (0, _classnames2.default)(classes.root, className) }, other));
return _react2.default.createElement(Component, (0, _extends3.default)({ className: (0, _classnames2.default)(classes.root, className) }, other));
}
CardContent.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), _ref) : {};
CardContent.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func])
} : {};
CardContent.defaultProps = {
component: 'div'
};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiCardContent' })(CardContent);

View File

@@ -1,10 +1,9 @@
// @flow
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
padding: theme.spacing.unit * 2,
'&:last-child': {
@@ -13,25 +12,30 @@ export const styles = (theme: Object) => ({
},
});
type ProvidedProps = {
classes: Object,
};
function CardContent(props) {
const { classes, className, component: Component, ...other } = props;
export type Props = {
return <Component className={classNames(classes.root, className)} {...other} />;
}
CardContent.propTypes = {
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className?: string,
className: PropTypes.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
};
function CardContent(props: ProvidedProps & Props) {
const { classes, className, ...other } = props;
return <div className={classNames(classes.root, className)} {...other} />;
}
CardContent.defaultProps = {
component: 'div',
};
export default withStyles(styles, { name: 'MuiCardContent' })(CardContent);

View File

@@ -1,24 +1,17 @@
import * as React from 'react';
import { StandardProps } from '..';
import { CardContentProps, CardContentClassKey } from './CardContent';
import { CardContentProps } from './CardContent';
export interface CardHeaderProps extends StandardProps<
CardContentProps,
CardHeaderClassKey,
'title'
> {
export interface CardHeaderProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, CardHeaderClassKey, 'title'> {
action?: React.ReactNode;
avatar?: React.ReactNode;
component?: React.ReactType<CardHeaderProps>;
subheader?: React.ReactNode;
title?: React.ReactNode;
}
export type CardHeaderClassKey =
| CardContentClassKey
| 'avatar'
| 'content'
| 'title'
| 'subheader'
;
export type CardHeaderClassKey = 'root' | 'avatar' | 'action' | 'content' | 'title' | 'subheader';
declare const CardHeader: React.ComponentType<CardHeaderProps>;

View File

@@ -5,10 +5,6 @@ Object.defineProperty(exports, "__esModule", {
});
exports.styles = undefined;
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
@@ -17,13 +13,14 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref;
// @inheritedComponent CardContent
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
@@ -36,24 +33,25 @@ var _Typography = require('../Typography');
var _Typography2 = _interopRequireDefault(_Typography);
var _CardContent = require('./CardContent');
var _CardContent2 = _interopRequireDefault(_CardContent);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var styles = exports.styles = function styles(theme) {
return {
root: {
display: 'flex',
alignItems: 'center'
alignItems: 'center',
padding: theme.spacing.unit * 2
},
avatar: {
flex: '0 0 auto',
marginRight: theme.spacing.unit * 2
},
action: {
flex: '0 0 auto',
alignSelf: 'flex-start',
marginTop: theme.spacing.unit * -1,
marginRight: theme.spacing.unit * -2
},
content: {
flex: '1 1 auto'
},
@@ -62,52 +60,20 @@ var styles = exports.styles = function styles(theme) {
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The Avatar for the Card Header.
*/
avatar: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* The content of the component.
*/
subheader: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* The content of the Card Title.
*/
title: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)
};
function CardHeader(props) {
var avatar = props.avatar,
var action = props.action,
avatar = props.avatar,
classes = props.classes,
classNameProp = props.className,
Component = props.component,
subheader = props.subheader,
title = props.title,
other = (0, _objectWithoutProperties3.default)(props, ['avatar', 'classes', 'className', 'subheader', 'title']);
other = (0, _objectWithoutProperties3.default)(props, ['action', 'avatar', 'classes', 'className', 'component', 'subheader', 'title']);
var className = (0, _classnames2.default)(classes.root, classNameProp);
// Adjustments that depend on the presence of an avatar
var titleType = avatar ? 'body2' : 'headline';
var subheaderType = avatar ? 'body2' : 'body1';
return _react2.default.createElement(
_CardContent2.default,
(0, _extends3.default)({ className: className }, other),
Component,
(0, _extends3.default)({ className: (0, _classnames2.default)(classes.root, classNameProp) }, other),
avatar && _react2.default.createElement(
'div',
{ className: classes.avatar },
@@ -118,25 +84,66 @@ function CardHeader(props) {
{ className: classes.content },
_react2.default.createElement(
_Typography2.default,
{ type: titleType, component: 'span', className: classes.title },
{
variant: avatar ? 'body2' : 'headline',
component: 'span',
className: classes.title
},
title
),
_react2.default.createElement(
subheader && _react2.default.createElement(
_Typography2.default,
{
type: subheaderType,
variant: avatar ? 'body2' : 'body1',
component: 'span',
color: 'secondary',
color: 'textSecondary',
className: classes.subheader
},
subheader
)
),
action && _react2.default.createElement(
'div',
{ className: classes.action },
action
)
);
}
CardHeader.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
avatar: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'subheader', typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)), (0, _defineProperty3.default)(_ref, 'title', typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)), _ref) : {};
CardHeader.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The action to display in the card header.
*/
action: _propTypes2.default.node,
/**
* The Avatar for the Card Header.
*/
avatar: _propTypes2.default.node,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func]),
/**
* The content of the component.
*/
subheader: _propTypes2.default.node,
/**
* The content of the Card Title.
*/
title: _propTypes2.default.node
} : {};
CardHeader.defaultProps = {
component: 'div'
};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiCardHeader' })(CardHeader);

View File

@@ -1,22 +1,25 @@
// @flow
// @inheritedComponent CardContent
import React from 'react';
import type { Node } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import Typography from '../Typography';
import CardContent from './CardContent';
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
display: 'flex',
alignItems: 'center',
padding: theme.spacing.unit * 2,
},
avatar: {
flex: '0 0 auto',
marginRight: theme.spacing.unit * 2,
},
action: {
flex: '0 0 auto',
alignSelf: 'flex-start',
marginTop: theme.spacing.unit * -1,
marginRight: theme.spacing.unit * -2,
},
content: {
flex: '1 1 auto',
},
@@ -24,60 +27,79 @@ export const styles = (theme: Object) => ({
subheader: {},
});
type ProvidedProps = {
classes: Object,
};
export type Props = {
/**
* The Avatar for the Card Header.
*/
avatar?: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* The content of the component.
*/
subheader?: Node,
/**
* The content of the Card Title.
*/
title?: Node,
};
function CardHeader(props: ProvidedProps & Props) {
const { avatar, classes, className: classNameProp, subheader, title, ...other } = props;
const className = classNames(classes.root, classNameProp);
// Adjustments that depend on the presence of an avatar
const titleType = avatar ? 'body2' : 'headline';
const subheaderType = avatar ? 'body2' : 'body1';
function CardHeader(props) {
const {
action,
avatar,
classes,
className: classNameProp,
component: Component,
subheader,
title,
...other
} = props;
return (
<CardContent className={className} {...other}>
<Component className={classNames(classes.root, classNameProp)} {...other}>
{avatar && <div className={classes.avatar}>{avatar}</div>}
<div className={classes.content}>
<Typography type={titleType} component="span" className={classes.title}>
<Typography
variant={avatar ? 'body2' : 'headline'}
component="span"
className={classes.title}
>
{title}
</Typography>
<Typography
type={subheaderType}
component="span"
color="secondary"
className={classes.subheader}
>
{subheader}
</Typography>
{subheader && (
<Typography
variant={avatar ? 'body2' : 'body1'}
component="span"
color="textSecondary"
className={classes.subheader}
>
{subheader}
</Typography>
)}
</div>
</CardContent>
{action && <div className={classes.action}>{action}</div>}
</Component>
);
}
CardHeader.propTypes = {
/**
* The action to display in the card header.
*/
action: PropTypes.node,
/**
* The Avatar for the Card Header.
*/
avatar: PropTypes.node,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
/**
* The content of the component.
*/
subheader: PropTypes.node,
/**
* The content of the Card Title.
*/
title: PropTypes.node,
};
CardHeader.defaultProps = {
component: 'div',
};
export default withStyles(styles, { name: 'MuiCardHeader' })(CardHeader);

View File

@@ -1,18 +1,14 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface CardMediaProps extends StandardProps<
React.HTMLAttributes<HTMLDivElement>,
CardMediaClassKey
> {
export interface CardMediaProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, CardMediaClassKey> {
component?: React.ReactType<CardMediaProps>;
image?: string;
src?: string;
component?: React.ReactType;
}
export type CardMediaClassKey =
| 'root'
;
export type CardMediaClassKey = 'root';
declare const CardMedia: React.ComponentType<CardMediaProps>;

View File

@@ -17,12 +17,14 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
@@ -37,8 +39,6 @@ var _withStyles2 = _interopRequireDefault(_withStyles);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_ElementType = require('react').babelPluginFlowReactPropTypes_proptype_ElementType || require('prop-types').any;
var styles = exports.styles = {
root: {
backgroundSize: 'cover',
@@ -50,74 +50,65 @@ var styles = exports.styles = {
}
};
var mediaComponents = ['video', 'audio', 'picture', 'iframe', 'img'];
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* Image to be displayed as a background image.
* Either `image` or `src` prop must be specified.
* Note that caller must specify height otherwise the image will not be visible.
*/
image: require('prop-types').string,
/**
* An alias for `image` property.
* Available only with media components.
* Media components: `video`, `audio`, `picture`, `iframe`, `img`.
*/
src: require('prop-types').string,
/**
* @ignore
*/
style: require('prop-types').object,
/**
* Component for rendering image.
*/
component: typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType)
};
var MEDIA_COMPONENTS = ['video', 'audio', 'picture', 'iframe', 'img'];
function CardMedia(props) {
var _classNames;
var classes = props.classes,
className = props.className,
Component = props.component,
image = props.image,
style = props.style,
src = props.src,
ComponentProp = props.component,
other = (0, _objectWithoutProperties3.default)(props, ['classes', 'className', 'image', 'style', 'src', 'component']);
style = props.style,
other = (0, _objectWithoutProperties3.default)(props, ['classes', 'className', 'component', 'image', 'src', 'style']);
process.env.NODE_ENV !== "production" ? (0, _warning2.default)(Boolean(image || src), 'Material-UI: either `image` or `src` property must be specified.') : void 0;
var isMediaComponent = mediaComponents.indexOf(ComponentProp) !== -1;
var isMediaComponent = MEDIA_COMPONENTS.indexOf(Component) !== -1;
var composedStyle = !isMediaComponent && image ? (0, _extends3.default)({ backgroundImage: 'url(' + image + ')' }, style) : style;
var composedClassName = (0, _classnames2.default)((_classNames = {}, (0, _defineProperty3.default)(_classNames, classes.root, !isMediaComponent), (0, _defineProperty3.default)(_classNames, classes.rootMedia, isMediaComponent), _classNames), className);
return _react2.default.createElement(ComponentProp, (0, _extends3.default)({
return _react2.default.createElement(Component, (0, _extends3.default)({
className: composedClassName,
style: composedStyle,
src: isMediaComponent ? image || src : undefined
}, other));
}
CardMedia.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
component: typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType.isRequired ? babelPluginFlowReactPropTypes_proptype_ElementType.isRequired : babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType).isRequired
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'image', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'src', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'style', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'component', typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType)), _ref) : {};
CardMedia.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* Component for rendering image.
* Either a string to use a DOM element or a component.
*/
component: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func]),
/**
* Image to be displayed as a background image.
* Either `image` or `src` prop must be specified.
* Note that caller must specify height otherwise the image will not be visible.
*/
image: _propTypes2.default.string,
/**
* An alias for `image` property.
* Available only with media components.
* Media components: `video`, `audio`, `picture`, `iframe`, `img`.
*/
src: _propTypes2.default.string,
/**
* @ignore
*/
style: _propTypes2.default.object
} : {};
CardMedia.defaultProps = {
component: 'div'
};

View File

@@ -1,9 +1,7 @@
// @flow
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import warning from 'warning';
import type { ElementType } from 'react';
import withStyles from '../styles/withStyles';
export const styles = {
@@ -17,53 +15,17 @@ export const styles = {
},
};
const mediaComponents = ['video', 'audio', 'picture', 'iframe', 'img'];
const MEDIA_COMPONENTS = ['video', 'audio', 'picture', 'iframe', 'img'];
type ProvidedProps = {
classes: Object,
component: ElementType,
};
export type Props = {
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* Image to be displayed as a background image.
* Either `image` or `src` prop must be specified.
* Note that caller must specify height otherwise the image will not be visible.
*/
image?: string,
/**
* An alias for `image` property.
* Available only with media components.
* Media components: `video`, `audio`, `picture`, `iframe`, `img`.
*/
src?: string,
/**
* @ignore
*/
style?: Object,
/**
* Component for rendering image.
*/
component?: ElementType,
};
function CardMedia(props: ProvidedProps & Props) {
const { classes, className, image, style, src, component: ComponentProp, ...other } = props;
function CardMedia(props) {
const { classes, className, component: Component, image, src, style, ...other } = props;
warning(
Boolean(image || src),
'Material-UI: either `image` or `src` property must be specified.',
);
const isMediaComponent = mediaComponents.indexOf(ComponentProp) !== -1;
const isMediaComponent = MEDIA_COMPONENTS.indexOf(Component) !== -1;
const composedStyle =
!isMediaComponent && image ? { backgroundImage: `url(${image})`, ...style } : style;
const composedClassName = classNames(
@@ -75,7 +37,7 @@ function CardMedia(props: ProvidedProps & Props) {
);
return (
<ComponentProp
<Component
className={composedClassName}
style={composedStyle}
src={isMediaComponent ? image || src : undefined}
@@ -84,6 +46,38 @@ function CardMedia(props: ProvidedProps & Props) {
);
}
CardMedia.propTypes = {
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* Component for rendering image.
* Either a string to use a DOM element or a component.
*/
component: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
/**
* Image to be displayed as a background image.
* Either `image` or `src` prop must be specified.
* Note that caller must specify height otherwise the image will not be visible.
*/
image: PropTypes.string,
/**
* An alias for `image` property.
* Available only with media components.
* Media components: `video`, `audio`, `picture`, `iframe`, `img`.
*/
src: PropTypes.string,
/**
* @ignore
*/
style: PropTypes.object,
};
CardMedia.defaultProps = {
component: 'div',
};

View File

@@ -1,5 +1,3 @@
// @flow
export { default } from './Card';
export { default as CardContent } from './CardContent';
export { default as CardActions } from './CardActions';

View File

@@ -2,14 +2,9 @@ import * as React from 'react';
import { StandardProps } from '..';
import { SwitchBaseProps, SwitchBaseClassKey } from '../internal/SwitchBase';
export interface CheckboxProps extends StandardProps<
SwitchBaseProps,
CheckboxClassKey
> {}
export interface CheckboxProps extends StandardProps<SwitchBaseProps, CheckboxClassKey> {}
export type CheckboxClassKey =
| SwitchBaseClassKey
;
export type CheckboxClassKey = SwitchBaseClassKey;
declare const Checkbox: React.ComponentType<CheckboxProps>;

View File

@@ -5,47 +5,55 @@ Object.defineProperty(exports, "__esModule", {
});
exports.styles = undefined;
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _withStyles = require('../styles/withStyles');
var _propTypes = require('prop-types');
var _withStyles2 = _interopRequireDefault(_withStyles);
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _SwitchBase = require('../internal/SwitchBase');
var _SwitchBase2 = _interopRequireDefault(_SwitchBase);
var _IndeterminateCheckBox = require('../svg-icons/IndeterminateCheckBox');
var _IndeterminateCheckBox = require('../internal/svg-icons/IndeterminateCheckBox');
var _IndeterminateCheckBox2 = _interopRequireDefault(_IndeterminateCheckBox);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _withStyles = require('../styles/withStyles');
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var _withStyles2 = _interopRequireDefault(_withStyles);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var styles = exports.styles = function styles(theme) {
return {
default: {
color: theme.palette.text.secondary
},
checked: {
color: theme.palette.primary[500]
checked: {},
checkedPrimary: {
color: theme.palette.primary.main
},
checkedSecondary: {
color: theme.palette.secondary.main
},
disabled: {
color: theme.palette.action.disabled
@@ -53,128 +61,98 @@ var styles = exports.styles = function styles(theme) {
};
};
var SwitchBase = (0, _SwitchBase2.default)();
function Checkbox(props) {
var _classNames;
var babelPluginFlowReactPropTypes_proptype_Props = {
var checkedIcon = props.checkedIcon,
classes = props.classes,
color = props.color,
icon = props.icon,
indeterminate = props.indeterminate,
indeterminateIcon = props.indeterminateIcon,
other = (0, _objectWithoutProperties3.default)(props, ['checkedIcon', 'classes', 'color', 'icon', 'indeterminate', 'indeterminateIcon']);
var checkedClass = (0, _classnames2.default)(classes.checked, (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes.checkedPrimary, color === 'primary'), (0, _defineProperty3.default)(_classNames, classes.checkedSecondary, color === 'secondary'), _classNames));
return _react2.default.createElement(_SwitchBase2.default, (0, _extends3.default)({
checkedIcon: indeterminate ? indeterminateIcon : checkedIcon,
classes: {
default: classes.default,
checked: checkedClass,
disabled: classes.disabled
},
icon: indeterminate ? indeterminateIcon : icon
}, other));
}
Checkbox.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* If `true`, the component is checked.
*/
checked: require('prop-types').oneOfType([require('prop-types').bool, require('prop-types').string]),
/**
* The CSS class name of the root element when checked.
*/
checkedClassName: require('prop-types').string,
checked: _propTypes2.default.oneOfType([_propTypes2.default.bool, _propTypes2.default.string]),
/**
* The icon to display when the component is checked.
* If a string is provided, it will be used as a font ligature.
*/
checkedIcon: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
checkedIcon: _propTypes2.default.node,
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
* The color of the component. It supports those theme colors that make sense for this component.
*/
className: require('prop-types').string,
/**
* @ignore
*/
defaultChecked: require('prop-types').bool,
color: _propTypes2.default.oneOf(['primary', 'secondary']),
/**
* If `true`, the switch will be disabled.
*/
disabled: require('prop-types').bool,
/**
* The CSS class name of the root element when disabled.
*/
disabledClassName: require('prop-types').string,
disabled: _propTypes2.default.bool,
/**
* If `true`, the ripple effect will be disabled.
*/
disableRipple: require('prop-types').bool,
disableRipple: _propTypes2.default.bool,
/**
* The icon to display when the component is unchecked.
* If a string is provided, it will be used as a font ligature.
*/
icon: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
icon: _propTypes2.default.node,
/**
* The id of the `input` element.
*/
id: _propTypes2.default.string,
/**
* If `true`, the component appears indeterminate.
*/
indeterminate: require('prop-types').bool,
indeterminate: _propTypes2.default.bool,
/**
* The icon to display when the component is indeterminate.
* If a string is provided, it will be used as a font ligature.
*/
indeterminateIcon: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
indeterminateIcon: _propTypes2.default.node,
/**
* Properties applied to the `input` element.
*/
inputProps: require('prop-types').object,
inputProps: _propTypes2.default.object,
/**
* Use that property to pass a ref callback to the native input component.
*/
inputRef: require('prop-types').func,
/*
* @ignore
*/
name: require('prop-types').string,
inputRef: _propTypes2.default.func,
/**
* Callback fired when the state is changed.
*
* @param {object} event The event source of the callback
* @param {boolean} checked The `checked` value of the switch
*/
onChange: require('prop-types').func,
onChange: _propTypes2.default.func,
/**
* @ignore
* The input component property `type`.
*/
tabIndex: require('prop-types').oneOfType([require('prop-types').number, require('prop-types').string]),
type: _propTypes2.default.string,
/**
* The value of the component.
*/
value: require('prop-types').string
};
value: _propTypes2.default.string
} : {};
function Checkbox(props) {
var checkedIcon = props.checkedIcon,
icon = props.icon,
indeterminate = props.indeterminate,
indeterminateIcon = props.indeterminateIcon,
other = (0, _objectWithoutProperties3.default)(props, ['checkedIcon', 'icon', 'indeterminate', 'indeterminateIcon']);
return _react2.default.createElement(SwitchBase, (0, _extends3.default)({
checkedIcon: indeterminate ? indeterminateIcon : checkedIcon,
icon: indeterminate ? indeterminateIcon : icon
}, other));
}
Checkbox.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
checked: require('prop-types').oneOfType([require('prop-types').bool, require('prop-types').string]),
checkedClassName: require('prop-types').string,
checkedIcon: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'defaultChecked', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'disabled', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'disabledClassName', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'disableRipple', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'icon', typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)), (0, _defineProperty3.default)(_ref, 'indeterminate', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'indeterminateIcon', typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)), (0, _defineProperty3.default)(_ref, 'inputProps', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'inputRef', require('prop-types').func), (0, _defineProperty3.default)(_ref, 'name', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'onChange', require('prop-types').func), (0, _defineProperty3.default)(_ref, 'tabIndex', require('prop-types').oneOfType([require('prop-types').number, require('prop-types').string])), (0, _defineProperty3.default)(_ref, 'value', require('prop-types').string), _ref) : {};
Checkbox.defaultProps = {
color: 'secondary',
indeterminate: false,
indeterminateIcon: _react2.default.createElement(_IndeterminateCheckBox2.default, null)
};

View File

@@ -1,123 +1,115 @@
// @flow
import React from 'react';
import type { Node } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import SwitchBase from '../internal/SwitchBase';
import IndeterminateCheckBoxIcon from '../internal/svg-icons/IndeterminateCheckBox';
import withStyles from '../styles/withStyles';
import createSwitch from '../internal/SwitchBase';
import IndeterminateCheckBoxIcon from '../svg-icons/IndeterminateCheckBox';
export const styles = (theme: Object) => ({
export const styles = theme => ({
default: {
color: theme.palette.text.secondary,
},
checked: {
color: theme.palette.primary[500],
checked: {},
checkedPrimary: {
color: theme.palette.primary.main,
},
checkedSecondary: {
color: theme.palette.secondary.main,
},
disabled: {
color: theme.palette.action.disabled,
},
});
const SwitchBase = createSwitch();
type ProvidedProps = {
classes: Object,
};
export type Props = {
/**
* If `true`, the component is checked.
*/
checked?: boolean | string,
/**
* The CSS class name of the root element when checked.
*/
checkedClassName?: string,
/**
* The icon to display when the component is checked.
* If a string is provided, it will be used as a font ligature.
*/
checkedIcon?: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* @ignore
*/
defaultChecked?: boolean,
/**
* If `true`, the switch will be disabled.
*/
disabled?: boolean,
/**
* The CSS class name of the root element when disabled.
*/
disabledClassName?: string,
/**
* If `true`, the ripple effect will be disabled.
*/
disableRipple?: boolean,
/**
* The icon to display when the component is unchecked.
* If a string is provided, it will be used as a font ligature.
*/
icon?: Node,
/**
* If `true`, the component appears indeterminate.
*/
indeterminate?: boolean,
/**
* The icon to display when the component is indeterminate.
* If a string is provided, it will be used as a font ligature.
*/
indeterminateIcon?: Node,
/**
* Properties applied to the `input` element.
*/
inputProps?: Object,
/**
* Use that property to pass a ref callback to the native input component.
*/
inputRef?: Function,
/*
* @ignore
*/
name?: string,
/**
* Callback fired when the state is changed.
*
* @param {object} event The event source of the callback
* @param {boolean} checked The `checked` value of the switch
*/
onChange?: Function,
/**
* @ignore
*/
tabIndex?: number | string,
/**
* The value of the component.
*/
value?: string,
};
function Checkbox(props: ProvidedProps & Props) {
const { checkedIcon, icon, indeterminate, indeterminateIcon, ...other } = props;
function Checkbox(props) {
const { checkedIcon, classes, color, icon, indeterminate, indeterminateIcon, ...other } = props;
const checkedClass = classNames(classes.checked, {
[classes.checkedPrimary]: color === 'primary',
[classes.checkedSecondary]: color === 'secondary',
});
return (
<SwitchBase
checkedIcon={indeterminate ? indeterminateIcon : checkedIcon}
classes={{
default: classes.default,
checked: checkedClass,
disabled: classes.disabled,
}}
icon={indeterminate ? indeterminateIcon : icon}
{...other}
/>
);
}
Checkbox.propTypes = {
/**
* If `true`, the component is checked.
*/
checked: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
/**
* The icon to display when the component is checked.
*/
checkedIcon: PropTypes.node,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* The color of the component. It supports those theme colors that make sense for this component.
*/
color: PropTypes.oneOf(['primary', 'secondary']),
/**
* If `true`, the switch will be disabled.
*/
disabled: PropTypes.bool,
/**
* If `true`, the ripple effect will be disabled.
*/
disableRipple: PropTypes.bool,
/**
* The icon to display when the component is unchecked.
*/
icon: PropTypes.node,
/**
* The id of the `input` element.
*/
id: PropTypes.string,
/**
* If `true`, the component appears indeterminate.
*/
indeterminate: PropTypes.bool,
/**
* The icon to display when the component is indeterminate.
*/
indeterminateIcon: PropTypes.node,
/**
* Properties applied to the `input` element.
*/
inputProps: PropTypes.object,
/**
* Use that property to pass a ref callback to the native input component.
*/
inputRef: PropTypes.func,
/**
* Callback fired when the state is changed.
*
* @param {object} event The event source of the callback
* @param {boolean} checked The `checked` value of the switch
*/
onChange: PropTypes.func,
/**
* The input component property `type`.
*/
type: PropTypes.string,
/**
* The value of the component.
*/
value: PropTypes.string,
};
Checkbox.defaultProps = {
color: 'secondary',
indeterminate: false,
indeterminateIcon: <IndeterminateCheckBoxIcon />,
};

View File

@@ -1,3 +1 @@
// @flow
export { default } from './Checkbox';

View File

@@ -1,15 +1,14 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface ChipProps extends StandardProps<
React.HTMLAttributes<HTMLDivElement>,
ChipClassKey
> {
export interface ChipProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, ChipClassKey> {
avatar?: React.ReactElement<any>;
label?: React.ReactNode;
onKeyDown?: React.EventHandler<React.KeyboardEvent<any>>;
onRequestDelete?: React.EventHandler<any>;
component?: React.ReactType<ChipProps>;
deleteIcon?: React.ReactElement<any>;
label?: React.ReactNode;
onDelete?: React.EventHandler<any>;
onKeyDown?: React.EventHandler<React.KeyboardEvent<any>>;
}
export type ChipClassKey =
@@ -19,8 +18,7 @@ export type ChipClassKey =
| 'avatar'
| 'avatarChildren'
| 'label'
| 'deleteIcon'
;
| 'deleteIcon';
declare const Chip: React.ComponentType<ChipProps>;

View File

@@ -41,6 +41,10 @@ var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
@@ -49,36 +53,32 @@ var _keycode = require('keycode');
var _keycode2 = _interopRequireDefault(_keycode);
var _Cancel = require('../internal/svg-icons/Cancel');
var _Cancel2 = _interopRequireDefault(_Cancel);
var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
var _Cancel = require('../svg-icons/Cancel');
var _Cancel2 = _interopRequireDefault(_Cancel);
var _colorManipulator = require('../styles/colorManipulator');
var _Avatar = require('../Avatar/Avatar');
var _Avatar2 = _interopRequireDefault(_Avatar);
require('../Avatar/Avatar');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var babelPluginFlowReactPropTypes_proptype_Element = require('react').babelPluginFlowReactPropTypes_proptype_Element || require('prop-types').any;
// So we don't have any override priority issue.
var styles = exports.styles = function styles(theme) {
var height = 32;
var backgroundColor = (0, _colorManipulator.emphasize)(theme.palette.background.default, 0.12);
var backgroundColor = theme.palette.type === 'light' ? theme.palette.grey[300] : theme.palette.grey[700];
var deleteIconColor = (0, _colorManipulator.fade)(theme.palette.text.primary, 0.26);
return {
root: {
fontFamily: theme.typography.fontFamily,
fontSize: theme.typography.pxToRem(13),
display: 'flex',
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
height: height,
@@ -86,7 +86,6 @@ var styles = exports.styles = function styles(theme) {
backgroundColor: backgroundColor,
borderRadius: height / 2,
whiteSpace: 'nowrap',
width: 'fit-content',
transition: theme.transitions.create(),
// label will inherit this from root, then `clickable` class overrides this for both
cursor: 'default',
@@ -96,7 +95,7 @@ var styles = exports.styles = function styles(theme) {
},
clickable: {
// Remove grey highlight
WebkitTapHighlightColor: theme.palette.common.transparent,
WebkitTapHighlightColor: 'transparent',
cursor: 'pointer',
'&:hover, &:focus': {
backgroundColor: (0, _colorManipulator.emphasize)(backgroundColor, 0.08)
@@ -113,8 +112,9 @@ var styles = exports.styles = function styles(theme) {
},
avatar: {
marginRight: -4,
width: 32,
height: 32,
width: height,
height: height,
color: theme.palette.type === 'light' ? theme.palette.grey[700] : theme.palette.grey[300],
fontSize: theme.typography.pxToRem(16)
},
avatarChildren: {
@@ -132,7 +132,7 @@ var styles = exports.styles = function styles(theme) {
},
deleteIcon: {
// Remove grey highlight
WebkitTapHighlightColor: theme.palette.common.transparent,
WebkitTapHighlightColor: 'transparent',
color: deleteIconColor,
cursor: 'pointer',
height: 'auto',
@@ -144,57 +144,10 @@ var styles = exports.styles = function styles(theme) {
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* Avatar element.
*/
avatar: typeof babelPluginFlowReactPropTypes_proptype_Element === 'function' ? babelPluginFlowReactPropTypes_proptype_Element : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Element),
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* Custom delete icon. Will be shown only if `onRequestDelete` is set.
*/
deleteIcon: typeof babelPluginFlowReactPropTypes_proptype_Element === 'function' ? babelPluginFlowReactPropTypes_proptype_Element : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Element),
/**
* The content of the label.
*/
label: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* @ignore
*/
onClick: require('prop-types').func,
/**
* @ignore
*/
onKeyDown: require('prop-types').func,
/**
* Callback function fired when the delete icon is clicked.
* If set, the delete icon will be shown.
*/
onRequestDelete: require('prop-types').func,
/**
* @ignore
*/
tabIndex: require('prop-types').oneOfType([require('prop-types').number, require('prop-types').string])
};
/**
* Chips represent complex entities in small blocks, such as a contact.
*/
var Chip = function (_React$Component) {
(0, _inherits3.default)(Chip, _React$Component);
@@ -212,15 +165,20 @@ var Chip = function (_React$Component) {
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = Chip.__proto__ || (0, _getPrototypeOf2.default)(Chip)).call.apply(_ref, [this].concat(args))), _this), _this.chipRef = null, _this.handleDeleteIconClick = function (event) {
// Stop the event from bubbling up to the `Chip`
event.stopPropagation();
var onRequestDelete = _this.props.onRequestDelete;
var onDelete = _this.props.onDelete;
if (onRequestDelete) {
onRequestDelete(event);
if (onDelete) {
onDelete(event);
}
}, _this.handleKeyDown = function (event) {
// Ignore events from children of `Chip`.
if (event.currentTarget !== event.target) {
return;
}
var _this$props = _this.props,
onClick = _this$props.onClick,
onRequestDelete = _this$props.onRequestDelete,
onDelete = _this$props.onDelete,
onKeyDown = _this$props.onKeyDown;
var key = (0, _keycode2.default)(event);
@@ -228,9 +186,9 @@ var Chip = function (_React$Component) {
if (onClick && (key === 'space' || key === 'enter')) {
event.preventDefault();
onClick(event);
} else if (onRequestDelete && key === 'backspace') {
} else if (onDelete && key === 'backspace') {
event.preventDefault();
onRequestDelete(event);
onDelete(event);
} else if (key === 'esc') {
event.preventDefault();
if (_this.chipRef) {
@@ -253,30 +211,28 @@ var Chip = function (_React$Component) {
avatarProp = _props.avatar,
classes = _props.classes,
classNameProp = _props.className,
Component = _props.component,
deleteIconProp = _props.deleteIcon,
label = _props.label,
onClick = _props.onClick,
onDelete = _props.onDelete,
onKeyDown = _props.onKeyDown,
onRequestDelete = _props.onRequestDelete,
deleteIconProp = _props.deleteIcon,
tabIndexProp = _props.tabIndex,
other = (0, _objectWithoutProperties3.default)(_props, ['avatar', 'classes', 'className', 'label', 'onClick', 'onKeyDown', 'onRequestDelete', 'deleteIcon', 'tabIndex']);
other = (0, _objectWithoutProperties3.default)(_props, ['avatar', 'classes', 'className', 'component', 'deleteIcon', 'label', 'onClick', 'onDelete', 'onKeyDown', 'tabIndex']);
var className = (0, _classnames2.default)(classes.root, (0, _defineProperty3.default)({}, classes.clickable, onClick), (0, _defineProperty3.default)({}, classes.deletable, onRequestDelete), classNameProp);
var className = (0, _classnames2.default)(classes.root, (0, _defineProperty3.default)({}, classes.clickable, onClick), (0, _defineProperty3.default)({}, classes.deletable, onDelete), classNameProp);
var deleteIcon = null;
if (onRequestDelete && deleteIconProp && _react2.default.isValidElement(deleteIconProp)) {
deleteIcon = _react2.default.cloneElement(deleteIconProp, {
onClick: this.handleDeleteIconClick,
className: (0, _classnames2.default)(classes.deleteIcon, deleteIconProp.props.className)
});
} else if (onRequestDelete) {
deleteIcon = _react2.default.createElement(_Cancel2.default, { className: classes.deleteIcon, onClick: this.handleDeleteIconClick });
if (onDelete) {
deleteIcon = deleteIconProp && _react2.default.isValidElement(deleteIconProp) ? _react2.default.cloneElement(deleteIconProp, {
className: (0, _classnames2.default)(deleteIconProp.props.className, classes.deleteIcon),
onClick: this.handleDeleteIconClick
}) : _react2.default.createElement(_Cancel2.default, { className: classes.deleteIcon, onClick: this.handleDeleteIconClick });
}
var avatar = null;
if (avatarProp && _react2.default.isValidElement(avatarProp)) {
// $FlowFixMe - this looks strictly correct, not sure why it errors.
avatar = _react2.default.cloneElement(avatarProp, {
className: (0, _classnames2.default)(classes.avatar, avatarProp.props.className),
childrenClassName: (0, _classnames2.default)(classes.avatarChildren, avatarProp.props.childrenClassName)
@@ -286,22 +242,21 @@ var Chip = function (_React$Component) {
var tabIndex = tabIndexProp;
if (!tabIndex) {
tabIndex = onClick || onRequestDelete ? 0 : -1;
tabIndex = onClick || onDelete ? 0 : -1;
}
return _react2.default.createElement(
'div',
Component,
(0, _extends3.default)({
role: 'button',
className: className,
tabIndex: tabIndex,
onClick: onClick,
onKeyDown: this.handleKeyDown
}, other, {
onKeyDown: this.handleKeyDown,
ref: function ref(node) {
_this2.chipRef = node;
}
}),
}, other),
avatar,
_react2.default.createElement(
'span',
@@ -315,4 +270,53 @@ var Chip = function (_React$Component) {
return Chip;
}(_react2.default.Component);
Chip.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* Avatar element.
*/
avatar: _propTypes2.default.element,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func]),
/**
* Override the default delete icon element. Shown only if `onDelete` is set.
*/
deleteIcon: _propTypes2.default.element,
/**
* The content of the label.
*/
label: _propTypes2.default.node,
/**
* @ignore
*/
onClick: _propTypes2.default.func,
/**
* Callback function fired when the delete icon is clicked.
* If set, the delete icon will be shown.
*/
onDelete: _propTypes2.default.func,
/**
* @ignore
*/
onKeyDown: _propTypes2.default.func,
/**
* @ignore
*/
tabIndex: _propTypes2.default.oneOfType([_propTypes2.default.number, _propTypes2.default.string])
} : {};
Chip.defaultProps = {
component: 'div'
};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiChip' })(Chip);

View File

@@ -1,24 +1,23 @@
// @flow
import React from 'react';
import type { Element, Node } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import keycode from 'keycode';
import CancelIcon from '../internal/svg-icons/Cancel';
import withStyles from '../styles/withStyles';
import CancelIcon from '../svg-icons/Cancel';
import { emphasize, fade } from '../styles/colorManipulator';
import Avatar from '../Avatar/Avatar';
import '../Avatar/Avatar'; // So we don't have any override priority issue.
export const styles = (theme: Object) => {
export const styles = theme => {
const height = 32;
const backgroundColor = emphasize(theme.palette.background.default, 0.12);
const backgroundColor =
theme.palette.type === 'light' ? theme.palette.grey[300] : theme.palette.grey[700];
const deleteIconColor = fade(theme.palette.text.primary, 0.26);
return {
root: {
fontFamily: theme.typography.fontFamily,
fontSize: theme.typography.pxToRem(13),
display: 'flex',
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
height,
@@ -26,7 +25,6 @@ export const styles = (theme: Object) => {
backgroundColor,
borderRadius: height / 2,
whiteSpace: 'nowrap',
width: 'fit-content',
transition: theme.transitions.create(),
// label will inherit this from root, then `clickable` class overrides this for both
cursor: 'default',
@@ -36,7 +34,7 @@ export const styles = (theme: Object) => {
},
clickable: {
// Remove grey highlight
WebkitTapHighlightColor: theme.palette.common.transparent,
WebkitTapHighlightColor: 'transparent',
cursor: 'pointer',
'&:hover, &:focus': {
backgroundColor: emphasize(backgroundColor, 0.08),
@@ -53,8 +51,9 @@ export const styles = (theme: Object) => {
},
avatar: {
marginRight: -4,
width: 32,
height: 32,
width: height,
height,
color: theme.palette.type === 'light' ? theme.palette.grey[700] : theme.palette.grey[300],
fontSize: theme.typography.pxToRem(16),
},
avatarChildren: {
@@ -72,7 +71,7 @@ export const styles = (theme: Object) => {
},
deleteIcon: {
// Remove grey highlight
WebkitTapHighlightColor: theme.palette.common.transparent,
WebkitTapHighlightColor: 'transparent',
color: deleteIconColor,
cursor: 'pointer',
height: 'auto',
@@ -84,75 +83,36 @@ export const styles = (theme: Object) => {
};
};
type ProvidedProps = {
classes: Object,
};
export type Props = {
/**
* Avatar element.
*/
avatar?: Element<typeof Avatar>,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* Custom delete icon. Will be shown only if `onRequestDelete` is set.
*/
deleteIcon?: Element<any>,
/**
* The content of the label.
*/
label?: Node,
/**
* @ignore
*/
onClick?: Function,
/**
* @ignore
*/
onKeyDown?: Function,
/**
* Callback function fired when the delete icon is clicked.
* If set, the delete icon will be shown.
*/
onRequestDelete?: (event: SyntheticEvent<>) => void,
/**
* @ignore
*/
tabIndex?: number | string,
};
/**
* Chips represent complex entities in small blocks, such as a contact.
*/
class Chip extends React.Component<ProvidedProps & Props> {
chipRef: ?HTMLElement = null;
class Chip extends React.Component {
chipRef = null;
handleDeleteIconClick = event => {
// Stop the event from bubbling up to the `Chip`
event.stopPropagation();
const { onRequestDelete } = this.props;
if (onRequestDelete) {
onRequestDelete(event);
const { onDelete } = this.props;
if (onDelete) {
onDelete(event);
}
};
handleKeyDown = event => {
const { onClick, onRequestDelete, onKeyDown } = this.props;
// Ignore events from children of `Chip`.
if (event.currentTarget !== event.target) {
return;
}
const { onClick, onDelete, onKeyDown } = this.props;
const key = keycode(event);
if (onClick && (key === 'space' || key === 'enter')) {
event.preventDefault();
onClick(event);
} else if (onRequestDelete && key === 'backspace') {
} else if (onDelete && key === 'backspace') {
event.preventDefault();
onRequestDelete(event);
onDelete(event);
} else if (key === 'esc') {
event.preventDefault();
if (this.chipRef) {
@@ -170,11 +130,12 @@ class Chip extends React.Component<ProvidedProps & Props> {
avatar: avatarProp,
classes,
className: classNameProp,
component: Component,
deleteIcon: deleteIconProp,
label,
onClick,
onDelete,
onKeyDown,
onRequestDelete,
deleteIcon: deleteIconProp,
tabIndex: tabIndexProp,
...other
} = this.props;
@@ -182,25 +143,25 @@ class Chip extends React.Component<ProvidedProps & Props> {
const className = classNames(
classes.root,
{ [classes.clickable]: onClick },
{ [classes.deletable]: onRequestDelete },
{ [classes.deletable]: onDelete },
classNameProp,
);
let deleteIcon = null;
if (onRequestDelete && deleteIconProp && React.isValidElement(deleteIconProp)) {
deleteIcon = React.cloneElement(deleteIconProp, {
onClick: this.handleDeleteIconClick,
className: classNames(classes.deleteIcon, deleteIconProp.props.className),
});
} else if (onRequestDelete) {
deleteIcon = (
<CancelIcon className={classes.deleteIcon} onClick={this.handleDeleteIconClick} />
);
if (onDelete) {
deleteIcon =
deleteIconProp && React.isValidElement(deleteIconProp) ? (
React.cloneElement(deleteIconProp, {
className: classNames(deleteIconProp.props.className, classes.deleteIcon),
onClick: this.handleDeleteIconClick,
})
) : (
<CancelIcon className={classes.deleteIcon} onClick={this.handleDeleteIconClick} />
);
}
let avatar = null;
if (avatarProp && React.isValidElement(avatarProp)) {
// $FlowFixMe - this looks strictly correct, not sure why it errors.
avatar = React.cloneElement(avatarProp, {
className: classNames(classes.avatar, avatarProp.props.className),
childrenClassName: classNames(classes.avatarChildren, avatarProp.props.childrenClassName),
@@ -210,27 +171,76 @@ class Chip extends React.Component<ProvidedProps & Props> {
let tabIndex = tabIndexProp;
if (!tabIndex) {
tabIndex = onClick || onRequestDelete ? 0 : -1;
tabIndex = onClick || onDelete ? 0 : -1;
}
return (
<div
<Component
role="button"
className={className}
tabIndex={tabIndex}
onClick={onClick}
onKeyDown={this.handleKeyDown}
{...other}
ref={node => {
this.chipRef = node;
}}
{...other}
>
{avatar}
<span className={classes.label}>{label}</span>
{deleteIcon}
</div>
</Component>
);
}
}
Chip.propTypes = {
/**
* Avatar element.
*/
avatar: PropTypes.element,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
/**
* Override the default delete icon element. Shown only if `onDelete` is set.
*/
deleteIcon: PropTypes.element,
/**
* The content of the label.
*/
label: PropTypes.node,
/**
* @ignore
*/
onClick: PropTypes.func,
/**
* Callback function fired when the delete icon is clicked.
* If set, the delete icon will be shown.
*/
onDelete: PropTypes.func,
/**
* @ignore
*/
onKeyDown: PropTypes.func,
/**
* @ignore
*/
tabIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
};
Chip.defaultProps = {
component: 'div',
};
export default withStyles(styles, { name: 'MuiChip' })(Chip);

View File

@@ -1,3 +1 @@
// @flow
export { default } from './Chip';

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

@@ -17,12 +17,14 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
@@ -33,7 +35,7 @@ var _withStyles2 = _interopRequireDefault(_withStyles);
var _helpers = require('../utils/helpers');
var _Modal = require('../internal/Modal');
var _Modal = require('../Modal');
var _Modal2 = _interopRequireDefault(_Modal);
@@ -49,14 +51,6 @@ var _Paper2 = _interopRequireDefault(_Paper);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var babelPluginFlowReactPropTypes_proptype_ComponentType = require('prop-types').func;
var babelPluginFlowReactPropTypes_proptype_TransitionCallback = require('../internal/transition').babelPluginFlowReactPropTypes_proptype_TransitionCallback || require('prop-types').any;
var babelPluginFlowReactPropTypes_proptype_TransitionDuration = require('../internal/transition').babelPluginFlowReactPropTypes_proptype_TransitionDuration || require('prop-types').any;
var styles = exports.styles = function styles(theme) {
return {
root: {
@@ -76,7 +70,7 @@ var styles = exports.styles = function styles(theme) {
}
},
paperWidthXs: {
maxWidth: theme.breakpoints.values.xs
maxWidth: Math.max(theme.breakpoints.values.xs, 360)
},
paperWidthSm: {
maxWidth: theme.breakpoints.values.sm
@@ -98,118 +92,11 @@ var styles = exports.styles = function styles(theme) {
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* Dialog children, usually the included sub-components.
*/
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* If `true`, it will be full-screen
*/
fullScreen: require('prop-types').bool,
/**
* If `true`, clicking the backdrop will not fire the `onRequestClose` callback.
*/
ignoreBackdropClick: require('prop-types').bool,
/**
* If `true`, hitting escape will not fire the `onRequestClose` callback.
*/
ignoreEscapeKeyUp: require('prop-types').bool,
/**
* The duration for the transition, in milliseconds.
* You may specify a single timeout for all transitions, or individually with an object.
*/
transitionDuration: typeof babelPluginFlowReactPropTypes_proptype_TransitionDuration === 'function' ? babelPluginFlowReactPropTypes_proptype_TransitionDuration : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_TransitionDuration),
/**
* 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.
*/
maxWidth: require('prop-types').oneOf(['xs', 'sm', 'md']),
/**
* If specified, stretches dialog to max width.
*/
fullWidth: require('prop-types').bool,
/**
* Callback fired when the backdrop is clicked.
*/
onBackdropClick: require('prop-types').func,
/**
* Callback fired before the dialog enters.
*/
onEnter: typeof babelPluginFlowReactPropTypes_proptype_TransitionCallback === 'function' ? babelPluginFlowReactPropTypes_proptype_TransitionCallback : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_TransitionCallback),
/**
* Callback fired when the dialog is entering.
*/
onEntering: typeof babelPluginFlowReactPropTypes_proptype_TransitionCallback === 'function' ? babelPluginFlowReactPropTypes_proptype_TransitionCallback : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_TransitionCallback),
/**
* Callback fired when the dialog has entered.
*/
onEntered: typeof babelPluginFlowReactPropTypes_proptype_TransitionCallback === 'function' ? babelPluginFlowReactPropTypes_proptype_TransitionCallback : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_TransitionCallback),
/**
* Callback fires when the escape key is released and the modal is in focus.
*/
onEscapeKeyUp: require('prop-types').func,
/**
* Callback fired before the dialog exits.
*/
onExit: typeof babelPluginFlowReactPropTypes_proptype_TransitionCallback === 'function' ? babelPluginFlowReactPropTypes_proptype_TransitionCallback : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_TransitionCallback),
/**
* Callback fired when the dialog is exiting.
*/
onExiting: typeof babelPluginFlowReactPropTypes_proptype_TransitionCallback === 'function' ? babelPluginFlowReactPropTypes_proptype_TransitionCallback : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_TransitionCallback),
/**
* Callback fired when the dialog has exited.
*/
onExited: typeof babelPluginFlowReactPropTypes_proptype_TransitionCallback === 'function' ? babelPluginFlowReactPropTypes_proptype_TransitionCallback : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_TransitionCallback),
/**
* Callback fired when the component requests to be closed.
*
* @param {object} event The event source of the callback
*/
onRequestClose: require('prop-types').func,
/**
* If `true`, the Dialog is open.
*/
open: require('prop-types').bool,
/**
* Transition component.
*/
transition: typeof babelPluginFlowReactPropTypes_proptype_ComponentType === 'function' ? babelPluginFlowReactPropTypes_proptype_ComponentType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ComponentType)
};
/**
* Dialogs are overlaid modal paper based components with a backdrop.
*/
// @inheritedComponent Modal
function Dialog(props) {
var _classNames;
@@ -217,36 +104,40 @@ function Dialog(props) {
classes = props.classes,
className = props.className,
fullScreen = props.fullScreen,
ignoreBackdropClick = props.ignoreBackdropClick,
ignoreEscapeKeyUp = props.ignoreEscapeKeyUp,
transitionDuration = props.transitionDuration,
maxWidth = props.maxWidth,
fullWidth = props.fullWidth,
open = props.open,
disableBackdropClick = props.disableBackdropClick,
disableEscapeKeyDown = props.disableEscapeKeyDown,
maxWidth = props.maxWidth,
onBackdropClick = props.onBackdropClick,
onEscapeKeyUp = props.onEscapeKeyUp,
onClose = props.onClose,
onEnter = props.onEnter,
onEntering = props.onEntering,
onEntered = props.onEntered,
onEntering = props.onEntering,
onEscapeKeyDown = props.onEscapeKeyDown,
onExit = props.onExit,
onExiting = props.onExiting,
onExited = props.onExited,
onRequestClose = props.onRequestClose,
onExiting = props.onExiting,
open = props.open,
PaperProps = props.PaperProps,
TransitionProp = props.transition,
other = (0, _objectWithoutProperties3.default)(props, ['children', 'classes', 'className', 'fullScreen', 'ignoreBackdropClick', 'ignoreEscapeKeyUp', 'transitionDuration', 'maxWidth', 'fullWidth', 'open', 'onBackdropClick', 'onEscapeKeyUp', 'onEnter', 'onEntering', 'onEntered', 'onExit', 'onExiting', 'onExited', 'onRequestClose', 'transition']);
transitionDuration = props.transitionDuration,
other = (0, _objectWithoutProperties3.default)(props, ['children', 'classes', 'className', 'fullScreen', 'fullWidth', 'disableBackdropClick', 'disableEscapeKeyDown', 'maxWidth', 'onBackdropClick', 'onClose', 'onEnter', 'onEntered', 'onEntering', 'onEscapeKeyDown', 'onExit', 'onExited', 'onExiting', 'open', 'PaperProps', 'transition', 'transitionDuration']);
return _react2.default.createElement(
_Modal2.default,
(0, _extends3.default)({
className: (0, _classnames2.default)(classes.root, className),
BackdropTransitionDuration: transitionDuration,
ignoreBackdropClick: ignoreBackdropClick,
ignoreEscapeKeyUp: ignoreEscapeKeyUp,
BackdropProps: {
transitionDuration: transitionDuration
},
disableBackdropClick: disableBackdropClick,
disableEscapeKeyDown: disableEscapeKeyDown,
onBackdropClick: onBackdropClick,
onEscapeKeyUp: onEscapeKeyUp,
onRequestClose: onRequestClose,
show: open
onEscapeKeyDown: onEscapeKeyDown,
onClose: onClose,
open: open,
role: 'dialog'
}, other),
_react2.default.createElement(
TransitionProp,
@@ -263,33 +154,118 @@ function Dialog(props) {
},
_react2.default.createElement(
_Paper2.default,
{
(0, _extends3.default)({
elevation: 24,
className: (0, _classnames2.default)(classes.paper, classes['paperWidth' + (0, _helpers.capitalizeFirstLetter)(maxWidth)], (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes.fullScreen, fullScreen), (0, _defineProperty3.default)(_classNames, classes.fullWidth, fullWidth), _classNames))
},
className: (0, _classnames2.default)(classes.paper, (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes['paperWidth' + (maxWidth ? (0, _helpers.capitalize)(maxWidth) : '')], maxWidth), (0, _defineProperty3.default)(_classNames, classes.fullScreen, fullScreen), (0, _defineProperty3.default)(_classNames, classes.fullWidth, fullWidth), _classNames))
}, PaperProps),
children
)
)
);
}
Dialog.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
transition: typeof babelPluginFlowReactPropTypes_proptype_ComponentType === 'function' ? babelPluginFlowReactPropTypes_proptype_ComponentType.isRequired ? babelPluginFlowReactPropTypes_proptype_ComponentType.isRequired : babelPluginFlowReactPropTypes_proptype_ComponentType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ComponentType).isRequired,
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'fullScreen', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'ignoreBackdropClick', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'ignoreEscapeKeyUp', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'transitionDuration', typeof babelPluginFlowReactPropTypes_proptype_TransitionDuration === 'function' ? babelPluginFlowReactPropTypes_proptype_TransitionDuration : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_TransitionDuration)), (0, _defineProperty3.default)(_ref, 'maxWidth', require('prop-types').oneOf(['xs', 'sm', 'md'])), (0, _defineProperty3.default)(_ref, 'fullWidth', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'onBackdropClick', require('prop-types').func), (0, _defineProperty3.default)(_ref, 'onEnter', typeof babelPluginFlowReactPropTypes_proptype_TransitionCallback === 'function' ? babelPluginFlowReactPropTypes_proptype_TransitionCallback : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_TransitionCallback)), (0, _defineProperty3.default)(_ref, 'onEntering', typeof babelPluginFlowReactPropTypes_proptype_TransitionCallback === 'function' ? babelPluginFlowReactPropTypes_proptype_TransitionCallback : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_TransitionCallback)), (0, _defineProperty3.default)(_ref, 'onEntered', typeof babelPluginFlowReactPropTypes_proptype_TransitionCallback === 'function' ? babelPluginFlowReactPropTypes_proptype_TransitionCallback : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_TransitionCallback)), (0, _defineProperty3.default)(_ref, 'onEscapeKeyUp', require('prop-types').func), (0, _defineProperty3.default)(_ref, 'onExit', typeof babelPluginFlowReactPropTypes_proptype_TransitionCallback === 'function' ? babelPluginFlowReactPropTypes_proptype_TransitionCallback : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_TransitionCallback)), (0, _defineProperty3.default)(_ref, 'onExiting', typeof babelPluginFlowReactPropTypes_proptype_TransitionCallback === 'function' ? babelPluginFlowReactPropTypes_proptype_TransitionCallback : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_TransitionCallback)), (0, _defineProperty3.default)(_ref, 'onExited', typeof babelPluginFlowReactPropTypes_proptype_TransitionCallback === 'function' ? babelPluginFlowReactPropTypes_proptype_TransitionCallback : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_TransitionCallback)), (0, _defineProperty3.default)(_ref, 'onRequestClose', require('prop-types').func), (0, _defineProperty3.default)(_ref, 'open', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'transition', typeof babelPluginFlowReactPropTypes_proptype_ComponentType === 'function' ? babelPluginFlowReactPropTypes_proptype_ComponentType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ComponentType)), _ref) : {};
Dialog.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* Dialog children, usually the included sub-components.
*/
children: _propTypes2.default.node.isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* If `true`, clicking the backdrop will not fire the `onClose` callback.
*/
disableBackdropClick: _propTypes2.default.bool,
/**
* If `true`, hitting escape will not fire the `onClose` callback.
*/
disableEscapeKeyDown: _propTypes2.default.bool,
/**
* If `true`, the dialog will be full-screen
*/
fullScreen: _propTypes2.default.bool,
/**
* If `true`, the dialog stretches to `maxWidth`.
*/
fullWidth: _propTypes2.default.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: _propTypes2.default.oneOf(['xs', 'sm', 'md', false]),
/**
* Callback fired when the backdrop is clicked.
*/
onBackdropClick: _propTypes2.default.func,
/**
* Callback fired when the component requests to be closed.
*
* @param {object} event The event source of the callback
*/
onClose: _propTypes2.default.func,
/**
* Callback fired before the dialog enters.
*/
onEnter: _propTypes2.default.func,
/**
* Callback fired when the dialog has entered.
*/
onEntered: _propTypes2.default.func,
/**
* Callback fired when the dialog is entering.
*/
onEntering: _propTypes2.default.func,
/**
* Callback fired when the escape key is pressed,
* `disableKeyboard` is false and the modal is in focus.
*/
onEscapeKeyDown: _propTypes2.default.func,
/**
* Callback fired before the dialog exits.
*/
onExit: _propTypes2.default.func,
/**
* Callback fired when the dialog has exited.
*/
onExited: _propTypes2.default.func,
/**
* Callback fired when the dialog is exiting.
*/
onExiting: _propTypes2.default.func,
/**
* If `true`, the Dialog is open.
*/
open: _propTypes2.default.bool.isRequired,
/**
* Properties applied to the `Paper` element.
*/
PaperProps: _propTypes2.default.object,
/**
* Transition component.
*/
transition: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func]),
/**
* The duration for the transition, in milliseconds.
* You may specify a single timeout for all transitions, or individually with an object.
*/
transitionDuration: _propTypes2.default.oneOfType([_propTypes2.default.number, _propTypes2.default.shape({ enter: _propTypes2.default.number, exit: _propTypes2.default.number })])
} : {};
Dialog.defaultProps = {
fullScreen: false,
ignoreBackdropClick: false,
ignoreEscapeKeyUp: false,
transitionDuration: {
enter: _transitions.duration.enteringScreen,
exit: _transitions.duration.leavingScreen
},
maxWidth: 'sm',
fullWidth: false,
open: false,
transition: _Fade2.default
disableBackdropClick: false,
disableEscapeKeyDown: false,
maxWidth: 'sm',
transition: _Fade2.default,
transitionDuration: { enter: _transitions.duration.enteringScreen, exit: _transitions.duration.leavingScreen }
};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiDialog' })(Dialog);

View File

@@ -1,17 +1,16 @@
// @flow
// @inheritedComponent Modal
import React from 'react';
import type { ComponentType, Node } 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';
import type { TransitionDuration, TransitionCallback } from '../internal/transition';
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
justifyContent: 'center',
alignItems: 'center',
@@ -29,7 +28,7 @@ export const styles = (theme: Object) => ({
},
},
paperWidthXs: {
maxWidth: theme.breakpoints.values.xs,
maxWidth: Math.max(theme.breakpoints.values.xs, 360),
},
paperWidthSm: {
maxWidth: theme.breakpoints.values.sm,
@@ -50,138 +49,48 @@ export const styles = (theme: Object) => ({
},
});
type ProvidedProps = {
classes: Object,
transition: ComponentType<*>,
};
export type Props = {
/**
* Dialog children, usually the included sub-components.
*/
children?: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* If `true`, it will be full-screen
*/
fullScreen?: boolean,
/**
* If `true`, clicking the backdrop will not fire the `onRequestClose` callback.
*/
ignoreBackdropClick?: boolean,
/**
* If `true`, hitting escape will not fire the `onRequestClose` callback.
*/
ignoreEscapeKeyUp?: boolean,
/**
* The duration for the transition, in milliseconds.
* You may specify a single timeout for all transitions, or individually with an object.
*/
transitionDuration?: TransitionDuration,
/**
* 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.
*/
maxWidth?: 'xs' | 'sm' | 'md',
/**
* If specified, stretches dialog to max width.
*/
fullWidth?: boolean,
/**
* Callback fired when the backdrop is clicked.
*/
onBackdropClick?: Function,
/**
* Callback fired before the dialog enters.
*/
onEnter?: TransitionCallback,
/**
* Callback fired when the dialog is entering.
*/
onEntering?: TransitionCallback,
/**
* Callback fired when the dialog has entered.
*/
onEntered?: TransitionCallback,
/**
* Callback fires when the escape key is released and the modal is in focus.
*/
onEscapeKeyUp?: Function,
/**
* Callback fired before the dialog exits.
*/
onExit?: TransitionCallback,
/**
* Callback fired when the dialog is exiting.
*/
onExiting?: TransitionCallback,
/**
* Callback fired when the dialog has exited.
*/
onExited?: TransitionCallback,
/**
* Callback fired when the component requests to be closed.
*
* @param {object} event The event source of the callback
*/
onRequestClose?: Function,
/**
* If `true`, the Dialog is open.
*/
open?: boolean,
/**
* Transition component.
*/
transition?: ComponentType<*>,
};
/**
* Dialogs are overlaid modal paper based components with a backdrop.
*/
function Dialog(props: ProvidedProps & Props) {
function Dialog(props) {
const {
children,
classes,
className,
fullScreen,
ignoreBackdropClick,
ignoreEscapeKeyUp,
transitionDuration,
maxWidth,
fullWidth,
open,
disableBackdropClick,
disableEscapeKeyDown,
maxWidth,
onBackdropClick,
onEscapeKeyUp,
onClose,
onEnter,
onEntering,
onEntered,
onEntering,
onEscapeKeyDown,
onExit,
onExiting,
onExited,
onRequestClose,
onExiting,
open,
PaperProps,
transition: TransitionProp,
transitionDuration,
...other
} = props;
return (
<Modal
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}
>
<TransitionProp
@@ -198,14 +107,12 @@ function Dialog(props: ProvidedProps & Props) {
<Paper
data-mui-test="Dialog"
elevation={24}
className={classNames(
classes.paper,
classes[`paperWidth${capitalizeFirstLetter(maxWidth)}`],
{
[classes.fullScreen]: fullScreen,
[classes.fullWidth]: fullWidth,
},
)}
className={classNames(classes.paper, {
[classes[`paperWidth${maxWidth ? capitalize(maxWidth) : ''}`]]: maxWidth,
[classes.fullScreen]: fullScreen,
[classes.fullWidth]: fullWidth,
})}
{...PaperProps}
>
{children}
</Paper>
@@ -214,18 +121,111 @@ function Dialog(props: ProvidedProps & Props) {
);
}
Dialog.propTypes = {
/**
* 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,
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

@@ -5,10 +5,6 @@ Object.defineProperty(exports, "__esModule", {
});
exports.styles = undefined;
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
@@ -17,12 +13,14 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
@@ -35,8 +33,6 @@ require('../Button');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
// So we don't have any override priority issue.
var styles = exports.styles = function styles(theme) {
@@ -57,24 +53,6 @@ var styles = exports.styles = function styles(theme) {
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The content of the component.
*/
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string
};
function DialogActions(props) {
var children = props.children,
classes = props.classes,
@@ -85,20 +63,35 @@ function DialogActions(props) {
return _react2.default.createElement(
'div',
(0, _extends3.default)({ className: (0, _classnames2.default)(classes.root, className) }, other),
_react2.default.Children.map(children, function (button) {
return _react2.default.isValidElement(button) && _react2.default.createElement(
_react2.default.Children.map(children, function (child) {
if (!_react2.default.isValidElement(child)) {
return null;
}
return _react2.default.createElement(
'div',
{ className: classes.action },
_react2.default.cloneElement(button, {
className: (0, _classnames2.default)(classes.button, button.props.className)
_react2.default.cloneElement(child, {
className: (0, _classnames2.default)(classes.button, child.props.className)
})
);
})
);
}
DialogActions.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), _ref) : {};
DialogActions.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the component.
*/
children: _propTypes2.default.node,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string
} : {};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiDialogActions' })(DialogActions);

View File

@@ -1,12 +1,10 @@
// @flow
import React from 'react';
import type { Node } 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.
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
display: 'flex',
justifyContent: 'flex-end',
@@ -22,43 +20,41 @@ export const styles = (theme: Object) => ({
},
});
type ProvidedProps = {
classes: Object,
};
export type Props = {
/**
* The content of the component.
*/
children?: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
};
function DialogActions(props: ProvidedProps & Props) {
function DialogActions(props) {
const { children, classes, className, ...other } = props;
return (
<div data-mui-test="DialogActions" className={classNames(classes.root, className)} {...other}>
{React.Children.map(
children,
button =>
React.isValidElement(button) && (
<div className={classes.action}>
{React.cloneElement(button, {
className: classNames(classes.button, button.props.className),
})}
</div>
),
)}
<div className={classNames(classes.root, className)} {...other}>
{React.Children.map(children, child => {
if (!React.isValidElement(child)) {
return null;
}
return (
<div className={classes.action}>
{React.cloneElement(child, {
className: classNames(classes.button, child.props.className),
})}
</div>
);
})}
</div>
);
}
DialogActions.propTypes = {
/**
* 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

@@ -5,10 +5,6 @@ Object.defineProperty(exports, "__esModule", {
});
exports.styles = undefined;
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
@@ -17,12 +13,14 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
@@ -33,8 +31,6 @@ var _withStyles2 = _interopRequireDefault(_withStyles);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var styles = exports.styles = function styles(theme) {
var spacing = theme.spacing.unit * 3;
return {
@@ -49,24 +45,6 @@ var styles = exports.styles = function styles(theme) {
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The content of the component.
*/
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string
};
function DialogContent(props) {
var classes = props.classes,
children = props.children,
@@ -81,8 +59,19 @@ function DialogContent(props) {
);
}
DialogContent.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), _ref) : {};
DialogContent.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the component.
*/
children: _propTypes2.default.node,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string
} : {};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiDialogContent' })(DialogContent);

View File

@@ -1,11 +1,9 @@
// @flow
import React from 'react';
import type { Node } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
export const styles = (theme: Object) => {
export const styles = theme => {
const spacing = theme.spacing.unit * 3;
return {
root: {
@@ -19,26 +17,7 @@ export const styles = (theme: Object) => {
};
};
type ProvidedProps = {
classes: Object,
};
export type Props = {
/**
* The content of the component.
*/
children?: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
};
function DialogContent(props: ProvidedProps & Props) {
function DialogContent(props) {
const { classes, children, className, ...other } = props;
return (
@@ -48,4 +27,19 @@ function DialogContent(props: ProvidedProps & Props) {
);
}
DialogContent.propTypes = {
/**
* 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

@@ -5,10 +5,6 @@ Object.defineProperty(exports, "__esModule", {
});
exports.styles = undefined;
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
@@ -17,12 +13,14 @@ var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _ref;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
@@ -33,8 +31,6 @@ var _withStyles2 = _interopRequireDefault(_withStyles);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var styles = exports.styles = function styles(theme) {
return {
root: (0, _extends3.default)({}, theme.typography.subheading, {
@@ -44,24 +40,6 @@ var styles = exports.styles = function styles(theme) {
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The content of the component.
*/
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string
};
function DialogContentText(props) {
var children = props.children,
classes = props.classes,
@@ -76,8 +54,19 @@ function DialogContentText(props) {
);
}
DialogContentText.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), _ref) : {};
DialogContentText.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the component.
*/
children: _propTypes2.default.node,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string
} : {};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiDialogContentText' })(DialogContentText);

View File

@@ -1,11 +1,9 @@
// @flow
import React from 'react';
import type { Node } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
...theme.typography.subheading,
color: theme.palette.text.secondary,
@@ -13,26 +11,7 @@ export const styles = (theme: Object) => ({
},
});
type ProvidedProps = {
classes: Object,
};
export type Props = {
/**
* The content of the component.
*/
children?: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
};
function DialogContentText(props: ProvidedProps & Props) {
function DialogContentText(props) {
const { children, classes, className, ...other } = props;
return (
@@ -42,4 +21,19 @@ function DialogContentText(props: ProvidedProps & Props) {
);
}
DialogContentText.propTypes = {
/**
* 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

@@ -5,10 +5,6 @@ Object.defineProperty(exports, "__esModule", {
});
exports.styles = undefined;
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
@@ -17,12 +13,14 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
@@ -37,8 +35,6 @@ var _Typography2 = _interopRequireDefault(_Typography);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var styles = exports.styles = function styles(theme) {
return {
root: {
@@ -49,30 +45,6 @@ var styles = exports.styles = function styles(theme) {
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The content of the component.
*/
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* If `true`, the children won't be wrapped by a typography component.
* For instance, that can be useful to can render an h4 instead of a
*/
disableTypography: require('prop-types').bool
};
function DialogTitle(props) {
var children = props.children,
classes = props.classes,
@@ -86,16 +58,32 @@ function DialogTitle(props) {
(0, _extends3.default)({ className: (0, _classnames2.default)(classes.root, className) }, other),
disableTypography ? children : _react2.default.createElement(
_Typography2.default,
{ type: 'title' },
{ variant: 'title' },
children
)
);
}
DialogTitle.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node)
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'disableTypography', require('prop-types').bool), _ref) : {};
DialogTitle.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the component.
*/
children: _propTypes2.default.node.isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.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: _propTypes2.default.bool
} : {};
DialogTitle.defaultProps = {
disableTypography: false
};

View File

@@ -1,12 +1,10 @@
// @flow
import React from 'react';
import type { Node } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import Typography from '../Typography';
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
margin: 0,
padding: `${theme.spacing.unit * 3}px ${theme.spacing.unit * 3}px \
@@ -15,40 +13,36 @@ export const styles = (theme: Object) => ({
},
});
type ProvidedProps = {
classes: Object,
};
export type Props = {
/**
* The content of the component.
*/
children?: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* If `true`, the children won't be wrapped by a typography component.
* For instance, that can be useful to can render an h4 instead of a
*/
disableTypography?: boolean,
};
function DialogTitle(props: ProvidedProps & Props) {
function DialogTitle(props) {
const { children, classes, className, disableTypography, ...other } = props;
return (
<div data-mui-test="DialogTitle" className={classNames(classes.root, className)} {...other}>
{disableTypography ? children : <Typography type="title">{children}</Typography>}
{disableTypography ? children : <Typography variant="title">{children}</Typography>}
</div>
);
}
DialogTitle.propTypes = {
/**
* 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

@@ -1,5 +1,3 @@
// @flow
export { default } from './Dialog';
export { default as DialogActions } from './DialogActions';
export { default as DialogTitle } from './DialogTitle';

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

@@ -12,9 +12,9 @@ var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _wrapDisplayName = require('recompose/wrapDisplayName');
var _propTypes = require('prop-types');
var _wrapDisplayName2 = _interopRequireDefault(_wrapDisplayName);
var _propTypes2 = _interopRequireDefault(_propTypes);
var _withWidth = require('../utils/withWidth');
@@ -22,27 +22,16 @@ var _withWidth2 = _interopRequireDefault(_withWidth);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_HigherOrderComponent = require('react-flow-types').babelPluginFlowReactPropTypes_proptype_HigherOrderComponent || require('prop-types').any;
var babelPluginFlowReactPropTypes_proptype_Breakpoint = require('../styles/createBreakpoints').babelPluginFlowReactPropTypes_proptype_Breakpoint || require('prop-types').any;
var babelPluginFlowReactPropTypes_proptype_InjectedProps = {
/**
* If isWidthDown(options.breakpoint), return true.
*/
fullScreen: require('prop-types').bool.isRequired
};
/**
* 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.
*/
var withMobileDialog = function withMobileDialog() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { breakpoint: 'sm' };
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return function (Component) {
var breakpoint = options.breakpoint;
var _options$breakpoint = options.breakpoint,
breakpoint = _options$breakpoint === undefined ? 'sm' : _options$breakpoint;
function WithMobileDialog(props) {
@@ -50,11 +39,8 @@ var withMobileDialog = function withMobileDialog() {
}
WithMobileDialog.propTypes = process.env.NODE_ENV !== "production" ? {
width: require('prop-types').string.isRequired
width: _propTypes2.default.oneOf(['xs', 'sm', 'md', 'lg', 'xl']).isRequired
} : {};
if (process.env.NODE_ENV !== 'production') {
WithMobileDialog.displayName = (0, _wrapDisplayName2.default)(Component, 'withMobileDialog');
}
return (0, _withWidth2.default)()(WithMobileDialog);
};

View File

@@ -1,37 +1,22 @@
// @flow
import React from 'react';
import type { HigherOrderComponent } from 'react-flow-types';
import wrapDisplayName from 'recompose/wrapDisplayName';
import PropTypes from 'prop-types';
import withWidth, { isWidthDown } from '../utils/withWidth';
import type { Breakpoint } from '../styles/createBreakpoints';
type Options = { breakpoint: Breakpoint };
export type InjectedProps = {
/**
* If isWidthDown(options.breakpoint), return true.
*/
fullScreen: boolean,
};
/**
* 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: Options = { breakpoint: 'sm' },
): HigherOrderComponent<{}, InjectedProps> => (Component: any): any => {
const { breakpoint } = options;
const withMobileDialog = (options = {}) => Component => {
const { breakpoint = 'sm' } = options;
function WithMobileDialog(props: { width: string }) {
function WithMobileDialog(props) {
return <Component fullScreen={isWidthDown(breakpoint, props.width)} {...props} />;
}
if (process.env.NODE_ENV !== 'production') {
WithMobileDialog.displayName = wrapDisplayName(Component, 'withMobileDialog');
}
WithMobileDialog.propTypes = {
width: PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']).isRequired,
};
return withWidth()(WithMobileDialog);
};

View File

@@ -1,22 +1,15 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface DividerProps extends StandardProps<
React.HTMLAttributes<HTMLHRElement>,
DividerClassKey
> {
export interface DividerProps
extends StandardProps<React.HTMLAttributes<HTMLHRElement>, DividerClassKey> {
absolute?: boolean;
component?: React.ReactType<DividerProps>;
inset?: boolean;
light?: boolean;
}
export type DividerClassKey =
| 'root'
| 'default'
| 'inset'
| 'light'
| 'absolute'
;
export type DividerClassKey = 'root' | 'default' | 'inset' | 'light' | 'absolute';
declare const Divider: React.ComponentType<DividerProps>;

View File

@@ -17,12 +17,14 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
@@ -31,6 +33,8 @@ var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
var _colorManipulator = require('../styles/colorManipulator');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var styles = exports.styles = function styles(theme) {
@@ -41,14 +45,14 @@ var styles = exports.styles = function styles(theme) {
border: 'none',
flexShrink: 0
},
default: {
backgroundColor: theme.palette.text.divider
},
inset: {
marginLeft: 72
},
default: {
backgroundColor: theme.palette.divider
},
light: {
backgroundColor: theme.palette.text.lightDivider
backgroundColor: (0, _colorManipulator.fade)(theme.palette.divider, 0.08)
},
absolute: {
position: 'absolute',
@@ -59,53 +63,51 @@ var styles = exports.styles = function styles(theme) {
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
absolute: require('prop-types').bool,
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* If `true`, the divider will be indented.
*/
inset: require('prop-types').bool,
/**
* If `true`, the divider will have a lighter color.
*/
light: require('prop-types').bool
};
function Divider(props) {
var _classNames;
var absolute = props.absolute,
classes = props.classes,
classNameProp = props.className,
Component = props.component,
inset = props.inset,
light = props.light,
other = (0, _objectWithoutProperties3.default)(props, ['absolute', 'classes', 'className', 'inset', 'light']);
other = (0, _objectWithoutProperties3.default)(props, ['absolute', 'classes', 'className', 'component', 'inset', 'light']);
var className = (0, _classnames2.default)(classes.root, (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes.absolute, absolute), (0, _defineProperty3.default)(_classNames, classes.inset, inset), (0, _defineProperty3.default)(_classNames, light ? classes.light : classes.default, true), _classNames), classNameProp);
var className = (0, _classnames2.default)(classes.root, (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes.absolute, absolute), (0, _defineProperty3.default)(_classNames, classes.inset, inset), _classNames), light ? classes.light : classes.default, classNameProp);
return _react2.default.createElement('hr', (0, _extends3.default)({ className: className }, other));
return _react2.default.createElement(Component, (0, _extends3.default)({ className: className }, other));
}
Divider.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
absolute: require('prop-types').bool
}, (0, _defineProperty3.default)(_ref, 'classes', require('prop-types').object), (0, _defineProperty3.default)(_ref, 'className', require('prop-types').string), (0, _defineProperty3.default)(_ref, 'inset', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'light', require('prop-types').bool), _ref) : {};
Divider.propTypes = process.env.NODE_ENV !== "production" ? {
absolute: _propTypes2.default.bool,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func]),
/**
* If `true`, the divider will be indented.
*/
inset: _propTypes2.default.bool,
/**
* If `true`, the divider will have a lighter color.
*/
light: _propTypes2.default.bool
} : {};
Divider.defaultProps = {
absolute: false,
component: 'hr',
inset: false,
light: false
};

View File

@@ -1,24 +1,24 @@
// @flow
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import { fade } from '../styles/colorManipulator';
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
height: 1,
margin: 0, // Reset browser default style.
border: 'none',
flexShrink: 0,
},
default: {
backgroundColor: theme.palette.text.divider,
},
inset: {
marginLeft: 72,
},
default: {
backgroundColor: theme.palette.divider,
},
light: {
backgroundColor: theme.palette.text.lightDivider,
backgroundColor: fade(theme.palette.divider, 0.08),
},
absolute: {
position: 'absolute',
@@ -28,48 +28,58 @@ export const styles = (theme: Object) => ({
},
});
type ProvidedProps = {
classes: Object,
};
export type Props = {
absolute?: boolean,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* If `true`, the divider will be indented.
*/
inset?: boolean,
/**
* If `true`, the divider will have a lighter color.
*/
light?: boolean,
};
function Divider(props: ProvidedProps & Props) {
const { absolute, classes, className: classNameProp, inset, light, ...other } = props;
function Divider(props) {
const {
absolute,
classes,
className: classNameProp,
component: Component,
inset,
light,
...other
} = props;
const className = classNames(
classes.root,
{
[classes.absolute]: absolute,
[classes.inset]: inset,
[light ? classes.light : classes.default]: true,
},
light ? classes.light : classes.default,
classNameProp,
);
return <hr className={className} {...other} />;
return <Component className={className} {...other} />;
}
Divider.propTypes = {
absolute: PropTypes.bool,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
/**
* If `true`, the divider will be indented.
*/
inset: PropTypes.bool,
/**
* If `true`, the divider will have a lighter color.
*/
light: PropTypes.bool,
};
Divider.defaultProps = {
absolute: false,
component: 'hr',
inset: false,
light: false,
};

View File

@@ -1,3 +1 @@
// @flow
export { default } from './Divider';

View File

@@ -1,33 +1,42 @@
import * as React from 'react';
import { StandardProps } from '..';
import { ModalProps, ModalClassKey } from '../internal/Modal';
import { TransitionDuration } from '../internal/transition';
import { ModalProps, ModalClassKey } from '../Modal';
import { SlideProps } from '../transitions/Slide';
import { PaperProps } from '../Paper';
import { Theme } from '../styles/createMuiTheme';
import { TransitionHandlerProps, TransitionProps } from '../transitions/transition';
export interface DrawerProps extends StandardProps<
ModalProps,
DrawerClassKey
> {
export interface DrawerProps
extends StandardProps<
ModalProps & Partial<TransitionHandlerProps>,
DrawerClassKey,
'open' | 'children'
> {
anchor?: 'left' | 'top' | 'right' | 'bottom';
children?: React.ReactNode;
elevation?: number;
transitionDuration?: TransitionDuration;
ModalProps?: Partial<ModalProps>;
open?: boolean;
SlideProps?: SlideProps;
PaperProps?: Partial<PaperProps>;
SlideProps?: Partial<SlideProps>;
theme?: Theme;
type?: 'permanent' | 'persistent' | 'temporary';
transitionDuration?: TransitionProps['timeout'];
variant?: 'permanent' | 'persistent' | 'temporary';
}
export type DrawerClassKey =
| ModalClassKey
| 'paper'
| 'anchorLeft'
| 'anchorRight'
| 'anchorTop'
| 'anchorBottom'
| 'docked'
| 'modal'
;
| 'paper'
| 'paperAnchorLeft'
| 'paperAnchorRight'
| 'paperAnchorTop'
| 'paperAnchorBottom'
| 'paperAnchorDockedLeft'
| 'paperAnchorDockedTop'
| 'paperAnchorDockedRight'
| 'paperAnchorDockedBottom'
| 'modal';
declare const Drawer: React.ComponentType<DrawerProps>;

View File

@@ -41,11 +41,15 @@ var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _Modal = require('../internal/Modal');
var _Modal = require('../Modal');
var _Modal2 = _interopRequireDefault(_Modal);
@@ -67,10 +71,6 @@ var _transitions = require('../styles/transitions');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var babelPluginFlowReactPropTypes_proptype_TransitionDuration = require('../internal/transition').babelPluginFlowReactPropTypes_proptype_TransitionDuration || require('prop-types').any;
function getSlideDirection(anchor) {
if (anchor === 'left') {
return 'right';
@@ -82,7 +82,7 @@ function getSlideDirection(anchor) {
// (anchor === 'bottom')
return 'up';
}
} // @inheritedComponent Modal
var styles = exports.styles = function styles(theme) {
return {
@@ -95,14 +95,17 @@ var styles = exports.styles = function styles(theme) {
flexDirection: 'column',
height: '100vh',
flex: '1 0 auto',
zIndex: theme.zIndex.drawer,
WebkitOverflowScrolling: 'touch', // Add iOS momentum scrolling.
// temporary style
position: 'fixed',
top: 0,
zIndex: theme.zIndex.navDrawer,
willChange: 'transform',
// We disable the focus ring for mouse, touch and keyboard users.
// At some point, it would be better to keep it for keyboard users.
// :focus-ring CSS pseudo-class will help.
'&:focus': {
outline: 'none'
},
WebkitOverflowScrolling: 'touch' // Add iOS momentum scrolling.
}
},
paperAnchorLeft: {
left: 0,
@@ -129,84 +132,21 @@ var styles = exports.styles = function styles(theme) {
maxHeight: '100vh'
},
paperAnchorDockedLeft: {
borderRight: '1px solid ' + theme.palette.text.divider
borderRight: '1px solid ' + theme.palette.divider
},
paperAnchorDockedTop: {
borderBottom: '1px solid ' + theme.palette.divider
},
paperAnchorDockedRight: {
borderLeft: '1px solid ' + theme.palette.text.divider
borderLeft: '1px solid ' + theme.palette.divider
},
paperAnchorDockedBottom: {
borderTop: '1px solid ' + theme.palette.divider
},
modal: {} // Just here so people can override the style.
};
};
var babelPluginFlowReactPropTypes_proptype_Anchor = require('prop-types').oneOf(['left', 'top', 'right', 'bottom']);
var babelPluginFlowReactPropTypes_proptype_Type = require('prop-types').oneOf(['permanent', 'persistent', 'temporary']);
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* Side from which the drawer will appear.
*/
anchor: require('prop-types').oneOf(['left', 'top', 'right', 'bottom']),
/**
* The contents of the drawer.
*/
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node.isRequired ? babelPluginFlowReactPropTypes_proptype_Node.isRequired : babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node).isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* @ignore
*/
className: require('prop-types').string,
/**
* The elevation of the drawer.
*/
elevation: require('prop-types').number,
/**
* The duration for the transition, in milliseconds.
* You may specify a single timeout for all transitions, or individually with an object.
*/
transitionDuration: typeof babelPluginFlowReactPropTypes_proptype_TransitionDuration === 'function' ? babelPluginFlowReactPropTypes_proptype_TransitionDuration : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_TransitionDuration),
/**
* Properties applied to the `Modal` element.
*/
ModalProps: require('prop-types').object,
/**
* Callback fired when the component requests to be closed.
*
* @param {object} event The event source of the callback
*/
onRequestClose: require('prop-types').func,
/**
* If `true`, the drawer is open.
*/
open: require('prop-types').bool,
/**
* @igonre
*/
theme: require('prop-types').object.isRequired,
/**
* Properties applied to the `Slide` element.
*/
SlideProps: require('prop-types').object,
/**
* The type of drawer.
*/
type: require('prop-types').oneOf(['permanent', 'persistent', 'temporary'])
};
var Drawer = function (_React$Component) {
(0, _inherits3.default)(Drawer, _React$Component);
@@ -239,41 +179,39 @@ var Drawer = function (_React$Component) {
}, {
key: 'render',
value: function render() {
var _classNames;
var _props = this.props,
anchorProp = _props.anchor,
children = _props.children,
classes = _props.classes,
className = _props.className,
elevation = _props.elevation,
transitionDuration = _props.transitionDuration,
ModalProps = _props.ModalProps,
onRequestClose = _props.onRequestClose,
onClose = _props.onClose,
open = _props.open,
PaperProps = _props.PaperProps,
SlideProps = _props.SlideProps,
theme = _props.theme,
type = _props.type,
other = (0, _objectWithoutProperties3.default)(_props, ['anchor', 'children', 'classes', 'className', 'elevation', 'transitionDuration', 'ModalProps', 'onRequestClose', 'open', 'SlideProps', 'theme', 'type']);
transitionDuration = _props.transitionDuration,
variant = _props.variant,
other = (0, _objectWithoutProperties3.default)(_props, ['anchor', 'children', 'classes', 'className', 'elevation', 'ModalProps', 'onClose', 'open', 'PaperProps', 'SlideProps', 'theme', 'transitionDuration', 'variant']);
var rtl = theme.direction === 'rtl';
var anchor = anchorProp;
if (rtl && ['left', 'right'].includes(anchor)) {
if (theme.direction === 'rtl' && ['left', 'right'].includes(anchor)) {
anchor = anchor === 'left' ? 'right' : 'left';
}
var drawer = _react2.default.createElement(
_Paper2.default,
{
elevation: type === 'temporary' ? elevation : 0,
(0, _extends3.default)({
elevation: variant === 'temporary' ? elevation : 0,
square: true,
className: (0, _classnames2.default)(classes.paper, (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes['paperAnchor' + (0, _helpers.capitalizeFirstLetter)(anchor)], type !== 'permanent'), (0, _defineProperty3.default)(_classNames, classes['paperAnchorDocked' + (0, _helpers.capitalizeFirstLetter)(anchor)], type !== 'temporary'), _classNames))
},
className: (0, _classnames2.default)(classes.paper, classes['paperAnchor' + (0, _helpers.capitalize)(anchor)], (0, _defineProperty3.default)({}, classes['paperAnchorDocked' + (0, _helpers.capitalize)(anchor)], variant !== 'temporary'))
}, PaperProps),
children
);
if (type === 'permanent') {
if (variant === 'permanent') {
return _react2.default.createElement(
'div',
(0, _extends3.default)({ className: (0, _classnames2.default)(classes.docked, className) }, other),
@@ -292,7 +230,7 @@ var Drawer = function (_React$Component) {
drawer
);
if (type === 'persistent') {
if (variant === 'persistent') {
return _react2.default.createElement(
'div',
(0, _extends3.default)({ className: (0, _classnames2.default)(classes.docked, className) }, other),
@@ -300,14 +238,16 @@ var Drawer = function (_React$Component) {
);
}
// type === temporary
// variant === temporary
return _react2.default.createElement(
_Modal2.default,
(0, _extends3.default)({
BackdropTransitionDuration: transitionDuration,
BackdropProps: {
transitionDuration: transitionDuration
},
className: (0, _classnames2.default)(classes.modal, className),
show: open,
onRequestClose: onRequestClose
open: open,
onClose: onClose
}, other, ModalProps),
slidingDrawer
);
@@ -316,14 +256,70 @@ var Drawer = function (_React$Component) {
return Drawer;
}(_react2.default.Component);
Drawer.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* Side from which the drawer will appear.
*/
anchor: _propTypes2.default.oneOf(['left', 'top', 'right', 'bottom']),
/**
* The contents of the drawer.
*/
children: _propTypes2.default.node,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* The elevation of the drawer.
*/
elevation: _propTypes2.default.number,
/**
* Properties applied to the `Modal` element.
*/
ModalProps: _propTypes2.default.object,
/**
* Callback fired when the component requests to be closed.
*
* @param {object} event The event source of the callback
*/
onClose: _propTypes2.default.func,
/**
* If `true`, the drawer is open.
*/
open: _propTypes2.default.bool,
/**
* Properties applied to the `Paper` element.
*/
PaperProps: _propTypes2.default.object,
/**
* Properties applied to the `Slide` element.
*/
SlideProps: _propTypes2.default.object,
/**
* @ignore
*/
theme: _propTypes2.default.object.isRequired,
/**
* The duration for the transition, in milliseconds.
* You may specify a single timeout for all transitions, or individually with an object.
*/
transitionDuration: _propTypes2.default.oneOfType([_propTypes2.default.number, _propTypes2.default.shape({ enter: _propTypes2.default.number, exit: _propTypes2.default.number })]),
/**
* The type of drawer.
*/
variant: _propTypes2.default.oneOf(['permanent', 'persistent', 'temporary'])
} : {};
Drawer.defaultProps = {
anchor: 'left',
elevation: 16,
transitionDuration: {
enter: _transitions.duration.enteringScreen,
exit: _transitions.duration.leavingScreen
},
open: false,
type: 'temporary' // Mobile first.
transitionDuration: { enter: _transitions.duration.enteringScreen, exit: _transitions.duration.leavingScreen },
variant: 'temporary' // Mobile first.
};
exports.default = (0, _withStyles2.default)(styles, { flip: false, withTheme: true, name: 'MuiDrawer' })(Drawer);
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiDrawer', flip: false, withTheme: true })(Drawer);

View File

@@ -1,15 +1,14 @@
// @flow
// @inheritedComponent Modal
import React from 'react';
import type { Node } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Modal from '../internal/Modal';
import Modal from '../Modal';
import withStyles from '../styles/withStyles';
import Slide from '../transitions/Slide';
import Paper from '../Paper';
import { capitalizeFirstLetter } from '../utils/helpers';
import { capitalize } from '../utils/helpers';
import { duration } from '../styles/transitions';
import type { TransitionDuration } from '../internal/transition';
function getSlideDirection(anchor) {
if (anchor === 'left') {
@@ -24,7 +23,7 @@ function getSlideDirection(anchor) {
return 'up';
}
export const styles = (theme: Object) => ({
export const styles = theme => ({
docked: {
flex: '0 0 auto',
},
@@ -34,14 +33,17 @@ export const styles = (theme: Object) => ({
flexDirection: 'column',
height: '100vh',
flex: '1 0 auto',
zIndex: theme.zIndex.drawer,
WebkitOverflowScrolling: 'touch', // Add iOS momentum scrolling.
// temporary style
position: 'fixed',
top: 0,
zIndex: theme.zIndex.navDrawer,
willChange: 'transform',
// We disable the focus ring for mouse, touch and keyboard users.
// At some point, it would be better to keep it for keyboard users.
// :focus-ring CSS pseudo-class will help.
'&:focus': {
outline: 'none',
},
WebkitOverflowScrolling: 'touch', // Add iOS momentum scrolling.
},
paperAnchorLeft: {
left: 0,
@@ -68,96 +70,21 @@ export const styles = (theme: Object) => ({
maxHeight: '100vh',
},
paperAnchorDockedLeft: {
borderRight: `1px solid ${theme.palette.text.divider}`,
borderRight: `1px solid ${theme.palette.divider}`,
},
paperAnchorDockedTop: {
borderBottom: `1px solid ${theme.palette.divider}`,
},
paperAnchorDockedRight: {
borderLeft: `1px solid ${theme.palette.text.divider}`,
borderLeft: `1px solid ${theme.palette.divider}`,
},
paperAnchorDockedBottom: {
borderTop: `1px solid ${theme.palette.divider}`,
},
modal: {}, // Just here so people can override the style.
});
export type Anchor = 'left' | 'top' | 'right' | 'bottom';
export type Type = 'permanent' | 'persistent' | 'temporary';
type ProvidedProps = {
anchor: Anchor,
classes: Object,
elevation: number,
transitionDuration: TransitionDuration,
open: boolean,
type: Type,
};
export type Props = {
/**
* Side from which the drawer will appear.
*/
anchor?: Anchor,
/**
* The contents of the drawer.
*/
children: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* The elevation of the drawer.
*/
elevation?: number,
/**
* The duration for the transition, in milliseconds.
* You may specify a single timeout for all transitions, or individually with an object.
*/
transitionDuration?: TransitionDuration,
/**
* Properties applied to the `Modal` element.
*/
ModalProps?: Object,
/**
* Callback fired when the component requests to be closed.
*
* @param {object} event The event source of the callback
*/
onRequestClose?: Function,
/**
* If `true`, the drawer is open.
*/
open?: boolean,
/**
* @igonre
*/
theme: Object,
/**
* Properties applied to the `Slide` element.
*/
SlideProps?: Object,
/**
* The type of drawer.
*/
type?: Type,
};
type State = {
firstMount: boolean,
};
class Drawer extends React.Component<ProvidedProps & Props, State> {
static defaultProps = {
anchor: 'left',
elevation: 16,
transitionDuration: {
enter: duration.enteringScreen,
exit: duration.leavingScreen,
},
open: false,
type: 'temporary', // Mobile first.
};
class Drawer extends React.Component {
state = {
// Let's assume that the Drawer will always be rendered on user space.
// We use that state is order to skip the appear transition during the
@@ -178,36 +105,36 @@ class Drawer extends React.Component<ProvidedProps & Props, State> {
classes,
className,
elevation,
transitionDuration,
ModalProps,
onRequestClose,
onClose,
open,
PaperProps,
SlideProps,
theme,
type,
transitionDuration,
variant,
...other
} = this.props;
const rtl = theme.direction === 'rtl';
let anchor = anchorProp;
if (rtl && ['left', 'right'].includes(anchor)) {
if (theme.direction === 'rtl' && ['left', 'right'].includes(anchor)) {
anchor = anchor === 'left' ? 'right' : 'left';
}
const drawer = (
<Paper
elevation={type === 'temporary' ? elevation : 0}
elevation={variant === 'temporary' ? elevation : 0}
square
className={classNames(classes.paper, {
[classes[`paperAnchor${capitalizeFirstLetter(anchor)}`]]: type !== 'permanent',
[classes[`paperAnchorDocked${capitalizeFirstLetter(anchor)}`]]: type !== 'temporary',
className={classNames(classes.paper, classes[`paperAnchor${capitalize(anchor)}`], {
[classes[`paperAnchorDocked${capitalize(anchor)}`]]: variant !== 'temporary',
})}
{...PaperProps}
>
{children}
</Paper>
);
if (type === 'permanent') {
if (variant === 'permanent') {
return (
<div className={classNames(classes.docked, className)} {...other}>
{drawer}
@@ -227,7 +154,7 @@ class Drawer extends React.Component<ProvidedProps & Props, State> {
</Slide>
);
if (type === 'persistent') {
if (variant === 'persistent') {
return (
<div className={classNames(classes.docked, className)} {...other}>
{slidingDrawer}
@@ -235,13 +162,15 @@ class Drawer extends React.Component<ProvidedProps & Props, State> {
);
}
// type === temporary
// variant === temporary
return (
<Modal
BackdropTransitionDuration={transitionDuration}
BackdropProps={{
transitionDuration,
}}
className={classNames(classes.modal, className)}
show={open}
onRequestClose={onRequestClose}
open={open}
onClose={onClose}
{...other}
{...ModalProps}
>
@@ -251,4 +180,73 @@ class Drawer extends React.Component<ProvidedProps & Props, State> {
}
}
export default withStyles(styles, { flip: false, withTheme: true, name: 'MuiDrawer' })(Drawer);
Drawer.propTypes = {
/**
* Side from which the drawer will appear.
*/
anchor: PropTypes.oneOf(['left', 'top', 'right', 'bottom']),
/**
* The contents of the drawer.
*/
children: PropTypes.node,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The elevation of the drawer.
*/
elevation: PropTypes.number,
/**
* Properties applied to the `Modal` element.
*/
ModalProps: PropTypes.object,
/**
* Callback fired when the component requests to be closed.
*
* @param {object} event The event source of the callback
*/
onClose: PropTypes.func,
/**
* If `true`, the drawer is open.
*/
open: PropTypes.bool,
/**
* Properties applied to the `Paper` element.
*/
PaperProps: PropTypes.object,
/**
* Properties applied to the `Slide` element.
*/
SlideProps: PropTypes.object,
/**
* @ignore
*/
theme: PropTypes.object.isRequired,
/**
* 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 }),
]),
/**
* The type of drawer.
*/
variant: PropTypes.oneOf(['permanent', 'persistent', 'temporary']),
};
Drawer.defaultProps = {
anchor: 'left',
elevation: 16,
open: false,
transitionDuration: { enter: duration.enteringScreen, exit: duration.leavingScreen },
variant: 'temporary', // Mobile first.
};
export default withStyles(styles, { name: 'MuiDrawer', flip: false, withTheme: true })(Drawer);

View File

@@ -1,3 +1 @@
// @flow
export { default } from './Drawer';

View File

@@ -0,0 +1,19 @@
import * as React from 'react';
import { StandardProps } from '..';
import { CollapseProps } from '../transitions/Collapse';
import { PaperProps, PaperClassKey } from '../Paper';
export interface ExpansionPanelProps
extends StandardProps<PaperProps, ExpansionPanelClassKey, 'onChange'> {
CollapseProps?: React.ComponentType<CollapseProps>;
defaultExpanded?: boolean;
disabled?: boolean;
expanded?: boolean;
onChange?: (event: React.ChangeEvent<{}>, expanded: boolean) => void;
}
export type ExpansionPanelClassKey = PaperClassKey | 'disabled' | 'expanded';
declare const ExpansionPanel: React.ComponentType<ExpansionPanelProps>;
export default ExpansionPanel;

View File

@@ -0,0 +1,278 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.styles = undefined;
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _Collapse = require('../transitions/Collapse');
var _Collapse2 = _interopRequireDefault(_Collapse);
var _Paper = require('../Paper');
var _Paper2 = _interopRequireDefault(_Paper);
var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
var _reactHelpers = require('../utils/reactHelpers');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var styles = exports.styles = function styles(theme) {
var transition = {
duration: theme.transitions.duration.shortest
};
return {
root: {
position: 'relative',
transition: theme.transitions.create(['margin'], transition),
'&:before': {
position: 'absolute',
left: 0,
top: -1,
right: 0,
height: 1,
content: '""',
opacity: 1,
backgroundColor: theme.palette.divider,
transition: theme.transitions.create(['opacity', 'background-color'], transition)
},
'&:first-child': {
borderTopLeftRadius: 2,
borderTopRightRadius: 2,
'&:before': {
display: 'none'
}
},
'&:last-child': {
borderBottomLeftRadius: 2,
borderBottomRightRadius: 2
},
'&$expanded + &': {
'&:before': {
display: 'none'
}
}
},
expanded: {
margin: theme.spacing.unit * 2 + 'px 0',
'&:first-child': {
marginTop: 0
},
'&:last-child': {
marginBottom: 0
},
'&:before': {
opacity: 0
}
},
disabled: {
backgroundColor: theme.palette.action.disabledBackground
}
};
}; // @inheritedComponent Paper
var ExpansionPanel = function (_React$Component) {
(0, _inherits3.default)(ExpansionPanel, _React$Component);
function ExpansionPanel() {
var _ref;
var _temp, _this, _ret;
(0, _classCallCheck3.default)(this, ExpansionPanel);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = ExpansionPanel.__proto__ || (0, _getPrototypeOf2.default)(ExpansionPanel)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
expanded: false
}, _this.isControlled = null, _this.handleChange = function (event) {
var onChange = _this.props.onChange;
var expanded = !_this.state.expanded;
if (onChange) {
onChange(event, expanded);
}
if (!_this.isControlled) {
_this.setState({ expanded: expanded });
}
}, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
}
(0, _createClass3.default)(ExpansionPanel, [{
key: 'componentWillMount',
value: function componentWillMount() {
var _props = this.props,
expanded = _props.expanded,
defaultExpanded = _props.defaultExpanded;
this.isControlled = expanded != null;
this.setState({
expanded: this.isControlled ? expanded : defaultExpanded
});
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
if (this.isControlled) {
this.setState({
expanded: nextProps.expanded
});
}
}
}, {
key: 'render',
value: function render() {
var _classNames,
_this2 = this;
var _props2 = this.props,
childrenProp = _props2.children,
classes = _props2.classes,
classNameProp = _props2.className,
CollapsePropsProp = _props2.CollapseProps,
defaultExpanded = _props2.defaultExpanded,
disabled = _props2.disabled,
expandedProp = _props2.expanded,
onChange = _props2.onChange,
other = (0, _objectWithoutProperties3.default)(_props2, ['children', 'classes', 'className', 'CollapseProps', 'defaultExpanded', 'disabled', 'expanded', 'onChange']);
var expanded = this.state.expanded;
var className = (0, _classnames2.default)(classes.root, (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes.expanded, expanded), (0, _defineProperty3.default)(_classNames, classes.disabled, disabled), _classNames), classNameProp);
var summary = null;
var children = _react2.default.Children.map(childrenProp, function (child) {
if (!_react2.default.isValidElement(child)) {
return null;
}
if ((0, _reactHelpers.isMuiElement)(child, ['ExpansionPanelSummary'])) {
summary = _react2.default.cloneElement(child, {
disabled: disabled,
expanded: expanded,
onChange: _this2.handleChange
});
return null;
}
return child;
});
var CollapseProps = !expanded ? {
'aria-hidden': 'true'
} : null;
return _react2.default.createElement(
_Paper2.default,
(0, _extends3.default)({ className: className, elevation: 1, square: true }, other),
summary,
_react2.default.createElement(
_Collapse2.default,
(0, _extends3.default)({ 'in': expanded, timeout: 'auto' }, CollapseProps, CollapsePropsProp),
children
)
);
}
}]);
return ExpansionPanel;
}(_react2.default.Component);
ExpansionPanel.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the expansion panel.
*/
children: _propTypes2.default.node.isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* Properties applied to the `Collapse` element.
*/
CollapseProps: _propTypes2.default.object,
/**
* If `true`, expands the panel by default.
*/
defaultExpanded: _propTypes2.default.bool,
/**
* If `true`, the panel will be displayed in a disabled state.
*/
disabled: _propTypes2.default.bool,
/**
* If `true`, expands the panel, otherwise collapse it.
* Setting this prop enables control over the panel.
*/
expanded: _propTypes2.default.bool,
/**
* Callback fired when the expand/collapse state is changed.
*
* @param {object} event The event source of the callback
* @param {boolean} expanded The `expanded` state of the panel
*/
onChange: _propTypes2.default.func
} : {};
ExpansionPanel.defaultProps = {
defaultExpanded: false,
disabled: false
};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiExpansionPanel' })(ExpansionPanel);

View File

@@ -0,0 +1,205 @@
// @inheritedComponent Paper
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Collapse from '../transitions/Collapse';
import Paper from '../Paper';
import withStyles from '../styles/withStyles';
import { isMuiElement } from '../utils/reactHelpers';
export const styles = theme => {
const transition = {
duration: theme.transitions.duration.shortest,
};
return {
root: {
position: 'relative',
transition: theme.transitions.create(['margin'], transition),
'&:before': {
position: 'absolute',
left: 0,
top: -1,
right: 0,
height: 1,
content: '""',
opacity: 1,
backgroundColor: theme.palette.divider,
transition: theme.transitions.create(['opacity', 'background-color'], transition),
},
'&:first-child': {
borderTopLeftRadius: 2,
borderTopRightRadius: 2,
'&:before': {
display: 'none',
},
},
'&:last-child': {
borderBottomLeftRadius: 2,
borderBottomRightRadius: 2,
},
'&$expanded + &': {
'&:before': {
display: 'none',
},
},
},
expanded: {
margin: `${theme.spacing.unit * 2}px 0`,
'&:first-child': {
marginTop: 0,
},
'&:last-child': {
marginBottom: 0,
},
'&:before': {
opacity: 0,
},
},
disabled: {
backgroundColor: theme.palette.action.disabledBackground,
},
};
};
class ExpansionPanel extends React.Component {
state = {
expanded: false,
};
componentWillMount() {
const { expanded, defaultExpanded } = this.props;
this.isControlled = expanded != null;
this.setState({
expanded: this.isControlled ? expanded : defaultExpanded,
});
}
componentWillReceiveProps(nextProps) {
if (this.isControlled) {
this.setState({
expanded: nextProps.expanded,
});
}
}
isControlled = null;
handleChange = event => {
const { onChange } = this.props;
const expanded = !this.state.expanded;
if (onChange) {
onChange(event, expanded);
}
if (!this.isControlled) {
this.setState({ expanded });
}
};
render() {
const {
children: childrenProp,
classes,
className: classNameProp,
CollapseProps: CollapsePropsProp,
defaultExpanded,
disabled,
expanded: expandedProp,
onChange,
...other
} = this.props;
const { expanded } = this.state;
const className = classNames(
classes.root,
{
[classes.expanded]: expanded,
[classes.disabled]: disabled,
},
classNameProp,
);
let summary = null;
const children = React.Children.map(childrenProp, child => {
if (!React.isValidElement(child)) {
return null;
}
if (isMuiElement(child, ['ExpansionPanelSummary'])) {
summary = React.cloneElement(child, {
disabled,
expanded,
onChange: this.handleChange,
});
return null;
}
return child;
});
const CollapseProps = !expanded
? {
'aria-hidden': 'true',
}
: null;
return (
<Paper className={className} elevation={1} square {...other}>
{summary}
<Collapse in={expanded} timeout="auto" {...CollapseProps} {...CollapsePropsProp}>
{children}
</Collapse>
</Paper>
);
}
}
ExpansionPanel.propTypes = {
/**
* The content of the expansion panel.
*/
children: PropTypes.node.isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* Properties applied to the `Collapse` element.
*/
CollapseProps: PropTypes.object,
/**
* If `true`, expands the panel by default.
*/
defaultExpanded: PropTypes.bool,
/**
* If `true`, the panel will be displayed in a disabled state.
*/
disabled: PropTypes.bool,
/**
* If `true`, expands the panel, otherwise collapse it.
* Setting this prop enables control over the panel.
*/
expanded: PropTypes.bool,
/**
* Callback fired when the expand/collapse state is changed.
*
* @param {object} event The event source of the callback
* @param {boolean} expanded The `expanded` state of the panel
*/
onChange: PropTypes.func,
};
ExpansionPanel.defaultProps = {
defaultExpanded: false,
disabled: false,
};
export default withStyles(styles, { name: 'MuiExpansionPanel' })(ExpansionPanel);

View File

@@ -0,0 +1,11 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface ExpansionPanelActionsProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, ExpansionPanelActionsClassKey> {}
export type ExpansionPanelActionsClassKey = 'root' | 'action';
declare const ExpansionPanelActions: React.ComponentType<ExpansionPanelActionsProps>;
export default ExpansionPanelActions;

View File

@@ -0,0 +1,79 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.styles = undefined;
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
var _reactHelpers = require('../utils/reactHelpers');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var styles = exports.styles = function styles(theme) {
return {
root: {
display: 'flex',
justifyContent: 'flex-end',
alignItems: 'center',
padding: theme.spacing.unit * 2 + 'px ' + theme.spacing.unit + 'px'
},
action: {
marginLeft: theme.spacing.unit
}
};
};
function ExpansionPanelActions(props) {
var children = props.children,
classes = props.classes,
className = props.className,
other = (0, _objectWithoutProperties3.default)(props, ['children', 'classes', 'className']);
return _react2.default.createElement(
'div',
(0, _extends3.default)({ className: (0, _classnames2.default)(classes.root, className) }, other),
(0, _reactHelpers.cloneChildrenWithClassName)(children, classes.action)
);
}
ExpansionPanelActions.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the component.
*/
children: _propTypes2.default.node.isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string
} : {};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiExpansionPanelActions' })(ExpansionPanelActions);

View File

@@ -0,0 +1,44 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import { cloneChildrenWithClassName } from '../utils/reactHelpers';
export const styles = theme => ({
root: {
display: 'flex',
justifyContent: 'flex-end',
alignItems: 'center',
padding: `${theme.spacing.unit * 2}px ${theme.spacing.unit}px`,
},
action: {
marginLeft: theme.spacing.unit,
},
});
function ExpansionPanelActions(props) {
const { children, classes, className, ...other } = props;
return (
<div className={classNames(classes.root, className)} {...other}>
{cloneChildrenWithClassName(children, classes.action)}
</div>
);
}
ExpansionPanelActions.propTypes = {
/**
* 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,
};
export default withStyles(styles, { name: 'MuiExpansionPanelActions' })(ExpansionPanelActions);

View File

@@ -0,0 +1,11 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface ExpansionPanelDetailsProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, ExpansionPanelDetailsClassKey> {}
export type ExpansionPanelDetailsClassKey = 'root';
declare const ExpansionPanelDetails: React.ComponentType<ExpansionPanelDetailsProps>;
export default ExpansionPanelDetails;

View File

@@ -0,0 +1,73 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.styles = undefined;
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var styles = exports.styles = function styles(theme) {
return {
root: {
display: 'flex',
flexGrow: 1,
padding: theme.spacing.unit + 'px ' + theme.spacing.unit * 3 + 'px ' + theme.spacing.unit * 3 + 'px'
}
};
};
function ExpansionPanelDetails(props) {
var classes = props.classes,
children = props.children,
className = props.className,
other = (0, _objectWithoutProperties3.default)(props, ['classes', 'children', 'className']);
return _react2.default.createElement(
'div',
(0, _extends3.default)({ className: (0, _classnames2.default)(classes.root, className) }, other),
children
);
}
ExpansionPanelDetails.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the expansion panel details.
*/
children: _propTypes2.default.node.isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string
} : {};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiExpansionPanelDetails' })(ExpansionPanelDetails);

View File

@@ -0,0 +1,39 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
export const styles = theme => ({
root: {
display: 'flex',
flexGrow: 1,
padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px ${theme.spacing.unit * 3}px`,
},
});
function ExpansionPanelDetails(props) {
const { classes, children, className, ...other } = props;
return (
<div className={classNames(classes.root, className)} {...other}>
{children}
</div>
);
}
ExpansionPanelDetails.propTypes = {
/**
* The content of the expansion panel details.
*/
children: PropTypes.node.isRequired,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
};
export default withStyles(styles, { name: 'MuiExpansionPanelDetails' })(ExpansionPanelDetails);

View File

@@ -0,0 +1,25 @@
import * as React from 'react';
import { StandardProps } from '..';
import { ButtonBaseProps, ButtonBaseClassKey } from '../ButtonBase';
export interface ExpansionPanelSummaryProps
extends StandardProps<ButtonBaseProps, ExpansionPanelSummaryClassKey> {
disabled?: boolean;
expanded?: boolean;
expandIcon?: React.ReactNode;
onChange?: React.ReactEventHandler<{}>;
}
export type ExpansionPanelSummaryClassKey =
| ButtonBaseClassKey
| 'expanded'
| 'focused'
| 'disabled'
| 'content'
| 'contentExpanded'
| 'expandIcon'
| 'expandIconExpanded';
declare const ExpansionPanelSummary: React.ComponentType<ExpansionPanelSummaryProps>;
export default ExpansionPanelSummary;

View File

@@ -0,0 +1,250 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.styles = undefined;
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _ButtonBase = require('../ButtonBase');
var _ButtonBase2 = _interopRequireDefault(_ButtonBase);
var _IconButton = require('../IconButton');
var _IconButton2 = _interopRequireDefault(_IconButton);
var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// @inheritedComponent ButtonBase
var styles = exports.styles = function styles(theme) {
var transition = {
duration: theme.transitions.duration.shortest
};
return {
root: {
display: 'flex',
minHeight: theme.spacing.unit * 6,
transition: theme.transitions.create(['min-height', 'background-color'], transition),
padding: '0 ' + theme.spacing.unit * 3 + 'px 0 ' + theme.spacing.unit * 3 + 'px',
'&:hover:not($disabled)': {
cursor: 'pointer'
}
},
expanded: {
minHeight: 64
},
focused: {
backgroundColor: theme.palette.grey[300]
},
disabled: {
opacity: 0.38
},
content: {
display: 'flex',
flexGrow: 1,
transition: theme.transitions.create(['margin'], transition),
margin: '12px 0',
'& > :last-child': {
paddingRight: theme.spacing.unit * 4
}
},
contentExpanded: {
margin: '20px 0'
},
expandIcon: {
position: 'absolute',
top: '50%',
right: theme.spacing.unit,
transform: 'translateY(-50%) rotate(0deg)',
transition: theme.transitions.create('transform', transition)
},
expandIconExpanded: {
transform: 'translateY(-50%) rotate(180deg)'
}
};
};
var ExpansionPanelSummary = function (_React$Component) {
(0, _inherits3.default)(ExpansionPanelSummary, _React$Component);
function ExpansionPanelSummary() {
var _ref;
var _temp, _this, _ret;
(0, _classCallCheck3.default)(this, ExpansionPanelSummary);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = ExpansionPanelSummary.__proto__ || (0, _getPrototypeOf2.default)(ExpansionPanelSummary)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
focused: false
}, _this.handleFocus = function () {
_this.setState({
focused: true
});
}, _this.handleBlur = function () {
_this.setState({
focused: false
});
}, _this.handleChange = function (event) {
var _this$props = _this.props,
onChange = _this$props.onChange,
onClick = _this$props.onClick;
if (onChange) {
onChange(event);
}
if (onClick) {
onClick(event);
}
}, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
}
(0, _createClass3.default)(ExpansionPanelSummary, [{
key: 'render',
value: function render() {
var _classNames;
var _props = this.props,
children = _props.children,
classes = _props.classes,
className = _props.className,
disabled = _props.disabled,
expanded = _props.expanded,
expandIcon = _props.expandIcon,
onChange = _props.onChange,
other = (0, _objectWithoutProperties3.default)(_props, ['children', 'classes', 'className', 'disabled', 'expanded', 'expandIcon', 'onChange']);
var focused = this.state.focused;
return _react2.default.createElement(
_ButtonBase2.default,
(0, _extends3.default)({
focusRipple: false,
disableRipple: true,
disabled: disabled,
component: 'div',
'aria-expanded': expanded,
className: (0, _classnames2.default)(classes.root, (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes.disabled, disabled), (0, _defineProperty3.default)(_classNames, classes.expanded, expanded), (0, _defineProperty3.default)(_classNames, classes.focused, focused), _classNames), className)
}, other, {
onKeyboardFocus: this.handleFocus,
onBlur: this.handleBlur,
onClick: this.handleChange
}),
_react2.default.createElement(
'div',
{ className: (0, _classnames2.default)(classes.content, (0, _defineProperty3.default)({}, classes.contentExpanded, expanded)) },
children
),
expandIcon && _react2.default.createElement(
_IconButton2.default,
{
disabled: disabled,
className: (0, _classnames2.default)(classes.expandIcon, (0, _defineProperty3.default)({}, classes.expandIconExpanded, expanded)),
component: 'div',
tabIndex: -1,
'aria-hidden': 'true'
},
expandIcon
)
);
}
}]);
return ExpansionPanelSummary;
}(_react2.default.Component);
ExpansionPanelSummary.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the expansion panel summary.
*/
children: _propTypes2.default.node,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* @ignore
* If `true`, the summary will be displayed in a disabled state.
*/
disabled: _propTypes2.default.bool,
/**
* @ignore
* If `true`, expands the summary, otherwise collapse it.
*/
expanded: _propTypes2.default.bool,
/**
* The icon to display as the expand indicator.
*/
expandIcon: _propTypes2.default.node,
/**
* @ignore
*/
onChange: _propTypes2.default.func,
/**
* @ignore
*/
onClick: _propTypes2.default.func
} : {};
ExpansionPanelSummary.defaultProps = {
disabled: false
};
ExpansionPanelSummary.muiName = 'ExpansionPanelSummary';
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiExpansionPanelSummary' })(ExpansionPanelSummary);

View File

@@ -0,0 +1,183 @@
// @inheritedComponent ButtonBase
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import ButtonBase from '../ButtonBase';
import IconButton from '../IconButton';
import withStyles from '../styles/withStyles';
export const styles = theme => {
const transition = {
duration: theme.transitions.duration.shortest,
};
return {
root: {
display: 'flex',
minHeight: theme.spacing.unit * 6,
transition: theme.transitions.create(['min-height', 'background-color'], transition),
padding: `0 ${theme.spacing.unit * 3}px 0 ${theme.spacing.unit * 3}px`,
'&:hover:not($disabled)': {
cursor: 'pointer',
},
},
expanded: {
minHeight: 64,
},
focused: {
backgroundColor: theme.palette.grey[300],
},
disabled: {
opacity: 0.38,
},
content: {
display: 'flex',
flexGrow: 1,
transition: theme.transitions.create(['margin'], transition),
margin: '12px 0',
'& > :last-child': {
paddingRight: theme.spacing.unit * 4,
},
},
contentExpanded: {
margin: '20px 0',
},
expandIcon: {
position: 'absolute',
top: '50%',
right: theme.spacing.unit,
transform: 'translateY(-50%) rotate(0deg)',
transition: theme.transitions.create('transform', transition),
},
expandIconExpanded: {
transform: 'translateY(-50%) rotate(180deg)',
},
};
};
class ExpansionPanelSummary extends React.Component {
state = {
focused: false,
};
handleFocus = () => {
this.setState({
focused: true,
});
};
handleBlur = () => {
this.setState({
focused: false,
});
};
handleChange = event => {
const { onChange, onClick } = this.props;
if (onChange) {
onChange(event);
}
if (onClick) {
onClick(event);
}
};
render() {
const {
children,
classes,
className,
disabled,
expanded,
expandIcon,
onChange,
...other
} = this.props;
const { focused } = this.state;
return (
<ButtonBase
focusRipple={false}
disableRipple
disabled={disabled}
component="div"
aria-expanded={expanded}
className={classNames(
classes.root,
{
[classes.disabled]: disabled,
[classes.expanded]: expanded,
[classes.focused]: focused,
},
className,
)}
{...other}
onKeyboardFocus={this.handleFocus}
onBlur={this.handleBlur}
onClick={this.handleChange}
>
<div className={classNames(classes.content, { [classes.contentExpanded]: expanded })}>
{children}
</div>
{expandIcon && (
<IconButton
disabled={disabled}
className={classNames(classes.expandIcon, {
[classes.expandIconExpanded]: expanded,
})}
component="div"
tabIndex={-1}
aria-hidden="true"
>
{expandIcon}
</IconButton>
)}
</ButtonBase>
);
}
}
ExpansionPanelSummary.propTypes = {
/**
* The content of the expansion panel summary.
*/
children: PropTypes.node,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* @ignore
* If `true`, the summary will be displayed in a disabled state.
*/
disabled: PropTypes.bool,
/**
* @ignore
* If `true`, expands the summary, otherwise collapse it.
*/
expanded: PropTypes.bool,
/**
* The icon to display as the expand indicator.
*/
expandIcon: PropTypes.node,
/**
* @ignore
*/
onChange: PropTypes.func,
/**
* @ignore
*/
onClick: PropTypes.func,
};
ExpansionPanelSummary.defaultProps = {
disabled: false,
};
ExpansionPanelSummary.muiName = 'ExpansionPanelSummary';
export default withStyles(styles, { name: 'MuiExpansionPanelSummary' })(ExpansionPanelSummary);

Some files were not shown because too many files have changed in this diff Show More