@s_mart/form 8.1.1 → 9.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +5 -5
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -623,6 +623,8 @@ type FieldLabelProps = {
|
|
|
623
623
|
|
|
624
624
|
declare const FieldLabel: ({ label, required, regular }: FieldLabelProps) => react_jsx_runtime.JSX.Element;
|
|
625
625
|
|
|
626
|
+
type ConditionalArrayType<T, Multiple extends boolean | undefined = undefined> = Multiple extends true ? T[] : T;
|
|
627
|
+
|
|
626
628
|
type SearchableV2Props<T extends FieldValues | string | number, Multiple extends boolean | undefined, _ValueType = unknown> = Omit<AutocompleteProps$1<T, Multiple, true, true>, 'renderInput' | 'size' | 'onInputChange' | 'onChange' | 'getOptionLabel' | 'getOptionKey' | 'defaultValue' | 'value'> & Omit<ControllerProps, 'render' | 'control'> & {
|
|
627
629
|
options: T[];
|
|
628
630
|
textFieldProps?: TextFieldProps$1;
|
|
@@ -665,8 +667,6 @@ type SearchableV2Props<T extends FieldValues | string | number, Multiple extends
|
|
|
665
667
|
getOptionAfterLabel?: (option: T) => string | React.ReactNode;
|
|
666
668
|
};
|
|
667
669
|
|
|
668
|
-
type ConditionalArrayType<T, Multiple extends boolean | undefined = undefined> = Multiple extends true ? T[] : T;
|
|
669
|
-
|
|
670
670
|
declare const _default$2: <T extends string | number | FieldValues, Multiple extends boolean | undefined = undefined, _ValueType = ConditionalArrayType<T, Multiple>>({ name, rules, defaultValue, shouldUnregister, label, required, options, textFieldProps, noOptionsText, footer, multiple, info, placeholder, onChange: onChangeProp, onInputChange, getOptionAfterLabel, getOptionLabel, getOptionKey, ...rest }: SearchableV2Props<T, Multiple, _ValueType>) => react_jsx_runtime.JSX.Element;
|
|
671
671
|
|
|
672
672
|
type ControllerSelect = Omit<ControllerProps, 'render' | 'control'>;
|
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 ke}from"react/jsx-runtime";function lo({children:e,style:t,onSubmit:i,...n}){return ke(io,{...n,children:ke("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{Grid as he,InputAdornment as vo,TextField as Po,Tooltip as Co}from"@mui/material";import{LIcon as we}from"@s_mart/core";import*as Re from"@s_mart/masks";import{lineEye as To,lineEyeSlash as So,lineInfoCircle as ko}from"@s_mart/solid-icons";import{memo as Io,useRef as Vo,useState as wo}from"react";import{Controller as Ro,useFormContext as Eo}from"react-hook-form";import{useFormContext as co}from"react-hook-form";import{Indicator as yo}from"@s_mart/core";var E=(e,t)=>t.replace(/[[\]]/g,"").split(".").reduce((n,l)=>n?.[l],e);import{jsx as bo}from"react/jsx-runtime";var xo=({name:e,disableIcon:t})=>{let i=co(),n=E(i?.formState?.errors,e);return n?bo(yo,{severity:"error",icon:t?!1:void 0,children:n?.message}):null},k=xo;import{Typography as Ie}from"@mui/material";import{toRem as Fo}from"@s_mart/utils";import{jsx as Ve,jsxs as ho}from"react/jsx-runtime";var go=({label:e,required:t,regular:i})=>ho("span",{style:{display:"flex",alignItems:"center",gap:Fo(2)},children:[Ve(Ie,{variant:"caption",style:{display:"flex",alignItems:"center"},sx:{fontWeight:i?400:700},children:e}),t&&Ve(Ie,{variant:"caption",color:"error",sx:{fontWeight:900},children:"*"})]}),P=go;import{jsx as z,jsxs as Ee}from"react/jsx-runtime";var Ao=({name:e,rules:t,defaultValue:i,shouldUnregister:n,label:l,required:g,mask:c,variant:y="outlined",info:C,parse:m,format:u,onInputChange:d,disableIconError:x,...a})=>{let h=Eo(),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[p,b]=wo(!1),s=r=>{let o=r;return o=u?.(r)??r,c?Re?.[c]?.format(o):o},f=r=>{let o=r;return o=m?.(r)??o,c?Re?.[c]?.parse(o,F.current):o},w=r=>{if(!r||c!=="porcentagem"&&c!=="porcentagem0")return;r?.stopPropagation();let o=(r?.target).value;if(o){let T=String(o);if(T.length>0){let S=T.indexOf("%");S>-1&&(r.currentTarget.selectionEnd=S)}}},$=E(h.formState.errors,e);return z(Ro,{control:h.control,name:e,rules:t,defaultValue:i,shouldUnregister:n,render:({field:{value:r,onChange:o,ref:T}})=>Ee(he,{sx:{display:"flex",flexDirection:"column"},children:[Ee("div",{style:{display:"flex"},children:[l&&z(he,{item:!0,children:z(P,{label:l,required:g})}),C&&z(he,{item:!0,children:z(Co,{title:C,placement:"top",children:z("div",{style:{width:"fit-content"},children:z(we,{icon:ko,color:"#757575"})})})})]}),z(Po,{variant:y,defaultValue:i,value:s(r||(r!=0?"":r)),onChange:S=>{let _=f(S?.target?.value);o(_),d?.(_,h.getValues()),F.current=S.target.value},error:!!$,...a,type:a.type==="password"?p?"text":"password":a.type,autoComplete:a.autoComplete||"off",slotProps:{input:{onKeyDown:w,inputRef:T,endAdornment:a.type==="password"&&z(vo,{position:"start",onClick:()=>b(!p),style:{cursor:"pointer"},children:z(we,{icon:p?To:So,size:"24px",removeMargin:!0})}),...a.InputProps}}},e),z(k,{name:e,disableIcon:x})]})})},Bo=Io(Ao);import{Divider as Lo,Grid as J,MenuItem as Go,Select as Mo,Tooltip as $o,useTheme as Do}from"@mui/material";import{IconButton as qo,LIcon as Ae}from"@s_mart/core";import{lineTimes as _o}from"@s_mart/regular-icons";import{lineInfoCircle as zo}from"@s_mart/solid-icons";import{colorPalette as Oo}from"@s_mart/tokens";import{memo as No,useState as Uo}from"react";import{Controller as jo,useFormContext as Ho}from"react-hook-form";import{Fragment as Yo,jsx as M,jsxs as ne}from"react/jsx-runtime";var Be=No(({name:e,rules:t,defaultValue:i,shouldUnregister:n,label:l,required:g,options:c,placeholder:y,clearable:C,disableOnChangeForm:m=!1,multiple:u,info:d,footer:x,onChange:a,disableIconError:h,variant:F="outlined",...p})=>{let b=Ho(),{palette:s}=Do(),[f,w]=Uo(!1);if(!b)throw new Error("Para usar o <Select /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let $=E(b.formState.errors,e);return M(jo,{control:b.control,name:e,rules:t,defaultValue:i,shouldUnregister:n,render:({field:{value:r,onChange:o,ref:T}})=>ne(J,{sx:{display:"flex",flexDirection:"column"},children:[ne("div",{style:{display:"flex"},children:[l&&M(J,{item:!0,children:M(P,{label:l,required:g})}),d&&M(J,{item:!0,children:M($o,{title:d,placement:"top",children:M("div",{style:{width:"fit-content"},children:M(Ae,{icon:zo,color:"#757575"})})})})]}),ne(Mo,{open:f,onOpen:()=>w(!0),onClose:()=>w(!1),displayEmpty:!!y,variant:F,autoComplete:"off",value:r?r||"":u?[]:"",renderValue:S=>{if(S.label)return S.label;if(y)return M("p",{style:{color:s.grey[400]},children:y})},multiple:u,onChange:S=>{!m&&o(S.target.value),a&&a(S.target.value,b.getValues())},error:!!$,size:p.size||"medium",inputRef:T,...p,endAdornment:ne(Yo,{children:[p.endAdornment,!!(C&&r)&&M(qo,{variant:"text",color:"neutral",size:"small",sx:{borderRadius:"50%",position:"absolute",right:"2rem"},style:{padding:0},"aria-label":"Clear",title:"Clear",onClick:()=>{!m&&o(null),a&&a(null,b.getValues())},children:M(Ae,{icon:_o,color:Oo.neutral[100],size:"25px",removeMargin:!0})})]}),children:[c?.map((S,_)=>M(Go,{value:S,children:ne(J,{container:!0,direction:"column",children:[M(J,{item:!0,children:S.label}),S.afterLabel&&M(J,{item:!0,children:S.afterLabel})]})},_)),x&&[M(J,{sx:{px:2,py:1},children:M(Lo,{})},"footer-divider"),M("div",{children:x({closeSelect:()=>w(!1)})},"footer-content")]]},e),M(k,{name:e,disableIcon:h})]})})});Be.displayName="Select";var Wo=Be;import{Autocomplete as Jo,Divider as Le,Grid as W,TextField as Ko,Tooltip as Xo}from"@mui/material";import{LIcon as Qo}from"@s_mart/core";import{lineInfoCircle as Zo}from"@s_mart/solid-icons";import{colorPalette as er}from"@s_mart/tokens";import{forwardRef as or,memo as rr}from"react";import{Controller as tr,useFormContext as ir}from"react-hook-form";import{Fragment as de,jsx as G,jsxs as K}from"react/jsx-runtime";import{createElement as Ge}from"react";var Me=rr(({name:e,rules:t,defaultValue:i,shouldUnregister:n,label:l,required:g,options:c,textFieldProps:y,noOptionsText:C,footer:m,multiple:u,info:d,placeholder:x,onChange:a,onInputChange:h,disableIconError:F,...p})=>{let b=ir();if(!b)throw new Error("Para usar o <Searchable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let s=E(b.formState.errors,e);return G(tr,{control:b.control,name:e,rules:t,defaultValue:i,shouldUnregister:n,render:({field:{onChange:f,value:w,ref:$}})=>K(W,{sx:{display:"flex",flexDirection:"column"},children:[K("div",{style:{display:"flex"},children:[l&&G(W,{item:!0,children:G(P,{label:l,required:g})}),d&&G(W,{item:!0,children:G(Xo,{title:d,placement:"top",children:G("div",{style:{width:"fit-content"},children:G(Qo,{icon:Zo,color:"#757575"})})})})]}),G(Jo,{onChange:(r,o)=>{f(o),a?.(o,b.getValues())},onInputChange:(r,o,T)=>{T==="input"&&setTimeout(()=>{h?.(o,b.getValues())},0)},slotProps:{...p.slotProps||{},paper:{...(p.slotProps||{}).paper||{},sx:{border:`1px solid ${er.neutral[30]}`,boxShadow:"0px 2px 4px rgba(0, 0, 0, 0.15)"}},listbox:{component:or(function(o,T){return K(de,{children:[G("ul",{...o,ref:T}),!!m&&G("div",{...o,children:K(de,{children:[G(W,{sx:{px:2,py:1},children:G(Le,{})}),m]})},"searchable-footer")]})})}},value:w||(u?[]:null),options:c,multiple:u,readOnly:p.disabled,noOptionsText:K(de,{children:[C||"Nenhum resultado encontrado",m?K(de,{children:[G(W,{sx:{py:1},children:G(Le,{})}),m]}):null]}),isOptionEqualToValue:(r,o)=>typeof r=="string"&&typeof o=="string"?r===o:typeof r=="object"&&typeof o=="object"?typeof r.value=="object"&&typeof o.value=="object"&&r.key!==void 0&&o.key!==void 0?r.key===o.key:r.value===o.value:!1,renderOption:(r,o)=>typeof o=="object"?Ge("li",{...r,key:o.key||o.value},K(W,{container:!0,direction:"column",children:[G(W,{item:!0,children:o.label}),o.afterLabel&&G(W,{item:!0,children:o.afterLabel})]})):Ge("li",{...r,key:o},o),...p,renderInput:r=>G(Ko,{error:!!s,placeholder:x,...r,...y,inputRef:$})},e),G(k,{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 vr}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;
|
|
@@ -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 ve,jsx as
|
|
54
|
+
`;import{Fragment as ve,jsx as I,jsxs as U}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:m,onCreateOption:u,textFieldProps:d,hideAddButton:x,multiple:a,info:h,onChange:F,onInputChange:p,placeholder:b,disableIconError:s,...f})=>{let w=mr();if(!w)throw new Error("Para usar o <Creatable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let $=E(w.formState.errors,e),r=x||f.disabled,o=R=>{let D=0;return d?.InputProps||(D+=2.5),r||(D+=2.56,T(R)&&(D+=2.56)),!f.disableClearable&&!f.disabled&&(D+=1.3),D+"rem"},T=R=>f.disabled?!1:y&&ur(R)&&!fr(R);console.warn=()=>{};let S=R=>{u?u(R):console.error("onCreateOption n\xE3o foi definido")},_=R=>{m?m(R):console.error("onEditOption n\xE3o foi definido")};return I(pr,{control:w.control,name:e,rules:t,defaultValue:i,shouldUnregister:n,render:({field:{value:R,onChange:D,ref:be}})=>{let ie=R?.label||R?.value||R;return U(X,{sx:{display:"flex",flexDirection:"column"},children:[U("div",{style:{display:"flex"},children:[l&&I(X,{item:!0,children:I(P,{label:l,required:g})}),h&&I(X,{item:!0,children:I(xr,{title:h,placement:"top",children:I("div",{style:{width:"fit-content"},children:I(me,{icon:vr,color:"#757575"})})})})]}),I(qe,{hideAddButton:r,children:I(cr,{fullWidth:!0,onChange:(A,v)=>{D(v),F?.(v,w.getValues())},onInputChange:(A,v,le)=>{le==="input"&&setTimeout(()=>{p?.(v,w.getValues())},0)},slotProps:{...f.slotProps||{},paper:{...(f.slotProps||{}).paper||{},sx:{border:`1px solid ${gr.neutral[30]}`,boxShadow:"0px 2px 4px rgba(0, 0, 0, 0.15)"}},listbox:{component:sr(function(v,le){return U(ve,{children:[I("ul",{...v,ref:le}),!!C&&I("div",{...v,children:U(ve,{children:[I(X,{sx:{px:2,py:1},children:I(br,{})}),C]})},"creatable-footer")]})})}},options:c,value:R||(a?[]:null),multiple:a,readOnly:f.disabled,noOptionsText:r?void 0:U(Fr,{sx:{justifyContent:"flex-start",padding:`${ze(6)} ${ze(-16)}`,margin:0},fullWidth:!0,onClick:()=>S(R),variant:"text",startIcon:I(me,{icon:_e}),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},U(X,{container:!0,direction:"column",children:[I(X,{item:!0,children:v.label}),v.afterLabel&&I(X,{item:!0,children:v.afterLabel})]})):Oe("li",{...A,key:v},v),...f,sx:{"& div.MuiInputBase-root":{paddingRight:`${o(R)} !important`},...f.sx},renderInput:A=>I(yr,{placeholder:b,...A,error:!!$,...d,slotProps:{input:{...A.InputProps,inputRef:be,endAdornment:U("div",{className:"endAdornments",children:[A.InputProps.endAdornment,!r&&U(ve,{children:[T(R)?U("div",{className:"editable",children:[I("div",{className:"divider"}),I("div",{className:"button",onClick:()=>_(R),children:I(me,{icon:hr,size:"24px",removeMargin:!0})})]}):null,U("div",{className:"creatable",children:[I("div",{className:"divider"}),I("div",{className:"button",onClick:()=>S(R),children:I(me,{icon:_e,size:"24px",removeMargin:!0})})]})]})]})}}})},e)}),I(k,{name:e,disableIcon:s})]})}})});Ne.displayName="Creatable";var Pr=Ne;import{useController as Cr,useFormContext as Tr}from"react-hook-form";import{Checkbox as Sr,FormControlLabel as kr}from"@mui/material";import{jsx as ue,jsxs as wr}from"react/jsx-runtime";var Ir=({name:e,rules:t,defaultValue:i,shouldUnregister:n,label:l,labelPlacement:g,required:c,disableIconError:y,onChange:C,...m})=>{let u=Tr();if(!u)throw new Error("Para usar o <Checkbox /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let{field:d}=Cr({control:u.control,name:e,rules:t,defaultValue:i,shouldUnregister:n});return wr("span",{children:[ue(kr,{control:ue(Sr,{checked:!!d.value,value:d.value??"",defaultValue:d.value,onChange:(x,a)=>{d.onChange(x,a),C?.(x,a)},...m},e),label:ue(P,{label:l,required:c,regular:!0}),labelPlacement:g||"end"}),ue(k,{name:e,disableIcon:y})]})},Vr=Ir;import{FormControlLabel as Rr,Grid as Er,Switch as Ar}from"@mui/material";import{Controller as Br,useFormContext as Lr}from"react-hook-form";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 m=Lr();if(!m)throw new Error("Para usar o <Switch /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return ae(Br,{control:m.control,name:e,rules:t,defaultValue:i,shouldUnregister:n,render:({field:{value:u,onChange:d}})=>$r(Er,{sx:{display:"flex",flexDirection:"column"},children:[ae(Rr,{control:ae(Ar,{value:u??"",checked:u??!1,defaultValue:u,onChange:(x,a)=>{d(x,a),y?.(x,a)},...C},e),label:ae(P,{label:l}),labelPlacement:g||"end"}),ae(k,{name:e,disableIcon:c})]})})},Mr=Gr;import{FormControlLabel as Dr,Grid as qr,Radio as _r}from"@mui/material";import{jsx as fe}from"react/jsx-runtime";var zr=({label:e,labelPlacement:t,...i})=>fe(qr,{sx:{display:"flex",flexDirection:"column"},children:fe(Dr,{control:fe(_r,{...i}),label:fe(P,{label:e}),labelPlacement:t||"end"})}),Or=zr;import{Grid as Nr,RadioGroup as Ur}from"@mui/material";import{Controller as jr,useFormContext as Hr}from"react-hook-form";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,...m})=>{let u=Hr();if(!u)throw new Error("Para usar o <RadioGroup /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return ce(jr,{control:u.control,name:e,rules:t,defaultValue:i,shouldUnregister:n,render:({field:{value:d,onChange:x}})=>Jr(Nr,{sx:{display:"flex",flexDirection:"column"},children:[l&&ce(P,{label:l,required:g}),ce(Ur,{value:d||"",name:e,...m,onChange:a=>{m?.onChange?.(a,a.target?.value),x(a)},style:{display:"flex",flexDirection:y},children:c},e),ce(k,{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{Grid as lt,TextField as nt}from"@mui/material";import{AdapterDayjs as at}from"@mui/x-date-pickers/AdapterDayjs";import{DatePicker as st}from"@mui/x-date-pickers/DatePicker";import{LocalizationProvider as dt}from"@mui/x-date-pickers/LocalizationProvider";import{ptBR as pt}from"@mui/x-date-pickers/locales/ptBR";import{composeValidators as mt,date as He}from"@s_mart/rules";import ut from"dayjs/locale/pt-br";import{memo as ft}from"react";import{Controller as ct,useFormContext as yt}from"react-hook-form";import ot from"@emotion/styled";import{IconButton as rt}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)}},it=e=>{switch(e){case"small":return`${j(2)} ${j(8)}`;default:case"medium":return`${j(6)} ${j(8)}`;case"large":return`${j(10)}`}},je=ot(rt)`
|
|
55
55
|
margin: 0px;
|
|
56
56
|
|
|
57
57
|
padding: ${({size:e})=>it(e)};
|
|
@@ -60,7 +60,7 @@ import{FormProvider as io}from"react-hook-form";import{jsx as Se}from"react/jsx-
|
|
|
60
60
|
svg {
|
|
61
61
|
width: ${({size:e})=>tt(e)} !important;
|
|
62
62
|
}
|
|
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:m,...u})=>{let d=
|
|
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:m,...u})=>{let d=yt();if(!d)throw new Error("Para usar o <DataPicker /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let x=E(d.formState.errors,t),a=l?.format||"DD/MM/YYYY",h=e?mt([He(a),e]):He(a);return se(dt,{dateAdapter:at,adapterLocale:ut,localeText:pt.components.MuiLocalizationProvider.defaultProps.localeText,children:se(ct,{control:d.control,name:t,rules:h,defaultValue:i,shouldUnregister:n,render:({field:{value:F,onChange:p,ref:b}})=>gt(lt,{sx:{display:"flex",flexDirection:"column"},children:[g&&se(P,{label:g,required:c}),Ft(st,{...l,key:t,value:F??null,format:a,onChange:(s,f)=>{p(s,f),l?.onChange?.(s,f)},disabled:C,slots:{textField:nt,openPickerButton:s=>se(je,{...s,size:u.size})},slotProps:{textField:s=>({variant:"outlined",...s,error:!!x,...u,inputProps:{...s.inputProps,placeholder:y||s.inputProps?.placeholder},InputProps:{...s.InputProps,inputRef:f=>{b(f),typeof s.inputRef=="function"&&s.inputRef(f)}}})}}),se(k,{name:t,disableIcon:m})]})})})},bt=ft(xt);import{Grid as Tt,TextField as St}from"@mui/material";import{AdapterDayjs as kt}from"@mui/x-date-pickers/AdapterDayjs";import{LocalizationProvider as It}from"@mui/x-date-pickers/LocalizationProvider";import{TimePicker as Vt}from"@mui/x-date-pickers/TimePicker";import{ptBR as wt}from"@mui/x-date-pickers/locales/ptBR";import{composeValidators as Rt,time as Ye}from"@s_mart/rules";import Et from"dayjs/locale/pt-br";import{memo as At}from"react";import{Controller as Bt,useFormContext as Lt}from"react-hook-form";import ht from"@emotion/styled";import{IconButton as vt}from"@mui/material";import{toRem as H}from"@s_mart/utils";var Pt=e=>{switch(e){case"small":return H(16);default:case"medium":return H(20);case"large":return H(24)}},Ct=e=>{switch(e){case"small":return`${H(2)} ${H(8)}`;default:case"medium":return`${H(6)} ${H(8)}`;case"large":return`${H(10)}`}},We=ht(vt)`
|
|
64
64
|
margin: 0px;
|
|
65
65
|
|
|
66
66
|
padding: ${({size:e})=>Ct(e)};
|
|
@@ -69,7 +69,7 @@ import{FormProvider as io}from"react-hook-form";import{jsx as Se}from"react/jsx-
|
|
|
69
69
|
svg {
|
|
70
70
|
width: ${({size:e})=>Pt(e)} !important;
|
|
71
71
|
}
|
|
72
|
-
`;import{jsx as re,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:m,...u})=>{let d=
|
|
72
|
+
`;import{jsx as re,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:m,...u})=>{let d=Lt();if(!d)throw new Error("Para usar o <TimePicker /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let x=E(d.formState.errors,n),a=c?.format||"HH:mm",h=e?Rt([Ye(a),e]):Ye(a);return re(It,{dateAdapter:kt,adapterLocale:Et,localeText:wt.components.MuiLocalizationProvider.defaultProps.localeText,children:re(Bt,{control:d.control,name:n,rules:h,defaultValue:t,shouldUnregister:i,render:({field:{value:F,onChange:p,ref:b}})=>$t(Tt,{sx:{display:"flex",flexDirection:"column"},children:[g&&re(P,{label:g,required:l}),re(Vt,{ampm:!1,format:a,value:F??null,disabled:C,...c,onChange:(s,f)=>{p(s,f),c?.onChange?.(s,f)},slots:{textField:St,openPickerButton:s=>re(We,{...s,size:u.size})},slotProps:{textField:s=>({variant:"outlined",...s,error:!!x,...u,inputProps:{...s.inputProps,placeholder:y||s.inputProps?.placeholder},InputProps:{...s.InputProps,inputRef:f=>{b(f),typeof s.inputRef=="function"&&s.inputRef(f)}}})}},n),re(k,{name:n,disableIcon:m})]})})})},Mt=At(Gt);import{Autocomplete as Dt,Grid as ye,TextField as qt}from"@mui/material";import{colorPalette as _t}from"@s_mart/tokens";import{memo as zt}from"react";import{Controller as Ot,useFormContext as Nt}from"react-hook-form";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:m,disableIconError:u,...d})=>{let x=Nt();if(!x)throw new Error("Para usar o <Autocomplete /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let a=E(x.formState.errors,e);return console.warn=()=>{},Q(Ot,{name:e,control:x.control,defaultValue:t,rules:i,shouldUnregister:n,render:({field:h})=>Je(ye,{sx:{display:"flex",flexDirection:"column"},children:[l&&Q(P,{label:l,required:g}),Q(Dt,{onChange:(F,p)=>{h.onChange(p),m?.(p,x.getValues())},onInputChange:(F,p,b)=>{b==="input"&&(h.onChange(p),setTimeout(()=>{C?.(p,x.getValues())},0))},slotProps:{...d.slotProps||{},paper:{...d.slotProps?.paper||{},sx:{border:`1px solid ${_t.neutral[30]}`,boxShadow:"0px 2px 4px rgba(0, 0, 0, 0.15)"}}},isOptionEqualToValue:(F,p)=>F.value===p.value,renderOption:(F,p)=>Ht("li",{...F,key:p.key||p.value,onClick:b=>{F.onClick?.(b),h.onChange(p)}},Je(ye,{container:!0,direction:"column",children:[Q(ye,{item:!0,children:p.label}),p.afterLabel&&Q(ye,{item:!0,children:p.afterLabel})]})),value:h.value||null,readOnly:d.disabled,noOptionsText:c||"Nenhuma op\xE7\xE3o encontrada",...d,renderInput:F=>Q(qt,{placeholder:y,...F,error:!!a,slotProps:{input:{inputProps:F.inputProps,inputRef:h.ref}}})},e),Q(k,{name:e,disableIcon:u})]})})},jt=zt(Ut);import{Autocomplete as Qt,Divider as Ke,TextField as Zt}from"@mui/material";import{colorPalette as ei}from"@s_mart/tokens";import{isEqual as oi}from"lodash-es";import{forwardRef as ri}from"react";import{useController as ti,useFormContext as ii}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 Pe}from"react/jsx-runtime";var Kt=({title:e})=>Pe(Wt,{title:e,placement:"top",children:Pe("div",{style:{width:"fit-content"},children:Pe(Yt,{icon:Jt,color:"#757575"})})}),Z=Kt;import{memo as Xt}from"react";var te=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:m,multiple:u,info:d,placeholder:x,onChange:a,onInputChange:h,getOptionAfterLabel:F,getOptionLabel:p,getOptionKey:b,...s})=>{let f=ii();if(!f)throw new Error("Para usar o <SearchableV2 /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let w=E(f.formState.errors,e),{field:$}=ti({name:e,control:f.control,rules:t,defaultValue:i,shouldUnregister:n});return ee("div",{style:{display:"flex",flexDirection:"column"},children:[ee("div",{style:{display:"flex"},children:[l&&q(P,{label:l,required:g}),d&&q(Z,{title:d})]}),q(Qt,{onChange:(r,o)=>{$.onChange(o),a?.(o)},onInputChange:(r,o,T)=>{T==="input"&&h?.(o)},value:$.value?$.value:u?[]:null,options:c,multiple:u,readOnly:s.disabled,slotProps:{...s.slotProps,paper:{...s.slotProps?.paper,sx:{border:`1px solid ${ei.neutral[30]}`,boxShadow:"0px 2px 4px rgba(0, 0, 0, 0.15)"}},listbox:{component:ri(function(o,T){return ee(Ce,{children:[q("ul",{...o,ref:T}),typeof m<"u"?ee("div",{...o,children:[q("div",{style:{paddingTop:"0.5rem",paddingBottom:"0.5rem"},children:q(Ke,{})}),m()]},"searchable-footer"):null]})})}},noOptionsText:ee(Ce,{children:[C||"Nenhuma op\xE7\xE3o encontrada",typeof m<"u"?ee(Ce,{children:[q("div",{style:{paddingTop:"0.5rem",paddingBottom:"0.5rem"},children:q(Ke,{})}),m()]}):null]}),isOptionEqualToValue:(r,o)=>oi(r,o),getOptionLabel:r=>p(r),getOptionKey:r=>b(r),renderOption:typeof F=="function"?(r,o)=>{let T=F(o),S=b(o);return ai("li",{...r,key:S},ee("div",{style:{display:"flex",flexDirection:"column",flex:1},children:[q("span",{children:p(o)}),typeof T=="string"?q("span",{children:T}):T]}))}:void 0,...s,renderInput:r=>q(Zt,{error:!!w,placeholder:x,...r,...y,inputRef:$.ref})},e),q(k,{name:e})]})},ni=te(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 Pi,jsx as O,jsxs as oe}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:m,footer:u,onChange:d,variant:x="outlined",getOptionKey:a,getOptionLabel:h,getOptionAfterLabel:F,getOptionIcon:p,...b})=>{let s=ui(),[f,w]=pi(!1);if(!s)throw new Error("Para usar o <SelectV2 /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let $=E(s.formState.errors,e),{field:r}=mi({control:s.control,name:e,rules:t,defaultValue:i,shouldUnregister:n});return oe("div",{style:{display:"flex",flexDirection:"column"},children:[oe("div",{style:{display:"flex"},children:[l&&O(P,{label:l,required:g}),m&&O(Z,{title:m})]}),oe(bi,{open:f,onOpen:()=>w(!0),onClose:()=>w(!1),displayEmpty:!!y,variant:x,autoComplete:"off",value:r.value||null,renderValue:o=>O(Xe,{getOptionLabel:h,placeholder:y,value:o}),onChange:o=>{r.onChange(o.target.value),d?.(o.target.value)},error:!!$,size:b.size||"medium",inputRef:r.ref,...b,endAdornment:oe(Pi,{children:[b.endAdornment,!!(C&&r.value)&&O(fi,{variant:"text",color:"neutral",size:"small",sx:{borderRadius:"50%",position:"absolute",right:"2rem"},style:{padding:0},"aria-label":"Limpar",title:"Limpar",onClick:()=>{r.onChange(null),d?.(null)},children:O(ci,{icon:yi,color:xi.neutral[100],size:"25px",removeMargin:!0})})]}),children:[c.map(o=>{let T=a(o),S=h(o),_=p?.(o);return O(Fi,{value:o,children:oe("div",{style:{display:"flex",flexDirection:"column",flex:1},children:[_!==void 0?oe("div",{style:{display:"flex",alignItems:"center"},children:[_,S]}):S,O("span",{children:F?.(o)??null})]})},T)}),u!==void 0&&oe("div",{children:[O("div",{style:{padding:"8px 16px"},children:O(gi,{})},"footer-divider"),O("div",{children:u({closeSelect:()=>w(!1)})},"footer-content")]},"footer")]},e),O(k,{name:e})]})},vi=te(hi);import{forwardRef as Si,useCallback as ki,useState as Ii}from"react";import{useController as Vi,useFormContext as wi}from"react-hook-form";import{isObject as Ri,isEmpty as Ei,isEqual as Ai}from"lodash-es";import{Autocomplete as Bi,TextField as Li,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;
|
|
@@ -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 L,jsxs as N}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:m,onEditOption:u,onCreateOption:d,getOptionKey:x,getOptionLabel:a,getOptionAfterLabel:h,textFieldProps:F,multiple:p,info:b,noOptionsText:s,onChange:f,onInputChange:w,placeholder:$,...r})=>{let[o,T]=Ii(""),S=wi();if(!S)throw new Error("Para usar o <CreatableV2 /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let _=E(S.formState.errors,e),R=!C||r.disabled,{field:D}=Vi({name:e,control:S.control,rules:t,defaultValue:i,shouldUnregister:n}),be=V=>{let B=0;return F?.InputProps||(B+=2.5),R||(B+=2.56,ie(V)&&(B+=2.56)),!r.disableClearable&&!r.disabled&&(B+=1.3),B+"rem"},ie=V=>r.disabled?!1:m&&Ri(V)&&!Ei(V),A=()=>r.disabled?!1:C,v=ki(()=>{typeof d<"u"&&(d(o),T(""))},[o]),le=V=>{u?.(V)};return N("div",{style:{display:"flex",flexDirection:"column"},children:[N("div",{style:{display:"flex"},children:[l&&L(P,{label:l,required:g}),b&&L(Z,{title:b})]}),L(Ze,{children:L(Bi,{fullWidth:!0,onChange:(V,B)=>{T(""),D.onChange(B),f?.(B)},onInputChange:(V,B,Y)=>{Y==="input"&&(T(B),w?.(B))},slotProps:{...r.slotProps,paper:{...r.slotProps?.paper,sx:{border:`1px solid ${Mi.neutral[30]}`,boxShadow:"0px 2px 4px rgba(0, 0, 0, 0.15)"}},listbox:{component:Si(function(B,Y){return N(Se,{children:[L("ul",{...B,ref:Y}),typeof y<"u"?N("div",{...B,children:[L("div",{style:{paddingTop:"0.5rem",paddingBottom:"0.5rem"},children:L(eo,{})}),y()]},"creatable-footer"):null]})})}},value:D.value?D.value:p?[]:null,options:c,multiple:p,readOnly:r.disabled,noOptionsText:N(Se,{children:[s||"Nenhuma op\xE7\xE3o encontrada",!R&&N(Gi,{sx:{justifyContent:"flex-start",padding:`${ro(6)} ${ro(-16)}`,margin:0},fullWidth:!0,onClick:v,variant:"text",startIcon:L(Te,{icon:oo}),children:["Adicionar ",`"${o}"`]}),typeof y<"u"&&N(Se,{children:[L("div",{style:{paddingTop:"0.5rem",paddingBottom:"0.5rem"},children:L(eo,{})}),y()]})]}),isOptionEqualToValue:(V,B)=>Ai(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},N("div",{style:{display:"flex",flexDirection:"column",flex:1},children:[L("span",{children:a(B)}),typeof Y=="string"?L("span",{children:Y}):Y]}))}:void 0,...r,sx:{"& div.MuiInputBase-root":{paddingRight:`${be(D.value)} !important`},...r.sx},onBlur:V=>{r?.onBlur?.(V),T("")},renderInput:V=>L(Li,{placeholder:$,...V,error:!!_,...F,slotProps:{input:{...V.InputProps,...F?.InputProps,inputRef:D.ref,endAdornment:N("div",{className:"endAdornments",children:[V.InputProps.endAdornment,F?.InputProps?.endAdornment??null,ie(D.value)?N("div",{className:"editable",children:[L("div",{className:"divider"}),L("div",{className:"button",onClick:()=>le(D.value),children:L(Te,{icon:$i,size:"24px",removeMargin:!0})})]}):null,A()&&N("div",{className:"creatable",children:[L("div",{className:"divider"}),L("div",{className:"button",onClick:v,children:L(Te,{icon:oo,size:"24px",removeMargin:!0})})]})]})}}})},e)}),L(k,{name:e})]})},qi=te(Di);export{jt as Autocomplete,Vr as Checkbox,Pr as Creatable,qi as CreatableV2,bt as DatePicker,P as FieldLabel,uo as Form,Fe as FormProvider,Or as RadioButton,Yr as RadioGroup,lr as Searchable,ni as SearchableV2,Wo as Select,vi as SelectV2,et as Slider,Mr as Switch,Bo as TextField,Mt as TimePicker,ge as useForm};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@s_mart/form",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"main": "./dist/index.mjs",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.mts",
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"react-hook-form": "^7.51.0",
|
|
32
32
|
"typescript": ">=5.4.2",
|
|
33
33
|
"zod": "^3.22.4",
|
|
34
|
-
"@s_mart/core": "
|
|
34
|
+
"@s_mart/core": "9.0.0",
|
|
35
35
|
"@s_mart/masks": "5.2.0",
|
|
36
|
-
"@s_mart/rules": "5.1.1",
|
|
37
36
|
"@s_mart/tokens": "5.1.1",
|
|
38
37
|
"@s_mart/typed": "7.2.1",
|
|
39
|
-
"@s_mart/utils": "5.3.
|
|
38
|
+
"@s_mart/utils": "5.3.4",
|
|
39
|
+
"@s_mart/rules": "5.1.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@emotion/styled": "^11.13.0",
|
|
@@ -48,12 +48,12 @@
|
|
|
48
48
|
"@types/react-dom": ">=18.3.1",
|
|
49
49
|
"dayjs": "^1.11.10",
|
|
50
50
|
"typescript": ">=5.4.2",
|
|
51
|
-
"@s_mart/core": "8.0.4",
|
|
52
51
|
"@s_mart/masks": "5.2.0",
|
|
53
52
|
"@s_mart/rules": "5.1.1",
|
|
53
|
+
"@s_mart/core": "9.0.0",
|
|
54
54
|
"@s_mart/tokens": "5.1.1",
|
|
55
55
|
"@s_mart/typed": "7.2.1",
|
|
56
|
-
"@s_mart/utils": "5.3.
|
|
56
|
+
"@s_mart/utils": "5.3.4"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "tsup src/index.tsx --minify --format esm --dts --external react",
|