Completely updated React, fixed #11, (hopefully)

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

View File

@@ -1,24 +1,18 @@
import * as React from 'react';
import { StandardProps } from '..';
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';