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