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