@pnkx-lib/ui 1.6.3 → 1.6.5

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.
@@ -150,4 +150,3 @@ const CheckboxField = (props) => {
150
150
  };
151
151
 
152
152
  export { CheckboxField as C, RadioGroup as R, Select as S };
153
- //# sourceMappingURL=Checkbox-CJ_M7IzZ.js.map
@@ -0,0 +1,156 @@
1
+ 'use strict';
2
+
3
+ const Switch = require('./Switch-03DUOS9f.js');
4
+ const antd = require('antd');
5
+
6
+ const Select = (props) => {
7
+ //! State
8
+ const {
9
+ field,
10
+ formState,
11
+ label,
12
+ required,
13
+ afterOnChange,
14
+ customStyleContainer,
15
+ ...restProps
16
+ } = props;
17
+ const { name, value, onChange, onBlur } = field || {};
18
+ const { touchedFields, errors, isSubmitted } = formState || {};
19
+ const isTouched = Switch.get(touchedFields, name);
20
+ const errorMessage = Switch.get(errors, name)?.message;
21
+ //! Function
22
+ const handleChange = (val) => {
23
+ onChange?.(val);
24
+ afterOnChange?.(val);
25
+ };
26
+ const renderErrorMessage = () => {
27
+ if (!errorMessage) return null;
28
+ return /* @__PURE__ */ Switch.jsxRuntimeExports.jsx(
29
+ Switch.ErrorMessage,
30
+ {
31
+ errorMessage,
32
+ isTouched,
33
+ isSubmitted
34
+ }
35
+ );
36
+ };
37
+ //! Render
38
+ return /* @__PURE__ */ Switch.jsxRuntimeExports.jsxs("div", { className: customStyleContainer, children: [
39
+ label && /* @__PURE__ */ Switch.jsxRuntimeExports.jsx(Switch.Label, { label, required }),
40
+ /* @__PURE__ */ Switch.jsxRuntimeExports.jsx(
41
+ antd.Select,
42
+ {
43
+ onChange: handleChange,
44
+ onBlur,
45
+ value,
46
+ style: { width: "100%" },
47
+ optionLabelProp: "label",
48
+ status: (isTouched || isSubmitted) && Boolean(errorMessage) ? "error" : void 0,
49
+ ...restProps
50
+ }
51
+ ),
52
+ renderErrorMessage()
53
+ ] });
54
+ };
55
+
56
+ const RadioGroup = (props) => {
57
+ //! State
58
+ const {
59
+ field,
60
+ formState,
61
+ customStyleRadio,
62
+ customStyleWrap = "",
63
+ afterOnChange,
64
+ options,
65
+ ...restProps
66
+ } = props;
67
+ const { name, value, onChange } = field || {};
68
+ const { touchedFields, errors, isSubmitted } = formState || {};
69
+ const isTouched = Switch.get(touchedFields, name);
70
+ const errorMessage = Switch.get(errors, name)?.message;
71
+ //! Function
72
+ const handleChange = (e) => {
73
+ onChange?.(e);
74
+ afterOnChange?.(e?.target?.value);
75
+ };
76
+ const renderErrorMessage = () => {
77
+ if (!errorMessage) return null;
78
+ return /* @__PURE__ */ Switch.jsxRuntimeExports.jsx(
79
+ Switch.ErrorMessage,
80
+ {
81
+ errorMessage,
82
+ isTouched,
83
+ isSubmitted
84
+ }
85
+ );
86
+ };
87
+ //! Render
88
+ return /* @__PURE__ */ Switch.jsxRuntimeExports.jsxs("div", { className: customStyleWrap, children: [
89
+ /* @__PURE__ */ Switch.jsxRuntimeExports.jsx(antd.Radio.Group, { onChange: handleChange, value, ...restProps, children: options.map((item) => /* @__PURE__ */ Switch.jsxRuntimeExports.jsx(
90
+ antd.Radio,
91
+ {
92
+ value: item.value,
93
+ className: customStyleRadio,
94
+ children: /* @__PURE__ */ Switch.jsxRuntimeExports.jsxs(Switch.Typography.Text, { children: [
95
+ " ",
96
+ item.label
97
+ ] })
98
+ },
99
+ `${name}-${item.value}`
100
+ )) }),
101
+ renderErrorMessage()
102
+ ] });
103
+ };
104
+
105
+ const CheckboxField = (props) => {
106
+ //! State
107
+ const {
108
+ field,
109
+ formState,
110
+ label,
111
+ afterOnChange,
112
+ customStyleContainer,
113
+ customStyleCheckbox,
114
+ ...restProps
115
+ } = props;
116
+ const { name, value, onChange, onBlur } = field || {};
117
+ const { touchedFields, errors, isSubmitted } = formState || {};
118
+ const isTouched = Switch.get(touchedFields, name);
119
+ const errorMessage = Switch.get(errors, name)?.message;
120
+ //! Function
121
+ const handleChange = (e) => {
122
+ const checked = e.target.checked;
123
+ onChange?.(checked);
124
+ afterOnChange?.(checked);
125
+ };
126
+ const renderErrorMessage = () => {
127
+ if (!errorMessage) return null;
128
+ return /* @__PURE__ */ Switch.jsxRuntimeExports.jsx(
129
+ Switch.ErrorMessage,
130
+ {
131
+ errorMessage,
132
+ isTouched,
133
+ isSubmitted
134
+ }
135
+ );
136
+ };
137
+ //! Render
138
+ return /* @__PURE__ */ Switch.jsxRuntimeExports.jsxs("div", { className: customStyleContainer, children: [
139
+ /* @__PURE__ */ Switch.jsxRuntimeExports.jsx(
140
+ antd.Checkbox,
141
+ {
142
+ onBlur,
143
+ checked: !!value,
144
+ onChange: handleChange,
145
+ className: customStyleCheckbox,
146
+ ...restProps,
147
+ children: /* @__PURE__ */ Switch.jsxRuntimeExports.jsx(Switch.Typography.Text, { children: label })
148
+ }
149
+ ),
150
+ renderErrorMessage()
151
+ ] });
152
+ };
153
+
154
+ exports.CheckboxField = CheckboxField;
155
+ exports.RadioGroup = RadioGroup;
156
+ exports.Select = Select;