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,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';