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