UNPKG

kitten-components

Version:
214 lines (164 loc) 8.18 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.ArrowIcon = undefined; 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 _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _radium = require('radium'); var _radium2 = _interopRequireDefault(_radium); var _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _deprecated = require('kitten/helpers/utils/deprecated'); var _colorsConfig = require('kitten/constants/colors-config'); var _colorsConfig2 = _interopRequireDefault(_colorsConfig); 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; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var DeprecatedArrowIconSvgBase = function (_Component) { _inherits(DeprecatedArrowIconSvgBase, _Component); function DeprecatedArrowIconSvgBase() { _classCallCheck(this, DeprecatedArrowIconSvgBase); return _possibleConstructorReturn(this, (DeprecatedArrowIconSvgBase.__proto__ || Object.getPrototypeOf(DeprecatedArrowIconSvgBase)).apply(this, arguments)); } _createClass(DeprecatedArrowIconSvgBase, [{ key: 'render', value: function render() { var _classNames; var _props = this.props, className = _props.className, direction = _props.direction, disabled = _props.disabled, version = _props.version, others = _objectWithoutProperties(_props, ['className', 'direction', 'disabled', 'version']); var arrowIconClassNames = (0, _classnames2.default)('k-ArrowIcon', (_classNames = {}, _defineProperty(_classNames, 'k-ArrowIcon--' + direction, direction), _defineProperty(_classNames, 'k-ArrowIcon--disabled', disabled), _classNames), className); return _react2.default.createElement( 'svg', _extends({ className: arrowIconClassNames, xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 6 6' }, others), _react2.default.createElement( 'title', null, 'Arrow' ), _react2.default.createElement('path', { d: 'M6 0H0v6h2V2h4z' }) ); } }]); return DeprecatedArrowIconSvgBase; }(_react.Component); DeprecatedArrowIconSvgBase.propTypes = { direction: _propTypes2.default.oneOf(['top', 'bottom', 'left', 'right']), disabled: _propTypes2.default.bool, className: _propTypes2.default.string }; DeprecatedArrowIconSvgBase.defaultProps = { direction: 'right', disabled: false, className: '' }; var DeprecatedArrowIconSvg = (0, _radium2.default)(DeprecatedArrowIconSvgBase); var DeprecatedArrowIcon = function (_Component2) { _inherits(DeprecatedArrowIcon, _Component2); function DeprecatedArrowIcon() { _classCallCheck(this, DeprecatedArrowIcon); return _possibleConstructorReturn(this, (DeprecatedArrowIcon.__proto__ || Object.getPrototypeOf(DeprecatedArrowIcon)).apply(this, arguments)); } _createClass(DeprecatedArrowIcon, [{ key: 'render', value: function render() { var warningMessage = 'The previous version of ArrowIcon does not handle ' + 'correctly the center of gravity of the arrow. Please use now the prop ' + '`version` with the value `solid` to display an arrow with the right ' + 'center of gravity.'; return _react2.default.createElement( _deprecated.Deprecated, { warningMessage: warningMessage }, _react2.default.createElement( _react.Fragment, null, _react2.default.createElement(DeprecatedArrowIconSvg, this.props) ) ); } }]); return DeprecatedArrowIcon; }(_react.Component); DeprecatedArrowIcon.propTypes = { direction: _propTypes2.default.oneOf(['top', 'bottom', 'left', 'right']), disabled: _propTypes2.default.bool, className: _propTypes2.default.string }; DeprecatedArrowIcon.defaultProps = { direction: 'right', disabled: false, className: '' }; var ArrowIconBase = function (_Component3) { _inherits(ArrowIconBase, _Component3); function ArrowIconBase() { _classCallCheck(this, ArrowIconBase); return _possibleConstructorReturn(this, (ArrowIconBase.__proto__ || Object.getPrototypeOf(ArrowIconBase)).apply(this, arguments)); } _createClass(ArrowIconBase, [{ key: 'render', value: function render() { var _props2 = this.props, version = _props2.version, direction = _props2.direction, disabled = _props2.disabled, style = _props2.style, others = _objectWithoutProperties(_props2, ['version', 'direction', 'disabled', 'style']); if (version === 'deprecated-center-of-gravity') { return _react2.default.createElement(DeprecatedArrowIcon, this.props); } var arrowStyles = [style, direction && styles[direction], disabled && styles.disabled]; return _react2.default.createElement( 'svg', _extends({ style: arrowStyles, xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 8.48 5.64', height: '5.64', width: '8.48' }, others), _react2.default.createElement('path', { d: 'M0 4.24 L4.24,0 L8.48,4.24 L7.08,5.64 L4.24,2.77 L1.4,5.6 z' }) ); } }]); return ArrowIconBase; }(_react.Component); ArrowIconBase.propTypes = { version: _propTypes2.default.oneOf(['solid', 'deprecated-center-of-gravity']), direction: _propTypes2.default.oneOf(['top', 'bottom', 'left', 'right']), disabled: _propTypes2.default.bool, className: _propTypes2.default.string }; ArrowIconBase.defaultProps = { version: 'deprecated-center-of-gravity', direction: 'right', disabled: false, className: '' }; var styles = { right: { transform: 'rotate(90deg)' }, left: { transform: 'rotate(-90deg)' }, bottom: { transform: 'rotate(180deg)' }, disabled: { fill: _colorsConfig2.default.background1 } }; var ArrowIcon = exports.ArrowIcon = (0, _radium2.default)(ArrowIconBase);