UNPKG

@atlaskit/panel

Version:

A React component rendering a collapsible panel

68 lines (57 loc) 3.14 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } import React, { PureComponent } from 'react'; import AnimateHeight from 'react-animate-height'; import Button from '@atlaskit/button/custom-theme-button'; import ChevronDownIcon from '@atlaskit/icon/glyph/chevron-down'; import ChevronRightIcon from '@atlaskit/icon/glyph/chevron-right'; import * as styles from './styledPanel'; var PanelStateless = /*#__PURE__*/function (_PureComponent) { _inherits(PanelStateless, _PureComponent); var _super = _createSuper(PanelStateless); function PanelStateless() { _classCallCheck(this, PanelStateless); return _super.apply(this, arguments); } _createClass(PanelStateless, [{ key: "render", value: function render() { var _this$props = this.props, children = _this$props.children, header = _this$props.header, isExpanded = _this$props.isExpanded, onChange = _this$props.onChange; return /*#__PURE__*/React.createElement(styles.PanelWrapper, null, /*#__PURE__*/React.createElement(styles.PanelHeader, { onClick: function onClick() { return onChange(!isExpanded); } }, /*#__PURE__*/React.createElement(styles.ButtonWrapper, { isHidden: isExpanded }, /*#__PURE__*/React.createElement(Button, { appearance: "subtle", "aria-expanded": isExpanded, spacing: "none", iconBefore: isExpanded ? /*#__PURE__*/React.createElement(ChevronDownIcon, { label: "collapse" }) : /*#__PURE__*/React.createElement(ChevronRightIcon, { label: "expand" }) })), /*#__PURE__*/React.createElement("span", null, header)), /*#__PURE__*/React.createElement(AnimateHeight, { duration: 200, easing: "linear", height: isExpanded ? 'auto' : 0 }, children)); } }]); return PanelStateless; }(PureComponent); _defineProperty(PanelStateless, "defaultProps", { isExpanded: false }); export { PanelStateless as default };