UNPKG

material-ui-cordova

Version:

React components that implement Google's Material Design.

91 lines (81 loc) 3.03 kB
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import withStyles from '../styles/withStyles'; import { capitalizeFirstLetter } from '../utils/helpers'; import { darken, fade, lighten } from '../styles/colorManipulator'; export const styles = theme => ({ root: { // 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.text.lightDivider, 1), 0.925) : darken(fade(theme.palette.text.lightDivider, 1), 0.685)}`, textAlign: 'left' }, numeric: { textAlign: 'right', flexDirection: 'row-reverse' // can be dynamically inherited at runtime by contents }, head: { fontWeight: theme.typography.fontWeightMedium, position: 'relative' // Workaround for Tooltip positioning issue. }, paddingDefault: { padding: `${theme.spacing.unit / 2}px ${theme.spacing.unit * 7}px ${theme.spacing.unit / 2}px ${theme.spacing.unit * 3}px`, '&:last-child': { paddingRight: theme.spacing.unit * 3 } }, paddingDense: { paddingRight: theme.spacing.unit * 3 }, paddingCheckbox: { padding: '0 12px' }, footer: { borderBottom: 0 } }); class TableCell extends React.Component { render() { const _props = this.props, { classes, className: classNameProp, children, numeric, padding, component } = _props, other = _objectWithoutProperties(_props, ['classes', 'className', 'children', 'numeric', 'padding', 'component']); const { table } = this.context; let Component; if (component) { Component = component; } else { Component = table && table.head ? 'th' : 'td'; } const className = classNames(classes.root, { [classes.numeric]: numeric, [classes[`padding${capitalizeFirstLetter(padding)}`]]: padding !== 'none' && padding !== 'default', [classes.paddingDefault]: padding !== 'none', [classes.head]: table && table.head, [classes.footer]: table && table.footer }, classNameProp); return React.createElement( Component, _extends({ className: className }, other), children ); } } TableCell.defaultProps = { numeric: false, padding: 'default' }; TableCell.contextTypes = { table: PropTypes.object.isRequired }; export default withStyles(styles, { name: 'MuiTableCell' })(TableCell);