UNPKG

kitten-components

Version:
135 lines (106 loc) 5.77 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.LinkList = 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 _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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 LinkList = exports.LinkList = function (_Component) { _inherits(LinkList, _Component); function LinkList() { _classCallCheck(this, LinkList); var _this = _possibleConstructorReturn(this, (LinkList.__proto__ || Object.getPrototypeOf(LinkList)).call(this)); _this.renderItem = _this.renderItem.bind(_this); return _this; } _createClass(LinkList, [{ key: 'renderItems', value: function renderItems() { return this.props.items.map(this.renderItem); } }, { key: 'renderItem', value: function renderItem(element) { var key = element.key, item = element.item, href = element.href, active = element.active, weight = element.weight, className = element.className, others = _objectWithoutProperties(element, ['key', 'item', 'href', 'active', 'weight', 'className']); var _props = this.props, color = _props.color, lineHeight = _props.lineHeight, itemMargin = _props.itemMargin; var linkListClassName = (0, _classnames2.default)('k-LinkList__link', className, { 'is-active': active, 'k-LinkList__link--light': color == 'light', 'k-LinkList__link--dark': color == 'dark', 'k-LinkList__link--normalLineHeight': lineHeight == 'normal', 'k-LinkList__link--regularWeight': this.props.weight == 'regular' && !weight, 'k-LinkList__link--lightWeight': this.props.weight == 'light' && !weight, 'k-LinkList__item--regularWeight': weight == 'regular', 'k-LinkList__item--lightWeight': weight == 'light' }); var linkListItemClassName = (0, _classnames2.default)('k-LinkList__item', { 'k-LinkList__item--doubleMargin': itemMargin == 'double', 'k-LinkList__item--tripleMargin': itemMargin == 'triple' }); return _react2.default.createElement( 'li', { className: linkListItemClassName, key: key }, _react2.default.createElement( 'a', _extends({}, others, { href: href, className: linkListClassName }), item ) ); } }, { key: 'render', value: function render() { var _props2 = this.props, className = _props2.className, margin = _props2.margin, items = _props2.items, lineHeight = _props2.lineHeight, itemMargin = _props2.itemMargin, others = _objectWithoutProperties(_props2, ['className', 'margin', 'items', 'lineHeight', 'itemMargin']); var listClassName = (0, _classnames2.default)('k-LinkList', className, { 'k-LinkList--withoutMargin': !margin }); return _react2.default.createElement( 'ul', _extends({}, others, { className: listClassName }), this.renderItems() ); } }]); return LinkList; }(_react.Component); LinkList.propTypes = { color: _propTypes2.default.oneOf(['light', 'dark']), lineHeight: _propTypes2.default.oneOf(['normal']), itemMargin: _propTypes2.default.oneOf(['double', 'triple']), weight: _propTypes2.default.oneOf(['regular', 'light']) }; LinkList.defaultProps = { className: null, margin: true, items: [], // Eg: [{ key: …, item: …, href: …, weight: …, }] color: 'dark', lineHeight: null, itemMargin: null, weight: 'regular' };