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

@@ -2,18 +2,16 @@ import * as React from 'react';
import { StandardProps, PropTypes } from '..';
import { Style, TextStyle } from '../styles/createTypography';
export interface TypographyProps extends StandardProps<
React.HTMLAttributes<HTMLElement>,
TypographyClassKey
> {
export interface TypographyProps
extends StandardProps<React.HTMLAttributes<HTMLElement>, TypographyClassKey> {
align?: PropTypes.Alignment;
component?: React.ReactType;
color?: PropTypes.Color | 'secondary' | 'error';
color?: PropTypes.Color | 'textSecondary' | 'error';
component?: React.ReactType<TypographyProps>;
gutterBottom?: boolean;
headlineMapping?: { [type in TextStyle]: string };
noWrap?: boolean;
paragraph?: boolean;
type?: Style | 'caption' | 'button';
variant?: Style | 'caption' | 'button';
}
export type TypographyClassKey =
@@ -38,8 +36,7 @@ export type TypographyClassKey =
| 'paragraph'
| 'colorInherit'
| 'colorSecondary'
| 'colorAccent'
;
| 'colorTextSecondary';
declare const Typography: React.ComponentType<TypographyProps>;

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);
@@ -35,10 +37,6 @@ 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 babelPluginFlowReactPropTypes_proptype_ElementType = require('react').babelPluginFlowReactPropTypes_proptype_ElementType || require('prop-types').any;
var styles = exports.styles = function styles(theme) {
return {
root: {
@@ -83,77 +81,20 @@ var styles = exports.styles = function styles(theme) {
color: 'inherit'
},
colorPrimary: {
color: theme.palette.primary[500]
color: theme.palette.primary.main
},
colorSecondary: {
color: theme.palette.secondary.main
},
colorTextSecondary: {
color: theme.palette.text.secondary
},
colorAccent: {
color: theme.palette.secondary.A400
},
colorError: {
color: theme.palette.error.A400
color: theme.palette.error.main
}
};
};
var babelPluginFlowReactPropTypes_proptype_Type = require('prop-types').oneOf(['display4', 'display3', 'display2', 'display1', 'headline', 'title', 'subheading', 'body2', 'body1', 'caption', 'button']);
var babelPluginFlowReactPropTypes_proptype_Props = {
align: require('prop-types').oneOf(['inherit', 'left', 'center', 'right', 'justify']),
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.
* By default we map the type to a good default headline component.
*/
component: typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType),
/**
* The color of the component. It's using the theme palette when that makes sense.
*/
color: require('prop-types').oneOf(['inherit', 'primary', 'secondary', 'accent', 'error', 'default']),
/**
* If `true`, the text will have a bottom margin.
*/
gutterBottom: require('prop-types').bool,
/**
* We are empirically mapping the type property to a range of different DOM element type.
* For instance, h1 to h6. If you wish to change that mapping, you can provide your own.
* Alternatively, you can use the `component` property.
*/
headlineMapping: require('prop-types').shape({}),
/**
* If `true`, the text will not wrap, but instead will truncate with an ellipsis.
*/
noWrap: require('prop-types').bool,
/**
* If `true`, the text will have a bottom margin.
*/
paragraph: require('prop-types').bool,
/**
* Applies the theme typography styles.
*/
type: require('prop-types').oneOf(['display4', 'display3', 'display2', 'display1', 'headline', 'title', 'subheading', 'body2', 'body1', 'caption', 'button'])
};
function Typography(props) {
var _classNames;
@@ -166,24 +107,68 @@ function Typography(props) {
headlineMapping = props.headlineMapping,
noWrap = props.noWrap,
paragraph = props.paragraph,
type = props.type,
other = (0, _objectWithoutProperties3.default)(props, ['align', 'classes', 'className', 'component', 'color', 'gutterBottom', 'headlineMapping', 'noWrap', 'paragraph', 'type']);
variant = props.variant,
other = (0, _objectWithoutProperties3.default)(props, ['align', 'classes', 'className', 'component', 'color', 'gutterBottom', 'headlineMapping', 'noWrap', 'paragraph', 'variant']);
var className = (0, _classnames2.default)(classes.root, classes[type], (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes['color' + (0, _helpers.capitalizeFirstLetter)(color)], color !== 'default'), (0, _defineProperty3.default)(_classNames, classes.noWrap, noWrap), (0, _defineProperty3.default)(_classNames, classes.gutterBottom, gutterBottom), (0, _defineProperty3.default)(_classNames, classes.paragraph, paragraph), (0, _defineProperty3.default)(_classNames, classes['align' + (0, _helpers.capitalizeFirstLetter)(align)], align !== 'inherit'), _classNames), classNameProp);
var className = (0, _classnames2.default)(classes.root, classes[variant], (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes['color' + (0, _helpers.capitalize)(color)], color !== 'default'), (0, _defineProperty3.default)(_classNames, classes.noWrap, noWrap), (0, _defineProperty3.default)(_classNames, classes.gutterBottom, gutterBottom), (0, _defineProperty3.default)(_classNames, classes.paragraph, paragraph), (0, _defineProperty3.default)(_classNames, classes['align' + (0, _helpers.capitalize)(align)], align !== 'inherit'), _classNames), classNameProp);
var Component = componentProp || (paragraph ? 'p' : headlineMapping[type]) || 'span';
var Component = componentProp || (paragraph ? 'p' : headlineMapping[variant]) || 'span';
return _react2.default.createElement(Component, (0, _extends3.default)({ className: className }, other));
}
Typography.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
headlineMapping: require('prop-types').shape({}).isRequired,
type: require('prop-types').oneOf(['display4', 'display3', 'display2', 'display1', 'headline', 'title', 'subheading', 'body2', 'body1', 'caption', 'button']).isRequired,
align: require('prop-types').oneOf(['inherit', 'left', 'center', 'right', 'justify']),
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, 'component', typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType)), (0, _defineProperty3.default)(_ref, 'color', require('prop-types').oneOf(['inherit', 'primary', 'secondary', 'accent', 'error', 'default'])), (0, _defineProperty3.default)(_ref, 'gutterBottom', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'headlineMapping', require('prop-types').shape({})), (0, _defineProperty3.default)(_ref, 'noWrap', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'paragraph', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'type', require('prop-types').oneOf(['display4', 'display3', 'display2', 'display1', 'headline', 'title', 'subheading', 'body2', 'body1', 'caption', 'button'])), _ref) : {};
Typography.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* Set the text-align on the component.
*/
align: _propTypes2.default.oneOf(['inherit', 'left', 'center', 'right', 'justify']),
/**
* 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 color of the component. It supports those theme colors that make sense for this component.
*/
color: _propTypes2.default.oneOf(['inherit', 'primary', 'textSecondary', 'secondary', 'error', 'default']),
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
* By default, it maps the variant to a good default headline component.
*/
component: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func]),
/**
* If `true`, the text will have a bottom margin.
*/
gutterBottom: _propTypes2.default.bool,
/**
* We are empirically mapping the variant property to a range of different DOM element types.
* For instance, h1 to h6. If you wish to change that mapping, you can provide your own.
* Alternatively, you can use the `component` property.
*/
headlineMapping: _propTypes2.default.object,
/**
* If `true`, the text will not wrap, but instead will truncate with an ellipsis.
*/
noWrap: _propTypes2.default.bool,
/**
* If `true`, the text will have a bottom margin.
*/
paragraph: _propTypes2.default.bool,
/**
* Applies the theme typography styles.
*/
variant: _propTypes2.default.oneOf(['display4', 'display3', 'display2', 'display1', 'headline', 'title', 'subheading', 'body2', 'body1', 'caption', 'button'])
} : {};
Typography.defaultProps = {
align: 'inherit',
color: 'default',
@@ -201,7 +186,7 @@ Typography.defaultProps = {
},
noWrap: false,
paragraph: false,
type: 'body1'
variant: 'body1'
};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiTypography' })(Typography);

