UNPKG

primereact

Version:

PrimeReact is an open source UI library for React featuring a rich set of 90+ 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.76 kB
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{ObjectUtils as r,UniqueComponentId as o,classNames as a}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,o,a,i=[],u=!0,s=!1;try{if(o=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;u=!1}else for(;!(u=(l=o.call(n)).done)&&(i.push(l.value),i.length!==t);u=!0);}catch(e){s=!0,r=e}finally{try{if(!u&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(s)throw r}}return i}}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 g(e,t){return u(e)||s(e,t)||p(e,t)||f()}var d={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,children:void 0},getProps:function(e){return r.getMergedProps(e,d.defaultProps)},getOtherProps:function(e){return r.getDiffProps(e,d.defaultProps)}},m=e.forwardRef((function(r,u){var s=d.getProps(r),c=g(e.useState(s.id),2),p=c[0],f=c[1],m=g(e.useState(s.collapsed),2),b=m[1],v=!!s.toggleable&&(s.onToggle?s.collapsed:m[0]),y=e.useRef(null),h=e.useRef(null),E=p+"_header",O=p+"_content",x=function(e){s.toggleable&&(v?N(e):P(e),s.onToggle&&s.onToggle({originalEvent:e,value:!v})),e.preventDefault()},N=function(e){s.onToggle||b(!1),s.onExpand&&s.onExpand(e)},P=function(e){s.onToggle||b(!0),s.onCollapse&&s.onCollapse(e)};n((function(){s.id||f(o())}));var C=function(){if(s.toggleable){var t=a("p-fieldset-toggler pi",{"pi-plus":v,"pi-minus":!v});return e.createElement("span",{className:t})}return null},j=function(){if(s.toggleable){var t=C();return e.createElement("a",{href:"#"+O,"aria-controls":O,id:E,"aria-expanded":!v,tabIndex:s.toggleable?null:-1},t,e.createElement("span",{className:"p-fieldset-legend-text"},s.legend),e.createElement(l,null))}return e.createElement("span",{className:"p-fieldset-legend-text",id:E},s.legend)};e.useImperativeHandle(u,(function(){return{props:s,getElement:function(){return y.current},getContent:function(){return h.current}}}));var T=d.getOtherProps(s),S=a("p-fieldset p-component",{"p-fieldset-toggleable":s.toggleable},s.className),w=function(){if(null!=s.legend||s.toggleable){var t=j();return e.createElement("legend",{className:"p-fieldset-legend p-unselectable-text",onClick:x},t)}}(),A=e.createElement(t,{nodeRef:h,classNames:"p-toggleable-content",timeout:{enter:1e3,exit:450},in:!v,unmountOnExit:!0,options:s.transitionOptions},e.createElement("div",{ref:h,id:O,className:"p-toggleable-content","aria-hidden":v,role:"region","aria-labelledby":E},e.createElement("div",{className:"p-fieldset-content"},s.children)));return e.createElement("fieldset",i({id:p,ref:y,className:S,style:s.style},T,{onClick:s.onClick}),w,A)}));m.displayName="Fieldset";export{m as Fieldset};