react-accessible-accordion
Advanced tools
Comparing version 3.3.1 to 3.3.2
@@ -6,2 +6,15 @@ # Changelog | ||
## [[v3.3.2]](https://github.com/springload/react-accessible-accordion/releases/tag/v3.4.0) | ||
### Changed | ||
- Bug fix release. See | ||
https://github.com/springload/react-accessible-accordion/issues/284 | ||
## [[v3.3.1]](https://github.com/springload/react-accessible-accordion/releases/tag/v3.4.0) | ||
### Changed | ||
- ESLint and related fixes. | ||
## [[v3.3.0]](https://github.com/springload/react-accessible-accordion/releases/tag/v3.3.0) | ||
@@ -8,0 +21,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { createContext, createElement, PureComponent, Component, Fragment } from 'react'; | ||
import { createElement, PureComponent, createContext, Component, Fragment } from 'react'; | ||
@@ -58,16 +58,31 @@ function _classCallCheck(instance, Constructor) { | ||
function _objectSpread(target) { | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
var ownKeys = Object.keys(source); | ||
if (typeof Object.getOwnPropertySymbols === 'function') { | ||
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(source, sym).enumerable; | ||
})); | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
ownKeys.forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} | ||
@@ -109,2 +124,15 @@ | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
@@ -162,20 +190,52 @@ if (source == null) return {}; | ||
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 _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
if (Array.isArray(arr)) return _arrayLikeToArray(arr); | ||
} | ||
function _iterableToArray(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
@@ -243,3 +303,3 @@ | ||
_defineProperty(this, "getHeadingAttributes", function (uuid) { | ||
_defineProperty(this, "getHeadingAttributes", function () { | ||
return { | ||
@@ -274,3 +334,3 @@ role: 'heading' | ||
_defineProperty(this, "augment", function (args) { | ||
return new AccordionStore(_objectSpread({ | ||
return new AccordionStore(_objectSpread2({ | ||
expanded: _this.expanded, | ||
@@ -287,11 +347,9 @@ allowMultipleExpanded: _this.allowMultipleExpanded, | ||
var Context = createContext(null); | ||
var Provider = | ||
/*#__PURE__*/ | ||
function (_React$PureComponent) { | ||
var Context = /*#__PURE__*/createContext(null); | ||
var Provider = /*#__PURE__*/function (_React$PureComponent) { | ||
_inherits(Provider, _React$PureComponent); | ||
var _super = _createSuper(Provider); | ||
function Provider() { | ||
var _getPrototypeOf2; | ||
var _this; | ||
@@ -305,3 +363,3 @@ | ||
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Provider)).call.apply(_getPrototypeOf2, [this].concat(args))); | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
@@ -336,4 +394,5 @@ _defineProperty(_assertThisInitialized(_this), "state", new AccordionStore({ | ||
_defineProperty(_assertThisInitialized(_this), "getHeadingAttributes", function (key) { | ||
return _this.state.getHeadingAttributes(key); | ||
_defineProperty(_assertThisInitialized(_this), "getHeadingAttributes", function () { | ||
// uuid: UUID | ||
return _this.state.getHeadingAttributes(); | ||
}); | ||
@@ -354,3 +413,3 @@ | ||
allowMultipleExpanded = _this$state.allowMultipleExpanded; | ||
return createElement(Context.Provider, { | ||
return /*#__PURE__*/createElement(Context.Provider, { | ||
value: { | ||
@@ -378,10 +437,8 @@ allowMultipleExpanded: allowMultipleExpanded, | ||
var Consumer = | ||
/*#__PURE__*/ | ||
function (_React$PureComponent2) { | ||
var Consumer = /*#__PURE__*/function (_React$PureComponent2) { | ||
_inherits(Consumer, _React$PureComponent2); | ||
var _super2 = _createSuper(Consumer); | ||
function Consumer() { | ||
var _getPrototypeOf3; | ||
var _this2; | ||
@@ -395,3 +452,3 @@ | ||
_this2 = _possibleConstructorReturn(this, (_getPrototypeOf3 = _getPrototypeOf(Consumer)).call.apply(_getPrototypeOf3, [this].concat(args))); | ||
_this2 = _super2.call.apply(_super2, [this].concat(args)); | ||
@@ -408,3 +465,3 @@ _defineProperty(_assertThisInitialized(_this2), "renderChildren", function (container) { | ||
value: function render() { | ||
return createElement(Context.Consumer, null, this.renderChildren); | ||
return /*#__PURE__*/createElement(Context.Consumer, null, this.renderChildren); | ||
} | ||
@@ -425,3 +482,3 @@ }]); | ||
return createElement(Provider, { | ||
return /*#__PURE__*/createElement(Provider, { | ||
preExpanded: preExpanded, | ||
@@ -431,3 +488,3 @@ allowMultipleExpanded: allowMultipleExpanded, | ||
onChange: onChange | ||
}, createElement("div", _extends({ | ||
}, /*#__PURE__*/createElement("div", _extends({ | ||
"data-accordion-component": "Accordion", | ||
@@ -438,2 +495,14 @@ className: className | ||
var DisplayName; | ||
(function (DisplayName) { | ||
DisplayName["Accordion"] = "Accordion"; | ||
DisplayName["AccordionItem"] = "AccordionItem"; | ||
DisplayName["AccordionItemButton"] = "AccordionItemButton"; | ||
DisplayName["AccordionItemHeading"] = "AccordionItemHeading"; | ||
DisplayName["AccordionItemPanel"] = "AccordionItemPanel"; | ||
})(DisplayName || (DisplayName = {})); | ||
var DisplayName$1 = DisplayName; | ||
var DEFAULT = 0; | ||
@@ -450,2 +519,3 @@ var counter = DEFAULT; | ||
// https://infra.spec.whatwg.org/#ascii-whitespace | ||
// eslint-disable-next-line no-control-regex | ||
@@ -455,3 +525,2 @@ var idRegex = /[\u0009\u000a\u000c\u000d\u0020]/g; | ||
if (htmlId === '' || idRegex.test(htmlId)) { | ||
// tslint:disable-next-line | ||
console.error("uuid must be a valid HTML5 id but was given \"".concat(htmlId, "\", ASCII whitespaces are forbidden")); | ||
@@ -464,12 +533,10 @@ return false; | ||
var Context$1 = createContext(null); | ||
var Context$1 = /*#__PURE__*/createContext(null); | ||
var Provider$1 = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
var Provider$1 = /*#__PURE__*/function (_React$Component) { | ||
_inherits(Provider, _React$Component); | ||
var _super = _createSuper(Provider); | ||
function Provider() { | ||
var _getPrototypeOf2; | ||
var _this; | ||
@@ -483,3 +550,3 @@ | ||
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Provider)).call.apply(_getPrototypeOf2, [this].concat(args))); | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
@@ -499,3 +566,3 @@ _defineProperty(_assertThisInitialized(_this), "toggleExpanded", function () { | ||
var buttonAttributes = accordionContext.getButtonAttributes(uuid, dangerouslySetExpanded); | ||
return createElement(Context$1.Provider, { | ||
return /*#__PURE__*/createElement(Context$1.Provider, { | ||
value: { | ||
@@ -509,5 +576,4 @@ uuid: uuid, | ||
buttonAttributes: buttonAttributes | ||
}, | ||
children: _this.props.children | ||
}); | ||
} | ||
}, _this.props.children); | ||
}); | ||
@@ -521,3 +587,3 @@ | ||
value: function render() { | ||
return createElement(Consumer, null, this.renderChildren); | ||
return /*#__PURE__*/createElement(Consumer, null, this.renderChildren); | ||
} | ||
@@ -530,4 +596,4 @@ }]); | ||
var ProviderWrapper = function ProviderWrapper(props) { | ||
return createElement(Consumer, null, function (accordionContext) { | ||
return createElement(Provider$1, _extends({}, props, { | ||
return /*#__PURE__*/createElement(Consumer, null, function (accordionContext) { | ||
return /*#__PURE__*/createElement(Provider$1, _extends({}, props, { | ||
accordionContext: accordionContext | ||
@@ -537,10 +603,8 @@ })); | ||
}; | ||
var Consumer$1 = | ||
/*#__PURE__*/ | ||
function (_React$PureComponent) { | ||
var Consumer$1 = /*#__PURE__*/function (_React$PureComponent) { | ||
_inherits(Consumer, _React$PureComponent); | ||
var _super2 = _createSuper(Consumer); | ||
function Consumer() { | ||
var _getPrototypeOf3; | ||
var _this2; | ||
@@ -554,3 +618,3 @@ | ||
_this2 = _possibleConstructorReturn(this, (_getPrototypeOf3 = _getPrototypeOf(Consumer)).call.apply(_getPrototypeOf3, [this].concat(args))); | ||
_this2 = _super2.call.apply(_super2, [this].concat(args)); | ||
@@ -567,3 +631,3 @@ _defineProperty(_assertThisInitialized(_this2), "renderChildren", function (container) { | ||
value: function render() { | ||
return createElement(Context$1.Consumer, null, this.renderChildren); | ||
return /*#__PURE__*/createElement(Context$1.Consumer, null, this.renderChildren); | ||
} | ||
@@ -575,30 +639,72 @@ }]); | ||
var AccordionItem = function AccordionItem(_ref) { | ||
var _ref$uuid = _ref.uuid, | ||
uuid = _ref$uuid === void 0 ? nextUuid() : _ref$uuid, | ||
_ref$className = _ref.className, | ||
className = _ref$className === void 0 ? 'accordion__item' : _ref$className, | ||
activeClassName = _ref.activeClassName, | ||
dangerouslySetExpanded = _ref.dangerouslySetExpanded, | ||
rest = _objectWithoutProperties(_ref, ["uuid", "className", "activeClassName", "dangerouslySetExpanded"]); | ||
var defaultProps = { | ||
className: 'accordion__item' | ||
}; | ||
var renderChildren = function renderChildren(itemContext) { | ||
var expanded = itemContext.expanded; | ||
var cx = expanded && activeClassName ? activeClassName : className; | ||
return createElement("div", _extends({ | ||
"data-accordion-component": "AccordionItem", | ||
className: cx | ||
}, rest)); | ||
}; | ||
var AccordionItem = /*#__PURE__*/function (_React$Component) { | ||
_inherits(AccordionItem, _React$Component); | ||
if (rest.id) { | ||
assertValidHtmlId(rest.id); | ||
var _super = _createSuper(AccordionItem); | ||
function AccordionItem() { | ||
var _this; | ||
_classCallCheck(this, AccordionItem); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
_defineProperty(_assertThisInitialized(_this), "instanceUuid", nextUuid()); | ||
_defineProperty(_assertThisInitialized(_this), "renderChildren", function (itemContext) { | ||
var _this$props = _this.props, | ||
uuid = _this$props.uuid, | ||
className = _this$props.className, | ||
activeClassName = _this$props.activeClassName, | ||
dangerouslySetExpanded = _this$props.dangerouslySetExpanded, | ||
rest = _objectWithoutProperties(_this$props, ["uuid", "className", "activeClassName", "dangerouslySetExpanded"]); | ||
var expanded = itemContext.expanded; | ||
var cx = expanded && activeClassName ? activeClassName : className; | ||
return /*#__PURE__*/createElement("div", _extends({ | ||
"data-accordion-component": "AccordionItem", | ||
className: cx | ||
}, rest)); | ||
}); | ||
return _this; | ||
} | ||
return createElement(ProviderWrapper, { | ||
uuid: uuid, | ||
dangerouslySetExpanded: dangerouslySetExpanded | ||
}, createElement(Consumer$1, null, renderChildren)); | ||
}; | ||
_createClass(AccordionItem, [{ | ||
key: "render", | ||
value: function render() { | ||
var _this$props2 = this.props, | ||
_this$props2$uuid = _this$props2.uuid, | ||
uuid = _this$props2$uuid === void 0 ? this.instanceUuid : _this$props2$uuid, | ||
dangerouslySetExpanded = _this$props2.dangerouslySetExpanded, | ||
rest = _objectWithoutProperties(_this$props2, ["uuid", "dangerouslySetExpanded"]); | ||
assertValidHtmlId(uuid); | ||
if (rest.id) { | ||
assertValidHtmlId(rest.id); | ||
} | ||
return /*#__PURE__*/createElement(ProviderWrapper, { | ||
uuid: uuid, | ||
dangerouslySetExpanded: dangerouslySetExpanded | ||
}, /*#__PURE__*/createElement(Consumer$1, null, this.renderChildren)); | ||
} | ||
}]); | ||
return AccordionItem; | ||
}(Component); | ||
_defineProperty(AccordionItem, "defaultProps", defaultProps); | ||
_defineProperty(AccordionItem, "displayName", DisplayName$1.AccordionItem); | ||
function getClosestAccordion(el) { | ||
@@ -714,5 +820,2 @@ return el && (el.matches('[data-accordion-component="Accordion"]') ? el : getClosestAccordion(el.parentElement)); | ||
} | ||
default: | ||
} | ||
@@ -726,6 +829,7 @@ } | ||
return createElement("div", _extends({ | ||
return /*#__PURE__*/createElement("div", _extends({ | ||
className: className | ||
}, rest, { | ||
// tslint:disable-next-line react-a11y-event-has-role | ||
role: "button", | ||
tabIndex: 0, | ||
onClick: toggleExpanded, | ||
@@ -738,6 +842,6 @@ onKeyDown: handleKeyPress, | ||
var AccordionItemButtonWrapper = function AccordionItemButtonWrapper(props) { | ||
return createElement(Consumer$1, null, function (itemContext) { | ||
return /*#__PURE__*/createElement(Consumer$1, null, function (itemContext) { | ||
var toggleExpanded = itemContext.toggleExpanded, | ||
buttonAttributes = itemContext.buttonAttributes; | ||
return createElement(AccordionItemButton, _extends({ | ||
return /*#__PURE__*/createElement(AccordionItemButton, _extends({ | ||
toggleExpanded: toggleExpanded | ||
@@ -748,15 +852,3 @@ }, props, buttonAttributes)); | ||
var DisplayName; | ||
(function (DisplayName) { | ||
DisplayName["Accordion"] = "Accordion"; | ||
DisplayName["AccordionItem"] = "AccordionItem"; | ||
DisplayName["AccordionItemButton"] = "AccordionItemButton"; | ||
DisplayName["AccordionItemHeading"] = "AccordionItemHeading"; | ||
DisplayName["AccordionItemPanel"] = "AccordionItemPanel"; | ||
})(DisplayName || (DisplayName = {})); | ||
var DisplayName$1 = DisplayName; | ||
var defaultProps = { | ||
var defaultProps$1 = { | ||
className: 'accordion__heading', | ||
@@ -766,10 +858,8 @@ 'aria-level': 3 | ||
var 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 = | ||
/*#__PURE__*/ | ||
function (_React$PureComponent) { | ||
var AccordionItemHeading = /*#__PURE__*/function (_React$PureComponent) { | ||
_inherits(AccordionItemHeading, _React$PureComponent); | ||
var _super = _createSuper(AccordionItemHeading); | ||
function AccordionItemHeading() { | ||
var _getPrototypeOf2; | ||
var _this; | ||
@@ -783,3 +873,3 @@ | ||
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(AccordionItemHeading)).call.apply(_getPrototypeOf2, [this].concat(args))); | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
@@ -808,3 +898,3 @@ _defineProperty(_assertThisInitialized(_this), "ref", void 0); | ||
value: function render() { | ||
return createElement("div", _extends({ | ||
return /*#__PURE__*/createElement("div", _extends({ | ||
"data-accordion-component": "AccordionItemHeading" | ||
@@ -831,6 +921,6 @@ }, this.props, { | ||
_defineProperty(AccordionItemHeading, "defaultProps", defaultProps); | ||
_defineProperty(AccordionItemHeading, "defaultProps", defaultProps$1); | ||
var AccordionItemHeadingWrapper = function AccordionItemHeadingWrapper(props) { | ||
return createElement(Consumer$1, null, function (itemContext) { | ||
return /*#__PURE__*/createElement(Consumer$1, null, function (itemContext) { | ||
var headingAttributes = itemContext.headingAttributes; | ||
@@ -842,3 +932,3 @@ | ||
return createElement(AccordionItemHeading, _extends({}, props, headingAttributes)); | ||
return /*#__PURE__*/createElement(AccordionItemHeading, _extends({}, props, headingAttributes)); | ||
}); | ||
@@ -862,3 +952,3 @@ }; | ||
return createElement("div", _extends({ | ||
return /*#__PURE__*/createElement("div", _extends({ | ||
"data-accordion-component": "AccordionItemPanel", | ||
@@ -869,3 +959,3 @@ className: className | ||
return createElement(Consumer$1, null, renderChildren); | ||
return /*#__PURE__*/createElement(Consumer$1, null, renderChildren); | ||
}; | ||
@@ -879,3 +969,3 @@ | ||
disabled = itemContext.disabled; | ||
return createElement(Fragment, null, children({ | ||
return /*#__PURE__*/createElement(Fragment, null, children({ | ||
expanded: expanded, | ||
@@ -886,5 +976,5 @@ disabled: disabled | ||
return createElement(Consumer$1, null, renderChildren); | ||
return /*#__PURE__*/createElement(Consumer$1, null, renderChildren); | ||
}; | ||
export { Accordion, AccordionItem, AccordionItemButtonWrapper as AccordionItemButton, AccordionItemHeadingWrapper as AccordionItemHeading, AccordionItemPanel, AccordionItemState, resetNextUuid }; |
@@ -29,3 +29,3 @@ import * as React from 'react'; | ||
getPanelAttributes: (key: UUID, dangerouslySetExpanded?: boolean | undefined) => InjectedPanelAttributes; | ||
getHeadingAttributes: (key: UUID) => InjectedHeadingAttributes; | ||
getHeadingAttributes: () => InjectedHeadingAttributes; | ||
getButtonAttributes: (key: UUID, dangerouslySetExpanded?: boolean | undefined) => InjectedButtonAttributes; | ||
@@ -32,0 +32,0 @@ render(): JSX.Element; |
@@ -1,6 +0,6 @@ | ||
/// <reference types="react" /> | ||
import * as React from 'react'; | ||
import DisplayName from '../helpers/DisplayName'; | ||
import { DivAttributes } from '../helpers/types'; | ||
import { UUID } from './ItemContext'; | ||
import { ItemContext, UUID } from './ItemContext'; | ||
declare type Props = DivAttributes & { | ||
className?: string; | ||
uuid?: UUID; | ||
@@ -10,3 +10,12 @@ activeClassName?: string; | ||
}; | ||
declare const AccordionItem: ({ uuid, className, activeClassName, dangerouslySetExpanded, ...rest }: Props) => JSX.Element; | ||
export default AccordionItem; | ||
declare const defaultProps: { | ||
className: string; | ||
}; | ||
export default class AccordionItem extends React.Component<Props> { | ||
static defaultProps: typeof defaultProps; | ||
static displayName: DisplayName.AccordionItem; | ||
instanceUuid: UUID; | ||
renderChildren: (itemContext: ItemContext) => JSX.Element; | ||
render(): JSX.Element; | ||
} | ||
export {}; |
@@ -33,3 +33,3 @@ import { UUID } from '../components/ItemContext'; | ||
readonly getPanelAttributes: (uuid: UUID, dangerouslySetExpanded?: boolean | undefined) => InjectedPanelAttributes; | ||
readonly getHeadingAttributes: (uuid: UUID) => InjectedHeadingAttributes; | ||
readonly getHeadingAttributes: () => InjectedHeadingAttributes; | ||
readonly getButtonAttributes: (uuid: UUID, dangerouslySetExpanded?: boolean | undefined) => InjectedButtonAttributes; | ||
@@ -36,0 +36,0 @@ private readonly getPanelId; |
@@ -5,3 +5,3 @@ (function (global, factory) { | ||
(global = global || self, factory(global.reactAccessibleAccordion = {}, global.React)); | ||
}(this, function (exports, React) { 'use strict'; | ||
}(this, (function (exports, React) { 'use strict'; | ||
@@ -63,16 +63,31 @@ function _classCallCheck(instance, Constructor) { | ||
function _objectSpread(target) { | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
var ownKeys = Object.keys(source); | ||
if (typeof Object.getOwnPropertySymbols === 'function') { | ||
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(source, sym).enumerable; | ||
})); | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
ownKeys.forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} | ||
@@ -114,2 +129,15 @@ | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
@@ -167,20 +195,52 @@ if (source == null) return {}; | ||
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 _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
if (Array.isArray(arr)) return _arrayLikeToArray(arr); | ||
} | ||
function _iterableToArray(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
@@ -248,3 +308,3 @@ | ||
_defineProperty(this, "getHeadingAttributes", function (uuid) { | ||
_defineProperty(this, "getHeadingAttributes", function () { | ||
return { | ||
@@ -279,3 +339,3 @@ role: 'heading' | ||
_defineProperty(this, "augment", function (args) { | ||
return new AccordionStore(_objectSpread({ | ||
return new AccordionStore(_objectSpread2({ | ||
expanded: _this.expanded, | ||
@@ -292,11 +352,9 @@ allowMultipleExpanded: _this.allowMultipleExpanded, | ||
var Context = React.createContext(null); | ||
var Provider = | ||
/*#__PURE__*/ | ||
function (_React$PureComponent) { | ||
var Context = /*#__PURE__*/React.createContext(null); | ||
var Provider = /*#__PURE__*/function (_React$PureComponent) { | ||
_inherits(Provider, _React$PureComponent); | ||
var _super = _createSuper(Provider); | ||
function Provider() { | ||
var _getPrototypeOf2; | ||
var _this; | ||
@@ -310,3 +368,3 @@ | ||
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Provider)).call.apply(_getPrototypeOf2, [this].concat(args))); | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
@@ -341,4 +399,5 @@ _defineProperty(_assertThisInitialized(_this), "state", new AccordionStore({ | ||
_defineProperty(_assertThisInitialized(_this), "getHeadingAttributes", function (key) { | ||
return _this.state.getHeadingAttributes(key); | ||
_defineProperty(_assertThisInitialized(_this), "getHeadingAttributes", function () { | ||
// uuid: UUID | ||
return _this.state.getHeadingAttributes(); | ||
}); | ||
@@ -359,3 +418,3 @@ | ||
allowMultipleExpanded = _this$state.allowMultipleExpanded; | ||
return React.createElement(Context.Provider, { | ||
return /*#__PURE__*/React.createElement(Context.Provider, { | ||
value: { | ||
@@ -383,10 +442,8 @@ allowMultipleExpanded: allowMultipleExpanded, | ||
var Consumer = | ||
/*#__PURE__*/ | ||
function (_React$PureComponent2) { | ||
var Consumer = /*#__PURE__*/function (_React$PureComponent2) { | ||
_inherits(Consumer, _React$PureComponent2); | ||
var _super2 = _createSuper(Consumer); | ||
function Consumer() { | ||
var _getPrototypeOf3; | ||
var _this2; | ||
@@ -400,3 +457,3 @@ | ||
_this2 = _possibleConstructorReturn(this, (_getPrototypeOf3 = _getPrototypeOf(Consumer)).call.apply(_getPrototypeOf3, [this].concat(args))); | ||
_this2 = _super2.call.apply(_super2, [this].concat(args)); | ||
@@ -413,3 +470,3 @@ _defineProperty(_assertThisInitialized(_this2), "renderChildren", function (container) { | ||
value: function render() { | ||
return React.createElement(Context.Consumer, null, this.renderChildren); | ||
return /*#__PURE__*/React.createElement(Context.Consumer, null, this.renderChildren); | ||
} | ||
@@ -430,3 +487,3 @@ }]); | ||
return React.createElement(Provider, { | ||
return /*#__PURE__*/React.createElement(Provider, { | ||
preExpanded: preExpanded, | ||
@@ -436,3 +493,3 @@ allowMultipleExpanded: allowMultipleExpanded, | ||
onChange: onChange | ||
}, React.createElement("div", _extends({ | ||
}, /*#__PURE__*/React.createElement("div", _extends({ | ||
"data-accordion-component": "Accordion", | ||
@@ -443,2 +500,14 @@ className: className | ||
var DisplayName; | ||
(function (DisplayName) { | ||
DisplayName["Accordion"] = "Accordion"; | ||
DisplayName["AccordionItem"] = "AccordionItem"; | ||
DisplayName["AccordionItemButton"] = "AccordionItemButton"; | ||
DisplayName["AccordionItemHeading"] = "AccordionItemHeading"; | ||
DisplayName["AccordionItemPanel"] = "AccordionItemPanel"; | ||
})(DisplayName || (DisplayName = {})); | ||
var DisplayName$1 = DisplayName; | ||
var DEFAULT = 0; | ||
@@ -455,2 +524,3 @@ var counter = DEFAULT; | ||
// https://infra.spec.whatwg.org/#ascii-whitespace | ||
// eslint-disable-next-line no-control-regex | ||
@@ -460,3 +530,2 @@ var idRegex = /[\u0009\u000a\u000c\u000d\u0020]/g; | ||
if (htmlId === '' || idRegex.test(htmlId)) { | ||
// tslint:disable-next-line | ||
console.error("uuid must be a valid HTML5 id but was given \"".concat(htmlId, "\", ASCII whitespaces are forbidden")); | ||
@@ -469,12 +538,10 @@ return false; | ||
var Context$1 = React.createContext(null); | ||
var Context$1 = /*#__PURE__*/React.createContext(null); | ||
var Provider$1 = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
var Provider$1 = /*#__PURE__*/function (_React$Component) { | ||
_inherits(Provider, _React$Component); | ||
var _super = _createSuper(Provider); | ||
function Provider() { | ||
var _getPrototypeOf2; | ||
var _this; | ||
@@ -488,3 +555,3 @@ | ||
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Provider)).call.apply(_getPrototypeOf2, [this].concat(args))); | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
@@ -504,3 +571,3 @@ _defineProperty(_assertThisInitialized(_this), "toggleExpanded", function () { | ||
var buttonAttributes = accordionContext.getButtonAttributes(uuid, dangerouslySetExpanded); | ||
return React.createElement(Context$1.Provider, { | ||
return /*#__PURE__*/React.createElement(Context$1.Provider, { | ||
value: { | ||
@@ -514,5 +581,4 @@ uuid: uuid, | ||
buttonAttributes: buttonAttributes | ||
}, | ||
children: _this.props.children | ||
}); | ||
} | ||
}, _this.props.children); | ||
}); | ||
@@ -526,3 +592,3 @@ | ||
value: function render() { | ||
return React.createElement(Consumer, null, this.renderChildren); | ||
return /*#__PURE__*/React.createElement(Consumer, null, this.renderChildren); | ||
} | ||
@@ -535,4 +601,4 @@ }]); | ||
var ProviderWrapper = function ProviderWrapper(props) { | ||
return React.createElement(Consumer, null, function (accordionContext) { | ||
return React.createElement(Provider$1, _extends({}, props, { | ||
return /*#__PURE__*/React.createElement(Consumer, null, function (accordionContext) { | ||
return /*#__PURE__*/React.createElement(Provider$1, _extends({}, props, { | ||
accordionContext: accordionContext | ||
@@ -542,10 +608,8 @@ })); | ||
}; | ||
var Consumer$1 = | ||
/*#__PURE__*/ | ||
function (_React$PureComponent) { | ||
var Consumer$1 = /*#__PURE__*/function (_React$PureComponent) { | ||
_inherits(Consumer, _React$PureComponent); | ||
var _super2 = _createSuper(Consumer); | ||
function Consumer() { | ||
var _getPrototypeOf3; | ||
var _this2; | ||
@@ -559,3 +623,3 @@ | ||
_this2 = _possibleConstructorReturn(this, (_getPrototypeOf3 = _getPrototypeOf(Consumer)).call.apply(_getPrototypeOf3, [this].concat(args))); | ||
_this2 = _super2.call.apply(_super2, [this].concat(args)); | ||
@@ -572,3 +636,3 @@ _defineProperty(_assertThisInitialized(_this2), "renderChildren", function (container) { | ||
value: function render() { | ||
return React.createElement(Context$1.Consumer, null, this.renderChildren); | ||
return /*#__PURE__*/React.createElement(Context$1.Consumer, null, this.renderChildren); | ||
} | ||
@@ -580,30 +644,72 @@ }]); | ||
var AccordionItem = function AccordionItem(_ref) { | ||
var _ref$uuid = _ref.uuid, | ||
uuid = _ref$uuid === void 0 ? nextUuid() : _ref$uuid, | ||
_ref$className = _ref.className, | ||
className = _ref$className === void 0 ? 'accordion__item' : _ref$className, | ||
activeClassName = _ref.activeClassName, | ||
dangerouslySetExpanded = _ref.dangerouslySetExpanded, | ||
rest = _objectWithoutProperties(_ref, ["uuid", "className", "activeClassName", "dangerouslySetExpanded"]); | ||
var defaultProps = { | ||
className: 'accordion__item' | ||
}; | ||
var renderChildren = function renderChildren(itemContext) { | ||
var expanded = itemContext.expanded; | ||
var cx = expanded && activeClassName ? activeClassName : className; | ||
return React.createElement("div", _extends({ | ||
"data-accordion-component": "AccordionItem", | ||
className: cx | ||
}, rest)); | ||
}; | ||
var AccordionItem = /*#__PURE__*/function (_React$Component) { | ||
_inherits(AccordionItem, _React$Component); | ||
if (rest.id) { | ||
assertValidHtmlId(rest.id); | ||
var _super = _createSuper(AccordionItem); | ||
function AccordionItem() { | ||
var _this; | ||
_classCallCheck(this, AccordionItem); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
_defineProperty(_assertThisInitialized(_this), "instanceUuid", nextUuid()); | ||
_defineProperty(_assertThisInitialized(_this), "renderChildren", function (itemContext) { | ||
var _this$props = _this.props, | ||
uuid = _this$props.uuid, | ||
className = _this$props.className, | ||
activeClassName = _this$props.activeClassName, | ||
dangerouslySetExpanded = _this$props.dangerouslySetExpanded, | ||
rest = _objectWithoutProperties(_this$props, ["uuid", "className", "activeClassName", "dangerouslySetExpanded"]); | ||
var expanded = itemContext.expanded; | ||
var cx = expanded && activeClassName ? activeClassName : className; | ||
return /*#__PURE__*/React.createElement("div", _extends({ | ||
"data-accordion-component": "AccordionItem", | ||
className: cx | ||
}, rest)); | ||
}); | ||
return _this; | ||
} | ||
return React.createElement(ProviderWrapper, { | ||
uuid: uuid, | ||
dangerouslySetExpanded: dangerouslySetExpanded | ||
}, React.createElement(Consumer$1, null, renderChildren)); | ||
}; | ||
_createClass(AccordionItem, [{ | ||
key: "render", | ||
value: function render() { | ||
var _this$props2 = this.props, | ||
_this$props2$uuid = _this$props2.uuid, | ||
uuid = _this$props2$uuid === void 0 ? this.instanceUuid : _this$props2$uuid, | ||
dangerouslySetExpanded = _this$props2.dangerouslySetExpanded, | ||
rest = _objectWithoutProperties(_this$props2, ["uuid", "dangerouslySetExpanded"]); | ||
assertValidHtmlId(uuid); | ||
if (rest.id) { | ||
assertValidHtmlId(rest.id); | ||
} | ||
return /*#__PURE__*/React.createElement(ProviderWrapper, { | ||
uuid: uuid, | ||
dangerouslySetExpanded: dangerouslySetExpanded | ||
}, /*#__PURE__*/React.createElement(Consumer$1, null, this.renderChildren)); | ||
} | ||
}]); | ||
return AccordionItem; | ||
}(React.Component); | ||
_defineProperty(AccordionItem, "defaultProps", defaultProps); | ||
_defineProperty(AccordionItem, "displayName", DisplayName$1.AccordionItem); | ||
function getClosestAccordion(el) { | ||
@@ -719,5 +825,2 @@ return el && (el.matches('[data-accordion-component="Accordion"]') ? el : getClosestAccordion(el.parentElement)); | ||
} | ||
default: | ||
} | ||
@@ -731,6 +834,7 @@ } | ||
return React.createElement("div", _extends({ | ||
return /*#__PURE__*/React.createElement("div", _extends({ | ||
className: className | ||
}, rest, { | ||
// tslint:disable-next-line react-a11y-event-has-role | ||
role: "button", | ||
tabIndex: 0, | ||
onClick: toggleExpanded, | ||
@@ -743,6 +847,6 @@ onKeyDown: handleKeyPress, | ||
var AccordionItemButtonWrapper = function AccordionItemButtonWrapper(props) { | ||
return React.createElement(Consumer$1, null, function (itemContext) { | ||
return /*#__PURE__*/React.createElement(Consumer$1, null, function (itemContext) { | ||
var toggleExpanded = itemContext.toggleExpanded, | ||
buttonAttributes = itemContext.buttonAttributes; | ||
return React.createElement(AccordionItemButton, _extends({ | ||
return /*#__PURE__*/React.createElement(AccordionItemButton, _extends({ | ||
toggleExpanded: toggleExpanded | ||
@@ -753,15 +857,3 @@ }, props, buttonAttributes)); | ||
var DisplayName; | ||
(function (DisplayName) { | ||
DisplayName["Accordion"] = "Accordion"; | ||
DisplayName["AccordionItem"] = "AccordionItem"; | ||
DisplayName["AccordionItemButton"] = "AccordionItemButton"; | ||
DisplayName["AccordionItemHeading"] = "AccordionItemHeading"; | ||
DisplayName["AccordionItemPanel"] = "AccordionItemPanel"; | ||
})(DisplayName || (DisplayName = {})); | ||
var DisplayName$1 = DisplayName; | ||
var defaultProps = { | ||
var defaultProps$1 = { | ||
className: 'accordion__heading', | ||
@@ -771,10 +863,8 @@ 'aria-level': 3 | ||
var 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 = | ||
/*#__PURE__*/ | ||
function (_React$PureComponent) { | ||
var AccordionItemHeading = /*#__PURE__*/function (_React$PureComponent) { | ||
_inherits(AccordionItemHeading, _React$PureComponent); | ||
var _super = _createSuper(AccordionItemHeading); | ||
function AccordionItemHeading() { | ||
var _getPrototypeOf2; | ||
var _this; | ||
@@ -788,3 +878,3 @@ | ||
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(AccordionItemHeading)).call.apply(_getPrototypeOf2, [this].concat(args))); | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
@@ -813,3 +903,3 @@ _defineProperty(_assertThisInitialized(_this), "ref", void 0); | ||
value: function render() { | ||
return React.createElement("div", _extends({ | ||
return /*#__PURE__*/React.createElement("div", _extends({ | ||
"data-accordion-component": "AccordionItemHeading" | ||
@@ -836,6 +926,6 @@ }, this.props, { | ||
_defineProperty(AccordionItemHeading, "defaultProps", defaultProps); | ||
_defineProperty(AccordionItemHeading, "defaultProps", defaultProps$1); | ||
var AccordionItemHeadingWrapper = function AccordionItemHeadingWrapper(props) { | ||
return React.createElement(Consumer$1, null, function (itemContext) { | ||
return /*#__PURE__*/React.createElement(Consumer$1, null, function (itemContext) { | ||
var headingAttributes = itemContext.headingAttributes; | ||
@@ -847,3 +937,3 @@ | ||
return React.createElement(AccordionItemHeading, _extends({}, props, headingAttributes)); | ||
return /*#__PURE__*/React.createElement(AccordionItemHeading, _extends({}, props, headingAttributes)); | ||
}); | ||
@@ -867,3 +957,3 @@ }; | ||
return React.createElement("div", _extends({ | ||
return /*#__PURE__*/React.createElement("div", _extends({ | ||
"data-accordion-component": "AccordionItemPanel", | ||
@@ -874,3 +964,3 @@ className: className | ||
return React.createElement(Consumer$1, null, renderChildren); | ||
return /*#__PURE__*/React.createElement(Consumer$1, null, renderChildren); | ||
}; | ||
@@ -884,3 +974,3 @@ | ||
disabled = itemContext.disabled; | ||
return React.createElement(React.Fragment, null, children({ | ||
return /*#__PURE__*/React.createElement(React.Fragment, null, children({ | ||
expanded: expanded, | ||
@@ -891,3 +981,3 @@ disabled: disabled | ||
return React.createElement(Consumer$1, null, renderChildren); | ||
return /*#__PURE__*/React.createElement(Consumer$1, null, renderChildren); | ||
}; | ||
@@ -905,2 +995,2 @@ | ||
})); | ||
}))); |
{ | ||
"name": "react-accessible-accordion", | ||
"version": "3.3.1", | ||
"version": "3.3.2", | ||
"description": "Accessible Accordion component for React", | ||
@@ -16,3 +16,3 @@ "main": "dist/umd/index.js", | ||
"coveralls": "cat ./coverage/lcov.info | coveralls", | ||
"lint": "tslint --project .", | ||
"lint": "eslint src", | ||
"typecheck": "tsc --project .", | ||
@@ -100,2 +100,4 @@ "build": "rimraf \"dist/**/*\" && yarn build:rollup && yarn build:types && yarn build:css", | ||
"@types/uuid": "^3.4.4", | ||
"@typescript-eslint/eslint-plugin": "^3.6.0", | ||
"@typescript-eslint/parser": "^3.6.0", | ||
"babel-core": "^7.0.0-bridge.0", | ||
@@ -106,2 +108,5 @@ "babel-jest": "^24.8.0", | ||
"css-loader": "^3.0.0", | ||
"eslint": "^7.4.0", | ||
"eslint-plugin-jsx-a11y": "^6.3.1", | ||
"eslint-plugin-react": "^7.20.3", | ||
"file-loader": "^4.0.0", | ||
@@ -127,7 +132,2 @@ "gh-pages": "^2.0.1", | ||
"style-loader": "^0.23.1", | ||
"tslint": "^6.1.2", | ||
"tslint-config-prettier": "^1.18.0", | ||
"tslint-microsoft-contrib": "^6.2.0", | ||
"tslint-plugin-prettier": "^2.3.0", | ||
"tslint-react": "^5.0.0", | ||
"typescript": "^3.9.5", | ||
@@ -134,0 +134,0 @@ "uuid": "^3.3.2", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
101858
1792
0