UNPKG

react-hold

Version:

Hold the empty presentational components in react.js

63 lines (56 loc) 1.68 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; }; import React from 'react'; import PropTypes from 'prop-types'; import shapes from '../shapes'; import { CENTER } from '../align'; import { isNull } from '../utils'; var Square = function Square(_ref) { var color = _ref.color, width = _ref.width, height = _ref.height, children = _ref.children, side = _ref.side, align = _ref.align, fillerStyle = _ref.fillerStyle; if (isNull(side)) { if (!isNull(width) && !isNull(height)) { side = width > height ? height : width; } else if (!isNull(width)) { side = width; } else if (!isNull(height)) { side = height; } } var lineHeight = typeof side === 'string' && side.trim() ? side : typeof side === 'number' ? side + 'px' : null; return React.createElement( 'div', { style: { textAlign: align } }, React.createElement( 'div', { style: _extends({ background: color }, fillerStyle, { display: 'inline-block', textAlign: 'center', width: side, height: side, lineHeight: lineHeight }) }, children ) ); }; Square.propTypes = _extends({}, shapes, { side: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), align: PropTypes.string }); Square.defaultProps = { width: null, height: null, side: null, align: CENTER, fillerStyle: null }; export default Square;