@s_mart/form 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,244 @@
1
+ import { PropsWithChildren } from 'react';
2
+ import { UseFormProps, ControllerProps } from 'react-hook-form';
3
+ import { TextFieldProps as TextFieldProps$1, SelectProps as SelectProps$1, AutocompleteProps, CheckboxProps as CheckboxProps$1, SwitchProps as SwitchProps$1, RadioProps as RadioProps$1, RadioGroupProps as RadioGroupProps$1, SliderProps as SliderProps$1 } from '@mui/material';
4
+
5
+ interface IFormProps<T> extends PropsWithChildren, UseFormProps {
6
+ onSubmit: (data: T) => void;
7
+ }
8
+ declare function Form({ children, onSubmit, ...rest }: IFormProps<any>): JSX.Element;
9
+
10
+ declare type ControllerTextField = Omit<ControllerProps, 'render' | 'control'>;
11
+ declare type Masks = 'cpf' | 'cnpj' | 'cpfCnpj' | 'cep' | 'telefone' | 'decimal' | 'porcentagem' | 'numero' | 'placa' | 'valor';
12
+ declare type TextFieldProps = TextFieldProps$1 & ControllerTextField & {
13
+ mask?: Masks;
14
+ };
15
+
16
+ declare const TextField: ({ name, rules, defaultValue, shouldUnregister, label, required, mask, ...rest }: TextFieldProps) => JSX.Element;
17
+
18
+ declare type ControllerSelect = Omit<ControllerProps, 'render' | 'control'>;
19
+ declare type SelectOption = {
20
+ label: string;
21
+ value: string | number | readonly string[] | undefined;
22
+ };
23
+ declare type SelectProps = SelectProps$1 & ControllerSelect & {
24
+ options: SelectOption[];
25
+ };
26
+
27
+ declare const Select: ({ name, rules, defaultValue, shouldUnregister, label, required, options, ...rest }: SelectProps) => JSX.Element;
28
+
29
+ declare type ControllerSearchable = Omit<ControllerProps, 'render' | 'control'>;
30
+ declare type SearchableOption = {
31
+ label: string;
32
+ value: string | number | readonly string[] | undefined;
33
+ } | string;
34
+ declare type SearchableProps = Omit<AutocompleteProps<SearchableOption, true, true, true>, 'renderInput'> & ControllerSearchable & {
35
+ /**
36
+ * Opções do autocomplete
37
+ * @default []
38
+ *
39
+ * @example
40
+ * [
41
+ * { label: 'Opção 1', value: '1' },
42
+ * ]
43
+ *
44
+ * @type {SearchableOption[]}
45
+ * @memberof SearchableProps
46
+ */
47
+ options: SearchableOption[];
48
+ /**
49
+ * Props do textField que é renderizado dentro do autocomplete
50
+ * @default {}
51
+ * @type {TextFieldProps}
52
+ * @memberof SearchableProps
53
+ */
54
+ textFieldProps?: TextFieldProps$1;
55
+ label?: React.ReactNode;
56
+ required?: boolean;
57
+ };
58
+
59
+ declare const Searchable: ({ name, rules, defaultValue, shouldUnregister, label, required, options, textFieldProps, ...rest }: SearchableProps) => JSX.Element;
60
+
61
+ declare type ControllerCreatable = Omit<ControllerProps, 'render' | 'control'>;
62
+ declare type CreatableOption = {
63
+ label: string;
64
+ value?: string | number | readonly string[] | undefined;
65
+ } | string;
66
+ declare type CreatableProps = Omit<AutocompleteProps<CreatableOption, true, true, true>, 'renderInput'> & ControllerCreatable & {
67
+ /**
68
+ * Opções do autocomplete
69
+ * @default []
70
+ *
71
+ * @example
72
+ * [
73
+ * { label: 'Opção 1', value: '1' },
74
+ * ]
75
+ *
76
+ * @type {CreatableOption[]}
77
+ * @memberof CreatableProps
78
+ */
79
+ options: CreatableOption[];
80
+ /**
81
+ * Props do textField que é renderizado dentro do autocomplete
82
+ * @default {}
83
+ * @type {TextFieldProps}
84
+ * @memberof CreatableProps
85
+ */
86
+ textFieldProps?: TextFieldProps$1;
87
+ /**
88
+ * Label do autocomplete
89
+ * @default ''
90
+ * @type {string}
91
+ * @memberof CreatableProps
92
+ */
93
+ label?: React.ReactNode;
94
+ /**
95
+ * Adiciona um * ao label do autocomplete para indicar que o campo é obrigatório
96
+ * @default false
97
+ * @type {boolean}
98
+ * @memberof CreatableProps
99
+ */
100
+ required?: boolean;
101
+ /**
102
+ * Função que será executada quando o usuário clicar no botão de criar uma nova opção
103
+ * @default () => {}
104
+ * @type {(value: string) => void}
105
+ * @memberof CreatableProps
106
+ */
107
+ onCreateOption?: (value: string) => void;
108
+ /**
109
+ * Quando true, o botão de criar uma nova opção externo não será renderizado
110
+ * @default false
111
+ * @type {boolean}
112
+ * @memberof CreatableProps
113
+ */
114
+ hideAddButton?: boolean;
115
+ };
116
+
117
+ declare const Creatable: ({ name, rules, defaultValue, shouldUnregister, label, required, options, onCreateOption, textFieldProps, hideAddButton, ...rest }: CreatableProps) => JSX.Element;
118
+
119
+ declare type ControllerCheckbox = Omit<ControllerProps, 'render' | 'control'>;
120
+ declare type CheckboxProps = CheckboxProps$1 & ControllerCheckbox & {
121
+ /**
122
+ * O nome do checkbox que será renderizado na tela
123
+ * @default ''
124
+ * @example 'Nome do checkbox'
125
+ * @type string
126
+ * @memberof CheckboxProps
127
+ */
128
+ label?: string;
129
+ /**
130
+ * Posição do label em relação ao checkbox
131
+ * @default 'end'
132
+ * @type 'start' | 'end' | 'top' | 'bottom'
133
+ * @example
134
+ * <Checkbox label="Checkbox" labelPlacement="start" />
135
+ */
136
+ labelPlacement?: 'start' | 'end' | 'top' | 'bottom';
137
+ };
138
+
139
+ declare const Checkbox: ({ name, rules, defaultValue, shouldUnregister, label, labelPlacement, required, ...rest }: CheckboxProps) => JSX.Element;
140
+
141
+ declare type ControllerSwitch = Omit<ControllerProps, 'render' | 'control'>;
142
+ declare type SwitchProps = SwitchProps$1 & ControllerSwitch & {
143
+ /**
144
+ * O nome do switch que será renderizado na tela
145
+ * @default ''
146
+ * @example 'Nome do switch'
147
+ * @type string
148
+ * @memberof SwitchProps
149
+ */
150
+ label?: string;
151
+ /**
152
+ * Posição do label em relação ao switch
153
+ * @default 'end'
154
+ * @type 'start' | 'end' | 'top' | 'bottom'
155
+ * @example
156
+ * <Switch label="Switch" labelPlacement="start" />
157
+ */
158
+ labelPlacement?: 'start' | 'end' | 'top' | 'bottom';
159
+ };
160
+
161
+ declare const Switch: ({ name, rules, defaultValue, shouldUnregister, label, labelPlacement, required, ...rest }: SwitchProps) => JSX.Element;
162
+
163
+ declare type RadioProps = RadioProps$1 & {
164
+ /**
165
+ * O nome do checkbox que será renderizado na tela
166
+ * @default ''
167
+ * @example 'Nome do checkbox'
168
+ * @type string
169
+ * @memberof RadioProps
170
+ */
171
+ label?: string;
172
+ /**
173
+ * Posição do label em relação ao checkbox
174
+ * @default 'end'
175
+ * @type 'start' | 'end' | 'top' | 'bottom'
176
+ * @example
177
+ * <Radio label="Radio" labelPlacement="start" />
178
+ */
179
+ labelPlacement?: 'start' | 'end' | 'top' | 'bottom';
180
+ };
181
+
182
+ declare const RadioButton: ({ label, labelPlacement, ...rest }: RadioProps) => JSX.Element;
183
+
184
+ declare type ControllerRadioGroup = Omit<ControllerProps, 'render' | 'control'>;
185
+ declare type RadioGroupProps = RadioGroupProps$1 & ControllerRadioGroup & {
186
+ /**
187
+ * O nome do checkbox que será renderizado na tela
188
+ * @default ''
189
+ * @example 'Nome do checkbox'
190
+ * @type string
191
+ * @memberof RadioGroupProps
192
+ */
193
+ label?: string;
194
+ /**
195
+ * Adiciona um asterisco ao label do radioGroup
196
+ * @default false
197
+ * @type boolean
198
+ * @memberof RadioGroupProps
199
+ */
200
+ required?: boolean;
201
+ /**
202
+ * Parte interna do componente para renderizar os RadiosButtons
203
+ * @default []
204
+ * @type ReactNode
205
+ * @memberof RadioGroupProps
206
+ * @example
207
+ * <Radio value="1" label="Radio 1" />
208
+ * <Radio value="2" label="Radio 2" />
209
+ */
210
+ children: React.ReactNode;
211
+ /**
212
+ * Define a orientação dos radios buttons dentro do radioGroup
213
+ * @default 'row'
214
+ * @type 'row' | 'column'
215
+ * @memberof RadioGroupProps
216
+ */
217
+ orientation?: 'row' | 'column';
218
+ };
219
+
220
+ declare const RadioGroup: ({ name, rules, defaultValue, shouldUnregister, label, required, children, orientation, ...rest }: RadioGroupProps) => JSX.Element;
221
+
222
+ declare type ControllerSlider = Omit<ControllerProps, 'render' | 'control'>;
223
+ declare type SliderProps = SliderProps$1 & ControllerSlider & {
224
+ /**
225
+ * O nome do switch que será renderizado na tela
226
+ * @default ''
227
+ * @example 'Nome do switch'
228
+ * @type string
229
+ * @memberof SliderProps
230
+ */
231
+ label?: string;
232
+ /**
233
+ * Posição do label em relação ao switch
234
+ * @default 'end'
235
+ * @type 'start' | 'end' | 'top' | 'bottom'
236
+ * @example
237
+ * <Slider label="Slider" labelPlacement="start" />
238
+ */
239
+ labelPlacement?: 'start' | 'end' | 'top' | 'bottom';
240
+ };
241
+
242
+ declare const Slider: ({ name, rules, defaultValue, shouldUnregister, label, labelPlacement, ...rest }: SliderProps) => JSX.Element;
243
+
244
+ export { Checkbox, CheckboxProps, Creatable, CreatableOption, CreatableProps, Form, RadioButton, RadioGroup, RadioGroupProps, RadioProps, Searchable, SearchableOption, SearchableProps, Select, SelectOption, SelectProps, Slider, SliderProps, Switch, SwitchProps, TextField };
package/dist/index.js ADDED
@@ -0,0 +1,60 @@
1
+ "use strict";var h2=Object.create;var E=Object.defineProperty;var x2=Object.getOwnPropertyDescriptor;var b2=Object.getOwnPropertyNames;var y2=Object.getPrototypeOf,F2=Object.prototype.hasOwnProperty;var w2=(C,i)=>{for(var e in i)E(C,e,{get:i[e],enumerable:!0})},j=(C,i,e,H)=>{if(i&&typeof i=="object"||typeof i=="function")for(let o of b2(i))!F2.call(C,o)&&o!==e&&E(C,o,{get:()=>i[o],enumerable:!(H=x2(i,o))||H.enumerable});return C};var C2=(C,i,e)=>(e=C!=null?h2(y2(C)):{},j(i||!C||!C.__esModule?E(e,"default",{value:C,enumerable:!0}):e,C)),P2=C=>j(E({},"__esModule",{value:!0}),C);var U2={};w2(U2,{Checkbox:()=>a2,Creatable:()=>c2,Form:()=>i2,RadioButton:()=>m2,RadioGroup:()=>u2,Searchable:()=>L2,Select:()=>V2,Slider:()=>g2,Switch:()=>p2,TextField:()=>l2});module.exports=P2(U2);var D=require("react-hook-form"),K=require("react/jsx-runtime");function k2({children:C,onSubmit:i,...e}){let H=(0,D.useForm)(e);return(0,K.jsx)(D.FormProvider,{...H,children:(0,K.jsx)("form",{onSubmit:H.handleSubmit(i),children:C})})}var i2=k2;var I=require("react-hook-form"),G=require("@mui/material");var Q=require("@mui/material"),e2=require("@s_mart/utils"),T=require("react/jsx-runtime"),t=({label:C,required:i})=>(0,T.jsxs)("span",{style:{display:"flex",gap:(0,e2.toRem)(2)},children:[(0,T.jsx)(Q.Typography,{variant:"caption",fontWeight:900,children:C}),i&&(0,T.jsx)(Q.Typography,{variant:"caption",fontWeight:900,color:"error",children:"*"})]});var o2=require("react-hook-form"),H2=require("@s_mart/core"),r2=require("react/jsx-runtime"),Z=({name:C})=>{var e,H,o;let i=(0,o2.useFormContext)();return(H=(e=i==null?void 0:i.formState)==null?void 0:e.errors)!=null&&H[C]?(0,r2.jsx)(H2.Indicator,{severity:"error",children:(o=i.formState.errors[C])==null?void 0:o.message}):null};var n2=C2(require("@s_mart/masks")),b=require("react/jsx-runtime"),v2=({name:C,rules:i,defaultValue:e,shouldUnregister:H,label:o,required:M,mask:r,...L})=>{let V=(0,I.useFormContext)();if(!V)throw new Error("Para usar o <TextField /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let l=n=>r?n2[r].format(n):n,c=n=>r?n2[r].parse(n):n,a=n=>{if(!n||r!=="porcentagem")return;n==null||n.stopPropagation();let d=(n==null?void 0:n.target).value;if(d){let x=String(d);if(x.length>0){let S=x.indexOf("%");S>-1&&(n.currentTarget.selectionEnd=S)}}};return(0,b.jsx)(I.Controller,{control:V.control,name:C,rules:i,defaultValue:e,shouldUnregister:H,render:({field:{value:n,onChange:d}})=>(0,b.jsxs)(G.Grid,{display:"flex",flexDirection:"column",children:[o&&(0,b.jsx)(t,{label:o,required:M}),(0,b.jsx)(G.TextField,{size:"small",variant:"outlined",autoComplete:"off",defaultValue:e,value:l(n||""),onChange:x=>d(c(x.target.value)),InputProps:{onKeyDown:a},...L}),(0,b.jsx)(Z,{name:C})]})})},l2=v2;var R=require("react-hook-form"),F=require("@mui/material");var m=require("react/jsx-runtime"),S2=({name:C,rules:i,defaultValue:e,shouldUnregister:H,label:o,required:M,options:r,...L})=>{let V=(0,R.useFormContext)();if(!V)throw new Error("Para usar o <Select /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,m.jsx)(R.Controller,{control:V.control,name:C,rules:i,defaultValue:e,shouldUnregister:H,render:({field:{value:l,onChange:c}})=>(0,m.jsxs)(F.Grid,{display:"flex",flexDirection:"column",children:[o&&(0,m.jsx)(t,{label:o,required:M}),(0,m.jsx)(F.Select,{size:"small",variant:"outlined",autoComplete:"off",value:l||"",onChange:c,...L,children:r==null?void 0:r.map((a,n)=>(0,m.jsx)(F.MenuItem,{value:a.value,children:a.label},n))}),(0,m.jsx)(Z,{name:C})]})})},V2=S2;var U=require("react-hook-form"),w=require("@mui/material");var u=require("react/jsx-runtime"),B2=({name:C,rules:i,defaultValue:e,shouldUnregister:H,label:o,required:M,options:r,textFieldProps:L,...V})=>{let l=(0,U.useFormContext)();if(!l)throw new Error("Para usar o <Searchable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,u.jsx)(U.Controller,{control:l.control,name:C,rules:i,defaultValue:e,shouldUnregister:H,render:({field:{onChange:c}})=>(0,u.jsxs)(w.Grid,{display:"flex",flexDirection:"column",children:[o&&(0,u.jsx)(t,{label:o,required:M}),(0,u.jsx)(w.Autocomplete,{size:"small",onChange:(a,n)=>c(n),options:r,noOptionsText:"Nenhuma op\xE7\xE3o encontrada",...V,renderInput:a=>(0,u.jsx)(w.TextField,{...a,...L})}),(0,u.jsx)(Z,{name:C})]})})},L2=B2;var q=require("react-hook-form"),f=require("@mui/material"),Z2=require("@s_mart/core");var d2={description:"M35.8286 21.8493H26.1506V12.1714C26.1506 11.6338 25.613 11.0961 25.0753 11.0961H22.9247C22.3198 11.0961 21.8493 11.6338 21.8493 12.1714V21.8493H12.1714C11.5666 21.8493 11.0961 22.387 11.0961 22.9247V25.0753C11.0961 25.6802 11.5666 26.1506 12.1714 26.1506H21.8493V35.8286C21.8493 36.4334 22.3198 36.9039 22.9247 36.9039H25.0753C25.613 36.9039 26.1506 36.4334 26.1506 35.8286V26.1506H35.8286C36.3662 26.1506 36.9039 25.6802 36.9039 25.0753V22.9247C36.9039 22.387 36.3662 21.8493 35.8286 21.8493Z",viewBox:"0 0 48 48",id:"line-plus-solid"};var p=require("@s_mart/utils"),Y=C2(require("@emotion/styled")),J=require("@emotion/react"),t2=J.css`
2
+ display: flex;
3
+ align-items: center;
4
+ justify-content: center;
5
+ `,T2=C=>J.css`
6
+ .MuiAutocomplete-endAdornment {
7
+ position: relative;
8
+ right: 0;
9
+ }
10
+
11
+ .creatable {
12
+ ${t2}
13
+
14
+ .divider {
15
+ width: 1px;
16
+ height: ${(0,p.toRem)(20)};
17
+ background-color: ${C.palette.grey[400]};
18
+ }
19
+
20
+ .button {
21
+ display: flex;
22
+ justify-content: center;
23
+ align-items: center;
24
+ color: ${C.palette.grey[600]};
25
+ border-radius: 50%;
26
+
27
+ margin: 0 ${(0,p.toRem)(6)};
28
+ width: ${(0,p.toRem)(28)};
29
+ height: ${(0,p.toRem)(28)};
30
+
31
+ &:hover {
32
+ cursor: pointer;
33
+ background-color: ${C.palette.grey[100]};
34
+ transition: background-color 0.2s ease-in-out;
35
+ }
36
+ }
37
+ }
38
+ `,s2=Y.default.div`
39
+ display: flex;
40
+
41
+ div.endAdornments {
42
+ position: absolute;
43
+ right: 0;
44
+
45
+ ${t2}
46
+ }
47
+
48
+ ${({hideAddButton:C,theme:i})=>!C&&T2(i)}
49
+ `,M2=Y.default.div`
50
+ color: ${({theme:C})=>C.palette.text.primary};
51
+
52
+ padding: ${(0,p.toRem)(6)} ${(0,p.toRem)(16)};
53
+ margin: ${(0,p.toRem)(-6)} ${(0,p.toRem)(-16)};
54
+
55
+ &:hover {
56
+ cursor: pointer;
57
+ transition: background-color 0.2s ease-in-out;
58
+ background-color: ${({theme:C})=>C.palette.grey[100]};
59
+ }
60
+ `;var s=require("react/jsx-runtime"),A2=({name:C,rules:i,defaultValue:e,shouldUnregister:H,label:o,required:M,options:r,onCreateOption:L,textFieldProps:V,hideAddButton:l,...c})=>{let a=(0,q.useFormContext)();if(!a)throw new Error("Para usar o <Creatable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let n=d=>{L?L(d):console.error("onCreateOption n\xE3o foi definido")};return(0,s.jsx)(q.Controller,{control:a.control,name:C,rules:i,defaultValue:e,shouldUnregister:H,render:({field:{value:d,onChange:x}})=>{let S=(d==null?void 0:d.label)||(d==null?void 0:d.value)||d;return(0,s.jsxs)(f.Grid,{display:"flex",flexDirection:"column",children:[o&&(0,s.jsx)(t,{label:o,required:M}),(0,s.jsx)(s2,{hideAddButton:l,children:(0,s.jsx)(f.Autocomplete,{size:"small",fullWidth:!0,onChange:(B,_)=>x(_),options:r,noOptionsText:(0,s.jsx)(M2,{onClick:()=>n(d),children:(0,s.jsxs)(f.Typography,{children:["Adicionar ",S&&`"${S}"`]})}),...c,renderInput:B=>{let _=l?B.InputProps:{...B.InputProps,endAdornment:(0,s.jsxs)("div",{className:"endAdornments",children:[B.InputProps.endAdornment,(0,s.jsxs)("div",{className:"creatable",children:[(0,s.jsx)("div",{className:"divider"}),(0,s.jsx)("div",{className:"button",onClick:()=>n(d),children:(0,s.jsx)(Z2.LIcon,{icon:d2,size:"24"})})]})]})};return(0,s.jsx)(f.TextField,{...B,onChange:x,InputProps:_,...V})}})}),(0,s.jsx)(Z,{name:C})]})}})},c2=A2;var $=require("react-hook-form"),P=require("@mui/material");var g=require("react/jsx-runtime"),E2=({name:C,rules:i,defaultValue:e,shouldUnregister:H,label:o,labelPlacement:M,required:r,...L})=>{let V=(0,$.useFormContext)();if(!V)throw new Error("Para usar o <Checkbox /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,g.jsx)($.Controller,{control:V.control,name:C,rules:i,defaultValue:e,shouldUnregister:H,render:({field:{value:l,onChange:c}})=>(0,g.jsxs)(P.Grid,{display:"flex",flexDirection:"column",children:[(0,g.jsx)(P.FormControlLabel,{control:(0,g.jsx)(P.Checkbox,{value:l??"",defaultValue:l,onChange:c,...L}),label:(0,g.jsx)(t,{label:o,required:r}),labelPlacement:M||"end"}),(0,g.jsx)(Z,{name:C})]})})},a2=E2;var O=require("react-hook-form"),k=require("@mui/material");var h=require("react/jsx-runtime"),D2=({name:C,rules:i,defaultValue:e,shouldUnregister:H,label:o,labelPlacement:M,required:r,...L})=>{let V=(0,O.useFormContext)();if(!V)throw new Error("Para usar o <Switch /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,h.jsx)(O.Controller,{control:V.control,name:C,rules:i,defaultValue:e,shouldUnregister:H,render:({field:{value:l,onChange:c}})=>(0,h.jsxs)(k.Grid,{display:"flex",flexDirection:"column",children:[(0,h.jsx)(k.FormControlLabel,{control:(0,h.jsx)(k.Switch,{value:l??"",defaultValue:l,onChange:c,...L}),label:(0,h.jsx)(t,{label:o}),labelPlacement:M||"end"}),(0,h.jsx)(Z,{name:C})]})})},p2=D2;var v=require("@mui/material");var A=require("react/jsx-runtime"),I2=({label:C,labelPlacement:i,...e})=>(0,A.jsx)(v.Grid,{display:"flex",flexDirection:"column",children:(0,A.jsx)(v.FormControlLabel,{control:(0,A.jsx)(v.Radio,{...e}),label:(0,A.jsx)(t,{label:C}),labelPlacement:i||"end"})}),m2=I2;var N=require("react-hook-form"),W=require("@mui/material");var y=require("react/jsx-runtime"),G2=({name:C,rules:i,defaultValue:e,shouldUnregister:H,label:o,required:M,children:r,orientation:L="row",...V})=>{let l=(0,N.useFormContext)();if(!l)throw new Error("Para usar o <RadioGroup /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,y.jsx)(N.Controller,{control:l.control,name:C,rules:i,defaultValue:e,shouldUnregister:H,render:({field:{value:c,onChange:a}})=>(0,y.jsxs)(W.Grid,{display:"flex",flexDirection:"column",children:[o&&(0,y.jsx)(t,{label:o,required:M}),(0,y.jsx)(W.RadioGroup,{value:c||"",onChange:a,name:C,...V,style:{display:"flex",flexDirection:L},children:r}),(0,y.jsx)(Z,{name:C})]})})},u2=G2;var z=require("react-hook-form"),f2=require("@mui/material"),X=require("react/jsx-runtime"),R2=({name:C,rules:i,defaultValue:e,shouldUnregister:H,label:o,labelPlacement:M,...r})=>{let L=(0,z.useFormContext)();if(!L)throw new Error("Para usar o <Slider /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,X.jsx)(z.Controller,{control:L.control,name:C,rules:i,defaultValue:e,shouldUnregister:H,render:({field:{value:V,onChange:l}})=>(0,X.jsx)(f2.Slider,{value:V||(r==null?void 0:r.min)||0,onChange:l,valueLabelDisplay:"auto",...r})})},g2=R2;0&&(module.exports={Checkbox,Creatable,Form,RadioButton,RadioGroup,Searchable,Select,Slider,Switch,TextField});
package/dist/index.mjs ADDED
@@ -0,0 +1,60 @@
1
+ import{FormProvider as q,useForm as $}from"react-hook-form";import{jsx as v}from"react/jsx-runtime";function O({children:C,onSubmit:i,...e}){let n=$(e);return v(q,{...n,children:v("form",{onSubmit:n.handleSubmit(i),children:C})})}var N=O;import{Controller as Y,useFormContext as J}from"react-hook-form";import{Grid as X,TextField as j}from"@mui/material";import{Typography as S}from"@mui/material";import{toRem as W}from"@s_mart/utils";import{jsx as B,jsxs as z}from"react/jsx-runtime";var t=({label:C,required:i})=>z("span",{style:{display:"flex",gap:W(2)},children:[B(S,{variant:"caption",fontWeight:900,children:C}),i&&B(S,{variant:"caption",fontWeight:900,color:"error",children:"*"})]});import{useFormContext as _}from"react-hook-form";import{Indicator as K}from"@s_mart/core";import{jsx as Q}from"react/jsx-runtime";var M=({name:C})=>{var e,n,r;let i=_();return(n=(e=i==null?void 0:i.formState)==null?void 0:e.errors)!=null&&n[C]?Q(K,{severity:"error",children:(r=i.formState.errors[C])==null?void 0:r.message}):null};import*as T from"@s_mart/masks";import{jsx as y,jsxs as e2}from"react/jsx-runtime";var C2=({name:C,rules:i,defaultValue:e,shouldUnregister:n,label:r,required:s,mask:o,...L})=>{let V=J();if(!V)throw new Error("Para usar o <TextField /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let l=H=>o?T[o].format(H):H,Z=H=>o?T[o].parse(H):H,c=H=>{if(!H||o!=="porcentagem")return;H==null||H.stopPropagation();let d=(H==null?void 0:H.target).value;if(d){let m=String(d);if(m.length>0){let u=m.indexOf("%");u>-1&&(H.currentTarget.selectionEnd=u)}}};return y(Y,{control:V.control,name:C,rules:i,defaultValue:e,shouldUnregister:n,render:({field:{value:H,onChange:d}})=>e2(X,{display:"flex",flexDirection:"column",children:[r&&y(t,{label:r,required:s}),y(j,{size:"small",variant:"outlined",autoComplete:"off",defaultValue:e,value:l(H||""),onChange:m=>d(Z(m.target.value)),InputProps:{onKeyDown:c},...L}),y(M,{name:C})]})})},i2=C2;import{Controller as o2,useFormContext as H2}from"react-hook-form";import{Grid as r2,Select as n2,MenuItem as l2}from"@mui/material";import{jsx as g,jsxs as d2}from"react/jsx-runtime";var V2=({name:C,rules:i,defaultValue:e,shouldUnregister:n,label:r,required:s,options:o,...L})=>{let V=H2();if(!V)throw new Error("Para usar o <Select /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return g(o2,{control:V.control,name:C,rules:i,defaultValue:e,shouldUnregister:n,render:({field:{value:l,onChange:Z}})=>d2(r2,{display:"flex",flexDirection:"column",children:[r&&g(t,{label:r,required:s}),g(n2,{size:"small",variant:"outlined",autoComplete:"off",value:l||"",onChange:Z,...L,children:o==null?void 0:o.map((c,H)=>g(l2,{value:c.value,children:c.label},H))}),g(M,{name:C})]})})},L2=V2;import{Controller as t2,useFormContext as s2}from"react-hook-form";import{Grid as M2,Autocomplete as Z2,TextField as c2}from"@mui/material";import{jsx as h,jsxs as m2}from"react/jsx-runtime";var a2=({name:C,rules:i,defaultValue:e,shouldUnregister:n,label:r,required:s,options:o,textFieldProps:L,...V})=>{let l=s2();if(!l)throw new Error("Para usar o <Searchable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return h(t2,{control:l.control,name:C,rules:i,defaultValue:e,shouldUnregister:n,render:({field:{onChange:Z}})=>m2(M2,{display:"flex",flexDirection:"column",children:[r&&h(t,{label:r,required:s}),h(Z2,{size:"small",onChange:(c,H)=>Z(H),options:o,noOptionsText:"Nenhuma op\xE7\xE3o encontrada",...V,renderInput:c=>h(c2,{...c,...L})}),h(M,{name:C})]})})},p2=a2;import{Controller as f2,useFormContext as g2}from"react-hook-form";import{Grid as h2,Autocomplete as x2,TextField as b2,Typography as y2}from"@mui/material";import{LIcon as F2}from"@s_mart/core";var A={description:"M35.8286 21.8493H26.1506V12.1714C26.1506 11.6338 25.613 11.0961 25.0753 11.0961H22.9247C22.3198 11.0961 21.8493 11.6338 21.8493 12.1714V21.8493H12.1714C11.5666 21.8493 11.0961 22.387 11.0961 22.9247V25.0753C11.0961 25.6802 11.5666 26.1506 12.1714 26.1506H21.8493V35.8286C21.8493 36.4334 22.3198 36.9039 22.9247 36.9039H25.0753C25.613 36.9039 26.1506 36.4334 26.1506 35.8286V26.1506H35.8286C36.3662 26.1506 36.9039 25.6802 36.9039 25.0753V22.9247C36.9039 22.387 36.3662 21.8493 35.8286 21.8493Z",viewBox:"0 0 48 48",id:"line-plus-solid"};import{toRem as p}from"@s_mart/utils";import E from"@emotion/styled";import{css as D}from"@emotion/react";var I=D`
2
+ display: flex;
3
+ align-items: center;
4
+ justify-content: center;
5
+ `,u2=C=>D`
6
+ .MuiAutocomplete-endAdornment {
7
+ position: relative;
8
+ right: 0;
9
+ }
10
+
11
+ .creatable {
12
+ ${I}
13
+
14
+ .divider {
15
+ width: 1px;
16
+ height: ${p(20)};
17
+ background-color: ${C.palette.grey[400]};
18
+ }
19
+
20
+ .button {
21
+ display: flex;
22
+ justify-content: center;
23
+ align-items: center;
24
+ color: ${C.palette.grey[600]};
25
+ border-radius: 50%;
26
+
27
+ margin: 0 ${p(6)};
28
+ width: ${p(28)};
29
+ height: ${p(28)};
30
+
31
+ &:hover {
32
+ cursor: pointer;
33
+ background-color: ${C.palette.grey[100]};
34
+ transition: background-color 0.2s ease-in-out;
35
+ }
36
+ }
37
+ }
38
+ `,G=E.div`
39
+ display: flex;
40
+
41
+ div.endAdornments {
42
+ position: absolute;
43
+ right: 0;
44
+
45
+ ${I}
46
+ }
47
+
48
+ ${({hideAddButton:C,theme:i})=>!C&&u2(i)}
49
+ `,R=E.div`
50
+ color: ${({theme:C})=>C.palette.text.primary};
51
+
52
+ padding: ${p(6)} ${p(16)};
53
+ margin: ${p(-6)} ${p(-16)};
54
+
55
+ &:hover {
56
+ cursor: pointer;
57
+ transition: background-color 0.2s ease-in-out;
58
+ background-color: ${({theme:C})=>C.palette.grey[100]};
59
+ }
60
+ `;import{jsx as a,jsxs as F}from"react/jsx-runtime";var w2=({name:C,rules:i,defaultValue:e,shouldUnregister:n,label:r,required:s,options:o,onCreateOption:L,textFieldProps:V,hideAddButton:l,...Z})=>{let c=g2();if(!c)throw new Error("Para usar o <Creatable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let H=d=>{L?L(d):console.error("onCreateOption n\xE3o foi definido")};return a(f2,{control:c.control,name:C,rules:i,defaultValue:e,shouldUnregister:n,render:({field:{value:d,onChange:m}})=>{let u=(d==null?void 0:d.label)||(d==null?void 0:d.value)||d;return F(h2,{display:"flex",flexDirection:"column",children:[r&&a(t,{label:r,required:s}),a(G,{hideAddButton:l,children:a(x2,{size:"small",fullWidth:!0,onChange:(f,k)=>m(k),options:o,noOptionsText:a(R,{onClick:()=>H(d),children:F(y2,{children:["Adicionar ",u&&`"${u}"`]})}),...Z,renderInput:f=>{let k=l?f.InputProps:{...f.InputProps,endAdornment:F("div",{className:"endAdornments",children:[f.InputProps.endAdornment,F("div",{className:"creatable",children:[a("div",{className:"divider"}),a("div",{className:"button",onClick:()=>H(d),children:a(F2,{icon:A,size:"24"})})]})]})};return a(b2,{...f,onChange:m,InputProps:k,...V})}})}),a(M,{name:C})]})}})},P2=w2;import{Controller as k2,useFormContext as v2}from"react-hook-form";import{Grid as S2,Checkbox as B2,FormControlLabel as T2}from"@mui/material";import{jsx as x,jsxs as D2}from"react/jsx-runtime";var A2=({name:C,rules:i,defaultValue:e,shouldUnregister:n,label:r,labelPlacement:s,required:o,...L})=>{let V=v2();if(!V)throw new Error("Para usar o <Checkbox /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return x(k2,{control:V.control,name:C,rules:i,defaultValue:e,shouldUnregister:n,render:({field:{value:l,onChange:Z}})=>D2(S2,{display:"flex",flexDirection:"column",children:[x(T2,{control:x(B2,{value:l??"",defaultValue:l,onChange:Z,...L}),label:x(t,{label:r,required:o}),labelPlacement:s||"end"}),x(M,{name:C})]})})},E2=A2;import{Controller as I2,useFormContext as G2}from"react-hook-form";import{Grid as R2,Switch as U2,FormControlLabel as q2}from"@mui/material";import{jsx as b,jsxs as N2}from"react/jsx-runtime";var $2=({name:C,rules:i,defaultValue:e,shouldUnregister:n,label:r,labelPlacement:s,required:o,...L})=>{let V=G2();if(!V)throw new Error("Para usar o <Switch /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return b(I2,{control:V.control,name:C,rules:i,defaultValue:e,shouldUnregister:n,render:({field:{value:l,onChange:Z}})=>N2(R2,{display:"flex",flexDirection:"column",children:[b(q2,{control:b(U2,{value:l??"",defaultValue:l,onChange:Z,...L}),label:b(t,{label:r}),labelPlacement:s||"end"}),b(M,{name:C})]})})},O2=$2;import{Grid as W2,Radio as z2,FormControlLabel as _2}from"@mui/material";import{jsx as w}from"react/jsx-runtime";var K2=({label:C,labelPlacement:i,...e})=>w(W2,{display:"flex",flexDirection:"column",children:w(_2,{control:w(z2,{...e}),label:w(t,{label:C}),labelPlacement:i||"end"})}),Q2=K2;import{Controller as Y2,useFormContext as J2}from"react-hook-form";import{Grid as X2,RadioGroup as j2}from"@mui/material";import{jsx as P,jsxs as e3}from"react/jsx-runtime";var C3=({name:C,rules:i,defaultValue:e,shouldUnregister:n,label:r,required:s,children:o,orientation:L="row",...V})=>{let l=J2();if(!l)throw new Error("Para usar o <RadioGroup /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return P(Y2,{control:l.control,name:C,rules:i,defaultValue:e,shouldUnregister:n,render:({field:{value:Z,onChange:c}})=>e3(X2,{display:"flex",flexDirection:"column",children:[r&&P(t,{label:r,required:s}),P(j2,{value:Z||"",onChange:c,name:C,...V,style:{display:"flex",flexDirection:L},children:o}),P(M,{name:C})]})})},i3=C3;import{Controller as o3,useFormContext as H3}from"react-hook-form";import{Slider as r3}from"@mui/material";import{jsx as U}from"react/jsx-runtime";var n3=({name:C,rules:i,defaultValue:e,shouldUnregister:n,label:r,labelPlacement:s,...o})=>{let L=H3();if(!L)throw new Error("Para usar o <Slider /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return U(o3,{control:L.control,name:C,rules:i,defaultValue:e,shouldUnregister:n,render:({field:{value:V,onChange:l}})=>U(r3,{value:V||(o==null?void 0:o.min)||0,onChange:l,valueLabelDisplay:"auto",...o})})},l3=n3;export{E2 as Checkbox,P2 as Creatable,N as Form,Q2 as RadioButton,i3 as RadioGroup,p2 as Searchable,L2 as Select,l3 as Slider,O2 as Switch,i2 as TextField};
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@s_mart/form",
3
+ "version": "1.4.2",
4
+ "main": "./dist/index.js",
5
+ "module": "./dist/index.mjs",
6
+ "types": "./dist/index.d.ts",
7
+ "sideEffects": false,
8
+ "license": "MIT",
9
+ "files": [
10
+ "dist/**"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsup src/index.tsx --minify --format esm,cjs --dts --external react",
14
+ "dev": "tsup src/index.tsx --format esm,cjs --watch --dts --external react",
15
+ "lint": "TIMING=1 eslint src/**/*.ts* --fix",
16
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
17
+ },
18
+ "dependencies": {
19
+ "tsup": "^6.2.3",
20
+ "typescript": "^4.5.3",
21
+ "@types/react": "18.0.18",
22
+ "@types/react-dom": "18.0.6",
23
+ "@s_mart/typed": "*",
24
+ "@s_mart/utils": "*",
25
+ "@s_mart/masks": "*"
26
+ },
27
+ "peerDependencies": {
28
+ "react": ">=18.0.0",
29
+ "react-dom": ">=18.0.0",
30
+ "typescript": ">=4.5.3",
31
+ "react-hook-form": ">=7.36.1",
32
+ "@mui/material": ">=5.10.6",
33
+ "@types/react": ">=18.0.18",
34
+ "@types/react-dom": ">=18.0.6",
35
+ "@emotion/react": ">=11.10.4",
36
+ "@emotion/styled": ">=11.10.4",
37
+ "@s_mart/core": "*"
38
+ },
39
+ "devDependencies": {
40
+ "@s_mart/eslint-config": "*",
41
+ "@s_mart/tsconfig": "*",
42
+ "eslint": "^8.15.0"
43
+ }
44
+ }