UNPKG

react-life-design

Version:
49 lines 2.58 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var React = require("react"); var Icons_1 = require("../Icons"); var Accordion_styled_1 = require("./Accordion.styled"); var WrapperAccordion = (function (_super) { __extends(WrapperAccordion, _super); function WrapperAccordion() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.accordionRef = React.createRef(); _this.state = { initialHeight: 0, active: false, }; _this.onToggle = function () { return _this.setState(function (prevState) { return ({ active: !prevState.active }); }, _this.props.click(_this.state.active)); }; _this.isAutomatic = function () { return _this.props.activeIndex === _this.props.active; }; _this.isActive = function () { return (_this.props.automatic) ? _this.isAutomatic() : _this.state.active; }; _this.render = function () { return (React.createElement(Accordion_styled_1.Wrapper, { active: _this.isActive(), ref: _this.accordionRef, initialHeight: _this.state.initialHeight }, React.createElement(Accordion_styled_1.Header, { onClick: _this.onToggle, active: _this.isActive() }, _this.props.header, React.createElement("div", { className: 'label-icons' }, _this.props.labels, React.createElement(Icons_1.default.Arrow, { degree: _this.isActive() ? 0 : 180, width: 20, height: 20 }))), React.createElement(Accordion_styled_1.Content, null, _this.props.content))); }; return _this; } WrapperAccordion.prototype.componentDidMount = function () { var initialHeight = this.accordionRef.current.childNodes[0].clientHeight || 0; this.setState({ initialHeight: initialHeight }); }; return WrapperAccordion; }(React.Component)); exports.default = WrapperAccordion; //# sourceMappingURL=AccordionWrapper.js.map