@s_mart/form 2.5.5 → 2.6.1
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 +15 -2
- package/dist/index.js +21 -14
- package/dist/index.mjs +15 -8
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { UseFormProps, UseFormReturn, ControllerProps } from 'react-hook-form';
|
|
1
|
+
import { UseFormProps, UseFormReturn, ControllerProps, UseControllerProps } from 'react-hook-form';
|
|
2
2
|
import { TextFieldProps as TextFieldProps$1, SelectProps as SelectProps$1, SelectChangeEvent, AutocompleteProps, CheckboxProps as CheckboxProps$1, SwitchProps as SwitchProps$1, RadioProps as RadioProps$1, RadioGroupProps as RadioGroupProps$1, SliderProps as SliderProps$1 } from '@mui/material';
|
|
3
|
+
import { DatePickerProps as DatePickerProps$1 } from '@mui/x-date-pickers';
|
|
3
4
|
|
|
4
5
|
interface IFormProps<T> extends UseFormProps {
|
|
5
6
|
onSubmit: (data: T) => void;
|
|
@@ -261,4 +262,16 @@ type SliderProps = SliderProps$1 & ControllerSlider & {
|
|
|
261
262
|
|
|
262
263
|
declare const Slider: ({ name, rules, defaultValue, shouldUnregister, ...rest }: SliderProps) => JSX.Element;
|
|
263
264
|
|
|
264
|
-
|
|
265
|
+
type DatePickerProps = Omit<UseControllerProps, 'control'> & Pick<TextFieldProps$1, 'label' | 'error' | 'helperText' | 'size' | 'fullWidth' | 'variant' | 'autoFocus' | 'placeholder'> & {
|
|
266
|
+
datePickerProps?: Partial<DatePickerProps$1<any, any>>;
|
|
267
|
+
/**
|
|
268
|
+
* Se `true` irá adicionar um asterisco ao label do campo
|
|
269
|
+
*
|
|
270
|
+
* @default false
|
|
271
|
+
*/
|
|
272
|
+
required?: boolean;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
declare const DatePicker: ({ rules, name, defaultValue, shouldUnregister, datePickerProps, label, required, placeholder, ...rest }: DatePickerProps) => JSX.Element;
|
|
276
|
+
|
|
277
|
+
export { Checkbox, CheckboxProps, Creatable, CreatableOption, CreatableProps, DatePicker, DatePickerProps, Form, RadioButton, RadioGroup, RadioGroupProps, RadioProps, Searchable, SearchableOption, SearchableProps, Select, SelectOption, SelectProps, Slider, SliderProps, Switch, SwitchProps, TextField };
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var We=Object.create;var B=Object.defineProperty,Ye=Object.defineProperties,He=Object.getOwnPropertyDescriptor,Ke=Object.getOwnPropertyDescriptors,Je=Object.getOwnPropertyNames,H=Object.getOwnPropertySymbols,Qe=Object.getPrototypeOf,ae=Object.prototype.hasOwnProperty,xe=Object.prototype.propertyIsEnumerable;var ce=(e,r,o)=>r in e?B(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o,l=(e,r)=>{for(var o in r||(r={}))ae.call(r,o)&&ce(e,o,r[o]);if(H)for(var o of H(r))xe.call(r,o)&&ce(e,o,r[o]);return e},F=(e,r)=>Ye(e,Ke(r));var f=(e,r)=>{var o={};for(var i in e)ae.call(e,i)&&r.indexOf(i)<0&&(o[i]=e[i]);if(e!=null&&H)for(var i of H(e))r.indexOf(i)<0&&xe.call(e,i)&&(o[i]=e[i]);return o};var Xe=(e,r)=>{for(var o in r)B(e,o,{get:r[o],enumerable:!0})},ye=(e,r,o,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of Je(r))!ae.call(e,t)&&t!==o&&B(e,t,{get:()=>r[t],enumerable:!(i=He(r,t))||i.enumerable});return e};var se=(e,r,o)=>(o=e!=null?We(Qe(e)):{},ye(r||!e||!e.__esModule?B(o,"default",{value:e,enumerable:!0}):o,e)),Ze=e=>ye(B({},"__esModule",{value:!0}),e);var fr={};Xe(fr,{Checkbox:()=>$e,Creatable:()=>Le,DatePicker:()=>je,Form:()=>be,RadioButton:()=>Ie,RadioGroup:()=>Me,Searchable:()=>De,Select:()=>Ee,Slider:()=>Ve,Switch:()=>qe,TextField:()=>we});module.exports=Ze(fr);var Fe=require("react"),K=require("react-hook-form");var de=require("react/jsx-runtime");function er(i){var t=i,{children:e,onSubmit:r}=t,o=f(t,["children","onSubmit"]);let a=(0,K.useForm)(o);(0,Fe.useEffect)(()=>{a.reset(o.defaultValues)},[o.defaultValues,a.reset]);let n=()=>typeof e=="function"?e(F(l({},a),{onSubmit:a.handleSubmit(r)})):e;return(0,de.jsx)(K.FormProvider,F(l({},a),{children:(0,de.jsx)("form",{onSubmit:a.handleSubmit(r),children:n()})}))}var be=er;var Se=require("react"),J=require("react-hook-form"),Q=require("phosphor-react"),v=require("@mui/material"),V=se(require("@s_mart/masks"));var me=require("@mui/material"),he=require("@s_mart/utils"),j=require("react/jsx-runtime"),P=({label:e,required:r,regular:o})=>(0,j.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:(0,he.toRem)(2)},children:[(0,j.jsx)(me.Typography,{variant:"caption",fontWeight:o?400:700,style:{display:"flex",alignItems:"center"},children:e}),r&&(0,j.jsx)(me.Typography,{variant:"caption",fontWeight:900,color:"error",children:"*"})]});var Pe=require("react-hook-form"),ge=require("@s_mart/core"),Ce=require("react/jsx-runtime"),S=({name:e})=>{var o,i,t;let r=(0,Pe.useFormContext)();return(i=(o=r==null?void 0:r.formState)==null?void 0:o.errors)!=null&&i[e]?(0,Ce.jsx)(ge.Indicator,{severity:"error",children:(t=r.formState.errors[e])==null?void 0:t.message}):null};var T=require("react/jsx-runtime"),rr=m=>{var s=m,{name:e,rules:r,defaultValue:o,shouldUnregister:i,label:t,required:a,mask:n,variant:y="outlined",onInputChange:u}=s,c=f(s,["name","rules","defaultValue","shouldUnregister","label","required","mask","variant","onInputChange"]);let g=(0,J.useFormContext)();if(!g)throw new Error("Para usar o <TextField /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let[E,x]=(0,Se.useState)(!1),C=b=>{var p;return n?(p=V==null?void 0:V[n])==null?void 0:p.format(b):b},d=b=>{var p;return n?(p=V==null?void 0:V[n])==null?void 0:p.parse(b):b},G=b=>{if(!b||n!=="porcentagem")return;b==null||b.stopPropagation();let p=(b==null?void 0:b.target).value;if(p){let h=String(p);if(h.length>0){let _=h.indexOf("%");_>-1&&(b.currentTarget.selectionEnd=_)}}};return(0,T.jsx)(J.Controller,{control:g.control,name:e,rules:r,defaultValue:o,shouldUnregister:i,render:({field:{value:b,onChange:p}})=>(0,T.jsxs)(v.Grid,{display:"flex",flexDirection:"column",children:[t&&(0,T.jsx)(P,{label:t,required:a}),(0,T.jsx)(v.TextField,F(l({size:"small",variant:y,autoComplete:"off",defaultValue:o,value:C(b||""),onChange:h=>{var _;u==null||u(h),p(d((_=h==null?void 0:h.target)==null?void 0:_.value))}},c),{type:c.type==="password"?E?"text":"password":c.type,InputProps:l({onKeyDown:G,endAdornment:c.type==="password"&&(0,T.jsx)(v.InputAdornment,{position:"end",onClick:()=>x(!E),style:{cursor:"pointer"},children:E?(0,T.jsx)(Q.Eye,{size:20}):(0,T.jsx)(Q.EyeSlash,{size:20})})},c.InputProps)})),(0,T.jsx)(S,{name:e})]})})},we=rr;var X=require("react-hook-form"),R=require("@mui/material");var A=require("react/jsx-runtime"),or=m=>{var s=m,{name:e,rules:r,defaultValue:o,shouldUnregister:i,label:t,required:a,options:n,placeholder:y,onInputChange:u}=s,c=f(s,["name","rules","defaultValue","shouldUnregister","label","required","options","placeholder","onInputChange"]);let g=(0,X.useFormContext)(),{palette:E}=(0,R.useTheme)();if(!g)throw new Error("Para usar o <Select /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,A.jsx)(X.Controller,{control:g.control,name:e,rules:r,defaultValue:o||"",shouldUnregister:i,render:({field:{value:x,onChange:C}})=>(0,A.jsxs)(R.Grid,{display:"flex",flexDirection:"column",children:[t&&(0,A.jsx)(P,{label:t,required:a}),(0,A.jsxs)(R.Select,F(l({displayEmpty:Boolean(y),size:"small",variant:"outlined",autoComplete:"off",value:x||"",onChange:d=>{u==null||u(d),C(d.target.value)}},c),{children:[y&&(0,A.jsx)(R.MenuItem,{disabled:!0,value:"",children:(0,A.jsx)("p",{style:{color:E.grey[400]},children:y})}),n==null?void 0:n.map((d,G)=>(0,A.jsx)(R.MenuItem,{value:d.value,children:d.label},G))]})),(0,A.jsx)(S,{name:e})]})})},Ee=or;var Z=require("react-hook-form"),U=require("@mui/material");var $=require("react/jsx-runtime"),tr=c=>{var m=c,{name:e,rules:r,defaultValue:o,shouldUnregister:i,label:t,required:a,options:n,textFieldProps:y}=m,u=f(m,["name","rules","defaultValue","shouldUnregister","label","required","options","textFieldProps"]);let s=(0,Z.useFormContext)();if(!s)throw new Error("Para usar o <Searchable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,$.jsx)(Z.Controller,{control:s.control,name:e,rules:r,defaultValue:o,shouldUnregister:i,render:({field:{onChange:g,value:E}})=>(0,$.jsxs)(U.Grid,{display:"flex",flexDirection:"column",children:[t&&(0,$.jsx)(P,{label:t,required:a}),(0,$.jsx)(U.Autocomplete,F(l({size:"small",onChange:(x,C)=>g(C),value:E||null,options:n,noOptionsText:"Nenhuma op\xE7\xE3o encontrada",isOptionEqualToValue:(x,C)=>typeof x=="string"&&typeof C=="string"?x===C:typeof x=="object"&&typeof C=="object"?x.value===C.value:!1},u),{renderInput:x=>(0,$.jsx)(U.TextField,l(l({},x),y))})),(0,$.jsx)(S,{name:e})]})})},De=tr;var ee=require("react-hook-form"),Re=require("phosphor-react"),q=require("@mui/material");var L=require("@s_mart/utils"),pe=se(require("@emotion/styled")),fe=require("@emotion/react"),Te=fe.css`
|
|
2
2
|
display: flex;
|
|
3
3
|
align-items: center;
|
|
4
4
|
justify-content: center;
|
|
5
|
-
`,
|
|
5
|
+
`,ir=e=>fe.css`
|
|
6
6
|
.MuiAutocomplete-endAdornment {
|
|
7
7
|
position: relative;
|
|
8
8
|
right: 0;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
.creatable {
|
|
12
|
-
${
|
|
12
|
+
${Te}
|
|
13
13
|
|
|
14
14
|
.divider {
|
|
15
15
|
width: 1px;
|
|
16
|
-
height: ${(0,
|
|
16
|
+
height: ${(0,L.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,L.toRem)(6)};
|
|
28
|
+
width: ${(0,L.toRem)(28)};
|
|
29
|
+
height: ${(0,L.toRem)(28)};
|
|
30
30
|
|
|
31
31
|
&:hover {
|
|
32
32
|
cursor: pointer;
|
|
@@ -35,26 +35,33 @@
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
`,
|
|
38
|
+
`,Ae=pe.default.div`
|
|
39
39
|
display: flex;
|
|
40
40
|
|
|
41
41
|
div.endAdornments {
|
|
42
42
|
position: absolute;
|
|
43
43
|
right: 0;
|
|
44
44
|
|
|
45
|
-
${
|
|
45
|
+
${Te}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
${({hideAddButton:e,theme:r})=>!e&&
|
|
49
|
-
`,
|
|
48
|
+
${({hideAddButton:e,theme:r})=>!e&&ir(r)}
|
|
49
|
+
`,Ge=pe.default.div`
|
|
50
50
|
color: ${({theme:e})=>e.palette.text.primary};
|
|
51
51
|
|
|
52
|
-
padding: ${(0,
|
|
53
|
-
margin: ${(0,
|
|
52
|
+
padding: ${(0,L.toRem)(6)} ${(0,L.toRem)(16)};
|
|
53
|
+
margin: ${(0,L.toRem)(-6)} ${(0,L.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
|
|
60
|
+
`;var w=require("react/jsx-runtime"),lr=g=>{var E=g,{name:e,rules:r,defaultValue:o,shouldUnregister:i,label:t,required:a,options:n,onCreateOption:y,textFieldProps:u,hideAddButton:c,onInputChange:m}=E,s=f(E,["name","rules","defaultValue","shouldUnregister","label","required","options","onCreateOption","textFieldProps","hideAddButton","onInputChange"]);let x=(0,ee.useFormContext)();if(!x)throw new Error("Para usar o <Creatable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let C=d=>{y?y(d):console.error("onCreateOption n\xE3o foi definido")};return(0,w.jsx)(ee.Controller,{control:x.control,name:e,rules:r,defaultValue:o,shouldUnregister:i,render:({field:{value:d,onChange:G}})=>{let b=(d==null?void 0:d.label)||(d==null?void 0:d.value)||d;return(0,w.jsxs)(q.Grid,{display:"flex",flexDirection:"column",children:[t&&(0,w.jsx)(P,{label:t,required:a}),(0,w.jsx)(Ae,{hideAddButton:c,children:(0,w.jsx)(q.Autocomplete,F(l({size:"small",fullWidth:!0,onChange:(p,h)=>(m==null||m(h),G(h)),options:n,value:d||null,noOptionsText:(0,w.jsx)(Ge,{onClick:()=>C(d),children:(0,w.jsxs)(q.Typography,{children:["Adicionar ",b&&`"${b}"`]})}),isOptionEqualToValue:(p,h)=>h?typeof p=="string"&&typeof h=="string"?p===h:typeof p=="object"&&typeof h=="object"?p.value===h.value:typeof p=="object"&&typeof h=="string":!1},s),{renderInput:p=>{let h=c?p.InputProps:F(l({},p.InputProps),{endAdornment:(0,w.jsxs)("div",{className:"endAdornments",children:[p.InputProps.endAdornment,(0,w.jsxs)("div",{className:"creatable",children:[(0,w.jsx)("div",{className:"divider"}),(0,w.jsx)("div",{className:"button",onClick:()=>C(d),children:(0,w.jsx)(Re.Plus,{size:18,weight:"bold"})})]})]})});return(0,w.jsx)(q.TextField,l(F(l({},p),{onChange:G,InputProps:h}),u))}}))}),(0,w.jsx)(S,{name:e})]})}})},Le=lr;var re=require("react-hook-form"),N=require("@mui/material");var I=require("react/jsx-runtime"),nr=u=>{var c=u,{name:e,rules:r,defaultValue:o,shouldUnregister:i,label:t,labelPlacement:a,required:n}=c,y=f(c,["name","rules","defaultValue","shouldUnregister","label","labelPlacement","required"]);let m=(0,re.useFormContext)();if(!m)throw new Error("Para usar o <Checkbox /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,I.jsx)(re.Controller,{control:m.control,name:e,rules:r,defaultValue:o,shouldUnregister:i,render:({field:{value:s,onChange:g}})=>(0,I.jsxs)(N.Grid,{display:"flex",flexDirection:"column",children:[(0,I.jsx)(N.FormControlLabel,{control:(0,I.jsx)(N.Checkbox,l({value:s!=null?s:"",defaultValue:s,onChange:g},y)),label:(0,I.jsx)(P,{label:t,required:n,regular:!0}),labelPlacement:a||"end"}),(0,I.jsx)(S,{name:e})]})})},$e=nr;var oe=require("react-hook-form"),z=require("@mui/material");var M=require("react/jsx-runtime"),ar=y=>{var u=y,{name:e,rules:r,defaultValue:o,shouldUnregister:i,label:t,labelPlacement:a}=u,n=f(u,["name","rules","defaultValue","shouldUnregister","label","labelPlacement"]);let c=(0,oe.useFormContext)();if(!c)throw new Error("Para usar o <Switch /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,M.jsx)(oe.Controller,{control:c.control,name:e,rules:r,defaultValue:o,shouldUnregister:i,render:({field:{value:m,onChange:s}})=>(0,M.jsxs)(z.Grid,{display:"flex",flexDirection:"column",children:[(0,M.jsx)(z.FormControlLabel,{control:(0,M.jsx)(z.Switch,l({value:m!=null?m:"",defaultValue:m,onChange:s},n)),label:(0,M.jsx)(P,{label:t}),labelPlacement:a||"end"}),(0,M.jsx)(S,{name:e})]})})},qe=ar;var O=require("@mui/material");var W=require("react/jsx-runtime"),sr=i=>{var t=i,{label:e,labelPlacement:r}=t,o=f(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,l({},o)),label:(0,W.jsx)(P,{label:e}),labelPlacement:r||"end"})})},Ie=sr;var te=require("react-hook-form"),ie=require("@mui/material");var k=require("react/jsx-runtime"),dr=c=>{var m=c,{name:e,rules:r,defaultValue:o,shouldUnregister:i,label:t,required:a,children:n,orientation:y="row"}=m,u=f(m,["name","rules","defaultValue","shouldUnregister","label","required","children","orientation"]);let s=(0,te.useFormContext)();if(!s)throw new Error("Para usar o <RadioGroup /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,k.jsx)(te.Controller,{control:s.control,name:e,rules:r,defaultValue:o,shouldUnregister:i,render:({field:{value:g,onChange:E}})=>(0,k.jsxs)(ie.Grid,{display:"flex",flexDirection:"column",children:[t&&(0,k.jsx)(P,{label:t,required:a}),(0,k.jsx)(ie.RadioGroup,F(l({value:g||"",onChange:E,name:e},u),{style:{display:"flex",flexDirection:y},children:n})),(0,k.jsx)(S,{name:e})]})})},Me=dr;var le=require("react-hook-form"),ke=require("@mui/material");var ue=require("react/jsx-runtime"),mr=a=>{var n=a,{name:e,rules:r,defaultValue:o,shouldUnregister:i}=n,t=f(n,["name","rules","defaultValue","shouldUnregister"]);let y=(0,le.useFormContext)();if(!y)throw new Error("Para usar o <Slider /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,ue.jsx)(le.Controller,{control:y.control,name:e,rules:r,defaultValue:o,shouldUnregister:i,render:({field:{value:u,onChange:c}})=>(0,ue.jsx)(ke.Slider,l({value:u||(t==null?void 0:t.min)||0,onChange:c,valueLabelDisplay:"auto"},t))})},Ve=mr;var ne=require("react-hook-form"),Ne=require("@s_mart/core"),ze=require("@mui/material"),Oe=require("@mui/x-date-pickers/DatePicker"),_e=require("@mui/x-date-pickers/AdapterDayjs"),Be=require("@mui/x-date-pickers/LocalizationProvider");var Y=require("@s_mart/utils"),ve=se(require("@emotion/styled")),Ue=ve.default.div`
|
|
61
|
+
> div > button {
|
|
62
|
+
padding: ${(0,Y.toRem)(6)} ${(0,Y.toRem)(8)};
|
|
63
|
+
border-radius: 0 ${(0,Y.toRem)(4)} ${(0,Y.toRem)(4)} 0;
|
|
64
|
+
|
|
65
|
+
margin: 0px -13px 0px 0px;
|
|
66
|
+
}
|
|
67
|
+
`;var D=require("react/jsx-runtime"),pr=c=>{var m=c,{rules:e,name:r,defaultValue:o,shouldUnregister:i,datePickerProps:t,label:a,required:n,placeholder:y}=m,u=f(m,["rules","name","defaultValue","shouldUnregister","datePickerProps","label","required","placeholder"]);let s=(0,ne.useFormContext)();if(!s)throw new Error("Para usar o <DataPicker /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,D.jsx)(Be.LocalizationProvider,{dateAdapter:_e.AdapterDayjs,children:(0,D.jsx)(ne.Controller,{control:s.control,name:r,rules:e,defaultValue:o,shouldUnregister:i,render:({field:{value:g,onChange:E}})=>(0,D.jsxs)(Ne.Grid,{display:"flex",flexDirection:"column",children:[a&&(0,D.jsx)(P,{label:a,required:n}),(0,D.jsx)(Oe.DatePicker,F(l({},t),{value:g!=null?g:null,inputFormat:(t==null?void 0:t.inputFormat)||"DD/MM/YYYY",onChange:E,renderInput:x=>{var C,d,G;return(0,D.jsxs)(D.Fragment,{children:[console.log((C=x.InputProps)==null?void 0:C.endAdornment),(0,D.jsx)(ze.TextField,F(l(l({size:"small",variant:"outlined"},x),u),{inputProps:F(l({},x.inputProps),{placeholder:y||((d=x.inputProps)==null?void 0:d.placeholder)}),InputProps:F(l({},x.InputProps),{endAdornment:(0,D.jsx)(Ue,{children:(G=x.InputProps)==null?void 0:G.endAdornment})})}))]})}})),(0,D.jsx)(S,{name:r})]})})})},je=pr;0&&(module.exports={Checkbox,Creatable,DatePicker,Form,RadioButton,RadioGroup,Searchable,Select,Slider,Switch,TextField});
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
var
|
|
1
|
+
var te=Object.defineProperty,ie=Object.defineProperties;var le=Object.getOwnPropertyDescriptors;var k=Object.getOwnPropertySymbols;var O=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable;var z=(e,r,o)=>r in e?te(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o,i=(e,r)=>{for(var o in r||(r={}))O.call(r,o)&&z(e,o,r[o]);if(k)for(var o of k(r))_.call(r,o)&&z(e,o,r[o]);return e},F=(e,r)=>ie(e,le(r));var f=(e,r)=>{var o={};for(var l in e)O.call(e,l)&&r.indexOf(l)<0&&(o[l]=e[l]);if(e!=null&&k)for(var l of k(e))r.indexOf(l)<0&&_.call(e,l)&&(o[l]=e[l]);return o};import{useEffect as ne}from"react";import{FormProvider as ae,useForm as se}from"react-hook-form";import{jsx as B}from"react/jsx-runtime";function de(l){var t=l,{children:e,onSubmit:r}=t,o=f(t,["children","onSubmit"]);let a=se(o);ne(()=>{a.reset(o.defaultValues)},[o.defaultValues,a.reset]);let n=()=>typeof e=="function"?e(F(i({},a),{onSubmit:a.handleSubmit(r)})):e;return B(ae,F(i({},a),{children:B("form",{onSubmit:a.handleSubmit(r),children:n()})}))}var me=de;import{useState as ye}from"react";import{Controller as Fe,useFormContext as be}from"react-hook-form";import{Eye as he,EyeSlash as Pe}from"phosphor-react";import{Grid as ge,InputAdornment as Ce,TextField as Se}from"@mui/material";import*as R from"@s_mart/masks";import{Typography as j}from"@mui/material";import{toRem as pe}from"@s_mart/utils";import{jsx as W,jsxs as fe}from"react/jsx-runtime";var P=({label:e,required:r,regular:o})=>fe("span",{style:{display:"flex",alignItems:"center",gap:pe(2)},children:[W(j,{variant:"caption",fontWeight:o?400:700,style:{display:"flex",alignItems:"center"},children:e}),r&&W(j,{variant:"caption",fontWeight:900,color:"error",children:"*"})]});import{useFormContext as ue}from"react-hook-form";import{Indicator as ce}from"@s_mart/core";import{jsx as xe}from"react/jsx-runtime";var S=({name:e})=>{var o,l,t;let r=ue();return(l=(o=r==null?void 0:r.formState)==null?void 0:o.errors)!=null&&l[e]?xe(ce,{severity:"error",children:(t=r.formState.errors[e])==null?void 0:t.message}):null};import{jsx as A,jsxs as De}from"react/jsx-runtime";var we=m=>{var s=m,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:a,mask:n,variant:y="outlined",onInputChange:u}=s,c=f(s,["name","rules","defaultValue","shouldUnregister","label","required","mask","variant","onInputChange"]);let g=be();if(!g)throw new Error("Para usar o <TextField /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let[w,x]=ye(!1),C=b=>{var p;return n?(p=R==null?void 0:R[n])==null?void 0:p.format(b):b},d=b=>{var p;return n?(p=R==null?void 0:R[n])==null?void 0:p.parse(b):b},D=b=>{if(!b||n!=="porcentagem")return;b==null||b.stopPropagation();let p=(b==null?void 0:b.target).value;if(p){let h=String(p);if(h.length>0){let $=h.indexOf("%");$>-1&&(b.currentTarget.selectionEnd=$)}}};return A(Fe,{control:g.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:b,onChange:p}})=>De(ge,{display:"flex",flexDirection:"column",children:[t&&A(P,{label:t,required:a}),A(Se,F(i({size:"small",variant:y,autoComplete:"off",defaultValue:o,value:C(b||""),onChange:h=>{var $;u==null||u(h),p(d(($=h==null?void 0:h.target)==null?void 0:$.value))}},c),{type:c.type==="password"?w?"text":"password":c.type,InputProps:i({onKeyDown:D,endAdornment:c.type==="password"&&A(Ce,{position:"end",onClick:()=>x(!w),style:{cursor:"pointer"},children:w?A(he,{size:20}):A(Pe,{size:20})})},c.InputProps)})),A(S,{name:e})]})})},Ee=we;import{Controller as Te,useFormContext as Ae}from"react-hook-form";import{Grid as Ge,Select as Re,MenuItem as Y,useTheme as Le}from"@mui/material";import{jsx as L,jsxs as H}from"react/jsx-runtime";var $e=m=>{var s=m,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:a,options:n,placeholder:y,onInputChange:u}=s,c=f(s,["name","rules","defaultValue","shouldUnregister","label","required","options","placeholder","onInputChange"]);let g=Ae(),{palette:w}=Le();if(!g)throw new Error("Para usar o <Select /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return L(Te,{control:g.control,name:e,rules:r,defaultValue:o||"",shouldUnregister:l,render:({field:{value:x,onChange:C}})=>H(Ge,{display:"flex",flexDirection:"column",children:[t&&L(P,{label:t,required:a}),H(Re,F(i({displayEmpty:Boolean(y),size:"small",variant:"outlined",autoComplete:"off",value:x||"",onChange:d=>{u==null||u(d),C(d.target.value)}},c),{children:[y&&L(Y,{disabled:!0,value:"",children:L("p",{style:{color:w.grey[400]},children:y})}),n==null?void 0:n.map((d,D)=>L(Y,{value:d.value,children:d.label},D))]})),L(S,{name:e})]})})},qe=$e;import{Controller as Ie,useFormContext as Me}from"react-hook-form";import{Grid as ke,Autocomplete as Ve,TextField as ve}from"@mui/material";import{jsx as q,jsxs as ze}from"react/jsx-runtime";var Ue=c=>{var m=c,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:a,options:n,textFieldProps:y}=m,u=f(m,["name","rules","defaultValue","shouldUnregister","label","required","options","textFieldProps"]);let s=Me();if(!s)throw new Error("Para usar o <Searchable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return q(Ie,{control:s.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{onChange:g,value:w}})=>ze(ke,{display:"flex",flexDirection:"column",children:[t&&q(P,{label:t,required:a}),q(Ve,F(i({size:"small",onChange:(x,C)=>g(C),value:w||null,options:n,noOptionsText:"Nenhuma op\xE7\xE3o encontrada",isOptionEqualToValue:(x,C)=>typeof x=="string"&&typeof C=="string"?x===C:typeof x=="object"&&typeof C=="object"?x.value===C.value:!1},u),{renderInput:x=>q(ve,i(i({},x),y))})),q(S,{name:e})]})})},Ne=Ue;import{Controller as _e,useFormContext as Be}from"react-hook-form";import{Plus as je}from"phosphor-react";import{Grid as We,Autocomplete as Ye,TextField as He,Typography as Ke}from"@mui/material";import{toRem as T}from"@s_mart/utils";import K from"@emotion/styled";import{css as J}from"@emotion/react";var Q=J`
|
|
2
2
|
display: flex;
|
|
3
3
|
align-items: center;
|
|
4
4
|
justify-content: center;
|
|
5
|
-
`,
|
|
5
|
+
`,Oe=e=>J`
|
|
6
6
|
.MuiAutocomplete-endAdornment {
|
|
7
7
|
position: relative;
|
|
8
8
|
right: 0;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
.creatable {
|
|
12
|
-
${
|
|
12
|
+
${Q}
|
|
13
13
|
|
|
14
14
|
.divider {
|
|
15
15
|
width: 1px;
|
|
@@ -35,18 +35,18 @@ var Z=Object.defineProperty,ee=Object.defineProperties;var re=Object.getOwnPrope
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
`,
|
|
38
|
+
`,X=K.div`
|
|
39
39
|
display: flex;
|
|
40
40
|
|
|
41
41
|
div.endAdornments {
|
|
42
42
|
position: absolute;
|
|
43
43
|
right: 0;
|
|
44
44
|
|
|
45
|
-
${
|
|
45
|
+
${Q}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
${({hideAddButton:e,theme:r})=>!e&&
|
|
49
|
-
`,
|
|
48
|
+
${({hideAddButton:e,theme:r})=>!e&&Oe(r)}
|
|
49
|
+
`,Z=K.div`
|
|
50
50
|
color: ${({theme:e})=>e.palette.text.primary};
|
|
51
51
|
|
|
52
52
|
padding: ${T(6)} ${T(16)};
|
|
@@ -57,4 +57,11 @@ var Z=Object.defineProperty,ee=Object.defineProperties;var re=Object.getOwnPrope
|
|
|
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 E,jsxs as V}from"react/jsx-runtime";var
|
|
60
|
+
`;import{jsx as E,jsxs as V}from"react/jsx-runtime";var Je=g=>{var w=g,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:a,options:n,onCreateOption:y,textFieldProps:u,hideAddButton:c,onInputChange:m}=w,s=f(w,["name","rules","defaultValue","shouldUnregister","label","required","options","onCreateOption","textFieldProps","hideAddButton","onInputChange"]);let x=Be();if(!x)throw new Error("Para usar o <Creatable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let C=d=>{y?y(d):console.error("onCreateOption n\xE3o foi definido")};return E(_e,{control:x.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:d,onChange:D}})=>{let b=(d==null?void 0:d.label)||(d==null?void 0:d.value)||d;return V(We,{display:"flex",flexDirection:"column",children:[t&&E(P,{label:t,required:a}),E(X,{hideAddButton:c,children:E(Ye,F(i({size:"small",fullWidth:!0,onChange:(p,h)=>(m==null||m(h),D(h)),options:n,value:d||null,noOptionsText:E(Z,{onClick:()=>C(d),children:V(Ke,{children:["Adicionar ",b&&`"${b}"`]})}),isOptionEqualToValue:(p,h)=>h?typeof p=="string"&&typeof h=="string"?p===h:typeof p=="object"&&typeof h=="object"?p.value===h.value:typeof p=="object"&&typeof h=="string":!1},s),{renderInput:p=>{let h=c?p.InputProps:F(i({},p.InputProps),{endAdornment:V("div",{className:"endAdornments",children:[p.InputProps.endAdornment,V("div",{className:"creatable",children:[E("div",{className:"divider"}),E("div",{className:"button",onClick:()=>C(d),children:E(je,{size:18,weight:"bold"})})]})]})});return E(He,i(F(i({},p),{onChange:D,InputProps:h}),u))}}))}),E(S,{name:e})]})}})},Qe=Je;import{Controller as Xe,useFormContext as Ze}from"react-hook-form";import{Grid as er,Checkbox as rr,FormControlLabel as or}from"@mui/material";import{jsx as I,jsxs as lr}from"react/jsx-runtime";var tr=u=>{var c=u,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,labelPlacement:a,required:n}=c,y=f(c,["name","rules","defaultValue","shouldUnregister","label","labelPlacement","required"]);let m=Ze();if(!m)throw new Error("Para usar o <Checkbox /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return I(Xe,{control:m.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:s,onChange:g}})=>lr(er,{display:"flex",flexDirection:"column",children:[I(or,{control:I(rr,i({value:s!=null?s:"",defaultValue:s,onChange:g},y)),label:I(P,{label:t,required:n,regular:!0}),labelPlacement:a||"end"}),I(S,{name:e})]})})},ir=tr;import{Controller as nr,useFormContext as ar}from"react-hook-form";import{Grid as sr,Switch as dr,FormControlLabel as mr}from"@mui/material";import{jsx as M,jsxs as ur}from"react/jsx-runtime";var pr=y=>{var u=y,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,labelPlacement:a}=u,n=f(u,["name","rules","defaultValue","shouldUnregister","label","labelPlacement"]);let c=ar();if(!c)throw new Error("Para usar o <Switch /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return M(nr,{control:c.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:m,onChange:s}})=>ur(sr,{display:"flex",flexDirection:"column",children:[M(mr,{control:M(dr,i({value:m!=null?m:"",defaultValue:m,onChange:s},n)),label:M(P,{label:t}),labelPlacement:a||"end"}),M(S,{name:e})]})})},fr=pr;import{Grid as cr,Radio as xr,FormControlLabel as yr}from"@mui/material";import{jsx as v}from"react/jsx-runtime";var Fr=l=>{var t=l,{label:e,labelPlacement:r}=t,o=f(t,["label","labelPlacement"]);return v(cr,{display:"flex",flexDirection:"column",children:v(yr,{control:v(xr,i({},o)),label:v(P,{label:e}),labelPlacement:r||"end"})})},br=Fr;import{Controller as hr,useFormContext as Pr}from"react-hook-form";import{Grid as gr,RadioGroup as Cr}from"@mui/material";import{jsx as U,jsxs as Er}from"react/jsx-runtime";var Sr=c=>{var m=c,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:a,children:n,orientation:y="row"}=m,u=f(m,["name","rules","defaultValue","shouldUnregister","label","required","children","orientation"]);let s=Pr();if(!s)throw new Error("Para usar o <RadioGroup /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return U(hr,{control:s.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:g,onChange:w}})=>Er(gr,{display:"flex",flexDirection:"column",children:[t&&U(P,{label:t,required:a}),U(Cr,F(i({value:g||"",onChange:w,name:e},u),{style:{display:"flex",flexDirection:y},children:n})),U(S,{name:e})]})})},wr=Sr;import{Controller as Dr,useFormContext as Tr}from"react-hook-form";import{Slider as Ar}from"@mui/material";import{jsx as ee}from"react/jsx-runtime";var Gr=a=>{var n=a,{name:e,rules:r,defaultValue:o,shouldUnregister:l}=n,t=f(n,["name","rules","defaultValue","shouldUnregister"]);let y=Tr();if(!y)throw new Error("Para usar o <Slider /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return ee(Dr,{control:y.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:u,onChange:c}})=>ee(Ar,i({value:u||(t==null?void 0:t.min)||0,onChange:c,valueLabelDisplay:"auto"},t))})},Rr=Gr;import{Controller as $r,useFormContext as qr}from"react-hook-form";import{Grid as Ir}from"@s_mart/core";import{TextField as Mr}from"@mui/material";import{DatePicker as kr}from"@mui/x-date-pickers/DatePicker";import{AdapterDayjs as Vr}from"@mui/x-date-pickers/AdapterDayjs";import{LocalizationProvider as vr}from"@mui/x-date-pickers/LocalizationProvider";import{toRem as N}from"@s_mart/utils";import Lr from"@emotion/styled";var re=Lr.div`
|
|
61
|
+
> div > button {
|
|
62
|
+
padding: ${N(6)} ${N(8)};
|
|
63
|
+
border-radius: 0 ${N(4)} ${N(4)} 0;
|
|
64
|
+
|
|
65
|
+
margin: 0px -13px 0px 0px;
|
|
66
|
+
}
|
|
67
|
+
`;import{Fragment as zr,jsx as G,jsxs as oe}from"react/jsx-runtime";var Ur=c=>{var m=c,{rules:e,name:r,defaultValue:o,shouldUnregister:l,datePickerProps:t,label:a,required:n,placeholder:y}=m,u=f(m,["rules","name","defaultValue","shouldUnregister","datePickerProps","label","required","placeholder"]);let s=qr();if(!s)throw new Error("Para usar o <DataPicker /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return G(vr,{dateAdapter:Vr,children:G($r,{control:s.control,name:r,rules:e,defaultValue:o,shouldUnregister:l,render:({field:{value:g,onChange:w}})=>oe(Ir,{display:"flex",flexDirection:"column",children:[a&&G(P,{label:a,required:n}),G(kr,F(i({},t),{value:g!=null?g:null,inputFormat:(t==null?void 0:t.inputFormat)||"DD/MM/YYYY",onChange:w,renderInput:x=>{var C,d,D;return oe(zr,{children:[console.log((C=x.InputProps)==null?void 0:C.endAdornment),G(Mr,F(i(i({size:"small",variant:"outlined"},x),u),{inputProps:F(i({},x.inputProps),{placeholder:y||((d=x.inputProps)==null?void 0:d.placeholder)}),InputProps:F(i({},x.InputProps),{endAdornment:G(re,{children:(D=x.InputProps)==null?void 0:D.endAdornment})})}))]})}})),G(S,{name:r})]})})})},Nr=Ur;export{ir as Checkbox,Qe as Creatable,Nr as DatePicker,me as Form,br as RadioButton,wr as RadioGroup,Ne as Searchable,qe as Select,Rr as Slider,fr as Switch,Ee as TextField};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@s_mart/form",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.1",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"@types/react-dom": ">=18.0.6",
|
|
37
37
|
"@emotion/react": ">=11.10.4",
|
|
38
38
|
"@emotion/styled": ">=11.10.4",
|
|
39
|
+
"@mui/x-date-pickers": ">=5.0.13",
|
|
39
40
|
"@s_mart/core": ">=2.1.0",
|
|
40
41
|
"phosphor-react": ">=1.4.1"
|
|
41
42
|
},
|