UNPKG

@pnp/spfx-controls-react

Version:

Reusable React controls for SharePoint Framework solutions

80 lines 3.5 kB
"use strict"; // tslint:disable:max-classes-per-file Object.defineProperty(exports, "__esModule", { value: true }); exports.Consumer = exports.Provider = void 0; var tslib_1 = require("tslib"); var React = tslib_1.__importStar(require("react")); var telemetry = tslib_1.__importStar(require("../../../common/telemetry")); var AccordionStore_1 = tslib_1.__importDefault(require("../helpers/AccordionStore")); var Context = React.createContext(null); var Provider = /** @class */ (function (_super) { tslib_1.__extends(Provider, _super); function Provider(props) { var _this = _super.call(this, props) || this; _this.state = new AccordionStore_1.default({ expanded: _this.props.preExpanded, allowMultipleExpanded: _this.props.allowMultipleExpanded, allowZeroExpanded: _this.props.allowZeroExpanded, }); _this.toggleExpanded = function (key) { _this.setState(function (state) { return state.toggleExpanded(key); }, function () { if (_this.props.onChange) { _this.props.onChange(_this.state.expanded); } }); }; _this.isItemDisabled = function (key) { return _this.state.isItemDisabled(key); }; _this.isItemExpanded = function (key) { return _this.state.isItemExpanded(key); }; _this.getPanelAttributes = function (key, dangerouslySetExpanded) { return _this.state.getPanelAttributes(key, dangerouslySetExpanded); }; _this.getHeadingAttributes = function () { // uuid: UUID return _this.state.getHeadingAttributes(); }; _this.getButtonAttributes = function (key, dangerouslySetExpanded) { return _this.state.getButtonAttributes(key, dangerouslySetExpanded); }; telemetry.track('ReactAccessibleAccordion', {}); return _this; } Provider.prototype.render = function () { var _a = this.state, allowZeroExpanded = _a.allowZeroExpanded, allowMultipleExpanded = _a.allowMultipleExpanded; return (React.createElement(Context.Provider, { value: { allowMultipleExpanded: allowMultipleExpanded, allowZeroExpanded: allowZeroExpanded, toggleExpanded: this.toggleExpanded, isItemDisabled: this.isItemDisabled, isItemExpanded: this.isItemExpanded, getPanelAttributes: this.getPanelAttributes, getHeadingAttributes: this.getHeadingAttributes, getButtonAttributes: this.getButtonAttributes, } }, this.props.children || null)); }; Provider.defaultProps = { allowMultipleExpanded: false, allowZeroExpanded: false, }; return Provider; }(React.PureComponent)); exports.Provider = Provider; var Consumer = /** @class */ (function (_super) { tslib_1.__extends(Consumer, _super); function Consumer() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.renderChildren = function (container) { return container ? _this.props.children(container) : null; }; return _this; } Consumer.prototype.render = function () { return React.createElement(Context.Consumer, null, this.renderChildren); }; return Consumer; }(React.PureComponent)); exports.Consumer = Consumer; //# sourceMappingURL=AccordionContext.js.map