UNPKG

@attivio/suit

Version:

Attivio SUIT, the Search UI Toolkit, is a library for creating search clients for searching the Attivio platform.

92 lines (71 loc) 3.29 kB
var _class2, _temp; 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; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } import React from 'react'; import CardPickerCard from './CardPickerCard'; import GridLayout from './GridLayout'; export var CardPickerItem = function CardPickerItem(label, key) { var iconUri = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; var description = arguments[3]; _classCallCheck(this, CardPickerItem); this.label = label; this.key = key; this.iconUri = iconUri; this.description = description; }; var CardPicker = (_temp = _class2 = function (_React$Component) { _inherits(CardPicker, _React$Component); function CardPicker(props) { _classCallCheck(this, CardPicker); var _this = _possibleConstructorReturn(this, _React$Component.call(this, props)); _this.state = { selection: _this.props.initialSelection }; _this.onClick = _this.onClick.bind(_this); return _this; } CardPicker.prototype.onClick = function onClick(key) { var _this2 = this; this.setState({ selection: key }, function () { _this2.props.onChange(key); }); }; CardPicker.prototype.render = function render() { var _this3 = this; var _props = this.props, dataTestPrefix = _props.dataTestPrefix, cards = _props.cards; var cardComponents = cards.map(function (cardItem, index) { var cardItemLabel = cardItem.label ? cardItem.label + '-' : ''; return React.createElement(CardPickerCard, { key: cardItem.label + '|' + (cardItem.iconUri ? cardItem.iconUri : 'noicon'), label: cardItem.label, iconUri: cardItem.iconUri || _this3.props.defaultIconUri, description: cardItem.description, defaultIconUri: _this3.props.defaultIconUri, selected: cardItem.key === _this3.state.selection, onClick: function onClick() { _this3.onClick(cardItem.key); }, columns: _this3.props.columns, dataTestValue: dataTestPrefix ? dataTestPrefix + '-' + cardItemLabel + index : null }); }); return React.createElement( GridLayout, null, cardComponents ); }; return CardPicker; }(React.Component), _class2.defaultProps = { initialSelection: null, defaultIconUri: null, columns: 3, dataTestPrefix: null }, _class2.displayName = 'CardPicker', _temp); export { CardPicker as default }; CardPicker.CardPickerItem = CardPickerItem;