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