sophia-components
Version:
Sophia React Components based on bulma.io
90 lines (64 loc) • 3.74 kB
JavaScript
'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 _Icon = require('../elements/Icon');
var _Icon2 = _interopRequireDefault(_Icon);
var _withAttrs = require('../base/withAttrs');
var _withAttrs2 = _interopRequireDefault(_withAttrs);
var _withIsHas = require('../base/withIsHas');
var _withIsHas2 = _interopRequireDefault(_withIsHas);
var _withEvents = require('../base/withEvents');
var _withEvents2 = _interopRequireDefault(_withEvents);
var _helpers = require('../utils/helpers');
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; }
var Control = function Control(_ref) {
var _ref$attrs = _ref.attrs,
className = _ref$attrs.className,
restAttrs = _objectWithoutProperties(_ref$attrs, ['className']),
events = _ref.events,
children = _ref.children,
iconLeft = _ref.iconLeft,
iconLeftSize = _ref.iconLeftSize,
iconRight = _ref.iconRight,
iconRightSize = _ref.iconRightSize;
var iconLeftProps = !iconLeftSize ? {} : _defineProperty({}, iconLeftSize, true);
var iconLeftElement = !iconLeft ? null : _react2.default.createElement(_Icon2.default, _extends({ icon: iconLeft, left: true }, iconLeftProps));
var iconLeftClassName = !iconLeftElement || typeof className === 'string' && className.includes('has-icons-left') ? null : 'has-icons-left';
var iconRightProps = !iconRightSize ? {} : _defineProperty({}, iconRightSize, true);
var iconRightElement = !iconRight ? null : _react2.default.createElement(_Icon2.default, _extends({ icon: iconRight, right: true }, iconRightProps));
var iconRightClassName = !iconRightElement || typeof className === 'string' && className.includes('has-icons-right') ? null : 'has-icons-right';
return _react2.default.createElement(
'div',
_extends({ className: (0, _helpers.classNameJoiner)('control', className, iconLeftClassName, iconRightClassName) }, events, restAttrs),
children,
iconLeftElement,
iconRightElement
);
};
Control.propTypes = {
children: _propTypes2.default.node,
iconLeft: _propTypes2.default.string,
iconLeftSize: _propTypes2.default.string,
iconRight: _propTypes2.default.string,
iconRightSize: _propTypes2.default.string,
attrs: _propTypes2.default.shape().isRequired,
events: _propTypes2.default.shape().isRequired
};
Control.defaultProps = {
children: null,
iconLeft: null,
iconLeftSize: null,
iconRight: null,
iconRightSize: null
};
exports.default = (0, _compose2.default)((0, _withEvents2.default)(), (0, _withIsHas2.default)((0, _helpers.combineSets)(_withIsHas.helpersIsKeys, ['expanded']), (0, _helpers.combineSets)(_withIsHas.helpersHasKeys, ['iconsRight', 'iconsLeft'])), (0, _withAttrs2.default)())(Control);