UNPKG

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.63 kB
import*as e from"react";import{useUpdateEffect as t}from"primereact/hooks";import{Tooltip as n}from"primereact/tooltip";import{ObjectUtils as r,DomHandler as o,classNames as a,IconUtils as l}from"primereact/utils";function c(){return c=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},c.apply(this,arguments)}function u(e){if(Array.isArray(e))return e}function i(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,a=[],l=!0,c=!1;try{for(n=n.call(e);!(l=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);l=!0);}catch(e){c=!0,o=e}finally{try{l||null==n.return||n.return()}finally{if(c)throw o}}return a}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function d(e,t){if(e){if("string"==typeof e)return s(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)?s(e,t):void 0}}function p(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var f=e.memo(e.forwardRef((function(s,m){var h,b,y=e.useState(!1),v=(b=2,u(h=y)||i(h,b)||d(h,b)||p()),g=v[0],k=v[1],x=e.useRef(null),E=e.useRef(s.inputRef),O=function(e){if(!s.disabled&&!s.readOnly&&s.onChange){var t=I(),n=e.target instanceof HTMLDivElement||e.target instanceof HTMLSpanElement;if(e.target===E.current||n&&e.target.checked!==t){var r=t?s.falseValue:s.trueValue;s.onChange({originalEvent:e,value:s.value,checked:r,stopPropagation:function(){},preventDefault:function(){},target:{type:"checkbox",name:s.name,id:s.id,value:s.value,checked:r}})}o.focus(E.current),e.preventDefault()}},I=function(){return s.checked===s.trueValue};e.useImperativeHandle(m,(function(){return{props:s,getElement:function(){return x.current},getInput:function(){return E.current}}})),e.useEffect((function(){r.combinedRefs(E,s.inputRef)}),[E,s.inputRef]),t((function(){E.current.checked=I()}),[s.checked,s.trueValue]);var C=I(),w=r.isNotEmpty(s.tooltip),R=r.findDiffKeys(s,f.defaultProps),S=r.reduceKeys(R,o.ARIA_PROPS),M=a("p-checkbox p-component",{"p-checkbox-checked":C,"p-checkbox-disabled":s.disabled,"p-checkbox-focused":g},s.className),A=a("p-checkbox-box",{"p-highlight":C,"p-disabled":s.disabled,"p-focus":g}),D=l.getJSXIcon(C?s.icon:"",{className:"p-checkbox-icon p-c"},{props:s,checked:C});return e.createElement(e.Fragment,null,e.createElement("div",c({ref:x,id:s.id,className:M,style:s.style},R,{onClick:O,onContextMenu:s.onContextMenu,onMouseDown:s.onMouseDown}),e.createElement("div",{className:"p-hidden-accessible"},e.createElement("input",c({ref:E,type:"checkbox",id:s.inputId,name:s.name,tabIndex:s.tabIndex,defaultChecked:C,onFocus:function(){k(!0)},onBlur:function(){k(!1)},onKeyDown:function(e){"Space"===e.code&&O(e)},disabled:s.disabled,readOnly:s.readOnly,required:s.required},S))),e.createElement("div",{className:A},D)),w&&e.createElement(n,c({target:x,content:s.tooltip},s.tooltipOptions)))})));f.displayName="Checkbox",f.defaultProps={__TYPE:"Checkbox",id:null,inputRef:null,inputId:null,value:null,name:null,checked:!1,trueValue:!0,falseValue:!1,style:null,className:null,disabled:!1,required:!1,readOnly:!1,tabIndex:null,icon:"pi pi-check",tooltip:null,tooltipOptions:null,onChange:null,onMouseDown:null,onContextMenu:null};export{f as Checkbox};