@s_mart/form 7.1.0 → 7.1.1
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 +4 -4
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{FormProvider as Oe}from"react-hook-form";import{jsx as Fe}from"react/jsx-runtime";function je({children:e,style:t,onSubmit:n,...i}){return Fe(Oe,{...i,children:Fe("form",{onSubmit:l=>{l.preventDefault(),l.stopPropagation(),n(l)},style:t,children:e})})}var pe=je;import{useEffect as Ne}from"react";import{useForm as He}from"react-hook-form";import{zodResolver as We}from"@hookform/resolvers/zod";var Ye=({disableDefaultValuesUpdate:e,onSubmit:t,...n})=>{let i=He({...n,resolver:n.schema&&We(n.schema)});return Ne(()=>{e||i.reset(n.defaultValues)},[n.defaultValues,i.reset]),{...i,onSubmit:i.handleSubmit(l=>t(l,i))}},me=Ye;import{jsx as Xe}from"react/jsx-runtime";function Je({children:e,style:t,...n}){let i=me(n);return Xe(pe,{...i,style:t,children:typeof e=="function"?e(i):e})}var Ke=Je;import{memo as lo,useState as no}from"react";import{Controller as ao,useFormContext as so}from"react-hook-form";import{Grid as ue,InputAdornment as
|
|
1
|
+
import{FormProvider as Oe}from"react-hook-form";import{jsx as Fe}from"react/jsx-runtime";function je({children:e,style:t,onSubmit:n,...i}){return Fe(Oe,{...i,children:Fe("form",{onSubmit:l=>{l.preventDefault(),l.stopPropagation(),n(l)},style:t,children:e})})}var pe=je;import{useEffect as Ne}from"react";import{useForm as He}from"react-hook-form";import{zodResolver as We}from"@hookform/resolvers/zod";var Ye=({disableDefaultValuesUpdate:e,onSubmit:t,...n})=>{let i=He({...n,resolver:n.schema&&We(n.schema)});return Ne(()=>{e||i.reset(n.defaultValues)},[n.defaultValues,i.reset]),{...i,onSubmit:i.handleSubmit(l=>t(l,i))}},me=Ye;import{jsx as Xe}from"react/jsx-runtime";function Je({children:e,style:t,...n}){let i=me(n);return Xe(pe,{...i,style:t,children:typeof e=="function"?e(i):e})}var Ke=Je;import{memo as lo,useState as no}from"react";import{Controller as ao,useFormContext as so}from"react-hook-form";import{Tooltip as po,Grid as ue,InputAdornment as mo,TextField as uo}from"@mui/material";import{lineEye as fo,lineEyeSlash as co,lineInfoCircle as yo}from"@s_mart/solid-icons";import*as he from"@s_mart/masks";import{Typography as Pe}from"@mui/material";import{toRem as Qe}from"@s_mart/utils";import{jsx as be,jsxs as eo}from"react/jsx-runtime";var Ze=({label:e,required:t,regular:n})=>eo("span",{style:{display:"flex",alignItems:"center",gap:Qe(2)},children:[be(Pe,{variant:"caption",fontWeight:n?400:700,style:{display:"flex",alignItems:"center"},children:e}),t&&be(Pe,{variant:"caption",fontWeight:900,color:"error",children:"*"})]}),C=Ze;import{useFormContext as oo}from"react-hook-form";import{Indicator as ro}from"@s_mart/core";var V=(e,t)=>t.replace(/[[\]]/g,"").split(".").reduce((i,l)=>i?.[l],e);import{jsx as io}from"react/jsx-runtime";var to=({name:e,disableIcon:t})=>{let n=oo(),i=V(n?.formState?.errors,e);return i?io(ro,{severity:"error",icon:t?!1:void 0,children:i?.message}):null},S=to;import{LIcon as ge}from"@s_mart/core";import{jsx as $,jsxs as ve}from"react/jsx-runtime";var xo=({name:e,rules:t,defaultValue:n,shouldUnregister:i,label:l,required:g,mask:x,variant:v="outlined",info:I,parse:u,inputMode:c,format:a,onInputChange:h,disableIconError:f,...F})=>{let P=so();if(!P)throw new Error("Para usar o <TextField /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let[s,b]=no(!1),d=r=>{let o=r;return a&&(o=a(r)),x?he?.[x]?.format(o):o},m=r=>{let o=r;return u&&(o=u(r)),x?he?.[x]?.parse(o):o},G=r=>{if(!r||x!=="porcentagem"&&x!=="porcentagem0")return;r?.stopPropagation();let o=(r?.target).value;if(o){let p=String(o);if(p.length>0){let y=p.indexOf("%");y>-1&&(r.currentTarget.selectionEnd=y)}}},A=V(P.formState.errors,e);return $(ao,{control:P.control,name:e,rules:t,defaultValue:n,shouldUnregister:i,render:({field:{value:r,onChange:o,ref:p}})=>ve(ue,{display:"flex",flexDirection:"column",children:[ve("div",{style:{display:"flex"},children:[l&&$(ue,{item:!0,children:$(C,{label:l,required:g})}),I&&$(ue,{item:!0,children:$(po,{title:I,placement:"top",children:$("div",{style:{width:"fit-content"},children:$(ge,{icon:yo,color:"#757575"})})})})]}),$(uo,{variant:v,defaultValue:n,value:d(r||(r!=0?"":r)),onChange:y=>{let B=m(y?.target?.value);o(B),h?.(B,P.getValues())},error:!!A,...F,type:F.type==="password"?s?"text":"password":F.type,autoComplete:F.autoComplete||"off",inputProps:{inputMode:c,...F.inputProps},InputProps:{onKeyDown:G,inputRef:p,endAdornment:F.type==="password"&&$(mo,{position:"start",onClick:()=>b(!s),style:{cursor:"pointer"},children:$(ge,{icon:s?fo:co,size:"24px",removeMargin:!0})}),...F.InputProps}},e),$(S,{name:e,disableIcon:f})]})})},Fo=lo(xo);import{memo as Po,useState as bo}from"react";import{Controller as ho,useFormContext as go}from"react-hook-form";import{IconButton as vo,LIcon as Ce}from"@s_mart/core";import{lineTimes as Co}from"@s_mart/regular-icons";import{lineInfoCircle as To}from"@s_mart/solid-icons";import{colorPalette as Io}from"@s_mart/tokens";import{Divider as So,Tooltip as ko,Grid as j,Select as wo,MenuItem as Vo,useTheme as Go}from"@mui/material";import{Fragment as Lo,jsx as R,jsxs as X}from"react/jsx-runtime";var Te=Po(({name:e,rules:t,defaultValue:n,shouldUnregister:i,label:l,required:g,options:x,placeholder:v,clearable:I,disableOnChangeForm:u=!1,multiple:c,info:a,footer:h,onChange:f,disableIconError:F,variant:P="outlined",...s})=>{let b=go(),{palette:d}=Go(),[m,G]=bo(!1);if(!b)throw new Error("Para usar o <Select /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let A=V(b.formState.errors,e);return R(ho,{control:b.control,name:e,rules:t,defaultValue:n,shouldUnregister:i,render:({field:{value:r,onChange:o,ref:p}})=>X(j,{display:"flex",flexDirection:"column",children:[X("div",{style:{display:"flex"},children:[l&&R(j,{item:!0,children:R(C,{label:l,required:g})}),a&&R(j,{item:!0,children:R(ko,{title:a,placement:"top",children:R("div",{style:{width:"fit-content"},children:R(Ce,{icon:To,color:"#757575"})})})})]}),X(wo,{open:m,onOpen:()=>G(!0),onClose:()=>G(!1),displayEmpty:!!v,variant:P,autoComplete:"off",value:r?r||"":c?[]:"",renderValue:y=>{if(y.label)return y.label;if(v)return R("p",{style:{color:d.grey[400]},children:v})},multiple:c,onChange:y=>{!u&&o(y.target.value),f&&f(y.target.value,b.getValues())},error:!!A,size:s.size||"medium",inputRef:p,...s,endAdornment:X(Lo,{children:[s.endAdornment,!!(I&&r)&&R(vo,{variant:"text",color:"neutral",size:"small",sx:{borderRadius:"50%",position:"absolute",right:"2rem"},style:{padding:0},"aria-label":"Clear",title:"Clear",onClick:()=>{!u&&o(null),f&&f(null,b.getValues())},children:R(Ce,{icon:Co,color:Io.neutral[100],size:"25px",removeMargin:!0})})]}),children:[x?.map((y,B)=>R(Vo,{value:y,children:X(j,{container:!0,direction:"column",children:[R(j,{item:!0,children:y.label}),y.afterLabel&&R(j,{item:!0,children:y.afterLabel})]})},B)),h&&[R(j,{px:2,py:1,children:R(So,{})},"footer-divider"),R("div",{children:h({closeSelect:()=>G(!1)})},"footer-content")]]},e),R(S,{name:e,disableIcon:F})]})})});Te.displayName="Select";var Eo=Te;import{forwardRef as Ro,memo as Bo}from"react";import{Controller as Do,useFormContext as Ao}from"react-hook-form";import{Tooltip as Mo,Divider as Ie,Grid as U,Autocomplete as $o,TextField as qo}from"@mui/material";import{LIcon as zo}from"@s_mart/core";import{lineInfoCircle as _o}from"@s_mart/solid-icons";import{colorPalette as Uo}from"@s_mart/tokens";import{Fragment as re,jsx as L,jsxs as N}from"react/jsx-runtime";import{createElement as Se}from"react";var ke=Bo(({name:e,rules:t,defaultValue:n,shouldUnregister:i,label:l,required:g,options:x,textFieldProps:v,noOptionsText:I,footer:u,multiple:c,info:a,placeholder:h,onChange:f,onInputChange:F,disableIconError:P,...s})=>{let b=Ao();if(!b)throw new Error("Para usar o <Searchable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let d=V(b.formState.errors,e);return L(Do,{control:b.control,name:e,rules:t,defaultValue:n,shouldUnregister:i,render:({field:{onChange:m,value:G,ref:A}})=>N(U,{display:"flex",flexDirection:"column",children:[N("div",{style:{display:"flex"},children:[l&&L(U,{item:!0,children:L(C,{label:l,required:g})}),a&&L(U,{item:!0,children:L(Mo,{title:a,placement:"top",children:L("div",{style:{width:"fit-content"},children:L(zo,{icon:_o,color:"#757575"})})})})]}),L($o,{onChange:(r,o)=>{m(o),f?.(o,b.getValues())},onInputChange:(r,o,p)=>{p==="input"&&setTimeout(()=>{F?.(o,b.getValues())},0)},slotProps:{...s.slotProps||{},paper:{...(s.slotProps||{}).paper||{},sx:{border:`1px solid ${Uo.neutral[30]}`,boxShadow:"0px 2px 4px rgba(0, 0, 0, 0.15)",...(s.slotProps||{}).paper?.sx||{}}}},value:G||(c?[]:null),options:x,multiple:c,readOnly:s.disabled,noOptionsText:N(re,{children:[I||"Nenhum resultado encontrado",u?N(re,{children:[L(U,{py:1,children:L(Ie,{})}),u]}):null]}),isOptionEqualToValue:(r,o)=>typeof r=="string"&&typeof o=="string"?r===o:typeof r=="object"&&typeof o=="object"?typeof r.value=="object"&&typeof o.value=="object"&&r.key!==void 0&&o.key!==void 0?r.key===o.key:r.value===o.value:!1,renderOption:(r,o)=>typeof o=="object"?Se("li",{...r,key:o.key||o.value},N(U,{container:!0,direction:"column",children:[L(U,{item:!0,children:o.label}),o.afterLabel&&L(U,{item:!0,children:o.afterLabel})]})):Se("li",{...r,key:o},o),ListboxComponent:Ro(function(o,p){return N(re,{children:[L("ul",{...o,ref:p}),!!u&&L("div",{...o,children:N(re,{children:[L(U,{px:2,py:1,children:L(Ie,{})}),u]})},"searchable-footer")]})}),...s,renderInput:r=>L(qo,{error:!!d,placeholder:h,...r,...v,inputRef:A})},e),L(S,{name:e,disableIcon:P})]})})});ke.displayName="Searchable";var Oo=ke;import{forwardRef as Ho,memo as Wo}from"react";import{Controller as Yo,useFormContext as Jo}from"react-hook-form";import{isObject as Ko,isEmpty as Xo}from"lodash-es";import{Grid as H,Autocomplete as Qo,TextField as Zo,Tooltip as er,Divider as or}from"@mui/material";import{LIcon as ie,Button as rr}from"@s_mart/core";import{colorPalette as tr}from"@s_mart/tokens";import{linePlus as Ee,linePen as ir,lineInfoCircle as lr}from"@s_mart/solid-icons";import{toRem as Le}from"@s_mart/utils";import{toRem as te}from"@s_mart/utils";import jo from"@emotion/styled";import{css as we}from"@emotion/react";var Ve=we`
|
|
2
2
|
display: flex;
|
|
3
3
|
align-items: center;
|
|
4
4
|
justify-content: center;
|
|
@@ -51,7 +51,7 @@ import{FormProvider as Oe}from"react-hook-form";import{jsx as Fe}from"react/jsx-
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
${({hideAddButton:e,theme:t})=>!e&&No(t)}
|
|
54
|
-
`;import{Fragment as fe,jsx as k,jsxs as q}from"react/jsx-runtime";import{createElement as Re}from"react";var nr=({name:e,rules:t,defaultValue:n,shouldUnregister:i,label:l,required:g,options:x,editable:v,footer:I,onEditOption:u,onCreateOption:c,textFieldProps:a,hideAddButton:h,multiple:f,info:F,onChange:P,onInputChange:s,placeholder:b,disableIconError:d,...m})=>{let G=Jo();if(!G)throw new Error("Para usar o <Creatable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let A=V(G.formState.errors,e),r=h||m.disabled,o=w=>{let O=0;return a?.InputProps||(O+=2.5),r||(O+=2.56,p(w)&&(O+=2.56)),!m.disableClearable&&!m.disabled&&(O+=1.3),O+"rem"},p=w=>m.disabled?!1:v&&Ko(w)&&!Xo(w);console.warn=()=>{};let y=w=>{c?c(w):console.error("onCreateOption n\xE3o foi definido")},B=w=>{u?u(w):console.error("onEditOption n\xE3o foi definido")};return k(Yo,{control:G.control,name:e,rules:t,defaultValue:n,shouldUnregister:i,render:({field:{value:w,onChange:O,ref:Ue}})=>{let xe=w?.label||w?.value||w;return q(H,{display:"flex",flexDirection:"column",children:[q("div",{style:{display:"flex"},children:[l&&k(H,{item:!0,children:k(C,{label:l,required:g})}),F&&k(H,{item:!0,children:k(er,{title:F,placement:"top",children:k("div",{style:{width:"fit-content"},children:k(ie,{icon:lr,color:"#757575"})})})})]}),k(Ge,{hideAddButton:r,children:k(Qo,{fullWidth:!0,onChange:(E,T)=>{O(T),P?.(T,G.getValues())},onInputChange:(E,T,de)=>{de==="input"&&setTimeout(()=>{s?.(T,G.getValues())},0)},slotProps:{...m.slotProps||{},paper:{...(m.slotProps||{}).paper||{},sx:{border:`1px solid ${tr.neutral[30]}`,boxShadow:"0px 2px 4px rgba(0, 0, 0, 0.15)",...(m.slotProps||{}).paper?.sx||{}}}},options:x,value:w||(f?[]:null),multiple:f,readOnly:m.disabled,noOptionsText:r?void 0:q(
|
|
54
|
+
`;import{Fragment as fe,jsx as k,jsxs as q}from"react/jsx-runtime";import{createElement as Re}from"react";var nr=({name:e,rules:t,defaultValue:n,shouldUnregister:i,label:l,required:g,options:x,editable:v,footer:I,onEditOption:u,onCreateOption:c,textFieldProps:a,hideAddButton:h,multiple:f,info:F,onChange:P,onInputChange:s,placeholder:b,disableIconError:d,...m})=>{let G=Jo();if(!G)throw new Error("Para usar o <Creatable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let A=V(G.formState.errors,e),r=h||m.disabled,o=w=>{let O=0;return a?.InputProps||(O+=2.5),r||(O+=2.56,p(w)&&(O+=2.56)),!m.disableClearable&&!m.disabled&&(O+=1.3),O+"rem"},p=w=>m.disabled?!1:v&&Ko(w)&&!Xo(w);console.warn=()=>{};let y=w=>{c?c(w):console.error("onCreateOption n\xE3o foi definido")},B=w=>{u?u(w):console.error("onEditOption n\xE3o foi definido")};return k(Yo,{control:G.control,name:e,rules:t,defaultValue:n,shouldUnregister:i,render:({field:{value:w,onChange:O,ref:Ue}})=>{let xe=w?.label||w?.value||w;return q(H,{display:"flex",flexDirection:"column",children:[q("div",{style:{display:"flex"},children:[l&&k(H,{item:!0,children:k(C,{label:l,required:g})}),F&&k(H,{item:!0,children:k(er,{title:F,placement:"top",children:k("div",{style:{width:"fit-content"},children:k(ie,{icon:lr,color:"#757575"})})})})]}),k(Ge,{hideAddButton:r,children:k(Qo,{fullWidth:!0,onChange:(E,T)=>{O(T),P?.(T,G.getValues())},onInputChange:(E,T,de)=>{de==="input"&&setTimeout(()=>{s?.(T,G.getValues())},0)},slotProps:{...m.slotProps||{},paper:{...(m.slotProps||{}).paper||{},sx:{border:`1px solid ${tr.neutral[30]}`,boxShadow:"0px 2px 4px rgba(0, 0, 0, 0.15)",...(m.slotProps||{}).paper?.sx||{}}}},options:x,value:w||(f?[]:null),multiple:f,readOnly:m.disabled,noOptionsText:r?void 0:q(rr,{sx:{justifyContent:"flex-start",padding:`${Le(6)} ${Le(-16)}`,margin:0},fullWidth:!0,onClick:()=>y(w),variant:"text",startIcon:k(ie,{icon:Ee}),children:["Adicionar ",xe&&`"${xe}"`]}),isOptionEqualToValue:(E,T)=>T?typeof E=="string"&&typeof T=="string"?E===T:typeof E=="object"&&typeof T=="object"?typeof E.value=="object"&&typeof T.value=="object"&&E.key!==void 0&&T.key!==void 0?E.key===T.key:E.value===T.value:typeof E=="object"&&typeof T=="string":!1,renderOption:(E,T)=>typeof T=="object"?Re("li",{...E,key:T.key||T.value},q(H,{container:!0,direction:"column",children:[k(H,{item:!0,children:T.label}),T.afterLabel&&k(H,{item:!0,children:T.afterLabel})]})):Re("li",{...E,key:T},T),ListboxComponent:Ho(function(T,de){return q(fe,{children:[k("ul",{...T,ref:de}),!!I&&k("div",{...T,children:q(fe,{children:[k(H,{px:2,py:1,children:k(or,{})}),I]})},"creatable-footer")]})}),...m,sx:{"& div.MuiInputBase-root":{paddingRight:`${o(w)} !important`},...m.sx},renderInput:E=>k(Zo,{placeholder:b,...E,error:!!A,InputProps:{...E.InputProps,inputRef:Ue,endAdornment:q("div",{className:"endAdornments",children:[E.InputProps.endAdornment,!r&&q(fe,{children:[p(w)?q("div",{className:"editable",children:[k("div",{className:"divider"}),k("div",{className:"button",onClick:()=>B(w),children:k(ie,{icon:ir,size:"24px",removeMargin:!0})})]}):null,q("div",{className:"creatable",children:[k("div",{className:"divider"}),k("div",{className:"button",onClick:()=>y(w),children:k(ie,{icon:Ee,size:"24px",removeMargin:!0})})]})]})]})},...a})},e)}),k(S,{name:e,disableIcon:d})]})}})},ar=Wo(nr);import{Controller as sr,useFormContext as dr}from"react-hook-form";import{Grid as pr,Checkbox as mr,FormControlLabel as ur}from"@mui/material";import{jsx as Q,jsxs as yr}from"react/jsx-runtime";var fr=({name:e,rules:t,defaultValue:n,shouldUnregister:i,label:l,labelPlacement:g,required:x,disableIconError:v,onChange:I,...u})=>{let c=dr();if(!c)throw new Error("Para usar o <Checkbox /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return Q(sr,{control:c.control,name:e,rules:t,defaultValue:n,shouldUnregister:i,render:({field:{value:a,onChange:h}})=>yr(pr,{display:"flex",flexDirection:"column",children:[Q(ur,{control:Q(mr,{checked:!!a,value:a??"",defaultValue:a,onChange:(f,F)=>{h(f,F),I?.(f,F)},...u},e),label:Q(C,{label:l,required:x,regular:!0}),labelPlacement:g||"end"}),Q(S,{name:e,disableIcon:v})]})})},cr=fr;import{Controller as xr,useFormContext as Fr}from"react-hook-form";import{Grid as Pr,Switch as br,FormControlLabel as hr}from"@mui/material";import{jsx as Z,jsxs as Cr}from"react/jsx-runtime";var gr=({name:e,rules:t,defaultValue:n,shouldUnregister:i,label:l,labelPlacement:g,disableIconError:x,onChange:v,...I})=>{let u=Fr();if(!u)throw new Error("Para usar o <Switch /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return Z(xr,{control:u.control,name:e,rules:t,defaultValue:n,shouldUnregister:i,render:({field:{value:c,onChange:a}})=>Cr(Pr,{display:"flex",flexDirection:"column",children:[Z(hr,{control:Z(br,{value:c??"",checked:c??!1,defaultValue:c,onChange:(h,f)=>{a(h,f),v?.(h,f)},...I},e),label:Z(C,{label:l}),labelPlacement:g||"end"}),Z(S,{name:e,disableIcon:x})]})})},vr=gr;import{Grid as Tr,Radio as Ir,FormControlLabel as Sr}from"@mui/material";import{jsx as le}from"react/jsx-runtime";var kr=({label:e,labelPlacement:t,...n})=>le(Tr,{display:"flex",flexDirection:"column",children:le(Sr,{control:le(Ir,{...n}),label:le(C,{label:e}),labelPlacement:t||"end"})}),wr=kr;import{Controller as Vr,useFormContext as Gr}from"react-hook-form";import{Grid as Er,RadioGroup as Lr}from"@mui/material";import{jsx as ne,jsxs as Dr}from"react/jsx-runtime";var Rr=({name:e,rules:t,defaultValue:n,shouldUnregister:i,label:l,required:g,children:x,orientation:v="row",disableIconError:I,...u})=>{let c=Gr();if(!c)throw new Error("Para usar o <RadioGroup /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return ne(Vr,{control:c.control,name:e,rules:t,defaultValue:n,shouldUnregister:i,render:({field:{value:a,onChange:h}})=>Dr(Er,{display:"flex",flexDirection:"column",children:[l&&ne(C,{label:l,required:g}),ne(Lr,{value:a||"",name:e,...u,onChange:f=>{u?.onChange?.(f,f.target?.value),h(f)},style:{display:"flex",flexDirection:v},children:x},e),ne(S,{name:e,disableIcon:I})]})})},Br=Rr;import{Controller as Ar,useFormContext as Mr}from"react-hook-form";import{Slider as $r}from"@mui/material";import{jsx as Be}from"react/jsx-runtime";var qr=({name:e,rules:t,defaultValue:n,shouldUnregister:i,...l})=>{let g=Mr();if(!g)throw new Error("Para usar o <Slider /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return Be(Ar,{control:g.control,name:e,rules:t,defaultValue:n,shouldUnregister:i,render:({field:{value:x,onChange:v}})=>Be($r,{value:x||l?.min||0,onChange:v,valueLabelDisplay:"auto",...l},e)})},zr=qr;import{memo as Nr}from"react";import{Controller as Hr,useFormContext as Wr}from"react-hook-form";import{composeValidators as Yr,date as Ae}from"@s_mart/rules";import{Grid as Jr,TextField as Kr}from"@mui/material";import{DatePicker as Xr}from"@mui/x-date-pickers/DatePicker";import{AdapterDayjs as Qr}from"@mui/x-date-pickers/AdapterDayjs";import{LocalizationProvider as Zr}from"@mui/x-date-pickers/LocalizationProvider";import{ptBR as et}from"@mui/x-date-pickers/locales/ptBR";import ot from"dayjs/locale/pt-br";import _r from"@emotion/styled";import{IconButton as Ur}from"@mui/material";import{toRem as z}from"@s_mart/utils";var Or=e=>{switch(e){case"small":return z(16);default:case"medium":return z(20);case"large":return z(24)}},jr=e=>{switch(e){case"small":return`${z(2)} ${z(8)}`;default:case"medium":return`${z(6)} ${z(8)}`;case"large":return`${z(10)}`}},De=_r(Ur)`
|
|
55
55
|
margin: 0px;
|
|
56
56
|
|
|
57
57
|
padding: ${({size:e})=>jr(e)};
|
|
@@ -60,7 +60,7 @@ import{FormProvider as Oe}from"react-hook-form";import{jsx as Fe}from"react/jsx-
|
|
|
60
60
|
svg {
|
|
61
61
|
width: ${({size:e})=>Or(e)} !important;
|
|
62
62
|
}
|
|
63
|
-
`;import{jsx as ee,jsxs as lt}from"react/jsx-runtime";import{createElement as it}from"react";var rt=({rules:e,name:t,defaultValue:n,shouldUnregister:i,datePickerProps:l,label:g,required:x,placeholder:v,disabled:I,disableIconError:u,...c})=>{let a=Wr();if(!a)throw new Error("Para usar o <DataPicker /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let h=V(a.formState.errors,t),f=l?.format||"DD/MM/YYYY",F=e?
|
|
63
|
+
`;import{jsx as ee,jsxs as lt}from"react/jsx-runtime";import{createElement as it}from"react";var rt=({rules:e,name:t,defaultValue:n,shouldUnregister:i,datePickerProps:l,label:g,required:x,placeholder:v,disabled:I,disableIconError:u,...c})=>{let a=Wr();if(!a)throw new Error("Para usar o <DataPicker /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let h=V(a.formState.errors,t),f=l?.format||"DD/MM/YYYY",F=e?Yr([Ae(f),e]):Ae(f);return ee(Zr,{dateAdapter:Qr,adapterLocale:ot,localeText:et.components.MuiLocalizationProvider.defaultProps.localeText,children:ee(Hr,{control:a.control,name:t,rules:F,defaultValue:n,shouldUnregister:i,render:({field:{value:P,onChange:s,ref:b}})=>lt(Jr,{display:"flex",flexDirection:"column",children:[g&&ee(C,{label:g,required:x}),it(Xr,{...l,key:t,value:P??null,format:f,onChange:(d,m)=>{s(d,m),l?.onChange?.(d,m)},disabled:I,slots:{textField:Kr,openPickerButton:d=>ee(De,{...d,size:c.size})},slotProps:{textField:d=>({variant:"outlined",...d,error:!!h,...c,inputProps:{...d.inputProps,placeholder:v||d.inputProps?.placeholder},InputProps:{...d.InputProps,inputRef(m){b(m),typeof d.inputRef=="function"&&d.inputRef(m)}}})}}),ee(S,{name:t,disableIcon:u})]})})})},tt=Nr(rt);import{memo as pt}from"react";import{Controller as mt,useFormContext as ut}from"react-hook-form";import{composeValidators as ft,time as $e}from"@s_mart/rules";import{Grid as ct,TextField as yt}from"@mui/material";import{TimePicker as xt}from"@mui/x-date-pickers/TimePicker";import{AdapterDayjs as Ft}from"@mui/x-date-pickers/AdapterDayjs";import{LocalizationProvider as Pt}from"@mui/x-date-pickers/LocalizationProvider";import{ptBR as bt}from"@mui/x-date-pickers/locales/ptBR";import ht from"dayjs/locale/pt-br";import nt from"@emotion/styled";import{IconButton as at}from"@mui/material";import{toRem as _}from"@s_mart/utils";var st=e=>{switch(e){case"small":return _(16);default:case"medium":return _(20);case"large":return _(24)}},dt=e=>{switch(e){case"small":return`${_(2)} ${_(8)}`;default:case"medium":return`${_(6)} ${_(8)}`;case"large":return`${_(10)}`}},Me=nt(at)`
|
|
64
64
|
margin: 0px;
|
|
65
65
|
|
|
66
66
|
padding: ${({size:e})=>dt(e)};
|
|
@@ -69,4 +69,4 @@ import{FormProvider as Oe}from"react-hook-form";import{jsx as Fe}from"react/jsx-
|
|
|
69
69
|
svg {
|
|
70
70
|
width: ${({size:e})=>st(e)} !important;
|
|
71
71
|
}
|
|
72
|
-
`;import{jsx as J,jsxs as Ct}from"react/jsx-runtime";var gt=({rules:e,defaultValue:t,shouldUnregister:n,name:i,required:l,label:g,timePickerProps:x,placeholder:v,disabled:I,disableIconError:u,...c})=>{let a=ut();if(!a)throw new Error("Para usar o <TimePicker /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let h=V(a.formState.errors,i),f=x?.format||"HH:mm",F=e?
|
|
72
|
+
`;import{jsx as J,jsxs as Ct}from"react/jsx-runtime";var gt=({rules:e,defaultValue:t,shouldUnregister:n,name:i,required:l,label:g,timePickerProps:x,placeholder:v,disabled:I,disableIconError:u,...c})=>{let a=ut();if(!a)throw new Error("Para usar o <TimePicker /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let h=V(a.formState.errors,i),f=x?.format||"HH:mm",F=e?ft([$e(f),e]):$e(f);return J(Pt,{dateAdapter:Ft,adapterLocale:ht,localeText:bt.components.MuiLocalizationProvider.defaultProps.localeText,children:J(mt,{control:a.control,name:i,rules:F,defaultValue:t,shouldUnregister:n,render:({field:{value:P,onChange:s,ref:b}})=>Ct(ct,{display:"flex",flexDirection:"column",children:[g&&J(C,{label:g,required:l}),J(xt,{ampm:!1,format:f,value:P??null,disabled:I,...x,onChange:(d,m)=>{s(d,m),x?.onChange?.(d,m)},slots:{textField:yt,openPickerButton:d=>J(Me,{...d,size:c.size})},slotProps:{textField:d=>({variant:"outlined",...d,error:!!h,...c,inputProps:{...d.inputProps,placeholder:v||d.inputProps?.placeholder},InputProps:{...d.InputProps,inputRef(m){b(m),typeof d.inputRef=="function"&&d.inputRef(m)}}})}},i),J(S,{name:i,disableIcon:u})]})})})},vt=pt(gt);import{memo as Tt}from"react";import{Controller as It,useFormContext as St}from"react-hook-form";import{Grid as ae,Autocomplete as kt,TextField as wt}from"@mui/material";import{colorPalette as Vt}from"@s_mart/tokens";import{jsx as W,jsxs as qe}from"react/jsx-runtime";import{createElement as Lt}from"react";var Gt=({name:e,defaultValue:t,rules:n,shouldUnregister:i,label:l,required:g,noOptionsText:x,placeholder:v,onInputChange:I,onChange:u,disableIconError:c,...a})=>{let h=St();if(!h)throw new Error("Para usar o <Autocomplete /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let f=V(h.formState.errors,e);return console.warn=()=>{},W(It,{name:e,control:h.control,defaultValue:t,rules:n,shouldUnregister:i,render:({field:F})=>qe(ae,{display:"flex",flexDirection:"column",children:[l&&W(C,{label:l,required:g}),W(kt,{onChange:(P,s)=>{F.onChange(s),u?.(s,h.getValues())},onInputChange:(P,s,b)=>{b==="input"&&(F.onChange(s),setTimeout(()=>{I?.(s,h.getValues())},0))},slotProps:{...a.slotProps||{},paper:{...(a.slotProps||{}).paper||{},sx:{border:`1px solid ${Vt.neutral[30]}`,boxShadow:"0px 2px 4px rgba(0, 0, 0, 0.15)",...(a.slotProps||{}).paper?.sx||{}}}},isOptionEqualToValue:(P,s)=>P.value===s.value,renderOption:(P,s)=>Lt("li",{...P,key:s.key||s.value,onClick:b=>{P.onClick?.(b),F.onChange(s)}},qe(ae,{container:!0,direction:"column",children:[W(ae,{item:!0,children:s.label}),s.afterLabel&&W(ae,{item:!0,children:s.afterLabel})]})),value:F.value||null,readOnly:a.disabled,noOptionsText:x||"Nenhuma op\xE7\xE3o encontrada",...a,renderInput:P=>W(wt,{placeholder:v,...P,...a.textFieldProps,error:!!f,InputProps:{...P.InputProps,...a.textFieldProps?.InputProps,inputRef:F.ref,inputProps:{...P.inputProps,...a.textFieldProps?.InputProps?.inputProps}}})},e),W(S,{name:e,disableIcon:c})]})})},Et=Tt(Gt);import{Controller as $t,useFormContext as qt}from"react-hook-form";import{Tooltip as Rt}from"@mui/material";import{LIcon as Bt}from"@s_mart/core";import{lineInfoCircle as Dt}from"@s_mart/solid-icons";import{jsx as ce}from"react/jsx-runtime";var At=({title:e})=>ce(Rt,{title:e,placement:"top",children:ce("div",{style:{width:"fit-content"},children:ce(Bt,{icon:Dt,color:"#757575"})})}),oe=At;import{Autocomplete as zt,Divider as ze,TextField as _t}from"@mui/material";import{isEqual as Ut}from"lodash-es";import{forwardRef as Ot}from"react";import{colorPalette as jt}from"@s_mart/tokens";import{memo as Mt}from"react";var se=Mt;import{Fragment as ye,jsx as D,jsxs as Y}from"react/jsx-runtime";import{createElement as Wt}from"react";var Nt=({name:e,rules:t,defaultValue:n,shouldUnregister:i,label:l,required:g,options:x,textFieldProps:v,noOptionsText:I,footer:u,multiple:c,info:a,placeholder:h,onChange:f,onInputChange:F,getOptionAfterLabel:P,getOptionLabel:s,getOptionKey:b,...d})=>{let m=qt();if(!m)throw new Error("Para usar o <SearchableV2 /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let G=V(m.formState.errors,e);return D($t,{control:m.control,name:e,rules:t,defaultValue:n,shouldUnregister:i,render:({field:{onChange:A,value:r,ref:o}})=>Y("div",{style:{display:"flex",flexDirection:"column"},children:[Y("div",{style:{display:"flex"},children:[l&&D(C,{label:l,required:g}),a&&D(oe,{title:a})]}),D(zt,{onChange:(p,y)=>{A(y),f?.(y)},onInputChange:(p,y,B)=>{B==="input"&&F?.(y)},value:r||(c?[]:null),options:x,multiple:c,readOnly:d.disabled,slotProps:{...d.slotProps||{},paper:{...(d.slotProps||{}).paper||{},sx:{border:`1px solid ${jt.neutral[30]}`,boxShadow:"0px 2px 4px rgba(0, 0, 0, 0.15)",...(d.slotProps||{}).paper?.sx||{}}}},noOptionsText:Y(ye,{children:[I||"Nenhuma op\xE7\xE3o encontrada",typeof u<"u"?Y(ye,{children:[D("div",{style:{paddingTop:"0.5rem",paddingBottom:"0.5rem"},children:D(ze,{})}),u()]}):null]}),isOptionEqualToValue:(p,y)=>Ut(p,y),getOptionLabel:p=>s(p),getOptionKey:p=>b(p),renderOption:typeof P=="function"?(p,y)=>{let B=P(y),w=b(y);return Wt("li",{...p,key:w},Y("div",{style:{display:"flex",flexDirection:"column"},children:[D("span",{children:s(y)}),typeof B=="string"?D("span",{children:B}):B]}))}:void 0,ListboxComponent:Ot(function(y,B){return Y(ye,{children:[D("ul",{...y,ref:B}),typeof u<"u"?Y("div",{...y,children:[D("div",{style:{paddingTop:"0.5rem",paddingBottom:"0.5rem"},children:D(ze,{})}),u()]},"searchable-footer"):null]})}),...d,renderInput:p=>D(_t,{error:!!G,placeholder:h,...p,...v,inputRef:o})},e),D(S,{name:e})]})})},Ht=se(Nt);import{useState as Yt}from"react";import{Controller as Jt,useFormContext as Kt}from"react-hook-form";import{IconButton as Xt,LIcon as Qt}from"@s_mart/core";import{lineTimes as Zt}from"@s_mart/regular-icons";import{colorPalette as _e}from"@s_mart/tokens";import{Select as ei,MenuItem as oi,Divider as ri}from"@mui/material";import{Fragment as li,jsx as M,jsxs as K}from"react/jsx-runtime";var ti=({name:e,rules:t,defaultValue:n,shouldUnregister:i,label:l,required:g,options:x,placeholder:v,clearable:I,info:u,footer:c,onChange:a,variant:h="outlined",getOptionKey:f,getOptionLabel:F,getOptionAfterLabel:P,...s})=>{let b=Kt(),[d,m]=Yt(!1);if(!b)throw new Error("Para usar o <SelectV2 /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let G=V(b.formState.errors,e);return M(Jt,{control:b.control,name:e,rules:t,defaultValue:n,shouldUnregister:i,render:({field:{value:A,onChange:r,ref:o}})=>K("div",{style:{display:"flex",flexDirection:"column"},children:[K("div",{style:{display:"flex"},children:[l&&M(C,{label:l,required:g}),u&&M(oe,{title:u})]}),K(ei,{open:d,onOpen:()=>m(!0),onClose:()=>m(!1),displayEmpty:!!v,variant:h,autoComplete:"off",value:A||"",renderValue:p=>p?.length===0?M("p",{style:{color:_e.neutral[100]},children:v}):F(p),onChange:p=>{r(p.target.value),a?.(p.target.value)},error:!!G,size:s.size||"medium",inputRef:o,...s,endAdornment:K(li,{children:[s.endAdornment,!!(I&&A)&&M(Xt,{variant:"text",color:"neutral",size:"small",sx:{borderRadius:"50%",position:"absolute",right:"2rem"},style:{padding:0},"aria-label":"Limpar",title:"Limpar",onClick:()=>{r(null),a?.(null)},children:M(Qt,{icon:Zt,color:_e.neutral[100],size:"25px",removeMargin:!0})})]}),children:[x.map(p=>{let y=f(p);return M(oi,{value:p,children:K("div",{style:{display:"flex",flexDirection:"column",flex:1},children:[F(p),M("span",{children:P?.(p)??null})]})},y)}),c!==void 0&&K("div",{children:[M("div",{style:{padding:"8px 16px"},children:M(ri,{})},"footer-divider"),M("div",{children:c({closeSelect:()=>m(!1)})},"footer-content")]},"footer")]},e),M(S,{name:e})]})})},ii=se(ti);export{Et as Autocomplete,cr as Checkbox,ar as Creatable,tt as DatePicker,C as FieldLabel,Ke as Form,pe as FormProvider,wr as RadioButton,Br as RadioGroup,Oo as Searchable,Ht as SearchableV2,Eo as Select,ii as SelectV2,zr as Slider,vr as Switch,Fo as TextField,vt as TimePicker,me as useForm};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@s_mart/form",
|
|
3
|
-
"version": "7.1.
|
|
3
|
+
"version": "7.1.1",
|
|
4
4
|
"main": "./dist/index.mjs",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.mts",
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
"lodash-es": "^4.17.21",
|
|
19
19
|
"tsup": "8.0.2",
|
|
20
20
|
"typescript": ">=5.4.2",
|
|
21
|
-
"@s_mart/core": "7.0.
|
|
22
|
-
"@s_mart/masks": "5.1.
|
|
21
|
+
"@s_mart/core": "7.0.1",
|
|
22
|
+
"@s_mart/masks": "5.1.1",
|
|
23
23
|
"eslint-config-smarten": "4.1.0",
|
|
24
24
|
"@s_mart/rules": "5.1.1",
|
|
25
25
|
"@s_mart/solid-icons": "5.2.0",
|
|
26
26
|
"@s_mart/regular-icons": "5.2.0",
|
|
27
27
|
"@s_mart/tokens": "5.1.0",
|
|
28
28
|
"@s_mart/typed": "6.0.0",
|
|
29
|
-
"@s_mart/utils": "5.1.
|
|
29
|
+
"@s_mart/utils": "5.1.1"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"@emotion/react": "^11.11.4",
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"react-hook-form": "^7.51.0",
|
|
43
43
|
"typescript": ">=5.4.2",
|
|
44
44
|
"zod": ">=3.21.4",
|
|
45
|
-
"@s_mart/core": "7.0.
|
|
46
|
-
"@s_mart/masks": "5.1.
|
|
45
|
+
"@s_mart/core": "7.0.1",
|
|
46
|
+
"@s_mart/masks": "5.1.1",
|
|
47
47
|
"@s_mart/rules": "5.1.1",
|
|
48
48
|
"@s_mart/tokens": "5.1.0",
|
|
49
49
|
"@s_mart/typed": "6.0.0",
|
|
50
|
-
"@s_mart/utils": "5.1.
|
|
50
|
+
"@s_mart/utils": "5.1.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"eslint": "^8.47.0"
|