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