@legion-ui-kit/react-core
Version:
To install the package into your project:
4 lines (3 loc) • 1.55 kB
JavaScript
"use client";
import{jsxs as e,jsx as t}from"react/jsx-runtime";import{useRef as l,useState as s,useEffect as o}from"react";import r from"classnames";import n from"./styles.module.scss.js";import{ACCORDION_DEFAULT_PROPS as a,ACCORDION_TOGGLE_POSITION as i,ACCORDION_TOGGLE_ICONS as c}from"./Accordion.constant.js";import{isEmpty as m}from"../../helpers/common.js";import{isFunction as d}from"../../helpers/typeChecker.js";import{snakeCase as g}from"../../helpers/typography.js";const p=p=>{const{children:h,className:f,contentClassName:y,contentStyle:N,disabled:u,headerClassName:C,headerStyle:j,isOpen:_=a.isOpen,noToggle:S,onClick:b,openedClassName:k,openedStyle:v,style:I,title:x,titleClassName:H,titleStyle:O,toggleClassName:A,toggleIcon:P=a.toggleIcon,toggleIconPosition:T=i.right,toggleStyle:$,...q}=p,w=T===i.left,z=l(null),[B,D]=s(0),E=r(n.legion_accordion,f,{[n.left_toggle]:w,[n.disabled]:u,[`${k}`]:_&&!!k,[n.open]:_}),F=r(C,n.accordion_header),G=r(H,n.title),J=r(A,n.toggle_icon),K=r(n.toggle_default,{[n[g(P)]]:c.includes(P)}),L=r(y,n.accordion_content),M={...I,..._?v:{}};o(()=>{m(z?.current?.offsetHeight)||D(z?.current.offsetHeight)},[]);return e("div",{className:E,style:M,...q,children:[e("button",{className:F,style:j,onClick:()=>{d(b)&&b(!_)},disabled:u,children:[t("span",{className:G,style:O,children:x}),!S&&t("span",{className:J,style:$,children:t("i",{className:K})})]}),t("div",{className:L,style:{...N,height:_?B:0},children:t("div",{ref:z,children:h})})]})};export{p as default};
//# sourceMappingURL=Accordion.js.map