@s_mart/form 10.0.4 → 10.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +3 -3
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -31,7 +31,7 @@ import{useController as _e,useFormContext as Ke}from"react-hook-form";import{Che
|
|
|
31
31
|
background-color: ${({theme:e})=>e.palette.grey[400]};
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
`;import{Tooltip as oo}from"@mui/material";import{LIcon as to}from"@s_mart/core";import{lineInfoCircle as ro}from"@s_mart/solid-icons";import{jsx as oe}from"react/jsx-runtime";var lo=({title:e})=>oe(oo,{title:e,placement:"top",children:oe("div",{style:{width:"fit-content"},children:oe(to,{icon:ro,color:"#757575"})})}),_=lo;import{Fragment as re,jsx as C,jsxs as D}from"react/jsx-runtime";import{createElement as bo}from"react";function Po(e){let{name:o,rules:t,defaultValue:l,shouldUnregister:a,control:f,label:c,required:m,options:h,footer:i,showCreatableButton:V=!0,showEditableButton:p,onEditOption:d,onCreateOption:s,getOptionKey:n,getOptionLabel:S,getOptionAfterLabel:F,multiple:k,info:
|
|
34
|
+
`;import{Tooltip as oo}from"@mui/material";import{LIcon as to}from"@s_mart/core";import{lineInfoCircle as ro}from"@s_mart/solid-icons";import{jsx as oe}from"react/jsx-runtime";var lo=({title:e})=>oe(oo,{title:e,placement:"top",children:oe("div",{style:{width:"fit-content"},children:oe(to,{icon:ro,color:"#757575"})})}),_=lo;import{Fragment as re,jsx as C,jsxs as D}from"react/jsx-runtime";import{createElement as bo}from"react";function Po(e){let{name:o,rules:t,defaultValue:l,shouldUnregister:a,control:f,label:c,required:m,options:h,footer:i,showCreatableButton:V=!0,showEditableButton:p,onEditOption:d,onCreateOption:s,getOptionKey:n,getOptionLabel:S,getOptionAfterLabel:F,multiple:k,info:I,noOptionsText:O="Nenhuma op\xE7\xE3o encontrada",onChange:$,onInputChange:M,placeholder:z,...y}=e,[N,R]=no(""),u=so()?.control,r=f??u;if(!r)throw new P("CreatableV2");let b=po({control:r,name:o}),E=L(b.errors,o),K=!V||y.disabled,{field:U}=ao({name:o,control:r,rules:t,defaultValue:l,shouldUnregister:a}),Ee=T=>{let g=0;return e.slotProps?.textField?.slotProps?.input||(g+=2.5),K||(g+=2.56,pe(T)&&(g+=2.56)),!y.disableClearable&&!y.disabled&&(g+=1.3),`${g}rem`},pe=T=>y.disabled?!1:p&&mo(T)&&!uo(T),Le=()=>y.disabled?!1:V,de=X(()=>{typeof s<"u"&&(s(N),R(""))},[N,s]),we=X(()=>{d?.(U.value)},[U.value,d]),Re=X((T,g,W)=>{W==="input"&&(R(g),M?.(g))},[M]),Be=X((T,g)=>{R(""),U.onChange(g),$?.(g)},[U.onChange,$]),Me=X(T=>{y?.onBlur?.(T),R("")},[y?.onBlur]),De=U.value?U.value:k?[]:null;return D("div",{style:{display:"flex",flexDirection:"column"},children:[D("div",{style:{display:"flex"},children:[c&&C(x,{label:c,required:m}),I&&C(_,{title:I})]}),C(ce,{children:C(co,{fullWidth:!0,onChange:Be,onInputChange:Re,onBlur:Me,slotProps:{...y.slotProps,listbox:{component:io(function(g,W){return D(re,{children:[C("ul",{...g,ref:W}),typeof i<"u"?D("div",{...g,children:[C("div",{style:{paddingTop:"0.5rem",paddingBottom:"0.5rem"},children:C(Fe,{})}),i()]},"creatable-footer"):null]})})}},value:De,options:h,multiple:k,readOnly:y.disabled,noOptionsText:D(re,{children:[O,!K&&D(yo,{sx:{justifyContent:"flex-start",padding:`${Pe(6)} ${Pe(-16)}`,margin:0},fullWidth:!0,onClick:de,variant:"text",startIcon:C(te,{icon:xe}),children:["Adicionar ",`"${N}"`]}),typeof i<"u"&&D(re,{children:[C("div",{style:{paddingTop:"0.5rem",paddingBottom:"0.5rem"},children:C(Fe,{})}),i()]})]}),isOptionEqualToValue:(T,g)=>fo(T,g),getOptionLabel:S,getOptionKey:n,renderOption:typeof F=="function"?(T,g)=>{let W=F(g),Ae=n(g);return bo("li",{...T,key:Ae},D("div",{style:{display:"flex",flexDirection:"column",flex:1},children:[C("span",{children:S(g)}),typeof W=="string"?C("span",{children:W}):W]}))}:void 0,...y,sx:{"& div.MuiInputBase-root":{paddingRight:`${Ee(U.value)} !important`},...y.sx},renderInput:T=>C(Fo,{placeholder:z,...T,error:!!E,...e.slotProps?.textField,slotProps:{input:{...T.InputProps,...e.slotProps?.textField?.slotProps?.input,inputRef:U.ref,endAdornment:D("div",{className:"endAdornments",children:[T.InputProps.endAdornment,e.slotProps?.textField?.slotProps?.input?.endAdornment??null,pe(U.value)?D("div",{className:"editable",children:[C("div",{className:"divider"}),C(ye,{size:"small",onClick:we,sx:{mx:"3px"},tabIndex:-1,children:C(te,{icon:xo,size:"24px",removeMargin:!0})})]}):null,Le()&&D("div",{className:"creatable",children:[C("div",{className:"divider"}),C(ye,{size:"small",onClick:de,sx:{mx:"3px"},tabIndex:-1,children:C(te,{icon:xe,size:"24px",removeMargin:!0})})]})]})}}})},o)}),C(v,{name:o,control:r})]})}var ho=w(Po);import{Stack as So}from"@mui/material";import{AdapterDayjs as Io}from"@mui/x-date-pickers/AdapterDayjs";import{DatePicker as To}from"@mui/x-date-pickers";import{LocalizationProvider as ko}from"@mui/x-date-pickers/LocalizationProvider";import{ptBR as Eo}from"@mui/x-date-pickers/locales";import{composeValidators as Lo,date as be}from"@s_mart/rules";import{useController as wo,useFormContext as Ro,useFormState as Bo}from"react-hook-form";import{IconButton as go,styled as vo}from"@mui/material";import{toRem as q}from"@s_mart/utils";var Co=e=>{switch(e){case"small":return q(16);case"large":return q(24);default:return q(20)}},Vo=e=>{switch(e){case"small":return`${q(2)} ${q(8)}`;case"large":return`${q(10)}`;default:return`${q(6)} ${q(8)}`}},he=vo(go)`
|
|
35
35
|
margin: 0px;
|
|
36
36
|
|
|
37
37
|
padding: ${({size:e})=>Vo(e)};
|
|
@@ -40,7 +40,7 @@ import{useController as _e,useFormContext as Ke}from"react-hook-form";import{Che
|
|
|
40
40
|
svg {
|
|
41
41
|
width: ${({size:e})=>Co(e)} !important;
|
|
42
42
|
}
|
|
43
|
-
`;import"dayjs/locale/pt-br";import{jsx as le,jsxs as Oo}from"react/jsx-runtime";import{createElement as Ao}from"react";var Mo=({rules:e,name:o,defaultValue:t,shouldUnregister:l,control:a,label:f,required:c,disabled:m,disableIconError:h,...i})=>{let V=Ro()?.control,p=a??V;if(!p)throw new P("DatePicker");let d=Bo({control:p,name:o}),s=L(d.errors,o),n=i?.format||"DD/MM/YYYY",S=e?Lo([be(n),e]):be(n),{field:F}=wo({control:p,name:o,rules:S,defaultValue:t,shouldUnregister:l});return le(ko,{dateAdapter:To,localeText:Eo.components.MuiLocalizationProvider.defaultProps.localeText,children:Oo(So,{children:[f&&le(x,{label:f,required:c}),Ao(Io,{...i,key:o,value:F.value??null,format:n,onChange:(k,T)=>{F.onChange(k,T),i?.onChange?.(k,T)},disabled:m,enableAccessibleFieldDOMStructure:!1,slots:{openPickerButton:he},slotProps:{...i?.slotProps,textField:{error:!!s,...i.slotProps?.textField,inputRef:F.ref}}}),le(v,{name:o,disableIcon:h,control:p})]})})},Do=w(Mo);import{FormProvider as $o}from"react-hook-form";import{jsx as ge}from"react/jsx-runtime";function zo({children:e,style:o,onSubmit:t,...l}){return ge($o,{...l,children:ge("form",{onSubmit:a=>{a.preventDefault(),a.stopPropagation(),t(a)},style:o,children:e})})}var ie=zo;import{useEffect as qo}from"react";import{useForm as Ho}from"react-hook-form";import{zodResolver as Go}from"@hookform/resolvers/zod";var No=({disableDefaultValuesUpdate:e,onSubmit:o,...t})=>{let l=Ho({...t,resolver:t.schema&&Go(t.schema)});return qo(()=>{e||l.reset(t.defaultValues)},[t.defaultValues,l.reset]),{...l,onSubmit:l.handleSubmit(a=>o(a,l))}},ne=No;import{jsx as Ko}from"react/jsx-runtime";function Uo({children:e,style:o,...t}){let l=ne(t);return Ko(ie,{...l,style:o,children:typeof e=="function"?e(l):e})}var _o=Uo;import{RadioGroup as Wo,Stack as Yo}from"@mui/material";import{useController as Jo,useFormContext as Xo}from"react-hook-form";import{jsx as ae,jsxs as jo}from"react/jsx-runtime";var Qo=({name:e,rules:o,defaultValue:t,shouldUnregister:l,control:a,label:f,required:c,children:m,orientation:h="row",disableIconError:i,...V})=>{let p=Xo()?.control,d=a??p;if(!d)throw new P("RadioGroup");let{field:s}=Jo({control:d,name:e,rules:o,defaultValue:t,shouldUnregister:l});return jo(Yo,{children:[f&&ae(x,{label:f,required:c}),ae(Wo,{value:s.value||"",name:e,...V,onChange:n=>{V?.onChange?.(n,n.target?.value),s.onChange(n)},style:{display:"flex",flexDirection:h},children:m},e),ae(v,{name:e,disableIcon:i,control:d})]})},Zo=Qo;import{FormControlLabel as et,Grid as ot,Radio as tt}from"@mui/material";import{jsx as Z}from"react/jsx-runtime";var rt=({label:e,labelPlacement:o,...t})=>Z(ot,{sx:{display:"flex",flexDirection:"column"},children:Z(et,{control:Z(tt,{...t}),label:Z(x,{label:e}),labelPlacement:o||"end"})}),lt=rt;import{Autocomplete as it,Divider as ve,TextField as nt}from"@mui/material";import at from"lodash-es/isEqual";import{forwardRef as st}from"react";import{useController as pt,useFormContext as dt,useFormState as mt}from"react-hook-form";import{Fragment as se,jsx as B,jsxs as Y}from"react/jsx-runtime";import{createElement as ct}from"react";var ut=e=>{let{name:o,rules:t,defaultValue:l,shouldUnregister:a,control:f,label:c,required:m,options:h,textFieldProps:i,noOptionsText:V,footer:p,multiple:d,info:s,placeholder:n,onChange:S,onInputChange:F,getOptionAfterLabel:k,getOptionLabel:T,getOptionKey:O,...$}=e,M=dt()?.control,z=f??M;if(!z)throw new P("SearchableV2");let y=mt({control:z,name:o}),N=L(y.errors,o),{field:R}=pt({name:o,control:z,rules:t,defaultValue:l,shouldUnregister:a}),u=R.value?R.value:d?[]:null;return Y("div",{style:{display:"flex",flexDirection:"column"},children:[Y("div",{style:{display:"flex"},children:[c&&B(x,{label:c,required:m}),s&&B(_,{title:s})]}),B(it,{onChange:(r,b)=>{R.onChange(b),S?.(b)},onInputChange:(r,b,E)=>{E==="input"&&F?.(b)},value:u,options:h,multiple:d,readOnly:$.disabled,slotProps:{...$.slotProps,listbox:{component:st(function(b,E){return Y(se,{children:[B("ul",{...b,ref:E}),typeof p<"u"?Y("div",{...b,children:[B("div",{style:{paddingTop:"0.5rem",paddingBottom:"0.5rem"},children:B(ve,{})}),p()]},"searchable-footer"):null]})})}},noOptionsText:Y(se,{children:[V||"Nenhuma op\xE7\xE3o encontrada",typeof p<"u"?Y(se,{children:[B("div",{style:{paddingTop:"0.5rem",paddingBottom:"0.5rem"},children:B(ve,{})}),p()]}):null]}),isOptionEqualToValue:(r,b)=>at(r,b),getOptionLabel:T,getOptionKey:O,renderOption:typeof k=="function"?(r,b)=>{let E=k(b),K=O(b);return ct("li",{...r,key:K},Y("div",{style:{display:"flex",flexDirection:"column",flex:1},children:[B("span",{children:T(b)}),typeof E=="string"?B("span",{children:E}):E]}))}:void 0,...$,renderInput:r=>B(nt,{error:!!N,placeholder:n,...r,...i,inputRef:R.ref})},o),B(v,{name:o,control:z})]})},ft=w(ut);import{useState as xt}from"react";import{useController as Pt,useFormContext as ht,useFormState as bt}from"react-hook-form";import{IconButton as gt,LIcon as vt}from"@s_mart/core";import{lineTimes as Ct}from"@s_mart/regular-icons";import{colorPalette as Vt}from"@s_mart/tokens";import{Select as St,MenuItem as Tt,Divider as It}from"@mui/material";import{colorPalette as Ft}from"@s_mart/tokens";import{jsx as yt}from"react/jsx-runtime";var Ce=({value:e,placeholder:o,getOptionLabel:t})=>e===null||e?.length===0?yt("p",{style:{color:Ft.neutral[100]},children:o}):t(e);import{Fragment as Lt,jsx as A,jsxs as J}from"react/jsx-runtime";var kt=e=>{let{name:o,rules:t,defaultValue:l,shouldUnregister:a,control:f,label:c,required:m,options:h,placeholder:i,clearable:V,info:p,footer:d,onChange:s,variant:n="outlined",getOptionKey:S,getOptionLabel:F,getOptionAfterLabel:k,getOptionIcon:T,...O}=e,$=ht()?.control,M=f??$,[z,y]=xt(!1);if(!M)throw new P("SelectV2");let N=bt({control:M,name:o}),R=L(N.errors,o),{field:u}=Pt({control:M,name:o,rules:t,defaultValue:l,shouldUnregister:a});return J("div",{style:{display:"flex",flexDirection:"column"},children:[J("div",{style:{display:"flex"},children:[c&&A(x,{label:c,required:m}),p&&A(_,{title:p})]}),J(St,{open:z,onOpen:()=>y(!0),onClose:()=>y(!1),displayEmpty:!!i,variant:n,autoComplete:"off",value:u.value||null,renderValue:r=>A(Ce,{getOptionLabel:F,placeholder:i,value:r}),onChange:r=>{u.onChange(r.target.value),s?.(r.target.value)},error:!!R,size:O.size||"medium",inputRef:u.ref,...O,endAdornment:J(Lt,{children:[O.endAdornment,!!(V&&u.value)&&A(gt,{variant:"text",color:"neutral",size:"small",sx:{borderRadius:"50%",position:"absolute",right:"2rem"},style:{padding:0},"aria-label":"Limpar",title:"Limpar",onClick:()=>{u.onChange(null),s?.(null)},children:A(vt,{icon:Ct,color:Vt.neutral[100],size:"25px",removeMargin:!0})})]}),children:[h.map(r=>{let b=S(r),E=F(r),K=T?.(r);return A(Tt,{value:r,children:J("div",{style:{display:"flex",flexDirection:"column",flex:1},children:[K!==void 0?J("div",{style:{display:"flex",alignItems:"center"},children:[K,E]}):E,A("span",{children:k?.(r)??null})]})},b)}),d!==void 0&&J("div",{children:[A("div",{style:{padding:"8px 16px"},children:A(It,{})},"footer-divider"),A("div",{children:d({closeSelect:()=>y(!1)})},"footer-content")]},"footer")]},o),A(v,{name:o,control:M})]})},Et=w(kt);import{useController as wt,useFormContext as Rt}from"react-hook-form";import{Slider as Bt}from"@mui/material";import{jsx as At}from"react/jsx-runtime";var Mt=({name:e,rules:o,defaultValue:t,shouldUnregister:l,control:a,...f})=>{let c=Rt()?.control,m=a??c;if(!m)throw new P("Slider");let{field:h}=wt({control:m,name:e,rules:o,defaultValue:t,shouldUnregister:l});return At(Bt,{value:h.value||f?.min||0,onChange:h.onChange,valueLabelDisplay:"auto",...f},e)},Dt=Mt;import{FormControlLabel as Ot,Stack as $t,Switch as zt}from"@mui/material";import{useController as qt,useFormContext as Ht}from"react-hook-form";import{useCallback as Gt}from"react";import{jsx as j,jsxs as _t}from"react/jsx-runtime";var Nt=({name:e,rules:o,defaultValue:t,defaultChecked:l,shouldUnregister:a,control:f,label:c,labelPlacement:m="end",disableIconError:h,onChange:i,...V})=>{let p=Ht()?.control,d=f??p;if(!d)throw new P("Switch");let{field:s}=qt({control:d,name:e,rules:o,defaultValue:l??t??!1,shouldUnregister:a}),n=Gt((S,F)=>{s.onChange(F),i?.(S,F)},[s,i]);return _t($t,{children:[j(Ot,{control:j(zt,{...V,...s,checked:!!s.value,onChange:n}),label:j(x,{label:c}),labelPlacement:m}),j(v,{name:e,disableIcon:h,control:d})]})},Ut=Nt;import{InputAdornment as Kt,Stack as Wt,TextField as Yt,Tooltip as Jt}from"@mui/material";import{LIcon as Ve}from"@s_mart/core";import*as Se from"@s_mart/masks";import{lineEye as Xt,lineEyeSlash as Qt,lineInfoCircle as Zt}from"@s_mart/solid-icons";import{useRef as jt,useState as er}from"react";import{useController as or,useFormContext as tr,useFormState as rr}from"react-hook-form";import{jsx as H,jsxs as Te}from"react/jsx-runtime";var lr=({name:e,rules:o,defaultValue:t,shouldUnregister:l,control:a,label:f,required:c,mask:m,variant:h="outlined",info:i,parse:V,format:p,onInputChange:d,disableIconError:s,...n})=>{let S=tr()?.control,F=a??S,k=jt(t||void 0);if(!F)throw new P("TextField");let[T,O]=er(!1),$=u=>{let r=u;return r=p?.(u)??u,m?Se?.[m]?.format(r):r},M=u=>{let r=u;return r=V?.(u)??r,m?Se?.[m]?.parse(r,k.current):r},z=u=>{if(!u||m!=="porcentagem"&&m!=="porcentagem0")return;u?.stopPropagation();let r=(u?.target).value;if(r){let b=String(r);if(b.length>0){let E=b.indexOf("%");E>-1&&(u.currentTarget.selectionEnd=E)}}},{field:y}=or({control:F,name:e,rules:o,defaultValue:t,shouldUnregister:l}),N=rr({control:F,name:e}),R=L(N.errors,e);return Te(Wt,{children:[Te("div",{style:{display:"flex"},children:[f&&H("div",{children:H(x,{label:f,required:c})}),i&&H("div",{children:H(Jt,{title:i,placement:"top",children:H("div",{style:{width:"fit-content"},children:H(Ve,{icon:Zt,color:"#757575"})})})})]}),H(Yt,{variant:h,defaultValue:t,value:$(y.value||(y.value!=0?"":y.value)),onChange:u=>{let r=M(u?.target?.value);y.onChange(r),d?.(r),k.current=u.target.value},error:!!R,...n,type:n.type==="password"?T?"text":"password":n.type,autoComplete:n.autoComplete||"off",slotProps:{...n.slotProps,input:{onKeyDown:z,inputRef:y.ref,endAdornment:n.type==="password"&&H(Kt,{position:"start",onClick:()=>O(!T),style:{cursor:"pointer"},children:H(Ve,{icon:T?Xt:Qt,size:"24px",removeMargin:!0})}),...n.slotProps?.input}}},e),H(v,{name:e,disableIcon:s,control:F})]})},ir=w(lr);import{Stack as dr}from"@mui/material";import{AdapterDayjs as mr}from"@mui/x-date-pickers/AdapterDayjs";import{LocalizationProvider as ur}from"@mui/x-date-pickers/LocalizationProvider";import{TimePicker as fr}from"@mui/x-date-pickers/TimePicker";import{composeValidators as cr,time as ke}from"@s_mart/rules";import{useController as Fr,useFormContext as yr,useFormState as xr}from"react-hook-form";import{styled as nr}from"@mui/material";import{IconButton as ar}from"@mui/material";import{toRem as G}from"@s_mart/utils";var sr=e=>{switch(e){case"small":return G(16);case"large":return G(24);default:return G(20)}},pr=e=>{switch(e){case"small":return`${G(2)} ${G(8)}`;case"large":return G(10);default:return`${G(6)} ${G(8)}`}},Ie=nr(ar)`
|
|
43
|
+
`;import"dayjs/locale/pt-br";import{jsx as le,jsxs as Oo}from"react/jsx-runtime";import{createElement as Ao}from"react";var Mo=({rules:e,name:o,defaultValue:t,shouldUnregister:l,control:a,label:f,required:c,disabled:m,disableIconError:h,...i})=>{let V=Ro()?.control,p=a??V;if(!p)throw new P("DatePicker");let d=Bo({control:p,name:o}),s=L(d.errors,o),n=i?.format||"DD/MM/YYYY",S=e?Lo([be(n),e]):be(n),{field:F}=wo({control:p,name:o,rules:S,defaultValue:t,shouldUnregister:l});return le(ko,{dateAdapter:Io,localeText:Eo.components.MuiLocalizationProvider.defaultProps.localeText,children:Oo(So,{children:[f&&le(x,{label:f,required:c}),Ao(To,{...i,key:o,value:F.value??null,format:n,onChange:(k,I)=>{F.onChange(k,I),i?.onChange?.(k,I)},disabled:m,enableAccessibleFieldDOMStructure:!1,slots:{openPickerButton:he},slotProps:{...i?.slotProps,textField:{error:!!s,...i.slotProps?.textField,inputRef:F.ref}}}),le(v,{name:o,disableIcon:h,control:p})]})})},Do=w(Mo);import{FormProvider as $o}from"react-hook-form";import{jsx as ge}from"react/jsx-runtime";function zo({children:e,style:o,onSubmit:t,...l}){return ge($o,{...l,children:ge("form",{onSubmit:a=>{a.preventDefault(),a.stopPropagation(),t(a)},style:o,children:e})})}var ie=zo;import{useEffect as qo}from"react";import{useForm as Ho}from"react-hook-form";import{zodResolver as Go}from"@hookform/resolvers/zod";var No=({disableDefaultValuesUpdate:e,onSubmit:o,...t})=>{let l=Ho({...t,resolver:t.schema&&Go(t.schema)});return qo(()=>{e||l.reset(t.defaultValues)},[t.defaultValues,l.reset]),{...l,onSubmit:l.handleSubmit(a=>o(a,l))}},ne=No;import{jsx as Ko}from"react/jsx-runtime";function Uo({children:e,style:o,...t}){let l=ne(t);return Ko(ie,{...l,style:o,children:typeof e=="function"?e(l):e})}var _o=Uo;import{RadioGroup as Wo,Stack as Yo}from"@mui/material";import{useController as Jo,useFormContext as Xo}from"react-hook-form";import{jsx as ae,jsxs as jo}from"react/jsx-runtime";var Qo=({name:e,rules:o,defaultValue:t,shouldUnregister:l,control:a,label:f,required:c,children:m,orientation:h="row",disableIconError:i,...V})=>{let p=Xo()?.control,d=a??p;if(!d)throw new P("RadioGroup");let{field:s}=Jo({control:d,name:e,rules:o,defaultValue:t,shouldUnregister:l});return jo(Yo,{children:[f&&ae(x,{label:f,required:c}),ae(Wo,{value:s.value||"",name:e,...V,onChange:n=>{V?.onChange?.(n,n.target?.value),s.onChange(n)},style:{display:"flex",flexDirection:h},children:m},e),ae(v,{name:e,disableIcon:i,control:d})]})},Zo=Qo;import{FormControlLabel as et,Grid as ot,Radio as tt}from"@mui/material";import{jsx as Z}from"react/jsx-runtime";var rt=({label:e,labelPlacement:o,...t})=>Z(ot,{sx:{display:"flex",flexDirection:"column"},children:Z(et,{control:Z(tt,{...t}),label:Z(x,{label:e}),labelPlacement:o||"end"})}),lt=rt;import{Autocomplete as it,Divider as ve,TextField as nt}from"@mui/material";import at from"lodash-es/isEqual";import{forwardRef as st}from"react";import{useController as pt,useFormContext as dt,useFormState as mt}from"react-hook-form";import{Fragment as se,jsx as B,jsxs as Y}from"react/jsx-runtime";import{createElement as ct}from"react";var ut=e=>{let{name:o,rules:t,defaultValue:l,shouldUnregister:a,control:f,label:c,required:m,options:h,textFieldProps:i,noOptionsText:V,footer:p,multiple:d,info:s,placeholder:n,onChange:S,onInputChange:F,getOptionAfterLabel:k,getOptionLabel:I,getOptionKey:O,...$}=e,M=dt()?.control,z=f??M;if(!z)throw new P("SearchableV2");let y=mt({control:z,name:o}),N=L(y.errors,o),{field:R}=pt({name:o,control:z,rules:t,defaultValue:l,shouldUnregister:a}),u=R.value?R.value:d?[]:null;return Y("div",{style:{display:"flex",flexDirection:"column"},children:[Y("div",{style:{display:"flex"},children:[c&&B(x,{label:c,required:m}),s&&B(_,{title:s})]}),B(it,{onChange:(r,b)=>{R.onChange(b),S?.(b)},onInputChange:(r,b,E)=>{E==="input"&&F?.(b)},value:u,options:h,multiple:d,readOnly:$.disabled,slotProps:{...$.slotProps,listbox:{component:st(function(b,E){return Y(se,{children:[B("ul",{...b,ref:E}),typeof p<"u"?Y("div",{...b,children:[B("div",{style:{paddingTop:"0.5rem",paddingBottom:"0.5rem"},children:B(ve,{})}),p()]},"searchable-footer"):null]})})}},noOptionsText:Y(se,{children:[V||"Nenhuma op\xE7\xE3o encontrada",typeof p<"u"?Y(se,{children:[B("div",{style:{paddingTop:"0.5rem",paddingBottom:"0.5rem"},children:B(ve,{})}),p()]}):null]}),isOptionEqualToValue:(r,b)=>at(r,b),getOptionLabel:I,getOptionKey:O,renderOption:typeof k=="function"?(r,b)=>{let E=k(b),K=O(b);return ct("li",{...r,key:K},Y("div",{style:{display:"flex",flexDirection:"column",flex:1},children:[B("span",{children:I(b)}),typeof E=="string"?B("span",{children:E}):E]}))}:void 0,...$,renderInput:r=>B(nt,{error:!!N,placeholder:n,...r,...i,inputRef:R.ref})},o),B(v,{name:o,control:z})]})},ft=w(ut);import{useState as xt}from"react";import{useController as Pt,useFormContext as ht,useFormState as bt}from"react-hook-form";import{IconButton as gt,LIcon as vt}from"@s_mart/core";import{lineTimes as Ct}from"@s_mart/regular-icons";import{colorPalette as Vt}from"@s_mart/tokens";import{Select as St,MenuItem as It,Divider as Tt}from"@mui/material";import{colorPalette as Ft}from"@s_mart/tokens";import{jsx as yt}from"react/jsx-runtime";var Ce=({value:e,placeholder:o,getOptionLabel:t})=>e===null||e?.length===0?yt("p",{style:{color:Ft.neutral[100]},children:o}):t(e);import{Fragment as Lt,jsx as A,jsxs as J}from"react/jsx-runtime";var kt=e=>{let{name:o,rules:t,defaultValue:l,shouldUnregister:a,control:f,label:c,required:m,options:h,placeholder:i,clearable:V,info:p,footer:d,onChange:s,variant:n="outlined",getOptionKey:S,getOptionLabel:F,getOptionAfterLabel:k,getOptionIcon:I,...O}=e,$=ht()?.control,M=f??$,[z,y]=xt(!1);if(!M)throw new P("SelectV2");let N=bt({control:M,name:o}),R=L(N.errors,o),{field:u}=Pt({control:M,name:o,rules:t,defaultValue:l,shouldUnregister:a});return J("div",{style:{display:"flex",flexDirection:"column"},children:[J("div",{style:{display:"flex"},children:[c&&A(x,{label:c,required:m}),p&&A(_,{title:p})]}),J(St,{open:z,onOpen:()=>y(!0),onClose:()=>y(!1),displayEmpty:!!i,variant:n,autoComplete:"off",value:u.value||null,renderValue:r=>A(Ce,{getOptionLabel:F,placeholder:i,value:r}),onChange:r=>{u.onChange(r.target.value),s?.(r.target.value)},error:!!R,size:O.size||"medium",inputRef:u.ref,...O,endAdornment:J(Lt,{children:[O.endAdornment,!!(V&&u.value)&&A(gt,{variant:"text",color:"neutral",size:"small",sx:{borderRadius:"50%",position:"absolute",right:"2rem"},style:{padding:0},"aria-label":"Limpar",title:"Limpar",onClick:()=>{u.onChange(null),s?.(null)},children:A(vt,{icon:Ct,color:Vt.neutral[100],size:"25px",removeMargin:!0})})]}),children:[h.map(r=>{let b=S(r),E=F(r),K=I?.(r);return A(It,{value:r,children:J("div",{style:{display:"flex",flexDirection:"column",flex:1},children:[K!==void 0?J("div",{style:{display:"flex",alignItems:"center"},children:[K,E]}):E,A("span",{children:k?.(r)??null})]})},b)}),d!==void 0&&J("div",{children:[A("div",{style:{padding:"8px 16px"},children:A(Tt,{})},"footer-divider"),A("div",{children:d({closeSelect:()=>y(!1)})},"footer-content")]},"footer")]},o),A(v,{name:o,control:M})]})},Et=w(kt);import{useController as wt,useFormContext as Rt}from"react-hook-form";import{Slider as Bt}from"@mui/material";import{jsx as At}from"react/jsx-runtime";var Mt=({name:e,rules:o,defaultValue:t,shouldUnregister:l,control:a,...f})=>{let c=Rt()?.control,m=a??c;if(!m)throw new P("Slider");let{field:h}=wt({control:m,name:e,rules:o,defaultValue:t,shouldUnregister:l});return At(Bt,{value:h.value||f?.min||0,onChange:h.onChange,valueLabelDisplay:"auto",...f},e)},Dt=Mt;import{FormControlLabel as Ot,Stack as $t,Switch as zt}from"@mui/material";import{useController as qt,useFormContext as Ht}from"react-hook-form";import{useCallback as Gt}from"react";import{jsx as j,jsxs as _t}from"react/jsx-runtime";var Nt=({name:e,rules:o,defaultValue:t,defaultChecked:l,shouldUnregister:a,control:f,label:c,labelPlacement:m="end",disableIconError:h,onChange:i,...V})=>{let p=Ht()?.control,d=f??p;if(!d)throw new P("Switch");let{field:s}=qt({control:d,name:e,rules:o,defaultValue:l??t??!1,shouldUnregister:a}),n=Gt((S,F)=>{s.onChange(F),i?.(S,F)},[s,i]);return _t($t,{children:[j(Ot,{control:j(zt,{...V,...s,checked:!!s.value,onChange:n}),label:j(x,{label:c}),labelPlacement:m}),j(v,{name:e,disableIcon:h,control:d})]})},Ut=Nt;import{InputAdornment as Kt,Stack as Wt,TextField as Yt,Tooltip as Jt}from"@mui/material";import{LIcon as Ve}from"@s_mart/core";import*as Se from"@s_mart/masks";import{lineEye as Xt,lineEyeSlash as Qt,lineInfoCircle as Zt}from"@s_mart/solid-icons";import{useRef as jt,useState as er}from"react";import{useController as or,useFormContext as tr,useFormState as rr}from"react-hook-form";import{jsx as H,jsxs as Ie}from"react/jsx-runtime";var lr=({name:e,rules:o,defaultValue:t,shouldUnregister:l,control:a,label:f,required:c,mask:m,variant:h="outlined",info:i,parse:V,format:p,onInputChange:d,disableIconError:s,...n})=>{let S=tr()?.control,F=a??S,k=jt(t||void 0);if(!F)throw new P("TextField");let[I,O]=er(!1),$=u=>{let r=u;return r=p?.(u)??u,m?Se?.[m]?.format(r):r},M=u=>{let r=u;return r=V?.(u)??r,m?Se?.[m]?.parse(r,k.current):r},z=u=>{if(!u||m!=="porcentagem"&&m!=="porcentagem0")return;u?.stopPropagation();let r=(u?.target).value;if(r){let b=String(r);if(b.length>0){let E=b.indexOf("%");E>-1&&(u.currentTarget.selectionEnd=E)}}},{field:y}=or({control:F,name:e,rules:o,defaultValue:t,shouldUnregister:l}),N=rr({control:F,name:e}),R=L(N.errors,e);return Ie(Wt,{children:[Ie("div",{style:{display:"flex"},children:[f&&H("div",{children:H(x,{label:f,required:c})}),i&&H("div",{children:H(Jt,{title:i,placement:"top",children:H("div",{style:{width:"fit-content"},children:H(Ve,{icon:Zt,color:"#757575"})})})})]}),H(Yt,{variant:h,defaultValue:t,value:$(y.value||(y.value!=0?"":y.value)),onChange:u=>{let r=M(u?.target?.value);y.onChange(r),d?.(r),k.current=u.target.value},error:!!R,...n,type:n.type==="password"?I?"text":"password":n.type,autoComplete:n.autoComplete||"off",slotProps:{...n.slotProps,input:{onKeyDown:z,inputRef:y.ref,endAdornment:n.type==="password"&&H(Kt,{position:"start",onClick:()=>O(!I),style:{cursor:"pointer"},children:H(Ve,{icon:I?Xt:Qt,size:"24px",removeMargin:!0})}),...n.slotProps?.input}}},e),H(v,{name:e,disableIcon:s,control:F})]})},ir=w(lr);import{Stack as dr}from"@mui/material";import{AdapterDayjs as mr}from"@mui/x-date-pickers/AdapterDayjs";import{LocalizationProvider as ur}from"@mui/x-date-pickers/LocalizationProvider";import{TimePicker as fr}from"@mui/x-date-pickers/TimePicker";import{composeValidators as cr,time as ke}from"@s_mart/rules";import{useController as Fr,useFormContext as yr,useFormState as xr}from"react-hook-form";import{styled as nr}from"@mui/material";import{IconButton as ar}from"@mui/material";import{toRem as G}from"@s_mart/utils";var sr=e=>{switch(e){case"small":return G(16);case"large":return G(24);default:return G(20)}},pr=e=>{switch(e){case"small":return`${G(2)} ${G(8)}`;case"large":return G(10);default:return`${G(6)} ${G(8)}`}},Te=nr(ar)`
|
|
44
44
|
margin: 0px;
|
|
45
45
|
|
|
46
46
|
padding: ${({size:e})=>pr(e)};
|
|
@@ -49,4 +49,4 @@ import{useController as _e,useFormContext as Ke}from"react-hook-form";import{Che
|
|
|
49
49
|
svg {
|
|
50
50
|
width: ${({size:e})=>sr(e)} !important;
|
|
51
51
|
}
|
|
52
|
-
`;import"dayjs/locale/pt-br";import{jsx as ee,jsxs as br}from"react/jsx-runtime";var Pr=({rules:e,defaultValue:o,shouldUnregister:t,name:l,control:a,required:f,label:c,disabled:m,disableIconError:h,...i})=>{let V=yr()?.control,p=a??V;if(!p)throw new P("TimePicker");let d=xr({control:p,name:l}),s=L(d.errors,l),n=i.format||"HH:mm",S=e?cr([ke(n),e]):ke(n),{field:F}=Fr({control:p,name:l,rules:S,defaultValue:o,shouldUnregister:t});return ee(ur,{dateAdapter:mr,children:br(dr,{children:[c&&ee(x,{label:c,required:f}),ee(fr,{ampm:!1,format:n,value:F.value??null,disabled:m,...i,enableAccessibleFieldDOMStructure:!1,onChange:(k,
|
|
52
|
+
`;import"dayjs/locale/pt-br";import{jsx as ee,jsxs as br}from"react/jsx-runtime";var Pr=({rules:e,defaultValue:o,shouldUnregister:t,name:l,control:a,required:f,label:c,disabled:m,disableIconError:h,...i})=>{let V=yr()?.control,p=a??V;if(!p)throw new P("TimePicker");let d=xr({control:p,name:l}),s=L(d.errors,l),n=i.format||"HH:mm",S=e?cr([ke(n),e]):ke(n),{field:F}=Fr({control:p,name:l,rules:S,defaultValue:o,shouldUnregister:t});return ee(ur,{dateAdapter:mr,children:br(dr,{children:[c&&ee(x,{label:c,required:f}),ee(fr,{ampm:!1,format:n,value:F.value??null,disabled:m,...i,enableAccessibleFieldDOMStructure:!1,onChange:(k,I)=>{F.onChange(k,I),i?.onChange?.(k,I)},slots:{openPickerButton:Te},slotProps:{...i.slotProps,textField:{error:!!s,...i.slotProps?.textField,inputRef:F.ref},actionBar:{actions:[],...i.slotProps?.actionBar}}},l),ee(v,{name:l,disableIcon:h,control:p})]})})},hr=w(Pr);export{Xe as Checkbox,ho as CreatableV2,Do as DatePicker,v as FieldError,_ as FieldInfo,x as FieldLabel,_o as Form,ie as FormProvider,lt as RadioButton,Zo as RadioGroup,ft as SearchableV2,Et as SelectV2,Dt as Slider,Ut as Switch,ir as TextField,hr as TimePicker,ne as useForm};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@s_mart/form",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.6",
|
|
4
4
|
"main": "./dist/index.mjs",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.mts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"react-hook-form": "^7.51.0",
|
|
32
32
|
"typescript": ">=5.4.2",
|
|
33
33
|
"zod": "^3.22.4",
|
|
34
|
-
"@s_mart/core": "10.0.
|
|
34
|
+
"@s_mart/core": "10.0.4",
|
|
35
35
|
"@s_mart/masks": "5.2.0",
|
|
36
36
|
"@s_mart/regular-icons": "6.0.12",
|
|
37
37
|
"@s_mart/rules": "5.1.2",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@types/react-dom": "^18.3.1",
|
|
52
52
|
"dayjs": "^1.11.10",
|
|
53
53
|
"typescript": ">=5.4.2",
|
|
54
|
-
"@s_mart/core": "10.0.
|
|
54
|
+
"@s_mart/core": "10.0.4",
|
|
55
55
|
"@s_mart/masks": "5.2.0",
|
|
56
56
|
"@s_mart/rules": "5.1.2",
|
|
57
57
|
"@s_mart/tokens": "6.0.0",
|