UNPKG

@iqmo/browser

Version:

Browser Stlite

2 lines (1 loc) 2.34 kB
import{r,bO as k,z as w,cZ as x,j as s,bY as D,bZ as E,cb as U,b_ as _,bH as A}from"./index-C9lG8Cnd.js";import{u as B}from"./uniqueId-C4k8y7l3.js";import{u as L,a as M,b as P}from"./useOnInputChange-BSGHLf6n.js";import{I as O}from"./InputInstructions-CqDJXUWS.js";import{a as Z}from"./useBasicWidgetState-C76uodSh.js";import{T as G}from"./textarea-E-XVHBZA.js";const W=(a,e)=>a.getStringValue(e)??e.default??null,K=a=>a.default??null,N=a=>a.value??null,Y=(a,e,i,d)=>{e.setStringValue(a,i.value,{fromUi:i.fromUi},d)},$=({disabled:a,element:e,widgetMgr:i,fragmentId:d})=>{var b;const p=r.useRef(B("text_area_")).current,[S,v]=k(),[l,m]=r.useState(!1),[I,c]=r.useState(!1),[o,n]=r.useState(()=>W(i,e)??null),C=r.useCallback(()=>{n(e.default??null),m(!0)},[e]),[T,u]=Z({getStateFromWidgetMgr:W,getDefaultStateFromProto:K,getCurrStateFromProto:N,updateWidgetMgrState:Y,element:e,widgetMgr:i,fragmentId:d,onFormCleared:C});L(T,o,n,l);const t=w(),g=r.useCallback(()=>{m(!1),u({value:o,fromUi:!0})},[o,u]),y=r.useCallback(()=>{l&&g(),c(!1)},[l,g]),F=r.useCallback(()=>{c(!0)},[]),j=M({formId:e.formId,maxChars:e.maxChars,setDirty:m,setUiValue:n,setValueWithSource:u}),z=P(e.formId,g,l,i,d,!0),{height:f,placeholder:H,formId:h}=e,R=x({formId:h})?i.allowFormEnterToSubmit(h):l,V=I&&S>t.breakpoints.hideWidgetDetails;return s.jsxs("div",{className:"stTextArea","data-testid":"stTextArea",ref:v,children:[s.jsx(D,{label:e.label,disabled:a,labelVisibility:E((b=e.labelVisibility)==null?void 0:b.value),htmlFor:p,children:e.help&&s.jsx(U,{children:s.jsx(_,{content:e.help,placement:A.TOP_RIGHT})})}),s.jsx(G,{value:o??"",placeholder:H,onBlur:y,onFocus:F,onChange:j,onKeyDown:z,"aria-label":e.label,disabled:a,id:p,overrides:{Input:{style:{lineHeight:t.lineHeights.inputWidget,height:f?`${f}px`:"",minHeight:t.sizes.largestElementHeight,resize:"vertical","::placeholder":{opacity:"0.7"},paddingRight:t.spacing.md,paddingLeft:t.spacing.md,paddingBottom:t.spacing.md,paddingTop:t.spacing.md}},Root:{props:{"data-testid":"stTextAreaRootElement"},style:{borderLeftWidth:t.sizes.borderWidth,borderRightWidth:t.sizes.borderWidth,borderTopWidth:t.sizes.borderWidth,borderBottomWidth:t.sizes.borderWidth}}}}),V&&s.jsx(O,{dirty:l,value:o??"",maxLength:e.maxChars,type:"multiline",inForm:x({formId:h}),allowEnterToSubmit:R})]})},q=r.memo($);export{q as default};