UNPKG

@iqmo/browser

Version:
2 lines (1 loc) 3.05 kB
import{b$ as S,d1 as B,c as L,r as l,bl as P,ao as G,d2 as W,j as s,b_ as $,cg as K,c0 as N,bI as O}from"./index-0xtYjrTa.js";import{u as q}from"./uniqueId-MII1RI5s.js";import{I as J}from"./InputInstructions-D_qxDPd4.js";import{a as Q}from"./useBasicWidgetState-0Cg3lNvA.js";import{u as X,a as Y,b as Z}from"./useUpdateUiValue-FPijrztp.js";import{u as ee,T as te}from"./useTextInputAutoExpand-NUdcCyCX.js";const ie=(t,e)=>{let a="auto";if(t.heightConfig?.useStretch)a="100%";else if(t.heightConfig?.pixelHeight&&t.heightConfig.pixelHeight>0){const r=S(e.labelVisibility?.value)===B.Collapsed?2:30;a=`${t.heightConfig.pixelHeight-r}px`}return a},ae=L("div",{target:"ezh4s2r0"})({name:"kdbhus",styles:"height:100%;display:flex;flex-direction:column"}),I=(t,e)=>t.getStringValue(e)??e.default??null,le=t=>t.default??null,re=t=>t.value??null,oe=(t,e,a,r)=>{e.setStringValue(t,a.value,{fromUi:a.fromUi},r)},se=({disabled:t,element:e,widgetMgr:a,fragmentId:r,outerElement:h})=>{const c=l.useRef(q("text_area_")).current,[v,y]=P(),[o,g]=l.useState(!1),[H,b]=l.useState(!1),d=h.heightConfig?.useContent??!1,T=h.heightConfig?.useStretch??!1,R=ie(h,e),x=l.useRef(null),[n,m]=l.useState(()=>I(a,e)??null),F=l.useCallback(()=>{m(e.default??null),g(!0)},[e]),[j,u]=Q({getStateFromWidgetMgr:I,getDefaultStateFromProto:le,getCurrStateFromProto:re,updateWidgetMgrState:oe,element:e,widgetMgr:a,fragmentId:r,onFormCleared:F});X(j,n,m,o);const i=G(),{height:k,maxHeight:z,updateScrollHeight:C}=ee({textareaRef:x,dependencies:[e.placeholder]}),f=l.useCallback(()=>{g(!1),u({value:n,fromUi:!0})},[n,u]),V=l.useCallback(()=>{o&&f(),b(!1)},[o,f]),w=l.useCallback(()=>{b(!0)},[]),E=l.useCallback(()=>{d&&C()},[d,C]),A=Y({formId:e.formId,maxChars:e.maxChars,setDirty:g,setUiValue:m,setValueWithSource:u,additionalAction:E}),D=Z(e.formId,f,o,a,r,!0),{placeholder:M,formId:p}=e,U=W({formId:p})?a.allowFormEnterToSubmit(p):o,_=H&&v>i.breakpoints.hideWidgetDetails;return s.jsxs(ae,{className:"stTextArea","data-testid":"stTextArea",ref:y,children:[s.jsx($,{label:e.label,disabled:t,labelVisibility:S(e.labelVisibility?.value),htmlFor:c,children:e.help&&s.jsx(K,{children:s.jsx(N,{content:e.help,placement:O.TOP_RIGHT})})}),s.jsx(te,{inputRef:d?x:void 0,value:n??"",placeholder:M,onBlur:V,onFocus:w,onChange:A,onKeyDown:D,"aria-label":e.label,disabled:t,id:c,overrides:{Input:{style:{fontWeight:i.fontWeights.normal,lineHeight:i.lineHeights.inputWidget,height:d?k:R,maxHeight:d?z:"",minHeight:i.sizes.largestElementHeight,resize:T?"none":"vertical",paddingRight:i.spacing.md,paddingLeft:i.spacing.md,paddingBottom:i.spacing.md,paddingTop:i.spacing.md,"::placeholder":{color:i.colors.fadedText60}}},Root:{props:{"data-testid":"stTextAreaRootElement"},style:{borderLeftWidth:i.sizes.borderWidth,borderRightWidth:i.sizes.borderWidth,borderTopWidth:i.sizes.borderWidth,borderBottomWidth:i.sizes.borderWidth,flexGrow:1}}}}),_&&s.jsx(J,{dirty:o,value:n??"",maxLength:e.maxChars,type:"multiline",inForm:W({formId:p}),allowEnterToSubmit:U})]})},de=l.memo(se);export{de as default};