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,14 +1,13 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface TableProps extends StandardProps<
React.TableHTMLAttributes<HTMLTableElement>,
TableClassKey
> {}
export interface TableProps extends StandardProps<TableBaseProps, TableClassKey> {
component?: React.ReactType<TableBaseProps>;
}
export type TableClassKey =
| 'root'
;
export type TableBaseProps = React.TableHTMLAttributes<HTMLTableElement>;
export type TableClassKey = 'root';
declare const Table: React.ComponentType<TableProps>;

View File

@@ -51,10 +51,6 @@ var _withStyles2 = _interopRequireDefault(_withStyles);
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: {
@@ -67,29 +63,6 @@ var styles = exports.styles = function styles(theme) {
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The content of the table, normally `TableHeader` and `TableBody`.
*/
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.
*/
component: typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType)
};
var Table = function (_React$Component) {
(0, _inherits3.default)(Table, _React$Component);
@@ -112,27 +85,40 @@ var Table = function (_React$Component) {
var _props = this.props,
classes = _props.classes,
classNameProp = _props.className,
children = _props.children,
ComponentProp = _props.component,
other = (0, _objectWithoutProperties3.default)(_props, ['classes', 'className', 'children', 'component']);
Component = _props.component,
other = (0, _objectWithoutProperties3.default)(_props, ['classes', 'className', 'component']);
var className = (0, _classnames2.default)(classes.root, classNameProp);
return _react2.default.createElement(
ComponentProp,
(0, _extends3.default)({ className: className }, other),
children
);
return _react2.default.createElement(Component, (0, _extends3.default)({ className: (0, _classnames2.default)(classes.root, classNameProp) }, other));
}
}]);
return Table;
}(_react2.default.Component);
Table.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the table, normally `TableHeader` and `TableBody`.
*/
children: _propTypes2.default.node.isRequired,
/**
* 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])
} : {};
Table.defaultProps = {
component: 'table'
};
Table.childContextTypes = {
table: _propTypes2.default.object
};

View File

@@ -1,12 +1,9 @@
// @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';
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
fontFamily: theme.typography.fontFamily,
width: '100%',
@@ -16,36 +13,7 @@ export const styles = (theme: Object) => ({
},
});
type ProvidedProps = {
classes: Object,
component: ElementType,
};
export type Props = {
/**
* The content of the table, normally `TableHeader` and `TableBody`.
*/
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.
*/
component?: ElementType,
};
class Table extends React.Component<ProvidedProps & Props> {
static defaultProps = {
component: 'table',
};
class Table extends React.Component {
getChildContext() {
// eslint-disable-line class-methods-use-this
return {
@@ -54,23 +22,36 @@ class Table extends React.Component<ProvidedProps & Props> {
}
render() {
const {
classes,
className: classNameProp,
children,
component: ComponentProp,
...other
} = this.props;
const className = classNames(classes.root, classNameProp);
const { classes, className: classNameProp, component: Component, ...other } = this.props;
return (
<ComponentProp className={className} {...other}>
{children}
</ComponentProp>
);
return <Component className={classNames(classes.root, classNameProp)} {...other} />;
}
}
Table.propTypes = {
/**
* The content of the table, normally `TableHeader` and `TableBody`.
*/
children: PropTypes.node.isRequired,
/**
* 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]),
};
Table.defaultProps = {
component: 'table',
};
Table.childContextTypes = {
table: PropTypes.object,
};

View File

@@ -1,14 +1,10 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface TableBodyProps extends StandardProps<
React.HTMLAttributes<HTMLTableSectionElement>,
TableBodyClassKey
> {}
export interface TableBodyProps extends TableBodyBaseProps {
component?: React.ReactType<TableBodyBaseProps>;
}
export type TableBodyClassKey =
| 'root'
;
export type TableBodyBaseProps = React.HTMLAttributes<HTMLTableSectionElement>;
declare const TableBody: React.ComponentType<TableBodyProps>;

View File

@@ -3,11 +3,6 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.styles = undefined;
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
@@ -41,52 +36,8 @@ var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
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: {
fontSize: theme.typography.pxToRem(13),
color: theme.palette.text.primary
}
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The content of the component, normally `TableRow`.
*/
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.
*/
component: typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType)
};
var TableBody = function (_React$Component) {
(0, _inherits3.default)(TableBody, _React$Component);
@@ -109,31 +60,34 @@ var TableBody = function (_React$Component) {
key: 'render',
value: function render() {
var _props = this.props,
classes = _props.classes,
classNameProp = _props.className,
children = _props.children,
ComponentProp = _props.component,
other = (0, _objectWithoutProperties3.default)(_props, ['classes', 'className', 'children', 'component']);
Component = _props.component,
other = (0, _objectWithoutProperties3.default)(_props, ['component']);
var className = (0, _classnames2.default)(classes.root, classNameProp);
return _react2.default.createElement(
ComponentProp,
(0, _extends3.default)({ className: className }, other),
children
);
return _react2.default.createElement(Component, other);
}
}]);
return TableBody;
}(_react2.default.Component);
TableBody.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the component, normally `TableRow`.
*/
children: _propTypes2.default.node.isRequired,
/**
* 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])
} : {};
TableBody.defaultProps = {
component: 'tbody'
};
TableBody.childContextTypes = {
table: _propTypes2.default.object
};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiTableBody' })(TableBody);
exports.default = TableBody;

View File

@@ -1,48 +1,7 @@
// @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';
export const styles = (theme: Object) => ({
root: {
fontSize: theme.typography.pxToRem(13),
color: theme.palette.text.primary,
},
});
type ProvidedProps = {
classes: Object,
component: ElementType,
};
export type Props = {
/**
* The content of the component, normally `TableRow`.
*/
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.
*/
component?: ElementType,
};
class TableBody extends React.Component<ProvidedProps & Props> {
static defaultProps = {
component: 'tbody',
};
class TableBody extends React.Component {
getChildContext() {
// eslint-disable-line class-methods-use-this
return {
@@ -53,25 +12,30 @@ class TableBody extends React.Component<ProvidedProps & Props> {
}
render() {
const {
classes,
className: classNameProp,
children,
component: ComponentProp,
...other
} = this.props;
const className = classNames(classes.root, classNameProp);
const { component: Component, ...other } = this.props;
return (
<ComponentProp className={className} {...other}>
{children}
</ComponentProp>
);
return <Component {...other} />;
}
}
TableBody.propTypes = {
/**
* The content of the component, normally `TableRow`.
*/
children: PropTypes.node.isRequired,
/**
* 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]),
};
TableBody.defaultProps = {
component: 'tbody',
};
TableBody.childContextTypes = {
table: PropTypes.object,
};
export default withStyles(styles, { name: 'MuiTableBody' })(TableBody);
export default TableBody;

View File

@@ -9,30 +9,32 @@ import { StandardProps } from '..';
* Since it is not decided via prop, we have create loose typings
* here.
*/
export interface TableCellProps extends StandardProps<
React.ThHTMLAttributes<HTMLTableHeaderCellElement> & React.TdHTMLAttributes<HTMLTableDataCellElement>,
TableCellClassKey
> {
padding?: Padding;
export interface TableCellProps extends StandardProps<TableCellBaseProps, TableCellClassKey> {
component?: React.ReactType<TableCellBaseProps>;
numeric?: boolean;
padding?: Padding;
sortDirection?: SortDirection;
type?: Type;
}
export type Padding =
| 'default'
| 'checkbox'
| 'dense'
| 'none'
;
export type TableCellBaseProps = React.ThHTMLAttributes<HTMLTableHeaderCellElement> &
React.TdHTMLAttributes<HTMLTableDataCellElement>;
export type Padding = 'default' | 'checkbox' | 'dense' | 'none';
export type SortDirection = 'asc' | 'desc' | false;
export type Type = 'head' | 'body' | 'footer';
export type TableCellClassKey =
| 'root'
| 'numeric'
| 'head'
| 'typeHead'
| 'typeBody'
| 'typeFooter'
| 'paddingDefault'
| 'paddingCompact'
| 'paddingCheckbox'
| 'footer'
;
| 'paddingDense'
| 'paddingCheckbox';
declare const TableCell: React.ComponentType<TableCellProps>;

View File

@@ -17,8 +17,6 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
@@ -37,64 +35,37 @@ var _withStyles2 = _interopRequireDefault(_withStyles);
var _helpers = require('../utils/helpers');
var _colorManipulator = require('../styles/colorManipulator');
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 babelPluginFlowReactPropTypes_proptype_Context = {
table: require('prop-types').object.isRequired
};
var babelPluginFlowReactPropTypes_proptype_Padding = require('prop-types').oneOf(['default', 'checkbox', 'dense', 'none']);
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The table cell contents.
*/
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.
*/
component: typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType),
/**
* If `true`, content will align to the right.
*/
numeric: require('prop-types').bool,
/**
* Sets the padding applied to the cell.
*/
padding: require('prop-types').oneOf(['default', 'checkbox', 'dense', 'none'])
};
var styles = exports.styles = function styles(theme) {
return {
root: {
borderBottom: '1px solid ' + theme.palette.text.lightDivider,
// Workaround for a rendering bug with spanned columns in Chrome 62.0.
// Removes the alpha (sets it to 1), and lightens or darkens the theme color.
borderBottom: '1px solid\n ' + (theme.palette.type === 'light' ? (0, _colorManipulator.lighten)((0, _colorManipulator.fade)(theme.palette.divider, 1), 0.88) : (0, _colorManipulator.darken)((0, _colorManipulator.fade)(theme.palette.divider, 1), 0.8)),
textAlign: 'left'
},
numeric: {
textAlign: 'right',
flexDirection: 'row-reverse' // can be dynamically inherited at runtime by contents
},
head: {
typeHead: {
color: theme.palette.text.secondary,
fontSize: theme.typography.pxToRem(12),
fontWeight: theme.typography.fontWeightMedium,
position: 'relative' // Workaround for Tooltip positioning issue.
},
typeBody: {
fontSize: theme.typography.pxToRem(13),
color: theme.palette.text.primary
},
typeFooter: {
borderBottom: 0,
color: theme.palette.text.secondary,
fontSize: theme.typography.pxToRem(12)
},
paddingDefault: {
padding: theme.spacing.unit / 2 + 'px ' + theme.spacing.unit * 7 + 'px ' + theme.spacing.unit / 2 + 'px ' + theme.spacing.unit * 3 + 'px',
'&:last-child': {
@@ -106,9 +77,6 @@ var styles = exports.styles = function styles(theme) {
},
paddingCheckbox: {
padding: '0 12px'
},
footer: {
borderBottom: 0
}
};
};
@@ -116,13 +84,16 @@ var styles = exports.styles = function styles(theme) {
function TableCell(props, context) {
var _classNames;
var classes = props.classes,
var children = props.children,
classes = props.classes,
classNameProp = props.className,
children = props.children,
component = props.component,
sortDirection = props.sortDirection,
numeric = props.numeric,
padding = props.padding,
component = props.component,
other = (0, _objectWithoutProperties3.default)(props, ['classes', 'className', 'children', 'numeric', 'padding', 'component']);
scopeProp = props.scope,
variant = props.variant,
other = (0, _objectWithoutProperties3.default)(props, ['children', 'classes', 'className', 'component', 'sortDirection', 'numeric', 'padding', 'scope', 'variant']);
var table = context.table;
var Component = void 0;
@@ -132,21 +103,66 @@ function TableCell(props, context) {
Component = table && table.head ? 'th' : 'td';
}
var className = (0, _classnames2.default)(classes.root, (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes.numeric, numeric), (0, _defineProperty3.default)(_classNames, classes['padding' + (0, _helpers.capitalizeFirstLetter)(padding)], padding !== 'none' && padding !== 'default'), (0, _defineProperty3.default)(_classNames, classes.paddingDefault, padding !== 'none'), (0, _defineProperty3.default)(_classNames, classes.head, table && table.head), (0, _defineProperty3.default)(_classNames, classes.footer, table && table.footer), _classNames), classNameProp);
var scope = scopeProp;
if (!scope && table && table.head) {
scope = 'col';
}
var className = (0, _classnames2.default)(classes.root, (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes.numeric, numeric), (0, _defineProperty3.default)(_classNames, classes['padding' + (0, _helpers.capitalize)(padding)], padding !== 'none' && padding !== 'default'), (0, _defineProperty3.default)(_classNames, classes.paddingDefault, padding !== 'none'), (0, _defineProperty3.default)(_classNames, classes.typeHead, variant ? variant === 'head' : table && table.head), (0, _defineProperty3.default)(_classNames, classes.typeBody, variant ? variant === 'body' : table && table.body), (0, _defineProperty3.default)(_classNames, classes.typeFooter, variant ? variant === 'footer' : table && table.footer), _classNames), classNameProp);
var ariaSort = null;
if (sortDirection) {
ariaSort = sortDirection === 'asc' ? 'ascending' : 'descending';
}
return _react2.default.createElement(
Component,
(0, _extends3.default)({ className: className }, other),
(0, _extends3.default)({ className: className, 'aria-sort': ariaSort, scope: scope }, other),
children
);
}
TableCell.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
classes: require('prop-types').object.isRequired,
padding: require('prop-types').oneOf(['default', 'checkbox', 'dense', 'none']).isRequired,
numeric: require('prop-types').bool.isRequired,
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, 'numeric', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'padding', require('prop-types').oneOf(['default', 'checkbox', 'dense', 'none'])), _ref) : {};
TableCell.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The table cell contents.
*/
children: _propTypes2.default.node,
/**
* 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]),
/**
* If `true`, content will align to the right.
*/
numeric: _propTypes2.default.bool,
/**
* Sets the padding applied to the cell.
*/
padding: _propTypes2.default.oneOf(['default', 'checkbox', 'dense', 'none']),
/**
* Set scope attribute.
*/
scope: _propTypes2.default.string,
/**
* Set aria-sort direction.
*/
sortDirection: _propTypes2.default.oneOf(['asc', 'desc', false]),
/**
* Specify the cell type.
* By default, the TableHead, TableBody or TableFooter parent component set the value.
*/
variant: _propTypes2.default.oneOf(['head', 'body', 'footer'])
} : {};
TableCell.defaultProps = {
numeric: false,
padding: 'default'

View File

@@ -1,65 +1,41 @@
// @flow
import React from 'react';
import PropTypes from 'prop-types';
import type { ElementType, Node } from 'react';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
import { capitalizeFirstLetter } from '../utils/helpers';
import { capitalize } from '../utils/helpers';
import { darken, fade, lighten } from '../styles/colorManipulator';
export type Context = {
table: Object,
};
export type Padding = 'default' | 'checkbox' | 'dense' | 'none';
type ProvidedProps = {
classes: Object,
padding: Padding,
numeric: boolean,
};
export type Props = {
/**
* The table cell contents.
*/
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.
*/
component?: ElementType,
/**
* If `true`, content will align to the right.
*/
numeric?: boolean,
/**
* Sets the padding applied to the cell.
*/
padding?: Padding,
};
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
borderBottom: `1px solid ${theme.palette.text.lightDivider}`,
// Workaround for a rendering bug with spanned columns in Chrome 62.0.
// Removes the alpha (sets it to 1), and lightens or darkens the theme color.
borderBottom: `1px solid
${
theme.palette.type === 'light'
? lighten(fade(theme.palette.divider, 1), 0.88)
: darken(fade(theme.palette.divider, 1), 0.8)
}`,
textAlign: 'left',
},
numeric: {
textAlign: 'right',
flexDirection: 'row-reverse', // can be dynamically inherited at runtime by contents
},
head: {
typeHead: {
color: theme.palette.text.secondary,
fontSize: theme.typography.pxToRem(12),
fontWeight: theme.typography.fontWeightMedium,
position: 'relative', // Workaround for Tooltip positioning issue.
},
typeBody: {
fontSize: theme.typography.pxToRem(13),
color: theme.palette.text.primary,
},
typeFooter: {
borderBottom: 0,
color: theme.palette.text.secondary,
fontSize: theme.typography.pxToRem(12),
},
paddingDefault: {
padding: `${theme.spacing.unit / 2}px ${theme.spacing.unit * 7}px ${theme.spacing.unit /
2}px ${theme.spacing.unit * 3}px`,
@@ -73,22 +49,21 @@ export const styles = (theme: Object) => ({
paddingCheckbox: {
padding: '0 12px',
},
footer: {
borderBottom: 0,
},
});
function TableCell(props: ProvidedProps & Props, context: Context) {
function TableCell(props, context) {
const {
children,
classes,
className: classNameProp,
children,
component,
sortDirection,
numeric,
padding,
component,
scope: scopeProp,
variant,
...other
} = props;
const { table } = context;
let Component;
if (component) {
@@ -97,26 +72,77 @@ function TableCell(props: ProvidedProps & Props, context: Context) {
Component = table && table.head ? 'th' : 'td';
}
let scope = scopeProp;
if (!scope && table && table.head) {
scope = 'col';
}
const className = classNames(
classes.root,
{
[classes.numeric]: numeric,
[classes[`padding${capitalizeFirstLetter(padding)}`]]:
padding !== 'none' && padding !== 'default',
[classes[`padding${capitalize(padding)}`]]: padding !== 'none' && padding !== 'default',
[classes.paddingDefault]: padding !== 'none',
[classes.head]: table && table.head,
[classes.footer]: table && table.footer,
[classes.typeHead]: variant ? variant === 'head' : table && table.head,
[classes.typeBody]: variant ? variant === 'body' : table && table.body,
[classes.typeFooter]: variant ? variant === 'footer' : table && table.footer,
},
classNameProp,
);
let ariaSort = null;
if (sortDirection) {
ariaSort = sortDirection === 'asc' ? 'ascending' : 'descending';
}
return (
<Component className={className} {...other}>
<Component className={className} aria-sort={ariaSort} scope={scope} {...other}>
{children}
</Component>
);
}
TableCell.propTypes = {
/**
* The table cell contents.
*/
children: PropTypes.node,
/**
* 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]),
/**
* If `true`, content will align to the right.
*/
numeric: PropTypes.bool,
/**
* Sets the padding applied to the cell.
*/
padding: PropTypes.oneOf(['default', 'checkbox', 'dense', 'none']),
/**
* Set scope attribute.
*/
scope: PropTypes.string,
/**
* Set aria-sort direction.
*/
sortDirection: PropTypes.oneOf(['asc', 'desc', false]),
/**
* Specify the cell type.
* By default, the TableHead, TableBody or TableFooter parent component set the value.
*/
variant: PropTypes.oneOf(['head', 'body', 'footer']),
};
TableCell.defaultProps = {
numeric: false,
padding: 'default',

View File

@@ -1,14 +1,10 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface TableFooterProps extends StandardProps<
React.HTMLAttributes<HTMLTableSectionElement>,
TableFooterClassKey
> {}
export interface TableFooterProps extends TableFooterBaseProps {
component?: React.ReactType<TableFooterBaseProps>;
}
export type TableFooterClassKey =
| 'root'
;
export type TableFooterBaseProps = React.HTMLAttributes<HTMLTableSectionElement>;
declare const TableFooter: React.ComponentType<TableFooterProps>;

View File

@@ -3,11 +3,6 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.styles = undefined;
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
@@ -41,52 +36,8 @@ var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
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: {
fontSize: theme.typography.pxToRem(12),
color: theme.palette.text.secondary
}
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The content of the component, normally `TableRow`.
*/
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.
*/
component: typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType)
};
var TableFooter = function (_React$Component) {
(0, _inherits3.default)(TableFooter, _React$Component);
@@ -109,30 +60,34 @@ var TableFooter = function (_React$Component) {
key: 'render',
value: function render() {
var _props = this.props,
classes = _props.classes,
classNameProp = _props.className,
children = _props.children,
ComponentProp = _props.component,
other = (0, _objectWithoutProperties3.default)(_props, ['classes', 'className', 'children', 'component']);
Component = _props.component,
other = (0, _objectWithoutProperties3.default)(_props, ['component']);
return _react2.default.createElement(
ComponentProp,
(0, _extends3.default)({ className: (0, _classnames2.default)(classes.root, classNameProp) }, other),
children
);
return _react2.default.createElement(Component, other);
}
}]);
return TableFooter;
}(_react2.default.Component);
TableFooter.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the component, normally `TableRow`.
*/
children: _propTypes2.default.node,
/**
* 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])
} : {};
TableFooter.defaultProps = {
component: 'tfoot'
};
TableFooter.childContextTypes = {
table: _propTypes2.default.object
};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiTableFooter' })(TableFooter);
exports.default = TableFooter;

View File

@@ -1,48 +1,7 @@
// @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';
export const styles = (theme: Object) => ({
root: {
fontSize: theme.typography.pxToRem(12),
color: theme.palette.text.secondary,
},
});
type ProvidedProps = {
classes: Object,
component: ElementType,
};
export type Props = {
/**
* The content of the component, normally `TableRow`.
*/
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.
*/
component?: ElementType,
};
class TableFooter extends React.Component<ProvidedProps & Props> {
static defaultProps = {
component: 'tfoot',
};
class TableFooter extends React.Component {
getChildContext() {
// eslint-disable-line class-methods-use-this
return {
@@ -53,24 +12,30 @@ class TableFooter extends React.Component<ProvidedProps & Props> {
}
render() {
const {
classes,
className: classNameProp,
children,
component: ComponentProp,
...other
} = this.props;
const { component: Component, ...other } = this.props;
return (
<ComponentProp className={classNames(classes.root, classNameProp)} {...other}>
{children}
</ComponentProp>
);
return <Component {...other} />;
}
}
TableFooter.propTypes = {
/**
* The content of the component, normally `TableRow`.
*/
children: PropTypes.node,
/**
* 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]),
};
TableFooter.defaultProps = {
component: 'tfoot',
};
TableFooter.childContextTypes = {
table: PropTypes.object,
};
export default withStyles(styles, { name: 'MuiTableFooter' })(TableFooter);
export default TableFooter;

View File

@@ -1,14 +1,10 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface TableHeadProps extends StandardProps<
React.HTMLAttributes<HTMLTableSectionElement>,
TableHeadClassKey
> {}
export interface TableHeadProps extends TableHeadBaseProps {
component?: React.ReactType<TableHeadBaseProps>;
}
export type TableHeadClassKey =
| 'root'
;
export type TableHeadBaseProps = React.HTMLAttributes<HTMLTableSectionElement>;
declare const TableHead: React.ComponentType<TableHeadProps>;

View File

@@ -3,11 +3,6 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.styles = undefined;
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
@@ -41,53 +36,8 @@ var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
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: {
fontSize: theme.typography.pxToRem(12),
fontWeight: theme.typography.fontWeightMedium,
color: theme.palette.text.secondary
}
};
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* The content of the component, normally `TableRow`.
*/
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.
*/
component: typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType)
};
var TableHead = function (_React$Component) {
(0, _inherits3.default)(TableHead, _React$Component);
@@ -110,31 +60,34 @@ var TableHead = function (_React$Component) {
key: 'render',
value: function render() {
var _props = this.props,
classes = _props.classes,
classNameProp = _props.className,
children = _props.children,
ComponentProp = _props.component,
other = (0, _objectWithoutProperties3.default)(_props, ['classes', 'className', 'children', 'component']);
Component = _props.component,
other = (0, _objectWithoutProperties3.default)(_props, ['component']);
var className = (0, _classnames2.default)(classes.root, classNameProp);
return _react2.default.createElement(
ComponentProp,
(0, _extends3.default)({ className: className }, other),
children
);
return _react2.default.createElement(Component, other);
}
}]);
return TableHead;
}(_react2.default.Component);
TableHead.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The content of the component, normally `TableRow`.
*/
children: _propTypes2.default.node.isRequired,
/**
* 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])
} : {};
TableHead.defaultProps = {
component: 'thead'
};
TableHead.childContextTypes = {
table: _propTypes2.default.object
};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiTableHead' })(TableHead);
exports.default = TableHead;

View File

@@ -1,49 +1,7 @@
// @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';
export const styles = (theme: Object) => ({
root: {
fontSize: theme.typography.pxToRem(12),
fontWeight: theme.typography.fontWeightMedium,
color: theme.palette.text.secondary,
},
});
type ProvidedProps = {
classes: Object,
component: ElementType,
};
export type Props = {
/**
* The content of the component, normally `TableRow`.
*/
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.
*/
component?: ElementType,
};
class TableHead extends React.Component<ProvidedProps & Props> {
static defaultProps = {
component: 'thead',
};
class TableHead extends React.Component {
getChildContext() {
// eslint-disable-line class-methods-use-this
return {
@@ -54,25 +12,30 @@ class TableHead extends React.Component<ProvidedProps & Props> {
}
render() {
const {
classes,
className: classNameProp,
children,
component: ComponentProp,
...other
} = this.props;
const className = classNames(classes.root, classNameProp);
const { component: Component, ...other } = this.props;
return (
<ComponentProp className={className} {...other}>
{children}
</ComponentProp>
);
return <Component {...other} />;
}
}
TableHead.propTypes = {
/**
* The content of the component, normally `TableRow`.
*/
children: PropTypes.node.isRequired,
/**
* 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]),
};
TableHead.defaultProps = {
component: 'thead',
};
TableHead.childContextTypes = {
table: PropTypes.object,
};
export default withStyles(styles, { name: 'MuiTableHead' })(TableHead);
export default TableHead;

View File

@@ -1,37 +1,41 @@
import * as React from 'react';
import { StandardProps } from '..';
import { TableCellProps, TableCellClassKey } from './TableCell.d'
import { TableCellProps, TableCellClassKey } from './TableCell.d';
import { IconButtonProps } from '../IconButton/IconButton';
interface LabelDisplayedRowsArgs {
export interface LabelDisplayedRowsArgs {
from: number;
to: number;
count: number;
page: number;
}
export interface TablePaginationProps extends StandardProps<
TableCellProps,
TablePaginationClassKey
> {
export interface TablePaginationProps
extends StandardProps<TablePaginationBaseProps, TablePaginationClassKey> {
Actions?: React.ReactType<TablePaginationBaseProps>;
backIconButtonProps?: Partial<IconButtonProps>;
component?: React.ReactType<TablePaginationBaseProps>;
count: number;
labelDisplayedRows?: (paginationInfo: LabelDisplayedRowsArgs) => Node;
labelRowsPerPage?: Node;
labelDisplayedRows?: (paginationInfo: LabelDisplayedRowsArgs) => React.ReactNode;
labelRowsPerPage?: React.ReactNode;
nextIconButtonProps?: Partial<IconButtonProps>;
onChangePage: (event: React.MouseEvent<HTMLButtonElement> | null, page: number) => void;
onChangeRowsPerPage: React.ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement>;
onChangeRowsPerPage?: React.ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement>;
page: number;
rowsPerPage: number;
rowsPerPageOptions?: number[];
}
export type TablePaginationBaseProps = TableCellProps;
export type TablePaginationClassKey =
| TableCellClassKey
| 'cell'
| 'toolbar'
| 'spacer'
| 'select'
| 'caption'
| 'input'
| 'selectRoot'
| 'actions'
;
| 'select';
declare const TablePagination: React.ComponentType<TablePaginationProps>;

View File

@@ -37,14 +37,14 @@ var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
var _IconButton = require('../IconButton');
var _IconButton2 = _interopRequireDefault(_IconButton);
var _Input = require('../Input');
var _Input2 = _interopRequireDefault(_Input);
@@ -67,21 +67,14 @@ var _Typography = require('../Typography');
var _Typography2 = _interopRequireDefault(_Typography);
var _KeyboardArrowLeft = require('../svg-icons/KeyboardArrowLeft');
var _TablePaginationActions = require('./TablePaginationActions');
var _KeyboardArrowLeft2 = _interopRequireDefault(_KeyboardArrowLeft);
var _KeyboardArrowRight = require('../svg-icons/KeyboardArrowRight');
var _KeyboardArrowRight2 = _interopRequireDefault(_KeyboardArrowRight);
var _TablePaginationActions2 = _interopRequireDefault(_TablePaginationActions);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
// @inheritedComponent TableCell
var babelPluginFlowReactPropTypes_proptype_ElementType = require('react').babelPluginFlowReactPropTypes_proptype_ElementType || require('prop-types').any;
var styles = exports.styles = function styles(theme) {
return {
root: {
@@ -102,19 +95,20 @@ var styles = exports.styles = function styles(theme) {
flexShrink: 0
},
input: {
fontSize: 'inherit'
fontSize: 'inherit',
flexShrink: 0
},
selectRoot: {
marginRight: theme.spacing.unit * 4
marginRight: theme.spacing.unit * 4,
marginLeft: theme.spacing.unit,
color: theme.palette.text.secondary
},
select: {
marginLeft: theme.spacing.unit,
width: 34,
textAlign: 'right',
paddingRight: 22,
color: theme.palette.text.secondary,
height: 32,
lineHeight: '32px'
paddingLeft: theme.spacing.unit,
paddingRight: theme.spacing.unit * 2
},
selectIcon: {
top: 1
},
actions: {
flexShrink: 0,
@@ -124,118 +118,24 @@ var styles = exports.styles = function styles(theme) {
};
};
var babelPluginFlowReactPropTypes_proptype_LabelDisplayedRowsArgs = {
from: require('prop-types').number.isRequired,
to: require('prop-types').number.isRequired,
count: require('prop-types').number.isRequired,
page: require('prop-types').number.isRequired
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* Useful to extend the style applied to components.
*/
classes: require('prop-types').object,
/**
* 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),
/**
* @ignore
*/
colSpan: require('prop-types').number,
/**
* The total number of rows.
*/
count: require('prop-types').number.isRequired,
/**
* Useful to customize the displayed rows label.
*/
labelDisplayedRows: require('prop-types').func,
/**
* Useful to customize the rows per page label. Invoked with a `{ from, to, count, page }`
* object.
*/
labelRowsPerPage: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
/**
* Callback fired when the page is changed. Invoked with two arguments: the event and the
* page to show.
*/
onChangePage: require('prop-types').func.isRequired,
/**
* Callback fired when the number of rows per page is changed. Invoked with two arguments: the
* event.
*/
onChangeRowsPerPage: require('prop-types').func.isRequired,
/**
* The zero-based index of the current page.
*/
page: require('prop-types').number.isRequired,
/**
* The number of rows per page.
*/
rowsPerPage: require('prop-types').number.isRequired,
/**
* Customizes the options of the rows per page select field.
*/
rowsPerPageOptions: require('prop-types').arrayOf(require('prop-types').number),
/**
* @ignore
*/
theme: require('prop-types').object
};
var _ref3 = _react2.default.createElement(_Input2.default, { disableUnderline: true });
var _ref4 = _react2.default.createElement(_KeyboardArrowRight2.default, null);
var _ref5 = _react2.default.createElement(_KeyboardArrowLeft2.default, null);
var _ref6 = _react2.default.createElement(_KeyboardArrowLeft2.default, null);
var _ref7 = _react2.default.createElement(_KeyboardArrowRight2.default, null);
/**
* A `TableRow` based component for placing inside `TableFooter` for pagination.
* A `TableCell` based component for placing inside `TableFooter` for pagination.
*/
var TablePagination = function (_React$Component) {
(0, _inherits3.default)(TablePagination, _React$Component);
function TablePagination() {
var _ref;
var _temp, _this, _ret;
(0, _classCallCheck3.default)(this, TablePagination);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = TablePagination.__proto__ || (0, _getPrototypeOf2.default)(TablePagination)).call.apply(_ref, [this].concat(args))), _this), _this.handleBackButtonClick = function (event) {
_this.props.onChangePage(event, _this.props.page - 1);
}, _this.handleNextButtonClick = function (event) {
_this.props.onChangePage(event, _this.props.page + 1);
}, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
return (0, _possibleConstructorReturn3.default)(this, (TablePagination.__proto__ || (0, _getPrototypeOf2.default)(TablePagination)).apply(this, arguments));
}
(0, _createClass3.default)(TablePagination, [{
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(_ref2) {
var count = _ref2.count,
onChangePage = _ref2.onChangePage,
rowsPerPage = _ref2.rowsPerPage;
value: function componentWillReceiveProps(nextProps) {
var count = nextProps.count,
onChangePage = nextProps.onChangePage,
rowsPerPage = nextProps.rowsPerPage;
var newLastPage = Math.max(0, Math.ceil(count / rowsPerPage) - 1);
if (this.props.page > newLastPage) {
@@ -246,25 +146,27 @@ var TablePagination = function (_React$Component) {
key: 'render',
value: function render() {
var _props = this.props,
Actions = _props.Actions,
backIconButtonProps = _props.backIconButtonProps,
classes = _props.classes,
Component = _props.component,
colSpanProp = _props.colSpan,
Component = _props.component,
count = _props.count,
labelDisplayedRows = _props.labelDisplayedRows,
labelRowsPerPage = _props.labelRowsPerPage,
nextIconButtonProps = _props.nextIconButtonProps,
onChangePage = _props.onChangePage,
onChangeRowsPerPage = _props.onChangeRowsPerPage,
page = _props.page,
rowsPerPage = _props.rowsPerPage,
rowsPerPageOptions = _props.rowsPerPageOptions,
theme = _props.theme,
other = (0, _objectWithoutProperties3.default)(_props, ['classes', 'component', 'colSpan', 'count', 'labelDisplayedRows', 'labelRowsPerPage', 'onChangePage', 'onChangeRowsPerPage', 'page', 'rowsPerPage', 'rowsPerPageOptions', 'theme']);
other = (0, _objectWithoutProperties3.default)(_props, ['Actions', 'backIconButtonProps', 'classes', 'colSpan', 'component', 'count', 'labelDisplayedRows', 'labelRowsPerPage', 'nextIconButtonProps', 'onChangePage', 'onChangeRowsPerPage', 'page', 'rowsPerPage', 'rowsPerPageOptions']);
var colSpan = void 0;
if (Component === _TableCell2.default || Component === 'td') {
colSpan = colSpanProp || 9001; // col-span over everything
colSpan = colSpanProp || 1000; // col-span over everything
}
return _react2.default.createElement(
@@ -274,19 +176,25 @@ var TablePagination = function (_React$Component) {
_Toolbar2.default,
{ className: classes.toolbar },
_react2.default.createElement('div', { className: classes.spacer }),
_react2.default.createElement(
rowsPerPageOptions.length > 1 && _react2.default.createElement(
_Typography2.default,
{ type: 'caption', className: classes.caption },
{ variant: 'caption', className: classes.caption },
labelRowsPerPage
),
_react2.default.createElement(
rowsPerPageOptions.length > 1 && _react2.default.createElement(
_Select2.default,
{
classes: { root: classes.selectRoot, select: classes.select },
InputClasses: {
root: classes.input
classes: {
root: classes.selectRoot,
select: classes.select,
icon: classes.selectIcon
},
input: _ref3,
input: _react2.default.createElement(_Input2.default, {
classes: {
root: classes.input
},
disableUnderline: true
}),
value: rowsPerPage,
onChange: onChangeRowsPerPage
},
@@ -300,7 +208,7 @@ var TablePagination = function (_React$Component) {
),
_react2.default.createElement(
_Typography2.default,
{ type: 'caption', className: classes.caption },
{ variant: 'caption', className: classes.caption },
labelDisplayedRows({
from: count === 0 ? 0 : page * rowsPerPage + 1,
to: Math.min(count, (page + 1) * rowsPerPage),
@@ -308,23 +216,14 @@ var TablePagination = function (_React$Component) {
page: page
})
),
_react2.default.createElement(
'div',
{ className: classes.actions },
_react2.default.createElement(
_IconButton2.default,
{ onClick: this.handleBackButtonClick, disabled: page === 0 },
theme.direction === 'rtl' ? _ref4 : _ref5
),
_react2.default.createElement(
_IconButton2.default,
{
onClick: this.handleNextButtonClick,
disabled: page >= Math.ceil(count / rowsPerPage) - 1
},
theme.direction === 'rtl' ? _ref6 : _ref7
)
)
_react2.default.createElement(Actions, {
backIconButtonProps: backIconButtonProps,
count: count,
nextIconButtonProps: nextIconButtonProps,
onChangePage: onChangePage,
page: page,
rowsPerPage: rowsPerPage
})
)
);
}
@@ -332,15 +231,85 @@ var TablePagination = function (_React$Component) {
return TablePagination;
}(_react2.default.Component);
TablePagination.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* The component used for displaying the actions.
* Either a string to use a DOM element or a component.
*/
Actions: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func]),
/**
* Properties applied to the back arrow `IconButton` component.
*/
backIconButtonProps: _propTypes2.default.object,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
colSpan: _propTypes2.default.number,
/**
* 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]),
/**
* The total number of rows.
*/
count: _propTypes2.default.number.isRequired,
/**
* Useful to customize the displayed rows label.
*/
labelDisplayedRows: _propTypes2.default.func,
/**
* Useful to customize the rows per page label. Invoked with a `{ from, to, count, page }`
* object.
*/
labelRowsPerPage: _propTypes2.default.node,
/**
* Properties applied to the next arrow `IconButton` component.
*/
nextIconButtonProps: _propTypes2.default.object,
/**
* Callback fired when the page is changed.
*
* @param {object} event The event source of the callback
* @param {number} page The page selected
*/
onChangePage: _propTypes2.default.func.isRequired,
/**
* Callback fired when the number of rows per page is changed.
*
* @param {object} event The event source of the callback
*/
onChangeRowsPerPage: _propTypes2.default.func,
/**
* The zero-based index of the current page.
*/
page: _propTypes2.default.number.isRequired,
/**
* The number of rows per page.
*/
rowsPerPage: _propTypes2.default.number.isRequired,
/**
* Customizes the options of the rows per page select field. If less than two options are
* available, no select field will be displayed.
*/
rowsPerPageOptions: _propTypes2.default.array
} : {};
TablePagination.defaultProps = {
Actions: _TablePaginationActions2.default,
component: _TableCell2.default,
labelRowsPerPage: 'Rows per page:',
labelDisplayedRows: function labelDisplayedRows(_ref8) {
var from = _ref8.from,
to = _ref8.to,
count = _ref8.count;
labelDisplayedRows: function labelDisplayedRows(_ref) {
var from = _ref.from,
to = _ref.to,
count = _ref.count;
return from + '-' + to + ' of ' + count;
},
labelRowsPerPage: 'Rows per page:',
rowsPerPageOptions: [5, 10, 25]
};
exports.default = (0, _withStyles2.default)(styles, { withTheme: true, name: 'MuiTablePagination' })(TablePagination);
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiTablePagination' })(TablePagination);

View File

@@ -1,20 +1,17 @@
// @flow
// @inheritedComponent TableCell
import React from 'react';
import type { ElementType, Node } from 'react';
import PropTypes from 'prop-types';
import withStyles from '../styles/withStyles';
import IconButton from '../IconButton';
import Input from '../Input';
import { MenuItem } from '../Menu';
import Select from '../Select';
import TableCell from './TableCell';
import Toolbar from '../Toolbar';
import Typography from '../Typography';
import KeyboardArrowLeft from '../svg-icons/KeyboardArrowLeft';
import KeyboardArrowRight from '../svg-icons/KeyboardArrowRight';
import TablePaginationActions from './TablePaginationActions';
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
// Increase the specificity to override TableCell.
'&:last-child': {
@@ -34,18 +31,19 @@ export const styles = (theme: Object) => ({
},
input: {
fontSize: 'inherit',
flexShrink: 0,
},
selectRoot: {
marginRight: theme.spacing.unit * 4,
marginLeft: theme.spacing.unit,
color: theme.palette.text.secondary,
},
select: {
marginLeft: theme.spacing.unit,
width: 34,
textAlign: 'right',
paddingRight: 22,
color: theme.palette.text.secondary,
height: 32,
lineHeight: '32px',
paddingLeft: theme.spacing.unit,
paddingRight: theme.spacing.unit * 2,
},
selectIcon: {
top: 1,
},
actions: {
flexShrink: 0,
@@ -54,149 +52,78 @@ export const styles = (theme: Object) => ({
},
});
export type LabelDisplayedRowsArgs = {
from: number,
to: number,
count: number,
page: number,
};
type ProvidedProps = {
classes: Object,
component: ElementType,
labelRowsPerPage: string,
labelDisplayedRows: (paginationInfo: LabelDisplayedRowsArgs) => string,
rowsPerPageOptions: number[],
theme: Object,
};
export type Props = {
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* The component used for the root node.
* Either a string to use a DOM element or a component.
*/
component?: ElementType,
/**
* @ignore
*/
colSpan?: number,
/**
* The total number of rows.
*/
count: number,
/**
* Useful to customize the displayed rows label.
*/
labelDisplayedRows?: (paginationInfo: LabelDisplayedRowsArgs) => Node,
/**
* Useful to customize the rows per page label. Invoked with a `{ from, to, count, page }`
* object.
*/
labelRowsPerPage?: Node,
/**
* Callback fired when the page is changed. Invoked with two arguments: the event and the
* page to show.
*/
onChangePage: (event: SyntheticInputEvent<> | null, page: number) => void,
/**
* Callback fired when the number of rows per page is changed. Invoked with two arguments: the
* event.
*/
onChangeRowsPerPage: (event: SyntheticInputEvent<>) => void,
/**
* The zero-based index of the current page.
*/
page: number,
/**
* The number of rows per page.
*/
rowsPerPage: number,
/**
* Customizes the options of the rows per page select field.
*/
rowsPerPageOptions?: number[],
/**
* @ignore
*/
theme?: Object,
};
/**
* A `TableRow` based component for placing inside `TableFooter` for pagination.
* A `TableCell` based component for placing inside `TableFooter` for pagination.
*/
class TablePagination extends React.Component<ProvidedProps & Props> {
static defaultProps = {
component: TableCell,
labelRowsPerPage: 'Rows per page:',
labelDisplayedRows: ({ from, to, count }) => `${from}-${to} of ${count}`,
rowsPerPageOptions: [5, 10, 25],
};
componentWillReceiveProps({ count, onChangePage, rowsPerPage }) {
class TablePagination extends React.Component {
componentWillReceiveProps(nextProps) {
const { count, onChangePage, rowsPerPage } = nextProps;
const newLastPage = Math.max(0, Math.ceil(count / rowsPerPage) - 1);
if (this.props.page > newLastPage) {
onChangePage(null, newLastPage);
}
}
handleBackButtonClick = event => {
this.props.onChangePage(event, this.props.page - 1);
};
handleNextButtonClick = event => {
this.props.onChangePage(event, this.props.page + 1);
};
render() {
const {
Actions,
backIconButtonProps,
classes,
component: Component,
colSpan: colSpanProp,
component: Component,
count,
labelDisplayedRows,
labelRowsPerPage,
nextIconButtonProps,
onChangePage,
onChangeRowsPerPage,
page,
rowsPerPage,
rowsPerPageOptions,
theme,
...other
} = this.props;
let colSpan;
if (Component === TableCell || Component === 'td') {
colSpan = colSpanProp || 9001; // col-span over everything
colSpan = colSpanProp || 1000; // col-span over everything
}
return (
<Component className={classes.root} colSpan={colSpan} {...other}>
<Toolbar className={classes.toolbar}>
<div className={classes.spacer} />
<Typography type="caption" className={classes.caption}>
{labelRowsPerPage}
</Typography>
<Select
classes={{ root: classes.selectRoot, select: classes.select }}
InputClasses={{
root: classes.input,
}}
input={<Input disableUnderline />}
value={rowsPerPage}
onChange={onChangeRowsPerPage}
>
{rowsPerPageOptions.map(rowsPerPageOption => (
<MenuItem key={rowsPerPageOption} value={rowsPerPageOption}>
{rowsPerPageOption}
</MenuItem>
))}
</Select>
<Typography type="caption" className={classes.caption}>
{rowsPerPageOptions.length > 1 && (
<Typography variant="caption" className={classes.caption}>
{labelRowsPerPage}
</Typography>
)}
{rowsPerPageOptions.length > 1 && (
<Select
classes={{
root: classes.selectRoot,
select: classes.select,
icon: classes.selectIcon,
}}
input={
<Input
classes={{
root: classes.input,
}}
disableUnderline
/>
}
value={rowsPerPage}
onChange={onChangeRowsPerPage}
>
{rowsPerPageOptions.map(rowsPerPageOption => (
<MenuItem key={rowsPerPageOption} value={rowsPerPageOption}>
{rowsPerPageOption}
</MenuItem>
))}
</Select>
)}
<Typography variant="caption" className={classes.caption}>
{labelDisplayedRows({
from: count === 0 ? 0 : page * rowsPerPage + 1,
to: Math.min(count, (page + 1) * rowsPerPage),
@@ -204,21 +131,94 @@ class TablePagination extends React.Component<ProvidedProps & Props> {
page,
})}
</Typography>
<div className={classes.actions}>
<IconButton onClick={this.handleBackButtonClick} disabled={page === 0}>
{theme.direction === 'rtl' ? <KeyboardArrowRight /> : <KeyboardArrowLeft />}
</IconButton>
<IconButton
onClick={this.handleNextButtonClick}
disabled={page >= Math.ceil(count / rowsPerPage) - 1}
>
{theme.direction === 'rtl' ? <KeyboardArrowLeft /> : <KeyboardArrowRight />}
</IconButton>
</div>
<Actions
backIconButtonProps={backIconButtonProps}
count={count}
nextIconButtonProps={nextIconButtonProps}
onChangePage={onChangePage}
page={page}
rowsPerPage={rowsPerPage}
/>
</Toolbar>
</Component>
);
}
}
export default withStyles(styles, { withTheme: true, name: 'MuiTablePagination' })(TablePagination);
TablePagination.propTypes = {
/**
* The component used for displaying the actions.
* Either a string to use a DOM element or a component.
*/
Actions: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
/**
* Properties applied to the back arrow `IconButton` component.
*/
backIconButtonProps: PropTypes.object,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
colSpan: PropTypes.number,
/**
* 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]),
/**
* The total number of rows.
*/
count: PropTypes.number.isRequired,
/**
* Useful to customize the displayed rows label.
*/
labelDisplayedRows: PropTypes.func,
/**
* Useful to customize the rows per page label. Invoked with a `{ from, to, count, page }`
* object.
*/
labelRowsPerPage: PropTypes.node,
/**
* Properties applied to the next arrow `IconButton` component.
*/
nextIconButtonProps: PropTypes.object,
/**
* Callback fired when the page is changed.
*
* @param {object} event The event source of the callback
* @param {number} page The page selected
*/
onChangePage: PropTypes.func.isRequired,
/**
* Callback fired when the number of rows per page is changed.
*
* @param {object} event The event source of the callback
*/
onChangeRowsPerPage: PropTypes.func,
/**
* The zero-based index of the current page.
*/
page: PropTypes.number.isRequired,
/**
* The number of rows per page.
*/
rowsPerPage: PropTypes.number.isRequired,
/**
* Customizes the options of the rows per page select field. If less than two options are
* available, no select field will be displayed.
*/
rowsPerPageOptions: PropTypes.array,
};
TablePagination.defaultProps = {
Actions: TablePaginationActions,
component: TableCell,
labelDisplayedRows: ({ from, to, count }) => `${from}-${to} of ${count}`,
labelRowsPerPage: 'Rows per page:',
rowsPerPageOptions: [5, 10, 25],
};
export default withStyles(styles, { name: 'MuiTablePagination' })(TablePagination);

View File

@@ -0,0 +1,20 @@
import * as React from 'react';
import { StandardProps } from '..';
import { TableCellClassKey } from './TableCell.d';
import { IconButtonProps } from '../IconButton/IconButton';
export interface TablePaginationActionsProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, TablePaginationActionsClassKey> {
backIconButtonProps?: Partial<IconButtonProps>;
count: number;
nextIconButtonProps?: Partial<IconButtonProps>;
onChangePage: (event: React.MouseEvent<HTMLButtonElement> | null, page: number) => void;
page: number;
rowsPerPage: number;
}
export type TablePaginationActionsClassKey = 'root';
declare const TablePaginationActions: React.ComponentType<TablePaginationActionsProps>;
export default TablePaginationActions;

View File

@@ -0,0 +1,183 @@
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.styles = undefined;
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _KeyboardArrowLeft = require('../internal/svg-icons/KeyboardArrowLeft');
var _KeyboardArrowLeft2 = _interopRequireDefault(_KeyboardArrowLeft);
var _KeyboardArrowRight = require('../internal/svg-icons/KeyboardArrowRight');
var _KeyboardArrowRight2 = _interopRequireDefault(_KeyboardArrowRight);
var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
var _IconButton = require('../IconButton');
var _IconButton2 = _interopRequireDefault(_IconButton);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var styles = exports.styles = function styles(theme) {
return {
root: {
flexShrink: 0,
color: theme.palette.text.secondary,
marginLeft: theme.spacing.unit * 2.5
}
};
};
/**
* @ignore - internal component.
*/
var _ref2 = _react2.default.createElement(_KeyboardArrowRight2.default, null);
var _ref3 = _react2.default.createElement(_KeyboardArrowLeft2.default, null);
var _ref4 = _react2.default.createElement(_KeyboardArrowLeft2.default, null);
var _ref5 = _react2.default.createElement(_KeyboardArrowRight2.default, null);
var TablePaginationActions = function (_React$Component) {
(0, _inherits3.default)(TablePaginationActions, _React$Component);
function TablePaginationActions() {
var _ref;
var _temp, _this, _ret;
(0, _classCallCheck3.default)(this, TablePaginationActions);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = TablePaginationActions.__proto__ || (0, _getPrototypeOf2.default)(TablePaginationActions)).call.apply(_ref, [this].concat(args))), _this), _this.handleBackButtonClick = function (event) {
_this.props.onChangePage(event, _this.props.page - 1);
}, _this.handleNextButtonClick = function (event) {
_this.props.onChangePage(event, _this.props.page + 1);
}, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
}
(0, _createClass3.default)(TablePaginationActions, [{
key: 'render',
value: function render() {
var _props = this.props,
backIconButtonProps = _props.backIconButtonProps,
classes = _props.classes,
count = _props.count,
nextIconButtonProps = _props.nextIconButtonProps,
onChangePage = _props.onChangePage,
page = _props.page,
rowsPerPage = _props.rowsPerPage,
theme = _props.theme,
other = (0, _objectWithoutProperties3.default)(_props, ['backIconButtonProps', 'classes', 'count', 'nextIconButtonProps', 'onChangePage', 'page', 'rowsPerPage', 'theme']);
return _react2.default.createElement(
'div',
(0, _extends3.default)({ className: classes.root }, other),
_react2.default.createElement(
_IconButton2.default,
(0, _extends3.default)({
onClick: this.handleBackButtonClick,
disabled: page === 0
}, backIconButtonProps),
theme.direction === 'rtl' ? _ref2 : _ref3
),
_react2.default.createElement(
_IconButton2.default,
(0, _extends3.default)({
onClick: this.handleNextButtonClick,
disabled: page >= Math.ceil(count / rowsPerPage) - 1
}, nextIconButtonProps),
theme.direction === 'rtl' ? _ref4 : _ref5
)
);
}
}]);
return TablePaginationActions;
}(_react2.default.Component);
TablePaginationActions.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* Properties applied to the back arrow `IconButton` component.
*/
backIconButtonProps: _propTypes2.default.object,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* The total number of rows.
*/
count: _propTypes2.default.number.isRequired,
/**
* Properties applied to the next arrow `IconButton` component.
*/
nextIconButtonProps: _propTypes2.default.object,
/**
* Callback fired when the page is changed.
*
* @param {object} event The event source of the callback
* @param {number} page The page selected
*/
onChangePage: _propTypes2.default.func.isRequired,
/**
* The zero-based index of the current page.
*/
page: _propTypes2.default.number.isRequired,
/**
* The number of rows per page.
*/
rowsPerPage: _propTypes2.default.number.isRequired,
/**
* @ignore
*/
theme: _propTypes2.default.object.isRequired
} : {};
exports.default = (0, _withStyles2.default)(styles, { name: 'MuiTablePaginationActions', withTheme: true })(TablePaginationActions);

View File

@@ -0,0 +1,102 @@
import React from 'react';
import PropTypes from 'prop-types';
import KeyboardArrowLeft from '../internal/svg-icons/KeyboardArrowLeft';
import KeyboardArrowRight from '../internal/svg-icons/KeyboardArrowRight';
import withStyles from '../styles/withStyles';
import IconButton from '../IconButton';
export const styles = theme => ({
root: {
flexShrink: 0,
color: theme.palette.text.secondary,
marginLeft: theme.spacing.unit * 2.5,
},
});
/**
* @ignore - internal component.
*/
class TablePaginationActions extends React.Component {
handleBackButtonClick = event => {
this.props.onChangePage(event, this.props.page - 1);
};
handleNextButtonClick = event => {
this.props.onChangePage(event, this.props.page + 1);
};
render() {
const {
backIconButtonProps,
classes,
count,
nextIconButtonProps,
onChangePage,
page,
rowsPerPage,
theme,
...other
} = this.props;
return (
<div className={classes.root} {...other}>
<IconButton
onClick={this.handleBackButtonClick}
disabled={page === 0}
{...backIconButtonProps}
>
{theme.direction === 'rtl' ? <KeyboardArrowRight /> : <KeyboardArrowLeft />}
</IconButton>
<IconButton
onClick={this.handleNextButtonClick}
disabled={page >= Math.ceil(count / rowsPerPage) - 1}
{...nextIconButtonProps}
>
{theme.direction === 'rtl' ? <KeyboardArrowLeft /> : <KeyboardArrowRight />}
</IconButton>
</div>
);
}
}
TablePaginationActions.propTypes = {
/**
* Properties applied to the back arrow `IconButton` component.
*/
backIconButtonProps: PropTypes.object,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* The total number of rows.
*/
count: PropTypes.number.isRequired,
/**
* Properties applied to the next arrow `IconButton` component.
*/
nextIconButtonProps: PropTypes.object,
/**
* Callback fired when the page is changed.
*
* @param {object} event The event source of the callback
* @param {number} page The page selected
*/
onChangePage: PropTypes.func.isRequired,
/**
* The zero-based index of the current page.
*/
page: PropTypes.number.isRequired,
/**
* The number of rows per page.
*/
rowsPerPage: PropTypes.number.isRequired,
/**
* @ignore
*/
theme: PropTypes.object.isRequired,
};
export default withStyles(styles, { name: 'MuiTablePaginationActions', withTheme: true })(
TablePaginationActions,
);

View File

@@ -1,21 +1,15 @@
import * as React from 'react';
import { StandardProps } from '..';
export interface TableRowProps extends StandardProps<
React.HTMLAttributes<HTMLTableRowElement>,
TableRowClassKey
> {
export interface TableRowProps extends StandardProps<TableRowBaseProps, TableRowClassKey> {
component?: React.ReactType<TableRowBaseProps>;
hover?: boolean;
selected?: boolean;
}
export type TableRowClassKey =
| 'root'
| 'head'
| 'footer'
| 'hover'
| 'selected'
;
export type TableRowBaseProps = React.HTMLAttributes<HTMLTableRowElement>;
export type TableRowClassKey = 'root' | 'typeHead' | 'typeFooter' | 'hover' | 'selected';
declare const TableRow: React.ComponentType<TableRowProps>;

View File

@@ -17,8 +17,6 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
@@ -37,10 +35,6 @@ var _withStyles2 = _interopRequireDefault(_withStyles);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_ElementType = require('react').babelPluginFlowReactPropTypes_proptype_ElementType || require('prop-types').any;
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
var styles = exports.styles = function styles(theme) {
return {
root: {
@@ -52,60 +46,25 @@ var styles = exports.styles = function styles(theme) {
},
verticalAlign: 'middle'
},
head: {
typeHead: {
height: 56
},
footer: {
typeFooter: {
height: 56
},
selected: {
backgroundColor: theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.04)' // grey[100]
: 'rgba(255, 255, 255, 0.08)'
},
hover: {
'&:hover': {
background: theme.palette.background.contentFrame
backgroundColor: theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.07)' // grey[200]
: 'rgba(255, 255, 255, 0.14)'
}
},
selected: {
background: theme.palette.background.appBar
}
};
};
var babelPluginFlowReactPropTypes_proptype_Context = {
table: require('prop-types').object.isRequired
};
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* Should be valid `<tr>` children such as `TableCell`.
*/
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.
*/
component: typeof babelPluginFlowReactPropTypes_proptype_ElementType === 'function' ? babelPluginFlowReactPropTypes_proptype_ElementType : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_ElementType),
/**
* If `true`, the table row will shade on hover.
*/
hover: require('prop-types').bool,
/**
* If `true`, the table row will have the selected shading.
*/
selected: require('prop-types').bool
};
/**
* Will automatically set dynamic row height
* based on the material table element parent (head, body, etc).
@@ -115,34 +74,50 @@ function TableRow(props, context) {
var classes = props.classes,
classNameProp = props.className,
children = props.children,
Component = props.component,
hover = props.hover,
selected = props.selected,
other = (0, _objectWithoutProperties3.default)(props, ['classes', 'className', 'children', 'component', 'hover', 'selected']);
other = (0, _objectWithoutProperties3.default)(props, ['classes', 'className', 'component', 'hover', 'selected']);
var table = context.table;
var className = (0, _classnames2.default)(classes.root, (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes.head, table && table.head), (0, _defineProperty3.default)(_classNames, classes.footer, table && table.footer), (0, _defineProperty3.default)(_classNames, classes.hover, table && hover), (0, _defineProperty3.default)(_classNames, classes.selected, table && selected), _classNames), classNameProp);
var className = (0, _classnames2.default)(classes.root, (_classNames = {}, (0, _defineProperty3.default)(_classNames, classes.typeHead, table && table.head), (0, _defineProperty3.default)(_classNames, classes.typeFooter, table && table.footer), (0, _defineProperty3.default)(_classNames, classes.hover, table && hover), (0, _defineProperty3.default)(_classNames, classes.selected, table && selected), _classNames), classNameProp);
return _react2.default.createElement(
Component,
(0, _extends3.default)({ className: className }, other),
children
);
return _react2.default.createElement(Component, (0, _extends3.default)({ className: className }, other));
}
TableRow.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,
hover: require('prop-types').bool.isRequired,
selected: require('prop-types').bool.isRequired,
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, 'hover', require('prop-types').bool), (0, _defineProperty3.default)(_ref, 'selected', require('prop-types').bool), _ref) : {};
TableRow.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* Should be valid `<tr>` children such as `TableCell`.
*/
children: _propTypes2.default.node,
/**
* 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]),
/**
* If `true`, the table row will shade on hover.
*/
hover: _propTypes2.default.bool,
/**
* If `true`, the table row will have the selected shading.
*/
selected: _propTypes2.default.bool
} : {};
TableRow.defaultProps = {
component: 'tr',
hover: false,
selected: false,
component: 'tr'
selected: false
};
TableRow.contextTypes = {

View File

@@ -1,12 +1,9 @@
// @flow
import React from 'react';
import type { Node, ElementType } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import withStyles from '../styles/withStyles';
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
color: 'inherit',
display: 'table-row',
@@ -16,70 +13,36 @@ export const styles = (theme: Object) => ({
},
verticalAlign: 'middle',
},
head: {
typeHead: {
height: 56,
},
footer: {
typeFooter: {
height: 56,
},
selected: {
backgroundColor:
theme.palette.type === 'light'
? 'rgba(0, 0, 0, 0.04)' // grey[100]
: 'rgba(255, 255, 255, 0.08)',
},
hover: {
'&:hover': {
background: theme.palette.background.contentFrame,
backgroundColor:
theme.palette.type === 'light'
? 'rgba(0, 0, 0, 0.07)' // grey[200]
: 'rgba(255, 255, 255, 0.14)',
},
},
selected: {
background: theme.palette.background.appBar,
},
});
export type Context = {
table: Object,
};
type ProvidedProps = {
classes: Object,
component: ElementType,
hover: boolean,
selected: boolean,
};
export type Props = {
/**
* Should be valid `<tr>` children such as `TableCell`.
*/
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.
*/
component?: ElementType,
/**
* If `true`, the table row will shade on hover.
*/
hover?: boolean,
/**
* If `true`, the table row will have the selected shading.
*/
selected?: boolean,
};
/**
* Will automatically set dynamic row height
* based on the material table element parent (head, body, etc).
*/
function TableRow(props: ProvidedProps & Props, context: Context) {
function TableRow(props, context) {
const {
classes,
className: classNameProp,
children,
component: Component,
hover,
selected,
@@ -90,25 +53,49 @@ function TableRow(props: ProvidedProps & Props, context: Context) {
const className = classNames(
classes.root,
{
[classes.head]: table && table.head,
[classes.footer]: table && table.footer,
[classes.typeHead]: table && table.head,
[classes.typeFooter]: table && table.footer,
[classes.hover]: table && hover,
[classes.selected]: table && selected,
},
classNameProp,
);
return (
<Component className={className} {...other}>
{children}
</Component>
);
return <Component className={className} {...other} />;
}
TableRow.propTypes = {
/**
* Should be valid `<tr>` children such as `TableCell`.
*/
children: PropTypes.node,
/**
* 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]),
/**
* If `true`, the table row will shade on hover.
*/
hover: PropTypes.bool,
/**
* If `true`, the table row will have the selected shading.
*/
selected: PropTypes.bool,
};
TableRow.defaultProps = {
component: 'tr',
hover: false,
selected: false,
component: 'tr',
};
TableRow.contextTypes = {

View File

@@ -2,21 +2,13 @@ import * as React from 'react';
import { StandardProps } from '..';
import { ButtonBaseProps, ButtonBaseClassKey } from '../ButtonBase';
export interface TableSortLabelProps extends StandardProps<
ButtonBaseProps,
TableSortLabelClassKey
> {
export interface TableSortLabelProps
extends StandardProps<ButtonBaseProps, TableSortLabelClassKey> {
active?: boolean;
direction?: 'asc' | 'desc';
}
export type TableSortLabelClassKey =
| ButtonBaseClassKey
| 'active'
| 'icon'
| 'desc'
| 'asc'
;
export type TableSortLabelClassKey = ButtonBaseClassKey | 'active' | 'icon' | 'desc' | 'asc';
declare const TableSortLabel: React.ComponentType<TableSortLabelProps>;

View File

@@ -17,17 +17,22 @@ var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProp
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
var _ref;
// @inheritedComponent ButtonBase
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);
var _ArrowDownward = require('../internal/svg-icons/ArrowDownward');
var _ArrowDownward2 = _interopRequireDefault(_ArrowDownward);
var _withStyles = require('../styles/withStyles');
var _withStyles2 = _interopRequireDefault(_withStyles);
@@ -36,13 +41,9 @@ var _ButtonBase = require('../ButtonBase');
var _ButtonBase2 = _interopRequireDefault(_ButtonBase);
var _ArrowDownward = require('../svg-icons/ArrowDownward');
var _ArrowDownward2 = _interopRequireDefault(_ArrowDownward);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any;
// @inheritedComponent ButtonBase
var styles = exports.styles = function styles(theme) {
return {
@@ -85,36 +86,6 @@ var styles = exports.styles = function styles(theme) {
};
};
var babelPluginFlowReactPropTypes_proptype_Direction = require('prop-types').oneOf(['asc', 'desc']);
var babelPluginFlowReactPropTypes_proptype_Props = {
/**
* If `true`, the label will have the active styling (should be true for the sorted column).
*/
active: require('prop-types').bool,
/**
* Label contents, the arrow will be appended automatically.
*/
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 current sort direction.
*/
direction: require('prop-types').oneOf(['asc', 'desc'])
};
/**
* A button based label for placing inside `TableCell` for column sorting.
*/
@@ -138,11 +109,29 @@ function TableSortLabel(props) {
);
}
TableSortLabel.propTypes = process.env.NODE_ENV !== "production" ? (_ref = {
active: require('prop-types').bool.isRequired,
classes: require('prop-types').object.isRequired,
direction: require('prop-types').oneOf(['asc', 'desc']).isRequired
}, (0, _defineProperty3.default)(_ref, 'active', require('prop-types').bool), (0, _defineProperty3.default)(_ref, '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, 'direction', require('prop-types').oneOf(['asc', 'desc'])), _ref) : {};
TableSortLabel.propTypes = process.env.NODE_ENV !== "production" ? {
/**
* If `true`, the label will have the active styling (should be true for the sorted column).
*/
active: _propTypes2.default.bool,
/**
* Label contents, the arrow will be appended automatically.
*/
children: _propTypes2.default.node,
/**
* Useful to extend the style applied to components.
*/
classes: _propTypes2.default.object.isRequired,
/**
* @ignore
*/
className: _propTypes2.default.string,
/**
* The current sort direction.
*/
direction: _propTypes2.default.oneOf(['asc', 'desc'])
} : {};
TableSortLabel.defaultProps = {
active: false,
direction: 'desc'

View File

@@ -1,14 +1,13 @@
// @flow
// @inheritedComponent ButtonBase
import React from 'react';
import type { Node } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import ArrowDownwardIcon from '../internal/svg-icons/ArrowDownward';
import withStyles from '../styles/withStyles';
import ButtonBase from '../ButtonBase';
import ArrowDownwardIcon from '../svg-icons/ArrowDownward';
export const styles = (theme: Object) => ({
export const styles = theme => ({
root: {
cursor: 'pointer',
display: 'inline-flex',
@@ -47,41 +46,10 @@ export const styles = (theme: Object) => ({
},
});
export type Direction = 'asc' | 'desc';
type ProvidedProps = {
active: boolean,
classes: Object,
direction: Direction,
};
export type Props = {
/**
* If `true`, the label will have the active styling (should be true for the sorted column).
*/
active?: boolean,
/**
* Label contents, the arrow will be appended automatically.
*/
children?: Node,
/**
* Useful to extend the style applied to components.
*/
classes?: Object,
/**
* @ignore
*/
className?: string,
/**
* The current sort direction.
*/
direction?: Direction,
};
/**
* A button based label for placing inside `TableCell` for column sorting.
*/
function TableSortLabel(props: ProvidedProps & Props) {
function TableSortLabel(props) {
const { active, classes, className: classNameProp, children, direction, ...other } = props;
const className = classNames(
classes.root,
@@ -103,6 +71,29 @@ function TableSortLabel(props: ProvidedProps & Props) {
);
}
TableSortLabel.propTypes = {
/**
* If `true`, the label will have the active styling (should be true for the sorted column).
*/
active: PropTypes.bool,
/**
* Label contents, the arrow will be appended automatically.
*/
children: PropTypes.node,
/**
* Useful to extend the style applied to components.
*/
classes: PropTypes.object.isRequired,
/**
* @ignore
*/
className: PropTypes.string,
/**
* The current sort direction.
*/
direction: PropTypes.oneOf(['asc', 'desc']),
};
TableSortLabel.defaultProps = {
active: false,
direction: 'desc',

View File

@@ -1,5 +1,3 @@
// @flow
export { default } from './Table';
export { default as TableBody } from './TableBody';
export { default as TableCell } from './TableCell';