All Downloads are FREE. Search and download functionalities are using the official Maven repository.

theme.keycloak.v2.admin.resources.assets.KeyValueInput-597f6e1a.js Maven / Gradle / Ivy

There is a newer version: 25.0.1
Show newest version
import{_,r as i,k as x,co as A,p as R,cn as q,u as I,ar as b,j as e,cS as S,a as O,aw as P,Q as F,B as v}from"./index-0cda761d.js";import{K as N}from"./KeycloakTextInput-ada01047.js";import{u as M}from"./useToggle-3764a2a4.js";import{G as $,a as h}from"./GridItem-1535d986.js";import{S as w,b as g}from"./Select-68736f55.js";import{M as G}from"./minus-icon-21b0d1e4.js";import{M as H}from"./minus-circle-icon-ac3563ca.js";import{A as L,a as B}from"./ActionListItem-c859aeaf.js";import{P as C}from"./plus-circle-icon-fe78809e.js";import{E as D,a as K}from"./EmptyStateBody-f9d2c033.js";const m={helperText:"pf-c-helper-text",helperTextItem:"pf-c-helper-text__item",helperTextItemIcon:"pf-c-helper-text__item-icon",helperTextItemText:"pf-c-helper-text__item-text",modifiers:{indeterminate:"pf-m-indeterminate",warning:"pf-m-warning",success:"pf-m-success",error:"pf-m-error",dynamic:"pf-m-dynamic"},themeDark:"pf-theme-dark"},y=t=>{var{children:c,className:s,component:o="div",id:r,isLiveRegion:l=!1}=t,n=_(t,["children","className","component","id","isLiveRegion"]);const d=o;return i.createElement(d,Object.assign({id:r,className:x(m.helperText,s)},l&&{"aria-live":"polite"},n),c)};y.displayName="HelperText";const V={default:"",indeterminate:m.modifiers.indeterminate,warning:m.modifiers.warning,success:m.modifiers.success,error:m.modifiers.error},k=t=>{var{children:c,className:s,component:o="div",variant:r="default",icon:l,isDynamic:n=!1,hasIcon:d=n,id:a,screenReaderText:u=`${r} status`}=t,f=_(t,["children","className","component","variant","icon","isDynamic","hasIcon","id","screenReaderText"]);const j=o;return i.createElement(j,Object.assign({className:x(m.helperTextItem,V[r],n&&m.modifiers.dynamic,s),id:a},f),l&&i.createElement("span",{className:x(m.helperTextItemIcon),"aria-hidden":!0},l),d&&!l&&i.createElement("span",{className:x(m.helperTextItemIcon),"aria-hidden":!0},(r==="default"||r==="indeterminate")&&i.createElement(G,null),r==="warning"&&i.createElement(A,null),r==="success"&&i.createElement(R,null),r==="error"&&i.createElement(q,null)),i.createElement("span",{className:x(m.helperTextItemText)},c,n&&i.createElement("span",{className:"pf-u-screen-reader"},": ",u,";")))};k.displayName="HelperTextItem";const Q=({selectItems:t,...c})=>{const{t:s}=I("common"),[o,r]=M(),{field:l}=b(c),[n,d]=i.useState(!t.map(({key:a})=>a).includes(l.value));return e.jsxs($,{children:[e.jsx(h,{lg:n?2:12,children:e.jsx(w,{onToggle:()=>r(),isOpen:o,onSelect:(a,u)=>{u&&d(!1),l.onChange(u),r()},selections:n?"":[l.value],children:[e.jsx(g,{onClick:()=>d(!0),children:s("customAttribute")},"custom"),...t.map(a=>e.jsx(g,{value:a.key,children:a.label},a.key))]})}),n&&e.jsx(h,{lg:10,children:e.jsx(S,{id:"customValue","data-testid":c.name,placeholder:s("keyPlaceholder"),value:l.value,onChange:l.onChange,autoFocus:!0})})]})},U=({selectItems:t,keyValue:c,...s})=>{const{t:o}=I(),{field:r}=b(s),[l,n]=i.useState(!1),d=i.useMemo(()=>t.find(a=>a.key===c),[t,c]);return d?.values?e.jsx(w,{onToggle:a=>n(a),isOpen:l,onSelect:(a,u)=>{r.onChange(u),n(!1)},selections:r.value?[r.value]:o("choose"),placeholder:o("valuePlaceholder"),children:d.values.map(a=>e.jsx(g,{value:a},a))}):e.jsx(S,{id:"customValue","data-testid":s.name,...r})},ae=({name:t,defaultKeyValue:c})=>{const{t:s}=I("common"),{control:o,register:r,formState:{errors:l}}=O(),{fields:n,append:d,remove:a}=P({shouldUnregister:!0,control:o,name:t}),u=()=>d({key:"",value:""}),f=F({name:t,control:o,defaultValue:[]});return n.length>0?e.jsxs(e.Fragment,{children:[e.jsxs($,{hasGutter:!0,children:[e.jsx(h,{className:"pf-c-form__label",span:5,children:e.jsx("span",{className:"pf-c-form__label-text",children:s("key")})}),e.jsx(h,{className:"pf-c-form__label",span:7,children:e.jsx("span",{className:"pf-c-form__label-text",children:s("value")})}),n.map((j,p)=>{const T=!!l[t]?.[p]?.key,E=!!l[t]?.[p]?.value;return e.jsxs(i.Fragment,{children:[e.jsxs(h,{span:5,children:[c?e.jsx(Q,{name:`${t}.${p}.key`,selectItems:c,rules:{required:!0}}):e.jsx(N,{placeholder:s("keyPlaceholder"),"aria-label":s("key"),"data-testid":`${t}-key`,...r(`${t}.${p}.key`,{required:!0}),validated:T?"error":"default",isRequired:!0}),T&&e.jsx(y,{children:e.jsx(k,{variant:"error",children:s("keyError")})})]}),e.jsxs(h,{span:5,children:[c?e.jsx(U,{name:`${t}.${p}.value`,keyValue:f[p]?.key,selectItems:c,rules:{required:!0}}):e.jsx(N,{placeholder:s("valuePlaceholder"),"aria-label":s("value"),"data-testid":`${t}-value`,...r(`${t}.${p}.value`,{required:!0}),validated:E?"error":"default",isRequired:!0}),E&&e.jsx(y,{children:e.jsx(k,{variant:"error",children:s("valueError")})})]}),e.jsx(h,{span:2,children:e.jsx(v,{variant:"link",title:s("removeAttribute"),onClick:()=>a(p),"data-testid":`${t}-remove`,children:e.jsx(H,{})})})]},j.id)})]}),e.jsx(L,{children:e.jsx(B,{children:e.jsx(v,{"data-testid":`${t}-add-row`,className:"pf-u-px-0 pf-u-mt-sm",variant:"link",icon:e.jsx(C,{}),onClick:u,children:s("addAttribute")})})})]}):e.jsxs(D,{"data-testid":`${t}-empty-state`,className:"pf-u-p-0",variant:"xs",children:[e.jsx(K,{children:s("missingAttributes")}),e.jsx(v,{"data-testid":`${t}-add-row`,variant:"link",icon:e.jsx(C,{}),isSmall:!0,onClick:u,children:s("addAttribute")})]})};export{ae as K};
//# sourceMappingURL=KeyValueInput-597f6e1a.js.map




© 2015 - 2024 Weber Informatics LLC | Privacy Policy