@attivio/suit
Version:
Attivio SUIT, the Search UI Toolkit, is a library for creating search clients for searching the Attivio platform.
116 lines (99 loc) • 4.43 kB
JavaScript
var _class, _temp;
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; }
import React, { Children } from 'react';
import Glyphicon from 'react-bootstrap/lib/Glyphicon';
/**
* 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 React.createElement(
'div',
{ className: outerClassName },
React.createElement(
'h3',
{ className: 'attivio-facet-hed' },
React.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
},
React.createElement(Glyphicon, { glyph: glyph }),
'\xA0',
this.props.title
)
),
React.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;
}(React.Component), _class.defaultProps = {
bordered: false,
initiallyCollapsed: false,
localStorageKey: null,
dataTestValue: null
}, _class.displayName = 'TrianglePanel', _temp);
export { TrianglePanel as default };