View File

@@ -1,12 +1,10 @@
// @flow
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 { capitalizeFirstLetter } from '../utils/helpers';
import { capitalize } from '../utils/helpers';
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
display: 'block',
margin: 0,
@@ -49,84 +47,20 @@ export const styles = (theme: Object) => ({
color: 'inherit',
},
colorPrimary: {
color: theme.palette.primary[500],
color: theme.palette.primary.main,
},
colorSecondary: {
color: theme.palette.secondary.main,
},
colorTextSecondary: {
color: theme.palette.text.secondary,
},
colorAccent: {
color: theme.palette.secondary.A400,
},
colorError: {
color: theme.palette.error.A400,
color: theme.palette.error.main,
},
});
export type Type =
| 'display4'
| 'display3'
| 'display2'
| 'display1'
| 'headline'
| 'title'
| 'subheading'
| 'body2'
| 'body1'
| 'caption'
| 'button';
type ProvidedProps = {
classes: Object,
headlineMapping: { [key: Type]: string },
type: Type,
};
export type Props = {
align?: 'inherit' | 'left' | 'center' | 'right' | 'justify',
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.
* By default we map the type to a good default headline component.
*/
component?: ElementType,
/**
* The color of the component. It's using the theme palette when that makes sense.
*/
color?: 'inherit' | 'primary' | 'secondary' | 'accent' | 'error' | 'default',
/**
* If `true`, the text will have a bottom margin.
*/
gutterBottom?: boolean,
/**
* We are empirically mapping the type property to a range of different DOM element type.
* For instance, h1 to h6. If you wish to change that mapping, you can provide your own.
* Alternatively, you can use the `component` property.
*/
headlineMapping?: { [key: Type]: string },
/**
* If `true`, the text will not wrap, but instead will truncate with an ellipsis.
*/
noWrap?: boolean,
/**
* If `true`, the text will have a bottom margin.
*/
paragraph?: boolean,
/**
* Applies the theme typography styles.
*/
type?: Type,
};
function Typography(props: ProvidedProps & Props) {
function Typography(props) {
const {
align,
classes,
@@ -137,28 +71,91 @@ function Typography(props: ProvidedProps & Props) {
headlineMapping,
noWrap,
paragraph,
type,
variant,
...other
} = props;
const className = classNames(
classes.root,
classes[type],
classes[variant],
{
[classes[`color${capitalizeFirstLetter(color)}`]]: color !== 'default',
[classes[`color${capitalize(color)}`]]: color !== 'default',
[classes.noWrap]: noWrap,
[classes.gutterBottom]: gutterBottom,
[classes.paragraph]: paragraph,
[classes[`align${capitalizeFirstLetter(align)}`]]: align !== 'inherit',
[classes[`align${capitalize(align)}`]]: align !== 'inherit',
},
classNameProp,
);
const Component = componentProp || (paragraph ? 'p' : headlineMapping[type]) || 'span';
const Component = componentProp || (paragraph ? 'p' : headlineMapping[variant]) || 'span';
return <Component className={className} {...other} />;
}
Typography.propTypes = {
/**
* Set the text-align on the component.
*/
align: PropTypes.oneOf(['inherit', 'left', 'center', 'right', 'justify']),
/**
* 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 color of the component. It supports those theme colors that make sense for this component.
*/
color: PropTypes.oneOf(['inherit', 'primary', 'textSecondary', 'secondary', 'error', 'default']),
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
* By default, it maps the variant to a good default headline component.
*/
component: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
/**
* If `true`, the text will have a bottom margin.
*/
gutterBottom: PropTypes.bool,
/**
* We are empirically mapping the variant property to a range of different DOM element types.
* For instance, h1 to h6. If you wish to change that mapping, you can provide your own.
* Alternatively, you can use the `component` property.
*/
headlineMapping: PropTypes.object,
/**
* If `true`, the text will not wrap, but instead will truncate with an ellipsis.
*/
noWrap: PropTypes.bool,
/**
* If `true`, the text will have a bottom margin.
*/
paragraph: PropTypes.bool,
/**
* Applies the theme typography styles.
*/
variant: PropTypes.oneOf([
'display4',
'display3',
'display2',
'display1',
'headline',
'title',
'subheading',
'body2',
'body1',
'caption',
'button',
]),
};
Typography.defaultProps = {
align: 'inherit',
color: 'default',
@@ -176,7 +173,7 @@ Typography.defaultProps = {
},
noWrap: false,
paragraph: false,
type: 'body1',
variant: 'body1',
};
export default withStyles(styles, { name: 'MuiTypography' })(Typography);

View File

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