keycloak-d4science-spi-parent/keycloak-d4science-theme/src/main/resources/theme/d4science/account/resources/assets/Label-CVk_ec5U.js

3 lines
4.8 KiB
JavaScript

import{_ as le,B as ae,g as oe,f as c,h as ne,i as A}from"./index-Bw6oJPms.js";import*as e from"react";import{useState as M}from"react";const a={button:"pf-v5-c-button",label:"pf-v5-c-label",labelActions:"pf-v5-c-label__actions",labelContent:"pf-v5-c-label__content",labelIcon:"pf-v5-c-label__icon",labelText:"pf-v5-c-label__text",modifiers:{compact:"pf-m-compact",blue:"pf-m-blue",green:"pf-m-green",orange:"pf-m-orange",red:"pf-m-red",purple:"pf-m-purple",cyan:"pf-m-cyan",gold:"pf-m-gold",outline:"pf-m-outline",overflow:"pf-m-overflow",add:"pf-m-add",editable:"pf-m-editable",editableActive:"pf-m-editable-active"},themeDark:"pf-v5-theme-dark"},se={button:"pf-v5-c-button",labelGroup:"pf-v5-c-label-group",labelGroupClose:"pf-v5-c-label-group__close",labelGroupLabel:"pf-v5-c-label-group__label",labelGroupList:"pf-v5-c-label-group__list",labelGroupListItem:"pf-v5-c-label-group__list-item",labelGroupMain:"pf-v5-c-label-group__main",labelGroupTextarea:"pf-v5-c-label-group__textarea",modifiers:{category:"pf-m-category",vertical:"pf-m-vertical",editable:"pf-m-editable",textarea:"pf-m-textarea"}},re={name:"--pf-v5-c-label__text--MaxWidth",value:"100%",var:"var(--pf-v5-c-label__text--MaxWidth)"},ie={blue:a.modifiers.blue,cyan:a.modifiers.cyan,green:a.modifiers.green,orange:a.modifiers.orange,purple:a.modifiers.purple,red:a.modifiers.red,gold:a.modifiers.gold,grey:""},ce=h=>{var{children:s,className:D="",color:G="grey",variant:W="filled",isCompact:S=!1,isEditable:r=!1,editableProps:x,textMaxWidth:y,tooltipPosition:L,icon:k,onClose:w,onClick:i,onEditCancel:P,onEditComplete:f,closeBtn:V,closeBtnAriaLabel:F,closeBtnProps:H,href:p,isOverflowLabel:d,render:R}=h,K=le(h,["children","className","color","variant","isCompact","isEditable","editableProps","textMaxWidth","tooltipPosition","icon","onClose","onClick","onEditCancel","onEditComplete","closeBtn","closeBtnAriaLabel","closeBtnProps","href","isOverflowLabel","render"]);const[o,u]=M(!1),[$,q]=M(s),n=e.useRef(),l=e.useRef();e.useEffect(()=>(document.addEventListener("mousedown",I),document.addEventListener("keydown",O),()=>{document.removeEventListener("mousedown",I),document.removeEventListener("keydown",O)})),e.useEffect(()=>{i&&p?console.warn("Link labels cannot have onClick passed, this results in invalid HTML. Please remove either the href or onClick prop."):i&&r&&console.warn("Editable labels cannot have onClick passed, clicking starts the label edit process. Please remove either the isEditable or onClick prop.")},[i,p,r]);const I=t=>{o&&l&&l.current&&!l.current.contains(t.target)&&(l.current.value&&f&&f(t,l.current.value),u(!1))},O=t=>{var C,E;const v=t.key;if(!(!o&&(!n||!n.current||!n.current.contains(t.target))||o&&(!l||!l.current||!l.current.contains(t.target)))&&(o&&(v==="Enter"||v==="Tab")&&(t.preventDefault(),t.stopImmediatePropagation(),l.current.value&&f&&f(t,l.current.value),u(!1),(C=n?.current)===null||C===void 0||C.focus()),o&&v==="Escape"&&(t.preventDefault(),t.stopImmediatePropagation(),l.current.value&&(l.current.value=s,P&&P(t,s)),u(!1),(E=n?.current)===null||E===void 0||E.focus()),!o&&v==="Enter")){t.preventDefault(),t.stopImmediatePropagation(),u(!0);const te=t.target,_=document.createRange(),T=window.getSelection();_.selectNodeContents(te),_.collapse(!1),T.removeAllRanges(),T.addRange(_)}},z=d?"button":"span",J=e.createElement(ae,Object.assign({type:"button",variant:"plain",onClick:w,"aria-label":F||`Close ${s}`},H),e.createElement(oe,null)),Q=e.createElement("span",{className:c(a.labelActions)},V||J),B=e.createRef(),N=e.useRef(),[g,U]=e.useState(!1);ne(()=>{const t=r?n:B;o||U(t.current&&t.current.offsetWidth<t.current.scrollWidth)},[o]);const j=e.createElement(e.Fragment,null,k&&e.createElement("span",{className:c(a.labelIcon)},k),e.createElement("span",Object.assign({ref:B,className:c(a.labelText)},y&&{style:{[re.name]:y}}),s));e.useEffect(()=>{o&&l&&l.current&&l.current.focus()},[l,o]);const X=()=>{q(l.current.value)};let b="span";p?b="a":(r||i&&!d)&&(b="button");const Y={type:"button",onClick:i},Z=b==="button",ee=Object.assign(Object.assign(Object.assign(Object.assign({className:c(a.labelContent)},g&&{tabIndex:0}),p&&{href:p}),Z&&Y),r&&Object.assign({ref:n,onClick:t=>{u(!0),t.stopPropagation()}},x));let m=e.createElement(b,Object.assign({},ee),j);return R?m=e.createElement(e.Fragment,null,g&&e.createElement(A,{triggerRef:N,content:s,position:L}),R({className:a.labelContent,content:j,componentRef:N})):g&&(m=e.createElement(A,{content:s,position:L},m)),e.createElement(z,Object.assign({},K,{className:c(a.label,ie[G],W==="outline"&&a.modifiers.outline,d&&a.modifiers.overflow,S&&a.modifiers.compact,r&&se.modifiers.editable,o&&a.modifiers.editableActive,D),onClick:d?i:void 0}),!o&&m,!o&&w&&Q,o&&e.createElement("input",Object.assign({className:c(a.labelContent),type:"text",id:"editable-input",ref:l,value:$,onChange:X},x)))};ce.displayName="Label";export{ce as L};
//# sourceMappingURL=Label-CVk_ec5U.js.map