2 lines
3.5 KiB
JavaScript
2 lines
3.5 KiB
JavaScript
import e,{Component as t}from"react";import{IconUtils as o,classNames as r,ObjectUtils as n}from"primereact/utils";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var o=0;o<t.length;o++){var r=t[o];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function p(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function c(e,t){return c=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},c(e,t)}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&c(e,t)}function u(e){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},u(e)}function a(e,t){if(t&&("object"===u(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return p(e)}function f(e){return f=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},f(e)}function y(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}var m,h,b,v=function(c){l(g,t);var u,m,h,b,v,d=(u=g,m=y(),function(){var e,t=f(u);if(m){var o=f(this).constructor;e=Reflect.construct(t,arguments,o)}else e=t.apply(this,arguments);return a(this,e)});function g(e){var t;return i(this,g),(t=d.call(this,e)).state={visible:!0},t.close=t.close.bind(p(t)),t.onKeyDown=t.onKeyDown.bind(p(t)),t}return h=g,(b=[{key:"onKeyDown",value:function(e){13===e.keyCode&&this.close(e)}},{key:"close",value:function(e){var t=this;e.persist(),this.setState({visible:!1},(function(){t.props.onRemove&&t.props.onRemove(e)}))}},{key:"renderContent",value:function(){var t=this,r=[];return this.props.image?r.push(e.createElement("img",{key:"image",src:this.props.image,alt:this.props.imageAlt,onError:function(e){t.props.onImageError&&t.props.onImageError(e)}})):this.props.icon&&r.push(o.getJSXIcon(this.props.icon,{key:"icon",className:"p-chip-icon"},{props:this.props})),this.props.label&&r.push(e.createElement("span",{key:"label",className:"p-chip-text"},this.props.label)),this.props.removable&&r.push(o.getJSXIcon(this.props.removeIcon,{key:"removeIcon",tabIndex:0,className:"p-chip-remove-icon",onClick:this.close,onKeyDown:this.onKeyDown},{props:this.props})),r}},{key:"renderElement",value:function(){var t=r("p-chip p-component",{"p-chip-image":null!=this.props.image},this.props.className),o=this.props.template?n.getJSXElement(this.props.template,this.props):this.renderContent();return e.createElement("div",{className:t,style:this.props.style},o)}},{key:"render",value:function(){return this.state.visible&&this.renderElement()}}])&&s(h.prototype,b),v&&s(h,v),Object.defineProperty(h,"prototype",{writable:!1}),g}();b={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},(h="defaultProps")in(m=v)?Object.defineProperty(m,h,{value:b,enumerable:!0,configurable:!0,writable:!0}):m[h]=b;export{v as Chip};
|