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.42 kB
JavaScript
import*as e from"react";import{PrimeReactContext as n,localeOption as t}from"primereact/api";import{Button as l}from"primereact/button";import{ComponentBase as a,useHandleStyle as r}from"primereact/componentbase";import{useMergeProps as o,useUpdateEffect as i}from"primereact/hooks";import{TimesIcon as c}from"primereact/icons/times";import{classNames as p,ObjectUtils as s,IconUtils as u}from"primereact/utils";function d(e){if(Array.isArray(e))return e}function f(e,n){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var l,a,r,o,i=[],c=!0,p=!1;try{if(r=(t=t.call(e)).next,0===n){if(Object(t)!==t)return;c=!1}else for(;!(c=(l=r.call(t)).done)&&(i.push(l.value),i.length!==n);c=!0);}catch(e){p=!0,a=e}finally{try{if(!c&&null!=t.return&&(o=t.return(),Object(o)!==o))return}finally{if(p)throw a}}return i}}function m(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,l=Array(n);t<n;t++)l[t]=e[t];return l}function v(e,n){if(e){if("string"==typeof e)return m(e,n);var t={}.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)?m(e,n):void 0}}function y(){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 b={display:function(e){return p("p-inplace-display",{"p-disabled":e.props.disabled})},root:function(e){return p("p-inplace p-component",{"p-inplace-closable":e.props.closable})},closeButton:"p-inplace-content-close",content:"p-inplace-content"};a.extend({defaultProps:{__TYPE:"InplaceDisplay",children:void 0}}),a.extend({defaultProps:{__TYPE:"InplaceContent",children:void 0}});var g=a.extend({defaultProps:{__TYPE:"Inplace",style:null,className:null,active:!1,closable:!1,closeIcon:null,disabled:!1,tabIndex:0,ariaLabel:null,onOpen:null,onClose:null,onToggle:null,children:void 0},css:{classes:b,styles:"\n@layer primereact {\n .p-inplace .p-inplace-display {\n display: inline;\n cursor: pointer;\n }\n \n .p-inplace .p-inplace-content {\n display: inline;\n }\n \n .p-fluid .p-inplace.p-inplace-closable .p-inplace-content {\n display: flex;\n }\n \n .p-fluid .p-inplace.p-inplace-closable .p-inplace-content > .p-inputtext {\n flex: 1 1 auto;\n width: 1%;\n }\n \n .p-inplace-content-close {\n margin-left: .25rem;\n }\n}\n"}}),h=function(e){return e.children},I=function(e){return e.children},C=e.forwardRef((function(a,m){var b,h,I=o(),C=e.useContext(n),E=g.getProps(a,C),x=e.useState(E.active),N=(h=2,d(b=x)||f(b,h)||v(b,h)||y()),T=N[0],P=N[1],S=e.useRef(null),_=E.onToggle?E.active:T,D={props:E,state:{active:T}},O=g.setMetaData(D),w=O.ptm,A=O.cx;r(g.css.styles,O.isUnstyled,{name:"inplace"});var j=function(e){E.disabled||(E.onOpen&&E.onOpen(e),E.onToggle?E.onToggle({originalEvent:e,value:!0}):P(!0))},k=function(e){E.disabled||(E.onClose&&E.onClose(e),E.onToggle?E.onToggle({originalEvent:e,value:!1}):P(!1))},B=function(e){"Enter"!==e.code&&"NumpadEnter"!==e.code&&"Space"!==e.code||(j(e),e.preventDefault())},M=function(n){var t=I({onClick:j,className:A("display"),onKeyDown:B,tabIndex:E.tabIndex||"0",role:"button","aria-label":E.ariaLabel},w("display"));return e.createElement("div",t,n)},Y=function(){var n=u.getJSXIcon(E.closeIcon||e.createElement(c,null),void 0,{props:E}),a=t("aria")?t("aria").close:void 0;if(E.closable){var r=I({className:A("closeButton"),icon:n,type:"button",onClick:k,"aria-label":a,pt:w("closeButton"),__parentMetadata:{parent:D}});return e.createElement(l,r)}return null};e.useImperativeHandle(m,(function(){return{props:E,getElement:function(){return S.current}}})),i((function(){E.active?j(null):k(null)}),[E.active]);var L,R=(L=["InplaceContent","InplaceDisplay"],e.Children.map(E.children,(function(n){return _&&s.isValidChild(n,"InplaceContent",L)?(t=n,l=Y(),a=I({className:A("content")},w("content")),e.createElement("div",a,t,l)):!_&&s.isValidChild(n,"InplaceDisplay",L)?M(n):void 0;var t,l,a}))),U=I({ref:S,className:p(E.className,A("root")),"aria-live":"polite"},g.getOtherProps(E),w("root"));return e.createElement("div",U,R)}));h.displayName="InplaceDisplay",I.displayName="InplaceContent",C.displayName="Inplace";export{C as Inplace,I as InplaceContent,h as InplaceDisplay};