primereact
Version:
PrimeReact is an open source UI library for React featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with Prime
2 lines (1 loc) • 3.52 kB
JavaScript
import*as e from"react";import{CSSTransition as t}from"primereact/csstransition";import{useMountEffect as n}from"primereact/hooks";import{Ripple as l}from"primereact/ripple";import{UniqueComponentId as r,ObjectUtils as a,classNames as o}from"primereact/utils";function i(){return i=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var l in n)Object.prototype.hasOwnProperty.call(n,l)&&(e[l]=n[l])}return e},i.apply(this,arguments)}function u(e){if(Array.isArray(e))return e}function s(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var l,r,a=[],o=!0,i=!1;try{for(n=n.call(e);!(o=(l=n.next()).done)&&(a.push(l.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==n.return||n.return()}finally{if(i)throw r}}return a}}function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,l=new Array(t);n<t;n++)l[n]=e[n];return l}function p(e,t){if(e){if("string"==typeof e)return c(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?c(e,t):void 0}}function f(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function d(e,t){return u(e)||s(e,t)||p(e,t)||f()}var g=e.forwardRef((function(u,s){var c=d(e.useState(u.id),2),p=c[0],f=c[1],m=d(e.useState(u.collapsed),2),b=m[1],y=!!u.toggleable&&(u.onToggle?u.collapsed:m[0]),v=e.useRef(null),E=e.useRef(null),h=p+"_header",x=p+"_content",N=function(e){u.toggleable&&(y?C(e):O(e),u.onToggle&&u.onToggle({originalEvent:e,value:!y})),e.preventDefault()},C=function(e){u.onToggle||b(!1),u.onExpand&&u.onExpand(e)},O=function(e){u.onToggle||b(!0),u.onCollapse&&u.onCollapse(e)};n((function(){u.id||f(r())}));var T=function(){if(u.toggleable){var t=o("p-fieldset-toggler pi",{"pi-plus":y,"pi-minus":!y});return e.createElement("span",{className:t})}return null},S=function(){if(u.toggleable){var t=T();return e.createElement("a",{href:"#"+x,"aria-controls":x,id:h,"aria-expanded":!y,tabIndex:u.toggleable?null:-1},t,e.createElement("span",{className:"p-fieldset-legend-text"},u.legend),e.createElement(l,null))}return e.createElement("span",{className:"p-fieldset-legend-text",id:h},u.legend)};e.useImperativeHandle(s,(function(){return{props:u,getElement:function(){return v.current},getContent:function(){return E.current}}}));var j=a.findDiffKeys(u,g.defaultProps),w=o("p-fieldset p-component",{"p-fieldset-toggleable":u.toggleable},u.className),A=function(){if(null!=u.legend||u.toggleable){var t=S();return e.createElement("legend",{className:"p-fieldset-legend p-unselectable-text",onClick:N},t)}}(),k=e.createElement(t,{nodeRef:E,classNames:"p-toggleable-content",timeout:{enter:1e3,exit:450},in:!y,unmountOnExit:!0,options:u.transitionOptions},e.createElement("div",{ref:E,id:x,className:"p-toggleable-content","aria-hidden":y,role:"region","aria-labelledby":h},e.createElement("div",{className:"p-fieldset-content"},u.children)));return e.createElement("fieldset",i({id:p,ref:v,className:w,style:u.style},j,{onClick:u.onClick}),A,k)}));g.displayName="Fieldset",g.defaultProps={__TYPE:"Fieldset",id:null,legend:null,className:null,style:null,toggleable:null,collapsed:null,transitionOptions:null,onExpand:null,onCollapse:null,onToggle:null,onClick:null};export{g as Fieldset};