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.17 kB
import*as e from"react";import{localeOption as n}from"primereact/api";import{Button as t}from"primereact/button";import{ObjectUtils as r,classNames as a}from"primereact/utils";function l(){return l=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},l.apply(this,arguments)}function o(e){if(Array.isArray(e))return e}function i(e,n){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var r,a,l=[],o=!0,i=!1;try{for(t=t.call(e);!(o=(r=t.next()).done)&&(l.push(r.value),!n||l.length!==n);o=!0);}catch(e){i=!0,a=e}finally{try{o||null==t.return||t.return()}finally{if(i)throw a}}return l}}function c(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function u(e,n){if(e){if("string"==typeof e)return c(e,n);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)?c(e,n):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 s=function(e){return e.children},f=function(e){return e.children},d=e.forwardRef((function(c,m){var y,b,v=e.useState(c.active),g=(b=2,o(y=v)||i(y,b)||u(y,b)||p()),h=g[0],I=g[1],E=e.useRef(null),P=c.onToggle?c.active:h,T=function(e){return e&&"InplaceContent"===e.props.__TYPE},C=function(e){return e&&"InplaceDisplay"===e.props.__TYPE},_=function(e){c.disabled||(c.onOpen&&c.onOpen(e),c.onToggle?c.onToggle({originalEvent:e,value:!0}):I(!0))},N=function(e){c.onClose&&c.onClose(e),c.onToggle?c.onToggle({originalEvent:e,value:!1}):I(!1)},O=function(e){"Enter"===e.key&&(_(e),e.preventDefault())},D=function(n){var t=r.findDiffKeys(n.props,s.defaultProps),o=a("p-inplace-display",{"p-disabled":c.disabled});return e.createElement("div",l({className:o},t,{onClick:_,onKeyDown:O,tabIndex:c.tabIndex,"aria-label":c.ariaLabel}),n)},w=function(a){var o=r.findDiffKeys(a.props,f.defaultProps),i=c.closable?e.createElement(t,{type:"button",className:"p-inplace-content-close",icon:"pi pi-times",onClick:N,"aria-label":n("close")}):null;return e.createElement("div",l({className:"p-inplace-content"},o),a,i)};e.useImperativeHandle(m,(function(){return{props:c,getElement:function(){return E.current}}}));var j=r.findDiffKeys(c,d.defaultProps),A=e.Children.map(c.children,(function(e){return P&&T(e)?w(e):!P&&C(e)?D(e):void 0})),S=a("p-inplace p-component",{"p-inplace-closable":c.closable},c.className);return e.createElement("div",l({ref:E,className:S},j),A)}));s.displayName="InplaceDisplay",s.defaultProps={__TYPE:"InplaceDisplay"},f.displayName="InplaceContent",f.defaultProps={__TYPE:"InplaceContent"},d.displayName="Inplace",d.defaultProps={__TYPE:"Inplace",style:null,className:null,active:!1,closable:!1,disabled:!1,tabIndex:0,ariaLabel:null,onOpen:null,onClose:null,onToggle:null};export{d as Inplace,f as InplaceContent,s as InplaceDisplay};