@pnp/spfx-controls-react
Version:
Reusable React controls for SharePoint Framework solutions
55 lines • 2.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AccordionItemHeading = exports.SPEC_ERROR = void 0;
var tslib_1 = require("tslib");
var React = tslib_1.__importStar(require("react"));
var DisplayName_1 = tslib_1.__importDefault(require("../helpers/DisplayName"));
var uuid_1 = require("../helpers/uuid");
var ItemContext_1 = require("./ItemContext");
var defaultProps = {
className: 'accordion__heading',
'aria-level': 3,
};
exports.SPEC_ERROR = "AccordionItemButton may contain only one child element, which must be an instance of AccordionItemButton.\n\nFrom the WAI-ARIA spec (https://www.w3.org/TR/wai-aria-practices-1.1/#accordion):\n\n\u201CThe button element is the only element inside the heading element. That is, if there are other visually persistent elements, they are not included inside the heading element.\u201D\n\n";
var AccordionItemHeading = /** @class */ (function (_super) {
tslib_1.__extends(AccordionItemHeading, _super);
function AccordionItemHeading() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.setRef = function (ref) {
_this.ref = ref;
};
return _this;
}
AccordionItemHeading.VALIDATE = function (ref) {
if (ref === undefined) {
throw new Error('ref is undefined');
}
if (!(ref.childElementCount === 1 &&
ref.firstElementChild &&
ref.firstElementChild.getAttribute('data-accordion-component') === 'AccordionItemButton')) {
throw new Error(exports.SPEC_ERROR);
}
};
AccordionItemHeading.prototype.componentDidUpdate = function () {
AccordionItemHeading.VALIDATE(this.ref);
};
AccordionItemHeading.prototype.componentDidMount = function () {
AccordionItemHeading.VALIDATE(this.ref);
};
AccordionItemHeading.prototype.render = function () {
return (React.createElement("div", tslib_1.__assign({ "data-accordion-component": "AccordionItemHeading" }, this.props, { ref: this.setRef })));
};
AccordionItemHeading.defaultProps = defaultProps;
return AccordionItemHeading;
}(React.PureComponent));
exports.AccordionItemHeading = AccordionItemHeading;
var AccordionItemHeadingWrapper = function (props) { return (React.createElement(ItemContext_1.Consumer, null, function (itemContext) {
var headingAttributes = itemContext.headingAttributes;
if (props.id) {
(0, uuid_1.assertValidHtmlId)(props.id);
}
return React.createElement(AccordionItemHeading, tslib_1.__assign({}, props, headingAttributes));
})); };
AccordionItemHeadingWrapper.displayName = DisplayName_1.default.AccordionItemHeading;
exports.default = AccordionItemHeadingWrapper;
//# sourceMappingURL=AccordionItemHeading.js.map