UNPKG

sophia-components

Version:
158 lines (123 loc) 4.71 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); 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; }; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _compose = require('recompose/compose'); var _compose2 = _interopRequireDefault(_compose); var _withAttrs = require('../base/withAttrs'); var _withAttrs2 = _interopRequireDefault(_withAttrs); var _withIsHas = require('../base/withIsHas'); var _withIsHas2 = _interopRequireDefault(_withIsHas); var _helpers = require('../utils/helpers'); var _withEvents = require('../base/withEvents'); var _withEvents2 = _interopRequireDefault(_withEvents); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } 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; } /* eslint-disable react/prop-types */ var mappedTag = { p: function p(_ref) { var children = _ref.children, props = _objectWithoutProperties(_ref, ['children']); return _react2.default.createElement( 'p', props, children ); }, h1: function h1(_ref2) { var children = _ref2.children, props = _objectWithoutProperties(_ref2, ['children']); return _react2.default.createElement( 'h1', props, children ); }, h2: function h2(_ref3) { var children = _ref3.children, props = _objectWithoutProperties(_ref3, ['children']); return _react2.default.createElement( 'h2', props, children ); }, h3: function h3(_ref4) { var children = _ref4.children, props = _objectWithoutProperties(_ref4, ['children']); return _react2.default.createElement( 'h3', props, children ); }, h4: function h4(_ref5) { var children = _ref5.children, props = _objectWithoutProperties(_ref5, ['children']); return _react2.default.createElement( 'h4', props, children ); }, h5: function h5(_ref6) { var children = _ref6.children, props = _objectWithoutProperties(_ref6, ['children']); return _react2.default.createElement( 'h5', props, children ); }, h6: function h6(_ref7) { var children = _ref7.children, props = _objectWithoutProperties(_ref7, ['children']); return _react2.default.createElement( 'h6', props, children ); } }; var sizes = ['one', 'two', 'three', 'four', 'five', 'six']; var Subtitle = function Subtitle(_ref8) { var children = _ref8.children, as = _ref8.as, attrs = _ref8.attrs, events = _ref8.events, restProps = _objectWithoutProperties(_ref8, ['children', 'as', 'attrs', 'events']); var MappedComponent = mappedTag[as]; var className = attrs.className, restAttrs = _objectWithoutProperties(attrs, ['className']); var sizeClassIndex = sizes.findIndex(function (size) { return restProps[size]; }); var sizeClassNameProp = sizeClassIndex !== -1 ? 'is-' + (sizeClassIndex + 1) : null; return _react2.default.createElement( MappedComponent, _extends({ className: (0, _helpers.classNameJoiner)('subtitle', sizeClassNameProp, className) }, events, restAttrs), children ); }; Subtitle.propTypes = _extends({ children: _propTypes2.default.node, as: _propTypes2.default.oneOf(['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']), attrs: _propTypes2.default.shape().isRequired, events: _propTypes2.default.shape().isRequired }, sizes.reduce(function (acum, size) { return _extends({}, acum, _defineProperty({}, size, _propTypes2.default.bool)); }, {})); Subtitle.defaultProps = _extends({ children: null, as: 'h2' }, sizes.reduce(function (acum, size) { return _extends({}, acum, _defineProperty({}, size, false)); }, {})); exports.default = (0, _compose2.default)((0, _withEvents2.default)(), (0, _withIsHas2.default)((0, _helpers.combineSets)(_withIsHas.helpersIsKeys, ['spaced']), _withIsHas.helpersHasKeys), (0, _withAttrs2.default)())(Subtitle);