UNPKG

@attivio/suit

Version:

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

128 lines (106 loc) 4.79 kB
'use strict'; exports.__esModule = true; exports.default = undefined; var _class, _temp; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _Glyphicon = require('react-bootstrap/lib/Glyphicon'); var _Glyphicon2 = _interopRequireDefault(_Glyphicon); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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; } /** * This is a panel that the user can expand or collapse by clicking * its header. It's similar to the CollapsiblePanel component except that * instead of a caret on the right side of the control, there's a triangle * icon to the left of the title which points to the right when closed and * down when open, the same as the "disclosure triangles" used in many UIs. * It can optionally remember the open/closed state between uses by using * the browser's local storage. */ var TrianglePanel = (_temp = _class = function (_React$Component) { _inherits(TrianglePanel, _React$Component); // eslint-disable-line max-len function TrianglePanel(props) { _classCallCheck(this, TrianglePanel); // If the localStorageKey is set, try to get the initial value for "open" from there. // Otherwise use the value passed in as initallyCollapsed. var _this = _possibleConstructorReturn(this, _React$Component.call(this, props)); var initiallyCollapsed = _this.props.initiallyCollapsed; if (_this.props.localStorageKey) { var collapsedString = window.localStorage.getItem(_this.props.localStorageKey); if (collapsedString !== null) { initiallyCollapsed = collapsedString === 'true'; } } _this.state = { open: !initiallyCollapsed }; _this.toggleState = _this.toggleState.bind(_this); return _this; } TrianglePanel.prototype.toggleState = function toggleState() { var updatedOpen = !this.state.open; if (this.props.localStorageKey) { window.localStorage.setItem(this.props.localStorageKey, updatedOpen ? 'false' : 'true'); } this.setState({ open: updatedOpen }); if (this.link) { this.link.blur(); } }; TrianglePanel.prototype.render = function render() { var _this2 = this; var outerClassName = this.props.bordered ? 'attivio-facet attivio-card' : 'attivio-facet'; var bottomClassName = this.state.open ? 'panel-collapse collapse in' : 'panel-collapse collapse'; var glyph = this.state.open ? 'triangle-bottom' : 'triangle-right'; var dataTestValue = this.props.dataTestValue; return _react2.default.createElement( 'div', { className: outerClassName }, _react2.default.createElement( 'h3', { className: 'attivio-facet-hed' }, _react2.default.createElement( 'a', { 'data-toggle': 'collapse', 'aria-expanded': this.state.open, 'aria-controls': 'key-phrases', id: this.props.id + '-hed', onClick: this.toggleState, role: 'button', tabIndex: 0, ref: function ref(c) { _this2.link = c; }, 'data-test': dataTestValue }, _react2.default.createElement(_Glyphicon2.default, { glyph: glyph }), '\xA0', this.props.title ) ), _react2.default.createElement( 'div', { id: this.props.id, className: bottomClassName, role: 'tabpanel', 'aria-labelledby': this.props.id + '-hed', 'aria-expanded': this.state.open }, this.props.children ) ); }; return TrianglePanel; }(_react2.default.Component), _class.defaultProps = { bordered: false, initiallyCollapsed: false, localStorageKey: null, dataTestValue: null }, _class.displayName = 'TrianglePanel', _temp); exports.default = TrianglePanel; module.exports = exports['default'];