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) • 4.34 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/hooks"),n=require("primereact/tooltip"),r=require("primereact/utils");function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var c=o(e);function l(){return l=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},l.apply(this,arguments)}function u(e){if(Array.isArray(e))return e}function a(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,c,l,u=[],a=!0,i=!1;try{if(c=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;a=!1}else for(;!(a=(r=c.call(n)).done)&&(u.push(r.value),u.length!==t);a=!0);}catch(e){i=!0,o=e}finally{try{if(!a&&null!=n.return&&(l=n.return(),Object(l)!==l))return}finally{if(i)throw o}}return u}}function i(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 s(e,t){if(e){if("string"==typeof e)return i(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)?i(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.")}var d={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,children:void 0},getProps:function(e){return r.ObjectUtils.getMergedProps(e,d.defaultProps)},getOtherProps:function(e){return r.ObjectUtils.getDiffProps(e,d.defaultProps)}},p=c.memo(c.forwardRef((function(e,o){var i,p,b=d.getProps(e),m=c.useState(!1),h=(p=2,u(i=m)||a(i,p)||s(i,p)||f()),y=h[0],g=h[1],v=c.useRef(null),O=c.useRef(b.inputRef),k=function(e){if(!b.disabled&&!b.readOnly&&b.onChange){var t=x(),n=e.target instanceof HTMLDivElement||e.target instanceof HTMLSpanElement;if(e.target===O.current||n&&e.target.checked!==t){var o=t?b.falseValue:b.trueValue;b.onChange({originalEvent:e,value:b.value,checked:o,stopPropagation:function(){},preventDefault:function(){},target:{type:"checkbox",name:b.name,id:b.id,value:b.value,checked:o}})}r.DomHandler.focus(O.current),e.preventDefault()}},x=function(){return b.checked===b.trueValue};c.useImperativeHandle(o,(function(){return{props:b,focus:function(){return r.DomHandler.focus(O.current)},getElement:function(){return v.current},getInput:function(){return O.current}}})),c.useEffect((function(){r.ObjectUtils.combinedRefs(O,b.inputRef)}),[O,b.inputRef]),t.useUpdateEffect((function(){O.current.checked=x()}),[b.checked,b.trueValue]);var j=x(),P=r.ObjectUtils.isNotEmpty(b.tooltip),E=d.getOtherProps(b),I=r.ObjectUtils.reduceKeys(E,r.DomHandler.ARIA_PROPS),C=r.classNames("p-checkbox p-component",{"p-checkbox-checked":j,"p-checkbox-disabled":b.disabled,"p-checkbox-focused":y},b.className),D=r.classNames("p-checkbox-box",{"p-highlight":j,"p-disabled":b.disabled,"p-focus":y}),M=r.IconUtils.getJSXIcon(j?b.icon:"",{className:"p-checkbox-icon p-c"},{props:b,checked:j});return c.createElement(c.Fragment,null,c.createElement("div",l({ref:v,id:b.id,className:C,style:b.style},E,{onClick:k,onContextMenu:b.onContextMenu,onMouseDown:b.onMouseDown}),c.createElement("div",{className:"p-hidden-accessible"},c.createElement("input",l({ref:O,type:"checkbox",id:b.inputId,name:b.name,tabIndex:b.tabIndex,defaultChecked:j,onFocus:function(){g(!0)},onBlur:function(){g(!1)},onKeyDown:function(e){"Space"!==e.code&&" "!==e.key||k(e)},disabled:b.disabled,readOnly:b.readOnly,required:b.required},I))),c.createElement("div",{className:D},M)),P&&c.createElement(n.Tooltip,l({target:v,content:b.tooltip},b.tooltipOptions)))})));p.displayName="Checkbox",exports.Checkbox=p;
;