@s_mart/form 16.1.2 → 16.1.3
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/checkbox/checkbox.mjs +43 -0
- package/dist/checkbox/checkbox.mjs.map +1 -0
- package/dist/components/fieldError/fieldError.mjs +20 -0
- package/dist/components/fieldError/fieldError.mjs.map +1 -0
- package/dist/components/fieldInfo/fieldInfo.mjs +20 -0
- package/dist/components/fieldInfo/fieldInfo.mjs.map +1 -0
- package/dist/components/fieldLabel/fieldLabel.mjs +29 -0
- package/dist/components/fieldLabel/fieldLabel.mjs.map +1 -0
- package/dist/creatable/creatable.mjs +191 -0
- package/dist/creatable/creatable.mjs.map +1 -0
- package/dist/creatable/creatable.styles.mjs +41 -0
- package/dist/creatable/creatable.styles.mjs.map +1 -0
- package/dist/datePicker/datePicker.mjs +75 -0
- package/dist/datePicker/datePicker.mjs.map +1 -0
- package/dist/datePicker/datePicker.styles.mjs +29 -0
- package/dist/datePicker/datePicker.styles.mjs.map +1 -0
- package/dist/form/form.mjs +16 -0
- package/dist/form/form.mjs.map +1 -0
- package/dist/form/formProvider.mjs +19 -0
- package/dist/form/formProvider.mjs.map +1 -0
- package/dist/form/useForm.mjs +20 -0
- package/dist/form/useForm.mjs.map +1 -0
- package/dist/formComponentPrecisaDeControl.mjs +10 -0
- package/dist/formComponentPrecisaDeControl.mjs.map +1 -0
- package/dist/index.mjs +18 -865
- package/dist/radio/radioButton/radioButton.mjs +19 -0
- package/dist/radio/radioButton/radioButton.mjs.map +1 -0
- package/dist/radio/radioGroup/radioGroup.mjs +46 -0
- package/dist/radio/radioGroup/radioGroup.mjs.map +1 -0
- package/dist/searchable/searchable.mjs +111 -0
- package/dist/searchable/searchable.mjs.map +1 -0
- package/dist/select/select.mjs +117 -0
- package/dist/select/select.mjs.map +1 -0
- package/dist/select/selectRenderValue.mjs +11 -0
- package/dist/select/selectRenderValue.mjs.map +1 -0
- package/dist/slider/slider.mjs +26 -0
- package/dist/slider/slider.mjs.map +1 -0
- package/dist/switch/switch.mjs +39 -0
- package/dist/switch/switch.mjs.map +1 -0
- package/dist/textField/textField.mjs +102 -0
- package/dist/textField/textField.mjs.map +1 -0
- package/dist/timePicker/timePicker.mjs +76 -0
- package/dist/timePicker/timePicker.mjs.map +1 -0
- package/dist/timePicker/timePicker.styles.mjs +29 -0
- package/dist/timePicker/timePicker.styles.mjs.map +1 -0
- package/dist/utils/erroFieldFormatado.mjs +6 -0
- package/dist/utils/erroFieldFormatado.mjs.map +1 -0
- package/dist/utils/typedMemo.mjs +7 -0
- package/dist/utils/typedMemo.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import e from "../../components/fieldLabel/fieldLabel.mjs";
|
|
2
|
+
import { FormControlLabel as t, Grid as n, Radio as r } from "@mui/material";
|
|
3
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
4
|
+
//#region src/radio/radioButton/radioButton.tsx
|
|
5
|
+
var a = ({ label: a, labelPlacement: o, ...s }) => /* @__PURE__ */ i(n, {
|
|
6
|
+
sx: {
|
|
7
|
+
display: "flex",
|
|
8
|
+
flexDirection: "column"
|
|
9
|
+
},
|
|
10
|
+
children: /* @__PURE__ */ i(t, {
|
|
11
|
+
control: /* @__PURE__ */ i(r, { ...s }),
|
|
12
|
+
label: /* @__PURE__ */ i(e, { label: a }),
|
|
13
|
+
labelPlacement: o || "end"
|
|
14
|
+
})
|
|
15
|
+
});
|
|
16
|
+
//#endregion
|
|
17
|
+
export { a as default };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=radioButton.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"radioButton.mjs","names":[],"sources":["../../../src/radio/radioButton/radioButton.tsx"],"sourcesContent":["import { FormControlLabel, Grid, Radio as RadioMui } from '@mui/material';\nimport type { RadioProps } from './radioButton.types';\nimport { FieldLabel } from '../../components/fieldLabel';\n\nconst RadioButton = ({ label, labelPlacement, ...rest }: RadioProps) => {\n return (\n <Grid\n sx={{\n display: 'flex',\n flexDirection: 'column',\n }}\n >\n <FormControlLabel\n control={<RadioMui {...rest} />}\n label={<FieldLabel label={label} />}\n labelPlacement={labelPlacement || 'end'}\n />\n </Grid>\n );\n};\n\nexport default RadioButton;\n"],"mappings":";;;;AAIA,IAAM,KAAe,EAAE,UAAO,mBAAgB,GAAG,QAE7C,kBAAC,GAAD;CACE,IAAI;EACF,SAAS;EACT,eAAe;CACjB;CAEA,UAAA,kBAAC,GAAD;EACE,SAAS,kBAAC,GAAD,EAAU,GAAI,EAAO,CAAA;EAC9B,OAAO,kBAAC,GAAD,EAAmB,SAAQ,CAAA;EAClC,gBAAgB,KAAkB;CACnC,CAAA;AACG,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import e from "../../components/fieldError/fieldError.mjs";
|
|
2
|
+
import t from "../../components/fieldLabel/fieldLabel.mjs";
|
|
3
|
+
import { FormComponentPrecisaDeControl as n } from "../../formComponentPrecisaDeControl.mjs";
|
|
4
|
+
import { useController as r, useFormContext as i } from "react-hook-form";
|
|
5
|
+
import { RadioGroup as a, Stack as o } from "@mui/material";
|
|
6
|
+
import { jsx as s, jsxs as c } from "react/jsx-runtime";
|
|
7
|
+
//#region src/radio/radioGroup/radioGroup.tsx
|
|
8
|
+
var l = ({ name: l, rules: u, defaultValue: d, shouldUnregister: f, control: p, label: m, required: h, children: g, orientation: _ = "row", disableIconError: v, ...y }) => {
|
|
9
|
+
let b = i()?.control, x = p ?? b;
|
|
10
|
+
if (!x) throw new n("RadioGroup");
|
|
11
|
+
let { field: S } = r({
|
|
12
|
+
control: x,
|
|
13
|
+
name: l,
|
|
14
|
+
rules: u,
|
|
15
|
+
defaultValue: d,
|
|
16
|
+
shouldUnregister: f
|
|
17
|
+
});
|
|
18
|
+
return /* @__PURE__ */ c(o, { children: [
|
|
19
|
+
m && /* @__PURE__ */ s(t, {
|
|
20
|
+
label: m,
|
|
21
|
+
required: h
|
|
22
|
+
}),
|
|
23
|
+
/* @__PURE__ */ s(a, {
|
|
24
|
+
value: S.value || "",
|
|
25
|
+
name: l,
|
|
26
|
+
...y,
|
|
27
|
+
onChange: (e) => {
|
|
28
|
+
y?.onChange?.(e, e.target?.value), S.onChange(e);
|
|
29
|
+
},
|
|
30
|
+
style: {
|
|
31
|
+
display: "flex",
|
|
32
|
+
flexDirection: _
|
|
33
|
+
},
|
|
34
|
+
children: g
|
|
35
|
+
}, l),
|
|
36
|
+
/* @__PURE__ */ s(e, {
|
|
37
|
+
name: l,
|
|
38
|
+
disableIcon: v,
|
|
39
|
+
control: x
|
|
40
|
+
})
|
|
41
|
+
] });
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
export { l as default };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=radioGroup.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"radioGroup.mjs","names":[],"sources":["../../../src/radio/radioGroup/radioGroup.tsx"],"sourcesContent":["import { RadioGroup as RadioGroupMui, Stack } from '@mui/material';\nimport { type FieldPath, type FieldValues, useController, useFormContext } from 'react-hook-form';\nimport { FieldError } from '../../components/fieldError';\nimport { FieldLabel } from '../../components/fieldLabel';\nimport type { RadioGroupProps } from './radioGroup.types';\nimport { FormComponentPrecisaDeControl } from '../../formComponentPrecisaDeControl';\n\nconst RadioGroup = ({\n // RHF\n name,\n rules,\n defaultValue,\n shouldUnregister,\n control: controlFromProps,\n // Component Props\n label,\n required,\n children,\n orientation = 'row',\n disableIconError,\n ...rest\n}: RadioGroupProps) => {\n const controlFromContext = useFormContext()?.control;\n\n const control = controlFromProps ?? controlFromContext;\n\n if (!control) {\n throw new FormComponentPrecisaDeControl('RadioGroup');\n }\n\n const { field } = useController({\n control,\n name,\n rules,\n defaultValue,\n shouldUnregister,\n });\n\n return (\n <Stack>\n {label && <FieldLabel label={label} required={required} />}\n <RadioGroupMui\n key={name}\n value={field.value || ''}\n name={name}\n {...rest}\n onChange={(e) => {\n rest?.onChange?.(e, e.target?.value);\n field.onChange(e);\n }}\n style={{\n display: 'flex',\n flexDirection: orientation,\n }}\n >\n {children}\n </RadioGroupMui>\n <FieldError name={name} disableIcon={disableIconError} control={control} />\n </Stack>\n );\n};\n\nexport default RadioGroup;\n"],"mappings":";;;;;;;AAOA,IAAM,KAAc,EAElB,SACA,UACA,iBACA,qBACA,SAAS,GAET,UACA,aACA,aACA,iBAAc,OACd,qBACA,GAAG,QACkB;CACrB,IAAM,IAAqB,EAAe,CAAC,EAAE,SAEvC,IAAU,KAAoB;CAEpC,IAAI,CAAC,GACH,MAAM,IAAI,EAA8B,YAAY;CAGtD,IAAM,EAAE,aAAU,EAAc;EAC9B;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,OACE,kBAAC,GAAD,EAAA,UAAA;EACG,KAAS,kBAAC,GAAD;GAAmB;GAAiB;EAAW,CAAA;EACzD,kBAAC,GAAD;GAEE,OAAO,EAAM,SAAS;GAChB;GACN,GAAI;GACJ,WAAW,MAAM;IAEf,AADA,GAAM,WAAW,GAAG,EAAE,QAAQ,KAAK,GACnC,EAAM,SAAS,CAAC;GAClB;GACA,OAAO;IACL,SAAS;IACT,eAAe;GACjB;GAEC;EACY,GAdR,CAcQ;EACf,kBAAC,GAAD;GAAkB;GAAM,aAAa;GAA2B;EAAU,CAAA;CACrE,EAAA,CAAA;AAEX"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { erroFieldFormatado as e } from "../utils/erroFieldFormatado.mjs";
|
|
2
|
+
import t from "../components/fieldError/fieldError.mjs";
|
|
3
|
+
import n from "../components/fieldLabel/fieldLabel.mjs";
|
|
4
|
+
import { FormComponentPrecisaDeControl as r } from "../formComponentPrecisaDeControl.mjs";
|
|
5
|
+
import { typedMemo as i } from "../utils/typedMemo.mjs";
|
|
6
|
+
import a from "../components/fieldInfo/fieldInfo.mjs";
|
|
7
|
+
import { useController as o, useFormContext as s, useFormState as c } from "react-hook-form";
|
|
8
|
+
import { Autocomplete as l, Divider as u, TextField as d } from "@mui/material";
|
|
9
|
+
import { Fragment as f, jsx as p, jsxs as m } from "react/jsx-runtime";
|
|
10
|
+
import { createElement as h, forwardRef as g } from "react";
|
|
11
|
+
import "@s_mart/tokens";
|
|
12
|
+
import _ from "lodash-es/isEqual";
|
|
13
|
+
var v = i((i) => {
|
|
14
|
+
let { name: v, rules: y, defaultValue: b, shouldUnregister: x, control: S, label: C, required: w, options: T, textFieldProps: E, noOptionsText: D, footer: O, multiple: k, info: A, placeholder: j, onChange: M, onInputChange: N, getOptionAfterLabel: P, getOptionLabel: F, getInputValueLabel: I, getOptionKey: L, ...R } = i, z = s()?.control, B = S ?? z;
|
|
15
|
+
if (!B) throw new r("Searchable");
|
|
16
|
+
let V = c({
|
|
17
|
+
control: B,
|
|
18
|
+
name: v
|
|
19
|
+
}), H = e(V.errors, v), { field: U } = o({
|
|
20
|
+
name: v,
|
|
21
|
+
control: B,
|
|
22
|
+
rules: y,
|
|
23
|
+
defaultValue: b,
|
|
24
|
+
shouldUnregister: x
|
|
25
|
+
}), W = U.value ? U.value : k ? [] : null;
|
|
26
|
+
return /* @__PURE__ */ m("div", {
|
|
27
|
+
style: {
|
|
28
|
+
display: "flex",
|
|
29
|
+
flexDirection: "column"
|
|
30
|
+
},
|
|
31
|
+
children: [
|
|
32
|
+
/* @__PURE__ */ m("div", {
|
|
33
|
+
style: { display: "flex" },
|
|
34
|
+
children: [C && /* @__PURE__ */ p(n, {
|
|
35
|
+
label: C,
|
|
36
|
+
required: w
|
|
37
|
+
}), A && /* @__PURE__ */ p(a, { title: A })]
|
|
38
|
+
}),
|
|
39
|
+
/* @__PURE__ */ p(l, {
|
|
40
|
+
onChange: (e, t) => {
|
|
41
|
+
U.onChange(t), M?.(t);
|
|
42
|
+
},
|
|
43
|
+
onInputChange: (e, t, n) => {
|
|
44
|
+
n === "input" && N?.(t);
|
|
45
|
+
},
|
|
46
|
+
value: W,
|
|
47
|
+
options: T,
|
|
48
|
+
multiple: k,
|
|
49
|
+
readOnly: R.disabled,
|
|
50
|
+
slotProps: {
|
|
51
|
+
...R.slotProps,
|
|
52
|
+
listbox: { component: g(function(e, t) {
|
|
53
|
+
return /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("ul", {
|
|
54
|
+
...e,
|
|
55
|
+
ref: t
|
|
56
|
+
}), O === void 0 ? null : /* @__PURE__ */ m("div", {
|
|
57
|
+
...e,
|
|
58
|
+
children: [/* @__PURE__ */ p("div", {
|
|
59
|
+
style: {
|
|
60
|
+
paddingTop: "0.5rem",
|
|
61
|
+
paddingBottom: "0.5rem"
|
|
62
|
+
},
|
|
63
|
+
children: /* @__PURE__ */ p(u, {})
|
|
64
|
+
}), O()]
|
|
65
|
+
}, "searchable-footer")] });
|
|
66
|
+
}) }
|
|
67
|
+
},
|
|
68
|
+
noOptionsText: /* @__PURE__ */ m(f, { children: [D || "Nenhuma opção encontrada", O === void 0 ? null : /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("div", {
|
|
69
|
+
style: {
|
|
70
|
+
paddingTop: "0.5rem",
|
|
71
|
+
paddingBottom: "0.5rem"
|
|
72
|
+
},
|
|
73
|
+
children: /* @__PURE__ */ p(u, {})
|
|
74
|
+
}), O()] })] }),
|
|
75
|
+
isOptionEqualToValue: (e, t) => _(e, t),
|
|
76
|
+
getOptionLabel: P && I || F,
|
|
77
|
+
getOptionKey: L,
|
|
78
|
+
renderOption: typeof P == "function" ? (e, t) => {
|
|
79
|
+
let n = P(t), r = L(t);
|
|
80
|
+
return /* @__PURE__ */ h("li", {
|
|
81
|
+
...e,
|
|
82
|
+
key: r
|
|
83
|
+
}, /* @__PURE__ */ m("div", {
|
|
84
|
+
style: {
|
|
85
|
+
display: "flex",
|
|
86
|
+
flexDirection: "column",
|
|
87
|
+
flex: 1
|
|
88
|
+
},
|
|
89
|
+
children: [/* @__PURE__ */ p("span", { children: F(t) }), typeof n == "string" ? /* @__PURE__ */ p("span", { children: n }) : n]
|
|
90
|
+
}));
|
|
91
|
+
} : void 0,
|
|
92
|
+
...R,
|
|
93
|
+
renderInput: (e) => /* @__PURE__ */ p(d, {
|
|
94
|
+
error: !!H,
|
|
95
|
+
placeholder: j,
|
|
96
|
+
...e,
|
|
97
|
+
...E,
|
|
98
|
+
inputRef: U.ref
|
|
99
|
+
})
|
|
100
|
+
}, v),
|
|
101
|
+
/* @__PURE__ */ p(t, {
|
|
102
|
+
name: v,
|
|
103
|
+
control: B
|
|
104
|
+
})
|
|
105
|
+
]
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
//#endregion
|
|
109
|
+
export { v as default };
|
|
110
|
+
|
|
111
|
+
//# sourceMappingURL=searchable.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"searchable.mjs","names":[],"sources":["../../src/searchable/searchable.tsx"],"sourcesContent":["import { forwardRef, type LegacyRef } from 'react';\n\nimport { colorPalette } from '@s_mart/tokens';\n\nimport type { AutocompleteValue } from '@mui/material';\nimport { Autocomplete, Divider, TextField } from '@mui/material';\nimport isEqual from 'lodash-es/isEqual';\nimport {\n type FieldPath,\n type FieldPathValue,\n type FieldValues,\n useController,\n useFormContext,\n useFormState,\n} from 'react-hook-form';\n\nimport { FieldError } from '../components/fieldError';\nimport { FieldInfo } from '../components/fieldInfo';\nimport { FieldLabel } from '../components/fieldLabel';\nimport { FormComponentPrecisaDeControl } from '../formComponentPrecisaDeControl';\nimport { erroFieldFormatado } from '../utils/erroFieldFormatado';\nimport { typedMemo } from '../utils/typedMemo';\nimport type { SearchableProps } from './searchable.types';\n\nconst Searchable = <\n FieldValue,\n Multiple extends boolean | undefined = undefined,\n DisableClearable extends boolean | undefined = undefined,\n FreeSolo extends boolean | undefined = undefined,\n>(\n props: SearchableProps<FieldValue, Multiple, DisableClearable, FreeSolo>,\n) => {\n const {\n // RHF\n name,\n rules,\n defaultValue,\n shouldUnregister,\n control: controlFromProps,\n // Component Props\n label,\n required,\n options,\n textFieldProps,\n noOptionsText,\n footer,\n multiple,\n info,\n placeholder,\n onChange: onChangeProp,\n onInputChange,\n getOptionAfterLabel,\n getOptionLabel,\n getInputValueLabel,\n getOptionKey,\n ...rest\n } = props;\n\n const controlFromContext = useFormContext()?.control;\n\n const control = controlFromProps ?? controlFromContext;\n\n if (!control) {\n throw new FormComponentPrecisaDeControl('Searchable');\n }\n\n const formState = useFormState({ control, name });\n\n const formattedError = erroFieldFormatado(formState.errors, name);\n\n const { field } = useController({\n name,\n control,\n rules,\n defaultValue,\n shouldUnregister,\n });\n\n const fieldValue = !field.value ? (multiple ? [] : null) : field.value;\n\n return (\n <div style={{ display: 'flex', flexDirection: 'column' }}>\n <div style={{ display: 'flex' }}>\n {label && <FieldLabel label={label} required={required} />}\n {info && <FieldInfo title={info} />}\n </div>\n <Autocomplete<FieldValue, Multiple, DisableClearable, FreeSolo>\n key={name}\n onChange={(_, value) => {\n field.onChange(value);\n onChangeProp?.(value);\n }}\n onInputChange={(_, value, reason) => {\n if (reason === 'input') {\n onInputChange?.(value);\n }\n }}\n value={fieldValue}\n options={options}\n multiple={multiple}\n readOnly={rest.disabled}\n slotProps={{\n ...rest.slotProps,\n\n listbox: {\n component: forwardRef(function Ul(props, ref: LegacyRef<HTMLUListElement>) {\n return (\n <>\n <ul {...props} ref={ref} />\n\n {typeof footer !== 'undefined' ? (\n <div key='searchable-footer' {...props}>\n <div style={{ paddingTop: '0.5rem', paddingBottom: '0.5rem' }}>\n <Divider />\n </div>\n {footer()}\n </div>\n ) : null}\n </>\n );\n }),\n },\n }}\n noOptionsText={\n <>\n {noOptionsText || 'Nenhuma opção encontrada'}\n {typeof footer !== 'undefined' ? (\n <>\n <div style={{ paddingTop: '0.5rem', paddingBottom: '0.5rem' }}>\n <Divider />\n </div>\n {footer()}\n </>\n ) : null}\n </>\n }\n isOptionEqualToValue={(option, value) => isEqual(option, value)}\n getOptionLabel={getOptionAfterLabel ? getInputValueLabel || getOptionLabel : getOptionLabel}\n getOptionKey={getOptionKey}\n renderOption={\n typeof getOptionAfterLabel === 'function'\n ? (props, option) => {\n const afterlabel = getOptionAfterLabel(option);\n const key = getOptionKey(option);\n return (\n <li {...props} key={key}>\n <div style={{ display: 'flex', flexDirection: 'column', flex: 1 }}>\n <span>{getOptionLabel(option)}</span>\n {typeof afterlabel === 'string' ? <span>{afterlabel}</span> : afterlabel}\n </div>\n </li>\n );\n }\n : undefined\n }\n {...rest}\n renderInput={(params) => {\n return (\n <TextField\n error={Boolean(formattedError)}\n placeholder={placeholder}\n {...params}\n {...textFieldProps}\n inputRef={field.ref}\n />\n );\n }}\n />\n <FieldError name={name} control={control} />\n </div>\n );\n};\n\nexport default typedMemo(Searchable);\n"],"mappings":";;;;;;;;;;;;AA6KA,IAAA,IAAe,GA/Ib,MACG;CACH,IAAM,EAEJ,SACA,UACA,iBACA,qBACA,SAAS,GAET,UACA,aACA,YACA,mBACA,kBACA,WACA,aACA,SACA,gBACA,UAAU,GACV,kBACA,wBACA,mBACA,uBACA,iBACA,GAAG,MACD,GAEE,IAAqB,EAAe,CAAC,EAAE,SAEvC,IAAU,KAAoB;CAEpC,IAAI,CAAC,GACH,MAAM,IAAI,EAA8B,YAAY;CAGtD,IAAM,IAAY,EAAa;EAAE;EAAS;CAAK,CAAC,GAE1C,IAAiB,EAAmB,EAAU,QAAQ,CAAI,GAE1D,EAAE,aAAU,EAAc;EAC9B;EACA;EACA;EACA;EACA;CACF,CAAC,GAEK,IAAc,EAAM,QAAiC,EAAM,QAA9B,IAAW,CAAC,IAAI;CAEnD,OACE,kBAAC,OAAD;EAAK,OAAO;GAAE,SAAS;GAAQ,eAAe;EAAS;EAAvD,UAAA;GACE,kBAAC,OAAD;IAAK,OAAO,EAAE,SAAS,OAAO;IAA9B,UAAA,CACG,KAAS,kBAAC,GAAD;KAAmB;KAAiB;IAAW,CAAA,GACxD,KAAQ,kBAAC,GAAD,EAAW,OAAO,EAAO,CAAA,CA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CAAM,EAAQ,CAAA,GACnC,OAAO,KAAe,WAAW,kBAAC,QAAD,EAAA,UAAO,EAAiB,CAAA,IAAI,CAC3D;KACH,CAAA,CAAA;IAER,IACA,KAAA;IAEN,GAAI;IACJ,cAAc,MAEV,kBAAC,GAAD;KACE,OAAO,EAAQ;KACF;KACb,GAAI;KACJ,GAAI;KACJ,UAAU,EAAM;IACjB,CAAA;GAGN,GAhFM,CAgFN;GACD,kBAAC,GAAD;IAAkB;IAAe;GAAU,CAAA;EACxC;;AAET,CAEmC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { erroFieldFormatado as e } from "../utils/erroFieldFormatado.mjs";
|
|
2
|
+
import t from "../components/fieldError/fieldError.mjs";
|
|
3
|
+
import n from "../components/fieldLabel/fieldLabel.mjs";
|
|
4
|
+
import { FormComponentPrecisaDeControl as r } from "../formComponentPrecisaDeControl.mjs";
|
|
5
|
+
import { typedMemo as i } from "../utils/typedMemo.mjs";
|
|
6
|
+
import a from "../components/fieldInfo/fieldInfo.mjs";
|
|
7
|
+
import { SelectRenderValue as o } from "./selectRenderValue.mjs";
|
|
8
|
+
import { useController as s, useFormContext as c, useFormState as l } from "react-hook-form";
|
|
9
|
+
import { Divider as u, MenuItem as d, Select as f } from "@mui/material";
|
|
10
|
+
import { IconButton as p, LIcon as m } from "@s_mart/core";
|
|
11
|
+
import { Fragment as h, jsx as g, jsxs as _ } from "react/jsx-runtime";
|
|
12
|
+
import { useState as v } from "react";
|
|
13
|
+
import { colorPalette as y } from "@s_mart/tokens";
|
|
14
|
+
import { lineTimes as b } from "@s_mart/regular-icons";
|
|
15
|
+
var x = i((i) => {
|
|
16
|
+
let { name: x, rules: S, defaultValue: C, shouldUnregister: w, control: T, label: E, required: D, options: O, placeholder: k, clearable: A, info: j, footer: M, onChange: N, variant: P = "outlined", getOptionKey: F, getOptionLabel: I, getOptionAfterLabel: L, getInputValueLabel: R, getOptionIcon: z, ...B } = i, V = c()?.control, H = T ?? V, [U, W] = v(!1);
|
|
17
|
+
if (!H) throw new r("Select");
|
|
18
|
+
let G = l({
|
|
19
|
+
control: H,
|
|
20
|
+
name: x
|
|
21
|
+
}), K = e(G.errors, x), { field: q } = s({
|
|
22
|
+
control: H,
|
|
23
|
+
name: x,
|
|
24
|
+
rules: S,
|
|
25
|
+
defaultValue: C,
|
|
26
|
+
shouldUnregister: w
|
|
27
|
+
});
|
|
28
|
+
return /* @__PURE__ */ _("div", {
|
|
29
|
+
style: {
|
|
30
|
+
display: "flex",
|
|
31
|
+
flexDirection: "column"
|
|
32
|
+
},
|
|
33
|
+
children: [
|
|
34
|
+
/* @__PURE__ */ _("div", {
|
|
35
|
+
style: { display: "flex" },
|
|
36
|
+
children: [E && /* @__PURE__ */ g(n, {
|
|
37
|
+
label: E,
|
|
38
|
+
required: D
|
|
39
|
+
}), j && /* @__PURE__ */ g(a, { title: j })]
|
|
40
|
+
}),
|
|
41
|
+
/* @__PURE__ */ _(f, {
|
|
42
|
+
open: U,
|
|
43
|
+
onOpen: () => W(!0),
|
|
44
|
+
onClose: () => W(!1),
|
|
45
|
+
displayEmpty: !!k,
|
|
46
|
+
variant: P,
|
|
47
|
+
autoComplete: "off",
|
|
48
|
+
value: q.value || null,
|
|
49
|
+
renderValue: (e) => /* @__PURE__ */ g(o, {
|
|
50
|
+
getOptionLabel: L && R || I,
|
|
51
|
+
placeholder: k,
|
|
52
|
+
value: e
|
|
53
|
+
}),
|
|
54
|
+
onChange: (e) => {
|
|
55
|
+
q.onChange(e.target.value), N?.(e.target.value);
|
|
56
|
+
},
|
|
57
|
+
error: !!K,
|
|
58
|
+
size: B.size || "medium",
|
|
59
|
+
inputRef: q.ref,
|
|
60
|
+
...B,
|
|
61
|
+
endAdornment: /* @__PURE__ */ _(h, { children: [B.endAdornment, !!(A && q.value) && /* @__PURE__ */ g(p, {
|
|
62
|
+
variant: "text",
|
|
63
|
+
color: "neutral",
|
|
64
|
+
size: "small",
|
|
65
|
+
sx: {
|
|
66
|
+
borderRadius: "50%",
|
|
67
|
+
position: "absolute",
|
|
68
|
+
right: "2rem"
|
|
69
|
+
},
|
|
70
|
+
style: { padding: 0 },
|
|
71
|
+
"aria-label": "Limpar",
|
|
72
|
+
title: "Limpar",
|
|
73
|
+
onClick: () => {
|
|
74
|
+
q.onChange(null), N?.(null);
|
|
75
|
+
},
|
|
76
|
+
children: /* @__PURE__ */ g(m, {
|
|
77
|
+
icon: b,
|
|
78
|
+
color: y.neutral[100],
|
|
79
|
+
size: "25px",
|
|
80
|
+
removeMargin: !0
|
|
81
|
+
})
|
|
82
|
+
})] }),
|
|
83
|
+
children: [O.map((e) => {
|
|
84
|
+
let t = F(e), n = I(e), r = z?.(e);
|
|
85
|
+
return /* @__PURE__ */ g(d, {
|
|
86
|
+
value: e,
|
|
87
|
+
children: /* @__PURE__ */ _("div", {
|
|
88
|
+
style: {
|
|
89
|
+
display: "flex",
|
|
90
|
+
flexDirection: "column",
|
|
91
|
+
flex: 1
|
|
92
|
+
},
|
|
93
|
+
children: [r === void 0 ? n : /* @__PURE__ */ _("div", {
|
|
94
|
+
style: {
|
|
95
|
+
display: "flex",
|
|
96
|
+
alignItems: "center"
|
|
97
|
+
},
|
|
98
|
+
children: [r, n]
|
|
99
|
+
}), /* @__PURE__ */ g("span", { children: L?.(e) ?? null })]
|
|
100
|
+
})
|
|
101
|
+
}, t);
|
|
102
|
+
}), M !== void 0 && /* @__PURE__ */ _("div", { children: [/* @__PURE__ */ g("div", {
|
|
103
|
+
style: { padding: "8px 16px" },
|
|
104
|
+
children: /* @__PURE__ */ g(u, {})
|
|
105
|
+
}, "footer-divider"), /* @__PURE__ */ g("div", { children: M({ closeSelect: () => W(!1) }) }, "footer-content")] }, "footer")]
|
|
106
|
+
}, x),
|
|
107
|
+
/* @__PURE__ */ g(t, {
|
|
108
|
+
name: x,
|
|
109
|
+
control: H
|
|
110
|
+
})
|
|
111
|
+
]
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
//#endregion
|
|
115
|
+
export { x as default };
|
|
116
|
+
|
|
117
|
+
//# sourceMappingURL=select.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.mjs","names":[],"sources":["../../src/select/select.tsx"],"sourcesContent":["import { useState } from 'react';\n\nimport { IconButton, LIcon } from '@s_mart/core';\nimport { lineTimes } from '@s_mart/regular-icons';\nimport { colorPalette } from '@s_mart/tokens';\n\nimport { Divider, MenuItem, Select as SelectMui } from '@mui/material';\nimport {\n type FieldPath,\n type FieldPathValue,\n type FieldValues,\n useController,\n useFormContext,\n useFormState,\n} from 'react-hook-form';\n\nimport { FieldError } from '../components/fieldError';\nimport { FieldInfo } from '../components/fieldInfo';\nimport { FieldLabel } from '../components/fieldLabel';\nimport { FormComponentPrecisaDeControl } from '../formComponentPrecisaDeControl';\nimport { erroFieldFormatado } from '../utils/erroFieldFormatado';\nimport { typedMemo } from '../utils/typedMemo';\nimport type { SelectProps } from './select.types';\nimport { SelectRenderValue } from './selectRenderValue';\n\nconst Select = <FieldValue extends FieldValues | string | number>(\n props: SelectProps<FieldValue>,\n) => {\n const {\n // RHF\n name,\n rules,\n defaultValue,\n shouldUnregister,\n control: controlFromProps,\n // Component Props\n label,\n required,\n options,\n placeholder,\n clearable,\n info,\n footer,\n onChange: onChangeProp,\n variant = 'outlined',\n getOptionKey,\n getOptionLabel,\n getOptionAfterLabel,\n getInputValueLabel,\n getOptionIcon,\n ...rest\n } = props;\n\n const controlFromContext = useFormContext()?.control;\n\n const control = controlFromProps ?? controlFromContext;\n\n const [showSelect, setShowSelect] = useState(false);\n\n if (!control) {\n throw new FormComponentPrecisaDeControl('Select');\n }\n\n const formState = useFormState({ control, name });\n\n const formattedError = erroFieldFormatado(formState.errors, name);\n\n const { field } = useController({\n control,\n name,\n rules,\n defaultValue,\n shouldUnregister,\n });\n\n return (\n <div style={{ display: 'flex', flexDirection: 'column' }}>\n <div style={{ display: 'flex' }}>\n {label && <FieldLabel label={label} required={required} />}\n {info && <FieldInfo title={info} />}\n </div>\n <SelectMui<FieldValue>\n key={name}\n open={showSelect}\n onOpen={() => setShowSelect(true)}\n onClose={() => setShowSelect(false)}\n displayEmpty={Boolean(placeholder)}\n variant={variant}\n autoComplete='off'\n value={field.value || null}\n renderValue={(value) => {\n return (\n <SelectRenderValue\n getOptionLabel={\n getOptionAfterLabel ? getInputValueLabel || getOptionLabel : getOptionLabel\n }\n placeholder={placeholder}\n value={value}\n />\n );\n }}\n onChange={(e) => {\n field.onChange(e.target.value);\n onChangeProp?.(e.target.value as FieldValue);\n }}\n error={Boolean(formattedError)}\n size={rest.size || 'medium'}\n inputRef={field.ref}\n {...rest}\n endAdornment={\n <>\n {rest.endAdornment}\n\n {Boolean(clearable && field.value) && (\n <IconButton\n variant='text'\n color='neutral'\n size='small'\n sx={{ borderRadius: '50%', position: 'absolute', right: '2rem' }}\n style={{ padding: 0 }}\n aria-label='Limpar'\n title='Limpar'\n onClick={() => {\n field.onChange(null);\n onChangeProp?.(null);\n }}\n >\n <LIcon\n icon={lineTimes}\n color={colorPalette.neutral[100]}\n size='25px'\n removeMargin\n />\n </IconButton>\n )}\n </>\n }\n >\n {options.map((option) => {\n const key = getOptionKey(option);\n const label = getOptionLabel(option);\n const icon = getOptionIcon?.(option);\n return (\n <MenuItem key={key} value={option as any}>\n <div style={{ display: 'flex', flexDirection: 'column', flex: 1 }}>\n {icon !== undefined ? (\n <div style={{ display: 'flex', alignItems: 'center' }}>\n {icon}\n {label}\n </div>\n ) : (\n label\n )}\n <span>{getOptionAfterLabel?.(option) ?? null}</span>\n </div>\n </MenuItem>\n );\n })}\n {footer !== undefined && (\n <div key='footer'>\n <div key='footer-divider' style={{ padding: '8px 16px' }}>\n <Divider />\n </div>\n <div key='footer-content'>{footer({ closeSelect: () => setShowSelect(false) })}</div>\n </div>\n )}\n </SelectMui>\n <FieldError name={name} control={control} />\n </div>\n );\n};\n\nexport default typedMemo(Select);\n"],"mappings":";;;;;;;;;;;;;;AA4KA,IAAA,IAAe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//#region src/select/selectRenderValue.tsx
|
|
4
|
+
var n = ({ value: n, placeholder: r, getOptionLabel: i }) => n === null || n?.length === 0 ? /* @__PURE__ */ e("p", {
|
|
5
|
+
style: { color: t.neutral[100] },
|
|
6
|
+
children: r
|
|
7
|
+
}) : i(n);
|
|
8
|
+
//#endregion
|
|
9
|
+
export { n as SelectRenderValue };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=selectRenderValue.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectRenderValue.mjs","names":[],"sources":["../../src/select/selectRenderValue.tsx"],"sourcesContent":["import { colorPalette } from '@s_mart/tokens';\n\nimport type { FieldPath, FieldValues } from 'react-hook-form';\n\nimport type { SelectReturnValueProps } from './select.types';\n\nexport const SelectRenderValue = <\n TFieldValues extends FieldValues = FieldValues,\n TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>({\n value,\n placeholder,\n getOptionLabel,\n}: SelectReturnValueProps<TFieldValues, TFieldName>) => {\n if (value === null || value?.length === 0) {\n return <p style={{ color: colorPalette.neutral[100] }}>{placeholder}</p>;\n }\n\n return getOptionLabel(value);\n};\n"],"mappings":";;;AAMA,IAAa,KAGX,EACA,UACA,gBACA,wBAEI,MAAU,QAAQ,GAAO,WAAW,IAC/B,kBAAC,KAAD;CAAG,OAAO,EAAE,OAAO,EAAa,QAAQ,KAAK;CAAI,UAAA;AAAe,CAAA,IAGlE,EAAe,CAAK"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { FormComponentPrecisaDeControl as e } from "../formComponentPrecisaDeControl.mjs";
|
|
2
|
+
import { useController as t, useFormContext as n } from "react-hook-form";
|
|
3
|
+
import { Slider as r } from "@mui/material";
|
|
4
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
5
|
+
//#region src/slider/slider.tsx
|
|
6
|
+
var a = ({ name: a, rules: o, defaultValue: s, shouldUnregister: c, control: l, ...u }) => {
|
|
7
|
+
let d = n()?.control, f = l ?? d;
|
|
8
|
+
if (!f) throw new e("Slider");
|
|
9
|
+
let { field: p } = t({
|
|
10
|
+
control: f,
|
|
11
|
+
name: a,
|
|
12
|
+
rules: o,
|
|
13
|
+
defaultValue: s,
|
|
14
|
+
shouldUnregister: c
|
|
15
|
+
});
|
|
16
|
+
return /* @__PURE__ */ i(r, {
|
|
17
|
+
value: p.value || u?.min || 0,
|
|
18
|
+
onChange: p.onChange,
|
|
19
|
+
valueLabelDisplay: "auto",
|
|
20
|
+
...u
|
|
21
|
+
}, a);
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { a as default };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=slider.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slider.mjs","names":[],"sources":["../../src/slider/slider.tsx"],"sourcesContent":["import { type FieldPath, type FieldValues, useController, useFormContext } from 'react-hook-form';\nimport type { SliderProps } from './slider.types';\nimport { Slider as SliderMui } from '@mui/material';\nimport { FormComponentPrecisaDeControl } from '../formComponentPrecisaDeControl';\n\nconst Slider = ({ name, rules, defaultValue, shouldUnregister, control: controlFromProps, ...rest }: SliderProps) => {\n const controlFromContext = useFormContext()?.control;\n\n const control = controlFromProps ?? controlFromContext;\n\n if (!control) {\n throw new FormComponentPrecisaDeControl('Slider');\n }\n\n const { field } = useController({\n control,\n name,\n rules,\n defaultValue,\n shouldUnregister,\n });\n\n return (\n <SliderMui\n key={name}\n value={field.value || rest?.min || 0}\n onChange={field.onChange}\n valueLabelDisplay='auto'\n {...rest}\n />\n );\n};\n\nexport default Slider;\n"],"mappings":";;;;;AAKA,IAAM,KAAU,EAAE,SAAM,UAAO,iBAAc,qBAAkB,SAAS,GAAkB,GAAG,QAAwB;CACnH,IAAM,IAAqB,EAAe,CAAC,EAAE,SAEvC,IAAU,KAAoB;CAEpC,IAAI,CAAC,GACH,MAAM,IAAI,EAA8B,QAAQ;CAGlD,IAAM,EAAE,aAAU,EAAc;EAC9B;EACA;EACA;EACA;EACA;CACF,CAAC;CAED,OACE,kBAAC,GAAD;EAEE,OAAO,EAAM,SAAS,GAAM,OAAO;EACnC,UAAU,EAAM;EAChB,mBAAkB;EAClB,GAAI;CACL,GALM,CAKN;AAEL"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import e from "../components/fieldError/fieldError.mjs";
|
|
2
|
+
import t from "../components/fieldLabel/fieldLabel.mjs";
|
|
3
|
+
import { FormComponentPrecisaDeControl as n } from "../formComponentPrecisaDeControl.mjs";
|
|
4
|
+
import { useController as r, useFormContext as i } from "react-hook-form";
|
|
5
|
+
import { FormControlLabel as a, Stack as o, Switch as s } from "@mui/material";
|
|
6
|
+
import { jsx as c, jsxs as l } from "react/jsx-runtime";
|
|
7
|
+
import { useCallback as u } from "react";
|
|
8
|
+
//#region src/switch/switch.tsx
|
|
9
|
+
var d = ({ name: d, rules: f, defaultValue: p, defaultChecked: m, shouldUnregister: h, control: g, label: _, labelPlacement: v = "end", disableIconError: y, onChange: b, ...x }) => {
|
|
10
|
+
let S = i()?.control, C = g ?? S;
|
|
11
|
+
if (!C) throw new n("Switch");
|
|
12
|
+
let { field: w } = r({
|
|
13
|
+
control: C,
|
|
14
|
+
name: d,
|
|
15
|
+
rules: f,
|
|
16
|
+
defaultValue: m ?? p ?? !1,
|
|
17
|
+
shouldUnregister: h
|
|
18
|
+
}), T = u((e, t) => {
|
|
19
|
+
w.onChange(t), b?.(e, t);
|
|
20
|
+
}, [w, b]);
|
|
21
|
+
return /* @__PURE__ */ l(o, { children: [/* @__PURE__ */ c(a, {
|
|
22
|
+
control: /* @__PURE__ */ c(s, {
|
|
23
|
+
...x,
|
|
24
|
+
...w,
|
|
25
|
+
checked: !!w.value,
|
|
26
|
+
onChange: T
|
|
27
|
+
}),
|
|
28
|
+
label: /* @__PURE__ */ c(t, { label: _ }),
|
|
29
|
+
labelPlacement: v
|
|
30
|
+
}), /* @__PURE__ */ c(e, {
|
|
31
|
+
name: d,
|
|
32
|
+
disableIcon: y,
|
|
33
|
+
control: C
|
|
34
|
+
})] });
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
export { d as default };
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=switch.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.mjs","names":[],"sources":["../../src/switch/switch.tsx"],"sourcesContent":["import { FormControlLabel, Stack, Switch as SwitchMui } from '@mui/material';\nimport { useController, useFormContext } from 'react-hook-form';\nimport { FieldError } from '../components/fieldError';\nimport { FieldLabel } from '../components/fieldLabel';\nimport type { SwitchProps } from './switch.types';\nimport { FormComponentPrecisaDeControl } from '../formComponentPrecisaDeControl';\nimport { typedMemo } from '../utils/typedMemo';\nimport { useCallback } from 'react';\n\nconst Switch = ({\n // RHF\n name,\n rules,\n defaultValue,\n defaultChecked,\n shouldUnregister,\n control: controlFromProps,\n // Component Props\n label,\n labelPlacement = 'end',\n disableIconError,\n onChange: onChangeProp,\n ...rest\n}: SwitchProps) => {\n const controlFromContext = useFormContext()?.control;\n\n const control = controlFromProps ?? controlFromContext;\n\n if (!control) {\n throw new FormComponentPrecisaDeControl('Switch');\n }\n\n const { field } = useController<Record<string, boolean>>({\n control,\n name,\n rules,\n defaultValue: defaultChecked ?? defaultValue ?? false,\n shouldUnregister,\n });\n\n const handleChange = useCallback(\n (event: React.ChangeEvent<HTMLInputElement>, checked: boolean) => {\n field.onChange(checked);\n onChangeProp?.(event, checked);\n },\n [field, onChangeProp],\n );\n\n return (\n <Stack>\n <FormControlLabel\n control={<SwitchMui {...rest} {...field} checked={Boolean(field.value)} onChange={handleChange} />}\n label={<FieldLabel label={label} />}\n labelPlacement={labelPlacement}\n />\n <FieldError name={name} disableIcon={disableIconError} control={control} />\n </Stack>\n );\n};\n\nexport default Switch;\n"],"mappings":";;;;;;;;AASA,IAAM,KAAU,EAEd,SACA,UACA,iBACA,mBACA,qBACA,SAAS,GAET,UACA,oBAAiB,OACjB,qBACA,UAAU,GACV,GAAG,QACc;CACjB,IAAM,IAAqB,EAAe,CAAC,EAAE,SAEvC,IAAU,KAAoB;CAEpC,IAAI,CAAC,GACH,MAAM,IAAI,EAA8B,QAAQ;CAGlD,IAAM,EAAE,aAAU,EAAuC;EACvD;EACA;EACA;EACA,cAAc,KAAkB,KAAgB;EAChD;CACF,CAAC,GAEK,IAAe,GAClB,GAA4C,MAAqB;EAEhE,AADA,EAAM,SAAS,CAAO,GACtB,IAAe,GAAO,CAAO;CAC/B,GACA,CAAC,GAAO,CAAY,CACtB;CAEA,OACE,kBAAC,GAAD,EAAA,UAAA,CACE,kBAAC,GAAD;EACE,SAAS,kBAAC,GAAD;GAAW,GAAI;GAAM,GAAI;GAAO,SAAS,EAAQ,EAAM;GAAQ,UAAU;EAAe,CAAA;EACjG,OAAO,kBAAC,GAAD,EAAmB,SAAQ,CAAA;EAClB;CACjB,CAAA,GACD,kBAAC,GAAD;EAAkB;EAAM,aAAa;EAA2B;CAAU,CAAA,CACrE,EAAA,CAAA;AAEX"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { erroFieldFormatado as e } from "../utils/erroFieldFormatado.mjs";
|
|
2
|
+
import t from "../components/fieldError/fieldError.mjs";
|
|
3
|
+
import n from "../components/fieldLabel/fieldLabel.mjs";
|
|
4
|
+
import { FormComponentPrecisaDeControl as r } from "../formComponentPrecisaDeControl.mjs";
|
|
5
|
+
import { typedMemo as i } from "../utils/typedMemo.mjs";
|
|
6
|
+
import { useController as a, useFormContext as o, useFormState as s } from "react-hook-form";
|
|
7
|
+
import { InputAdornment as c, Stack as l, TextField as u, Tooltip as d } from "@mui/material";
|
|
8
|
+
import { LIcon as f } from "@s_mart/core";
|
|
9
|
+
import { jsx as p, jsxs as m } from "react/jsx-runtime";
|
|
10
|
+
import { useRef as h, useState as g } from "react";
|
|
11
|
+
import { lineEye as _, lineEyeSlash as v, lineInfoCircle as y } from "@s_mart/solid-icons";
|
|
12
|
+
import * as b from "@s_mart/masks";
|
|
13
|
+
var x = i(({ name: i, rules: x, defaultValue: S, shouldUnregister: C, control: w, label: T, required: E, mask: D, variant: O = "outlined", info: k, parse: A, format: j, onInputChange: M, disableIconError: N, ...P }) => {
|
|
14
|
+
let F = o()?.control, I = w ?? F, L = h(S || void 0);
|
|
15
|
+
if (!I) throw new r("TextField");
|
|
16
|
+
let [R, z] = g(!1), B = (e) => {
|
|
17
|
+
let t = e;
|
|
18
|
+
return t = j?.(e) ?? e, D ? b?.[D]?.format(t) : t;
|
|
19
|
+
}, V = (e) => {
|
|
20
|
+
let t = e;
|
|
21
|
+
return t = A?.(e) ?? t, D ? b?.[D]?.parse(t, L.current) : t;
|
|
22
|
+
}, H = (e) => {
|
|
23
|
+
if (!e || D !== "porcentagem" && D !== "porcentagem0") return;
|
|
24
|
+
e?.stopPropagation();
|
|
25
|
+
let t = (e?.target).value;
|
|
26
|
+
if (t) {
|
|
27
|
+
let n = String(t);
|
|
28
|
+
if (n.length > 0) {
|
|
29
|
+
let t = n.indexOf("%");
|
|
30
|
+
t > -1 && (e.currentTarget.selectionEnd = t);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}, { field: U } = a({
|
|
34
|
+
control: I,
|
|
35
|
+
name: i,
|
|
36
|
+
rules: x,
|
|
37
|
+
defaultValue: S,
|
|
38
|
+
shouldUnregister: C
|
|
39
|
+
}), W = s({
|
|
40
|
+
control: I,
|
|
41
|
+
name: i
|
|
42
|
+
}), G = e(W.errors, i);
|
|
43
|
+
return /* @__PURE__ */ m(l, { children: [
|
|
44
|
+
/* @__PURE__ */ m("div", {
|
|
45
|
+
style: { display: "flex" },
|
|
46
|
+
children: [T && /* @__PURE__ */ p("div", { children: /* @__PURE__ */ p(n, {
|
|
47
|
+
label: T,
|
|
48
|
+
required: E
|
|
49
|
+
}) }), k && /* @__PURE__ */ p("div", { children: /* @__PURE__ */ p(d, {
|
|
50
|
+
title: k,
|
|
51
|
+
placement: "top",
|
|
52
|
+
children: /* @__PURE__ */ p("div", {
|
|
53
|
+
style: { width: "fit-content" },
|
|
54
|
+
children: /* @__PURE__ */ p(f, {
|
|
55
|
+
icon: y,
|
|
56
|
+
color: "#757575"
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
}) })]
|
|
60
|
+
}),
|
|
61
|
+
/* @__PURE__ */ p(u, {
|
|
62
|
+
variant: O,
|
|
63
|
+
defaultValue: S,
|
|
64
|
+
value: B(U.value || (U.value == 0 ? U.value : "")),
|
|
65
|
+
onChange: (e) => {
|
|
66
|
+
let t = V(e?.target?.value);
|
|
67
|
+
U.onChange(t), M?.(t), L.current = e.target.value;
|
|
68
|
+
},
|
|
69
|
+
error: !!G,
|
|
70
|
+
...P,
|
|
71
|
+
type: P.type === "password" ? R ? "text" : "password" : P.type,
|
|
72
|
+
autoComplete: P.autoComplete || "off",
|
|
73
|
+
slotProps: {
|
|
74
|
+
...P.slotProps,
|
|
75
|
+
input: {
|
|
76
|
+
onKeyDown: H,
|
|
77
|
+
inputRef: U.ref,
|
|
78
|
+
endAdornment: P.type === "password" && /* @__PURE__ */ p(c, {
|
|
79
|
+
position: "start",
|
|
80
|
+
onClick: () => z(!R),
|
|
81
|
+
style: { cursor: "pointer" },
|
|
82
|
+
children: /* @__PURE__ */ p(f, {
|
|
83
|
+
icon: R ? _ : v,
|
|
84
|
+
size: "24px",
|
|
85
|
+
removeMargin: !0
|
|
86
|
+
})
|
|
87
|
+
}),
|
|
88
|
+
...P.slotProps?.input
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}, i),
|
|
92
|
+
/* @__PURE__ */ p(t, {
|
|
93
|
+
name: i,
|
|
94
|
+
disableIcon: N,
|
|
95
|
+
control: I
|
|
96
|
+
})
|
|
97
|
+
] });
|
|
98
|
+
});
|
|
99
|
+
//#endregion
|
|
100
|
+
export { x as default };
|
|
101
|
+
|
|
102
|
+
//# sourceMappingURL=textField.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textField.mjs","names":[],"sources":["../../src/textField/textField.tsx"],"sourcesContent":["import { Grid, InputAdornment, Stack, TextField as TextFieldMui, Tooltip } from '@mui/material';\nimport { LIcon } from '@s_mart/core';\nimport * as masks from '@s_mart/masks';\nimport { lineEye, lineEyeSlash, lineInfoCircle } from '@s_mart/solid-icons';\nimport { useRef, useState } from 'react';\nimport { type FieldPath, type FieldValues, useController, useFormContext, useFormState } from 'react-hook-form';\nimport { FieldError } from '../components/fieldError';\nimport { FieldLabel } from '../components/fieldLabel';\nimport { erroFieldFormatado } from '../utils/erroFieldFormatado';\nimport type { TextFieldProps } from './textField.types';\nimport { FormComponentPrecisaDeControl } from '../formComponentPrecisaDeControl';\nimport { typedMemo } from '../utils/typedMemo';\n\nconst TextField = ({\n // RHF\n name,\n rules,\n defaultValue,\n shouldUnregister,\n control: controlFromProps,\n // Component Props\n label,\n required,\n mask,\n variant = 'outlined',\n info,\n parse,\n format,\n onInputChange,\n disableIconError,\n ...rest\n}: TextFieldProps) => {\n const controlFromContext = useFormContext()?.control;\n\n const control = controlFromProps ?? controlFromContext;\n\n const previousValue = useRef<string | undefined>(defaultValue || undefined);\n\n if (!control) {\n throw new FormComponentPrecisaDeControl('TextField');\n }\n\n const [showPassword, setShowPassword] = useState(false);\n\n const _handleFormat = (value: string) => {\n let _value = value;\n\n _value = format?.(value) ?? value;\n\n if (mask) {\n return masks?.[mask]?.format(_value);\n }\n\n return _value;\n };\n\n const handleParse = (value: string) => {\n let _value = value;\n\n _value = parse?.(value) ?? _value;\n\n if (mask) {\n return masks?.[mask]?.parse(_value, previousValue.current);\n }\n return _value;\n };\n\n const onKeyDown = (event?: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>): void => {\n if (!event) return;\n\n if (mask !== 'porcentagem' && mask !== 'porcentagem0') {\n return;\n }\n\n event?.stopPropagation();\n\n const value = (event?.target as HTMLInputElement).value;\n\n if (value) {\n const str = String(value);\n\n if (str.length > 0) {\n const percentIndex = str.indexOf('%');\n\n if (percentIndex > -1) {\n event.currentTarget.selectionEnd = percentIndex;\n }\n }\n }\n };\n\n const { field } = useController({\n control,\n name,\n rules,\n defaultValue,\n shouldUnregister,\n });\n\n const formState = useFormState({ control, name });\n\n const formattedError = erroFieldFormatado(formState.errors, name);\n\n return (\n <Stack>\n <div style={{ display: 'flex' }}>\n {label && (\n <div>\n <FieldLabel label={label} required={required} />\n </div>\n )}\n {info && (\n <div>\n <Tooltip title={info} placement='top'>\n <div style={{ width: 'fit-content' }}>\n <LIcon icon={lineInfoCircle} color='#757575' />\n </div>\n </Tooltip>\n </div>\n )}\n </div>\n <TextFieldMui\n key={name}\n variant={variant}\n defaultValue={defaultValue}\n // biome-ignore lint/suspicious/noDoubleEquals: Comparamos com != pois pode ser que o valor seja '0' ou 0\n value={_handleFormat(field.value || (field.value != 0 ? '' : field.value))}\n onChange={(e) => {\n const parsedValue = handleParse(e?.target?.value);\n field.onChange(parsedValue);\n onInputChange?.(parsedValue);\n\n previousValue.current = e.target.value;\n }}\n error={Boolean(formattedError)}\n {...rest}\n type={rest.type === 'password' ? (showPassword ? 'text' : 'password') : rest.type}\n autoComplete={rest.autoComplete || 'off'}\n slotProps={{\n ...rest.slotProps,\n input: {\n onKeyDown,\n inputRef: field.ref,\n endAdornment: rest.type === 'password' && (\n <InputAdornment\n position='start'\n onClick={() => setShowPassword(!showPassword)}\n style={{ cursor: 'pointer' }}\n >\n <LIcon icon={showPassword ? lineEye : lineEyeSlash} size='24px' removeMargin />\n </InputAdornment>\n ),\n ...rest.slotProps?.input,\n },\n }}\n />\n <FieldError name={name} disableIcon={disableIconError} control={control} />\n </Stack>\n );\n};\n\nexport default typedMemo(TextField);\n"],"mappings":";;;;;;;;;;;;AAiKA,IAAA,IAAe,GApJI,EAEjB,SACA,UACA,iBACA,qBACA,SAAS,GAET,UACA,aACA,SACA,aAAU,YACV,SACA,UACA,WACA,kBACA,qBACA,GAAG,QACiB;CACpB,IAAM,IAAqB,EAAe,CAAC,EAAE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B,OAAM;KAAW,CAAA;IAC3C,CAAA;GACE,CAAA,EACN,CAAA,CAEJ;;EACL,kBAAC,GAAD;GAEW;GACK;GAEd,OAAO,EAAc,EAAM,UAAU,EAAM,SAAS,IAAS,EAAM,QAAX,GAAiB;GACzE,WAAW,MAAM;IACf,IAAM,IAAc,EAAY,GAAG,QAAQ,KAAK;IAIhD,AAHA,EAAM,SAAS,CAAW,GAC1B,IAAgB,CAAW,GAE3B,EAAc,UAAU,EAAE,OAAO;GACnC;GACA,OAAO,EAAQ;GACf,GAAI;GACJ,MAAM,EAAK,SAAS,aAAc,IAAe,SAAS,aAAc,EAAK;GAC7E,cAAc,EAAK,gBAAgB;GACnC,WAAW;IACT,GAAG,EAAK;IACR,OAAO;KACL;KACA,UAAU,EAAM;KAChB,cAAc,EAAK,SAAS,cAC1B,kBAAC,GAAD;MACE,UAAS;MACT,eAAe,EAAgB,CAAC,CAAY;MAC5C,OAAO,EAAE,QAAQ,UAAU;MAE3B,UAAA,kBAAC,GAAD;OAAO,MAAM,IAAe,IAAU;OAAc,MAAK;OAAO,cAAA;MAAc,CAAA;KAChE,CAAA;KAElB,GAAG,EAAK,WAAW;IACrB;GACF;EACD,GAjCM,CAiCN;EACD,kBAAC,GAAD;GAAkB;GAAM,aAAa;GAA2B;EAAU,CAAA;CACrE,EAAA,CAAA;AAEX,CAEkC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { erroFieldFormatado as e } from "../utils/erroFieldFormatado.mjs";
|
|
2
|
+
import t from "../components/fieldError/fieldError.mjs";
|
|
3
|
+
import n from "../components/fieldLabel/fieldLabel.mjs";
|
|
4
|
+
import { FormComponentPrecisaDeControl as r } from "../formComponentPrecisaDeControl.mjs";
|
|
5
|
+
import { typedMemo as i } from "../utils/typedMemo.mjs";
|
|
6
|
+
import { SIconButton as a } from "./timePicker.styles.mjs";
|
|
7
|
+
import { useController as o, useFormContext as s, useFormState as c } from "react-hook-form";
|
|
8
|
+
import { Stack as l } from "@mui/material";
|
|
9
|
+
import { jsx as u, jsxs as d } from "react/jsx-runtime";
|
|
10
|
+
import { composeValidators as f, time as p } from "@s_mart/rules";
|
|
11
|
+
import { AdapterDayjs as m } from "@mui/x-date-pickers/AdapterDayjs";
|
|
12
|
+
import { LocalizationProvider as h } from "@mui/x-date-pickers/LocalizationProvider";
|
|
13
|
+
import "dayjs/locale/pt-br";
|
|
14
|
+
import { TimePicker as g } from "@mui/x-date-pickers/TimePicker";
|
|
15
|
+
var _ = i(({ rules: i, defaultValue: _, shouldUnregister: v, name: y, control: b, required: x, label: S, disabled: C, disableIconError: w, size: T, ...E }) => {
|
|
16
|
+
let D = s()?.control, O = b ?? D;
|
|
17
|
+
if (!O) throw new r("TimePicker");
|
|
18
|
+
let k = c({
|
|
19
|
+
control: O,
|
|
20
|
+
name: y
|
|
21
|
+
}), A = e(k.errors, y), j = E.format || "HH:mm", M = i ? f([p(j), i]) : p(j), { field: N } = o({
|
|
22
|
+
control: O,
|
|
23
|
+
name: y,
|
|
24
|
+
rules: M,
|
|
25
|
+
defaultValue: _,
|
|
26
|
+
shouldUnregister: v
|
|
27
|
+
});
|
|
28
|
+
return /* @__PURE__ */ u(h, {
|
|
29
|
+
dateAdapter: m,
|
|
30
|
+
children: /* @__PURE__ */ d(l, { children: [
|
|
31
|
+
S && /* @__PURE__ */ u(n, {
|
|
32
|
+
label: S,
|
|
33
|
+
required: x
|
|
34
|
+
}),
|
|
35
|
+
/* @__PURE__ */ u(g, {
|
|
36
|
+
ampm: !1,
|
|
37
|
+
format: j,
|
|
38
|
+
value: N.value ?? null,
|
|
39
|
+
disabled: C,
|
|
40
|
+
...E,
|
|
41
|
+
onChange: (e, t) => {
|
|
42
|
+
N.onChange(e, t), E?.onChange?.(e, t);
|
|
43
|
+
},
|
|
44
|
+
slots: { openPickerButton: a },
|
|
45
|
+
slotProps: {
|
|
46
|
+
...E.slotProps,
|
|
47
|
+
textField: {
|
|
48
|
+
error: !!A,
|
|
49
|
+
size: T,
|
|
50
|
+
...E.slotProps?.textField,
|
|
51
|
+
slotProps: {
|
|
52
|
+
...E.slotProps?.textField?.slotProps,
|
|
53
|
+
input: {
|
|
54
|
+
...(E.slotProps?.textField)?.slotProps?.input,
|
|
55
|
+
inputRef: N.ref
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
actionBar: {
|
|
60
|
+
actions: [],
|
|
61
|
+
...E.slotProps?.actionBar
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}, y),
|
|
65
|
+
/* @__PURE__ */ u(t, {
|
|
66
|
+
name: y,
|
|
67
|
+
disableIcon: w,
|
|
68
|
+
control: O
|
|
69
|
+
})
|
|
70
|
+
] })
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
//#endregion
|
|
74
|
+
export { _ as default };
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=timePicker.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timePicker.mjs","names":[],"sources":["../../src/timePicker/timePicker.tsx"],"sourcesContent":["import { composeValidators, time } from '@s_mart/rules';\n\nimport { Stack } from '@mui/material';\nimport { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';\nimport { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';\nimport { TimePicker as TimePickerMui } from '@mui/x-date-pickers/TimePicker';\nimport { useController, useFormContext, useFormState } from 'react-hook-form';\n\nimport { FieldError } from '../components/fieldError';\nimport { FieldLabel } from '../components/fieldLabel';\nimport { FormComponentPrecisaDeControl } from '../formComponentPrecisaDeControl';\nimport { erroFieldFormatado } from '../utils/erroFieldFormatado';\nimport { typedMemo } from '../utils/typedMemo';\nimport { SIconButton } from './timePicker.styles';\nimport type { TimePickerProps } from './timePicker.types';\n\nimport 'dayjs/locale/pt-br';\n\nconst TimePicker = ({\n // RHF\n rules,\n defaultValue,\n shouldUnregister,\n name,\n control: controlFromProps,\n // Component Props\n required,\n label,\n disabled,\n disableIconError,\n size,\n ...rest\n}: TimePickerProps) => {\n const controlFromContext = useFormContext()?.control;\n\n const control = controlFromProps ?? controlFromContext;\n\n if (!control) {\n throw new FormComponentPrecisaDeControl('TimePicker');\n }\n\n const formState = useFormState({ control, name });\n\n const formattedError = erroFieldFormatado(formState.errors, name);\n\n const timeFormat = rest.format || 'HH:mm';\n const newRules = rules ? composeValidators([time(timeFormat), rules as any]) : time(timeFormat);\n\n const { field } = useController({\n control,\n name,\n rules: newRules,\n defaultValue,\n shouldUnregister,\n });\n\n return (\n <LocalizationProvider dateAdapter={AdapterDayjs}>\n <Stack>\n {label && <FieldLabel label={label} required={required} />}\n <TimePickerMui\n key={name}\n ampm={false}\n format={timeFormat}\n value={field.value ?? null}\n disabled={disabled}\n {...rest}\n onChange={(value, context) => {\n field.onChange(value, context);\n rest?.onChange?.(value, context);\n }}\n slots={{\n openPickerButton: SIconButton,\n }}\n slotProps={{\n ...rest.slotProps,\n textField: {\n error: Boolean(formattedError),\n size,\n ...rest.slotProps?.textField,\n slotProps: {\n ...(rest.slotProps?.textField as any)?.slotProps,\n input: {\n ...(rest.slotProps?.textField as any)?.slotProps?.input,\n inputRef: field.ref,\n },\n },\n },\n actionBar: {\n actions: [],\n ...rest.slotProps?.actionBar,\n },\n }}\n />\n <FieldError name={name} disableIcon={disableIconError} control={control} />\n </Stack>\n </LocalizationProvider>\n );\n};\n\nexport default typedMemo(TimePicker);\n"],"mappings":";;;;;;;;;;;;;;AAoGA,IAAA,IAAe,GAlFK,EAElB,UACA,iBACA,qBACA,SACA,SAAS,GAET,aACA,UACA,aACA,qBACA,SACA,GAAG,QACkB;CACrB,IAAM,IAAqB,EAAe,CAAC,EAAE,SAEvC,IAAU,KAAoB;CAEpC,IAAI,CAAC,GACH,MAAM,IAAI,EAA8B,YAAY;CAGtD,IAAM,IAAY,EAAa;EAAE;EAAS;CAAK,CAAC,GAE1C,IAAiB,EAAmB,EAAU,QAAQ,CAAI,GAE1D,IAAa,EAAK,UAAU,SAC5B,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