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

@@ -1,21 +1,19 @@
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
// weak
import _extends from 'babel-runtime/helpers/extends';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import { capitalizeFirstLetter } from '../utils/helpers';
import { capitalize } from '../utils/helpers';
const RADIUS = 12;
export const styles = theme => ({
root: {
position: 'relative',
display: 'inline-flex'
display: 'inline-flex',
// For correct alignment with the text.
verticalAlign: 'middle'
},
badge: {
display: 'flex',
@@ -38,26 +36,37 @@ export const 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
}
});
function Badge(props) {
const { badgeContent, classes, className: classNameProp, color, children } = props,
other = _objectWithoutProperties(props, ['badgeContent', 'classes', 'className', 'color', 'children']);
const className = classNames(classes.root, classNameProp);
const {
badgeContent,
children,
classes,
className: classNameProp,
color,
component: ComponentProp
} = props,
other = _objectWithoutProperties(props, ['badgeContent', 'children', 'classes', 'className', 'color', 'component']);
const badgeClassName = classNames(classes.badge, {
[classes[`color${capitalizeFirstLetter(color)}`]]: color !== 'default'
[classes[`color${capitalize(color)}`]]: color !== 'default'
});
return React.createElement(
'div',
_extends({ className: className }, other),
ComponentProp,
_extends({ className: classNames(classes.root, classNameProp) }, other),
children,
React.createElement(
'span',
@@ -67,8 +76,37 @@ function Badge(props) {
);
}
Badge.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* 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'
color: 'default',
component: 'span'
};
export default withStyles(styles, { name: 'MuiBadge' })(Badge);