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) 2.48 kB
import*as e from"react";import{ObjectUtils as r,classNames as t,IconUtils as n}from"primereact/utils";function o(){return o=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},o.apply(this,arguments)}function l(e){if(Array.isArray(e))return e}function a(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,o,l=[],a=!0,i=!1;try{for(t=t.call(e);!(a=(n=t.next()).done)&&(l.push(n.value),!r||l.length!==r);a=!0);}catch(e){i=!0,o=e}finally{try{a||null==t.return||t.return()}finally{if(i)throw o}}return l}}function i(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function c(e,r){if(e){if("string"==typeof e)return i(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?i(e,r):void 0}}function u(){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 m=e.memo(e.forwardRef((function(i,p){var s,f,y,v,g,h=e.useRef(null),b=e.useState(!0),d=(f=2,l(s=b)||a(s,f)||c(s,f)||u()),I=d[0],E=d[1],S=function(e){13===e.keyCode&&A(e)},A=function(e){E(!1),i.onRemove&&i.onRemove(e)},w=function(){var r=[];return i.image?r.push(e.createElement("img",{key:"image",src:i.image,alt:i.imageAlt,onError:i.onImageError})):i.icon&&r.push(n.getJSXIcon(i.icon,{key:"icon",className:"p-chip-icon"},{props:i})),i.label&&r.push(e.createElement("span",{key:"label",className:"p-chip-text"},i.label)),i.removable&&r.push(n.getJSXIcon(i.removeIcon,{key:"removeIcon",tabIndex:0,className:"p-chip-remove-icon",onClick:A,onKeyDown:S},{props:i})),r};return e.useImperativeHandle(p,(function(){return{props:i,getElement:function(){return h.current}}})),I&&(y=r.findDiffKeys(i,m.defaultProps),v=t("p-chip p-component",{"p-chip-image":null!=i.image},i.className),g=i.template?r.getJSXElement(i.template,i):w(),e.createElement("div",o({ref:h,className:v,style:i.style},y),g))})));m.displayName="Chip",m.defaultProps={__TYPE:"Chip",label:null,icon:null,image:null,removable:!1,removeIcon:"pi pi-times-circle",className:null,style:null,template:null,imageAlt:"chip",onImageError:null,onRemove:null};export{m as Chip};