@iqmo/browser
Version:
Browser Stlite
2 lines (1 loc) • 2.82 kB
JavaScript
import{c as L,r as i,bl as P,ao as D,d2 as W,j as r,b_ as H,b$ as M,cg as U,c0 as _,bI as B,b8 as O,d3 as A}from"./index-0xtYjrTa.js";import{u as G}from"./uniqueId-MII1RI5s.js";import{I as K}from"./InputInstructions-D_qxDPd4.js";import{a as N}from"./useBasicWidgetState-0Cg3lNvA.js";import{u as $,a as q,b as J}from"./useUpdateUiValue-FPijrztp.js";import{I as Q}from"./input-BTpFoeVg.js";const X=L("div",{target:"e11y4ecf0"})({name:"bjn8wh",styles:"position:relative"});function Y({disabled:a,element:e,widgetMgr:s,fragmentId:d}){const[l,m]=i.useState(()=>S(s,e)??null),[I,y]=P(),[o,c]=i.useState(!1),T=i.useCallback(()=>{m(e.default??null),c(!0)},[e.default]),[C,g]=N({getStateFromWidgetMgr:S,getDefaultStateFromProto:Z,getCurrStateFromProto:ee,updateWidgetMgrState:te,element:e,widgetMgr:s,fragmentId:d,onFormCleared:T});$(C,l,m,o);const[j,h]=i.useState(!1),t=D(),[f]=i.useState(()=>G("text_input_")),{placeholder:v,formId:n,icon:u,maxChars:b}=e,p=i.useCallback(()=>{c(!1),g({value:l,fromUi:!0})},[l,g]),F=W({formId:n})?s.allowFormEnterToSubmit(n):o,z=j&&I>t.breakpoints.hideWidgetDetails,R=i.useCallback(()=>{o&&p(),h(!1)},[o,p]),V=i.useCallback(()=>{h(!0)},[]),w=q({formId:n,maxChars:b,setDirty:c,setUiValue:m,setValueWithSource:g}),E=J(n,p,o,s,d),x=u?.startsWith(":material"),k=x?"lg":"base";return r.jsxs(X,{className:"stTextInput","data-testid":"stTextInput",ref:y,children:[r.jsx(H,{label:e.label,disabled:a,labelVisibility:M(e.labelVisibility?.value),htmlFor:f,children:e.help&&r.jsx(U,{children:r.jsx(_,{content:e.help,placement:B.TOP_RIGHT})})}),r.jsx(Q,{value:l??"",placeholder:v,onBlur:R,onFocus:V,onChange:w,onKeyPress:E,"aria-label":e.label,disabled:a,id:f,type:ae(e),autoComplete:e.autocomplete,startEnhancer:u&&r.jsx(O,{"data-testid":"stTextInputIcon",iconValue:u,size:k}),overrides:{Input:{style:{fontWeight:t.fontWeights.normal,minWidth:0,lineHeight:t.lineHeights.inputWidget,paddingRight:t.spacing.sm,paddingLeft:t.spacing.md,paddingBottom:t.spacing.sm,paddingTop:t.spacing.sm,"::placeholder":{color:t.colors.fadedText60}}},Root:{props:{"data-testid":"stTextInputRootElement"},style:{height:t.sizes.minElementHeight,borderLeftWidth:t.sizes.borderWidth,borderRightWidth:t.sizes.borderWidth,borderTopWidth:t.sizes.borderWidth,borderBottomWidth:t.sizes.borderWidth,paddingLeft:u?t.spacing.sm:0}},StartEnhancer:{style:{paddingLeft:0,paddingRight:0,minWidth:t.iconSizes.lg,color:x?t.colors.fadedText60:"inherit"}}}}),z&&r.jsx(K,{dirty:o,value:l??"",maxLength:b,inForm:W({formId:n}),allowEnterToSubmit:F})]})}function S(a,e){return a.getStringValue(e)??null}function Z(a){return a.default??null}function ee(a){return a.value??null}function te(a,e,s,d){e.setStringValue(a,s.value,{fromUi:s.fromUi},d)}function ae(a){return a.type===A.Type.PASSWORD?"password":"text"}const ie=i.memo(Y);export{ie as default};