react-simple-accordion-ui
Version:
A flexible and customizable accordion component for React applications.
96 lines (88 loc) • 18.5 kB
JavaScript
(function(j,A){typeof exports=="object"&&typeof module<"u"?A(exports,require("react"),require("styled-components")):typeof define=="function"&&define.amd?define(["exports","react","styled-components"],A):(j=typeof globalThis<"u"?globalThis:j||self,A(j.ReactSimpleAccordion={},j.React,j.styled))})(this,function(j,A,Pe){"use strict";function ke(d){return d&&d.__esModule&&Object.prototype.hasOwnProperty.call(d,"default")?d.default:d}var J={exports:{}},F={};/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var te;function Ie(){if(te)return F;te=1;var d=A,S=Symbol.for("react.element"),m=Symbol.for("react.fragment"),g=Object.prototype.hasOwnProperty,l=d.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};function u(v,_,w){var h,C={},O=null,V=null;w!==void 0&&(O=""+w),_.key!==void 0&&(O=""+_.key),_.ref!==void 0&&(V=_.ref);for(h in _)g.call(_,h)&&!a.hasOwnProperty(h)&&(C[h]=_[h]);if(v&&v.defaultProps)for(h in _=v.defaultProps,_)C[h]===void 0&&(C[h]=_[h]);return{$$typeof:S,type:v,key:O,ref:V,props:C,_owner:l.current}}return F.Fragment=m,F.jsx=u,F.jsxs=u,F}var N={};/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var ne;function We(){return ne||(ne=1,process.env.NODE_ENV!=="production"&&function(){var d=A,S=Symbol.for("react.element"),m=Symbol.for("react.portal"),g=Symbol.for("react.fragment"),l=Symbol.for("react.strict_mode"),a=Symbol.for("react.profiler"),u=Symbol.for("react.provider"),v=Symbol.for("react.context"),_=Symbol.for("react.forward_ref"),w=Symbol.for("react.suspense"),h=Symbol.for("react.suspense_list"),C=Symbol.for("react.memo"),O=Symbol.for("react.lazy"),V=Symbol.for("react.offscreen"),ie=Symbol.iterator,Me="@@iterator";function Ve(e){if(e===null||typeof e!="object")return null;var r=ie&&e[ie]||e[Me];return typeof r=="function"?r:null}var I=d.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function y(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];Ue("error",e,t)}}function Ue(e,r,t){{var n=I.ReactDebugCurrentFrame,s=n.getStackAddendum();s!==""&&(r+="%s",t=t.concat([s]));var c=t.map(function(i){return String(i)});c.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,c)}}var $e=!1,He=!1,Be=!1,Je=!1,ze=!1,se;se=Symbol.for("react.module.reference");function Ke(e){return!!(typeof e=="string"||typeof e=="function"||e===g||e===a||ze||e===l||e===w||e===h||Je||e===V||$e||He||Be||typeof e=="object"&&e!==null&&(e.$$typeof===O||e.$$typeof===C||e.$$typeof===u||e.$$typeof===v||e.$$typeof===_||e.$$typeof===se||e.getModuleId!==void 0))}function Ge(e,r,t){var n=e.displayName;if(n)return n;var s=r.displayName||r.name||"";return s!==""?t+"("+s+")":t}function ce(e){return e.displayName||"Context"}function x(e){if(e==null)return null;if(typeof e.tag=="number"&&y("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case g:return"Fragment";case m:return"Portal";case a:return"Profiler";case l:return"StrictMode";case w:return"Suspense";case h:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case v:var r=e;return ce(r)+".Consumer";case u:var t=e;return ce(t._context)+".Provider";case _:return Ge(e,e.render,"ForwardRef");case C:var n=e.displayName||null;return n!==null?n:x(e.type)||"Memo";case O:{var s=e,c=s._payload,i=s._init;try{return x(i(c))}catch{return null}}}return null}var P=Object.assign,Y=0,ue,le,fe,de,pe,_e,ve;function me(){}me.__reactDisabledLog=!0;function Xe(){{if(Y===0){ue=console.log,le=console.info,fe=console.warn,de=console.error,pe=console.group,_e=console.groupCollapsed,ve=console.groupEnd;var e={configurable:!0,enumerable:!0,value:me,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}Y++}}function qe(){{if(Y--,Y===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:P({},e,{value:ue}),info:P({},e,{value:le}),warn:P({},e,{value:fe}),error:P({},e,{value:de}),group:P({},e,{value:pe}),groupCollapsed:P({},e,{value:_e}),groupEnd:P({},e,{value:ve})})}Y<0&&y("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var z=I.ReactCurrentDispatcher,K;function U(e,r,t){{if(K===void 0)try{throw Error()}catch(s){var n=s.stack.trim().match(/\n( *(at )?)/);K=n&&n[1]||""}return`
`+K+e}}var G=!1,$;{var Ze=typeof WeakMap=="function"?WeakMap:Map;$=new Ze}function he(e,r){if(!e||G)return"";{var t=$.get(e);if(t!==void 0)return t}var n;G=!0;var s=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var c;c=z.current,z.current=null,Xe();try{if(r){var i=function(){throw Error()};if(Object.defineProperty(i.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(i,[])}catch(E){n=E}Reflect.construct(e,[],i)}else{try{i.call()}catch(E){n=E}e.call(i.prototype)}}else{try{throw Error()}catch(E){n=E}e()}}catch(E){if(E&&n&&typeof E.stack=="string"){for(var o=E.stack.split(`
`),R=n.stack.split(`
`),f=o.length-1,p=R.length-1;f>=1&&p>=0&&o[f]!==R[p];)p--;for(;f>=1&&p>=0;f--,p--)if(o[f]!==R[p]){if(f!==1||p!==1)do if(f--,p--,p<0||o[f]!==R[p]){var T=`
`+o[f].replace(" at new "," at ");return e.displayName&&T.includes("<anonymous>")&&(T=T.replace("<anonymous>",e.displayName)),typeof e=="function"&&$.set(e,T),T}while(f>=1&&p>=0);break}}}finally{G=!1,z.current=c,qe(),Error.prepareStackTrace=s}var D=e?e.displayName||e.name:"",k=D?U(D):"";return typeof e=="function"&&$.set(e,k),k}function Qe(e,r,t){return he(e,!1)}function er(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function H(e,r,t){if(e==null)return"";if(typeof e=="function")return he(e,er(e));if(typeof e=="string")return U(e);switch(e){case w:return U("Suspense");case h:return U("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case _:return Qe(e.render);case C:return H(e.type,r,t);case O:{var n=e,s=n._payload,c=n._init;try{return H(c(s),r,t)}catch{}}}return""}var L=Object.prototype.hasOwnProperty,ge={},ye=I.ReactDebugCurrentFrame;function B(e){if(e){var r=e._owner,t=H(e.type,e._source,r?r.type:null);ye.setExtraStackFrame(t)}else ye.setExtraStackFrame(null)}function rr(e,r,t,n,s){{var c=Function.call.bind(L);for(var i in e)if(c(e,i)){var o=void 0;try{if(typeof e[i]!="function"){var R=Error((n||"React class")+": "+t+" type `"+i+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[i]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw R.name="Invariant Violation",R}o=e[i](r,i,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(f){o=f}o&&!(o instanceof Error)&&(B(s),y("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,i,typeof o),B(null)),o instanceof Error&&!(o.message in ge)&&(ge[o.message]=!0,B(s),y("Failed %s type: %s",t,o.message),B(null))}}}var tr=Array.isArray;function X(e){return tr(e)}function nr(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function ar(e){try{return Re(e),!1}catch{return!0}}function Re(e){return""+e}function be(e){if(ar(e))return y("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",nr(e)),Re(e)}var M=I.ReactCurrentOwner,or={key:!0,ref:!0,__self:!0,__source:!0},Ee,Se,q;q={};function ir(e){if(L.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function sr(e){if(L.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function cr(e,r){if(typeof e.ref=="string"&&M.current&&r&&M.current.stateNode!==r){var t=x(M.current.type);q[t]||(y('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',x(M.current.type),e.ref),q[t]=!0)}}function ur(e,r){{var t=function(){Ee||(Ee=!0,y("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function lr(e,r){{var t=function(){Se||(Se=!0,y("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var fr=function(e,r,t,n,s,c,i){var o={$$typeof:S,type:e,key:r,ref:t,props:i,_owner:c};return o._store={},Object.defineProperty(o._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(o,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(o,"_source",{configurable:!1,enumerable:!1,writable:!1,value:s}),Object.freeze&&(Object.freeze(o.props),Object.freeze(o)),o};function dr(e,r,t,n,s){{var c,i={},o=null,R=null;t!==void 0&&(be(t),o=""+t),sr(r)&&(be(r.key),o=""+r.key),ir(r)&&(R=r.ref,cr(r,s));for(c in r)L.call(r,c)&&!or.hasOwnProperty(c)&&(i[c]=r[c]);if(e&&e.defaultProps){var f=e.defaultProps;for(c in f)i[c]===void 0&&(i[c]=f[c])}if(o||R){var p=typeof e=="function"?e.displayName||e.name||"Unknown":e;o&&ur(i,p),R&&lr(i,p)}return fr(e,o,R,s,n,M.current,i)}}var Z=I.ReactCurrentOwner,Te=I.ReactDebugCurrentFrame;function W(e){if(e){var r=e._owner,t=H(e.type,e._source,r?r.type:null);Te.setExtraStackFrame(t)}else Te.setExtraStackFrame(null)}var Q;Q=!1;function ee(e){return typeof e=="object"&&e!==null&&e.$$typeof===S}function Ce(){{if(Z.current){var e=x(Z.current.type);if(e)return`
Check the render method of \``+e+"`."}return""}}function pr(e){return""}var Ae={};function _r(e){{var r=Ce();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=`
Check the top-level render call using <`+t+">.")}return r}}function xe(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=_r(r);if(Ae[t])return;Ae[t]=!0;var n="";e&&e._owner&&e._owner!==Z.current&&(n=" It was passed a child from "+x(e._owner.type)+"."),W(e),y('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),W(null)}}function je(e,r){{if(typeof e!="object")return;if(X(e))for(var t=0;t<e.length;t++){var n=e[t];ee(n)&&xe(n,r)}else if(ee(e))e._store&&(e._store.validated=!0);else if(e){var s=Ve(e);if(typeof s=="function"&&s!==e.entries)for(var c=s.call(e),i;!(i=c.next()).done;)ee(i.value)&&xe(i.value,r)}}}function vr(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===_||r.$$typeof===C))t=r.propTypes;else return;if(t){var n=x(r);rr(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!Q){Q=!0;var s=x(r);y("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",s||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&y("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function mr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){W(e),y("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),W(null);break}}e.ref!==null&&(W(e),y("Invalid attribute `ref` supplied to `React.Fragment`."),W(null))}}var we={};function Oe(e,r,t,n,s,c){{var i=Ke(e);if(!i){var o="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(o+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var R=pr();R?o+=R:o+=Ce();var f;e===null?f="null":X(e)?f="array":e!==void 0&&e.$$typeof===S?(f="<"+(x(e.type)||"Unknown")+" />",o=" Did you accidentally export a JSX literal instead of a component?"):f=typeof e,y("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",f,o)}var p=dr(e,r,t,s,c);if(p==null)return p;if(i){var T=r.children;if(T!==void 0)if(n)if(X(T)){for(var D=0;D<T.length;D++)je(T[D],e);Object.freeze&&Object.freeze(T)}else y("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else je(T,e)}if(L.call(r,"key")){var k=x(e),E=Object.keys(r).filter(function(Er){return Er!=="key"}),re=E.length>0?"{key: someKey, "+E.join(": ..., ")+": ...}":"{key: someKey}";if(!we[k+re]){var br=E.length>0?"{"+E.join(": ..., ")+": ...}":"{}";y(`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`,re,k,br,k),we[k+re]=!0}}return e===g?mr(p):vr(p),p}}function hr(e,r,t){return Oe(e,r,t,!0)}function gr(e,r,t){return Oe(e,r,t,!1)}var yr=gr,Rr=hr;N.Fragment=g,N.jsx=yr,N.jsxs=Rr}()),N}process.env.NODE_ENV==="production"?J.exports=Ie():J.exports=We();var b=J.exports,ae={exports:{}};/*!
Copyright (c) 2018 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/(function(d){(function(){var S={}.hasOwnProperty;function m(){for(var a="",u=0;u<arguments.length;u++){var v=arguments[u];v&&(a=l(a,g(v)))}return a}function g(a){if(typeof a=="string"||typeof a=="number")return a;if(typeof a!="object")return"";if(Array.isArray(a))return m.apply(null,a);if(a.toString!==Object.prototype.toString&&!a.toString.toString().includes("[native code]"))return a.toString();var u="";for(var v in a)S.call(a,v)&&a[v]&&(u=l(u,v));return u}function l(a,u){return u?a?a+" "+u:a+u:a}d.exports?(m.default=m,d.exports=m):window.classNames=m})()})(ae);var De=ae.exports;const oe=ke(De),Fe=Pe.section`
&.RSA__AccordionWrapper {
.RSA__AccordionWrapper__Item {
&.active {
.RSA__AccordionWrapper__Item__Header {
.RSA__AccordionWrapper__Item__Header__Toggle {
.RSA__AccordionWrapper__Item__Header__Toggle__Icon {
transform: rotate(180deg);
}
}
}
.RSA__AccordionWrapper__Item__Content {
opacity: 1;
visibility: visible;
grid-template-rows: 1fr;
}
}
.RSA__AccordionWrapper__Item__Header {
position: relative;
.RSA__AccordionWrapper__Item__Header__Toggle {
font-size: initial;
font-family: inherit;
cursor: pointer;
position: relative;
width: 100%;
background: 0;
padding: 0;
margin: 0;
border: 0;
outline: none;
display: flex;
align-items: center;
color: currentColor;
.RSA__AccordionWrapper__Item__Header__Toggle__Icon {
margin-left: auto;
transition: 200ms ease-in-out;
flex: 0 0 24px;
}
}
}
.RSA__AccordionWrapper__Item__Content {
opacity: 0;
visibility: hidden;
position: relative;
display: grid;
grid-template-rows: 0fr;
transition:
grid-template-rows 400ms ease-in-out,
opacity 800ms ease-in-out,
visibility 800ms ease-in-out;
.RSA__AccordionWrapper__Item__Content__ContentContainer {
overflow: hidden;
}
}
}
}
`,Ne=d=>{const[S,m]=A.useState(new Set),g=A.useCallback(l=>{m(a=>d?a.has(l)?new Set([...a].filter(u=>u!==l)):new Set([...a,l]):a.has(l)?new Set:new Set([l]))},[d]);return{active:S,toggleActive:g}},Ye=A.memo(({title:d,content:S,action:m,uuid:g,isActive:l,toggleActive:a,duration:u,easing:v})=>{const _=oe("RSA__AccordionWrapper__Item",{active:l});return b.jsxs("div",{className:_,children:[b.jsx("div",{className:"RSA__AccordionWrapper__Item__Header",children:m?b.jsxs(b.Fragment,{children:[d,b.jsx("span",{"aria-expanded":l,"aria-label":"expand",onClick:()=>a(g),role:"button",children:m(l)})]}):b.jsxs("button",{"aria-expanded":l,"aria-label":"expand",onClick:()=>a(g),className:"RSA__AccordionWrapper__Item__Header__Toggle",children:[d,b.jsxs("svg",{className:"RSA__AccordionWrapper__Item__Header__Toggle__Icon",width:"24",height:"24",viewBox:"0 0 24 24",strokeWidth:"2",stroke:"currentColor",fill:"none",strokeLinecap:"round",strokeLinejoin:"round",children:[b.jsx("path",{d:"M0 0h24v24H0z",stroke:"none"}),b.jsx("path",{d:"m6 9 6 6 6-6"})]})]})}),b.jsx("div",{className:"RSA__AccordionWrapper__Item__Content","aria-hidden":!l,style:{transitionTimingFunction:v,transitionDuration:u?`${u}ms`:void 0},children:b.jsx("div",{className:"RSA__AccordionWrapper__Item__Content__ContentContainer",children:b.jsx("div",{className:"RSA__AccordionWrapper__Item__Content__ContentContainer__Wrapper",children:S})})})]})}),Le=({allowMultiple:d=!0,className:S,duration:m,easing:g,items:l})=>{const{active:a,toggleActive:u}=Ne(d),v=A.useMemo(()=>l.map((_,w)=>{const h=`accordion-item-${w}`,C=a.has(h);return b.jsx(Ye,{..._,uuid:h,isActive:C,toggleActive:u,duration:m,easing:g},h)}),[l,a,u,m,g]);return b.jsx(Fe,{className:oe("RSA__AccordionWrapper",S),children:v})};j.Accordion=Le,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"})});