@s_mart/form 2.5.0 → 2.5.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 +1 -1
- package/dist/index.js +10 -10
- package/dist/index.mjs +8 -8
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ type SelectProps = SelectProps$1 & ControllerSelect & {
|
|
|
26
26
|
options: SelectOption[];
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
declare const Select: ({ name, rules, defaultValue, shouldUnregister, label, required, options, ...rest }: SelectProps) => JSX.Element;
|
|
29
|
+
declare const Select: ({ name, rules, defaultValue, shouldUnregister, label, required, options, placeholder, ...rest }: SelectProps) => JSX.Element;
|
|
30
30
|
|
|
31
31
|
type ControllerSearchable = Omit<ControllerProps, 'render' | 'control'>;
|
|
32
32
|
type SearchableOption = {
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var $e=Object.create;var z=Object.defineProperty,Me=Object.defineProperties,Ve=Object.getOwnPropertyDescriptor,Ue=Object.getOwnPropertyDescriptors,ve=Object.getOwnPropertyNames,W=Object.getOwnPropertySymbols,Ne=Object.getPrototypeOf,te=Object.prototype.hasOwnProperty,pe=Object.prototype.propertyIsEnumerable;var de=(e,r,o)=>r in e?z(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o,i=(e,r)=>{for(var o in r||(r={}))te.call(r,o)&&de(e,o,r[o]);if(W)for(var o of W(r))pe.call(r,o)&&de(e,o,r[o]);return e},F=(e,r)=>Me(e,Ue(r));var m=(e,r)=>{var o={};for(var l in e)te.call(e,l)&&r.indexOf(l)<0&&(o[l]=e[l]);if(e!=null&&W)for(var l of W(e))r.indexOf(l)<0&&pe.call(e,l)&&(o[l]=e[l]);return o};var ke=(e,r)=>{for(var o in r)z(e,o,{get:r[o],enumerable:!0})},me=(e,r,o,l)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of ve(r))!te.call(e,t)&&t!==o&&z(e,t,{get:()=>r[t],enumerable:!(l=Ve(r,t))||l.enumerable});return e};var ue=(e,r,o)=>(o=e!=null?$e(Ne(e)):{},me(r||!e||!e.__esModule?z(o,"default",{value:e,enumerable:!0}):o,e)),Oe=e=>me(z({},"__esModule",{value:!0}),e);var Ze={};ke(Ze,{Checkbox:()=>Re,Creatable:()=>Ie,Form:()=>ce,RadioButton:()=>Ae,RadioGroup:()=>De,Searchable:()=>Pe,Select:()=>Ce,Slider:()=>qe,Switch:()=>Ge,TextField:()=>ge});module.exports=Oe(Ze);var fe=require("react"),j=require("react-hook-form");var le=require("react/jsx-runtime");function ze(l){var t=l,{children:e,onSubmit:r}=t,o=m(t,["children","onSubmit"]);let d=(0,j.useForm)(o);(0,fe.useEffect)(()=>{d.reset(o.defaultValues)},[o.defaultValues,d.reset]);let n=()=>typeof e=="function"?e(F(i({},d),{onSubmit:d.handleSubmit(r)})):e;return(0,le.jsx)(j.FormProvider,F(i({},d),{children:(0,le.jsx)("form",{onSubmit:d.handleSubmit(r),children:n()})}))}var ce=ze;var Fe=require("react"),H=require("react-hook-form"),K=require("phosphor-react"),V=require("@mui/material"),M=ue(require("@s_mart/masks"));var ie=require("@mui/material"),xe=require("@s_mart/utils"),_=require("react/jsx-runtime"),h=({label:e,required:r,regular:o})=>(0,_.jsxs)("span",{style:{display:"flex",alignItems:"center",gap:(0,xe.toRem)(2)},children:[(0,_.jsx)(ie.Typography,{variant:"caption",fontWeight:o?400:700,style:{display:"flex",alignItems:"center"},children:e}),r&&(0,_.jsx)(ie.Typography,{variant:"caption",fontWeight:900,color:"error",children:"*"})]});var ye=require("react-hook-form"),he=require("@s_mart/core"),be=require("react/jsx-runtime"),S=({name:e})=>{var o,l,t;let r=(0,ye.useFormContext)();return(l=(o=r==null?void 0:r.formState)==null?void 0:o.errors)!=null&&l[e]?(0,be.jsx)(he.Indicator,{severity:"error",children:(t=r.formState.errors[e])==null?void 0:t.message}):null};var E=require("react/jsx-runtime"),_e=g=>{var p=g,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:d,mask:n,variant:x="outlined"}=p,u=m(p,["name","rules","defaultValue","shouldUnregister","label","required","mask","variant"]);let f=(0,H.useFormContext)();if(!f)throw new Error("Para usar o <TextField /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let[C,w]=(0,Fe.useState)(!1),P=c=>{var s;return n?(s=M==null?void 0:M[n])==null?void 0:s.format(c):c},a=c=>{var s;return n?(s=M==null?void 0:M[n])==null?void 0:s.parse(c):c},$=c=>{if(!c||n!=="porcentagem")return;c==null||c.stopPropagation();let s=(c==null?void 0:c.target).value;if(s){let y=String(s);if(y.length>0){let O=y.indexOf("%");O>-1&&(c.currentTarget.selectionEnd=O)}}};return(0,E.jsx)(H.Controller,{control:f.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:c,onChange:s}})=>(0,E.jsxs)(V.Grid,{display:"flex",flexDirection:"column",children:[t&&(0,E.jsx)(h,{label:t,required:d}),(0,E.jsx)(V.TextField,F(i({size:"small",variant:x,autoComplete:"off",defaultValue:o,value:P(c||""),onChange:y=>{var O;return s(a((O=y==null?void 0:y.target)==null?void 0:O.value))}},u),{type:u.type==="password"?C?"text":"password":u.type,InputProps:i({onKeyDown:$,endAdornment:u.type==="password"&&(0,E.jsx)(V.InputAdornment,{position:"end",onClick:()=>w(!C),style:{cursor:"pointer"},children:C?(0,E.jsx)(K.Eye,{size:20}):(0,E.jsx)(K.EyeSlash,{size:20})})},u.InputProps)})),(0,E.jsx)(S,{name:e})]})})},ge=_e;var J=require("react-hook-form"),I=require("@mui/material");var T=require("react/jsx-runtime"),Be=g=>{var p=g,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:d,options:n,placeholder:x}=p,u=m(p,["name","rules","defaultValue","shouldUnregister","label","required","options","placeholder"]);let f=(0,J.useFormContext)(),{palette:C}=(0,I.useTheme)();if(!f)throw new Error("Para usar o <Select /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,T.jsx)(J.Controller,{control:f.control,name:e,rules:r,defaultValue:o||"",shouldUnregister:l,render:({field:{value:w,onChange:P}})=>(0,T.jsxs)(I.Grid,{display:"flex",flexDirection:"column",children:[t&&(0,T.jsx)(h,{label:t,required:d}),(0,T.jsxs)(I.Select,F(i({displayEmpty:Boolean(x),size:"small",variant:"outlined",autoComplete:"off",value:w||"",onChange:P},u),{children:[x&&(0,T.jsx)(I.MenuItem,{disabled:!0,value:"",children:(0,T.jsx)("p",{style:{color:C.grey[400]},children:x})}),n==null?void 0:n.map((a,$)=>(0,T.jsx)(I.MenuItem,{value:a.value,children:a.label},$))]})),(0,T.jsx)(S,{name:e})]})})},Ce=Be;var Q=require("react-hook-form"),U=require("@mui/material");var G=require("react/jsx-runtime"),We=g=>{var p=g,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:d,options:n,textFieldProps:x}=p,u=m(p,["name","rules","defaultValue","shouldUnregister","label","required","options","textFieldProps"]);let f=(0,Q.useFormContext)();if(!f)throw new Error("Para usar o <Searchable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,G.jsx)(Q.Controller,{control:f.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{onChange:C,value:w}})=>(0,G.jsxs)(U.Grid,{display:"flex",flexDirection:"column",children:[t&&(0,G.jsx)(h,{label:t,required:d}),(0,G.jsx)(U.Autocomplete,F(i({size:"small",onChange:(P,a)=>C(a),value:w,options:n,noOptionsText:"Nenhuma op\xE7\xE3o encontrada",isOptionEqualToValue:(P,a)=>typeof P=="string"&&typeof a=="string"?P===a:typeof P=="object"&&typeof a=="object"?P.value===a.value:!1},u),{renderInput:P=>(0,G.jsx)(U.TextField,i(i({},P),x))})),(0,G.jsx)(S,{name:e})]})})},Pe=We;var X=require("react-hook-form"),Te=require("phosphor-react"),A=require("@mui/material");var R=require("@s_mart/utils"),ne=ue(require("@emotion/styled")),ae=require("@emotion/react"),Se=ae.css`
|
|
2
2
|
display: flex;
|
|
3
3
|
align-items: center;
|
|
4
4
|
justify-content: center;
|
|
5
|
-
`,
|
|
5
|
+
`,je=e=>ae.css`
|
|
6
6
|
.MuiAutocomplete-endAdornment {
|
|
7
7
|
position: relative;
|
|
8
8
|
right: 0;
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
.divider {
|
|
15
15
|
width: 1px;
|
|
16
|
-
height: ${(0,
|
|
16
|
+
height: ${(0,R.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,R.toRem)(6)};
|
|
28
|
+
width: ${(0,R.toRem)(28)};
|
|
29
|
+
height: ${(0,R.toRem)(28)};
|
|
30
30
|
|
|
31
31
|
&:hover {
|
|
32
32
|
cursor: pointer;
|
|
@@ -45,16 +45,16 @@
|
|
|
45
45
|
${Se}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
${({hideAddButton:e,theme:r})=>!e&&
|
|
48
|
+
${({hideAddButton:e,theme:r})=>!e&&je(r)}
|
|
49
49
|
`,Ee=ne.default.div`
|
|
50
50
|
color: ${({theme:e})=>e.palette.text.primary};
|
|
51
51
|
|
|
52
|
-
padding: ${(0,
|
|
53
|
-
margin: ${(0,
|
|
52
|
+
padding: ${(0,R.toRem)(6)} ${(0,R.toRem)(16)};
|
|
53
|
+
margin: ${(0,R.toRem)(-6)} ${(0,R.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 b=require("react/jsx-runtime"),He=f=>{var C=f,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:d,options:n,onCreateOption:x,textFieldProps:u,hideAddButton:g}=C,p=m(C,["name","rules","defaultValue","shouldUnregister","label","required","options","onCreateOption","textFieldProps","hideAddButton"]);let w=(0,X.useFormContext)();if(!w)throw new Error("Para usar o <Creatable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let P=a=>{x?x(a):console.error("onCreateOption n\xE3o foi definido")};return(0,b.jsx)(X.Controller,{control:w.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:a,onChange:$}})=>{let c=(a==null?void 0:a.label)||(a==null?void 0:a.value)||a;return(0,b.jsxs)(A.Grid,{display:"flex",flexDirection:"column",children:[t&&(0,b.jsx)(h,{label:t,required:d}),(0,b.jsx)(we,{hideAddButton:g,children:(0,b.jsx)(A.Autocomplete,F(i({size:"small",fullWidth:!0,onChange:(s,y)=>$(y),options:n,value:a,noOptionsText:(0,b.jsx)(Ee,{onClick:()=>P(a),children:(0,b.jsxs)(A.Typography,{children:["Adicionar ",c&&`"${c}"`]})}),isOptionEqualToValue:(s,y)=>y?typeof s=="string"&&typeof y=="string"?s===y:typeof s=="object"&&typeof y=="object"?s.value===y.value:typeof s=="object"&&typeof y=="string":!1},p),{renderInput:s=>{let y=g?s.InputProps:F(i({},s.InputProps),{endAdornment:(0,b.jsxs)("div",{className:"endAdornments",children:[s.InputProps.endAdornment,(0,b.jsxs)("div",{className:"creatable",children:[(0,b.jsx)("div",{className:"divider"}),(0,b.jsx)("div",{className:"button",onClick:()=>P(a),children:(0,b.jsx)(Te.Plus,{size:18,weight:"bold"})})]})]})});return(0,b.jsx)(A.TextField,i(F(i({},s),{onChange:$,InputProps:y}),u))}}))}),(0,b.jsx)(S,{name:e})]})}})},Ie=He;var Y=require("react-hook-form"),v=require("@mui/material");var D=require("react/jsx-runtime"),Ke=u=>{var g=u,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,labelPlacement:d,required:n}=g,x=m(g,["name","rules","defaultValue","shouldUnregister","label","labelPlacement","required"]);let p=(0,Y.useFormContext)();if(!p)throw new Error("Para usar o <Checkbox /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,D.jsx)(Y.Controller,{control:p.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:f,onChange:C}})=>(0,D.jsxs)(v.Grid,{display:"flex",flexDirection:"column",children:[(0,D.jsx)(v.FormControlLabel,{control:(0,D.jsx)(v.Checkbox,i({value:f!=null?f:"",defaultValue:f,onChange:C},x)),label:(0,D.jsx)(h,{label:t,required:n,regular:!0}),labelPlacement:d||"end"}),(0,D.jsx)(S,{name:e})]})})},Re=Ke;var Z=require("react-hook-form"),N=require("@mui/material");var L=require("react/jsx-runtime"),Je=x=>{var u=x,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,labelPlacement:d}=u,n=m(u,["name","rules","defaultValue","shouldUnregister","label","labelPlacement"]);let g=(0,Z.useFormContext)();if(!g)throw new Error("Para usar o <Switch /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,L.jsx)(Z.Controller,{control:g.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:p,onChange:f}})=>(0,L.jsxs)(N.Grid,{display:"flex",flexDirection:"column",children:[(0,L.jsx)(N.FormControlLabel,{control:(0,L.jsx)(N.Switch,i({value:p!=null?p:"",defaultValue:p,onChange:f},n)),label:(0,L.jsx)(h,{label:t}),labelPlacement:d||"end"}),(0,L.jsx)(S,{name:e})]})})},Ge=Je;var k=require("@mui/material");var B=require("react/jsx-runtime"),Qe=l=>{var t=l,{label:e,labelPlacement:r}=t,o=m(t,["label","labelPlacement"]);return(0,B.jsx)(k.Grid,{display:"flex",flexDirection:"column",children:(0,B.jsx)(k.FormControlLabel,{control:(0,B.jsx)(k.Radio,i({},o)),label:(0,B.jsx)(h,{label:e}),labelPlacement:r||"end"})})},Ae=Qe;var ee=require("react-hook-form"),re=require("@mui/material");var q=require("react/jsx-runtime"),Xe=g=>{var p=g,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:d,children:n,orientation:x="row"}=p,u=m(p,["name","rules","defaultValue","shouldUnregister","label","required","children","orientation"]);let f=(0,ee.useFormContext)();if(!f)throw new Error("Para usar o <RadioGroup /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,q.jsx)(ee.Controller,{control:f.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:C,onChange:w}})=>(0,q.jsxs)(re.Grid,{display:"flex",flexDirection:"column",children:[t&&(0,q.jsx)(h,{label:t,required:d}),(0,q.jsx)(re.RadioGroup,F(i({value:C||"",onChange:w,name:e},u),{style:{display:"flex",flexDirection:x},children:n})),(0,q.jsx)(S,{name:e})]})})},De=Xe;var oe=require("react-hook-form"),Le=require("@mui/material");var se=require("react/jsx-runtime"),Ye=d=>{var n=d,{name:e,rules:r,defaultValue:o,shouldUnregister:l}=n,t=m(n,["name","rules","defaultValue","shouldUnregister"]);let x=(0,oe.useFormContext)();if(!x)throw new Error("Para usar o <Slider /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return(0,se.jsx)(oe.Controller,{control:x.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:u,onChange:g}})=>(0,se.jsx)(Le.Slider,i({value:u||(t==null?void 0:t.min)||0,onChange:g,valueLabelDisplay:"auto"},t))})},qe=Ye;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 Y=Object.defineProperty,Z=Object.defineProperties;var ee=Object.getOwnPropertyDescriptors;var $=Object.getOwnPropertySymbols;var N=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable;var v=(e,r,o)=>r in e?Y(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o,i=(e,r)=>{for(var o in r||(r={}))N.call(r,o)&&v(e,o,r[o]);if($)for(var o of $(r))k.call(r,o)&&v(e,o,r[o]);return e},b=(e,r)=>Z(e,ee(r));var m=(e,r)=>{var o={};for(var l in e)N.call(e,l)&&r.indexOf(l)<0&&(o[l]=e[l]);if(e!=null&&$)for(var l of $(e))r.indexOf(l)<0&&k.call(e,l)&&(o[l]=e[l]);return o};import{useEffect as re}from"react";import{FormProvider as oe,useForm as te}from"react-hook-form";import{jsx as O}from"react/jsx-runtime";function le(l){var t=l,{children:e,onSubmit:r}=t,o=m(t,["children","onSubmit"]);let d=te(o);re(()=>{d.reset(o.defaultValues)},[o.defaultValues,d.reset]);let n=()=>typeof e=="function"?e(b(i({},d),{onSubmit:d.handleSubmit(r)})):e;return O(oe,b(i({},d),{children:O("form",{onSubmit:d.handleSubmit(r),children:n()})}))}var ie=le;import{useState as me}from"react";import{Controller as ue,useFormContext as fe}from"react-hook-form";import{Eye as ce,EyeSlash as xe}from"phosphor-react";import{Grid as ye,InputAdornment as he,TextField as be}from"@mui/material";import*as R from"@s_mart/masks";import{Typography as z}from"@mui/material";import{toRem as ne}from"@s_mart/utils";import{jsx as _,jsxs as ae}from"react/jsx-runtime";var h=({label:e,required:r,regular:o})=>ae("span",{style:{display:"flex",alignItems:"center",gap:ne(2)},children:[_(z,{variant:"caption",fontWeight:o?400:700,style:{display:"flex",alignItems:"center"},children:e}),r&&_(z,{variant:"caption",fontWeight:900,color:"error",children:"*"})]});import{useFormContext as se}from"react-hook-form";import{Indicator as de}from"@s_mart/core";import{jsx as pe}from"react/jsx-runtime";var P=({name:e})=>{var o,l,t;let r=se();return(l=(o=r==null?void 0:r.formState)==null?void 0:o.errors)!=null&&l[e]?pe(de,{severity:"error",children:(t=r.formState.errors[e])==null?void 0:t.message}):null};import{jsx as T,jsxs as Ce}from"react/jsx-runtime";var Fe=F=>{var p=F,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:d,mask:n,variant:x="outlined"}=p,u=m(p,["name","rules","defaultValue","shouldUnregister","label","required","mask","variant"]);let f=fe();if(!f)throw new Error("Para usar o <TextField /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let[g,S]=me(!1),C=c=>{var s;return n?(s=R==null?void 0:R[n])==null?void 0:s.format(c):c},a=c=>{var s;return n?(s=R==null?void 0:R[n])==null?void 0:s.parse(c):c},I=c=>{if(!c||n!=="porcentagem")return;c==null||c.stopPropagation();let s=(c==null?void 0:c.target).value;if(s){let y=String(s);if(y.length>0){let A=y.indexOf("%");A>-1&&(c.currentTarget.selectionEnd=A)}}};return T(ue,{control:f.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:c,onChange:s}})=>Ce(ye,{display:"flex",flexDirection:"column",children:[t&&T(h,{label:t,required:d}),T(be,b(i({size:"small",variant:x,autoComplete:"off",defaultValue:o,value:C(c||""),onChange:y=>{var A;return s(a((A=y==null?void 0:y.target)==null?void 0:A.value))}},u),{type:u.type==="password"?g?"text":"password":u.type,InputProps:i({onKeyDown:I,endAdornment:u.type==="password"&&T(he,{position:"end",onClick:()=>S(!g),style:{cursor:"pointer"},children:g?T(ce,{size:20}):T(xe,{size:20})})},u.InputProps)})),T(P,{name:e})]})})},ge=Fe;import{Controller as Pe,useFormContext as Se}from"react-hook-form";import{Grid as we,Select as Ee,MenuItem as B,useTheme as Te}from"@mui/material";import{jsx as G,jsxs as W}from"react/jsx-runtime";var Ie=F=>{var p=F,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:d,options:n,placeholder:x}=p,u=m(p,["name","rules","defaultValue","shouldUnregister","label","required","options","placeholder"]);let f=Se(),{palette:g}=Te();if(!f)throw new Error("Para usar o <Select /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return G(Pe,{control:f.control,name:e,rules:r,defaultValue:o||"",shouldUnregister:l,render:({field:{value:S,onChange:C}})=>W(we,{display:"flex",flexDirection:"column",children:[t&&G(h,{label:t,required:d}),W(Ee,b(i({displayEmpty:Boolean(x),size:"small",variant:"outlined",autoComplete:"off",value:S||"",onChange:C},u),{children:[x&&G(B,{disabled:!0,value:"",children:G("p",{style:{color:g.grey[400]},children:x})}),n==null?void 0:n.map((a,I)=>G(B,{value:a.value,children:a.label},I))]})),G(P,{name:e})]})})},Re=Ie;import{Controller as Ge,useFormContext as Ae}from"react-hook-form";import{Grid as De,Autocomplete as Le,TextField as qe}from"@mui/material";import{jsx as D,jsxs as Ve}from"react/jsx-runtime";var $e=F=>{var p=F,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:d,options:n,textFieldProps:x}=p,u=m(p,["name","rules","defaultValue","shouldUnregister","label","required","options","textFieldProps"]);let f=Ae();if(!f)throw new Error("Para usar o <Searchable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return D(Ge,{control:f.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{onChange:g,value:S}})=>Ve(De,{display:"flex",flexDirection:"column",children:[t&&D(h,{label:t,required:d}),D(Le,b(i({size:"small",onChange:(C,a)=>g(a),value:S,options:n,noOptionsText:"Nenhuma op\xE7\xE3o encontrada",isOptionEqualToValue:(C,a)=>typeof C=="string"&&typeof a=="string"?C===a:typeof C=="object"&&typeof a=="object"?C.value===a.value:!1},u),{renderInput:C=>D(qe,i(i({},C),x))})),D(P,{name:e})]})})},Me=$e;import{Controller as ve,useFormContext as Ne}from"react-hook-form";import{Plus as ke}from"phosphor-react";import{Grid as Oe,Autocomplete as ze,TextField as _e,Typography as Be}from"@mui/material";import{toRem as E}from"@s_mart/utils";import j from"@emotion/styled";import{css as H}from"@emotion/react";var K=H`
|
|
2
2
|
display: flex;
|
|
3
3
|
align-items: center;
|
|
4
4
|
justify-content: center;
|
|
5
|
-
`,
|
|
5
|
+
`,Ue=e=>H`
|
|
6
6
|
.MuiAutocomplete-endAdornment {
|
|
7
7
|
position: relative;
|
|
8
8
|
right: 0;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
.creatable {
|
|
12
|
-
${
|
|
12
|
+
${K}
|
|
13
13
|
|
|
14
14
|
.divider {
|
|
15
15
|
width: 1px;
|
|
@@ -35,18 +35,18 @@ var X=Object.defineProperty,Y=Object.defineProperties;var Z=Object.getOwnPropert
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
`,
|
|
38
|
+
`,J=j.div`
|
|
39
39
|
display: flex;
|
|
40
40
|
|
|
41
41
|
div.endAdornments {
|
|
42
42
|
position: absolute;
|
|
43
43
|
right: 0;
|
|
44
44
|
|
|
45
|
-
${
|
|
45
|
+
${K}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
${({hideAddButton:e,theme:r})=>!e&&
|
|
49
|
-
`,
|
|
48
|
+
${({hideAddButton:e,theme:r})=>!e&&Ue(r)}
|
|
49
|
+
`,Q=j.div`
|
|
50
50
|
color: ${({theme:e})=>e.palette.text.primary};
|
|
51
51
|
|
|
52
52
|
padding: ${E(6)} ${E(16)};
|
|
@@ -57,4 +57,4 @@ var X=Object.defineProperty,Y=Object.defineProperties;var Z=Object.getOwnPropert
|
|
|
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 M}from"react/jsx-runtime";var We=f=>{var g=f,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:d,options:n,onCreateOption:x,textFieldProps:u,hideAddButton:F}=g,p=m(g,["name","rules","defaultValue","shouldUnregister","label","required","options","onCreateOption","textFieldProps","hideAddButton"]);let S=Ne();if(!S)throw new Error("Para usar o <Creatable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let C=a=>{x?x(a):console.error("onCreateOption n\xE3o foi definido")};return w(ve,{control:S.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:a,onChange:I}})=>{let c=(a==null?void 0:a.label)||(a==null?void 0:a.value)||a;return M(Oe,{display:"flex",flexDirection:"column",children:[t&&w(h,{label:t,required:d}),w(J,{hideAddButton:F,children:w(ze,b(i({size:"small",fullWidth:!0,onChange:(s,y)=>I(y),options:n,value:a,noOptionsText:w(Q,{onClick:()=>C(a),children:M(Be,{children:["Adicionar ",c&&`"${c}"`]})}),isOptionEqualToValue:(s,y)=>y?typeof s=="string"&&typeof y=="string"?s===y:typeof s=="object"&&typeof y=="object"?s.value===y.value:typeof s=="object"&&typeof y=="string":!1},p),{renderInput:s=>{let y=F?s.InputProps:b(i({},s.InputProps),{endAdornment:M("div",{className:"endAdornments",children:[s.InputProps.endAdornment,M("div",{className:"creatable",children:[w("div",{className:"divider"}),w("div",{className:"button",onClick:()=>C(a),children:w(ke,{size:18,weight:"bold"})})]})]})});return w(_e,i(b(i({},s),{onChange:I,InputProps:y}),u))}}))}),w(P,{name:e})]})}})},je=We;import{Controller as He,useFormContext as Ke}from"react-hook-form";import{Grid as Je,Checkbox as Qe,FormControlLabel as Xe}from"@mui/material";import{jsx as L,jsxs as er}from"react/jsx-runtime";var Ye=u=>{var F=u,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,labelPlacement:d,required:n}=F,x=m(F,["name","rules","defaultValue","shouldUnregister","label","labelPlacement","required"]);let p=Ke();if(!p)throw new Error("Para usar o <Checkbox /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return L(He,{control:p.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:f,onChange:g}})=>er(Je,{display:"flex",flexDirection:"column",children:[L(Xe,{control:L(Qe,i({value:f!=null?f:"",defaultValue:f,onChange:g},x)),label:L(h,{label:t,required:n,regular:!0}),labelPlacement:d||"end"}),L(P,{name:e})]})})},Ze=Ye;import{Controller as rr,useFormContext as or}from"react-hook-form";import{Grid as tr,Switch as lr,FormControlLabel as ir}from"@mui/material";import{jsx as q,jsxs as sr}from"react/jsx-runtime";var nr=x=>{var u=x,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,labelPlacement:d}=u,n=m(u,["name","rules","defaultValue","shouldUnregister","label","labelPlacement"]);let F=or();if(!F)throw new Error("Para usar o <Switch /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return q(rr,{control:F.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:p,onChange:f}})=>sr(tr,{display:"flex",flexDirection:"column",children:[q(ir,{control:q(lr,i({value:p!=null?p:"",defaultValue:p,onChange:f},n)),label:q(h,{label:t}),labelPlacement:d||"end"}),q(P,{name:e})]})})},ar=nr;import{Grid as dr,Radio as pr,FormControlLabel as mr}from"@mui/material";import{jsx as V}from"react/jsx-runtime";var ur=l=>{var t=l,{label:e,labelPlacement:r}=t,o=m(t,["label","labelPlacement"]);return V(dr,{display:"flex",flexDirection:"column",children:V(mr,{control:V(pr,i({},o)),label:V(h,{label:e}),labelPlacement:r||"end"})})},fr=ur;import{Controller as cr,useFormContext as xr}from"react-hook-form";import{Grid as yr,RadioGroup as hr}from"@mui/material";import{jsx as U,jsxs as gr}from"react/jsx-runtime";var br=F=>{var p=F,{name:e,rules:r,defaultValue:o,shouldUnregister:l,label:t,required:d,children:n,orientation:x="row"}=p,u=m(p,["name","rules","defaultValue","shouldUnregister","label","required","children","orientation"]);let f=xr();if(!f)throw new Error("Para usar o <RadioGroup /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return U(cr,{control:f.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:g,onChange:S}})=>gr(yr,{display:"flex",flexDirection:"column",children:[t&&U(h,{label:t,required:d}),U(hr,b(i({value:g||"",onChange:S,name:e},u),{style:{display:"flex",flexDirection:x},children:n})),U(P,{name:e})]})})},Fr=br;import{Controller as Cr,useFormContext as Pr}from"react-hook-form";import{Slider as Sr}from"@mui/material";import{jsx as X}from"react/jsx-runtime";var wr=d=>{var n=d,{name:e,rules:r,defaultValue:o,shouldUnregister:l}=n,t=m(n,["name","rules","defaultValue","shouldUnregister"]);let x=Pr();if(!x)throw new Error("Para usar o <Slider /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return X(Cr,{control:x.control,name:e,rules:r,defaultValue:o,shouldUnregister:l,render:({field:{value:u,onChange:F}})=>X(Sr,i({value:u||(t==null?void 0:t.min)||0,onChange:F,valueLabelDisplay:"auto"},t))})},Er=wr;export{Ze as Checkbox,je as Creatable,ie as Form,fr as RadioButton,Fr as RadioGroup,Me as Searchable,Re as Select,Er as Slider,ar as Switch,ge as TextField};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@s_mart/form",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.1",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"@s_mart/typed": "*",
|
|
24
24
|
"@s_mart/utils": "*",
|
|
25
25
|
"@s_mart/masks": "*",
|
|
26
|
-
"@s_mart/core": "*"
|
|
26
|
+
"@s_mart/core": "*",
|
|
27
|
+
"@s_mart/tokens": "*"
|
|
27
28
|
},
|
|
28
29
|
"peerDependencies": {
|
|
29
30
|
"react": ">=18.0.0",
|