@s_mart/form 7.1.2 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +81 -7
- package/dist/index.mjs +70 -19
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -267,12 +267,18 @@ type SearchableProps = Omit<AutocompleteProps$1<SearchableOption, true, true, tr
|
|
|
267
267
|
declare const Searchable: react.MemoExoticComponent<({ name, rules, defaultValue, shouldUnregister, label, required, options, textFieldProps, noOptionsText, footer, multiple, info, placeholder, onChange: onChangeProp, onInputChange, disableIconError, ...rest }: SearchableProps) => react_jsx_runtime.JSX.Element>;
|
|
268
268
|
|
|
269
269
|
type ControllerCreatable = Omit<ControllerProps, 'render' | 'control'>;
|
|
270
|
+
/**
|
|
271
|
+
* @deprecated usar CreatableV2
|
|
272
|
+
*/
|
|
270
273
|
type CreatableOption = {
|
|
271
274
|
key?: string | number;
|
|
272
275
|
label: string;
|
|
273
276
|
value?: string | number | readonly string[] | undefined;
|
|
274
277
|
afterLabel?: string | React.ReactNode;
|
|
275
278
|
} | string;
|
|
279
|
+
/**
|
|
280
|
+
* @deprecated usar CreatableV2
|
|
281
|
+
*/
|
|
276
282
|
type CreatableProps = Omit<AutocompleteProps$1<CreatableOption, true, true, true>, 'renderInput' | 'size' | 'onInputChange' | 'onChange'> & ControllerCreatable & {
|
|
277
283
|
/**
|
|
278
284
|
* Opções do autocomplete
|
|
@@ -365,7 +371,10 @@ type CreatableProps = Omit<AutocompleteProps$1<CreatableOption, true, true, true
|
|
|
365
371
|
placeholder?: string;
|
|
366
372
|
};
|
|
367
373
|
|
|
368
|
-
|
|
374
|
+
/**
|
|
375
|
+
* @deprecated usar CreatableV2
|
|
376
|
+
*/
|
|
377
|
+
declare const Creatable: react.MemoExoticComponent<({ name, rules, defaultValue, shouldUnregister, label, required, options, editable, footer, onEditOption, onCreateOption, textFieldProps, hideAddButton, multiple, info, onChange: onChangeProp, onInputChange, placeholder, disableIconError, ...rest }: CreatableProps) => react_jsx_runtime.JSX.Element>;
|
|
369
378
|
|
|
370
379
|
type ControllerCheckbox = Omit<ControllerProps, 'render' | 'control'>;
|
|
371
380
|
type CheckboxProps = CheckboxProps$1 & ControllerCheckbox & {
|
|
@@ -540,7 +549,7 @@ type DatePickerProps = Omit<UseControllerProps, 'control'> & Pick<TextFieldProps
|
|
|
540
549
|
disableIconError?: boolean;
|
|
541
550
|
};
|
|
542
551
|
|
|
543
|
-
declare const _default$
|
|
552
|
+
declare const _default$5: react.MemoExoticComponent<({ rules, name, defaultValue, shouldUnregister, datePickerProps, label, required, placeholder, disabled, disableIconError, ...rest }: DatePickerProps) => react_jsx_runtime.JSX.Element>;
|
|
544
553
|
|
|
545
554
|
type TimePickerProps = Omit<UseControllerProps, 'control'> & Pick<TextFieldProps$1, 'label' | 'error' | 'helperText' | 'size' | 'fullWidth' | 'variant' | 'autoFocus' | 'placeholder'> & {
|
|
546
555
|
timePickerProps?: Partial<TimePickerProps$1<any>>;
|
|
@@ -566,7 +575,7 @@ type TimePickerProps = Omit<UseControllerProps, 'control'> & Pick<TextFieldProps
|
|
|
566
575
|
disableIconError?: boolean;
|
|
567
576
|
};
|
|
568
577
|
|
|
569
|
-
declare const _default$
|
|
578
|
+
declare const _default$4: react.MemoExoticComponent<({ rules, defaultValue, shouldUnregister, name, required, label, timePickerProps, placeholder, disabled, disableIconError, ...rest }: TimePickerProps) => react_jsx_runtime.JSX.Element>;
|
|
570
579
|
|
|
571
580
|
type AutoCompleteOption = {
|
|
572
581
|
key?: string | number;
|
|
@@ -610,7 +619,7 @@ type AutocompleteProps<T = any> = Omit<UseControllerProps, 'control'> & Omit<Aut
|
|
|
610
619
|
placeholder?: string;
|
|
611
620
|
};
|
|
612
621
|
|
|
613
|
-
declare const _default$
|
|
622
|
+
declare const _default$3: react.MemoExoticComponent<({ name, defaultValue, rules, shouldUnregister, label, required, noOptionsText, placeholder, onInputChange, onChange, disableIconError, ...rest }: AutocompleteProps) => react_jsx_runtime.JSX.Element>;
|
|
614
623
|
|
|
615
624
|
type FieldLabelProps = {
|
|
616
625
|
label: React.ReactNode;
|
|
@@ -662,7 +671,7 @@ type SearchableV2Props<T extends FieldValues | string | number> = Omit<Autocompl
|
|
|
662
671
|
getOptionAfterLabel?: (option: T) => string | React.ReactNode;
|
|
663
672
|
};
|
|
664
673
|
|
|
665
|
-
declare const _default$
|
|
674
|
+
declare const _default$2: <T extends string | number | FieldValues>({ name, rules, defaultValue, shouldUnregister, label, required, options, textFieldProps, noOptionsText, footer, multiple, info, placeholder, onChange: onChangeProp, onInputChange, getOptionAfterLabel, getOptionLabel, getOptionKey, ...rest }: SearchableV2Props<T>) => react_jsx_runtime.JSX.Element;
|
|
666
675
|
|
|
667
676
|
type ControllerSelect = Omit<ControllerProps, 'render' | 'control'>;
|
|
668
677
|
type FooterPropsV2 = {
|
|
@@ -714,6 +723,71 @@ type SelectV2Props<T extends FieldValues | string | number> = Omit<SelectProps$1
|
|
|
714
723
|
getOptionAfterLabel?: (option: T) => string | React.ReactNode;
|
|
715
724
|
};
|
|
716
725
|
|
|
717
|
-
declare const _default: <T extends string | number | FieldValues>({ name, rules, defaultValue, shouldUnregister, label, required, options, placeholder, clearable, info, footer, onChange: onChangeProp, variant, getOptionKey, getOptionLabel, getOptionAfterLabel, ...rest }: SelectV2Props<T>) => react_jsx_runtime.JSX.Element;
|
|
726
|
+
declare const _default$1: <T extends string | number | FieldValues>({ name, rules, defaultValue, shouldUnregister, label, required, options, placeholder, clearable, info, footer, onChange: onChangeProp, variant, getOptionKey, getOptionLabel, getOptionAfterLabel, ...rest }: SelectV2Props<T>) => react_jsx_runtime.JSX.Element;
|
|
727
|
+
|
|
728
|
+
type CreatableV2Props<T extends FieldValues | string | number> = Omit<AutocompleteProps$1<T, true, true, true>, 'renderInput' | 'size' | 'onInputChange' | 'onChange' | 'getOptionLabel' | 'getOptionKey' | 'defaultValue' | 'value'> & Omit<ControllerProps, 'render' | 'control'> & {
|
|
729
|
+
options: T[];
|
|
730
|
+
textFieldProps?: TextFieldProps$1;
|
|
731
|
+
label?: React.ReactNode;
|
|
732
|
+
required?: boolean;
|
|
733
|
+
/**
|
|
734
|
+
* Define se mostra o botão para criar uma nova opção
|
|
735
|
+
* @default true
|
|
736
|
+
* @type {boolean}
|
|
737
|
+
* @memberof CreatableV2Props
|
|
738
|
+
*/
|
|
739
|
+
showCreatableButton?: boolean;
|
|
740
|
+
/**
|
|
741
|
+
* Define se mostra o botão para editar uma opção existente
|
|
742
|
+
* @default false
|
|
743
|
+
* @type {boolean}
|
|
744
|
+
* @memberof CreatableV2Props
|
|
745
|
+
*/
|
|
746
|
+
showEditableButton?: boolean;
|
|
747
|
+
/**
|
|
748
|
+
* Função que será executada quando o usuário clicar no botão de criar uma nova opção
|
|
749
|
+
* @default () => {}
|
|
750
|
+
* @type {(value: string) => void}
|
|
751
|
+
* @memberof CreatableV2Props
|
|
752
|
+
*/
|
|
753
|
+
onCreateOption?: (value: string) => void;
|
|
754
|
+
/**
|
|
755
|
+
* Função que será executada quando o usuário clicar no botão de editar uma opção
|
|
756
|
+
* @default () => {}
|
|
757
|
+
* @type {(value) => void}
|
|
758
|
+
* @memberof CreatableV2Props
|
|
759
|
+
*/
|
|
760
|
+
onEditOption?: (value: T | T[]) => void;
|
|
761
|
+
/**
|
|
762
|
+
* Componente que renderiza no footer do searchable (opcional)
|
|
763
|
+
* @example
|
|
764
|
+
* footer: (
|
|
765
|
+
* <Button onClick={handleClick}>Mostrar mais...</Button>
|
|
766
|
+
* )
|
|
767
|
+
*/
|
|
768
|
+
footer?: () => React.ReactNode;
|
|
769
|
+
/**
|
|
770
|
+
* É o conteúdo passado para a tooltip que renderizará ao lado da label do campo,
|
|
771
|
+
* montada à tela como um ícone de informação.
|
|
772
|
+
*/
|
|
773
|
+
info?: React.ReactNode;
|
|
774
|
+
onInputChange?: (value: string) => void;
|
|
775
|
+
onChange?: (value: T | T[]) => void;
|
|
776
|
+
placeholder?: string;
|
|
777
|
+
/**
|
|
778
|
+
* Define a key unica da option
|
|
779
|
+
*/
|
|
780
|
+
getOptionKey: (option: T) => string | number;
|
|
781
|
+
/**
|
|
782
|
+
* Define a label da option
|
|
783
|
+
*/
|
|
784
|
+
getOptionLabel: (option: T) => string;
|
|
785
|
+
/**
|
|
786
|
+
* Componente renderizado embaixo da option da listagem
|
|
787
|
+
*/
|
|
788
|
+
getOptionAfterLabel?: (option: T) => string | React.ReactNode;
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
declare const _default: <T extends string | number | FieldValues>({ name, rules, defaultValue, shouldUnregister, label, required, options, footer, showCreatableButton, showEditableButton, onEditOption, onCreateOption, getOptionKey, getOptionLabel, getOptionAfterLabel, textFieldProps, multiple, info, noOptionsText, onChange: onChangeProp, onInputChange, placeholder, ...rest }: CreatableV2Props<T>) => react_jsx_runtime.JSX.Element;
|
|
718
792
|
|
|
719
|
-
export { _default$
|
|
793
|
+
export { _default$3 as Autocomplete, type AutocompleteProps, Checkbox, type CheckboxProps, Creatable, type CreatableOption, type CreatableProps, _default as CreatableV2, type CreatableV2Props, _default$5 as DatePicker, type DatePickerProps, FieldLabel, type FieldLabelProps, type FooterProps, type FooterPropsV2, Form, FormProvider, type IFormProps, type IFormProviderProps, type IUseFormProps, RadioButton, RadioGroup, type RadioGroupProps, type RadioProps, Searchable, type SearchableOption, type SearchableProps, _default$2 as SearchableV2, type SearchableV2Props, Select, type SelectOption, type SelectProps, _default$1 as SelectV2, type SelectV2Props, Slider, type SliderProps, Switch, type SwitchProps, _default$6 as TextField, type TextFieldProps, _default$4 as TimePicker, type TimePickerProps, useForm };
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import{FormProvider as
|
|
1
|
+
import{FormProvider as to}from"react-hook-form";import{jsx as Ie}from"react/jsx-runtime";function io({children:e,style:t,onSubmit:i,...n}){return Ie(to,{...n,children:Ie("form",{onSubmit:l=>{l.preventDefault(),l.stopPropagation(),i(l)},style:t,children:e})})}var Fe=io;import{useEffect as lo}from"react";import{useForm as no}from"react-hook-form";import{zodResolver as ao}from"@hookform/resolvers/zod";var so=({disableDefaultValuesUpdate:e,onSubmit:t,...i})=>{let n=no({...i,resolver:i.schema&&ao(i.schema)});return lo(()=>{e||n.reset(i.defaultValues)},[i.defaultValues,n.reset]),{...n,onSubmit:n.handleSubmit(l=>t(l,n))}},be=so;import{jsx as uo}from"react/jsx-runtime";function po({children:e,style:t,...i}){let n=be(i);return uo(Fe,{...n,style:t,children:typeof e=="function"?e(n):e})}var mo=po;import{memo as Po,useState as ho}from"react";import{Controller as vo,useFormContext as Co}from"react-hook-form";import{Tooltip as To,Grid as ge,InputAdornment as Io,TextField as So}from"@mui/material";import{lineEye as ko,lineEyeSlash as wo,lineInfoCircle as Vo}from"@s_mart/solid-icons";import*as we from"@s_mart/masks";import{Typography as Se}from"@mui/material";import{toRem as fo}from"@s_mart/utils";import{jsx as ke,jsxs as yo}from"react/jsx-runtime";var co=({label:e,required:t,regular:i})=>yo("span",{style:{display:"flex",alignItems:"center",gap:fo(2)},children:[ke(Se,{variant:"caption",fontWeight:i?400:700,style:{display:"flex",alignItems:"center"},children:e}),t&&ke(Se,{variant:"caption",fontWeight:900,color:"error",children:"*"})]}),h=co;import{useFormContext as xo}from"react-hook-form";import{Indicator as Fo}from"@s_mart/core";var R=(e,t)=>t.replace(/[[\]]/g,"").split(".").reduce((n,l)=>n?.[l],e);import{jsx as go}from"react/jsx-runtime";var bo=({name:e,disableIcon:t})=>{let i=xo(),n=R(i?.formState?.errors,e);return n?go(Fo,{severity:"error",icon:t?!1:void 0,children:n?.message}):null},S=bo;import{LIcon as Ve}from"@s_mart/core";import{jsx as q,jsxs as Re}from"react/jsx-runtime";var Ro=({name:e,rules:t,defaultValue:i,shouldUnregister:n,label:l,required:P,mask:y,variant:x="outlined",info:v,parse:u,inputMode:f,format:a,onInputChange:g,disableIconError:p,...c})=>{let F=Co();if(!F)throw new Error("Para usar o <TextField /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let[s,b]=ho(!1),d=o=>{let r=o;return a&&(r=a(o)),y?we?.[y]?.format(r):r},m=o=>{let r=o;return u&&(r=u(o)),y?we?.[y]?.parse(r):r},L=o=>{if(!o||y!=="porcentagem"&&y!=="porcentagem0")return;o?.stopPropagation();let r=(o?.target).value;if(r){let C=String(r);if(C.length>0){let k=C.indexOf("%");k>-1&&(o.currentTarget.selectionEnd=k)}}},B=R(F.formState.errors,e);return q(vo,{control:F.control,name:e,rules:t,defaultValue:i,shouldUnregister:n,render:({field:{value:o,onChange:r,ref:C}})=>Re(ge,{display:"flex",flexDirection:"column",children:[Re("div",{style:{display:"flex"},children:[l&&q(ge,{item:!0,children:q(h,{label:l,required:P})}),v&&q(ge,{item:!0,children:q(To,{title:v,placement:"top",children:q("div",{style:{width:"fit-content"},children:q(Ve,{icon:Vo,color:"#757575"})})})})]}),q(So,{variant:x,defaultValue:i,value:d(o||(o!=0?"":o)),onChange:k=>{let H=m(k?.target?.value);r(H),g?.(H,F.getValues())},error:!!B,...c,type:c.type==="password"?s?"text":"password":c.type,autoComplete:c.autoComplete||"off",inputProps:{inputMode:f,...c.inputProps},InputProps:{onKeyDown:L,inputRef:C,endAdornment:c.type==="password"&&q(Io,{position:"start",onClick:()=>b(!s),style:{cursor:"pointer"},children:q(Ve,{icon:s?ko:wo,size:"24px",removeMargin:!0})}),...c.InputProps}},e),q(S,{name:e,disableIcon:p})]})})},Eo=Po(Ro);import{memo as Lo,useState as Bo}from"react";import{Controller as Go,useFormContext as Ao}from"react-hook-form";import{IconButton as $o,LIcon as Ee}from"@s_mart/core";import{lineTimes as Do}from"@s_mart/regular-icons";import{lineInfoCircle as Mo}from"@s_mart/solid-icons";import{colorPalette as _o}from"@s_mart/tokens";import{Divider as qo,Tooltip as zo,Grid as J,Select as Oo,MenuItem as No,useTheme as Uo}from"@mui/material";import{Fragment as Ho,jsx as D,jsxs as le}from"react/jsx-runtime";var Le=Lo(({name:e,rules:t,defaultValue:i,shouldUnregister:n,label:l,required:P,options:y,placeholder:x,clearable:v,disableOnChangeForm:u=!1,multiple:f,info:a,footer:g,onChange:p,disableIconError:c,variant:F="outlined",...s})=>{let b=Ao(),{palette:d}=Uo(),[m,L]=Bo(!1);if(!b)throw new Error("Para usar o <Select /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let B=R(b.formState.errors,e);return D(Go,{control:b.control,name:e,rules:t,defaultValue:i,shouldUnregister:n,render:({field:{value:o,onChange:r,ref:C}})=>le(J,{display:"flex",flexDirection:"column",children:[le("div",{style:{display:"flex"},children:[l&&D(J,{item:!0,children:D(h,{label:l,required:P})}),a&&D(J,{item:!0,children:D(zo,{title:a,placement:"top",children:D("div",{style:{width:"fit-content"},children:D(Ee,{icon:Mo,color:"#757575"})})})})]}),le(Oo,{open:m,onOpen:()=>L(!0),onClose:()=>L(!1),displayEmpty:!!x,variant:F,autoComplete:"off",value:o?o||"":f?[]:"",renderValue:k=>{if(k.label)return k.label;if(x)return D("p",{style:{color:d.grey[400]},children:x})},multiple:f,onChange:k=>{!u&&r(k.target.value),p&&p(k.target.value,b.getValues())},error:!!B,size:s.size||"medium",inputRef:C,...s,endAdornment:le(Ho,{children:[s.endAdornment,!!(v&&o)&&D($o,{variant:"text",color:"neutral",size:"small",sx:{borderRadius:"50%",position:"absolute",right:"2rem"},style:{padding:0},"aria-label":"Clear",title:"Clear",onClick:()=>{!u&&r(null),p&&p(null,b.getValues())},children:D(Ee,{icon:Do,color:_o.neutral[100],size:"25px",removeMargin:!0})})]}),children:[y?.map((k,H)=>D(No,{value:k,children:le(J,{container:!0,direction:"column",children:[D(J,{item:!0,children:k.label}),k.afterLabel&&D(J,{item:!0,children:k.afterLabel})]})},H)),g&&[D(J,{px:2,py:1,children:D(qo,{})},"footer-divider"),D("div",{children:g({closeSelect:()=>L(!1)})},"footer-content")]]},e),D(S,{name:e,disableIcon:c})]})})});Le.displayName="Select";var jo=Le;import{forwardRef as Wo,memo as Yo}from"react";import{Controller as Jo,useFormContext as Ko}from"react-hook-form";import{Tooltip as Xo,Divider as Be,Grid as W,Autocomplete as Qo,TextField as Zo}from"@mui/material";import{LIcon as er}from"@s_mart/core";import{lineInfoCircle as or}from"@s_mart/solid-icons";import{colorPalette as rr}from"@s_mart/tokens";import{Fragment as de,jsx as $,jsxs as K}from"react/jsx-runtime";import{createElement as Ge}from"react";var Ae=Yo(({name:e,rules:t,defaultValue:i,shouldUnregister:n,label:l,required:P,options:y,textFieldProps:x,noOptionsText:v,footer:u,multiple:f,info:a,placeholder:g,onChange:p,onInputChange:c,disableIconError:F,...s})=>{let b=Ko();if(!b)throw new Error("Para usar o <Searchable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let d=R(b.formState.errors,e);return $(Jo,{control:b.control,name:e,rules:t,defaultValue:i,shouldUnregister:n,render:({field:{onChange:m,value:L,ref:B}})=>K(W,{display:"flex",flexDirection:"column",children:[K("div",{style:{display:"flex"},children:[l&&$(W,{item:!0,children:$(h,{label:l,required:P})}),a&&$(W,{item:!0,children:$(Xo,{title:a,placement:"top",children:$("div",{style:{width:"fit-content"},children:$(er,{icon:or,color:"#757575"})})})})]}),$(Qo,{onChange:(o,r)=>{m(r),p?.(r,b.getValues())},onInputChange:(o,r,C)=>{C==="input"&&setTimeout(()=>{c?.(r,b.getValues())},0)},slotProps:{...s.slotProps||{},paper:{...(s.slotProps||{}).paper||{},sx:{border:`1px solid ${rr.neutral[30]}`,boxShadow:"0px 2px 4px rgba(0, 0, 0, 0.15)",...(s.slotProps||{}).paper?.sx||{}}}},value:L||(f?[]:null),options:y,multiple:f,readOnly:s.disabled,noOptionsText:K(de,{children:[v||"Nenhum resultado encontrado",u?K(de,{children:[$(W,{py:1,children:$(Be,{})}),u]}):null]}),isOptionEqualToValue:(o,r)=>typeof o=="string"&&typeof r=="string"?o===r:typeof o=="object"&&typeof r=="object"?typeof o.value=="object"&&typeof r.value=="object"&&o.key!==void 0&&r.key!==void 0?o.key===r.key:o.value===r.value:!1,renderOption:(o,r)=>typeof r=="object"?Ge("li",{...o,key:r.key||r.value},K(W,{container:!0,direction:"column",children:[$(W,{item:!0,children:r.label}),r.afterLabel&&$(W,{item:!0,children:r.afterLabel})]})):Ge("li",{...o,key:r},r),ListboxComponent:Wo(function(r,C){return K(de,{children:[$("ul",{...r,ref:C}),!!u&&$("div",{...r,children:K(de,{children:[$(W,{px:2,py:1,children:$(Be,{})}),u]})},"searchable-footer")]})}),...s,renderInput:o=>$(Zo,{error:!!d,placeholder:g,...o,...x,inputRef:B})},e),$(S,{name:e,disableIcon:F})]})})});Ae.displayName="Searchable";var tr=Ae;import{forwardRef as nr,memo as ar}from"react";import{Controller as sr,useFormContext as dr}from"react-hook-form";import{isObject as pr,isEmpty as mr}from"lodash-es";import{Grid as X,Autocomplete as ur,TextField as fr,Tooltip as cr,Divider as yr}from"@mui/material";import{LIcon as me,Button as xr}from"@s_mart/core";import{colorPalette as Fr}from"@s_mart/tokens";import{linePlus as _e,linePen as br,lineInfoCircle as gr}from"@s_mart/solid-icons";import{toRem as qe}from"@s_mart/utils";import{toRem as pe}from"@s_mart/utils";import ir from"@emotion/styled";import{css as $e}from"@emotion/react";var De=$e`
|
|
2
2
|
display: flex;
|
|
3
3
|
align-items: center;
|
|
4
4
|
justify-content: center;
|
|
5
|
-
`,
|
|
5
|
+
`,lr=e=>$e`
|
|
6
6
|
.creatable,
|
|
7
7
|
.editable {
|
|
8
|
-
${
|
|
8
|
+
${De}
|
|
9
9
|
|
|
10
10
|
.divider {
|
|
11
11
|
width: 1px;
|
|
12
|
-
height: ${
|
|
12
|
+
height: ${pe(20)};
|
|
13
13
|
background-color: ${e.palette.grey[400]};
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -20,9 +20,9 @@ import{FormProvider as Ue}from"react-hook-form";import{jsx as Fe}from"react/jsx-
|
|
|
20
20
|
color: ${e.palette.grey[600]};
|
|
21
21
|
border-radius: 50%;
|
|
22
22
|
|
|
23
|
-
margin: 0 ${
|
|
24
|
-
width: ${
|
|
25
|
-
height: ${
|
|
23
|
+
margin: 0 ${pe(6)};
|
|
24
|
+
width: ${pe(28)};
|
|
25
|
+
height: ${pe(28)};
|
|
26
26
|
|
|
27
27
|
&:hover {
|
|
28
28
|
cursor: pointer;
|
|
@@ -31,14 +31,14 @@ import{FormProvider as Ue}from"react-hook-form";import{jsx as Fe}from"react/jsx-
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
`,
|
|
34
|
+
`,Me=ir.div`
|
|
35
35
|
display: flex;
|
|
36
36
|
|
|
37
37
|
div.endAdornments {
|
|
38
38
|
position: absolute;
|
|
39
39
|
right: 0;
|
|
40
40
|
|
|
41
|
-
${
|
|
41
|
+
${De}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
.MuiAutocomplete-endAdornment {
|
|
@@ -50,23 +50,74 @@ import{FormProvider as Ue}from"react-hook-form";import{jsx as Fe}from"react/jsx-
|
|
|
50
50
|
transform: translate(0, 0);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
${({hideAddButton:e,theme:t})=>!e&&
|
|
54
|
-
`;import{Fragment as
|
|
53
|
+
${({hideAddButton:e,theme:t})=>!e&&lr(t)}
|
|
54
|
+
`;import{Fragment as Pe,jsx as w,jsxs as N}from"react/jsx-runtime";import{createElement as ze}from"react";var Oe=ar(({name:e,rules:t,defaultValue:i,shouldUnregister:n,label:l,required:P,options:y,editable:x,footer:v,onEditOption:u,onCreateOption:f,textFieldProps:a,hideAddButton:g,multiple:p,info:c,onChange:F,onInputChange:s,placeholder:b,disableIconError:d,...m})=>{let L=dr();if(!L)throw new Error("Para usar o <Creatable /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let B=R(L.formState.errors,e),o=g||m.disabled,r=V=>{let M=0;return a?.InputProps||(M+=2.5),o||(M+=2.56,C(V)&&(M+=2.56)),!m.disableClearable&&!m.disabled&&(M+=1.3),M+"rem"},C=V=>m.disabled?!1:x&&pr(V)&&!mr(V);console.warn=()=>{};let k=V=>{f?f(V):console.error("onCreateOption n\xE3o foi definido")},H=V=>{u?u(V):console.error("onEditOption n\xE3o foi definido")};return w(sr,{control:L.control,name:e,rules:t,defaultValue:i,shouldUnregister:n,render:({field:{value:V,onChange:M,ref:xe}})=>{let ie=V?.label||V?.value||V;return N(X,{display:"flex",flexDirection:"column",children:[N("div",{style:{display:"flex"},children:[l&&w(X,{item:!0,children:w(h,{label:l,required:P})}),c&&w(X,{item:!0,children:w(cr,{title:c,placement:"top",children:w("div",{style:{width:"fit-content"},children:w(me,{icon:gr,color:"#757575"})})})})]}),w(Me,{hideAddButton:o,children:w(ur,{fullWidth:!0,onChange:(E,T)=>{M(T),F?.(T,L.getValues())},onInputChange:(E,T,I)=>{I==="input"&&setTimeout(()=>{s?.(T,L.getValues())},0)},slotProps:{...m.slotProps||{},paper:{...(m.slotProps||{}).paper||{},sx:{border:`1px solid ${Fr.neutral[30]}`,boxShadow:"0px 2px 4px rgba(0, 0, 0, 0.15)",...(m.slotProps||{}).paper?.sx||{}}}},options:y,value:V||(p?[]:null),multiple:p,readOnly:m.disabled,noOptionsText:o?void 0:N(xr,{sx:{justifyContent:"flex-start",padding:`${qe(6)} ${qe(-16)}`,margin:0},fullWidth:!0,onClick:()=>k(V),variant:"text",startIcon:w(me,{icon:_e}),children:["Adicionar ",ie&&`"${ie}"`]}),isOptionEqualToValue:(E,T)=>T?typeof E=="string"&&typeof T=="string"?E===T:typeof E=="object"&&typeof T=="object"?typeof E.value=="object"&&typeof T.value=="object"&&E.key!==void 0&&T.key!==void 0?E.key===T.key:E.value===T.value:typeof E=="object"&&typeof T=="string":!1,renderOption:(E,T)=>typeof T=="object"?ze("li",{...E,key:T.key||T.value},N(X,{container:!0,direction:"column",children:[w(X,{item:!0,children:T.label}),T.afterLabel&&w(X,{item:!0,children:T.afterLabel})]})):ze("li",{...E,key:T},T),ListboxComponent:nr(function(T,I){return N(Pe,{children:[w("ul",{...T,ref:I}),!!v&&w("div",{...T,children:N(Pe,{children:[w(X,{px:2,py:1,children:w(yr,{})}),v]})},"creatable-footer")]})}),...m,sx:{"& div.MuiInputBase-root":{paddingRight:`${r(V)} !important`},...m.sx},renderInput:E=>w(fr,{placeholder:b,...E,error:!!B,InputProps:{...E.InputProps,inputRef:xe,endAdornment:N("div",{className:"endAdornments",children:[E.InputProps.endAdornment,!o&&N(Pe,{children:[C(V)?N("div",{className:"editable",children:[w("div",{className:"divider"}),w("div",{className:"button",onClick:()=>H(V),children:w(me,{icon:br,size:"24px",removeMargin:!0})})]}):null,N("div",{className:"creatable",children:[w("div",{className:"divider"}),w("div",{className:"button",onClick:()=>k(V),children:w(me,{icon:_e,size:"24px",removeMargin:!0})})]})]})]})},...a})},e)}),w(S,{name:e,disableIcon:d})]})}})});Oe.displayName="Creatable";var Pr=Oe;import{Controller as hr,useFormContext as vr}from"react-hook-form";import{Grid as Cr,Checkbox as Tr,FormControlLabel as Ir}from"@mui/material";import{jsx as ne,jsxs as wr}from"react/jsx-runtime";var Sr=({name:e,rules:t,defaultValue:i,shouldUnregister:n,label:l,labelPlacement:P,required:y,disableIconError:x,onChange:v,...u})=>{let f=vr();if(!f)throw new Error("Para usar o <Checkbox /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return ne(hr,{control:f.control,name:e,rules:t,defaultValue:i,shouldUnregister:n,render:({field:{value:a,onChange:g}})=>wr(Cr,{display:"flex",flexDirection:"column",children:[ne(Ir,{control:ne(Tr,{checked:!!a,value:a??"",defaultValue:a,onChange:(p,c)=>{g(p,c),v?.(p,c)},...u},e),label:ne(h,{label:l,required:y,regular:!0}),labelPlacement:P||"end"}),ne(S,{name:e,disableIcon:x})]})})},kr=Sr;import{Controller as Vr,useFormContext as Rr}from"react-hook-form";import{Grid as Er,Switch as Lr,FormControlLabel as Br}from"@mui/material";import{jsx as ae,jsxs as $r}from"react/jsx-runtime";var Gr=({name:e,rules:t,defaultValue:i,shouldUnregister:n,label:l,labelPlacement:P,disableIconError:y,onChange:x,...v})=>{let u=Rr();if(!u)throw new Error("Para usar o <Switch /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return ae(Vr,{control:u.control,name:e,rules:t,defaultValue:i,shouldUnregister:n,render:({field:{value:f,onChange:a}})=>$r(Er,{display:"flex",flexDirection:"column",children:[ae(Br,{control:ae(Lr,{value:f??"",checked:f??!1,defaultValue:f,onChange:(g,p)=>{a(g,p),x?.(g,p)},...v},e),label:ae(h,{label:l}),labelPlacement:P||"end"}),ae(S,{name:e,disableIcon:y})]})})},Ar=Gr;import{Grid as Dr,Radio as Mr,FormControlLabel as _r}from"@mui/material";import{jsx as ue}from"react/jsx-runtime";var qr=({label:e,labelPlacement:t,...i})=>ue(Dr,{display:"flex",flexDirection:"column",children:ue(_r,{control:ue(Mr,{...i}),label:ue(h,{label:e}),labelPlacement:t||"end"})}),zr=qr;import{Controller as Or,useFormContext as Nr}from"react-hook-form";import{Grid as Ur,RadioGroup as jr}from"@mui/material";import{jsx as fe,jsxs as Yr}from"react/jsx-runtime";var Hr=({name:e,rules:t,defaultValue:i,shouldUnregister:n,label:l,required:P,children:y,orientation:x="row",disableIconError:v,...u})=>{let f=Nr();if(!f)throw new Error("Para usar o <RadioGroup /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return fe(Or,{control:f.control,name:e,rules:t,defaultValue:i,shouldUnregister:n,render:({field:{value:a,onChange:g}})=>Yr(Ur,{display:"flex",flexDirection:"column",children:[l&&fe(h,{label:l,required:P}),fe(jr,{value:a||"",name:e,...u,onChange:p=>{u?.onChange?.(p,p.target?.value),g(p)},style:{display:"flex",flexDirection:x},children:y},e),fe(S,{name:e,disableIcon:v})]})})},Wr=Hr;import{Controller as Jr,useFormContext as Kr}from"react-hook-form";import{Slider as Xr}from"@mui/material";import{jsx as Ne}from"react/jsx-runtime";var Qr=({name:e,rules:t,defaultValue:i,shouldUnregister:n,...l})=>{let P=Kr();if(!P)throw new Error("Para usar o <Slider /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");return Ne(Jr,{control:P.control,name:e,rules:t,defaultValue:i,shouldUnregister:n,render:({field:{value:y,onChange:x}})=>Ne(Xr,{value:y||l?.min||0,onChange:x,valueLabelDisplay:"auto",...l},e)})},Zr=Qr;import{memo as it}from"react";import{Controller as lt,useFormContext as nt}from"react-hook-form";import{composeValidators as at,date as je}from"@s_mart/rules";import{Grid as st,TextField as dt}from"@mui/material";import{DatePicker as pt}from"@mui/x-date-pickers/DatePicker";import{AdapterDayjs as mt}from"@mui/x-date-pickers/AdapterDayjs";import{LocalizationProvider as ut}from"@mui/x-date-pickers/LocalizationProvider";import{ptBR as ft}from"@mui/x-date-pickers/locales/ptBR";import ct from"dayjs/locale/pt-br";import et from"@emotion/styled";import{IconButton as ot}from"@mui/material";import{toRem as U}from"@s_mart/utils";var rt=e=>{switch(e){case"small":return U(16);default:case"medium":return U(20);case"large":return U(24)}},tt=e=>{switch(e){case"small":return`${U(2)} ${U(8)}`;default:case"medium":return`${U(6)} ${U(8)}`;case"large":return`${U(10)}`}},Ue=et(ot)`
|
|
55
55
|
margin: 0px;
|
|
56
56
|
|
|
57
|
-
padding: ${({size:e})=>
|
|
58
|
-
border-radius: 0 ${
|
|
57
|
+
padding: ${({size:e})=>tt(e)};
|
|
58
|
+
border-radius: 0 ${U(4)} ${U(4)} 0;
|
|
59
59
|
|
|
60
60
|
svg {
|
|
61
|
-
width: ${({size:e})=>
|
|
61
|
+
width: ${({size:e})=>rt(e)} !important;
|
|
62
62
|
}
|
|
63
|
-
`;import{jsx as
|
|
63
|
+
`;import{jsx as se,jsxs as bt}from"react/jsx-runtime";import{createElement as Ft}from"react";var yt=({rules:e,name:t,defaultValue:i,shouldUnregister:n,datePickerProps:l,label:P,required:y,placeholder:x,disabled:v,disableIconError:u,...f})=>{let a=nt();if(!a)throw new Error("Para usar o <DataPicker /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let g=R(a.formState.errors,t),p=l?.format||"DD/MM/YYYY",c=e?at([je(p),e]):je(p);return se(ut,{dateAdapter:mt,adapterLocale:ct,localeText:ft.components.MuiLocalizationProvider.defaultProps.localeText,children:se(lt,{control:a.control,name:t,rules:c,defaultValue:i,shouldUnregister:n,render:({field:{value:F,onChange:s,ref:b}})=>bt(st,{display:"flex",flexDirection:"column",children:[P&&se(h,{label:P,required:y}),Ft(pt,{...l,key:t,value:F??null,format:p,onChange:(d,m)=>{s(d,m),l?.onChange?.(d,m)},disabled:v,slots:{textField:dt,openPickerButton:d=>se(Ue,{...d,size:f.size})},slotProps:{textField:d=>({variant:"outlined",...d,error:!!g,...f,inputProps:{...d.inputProps,placeholder:x||d.inputProps?.placeholder},InputProps:{...d.InputProps,inputRef(m){b(m),typeof d.inputRef=="function"&&d.inputRef(m)}}})}}),se(S,{name:t,disableIcon:u})]})})})},xt=it(yt);import{memo as Ct}from"react";import{Controller as Tt,useFormContext as It}from"react-hook-form";import{composeValidators as St,time as We}from"@s_mart/rules";import{Grid as kt,TextField as wt}from"@mui/material";import{TimePicker as Vt}from"@mui/x-date-pickers/TimePicker";import{AdapterDayjs as Rt}from"@mui/x-date-pickers/AdapterDayjs";import{LocalizationProvider as Et}from"@mui/x-date-pickers/LocalizationProvider";import{ptBR as Lt}from"@mui/x-date-pickers/locales/ptBR";import Bt from"dayjs/locale/pt-br";import gt from"@emotion/styled";import{IconButton as Pt}from"@mui/material";import{toRem as j}from"@s_mart/utils";var ht=e=>{switch(e){case"small":return j(16);default:case"medium":return j(20);case"large":return j(24)}},vt=e=>{switch(e){case"small":return`${j(2)} ${j(8)}`;default:case"medium":return`${j(6)} ${j(8)}`;case"large":return`${j(10)}`}},He=gt(Pt)`
|
|
64
64
|
margin: 0px;
|
|
65
65
|
|
|
66
|
-
padding: ${({size:e})=>
|
|
67
|
-
border-radius: 0 ${
|
|
66
|
+
padding: ${({size:e})=>vt(e)};
|
|
67
|
+
border-radius: 0 ${j(4)} ${j(4)} 0;
|
|
68
68
|
|
|
69
69
|
svg {
|
|
70
|
-
width: ${({size:e})=>
|
|
70
|
+
width: ${({size:e})=>ht(e)} !important;
|
|
71
71
|
}
|
|
72
|
-
`;import{jsx as
|
|
72
|
+
`;import{jsx as oe,jsxs as $t}from"react/jsx-runtime";var Gt=({rules:e,defaultValue:t,shouldUnregister:i,name:n,required:l,label:P,timePickerProps:y,placeholder:x,disabled:v,disableIconError:u,...f})=>{let a=It();if(!a)throw new Error("Para usar o <TimePicker /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let g=R(a.formState.errors,n),p=y?.format||"HH:mm",c=e?St([We(p),e]):We(p);return oe(Et,{dateAdapter:Rt,adapterLocale:Bt,localeText:Lt.components.MuiLocalizationProvider.defaultProps.localeText,children:oe(Tt,{control:a.control,name:n,rules:c,defaultValue:t,shouldUnregister:i,render:({field:{value:F,onChange:s,ref:b}})=>$t(kt,{display:"flex",flexDirection:"column",children:[P&&oe(h,{label:P,required:l}),oe(Vt,{ampm:!1,format:p,value:F??null,disabled:v,...y,onChange:(d,m)=>{s(d,m),y?.onChange?.(d,m)},slots:{textField:wt,openPickerButton:d=>oe(He,{...d,size:f.size})},slotProps:{textField:d=>({variant:"outlined",...d,error:!!g,...f,inputProps:{...d.inputProps,placeholder:x||d.inputProps?.placeholder},InputProps:{...d.InputProps,inputRef(m){b(m),typeof d.inputRef=="function"&&d.inputRef(m)}}})}},n),oe(S,{name:n,disableIcon:u})]})})})},At=Ct(Gt);import{memo as Dt}from"react";import{Controller as Mt,useFormContext as _t}from"react-hook-form";import{Grid as ce,Autocomplete as qt,TextField as zt}from"@mui/material";import{colorPalette as Ot}from"@s_mart/tokens";import{jsx as Q,jsxs as Ye}from"react/jsx-runtime";import{createElement as jt}from"react";var Nt=({name:e,defaultValue:t,rules:i,shouldUnregister:n,label:l,required:P,noOptionsText:y,placeholder:x,onInputChange:v,onChange:u,disableIconError:f,...a})=>{let g=_t();if(!g)throw new Error("Para usar o <Autocomplete /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let p=R(g.formState.errors,e);return console.warn=()=>{},Q(Mt,{name:e,control:g.control,defaultValue:t,rules:i,shouldUnregister:n,render:({field:c})=>Ye(ce,{display:"flex",flexDirection:"column",children:[l&&Q(h,{label:l,required:P}),Q(qt,{onChange:(F,s)=>{c.onChange(s),u?.(s,g.getValues())},onInputChange:(F,s,b)=>{b==="input"&&(c.onChange(s),setTimeout(()=>{v?.(s,g.getValues())},0))},slotProps:{...a.slotProps||{},paper:{...(a.slotProps||{}).paper||{},sx:{border:`1px solid ${Ot.neutral[30]}`,boxShadow:"0px 2px 4px rgba(0, 0, 0, 0.15)",...(a.slotProps||{}).paper?.sx||{}}}},isOptionEqualToValue:(F,s)=>F.value===s.value,renderOption:(F,s)=>jt("li",{...F,key:s.key||s.value,onClick:b=>{F.onClick?.(b),c.onChange(s)}},Ye(ce,{container:!0,direction:"column",children:[Q(ce,{item:!0,children:s.label}),s.afterLabel&&Q(ce,{item:!0,children:s.afterLabel})]})),value:c.value||null,readOnly:a.disabled,noOptionsText:y||"Nenhuma op\xE7\xE3o encontrada",...a,renderInput:F=>Q(zt,{placeholder:x,...F,...a.textFieldProps,error:!!p,InputProps:{...F.InputProps,...a.textFieldProps?.InputProps,inputRef:c.ref,inputProps:{...F.inputProps,...a.textFieldProps?.InputProps?.inputProps}}})},e),Q(S,{name:e,disableIcon:f})]})})},Ut=Dt(Nt);import{useController as Xt,useFormContext as Qt}from"react-hook-form";import{Tooltip as Ht}from"@mui/material";import{LIcon as Wt}from"@s_mart/core";import{lineInfoCircle as Yt}from"@s_mart/solid-icons";import{jsx as he}from"react/jsx-runtime";var Jt=({title:e})=>he(Ht,{title:e,placement:"top",children:he("div",{style:{width:"fit-content"},children:he(Wt,{icon:Yt,color:"#757575"})})}),Z=Jt;import{Autocomplete as Zt,Divider as Je,TextField as ei}from"@mui/material";import{isEqual as oi}from"lodash-es";import{forwardRef as ri}from"react";import{colorPalette as ti}from"@s_mart/tokens";import{memo as Kt}from"react";var re=Kt;import{Fragment as ve,jsx as _,jsxs as ee}from"react/jsx-runtime";import{createElement as ni}from"react";var ii=({name:e,rules:t,defaultValue:i,shouldUnregister:n,label:l,required:P,options:y,textFieldProps:x,noOptionsText:v,footer:u,multiple:f,info:a,placeholder:g,onChange:p,onInputChange:c,getOptionAfterLabel:F,getOptionLabel:s,getOptionKey:b,...d})=>{let m=Qt();if(!m)throw new Error("Para usar o <SearchableV2 /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let L=R(m.formState.errors,e),{field:B}=Xt({name:e,control:m.control,rules:t,defaultValue:i,shouldUnregister:n});return ee("div",{style:{display:"flex",flexDirection:"column"},children:[ee("div",{style:{display:"flex"},children:[l&&_(h,{label:l,required:P}),a&&_(Z,{title:a})]}),_(Zt,{onChange:(o,r)=>{B.onChange(r),p?.(r)},onInputChange:(o,r,C)=>{C==="input"&&c?.(r)},value:B.value?B.value:f?[]:null,options:y,multiple:f,readOnly:d.disabled,slotProps:{...d.slotProps,paper:{...d.slotProps?.paper,sx:{border:`1px solid ${ti.neutral[30]}`,boxShadow:"0px 2px 4px rgba(0, 0, 0, 0.15)",...d.slotProps?.paper?.sx}}},noOptionsText:ee(ve,{children:[v||"Nenhuma op\xE7\xE3o encontrada",typeof u<"u"?ee(ve,{children:[_("div",{style:{paddingTop:"0.5rem",paddingBottom:"0.5rem"},children:_(Je,{})}),u()]}):null]}),isOptionEqualToValue:(o,r)=>oi(o,r),getOptionLabel:o=>s(o),getOptionKey:o=>b(o),renderOption:typeof F=="function"?(o,r)=>{let C=F(r),k=b(r);return ni("li",{...o,key:k},ee("div",{style:{display:"flex",flexDirection:"column"},children:[_("span",{children:s(r)}),typeof C=="string"?_("span",{children:C}):C]}))}:void 0,ListboxComponent:ri(function(r,C){return ee(ve,{children:[_("ul",{...r,ref:C}),typeof u<"u"?ee("div",{...r,children:[_("div",{style:{paddingTop:"0.5rem",paddingBottom:"0.5rem"},children:_(Je,{})}),u()]},"searchable-footer"):null]})}),...d,renderInput:o=>_(ei,{error:!!L,placeholder:g,...o,...x,inputRef:B.ref})},e),_(S,{name:e})]})},li=re(ii);import{useState as di}from"react";import{useController as pi,useFormContext as mi}from"react-hook-form";import{IconButton as ui,LIcon as fi}from"@s_mart/core";import{lineTimes as ci}from"@s_mart/regular-icons";import{colorPalette as yi}from"@s_mart/tokens";import{Select as xi,MenuItem as Fi,Divider as bi}from"@mui/material";import{colorPalette as ai}from"@s_mart/tokens";import{jsx as si}from"react/jsx-runtime";var Ke=({value:e,placeholder:t,getOptionLabel:i})=>e===null||e?.length===0?si("p",{style:{color:ai.neutral[100]},children:t}):i(e);import{Fragment as hi,jsx as z,jsxs as te}from"react/jsx-runtime";var gi=({name:e,rules:t,defaultValue:i,shouldUnregister:n,label:l,required:P,options:y,placeholder:x,clearable:v,info:u,footer:f,onChange:a,variant:g="outlined",getOptionKey:p,getOptionLabel:c,getOptionAfterLabel:F,...s})=>{let b=mi(),[d,m]=di(!1);if(!b)throw new Error("Para usar o <SelectV2 /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let L=R(b.formState.errors,e),{field:B}=pi({control:b.control,name:e,rules:t,defaultValue:i,shouldUnregister:n});return te("div",{style:{display:"flex",flexDirection:"column"},children:[te("div",{style:{display:"flex"},children:[l&&z(h,{label:l,required:P}),u&&z(Z,{title:u})]}),te(xi,{open:d,onOpen:()=>m(!0),onClose:()=>m(!1),displayEmpty:!!x,variant:g,autoComplete:"off",value:B.value||null,renderValue:o=>z(Ke,{getOptionLabel:c,placeholder:x,value:o}),onChange:o=>{B.onChange(o.target.value),a?.(o.target.value)},error:!!L,size:s.size||"medium",inputRef:B.ref,...s,endAdornment:te(hi,{children:[s.endAdornment,!!(v&&B.value)&&z(ui,{variant:"text",color:"neutral",size:"small",sx:{borderRadius:"50%",position:"absolute",right:"2rem"},style:{padding:0},"aria-label":"Limpar",title:"Limpar",onClick:()=>{B.onChange(null),a?.(null)},children:z(fi,{icon:ci,color:yi.neutral[100],size:"25px",removeMargin:!0})})]}),children:[y.map(o=>{let r=p(o),C=c(o);return z(Fi,{value:o,children:te("div",{style:{display:"flex",flexDirection:"column",flex:1},children:[C,z("span",{children:F?.(o)??null})]})},r)}),f!==void 0&&te("div",{children:[z("div",{style:{padding:"8px 16px"},children:z(bi,{})},"footer-divider"),z("div",{children:f({closeSelect:()=>m(!1)})},"footer-content")]},"footer")]},e),z(S,{name:e})]})},Pi=re(gi);import{forwardRef as Ti,useCallback as Ii,useState as Si}from"react";import{useController as ki,useFormContext as wi}from"react-hook-form";import{isObject as Vi,isEmpty as Ri,isEqual as Ei}from"lodash-es";import{Autocomplete as Li,TextField as Bi,Divider as Ze}from"@mui/material";import{LIcon as Ce,Button as Gi}from"@s_mart/core";import{colorPalette as Ai}from"@s_mart/tokens";import{linePlus as eo,linePen as $i}from"@s_mart/solid-icons";import{toRem as oo}from"@s_mart/utils";import{toRem as ye}from"@s_mart/utils";import vi from"@emotion/styled";import{css as Ci}from"@emotion/react";var Xe=Ci`
|
|
73
|
+
display: flex;
|
|
74
|
+
align-items: center;
|
|
75
|
+
justify-content: center;
|
|
76
|
+
`,Qe=vi.div`
|
|
77
|
+
display: flex;
|
|
78
|
+
|
|
79
|
+
div.endAdornments {
|
|
80
|
+
position: absolute;
|
|
81
|
+
right: 0;
|
|
82
|
+
|
|
83
|
+
${Xe}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.MuiAutocomplete-endAdornment {
|
|
87
|
+
position: relative;
|
|
88
|
+
right: 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.endAdornments > .MuiAutocomplete-endAdornment {
|
|
92
|
+
transform: translate(0, 0);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.creatable,
|
|
96
|
+
.editable {
|
|
97
|
+
${Xe}
|
|
98
|
+
|
|
99
|
+
.divider {
|
|
100
|
+
width: 1px;
|
|
101
|
+
height: ${ye(20)};
|
|
102
|
+
background-color: ${({theme:e})=>e.palette.grey[400]};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.button {
|
|
106
|
+
display: flex;
|
|
107
|
+
justify-content: center;
|
|
108
|
+
align-items: center;
|
|
109
|
+
color: ${({theme:e})=>e.palette.grey[600]};
|
|
110
|
+
border-radius: 50%;
|
|
111
|
+
|
|
112
|
+
margin: 0 ${ye(6)};
|
|
113
|
+
width: ${ye(28)};
|
|
114
|
+
height: ${ye(28)};
|
|
115
|
+
|
|
116
|
+
&:hover {
|
|
117
|
+
cursor: pointer;
|
|
118
|
+
background-color: ${({theme:e})=>e.palette.grey[100]};
|
|
119
|
+
transition: background-color 0.2s ease-in-out;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
`;import{Fragment as Te,jsx as A,jsxs as O}from"react/jsx-runtime";import{createElement as _i}from"react";var Di=({name:e,rules:t,defaultValue:i,shouldUnregister:n,label:l,required:P,options:y,footer:x,showCreatableButton:v=!0,showEditableButton:u,onEditOption:f,onCreateOption:a,getOptionKey:g,getOptionLabel:p,getOptionAfterLabel:c,textFieldProps:F,multiple:s,info:b,noOptionsText:d,onChange:m,onInputChange:L,placeholder:B,...o})=>{let[r,C]=Si(""),k=wi();if(!k)throw new Error("Para usar o <CreatableV2 /> \xE9 necess\xE1rio que ele esteja dentro de um <Form />");let H=R(k.formState.errors,e),V=!v||o.disabled,{field:M}=ki({name:e,control:k.control,rules:t,defaultValue:i,shouldUnregister:n}),xe=I=>{let G=0;return F?.InputProps||(G+=2.5),V||(G+=2.56,ie(I)&&(G+=2.56)),!o.disableClearable&&!o.disabled&&(G+=1.3),G+"rem"},ie=I=>o.disabled?!1:u&&Vi(I)&&!Ri(I),E=Ii(()=>{typeof a<"u"&&(a(r),C(""))},[r]),T=I=>{f?.(I)};return O("div",{style:{display:"flex",flexDirection:"column"},children:[O("div",{style:{display:"flex"},children:[l&&A(h,{label:l,required:P}),b&&A(Z,{title:b})]}),A(Qe,{children:A(Li,{fullWidth:!0,onChange:(I,G)=>{C(""),M.onChange(G),m?.(G)},onInputChange:(I,G,Y)=>{Y==="input"&&(C(G),L?.(G))},slotProps:{...o.slotProps,paper:{...o.slotProps?.paper,sx:{border:`1px solid ${Ai.neutral[30]}`,boxShadow:"0px 2px 4px rgba(0, 0, 0, 0.15)",...o.slotProps?.paper?.sx}}},value:M.value?M.value:s?[]:null,options:y,multiple:s,readOnly:o.disabled,noOptionsText:O(Te,{children:[d||"Nenhuma op\xE7\xE3o encontrada",!V&&O(Gi,{sx:{justifyContent:"flex-start",padding:`${oo(6)} ${oo(-16)}`,margin:0},fullWidth:!0,onClick:E,variant:"text",startIcon:A(Ce,{icon:eo}),children:["Adicionar ",`"${r}"`]}),typeof x<"u"&&O(Te,{children:[A("div",{style:{paddingTop:"0.5rem",paddingBottom:"0.5rem"},children:A(Ze,{})}),x()]})]}),isOptionEqualToValue:(I,G)=>Ei(I,G),getOptionLabel:I=>p(I),getOptionKey:I=>g(I),renderOption:typeof c=="function"?(I,G)=>{let Y=c(G),ro=g(G);return _i("li",{...I,key:ro},O("div",{style:{display:"flex",flexDirection:"column"},children:[A("span",{children:p(G)}),typeof Y=="string"?A("span",{children:Y}):Y]}))}:void 0,ListboxComponent:Ti(function(G,Y){return O(Te,{children:[A("ul",{...G,ref:Y}),typeof x<"u"?O("div",{...G,children:[A("div",{style:{paddingTop:"0.5rem",paddingBottom:"0.5rem"},children:A(Ze,{})}),x()]},"creatable-footer"):null]})}),...o,sx:{"& div.MuiInputBase-root":{paddingRight:`${xe(M.value)} !important`},...o.sx},onBlur:I=>{o?.onBlur?.(I),C("")},renderInput:I=>A(Bi,{placeholder:B,...I,error:!!H,InputProps:{...I.InputProps,inputRef:M.ref,endAdornment:O("div",{className:"endAdornments",children:[I.InputProps.endAdornment,ie(M.value)?O("div",{className:"editable",children:[A("div",{className:"divider"}),A("div",{className:"button",onClick:()=>T(M.value),children:A(Ce,{icon:$i,size:"24px",removeMargin:!0})})]}):null,v&&O("div",{className:"creatable",children:[A("div",{className:"divider"}),A("div",{className:"button",onClick:E,children:A(Ce,{icon:eo,size:"24px",removeMargin:!0})})]})]})},...F})},e)}),A(S,{name:e})]})},Mi=re(Di);export{Ut as Autocomplete,kr as Checkbox,Pr as Creatable,Mi as CreatableV2,xt as DatePicker,h as FieldLabel,mo as Form,Fe as FormProvider,zr as RadioButton,Wr as RadioGroup,tr as Searchable,li as SearchableV2,jo as Select,Pi as SelectV2,Zr as Slider,Ar as Switch,Eo as TextField,At as TimePicker,be as useForm};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@s_mart/form",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
4
4
|
"main": "./dist/index.mjs",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.mts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"eslint-config-smarten": "4.1.0",
|
|
24
24
|
"@s_mart/rules": "5.1.1",
|
|
25
25
|
"@s_mart/solid-icons": "5.2.0",
|
|
26
|
-
"@s_mart/regular-icons": "5.
|
|
26
|
+
"@s_mart/regular-icons": "5.3.0",
|
|
27
27
|
"@s_mart/tokens": "5.1.0",
|
|
28
28
|
"@s_mart/typed": "6.0.0",
|
|
29
29
|
"@s_mart/utils": "5.1.1"
|