UNPKG

@uifabric/experiments

Version:

Experimental React components for building experiences for Microsoft 365.

52 lines 2.73 kB
"use strict"; /*! * Copyright (C) Microsoft Corporation. All rights reserved. */ Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var Button_1 = require("office-ui-fabric-react/lib-commonjs/Button"); var Utilities_1 = require("office-ui-fabric-react/lib-commonjs/Utilities"); var React = require("react"); require("./Accordion.scss"); var Accordion = /** @class */ (function (_super) { tslib_1.__extends(Accordion, _super); function Accordion(props) { var _this = _super.call(this, props) || this; _this.toggleState = function () { _this.setState(function (prevState) { return { isContentVisible: !prevState.isContentVisible }; }); }; Utilities_1.initializeComponentRef(_this); _this.state = { isContentVisible: false, }; return _this; } Accordion.prototype.componentDidUpdate = function (prevProps, prevState) { if (this.state.isContentVisible && !prevState.isContentVisible && this.props.onOpen) { this.props.onOpen(); } else if (!this.state.isContentVisible && prevState.isContentVisible && this.props.onClose) { this.props.onClose(); } }; Accordion.prototype.render = function () { // eslint-disable-next-line deprecation/deprecation var _a = this.props, onRenderMenu = _a.onRenderMenu, className = _a.className, buttonAs = _a.buttonAs, onClick = _a.onClick, other = tslib_1.__rest(_a, ["onRenderMenu", "className", "buttonAs", "onClick"]); var menuIconProps = this.props.menuIconProps; var AccordionButton = buttonAs || Button_1.DefaultButton; if (!menuIconProps) { menuIconProps = this.state.isContentVisible ? { iconName: 'ChevronUp' } : { iconName: 'ChevronDown' }; } var onRenderContent = onRenderMenu ? Utilities_1.composeRenderFunction(this.props.onRenderContent, onRenderMenu) : this.props.onRenderContent; return (React.createElement("div", { className: Utilities_1.css('ba-Accordion', this.state.isContentVisible && 'ba-Accordion--contentVisible', className) }, React.createElement(AccordionButton, tslib_1.__assign({ onClick: this.toggleState, onMenuClick: this.toggleState, menuIconProps: menuIconProps, className: 'ba-Accordion-header', "aria-expanded": this.state.isContentVisible }, other)), this.state.isContentVisible && (React.createElement("div", { className: 'ba-Accordion-content' }, onRenderContent(this.props.menuProps))))); }; return Accordion; }(React.Component)); exports.Accordion = Accordion; //# sourceMappingURL=Accordion.js.map