@s_mart/form 2.5.3 → 2.5.4
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.ts +30 -3
- package/dist/index.js +14 -14
- package/dist/index.mjs +8 -8
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -13,9 +13,16 @@ type ControllerTextField = Omit<ControllerProps, 'render' | 'control'>;
|
|
|
13
13
|
type Masks = 'cpf' | 'cnpj' | 'cpfCnpj' | 'cep' | 'telefone' | 'decimal' | 'porcentagem' | 'numero' | 'placa' | 'valor';
|
|
14
14
|
type TextFieldProps = TextFieldProps$1 & ControllerTextField & {
|
|
15
15
|
mask?: Masks;
|
|
16
|
+
/**
|
|
17
|
+
* @description Função que será executada quando o valor do input for alterado
|
|
18
|
+
* @param event Evento de alteração do input
|
|
19
|
+
*
|
|
20
|
+
* @example onInputChange={(event) => console.log(event.target.value)}
|
|
21
|
+
*/
|
|
22
|
+
onInputChange?: (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
16
23
|
};
|
|
17
24
|
|
|
18
|
-
declare const TextField: ({ name, rules, defaultValue, shouldUnregister, label, required, mask, variant, ...rest }: TextFieldProps) => JSX.Element;
|
|
25
|
+
declare const TextField: ({ name, rules, defaultValue, shouldUnregister, label, required, mask, variant, onInputChange, ...rest }: TextFieldProps) => JSX.Element;
|
|
19
26
|
|
|
20
27
|
type ControllerSelect = Omit<ControllerProps, 'render' | 'control'>;
|
|
21
28
|
type SelectOption = {
|
|
@@ -57,9 +64,19 @@ type SearchableProps = Omit<AutocompleteProps<SearchableOption, true, true, true
|
|
|
57
64
|
textFieldProps?: TextFieldProps$1;
|
|
58
65
|
label?: React.ReactNode;
|
|
59
66
|
required?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* @description Função que será executada quando o valor do input for alterado
|
|
69
|
+
* @param values Valor do input alterado
|
|
70
|
+
*
|
|
71
|
+
* @example onInputChange={(values) => console.log(values)}
|
|
72
|
+
*/
|
|
73
|
+
onInputChange?: (event: (string | {
|
|
74
|
+
label: string;
|
|
75
|
+
value: string | number | readonly string[] | undefined;
|
|
76
|
+
})[]) => void;
|
|
60
77
|
};
|
|
61
78
|
|
|
62
|
-
declare const Searchable: ({ name, rules, defaultValue, shouldUnregister, label, required, options, textFieldProps, ...rest }: SearchableProps) => JSX.Element;
|
|
79
|
+
declare const Searchable: ({ name, rules, defaultValue, shouldUnregister, label, required, options, textFieldProps, onInputChange, ...rest }: SearchableProps) => JSX.Element;
|
|
63
80
|
|
|
64
81
|
type ControllerCreatable = Omit<ControllerProps, 'render' | 'control'>;
|
|
65
82
|
type CreatableOption = {
|
|
@@ -115,9 +132,19 @@ type CreatableProps = Omit<AutocompleteProps<CreatableOption, true, true, true>,
|
|
|
115
132
|
* @memberof CreatableProps
|
|
116
133
|
*/
|
|
117
134
|
hideAddButton?: boolean;
|
|
135
|
+
/**
|
|
136
|
+
* @description Função que será executada quando o valor do input for alterado
|
|
137
|
+
* @param values Valor do input alterado
|
|
138
|
+
*
|
|
139
|
+
* @example onInputChange={(values) => console.log(values)}
|
|
140
|
+
*/
|
|
141
|
+
onInputChange?: (event: (string | {
|
|
142
|
+
label: string;
|
|
143
|
+
value?: string | number | readonly string[] | undefined;
|
|
144
|
+
})[]) => void;
|
|
118
145
|
};
|
|
119
146
|
|
|
120
|
-
declare const Creatable: ({ name, rules, defaultValue, shouldUnregister, label, required, options, onCreateOption, textFieldProps, hideAddButton, ...rest }: CreatableProps) => JSX.Element;
|
|
147
|
+
declare const Creatable: ({ name, rules, defaultValue, shouldUnregister, label, required, options, onCreateOption, textFieldProps, hideAddButton, onInputChange, ...rest }: CreatableProps) => JSX.Element;
|
|
121
148
|
|
|
122
149
|
type ControllerCheckbox = Omit<ControllerProps, 'render' | 'control'>;
|
|
123
150
|
type CheckboxProps = CheckboxProps$1 & ControllerCheckbox & {
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var Ve=Object.create;var _=Object.defineProperty,Ue=Object.defineProperties,Ne=Object.getOwnPropertyDescriptor,ke=Object.getOwnPropertyDescriptors,ve=Object.getOwnPropertyNames,j=Object.getOwnPropertySymbols,Ie=Object.getPrototypeOf,le=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable;var me=(e,r,o)=>r in e?_(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o,n=(e,r)=>{for(var o in r||(r={}))le.call(r,o)&&me(e,o,r[o]);if(j)for(var o of j(r))pe.call(r,o)&&me(e,o,r[o]);return e},P=(e,r)=>Ue(e,ke(r));var u=(e,r)=>{var o={};for(var l in e)le.call(e,l)&&r.indexOf(l)<0&&(o[l]=e[l]);if(e!=null&&j)for(var l of j(e))r.indexOf(l)<0&&pe.call(e,l)&&(o[l]=e[l]);return o};var Oe=(e,r)=>{for(var o in r)_(e,o,{get:r[o],enumerable:!0})},fe=(e,r,o,l)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of ve(r))!le.call(e,t)&&t!==o&&_(e,t,{get:()=>r[t],enumerable:!(l=Ne(r,t))||l.enumerable});return e};var ue=(e,r,o)=>(o=e!=null?Ve(Ie(e)):{},fe(r||!e||!e.__esModule?_(o,"default",{value:e,enumerable:!0}):o,e)),ze=e=>fe(_({},"__esModule",{value:!0}),e);var er={};Oe(er,{Checkbox:()=>Ae,Creatable:()=>Ge,Form:()=>xe,RadioButton:()=>Le,RadioGroup:()=>qe,Searchable:()=>Ce,Select:()=>Se,Slider:()=>Me,Switch:()=>De,TextField:()=>ge});module.exports=ze(er);var ce=require("react"),H=require("react-hook-form");var ie=require("react/jsx-runtime");function _e(l){var t=l,{children:e,onSubmit:r}=t,o=u(t,["children","onSubmit"]);let d=(0,H.useForm)(o);(0,ce.useEffect)(()=>{d.reset(o.defaultValues)},[o.defaultValues,d.reset]);let s=()=>typeof e=="function"?e(P(n({},d),{onSubmit:d.handleSubmit(r)})):e;return(0,ie.jsx)(H.FormProvider,P(n({},d),{children:(0,ie.jsx)("form",{onSubmit:d.handleSubmit(r),children:s()})}))}var xe=_e;var Pe=require("react"),K=require("react-hook-form"),J=require("phosphor-react"),N=require("@mui/material"),U=ue(require("@s_mart/masks"));var ne=require("@mui/material"),ye=require("@s_mart/utils"),B=require("react/jsx-runtime"),F=({label:e,required:r,regular:o})=>(0,B.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:(0,ye.toRem)(2)},children:[(0,B.jsx)(ne.Typography,{variant:"caption",fontWeight:o?400:700,style:{display:"flex",alignItems:"center"},children:e}),r&&(0,B.jsx)(ne.Typography,{variant:"caption",fontWeight:900,color:"error",children:"*"})]});var be=require("react-hook-form"),Fe=require("@s_mart/core"),he=require("react/jsx-runtime"),S=({name:e})=>{var o,l,t;let r=(0,be.useFormContext)();return(l=(o=r==null?void 0:r.formState)==null?void 0:o.errors)!=null&&l[e]?(0,he.jsx)(Fe.Indicator,{severity:"error",children:(t=r.formState.errors[e])==null?void 0:t.message}):null};var E=require("react/jsx-runtime"),Be=b=>{var f=b,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:d,mask:s,variant:y="outlined",onInputChange:m}=f,p=u(f,["name","rules","defaultValue","shouldUnregister","label","required","mask","variant","onInputChange"]);let C=(0,K.useFormContext)();if(!C)throw new Error("Para usar o <TextField /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let[w,A]=(0,Pe.useState)(!1),g=c=>{var a;return s?(a=U==null?void 0:U[s])==null?void 0:a.format(c):c},i=c=>{var a;return s?(a=U==null?void 0:U[s])==null?void 0:a.parse(c):c},V=c=>{if(!c||s!=="porcentagem")return;c==null||c.stopPropagation();let a=(c==null?void 0:c.target).value;if(a){let x=String(a);if(x.length>0){let z=x.indexOf("%");z>-1&&(c.currentTarget.selectionEnd=z)}}};return(0,E.jsx)(K.Controller,{control:C.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:c,onChange:a}})=>(0,E.jsxs)(N.Grid,{display:"flex",flexDirection:"column",children:[t&&(0,E.jsx)(F,{label:t,required:d}),(0,E.jsx)(N.TextField,P(n({size:"small",variant:y,autoComplete:"off",defaultValue:o,value:g(c||""),onChange:x=>{var z;m==null||m(x),a(i((z=x==null?void 0:x.target)==null?void 0:z.value))}},p),{type:p.type==="password"?w?"text":"password":p.type,InputProps:n({onKeyDown:V,endAdornment:p.type==="password"&&(0,E.jsx)(N.InputAdornment,{position:"end",onClick:()=>A(!w),style:{cursor:"pointer"},children:w?(0,E.jsx)(J.Eye,{size:20}):(0,E.jsx)(J.EyeSlash,{size:20})})},p.InputProps)})),(0,E.jsx)(S,{name:e})]})})},ge=Be;var Q=require("react-hook-form"),R=require("@mui/material");var T=require("react/jsx-runtime"),We=b=>{var f=b,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:d,options:s,placeholder:y,onInputChange:m}=f,p=u(f,["name","rules","defaultValue","shouldUnregister","label","required","options","placeholder","onInputChange"]);let C=(0,Q.useFormContext)(),{palette:w}=(0,R.useTheme)();if(!C)throw new Error("Para usar o <Select /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,T.jsx)(Q.Controller,{control:C.control,name:e,rules:r,defaultValue:o||"",shouldUnregister:l,render:({field:{value:A,onChange:g}})=>(0,T.jsxs)(R.Grid,{display:"flex",flexDirection:"column",children:[t&&(0,T.jsx)(F,{label:t,required:d}),(0,T.jsxs)(R.Select,P(n({displayEmpty:Boolean(y),size:"small",variant:"outlined",autoComplete:"off",value:A||"",onChange:i=>{m==null||m(i),g(i.target.value)}},p),{children:[y&&(0,T.jsx)(R.MenuItem,{disabled:!0,value:"",children:(0,T.jsx)("p",{style:{color:w.grey[400]},children:y})}),s==null?void 0:s.map((i,V)=>(0,T.jsx)(R.MenuItem,{value:i.value,children:i.label},V))]})),(0,T.jsx)(S,{name:e})]})})},Se=We;var X=require("react-hook-form"),k=require("@mui/material");var D=require("react/jsx-runtime"),je=b=>{var f=b,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:d,options:s,textFieldProps:y,onInputChange:m}=f,p=u(f,["name","rules","defaultValue","shouldUnregister","label","required","options","textFieldProps","onInputChange"]);let C=(0,X.useFormContext)();if(!C)throw new Error("Para usar o <Searchable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,D.jsx)(X.Controller,{control:C.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{onChange:w,value:A}})=>(0,D.jsxs)(k.Grid,{display:"flex",flexDirection:"column",children:[t&&(0,D.jsx)(F,{label:t,required:d}),(0,D.jsx)(k.Autocomplete,P(n({size:"small",onChange:(g,i)=>(m==null||m(i),w(i)),value:A||null,options:s,noOptionsText:"Nenhuma op\xE7\xE3o encontrada",isOptionEqualToValue:(g,i)=>typeof g=="string"&&typeof i=="string"?g===i:typeof g=="object"&&typeof i=="object"?g.value===i.value:!1},p),{renderInput:g=>(0,D.jsx)(k.TextField,n(n({},g),y))})),(0,D.jsx)(S,{name:e})]})})},Ce=je;var Y=require("react-hook-form"),Re=require("phosphor-react"),L=require("@mui/material");var G=require("@s_mart/utils"),se=ue(require("@emotion/styled")),ae=require("@emotion/react"),we=ae.css`
|
|
2
2
|
display: flex;
|
|
3
3
|
align-items: center;
|
|
4
4
|
justify-content: center;
|
|
5
|
-
`,
|
|
5
|
+
`,He=e=>ae.css`
|
|
6
6
|
.MuiAutocomplete-endAdornment {
|
|
7
7
|
position: relative;
|
|
8
8
|
right: 0;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
.creatable {
|
|
12
|
-
${
|
|
12
|
+
${we}
|
|
13
13
|
|
|
14
14
|
.divider {
|
|
15
15
|
width: 1px;
|
|
16
|
-
height: ${(0,
|
|
16
|
+
height: ${(0,G.toRem)(20)};
|
|
17
17
|
background-color: ${e.palette.grey[400]};
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
color: ${e.palette.grey[600]};
|
|
25
25
|
border-radius: 50%;
|
|
26
26
|
|
|
27
|
-
margin: 0 ${(0,
|
|
28
|
-
width: ${(0,
|
|
29
|
-
height: ${(0,
|
|
27
|
+
margin: 0 ${(0,G.toRem)(6)};
|
|
28
|
+
width: ${(0,G.toRem)(28)};
|
|
29
|
+
height: ${(0,G.toRem)(28)};
|
|
30
30
|
|
|
31
31
|
&:hover {
|
|
32
32
|
cursor: pointer;
|
|
@@ -35,26 +35,26 @@
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
`,
|
|
38
|
+
`,Ee=se.default.div`
|
|
39
39
|
display: flex;
|
|
40
40
|
|
|
41
41
|
div.endAdornments {
|
|
42
42
|
position: absolute;
|
|
43
43
|
right: 0;
|
|
44
44
|
|
|
45
|
-
${
|
|
45
|
+
${we}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
${({hideAddButton:e,theme:r})=>!e&&
|
|
49
|
-
`,
|
|
48
|
+
${({hideAddButton:e,theme:r})=>!e&&He(r)}
|
|
49
|
+
`,Te=se.default.div`
|
|
50
50
|
color: ${({theme:e})=>e.palette.text.primary};
|
|
51
51
|
|
|
52
|
-
padding: ${(0,
|
|
53
|
-
margin: ${(0,
|
|
52
|
+
padding: ${(0,G.toRem)(6)} ${(0,G.toRem)(16)};
|
|
53
|
+
margin: ${(0,G.toRem)(-6)} ${(0,G.toRem)(-16)};
|
|
54
54
|
|
|
55
55
|
&:hover {
|
|
56
56
|
cursor: pointer;
|
|
57
57
|
transition: background-color 0.2s ease-in-out;
|
|
58
58
|
background-color: ${({theme:e})=>e.palette.grey[100]};
|
|
59
59
|
}
|
|
60
|
-
`;var h=require("react/jsx-runtime"),
|
|
60
|
+
`;var h=require("react/jsx-runtime"),Ke=C=>{var w=C,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:d,options:s,onCreateOption:y,textFieldProps:m,hideAddButton:p,onInputChange:b}=w,f=u(w,["name","rules","defaultValue","shouldUnregister","label","required","options","onCreateOption","textFieldProps","hideAddButton","onInputChange"]);let A=(0,Y.useFormContext)();if(!A)throw new Error("Para usar o <Creatable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let g=i=>{y?y(i):console.error("onCreateOption n\xE3o foi definido")};return(0,h.jsx)(Y.Controller,{control:A.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:i,onChange:V}})=>{let c=(i==null?void 0:i.label)||(i==null?void 0:i.value)||i;return(0,h.jsxs)(L.Grid,{display:"flex",flexDirection:"column",children:[t&&(0,h.jsx)(F,{label:t,required:d}),(0,h.jsx)(Ee,{hideAddButton:p,children:(0,h.jsx)(L.Autocomplete,P(n({size:"small",fullWidth:!0,onChange:(a,x)=>(b==null||b(x),V(x)),options:s,value:i||null,noOptionsText:(0,h.jsx)(Te,{onClick:()=>g(i),children:(0,h.jsxs)(L.Typography,{children:["Adicionar ",c&&`"${c}"`]})}),isOptionEqualToValue:(a,x)=>x?typeof a=="string"&&typeof x=="string"?a===x:typeof a=="object"&&typeof x=="object"?a.value===x.value:typeof a=="object"&&typeof x=="string":!1},f),{renderInput:a=>{let x=p?a.InputProps:P(n({},a.InputProps),{endAdornment:(0,h.jsxs)("div",{className:"endAdornments",children:[a.InputProps.endAdornment,(0,h.jsxs)("div",{className:"creatable",children:[(0,h.jsx)("div",{className:"divider"}),(0,h.jsx)("div",{className:"button",onClick:()=>g(i),children:(0,h.jsx)(Re.Plus,{size:18,weight:"bold"})})]})]})});return(0,h.jsx)(L.TextField,n(P(n({},a),{onChange:V,InputProps:x}),m))}}))}),(0,h.jsx)(S,{name:e})]})}})},Ge=Ke;var Z=require("react-hook-form"),v=require("@mui/material");var q=require("react/jsx-runtime"),Je=m=>{var p=m,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,labelPlacement:d,required:s}=p,y=u(p,["name","rules","defaultValue","shouldUnregister","label","labelPlacement","required"]);let b=(0,Z.useFormContext)();if(!b)throw new Error("Para usar o <Checkbox /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,q.jsx)(Z.Controller,{control:b.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:f,onChange:C}})=>(0,q.jsxs)(v.Grid,{display:"flex",flexDirection:"column",children:[(0,q.jsx)(v.FormControlLabel,{control:(0,q.jsx)(v.Checkbox,n({value:f!=null?f:"",defaultValue:f,onChange:C},y)),label:(0,q.jsx)(F,{label:t,required:s,regular:!0}),labelPlacement:d||"end"}),(0,q.jsx)(S,{name:e})]})})},Ae=Je;var ee=require("react-hook-form"),I=require("@mui/material");var $=require("react/jsx-runtime"),Qe=y=>{var m=y,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,labelPlacement:d}=m,s=u(m,["name","rules","defaultValue","shouldUnregister","label","labelPlacement"]);let p=(0,ee.useFormContext)();if(!p)throw new Error("Para usar o <Switch /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,$.jsx)(ee.Controller,{control:p.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:b,onChange:f}})=>(0,$.jsxs)(I.Grid,{display:"flex",flexDirection:"column",children:[(0,$.jsx)(I.FormControlLabel,{control:(0,$.jsx)(I.Switch,n({value:b!=null?b:"",defaultValue:b,onChange:f},s)),label:(0,$.jsx)(F,{label:t}),labelPlacement:d||"end"}),(0,$.jsx)(S,{name:e})]})})},De=Qe;var O=require("@mui/material");var W=require("react/jsx-runtime"),Xe=l=>{var t=l,{label:e,labelPlacement:r}=t,o=u(t,["label","labelPlacement"]);return(0,W.jsx)(O.Grid,{display:"flex",flexDirection:"column",children:(0,W.jsx)(O.FormControlLabel,{control:(0,W.jsx)(O.Radio,n({},o)),label:(0,W.jsx)(F,{label:e}),labelPlacement:r||"end"})})},Le=Xe;var re=require("react-hook-form"),oe=require("@mui/material");var M=require("react/jsx-runtime"),Ye=p=>{var b=p,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:d,children:s,orientation:y="row"}=b,m=u(b,["name","rules","defaultValue","shouldUnregister","label","required","children","orientation"]);let f=(0,re.useFormContext)();if(!f)throw new Error("Para usar o <RadioGroup /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,M.jsx)(re.Controller,{control:f.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:C,onChange:w}})=>(0,M.jsxs)(oe.Grid,{display:"flex",flexDirection:"column",children:[t&&(0,M.jsx)(F,{label:t,required:d}),(0,M.jsx)(oe.RadioGroup,P(n({value:C||"",onChange:w,name:e},m),{style:{display:"flex",flexDirection:y},children:s})),(0,M.jsx)(S,{name:e})]})})},qe=Ye;var te=require("react-hook-form"),$e=require("@mui/material");var de=require("react/jsx-runtime"),Ze=d=>{var s=d,{name:e,rules:r,defaultValue:o,shouldUnregister:l}=s,t=u(s,["name","rules","defaultValue","shouldUnregister"]);let y=(0,te.useFormContext)();if(!y)throw new Error("Para usar o <Slider /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,de.jsx)(te.Controller,{control:y.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:m,onChange:p}})=>(0,de.jsx)($e.Slider,n({value:m||(t==null?void 0:t.min)||0,onChange:p,valueLabelDisplay:"auto"},t))})},Me=Ze;0&&(module.exports={Checkbox,Creatable,Form,RadioButton,RadioGroup,Searchable,Select,Slider,Switch,TextField});
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Z=Object.defineProperty,ee=Object.defineProperties;var re=Object.getOwnPropertyDescriptors;var V=Object.getOwnPropertySymbols;var I=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable;var v=(e,r,o)=>r in e?Z(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o,n=(e,r)=>{for(var o in r||(r={}))I.call(r,o)&&v(e,o,r[o]);if(V)for(var o of V(r))O.call(r,o)&&v(e,o,r[o]);return e},h=(e,r)=>ee(e,re(r));var u=(e,r)=>{var o={};for(var l in e)I.call(e,l)&&r.indexOf(l)<0&&(o[l]=e[l]);if(e!=null&&V)for(var l of V(e))r.indexOf(l)<0&&O.call(e,l)&&(o[l]=e[l]);return o};import{useEffect as oe}from"react";import{FormProvider as te,useForm as le}from"react-hook-form";import{jsx as z}from"react/jsx-runtime";function ie(l){var t=l,{children:e,onSubmit:r}=t,o=u(t,["children","onSubmit"]);let d=le(o);oe(()=>{d.reset(o.defaultValues)},[o.defaultValues,d.reset]);let s=()=>typeof e=="function"?e(h(n({},d),{onSubmit:d.handleSubmit(r)})):e;return z(te,h(n({},d),{children:z("form",{onSubmit:d.handleSubmit(r),children:s()})}))}var ne=ie;import{useState as fe}from"react";import{Controller as ue,useFormContext as ce}from"react-hook-form";import{Eye as xe,EyeSlash as ye}from"phosphor-react";import{Grid as be,InputAdornment as Fe,TextField as he}from"@mui/material";import*as A from"@s_mart/masks";import{Typography as _}from"@mui/material";import{toRem as se}from"@s_mart/utils";import{jsx as B,jsxs as ae}from"react/jsx-runtime";var F=({label:e,required:r,regular:o})=>ae("span",{style:{display:"flex",alignItems:"center",gap:se(2)},children:[B(_,{variant:"caption",fontWeight:o?400:700,style:{display:"flex",alignItems:"center"},children:e}),r&&B(_,{variant:"caption",fontWeight:900,color:"error",children:"*"})]});import{useFormContext as de}from"react-hook-form";import{Indicator as me}from"@s_mart/core";import{jsx as pe}from"react/jsx-runtime";var g=({name:e})=>{var o,l,t;let r=de();return(l=(o=r==null?void 0:r.formState)==null?void 0:o.errors)!=null&&l[e]?pe(me,{severity:"error",children:(t=r.formState.errors[e])==null?void 0:t.message}):null};import{jsx as R,jsxs as Se}from"react/jsx-runtime";var Pe=b=>{var f=b,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:d,mask:s,variant:y="outlined",onInputChange:m}=f,p=u(f,["name","rules","defaultValue","shouldUnregister","label","required","mask","variant","onInputChange"]);let S=ce();if(!S)throw new Error("Para usar o <TextField /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let[C,E]=fe(!1),P=c=>{var a;return s?(a=A==null?void 0:A[s])==null?void 0:a.format(c):c},i=c=>{var a;return s?(a=A==null?void 0:A[s])==null?void 0:a.parse(c):c},G=c=>{if(!c||s!=="porcentagem")return;c==null||c.stopPropagation();let a=(c==null?void 0:c.target).value;if(a){let x=String(a);if(x.length>0){let L=x.indexOf("%");L>-1&&(c.currentTarget.selectionEnd=L)}}};return R(ue,{control:S.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:c,onChange:a}})=>Se(be,{display:"flex",flexDirection:"column",children:[t&&R(F,{label:t,required:d}),R(he,h(n({size:"small",variant:y,autoComplete:"off",defaultValue:o,value:P(c||""),onChange:x=>{var L;m==null||m(x),a(i((L=x==null?void 0:x.target)==null?void 0:L.value))}},p),{type:p.type==="password"?C?"text":"password":p.type,InputProps:n({onKeyDown:G,endAdornment:p.type==="password"&&R(Fe,{position:"end",onClick:()=>E(!C),style:{cursor:"pointer"},children:C?R(xe,{size:20}):R(ye,{size:20})})},p.InputProps)})),R(g,{name:e})]})})},ge=Pe;import{Controller as Ce,useFormContext as we}from"react-hook-form";import{Grid as Ee,Select as Te,MenuItem as W,useTheme as Re}from"@mui/material";import{jsx as D,jsxs as j}from"react/jsx-runtime";var Ge=b=>{var f=b,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:d,options:s,placeholder:y,onInputChange:m}=f,p=u(f,["name","rules","defaultValue","shouldUnregister","label","required","options","placeholder","onInputChange"]);let S=we(),{palette:C}=Re();if(!S)throw new Error("Para usar o <Select /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return D(Ce,{control:S.control,name:e,rules:r,defaultValue:o||"",shouldUnregister:l,render:({field:{value:E,onChange:P}})=>j(Ee,{display:"flex",flexDirection:"column",children:[t&&D(F,{label:t,required:d}),j(Te,h(n({displayEmpty:Boolean(y),size:"small",variant:"outlined",autoComplete:"off",value:E||"",onChange:i=>{m==null||m(i),P(i.target.value)}},p),{children:[y&&D(W,{disabled:!0,value:"",children:D("p",{style:{color:C.grey[400]},children:y})}),s==null?void 0:s.map((i,G)=>D(W,{value:i.value,children:i.label},G))]})),D(g,{name:e})]})})},Ae=Ge;import{Controller as De,useFormContext as Le}from"react-hook-form";import{Grid as qe,Autocomplete as $e,TextField as Me}from"@mui/material";import{jsx as q,jsxs as Ne}from"react/jsx-runtime";var Ve=b=>{var f=b,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:d,options:s,textFieldProps:y,onInputChange:m}=f,p=u(f,["name","rules","defaultValue","shouldUnregister","label","required","options","textFieldProps","onInputChange"]);let S=Le();if(!S)throw new Error("Para usar o <Searchable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return q(De,{control:S.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{onChange:C,value:E}})=>Ne(qe,{display:"flex",flexDirection:"column",children:[t&&q(F,{label:t,required:d}),q($e,h(n({size:"small",onChange:(P,i)=>(m==null||m(i),C(i)),value:E||null,options:s,noOptionsText:"Nenhuma op\xE7\xE3o encontrada",isOptionEqualToValue:(P,i)=>typeof P=="string"&&typeof i=="string"?P===i:typeof P=="object"&&typeof i=="object"?P.value===i.value:!1},p),{renderInput:P=>q(Me,n(n({},P),y))})),q(g,{name:e})]})})},Ue=Ve;import{Controller as ve,useFormContext as Ie}from"react-hook-form";import{Plus as Oe}from"phosphor-react";import{Grid as ze,Autocomplete as _e,TextField as Be,Typography as We}from"@mui/material";import{toRem as T}from"@s_mart/utils";import H from"@emotion/styled";import{css as K}from"@emotion/react";var J=K`
|
|
2
2
|
display: flex;
|
|
3
3
|
align-items: center;
|
|
4
4
|
justify-content: center;
|
|
5
|
-
`,
|
|
5
|
+
`,ke=e=>K`
|
|
6
6
|
.MuiAutocomplete-endAdornment {
|
|
7
7
|
position: relative;
|
|
8
8
|
right: 0;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
.creatable {
|
|
12
|
-
${
|
|
12
|
+
${J}
|
|
13
13
|
|
|
14
14
|
.divider {
|
|
15
15
|
width: 1px;
|
|
@@ -35,18 +35,18 @@ var Y=Object.defineProperty,Z=Object.defineProperties;var ee=Object.getOwnProper
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
`,
|
|
38
|
+
`,Q=H.div`
|
|
39
39
|
display: flex;
|
|
40
40
|
|
|
41
41
|
div.endAdornments {
|
|
42
42
|
position: absolute;
|
|
43
43
|
right: 0;
|
|
44
44
|
|
|
45
|
-
${
|
|
45
|
+
${J}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
${({hideAddButton:e,theme:r})=>!e&&
|
|
49
|
-
`,
|
|
48
|
+
${({hideAddButton:e,theme:r})=>!e&&ke(r)}
|
|
49
|
+
`,X=H.div`
|
|
50
50
|
color: ${({theme:e})=>e.palette.text.primary};
|
|
51
51
|
|
|
52
52
|
padding: ${T(6)} ${T(16)};
|
|
@@ -57,4 +57,4 @@ var Y=Object.defineProperty,Z=Object.defineProperties;var ee=Object.getOwnProper
|
|
|
57
57
|
transition: background-color 0.2s ease-in-out;
|
|
58
58
|
background-color: ${({theme:e})=>e.palette.grey[100]};
|
|
59
59
|
}
|
|
60
|
-
`;import{jsx as
|
|
60
|
+
`;import{jsx as w,jsxs as U}from"react/jsx-runtime";var je=S=>{var C=S,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:d,options:s,onCreateOption:y,textFieldProps:m,hideAddButton:p,onInputChange:b}=C,f=u(C,["name","rules","defaultValue","shouldUnregister","label","required","options","onCreateOption","textFieldProps","hideAddButton","onInputChange"]);let E=Ie();if(!E)throw new Error("Para usar o <Creatable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let P=i=>{y?y(i):console.error("onCreateOption n\xE3o foi definido")};return w(ve,{control:E.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:i,onChange:G}})=>{let c=(i==null?void 0:i.label)||(i==null?void 0:i.value)||i;return U(ze,{display:"flex",flexDirection:"column",children:[t&&w(F,{label:t,required:d}),w(Q,{hideAddButton:p,children:w(_e,h(n({size:"small",fullWidth:!0,onChange:(a,x)=>(b==null||b(x),G(x)),options:s,value:i||null,noOptionsText:w(X,{onClick:()=>P(i),children:U(We,{children:["Adicionar ",c&&`"${c}"`]})}),isOptionEqualToValue:(a,x)=>x?typeof a=="string"&&typeof x=="string"?a===x:typeof a=="object"&&typeof x=="object"?a.value===x.value:typeof a=="object"&&typeof x=="string":!1},f),{renderInput:a=>{let x=p?a.InputProps:h(n({},a.InputProps),{endAdornment:U("div",{className:"endAdornments",children:[a.InputProps.endAdornment,U("div",{className:"creatable",children:[w("div",{className:"divider"}),w("div",{className:"button",onClick:()=>P(i),children:w(Oe,{size:18,weight:"bold"})})]})]})});return w(Be,n(h(n({},a),{onChange:G,InputProps:x}),m))}}))}),w(g,{name:e})]})}})},He=je;import{Controller as Ke,useFormContext as Je}from"react-hook-form";import{Grid as Qe,Checkbox as Xe,FormControlLabel as Ye}from"@mui/material";import{jsx as $,jsxs as rr}from"react/jsx-runtime";var Ze=m=>{var p=m,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,labelPlacement:d,required:s}=p,y=u(p,["name","rules","defaultValue","shouldUnregister","label","labelPlacement","required"]);let b=Je();if(!b)throw new Error("Para usar o <Checkbox /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return $(Ke,{control:b.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:f,onChange:S}})=>rr(Qe,{display:"flex",flexDirection:"column",children:[$(Ye,{control:$(Xe,n({value:f!=null?f:"",defaultValue:f,onChange:S},y)),label:$(F,{label:t,required:s,regular:!0}),labelPlacement:d||"end"}),$(g,{name:e})]})})},er=Ze;import{Controller as or,useFormContext as tr}from"react-hook-form";import{Grid as lr,Switch as ir,FormControlLabel as nr}from"@mui/material";import{jsx as M,jsxs as dr}from"react/jsx-runtime";var sr=y=>{var m=y,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,labelPlacement:d}=m,s=u(m,["name","rules","defaultValue","shouldUnregister","label","labelPlacement"]);let p=tr();if(!p)throw new Error("Para usar o <Switch /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return M(or,{control:p.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:b,onChange:f}})=>dr(lr,{display:"flex",flexDirection:"column",children:[M(nr,{control:M(ir,n({value:b!=null?b:"",defaultValue:b,onChange:f},s)),label:M(F,{label:t}),labelPlacement:d||"end"}),M(g,{name:e})]})})},ar=sr;import{Grid as mr,Radio as pr,FormControlLabel as fr}from"@mui/material";import{jsx as N}from"react/jsx-runtime";var ur=l=>{var t=l,{label:e,labelPlacement:r}=t,o=u(t,["label","labelPlacement"]);return N(mr,{display:"flex",flexDirection:"column",children:N(fr,{control:N(pr,n({},o)),label:N(F,{label:e}),labelPlacement:r||"end"})})},cr=ur;import{Controller as xr,useFormContext as yr}from"react-hook-form";import{Grid as br,RadioGroup as Fr}from"@mui/material";import{jsx as k,jsxs as gr}from"react/jsx-runtime";var hr=p=>{var b=p,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:d,children:s,orientation:y="row"}=b,m=u(b,["name","rules","defaultValue","shouldUnregister","label","required","children","orientation"]);let f=yr();if(!f)throw new Error("Para usar o <RadioGroup /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return k(xr,{control:f.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:S,onChange:C}})=>gr(br,{display:"flex",flexDirection:"column",children:[t&&k(F,{label:t,required:d}),k(Fr,h(n({value:S||"",onChange:C,name:e},m),{style:{display:"flex",flexDirection:y},children:s})),k(g,{name:e})]})})},Pr=hr;import{Controller as Sr,useFormContext as Cr}from"react-hook-form";import{Slider as wr}from"@mui/material";import{jsx as Y}from"react/jsx-runtime";var Er=d=>{var s=d,{name:e,rules:r,defaultValue:o,shouldUnregister:l}=s,t=u(s,["name","rules","defaultValue","shouldUnregister"]);let y=Cr();if(!y)throw new Error("Para usar o <Slider /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return Y(Sr,{control:y.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:m,onChange:p}})=>Y(wr,n({value:m||(t==null?void 0:t.min)||0,onChange:p,valueLabelDisplay:"auto"},t))})},Tr=Er;export{er as Checkbox,He as Creatable,ne as Form,cr as RadioButton,Pr as RadioGroup,Ue as Searchable,Ae as Select,Tr as Slider,ar as Switch,ge as TextField};
|