@arkyn/components 1.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/bundle.js +1348 -0
- package/dist/bundle.umd.cjs +32 -0
- package/dist/components/Badge/index.d.ts +5 -0
- package/dist/components/Badge/index.d.ts.map +1 -0
- package/dist/components/Badge/index.js +8 -0
- package/dist/components/Breadcrumb/index.d.ts +6 -0
- package/dist/components/Breadcrumb/index.d.ts.map +1 -0
- package/dist/components/Breadcrumb/index.js +18 -0
- package/dist/components/Button/index.d.ts +5 -0
- package/dist/components/Button/index.d.ts.map +1 -0
- package/dist/components/Button/index.js +9 -0
- package/dist/components/Divider/index.d.ts +5 -0
- package/dist/components/Divider/index.d.ts.map +1 -0
- package/dist/components/Divider/index.js +8 -0
- package/dist/components/Form/FormController/index.d.ts +6 -0
- package/dist/components/Form/FormController/index.d.ts.map +1 -0
- package/dist/components/Form/FormController/index.js +17 -0
- package/dist/components/Form/FormError/index.d.ts +4 -0
- package/dist/components/Form/FormError/index.d.ts.map +1 -0
- package/dist/components/Form/FormError/index.js +10 -0
- package/dist/components/Form/FormLabel/index.d.ts +5 -0
- package/dist/components/Form/FormLabel/index.d.ts.map +1 -0
- package/dist/components/Form/FormLabel/index.js +9 -0
- package/dist/components/Form/index.d.ts +4 -0
- package/dist/components/Form/index.d.ts.map +1 -0
- package/dist/components/Form/index.js +3 -0
- package/dist/components/IconButton/index.d.ts +5 -0
- package/dist/components/IconButton/index.d.ts.map +1 -0
- package/dist/components/IconButton/index.js +15 -0
- package/dist/components/Input/CpfCpnjInput/getConfig.d.ts +308 -0
- package/dist/components/Input/CpfCpnjInput/getConfig.d.ts.map +1 -0
- package/dist/components/Input/CpfCpnjInput/getConfig.js +35 -0
- package/dist/components/Input/CpfCpnjInput/index.d.ts +4 -0
- package/dist/components/Input/CpfCpnjInput/index.d.ts.map +1 -0
- package/dist/components/Input/CpfCpnjInput/index.js +47 -0
- package/dist/components/Input/CpfCpnjInput/utils.d.ts +10 -0
- package/dist/components/Input/CpfCpnjInput/utils.d.ts.map +1 -0
- package/dist/components/Input/CpfCpnjInput/utils.js +24 -0
- package/dist/components/Input/CurrencyInput/getConfig.d.ts +309 -0
- package/dist/components/Input/CurrencyInput/getConfig.d.ts.map +1 -0
- package/dist/components/Input/CurrencyInput/getConfig.js +37 -0
- package/dist/components/Input/CurrencyInput/index.d.ts +4 -0
- package/dist/components/Input/CurrencyInput/index.d.ts.map +1 -0
- package/dist/components/Input/CurrencyInput/index.js +41 -0
- package/dist/components/Input/CurrencyInput/utils.d.ts +11 -0
- package/dist/components/Input/CurrencyInput/utils.d.ts.map +1 -0
- package/dist/components/Input/CurrencyInput/utils.js +39 -0
- package/dist/components/Input/MaskInput/getConfig.d.ts +312 -0
- package/dist/components/Input/MaskInput/getConfig.d.ts.map +1 -0
- package/dist/components/Input/MaskInput/getConfig.js +36 -0
- package/dist/components/Input/MaskInput/index.d.ts +4 -0
- package/dist/components/Input/MaskInput/index.d.ts.map +1 -0
- package/dist/components/Input/MaskInput/index.js +42 -0
- package/dist/components/Input/SimpleInput/getConfig.d.ts +308 -0
- package/dist/components/Input/SimpleInput/getConfig.d.ts.map +1 -0
- package/dist/components/Input/SimpleInput/getConfig.js +35 -0
- package/dist/components/Input/SimpleInput/index.d.ts +4 -0
- package/dist/components/Input/SimpleInput/index.d.ts.map +1 -0
- package/dist/components/Input/SimpleInput/index.js +34 -0
- package/dist/components/Input/index.d.ts +5 -0
- package/dist/components/Input/index.d.ts.map +1 -0
- package/dist/components/Input/index.js +16 -0
- package/dist/components/Input/utils/morpheme.d.ts +4 -0
- package/dist/components/Input/utils/morpheme.d.ts.map +1 -0
- package/dist/components/Input/utils/morpheme.js +10 -0
- package/dist/components/Modal/Container/index.d.ts +10 -0
- package/dist/components/Modal/Container/index.d.ts.map +1 -0
- package/dist/components/Modal/Container/index.js +12 -0
- package/dist/components/Modal/Footer/index.d.ts +5 -0
- package/dist/components/Modal/Footer/index.d.ts.map +1 -0
- package/dist/components/Modal/Footer/index.js +8 -0
- package/dist/components/Modal/Header/index.d.ts +5 -0
- package/dist/components/Modal/Header/index.d.ts.map +1 -0
- package/dist/components/Modal/Header/index.js +13 -0
- package/dist/components/Modal/index.d.ts +9 -0
- package/dist/components/Modal/index.d.ts.map +1 -0
- package/dist/components/Modal/index.js +4 -0
- package/dist/components/Tooltip/index.d.ts +5 -0
- package/dist/components/Tooltip/index.d.ts.map +1 -0
- package/dist/components/Tooltip/index.js +7 -0
- package/dist/config/buildBadgeConfig.d.ts +274 -0
- package/dist/config/buildBadgeConfig.d.ts.map +1 -0
- package/dist/config/buildBadgeConfig.js +15 -0
- package/dist/config/buildBreadcrumLinkConfig.d.ts +288 -0
- package/dist/config/buildBreadcrumLinkConfig.d.ts.map +1 -0
- package/dist/config/buildBreadcrumLinkConfig.js +14 -0
- package/dist/config/buildBreadcrumbConfig.d.ts +272 -0
- package/dist/config/buildBreadcrumbConfig.d.ts.map +1 -0
- package/dist/config/buildBreadcrumbConfig.js +6 -0
- package/dist/config/buildButtonConfig.d.ts +286 -0
- package/dist/config/buildButtonConfig.d.ts.map +1 -0
- package/dist/config/buildButtonConfig.js +18 -0
- package/dist/config/buildFormLabelConfig.d.ts +274 -0
- package/dist/config/buildFormLabelConfig.d.ts.map +1 -0
- package/dist/config/buildFormLabelConfig.js +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/style.css +1 -0
- package/dist/utils/generateIcon.d.ts +4 -0
- package/dist/utils/generateIcon.d.ts.map +1 -0
- package/dist/utils/generateIcon.js +7 -0
- package/package.json +30 -0
- package/src/components/Badge/index.tsx +18 -0
- package/src/components/Badge/styles.css +119 -0
- package/src/components/Breadcrumb/index.tsx +35 -0
- package/src/components/Breadcrumb/styles.css +39 -0
- package/src/components/Button/index.tsx +27 -0
- package/src/components/Button/styles.css +363 -0
- package/src/components/Divider/index.tsx +17 -0
- package/src/components/Divider/styles.css +17 -0
- package/src/components/Form/FormController/index.tsx +36 -0
- package/src/components/Form/FormController/styles.css +5 -0
- package/src/components/Form/FormError/index.tsx +11 -0
- package/src/components/Form/FormError/styles.css +6 -0
- package/src/components/Form/FormLabel/index.tsx +13 -0
- package/src/components/Form/FormLabel/styles.css +15 -0
- package/src/components/Form/index.ts +3 -0
- package/src/components/IconButton/index.tsx +44 -0
- package/src/components/IconButton/styles.css +318 -0
- package/src/components/Input/CpfCpnjInput/getConfig.tsx +60 -0
- package/src/components/Input/CpfCpnjInput/index.tsx +112 -0
- package/src/components/Input/CpfCpnjInput/utils.ts +30 -0
- package/src/components/Input/CurrencyInput/getConfig.tsx +64 -0
- package/src/components/Input/CurrencyInput/index.tsx +103 -0
- package/src/components/Input/CurrencyInput/utils.ts +56 -0
- package/src/components/Input/MaskInput/getConfig.tsx +62 -0
- package/src/components/Input/MaskInput/index.tsx +89 -0
- package/src/components/Input/SimpleInput/getConfig.tsx +60 -0
- package/src/components/Input/SimpleInput/index.tsx +87 -0
- package/src/components/Input/index.tsx +17 -0
- package/src/components/Input/styles.css +223 -0
- package/src/components/Input/utils/morpheme.tsx +19 -0
- package/src/components/Modal/Container/index.tsx +53 -0
- package/src/components/Modal/Container/styles.css +35 -0
- package/src/components/Modal/Footer/index.tsx +12 -0
- package/src/components/Modal/Footer/styles.css +27 -0
- package/src/components/Modal/Header/index.tsx +26 -0
- package/src/components/Modal/Header/styles.css +36 -0
- package/src/components/Modal/index.ts +5 -0
- package/src/components/Tooltip/index.tsx +26 -0
- package/src/components/Tooltip/styles.css +112 -0
- package/src/config/buildBadgeConfig.tsx +32 -0
- package/src/config/buildBreadcrumLinkConfig.tsx +27 -0
- package/src/config/buildBreadcrumbConfig.tsx +12 -0
- package/src/config/buildButtonConfig.tsx +38 -0
- package/src/config/buildFormLabelConfig.tsx +17 -0
- package/src/index.ts +16 -0
- package/src/utils/generateIcon.tsx +9 -0
- package/tsconfig.json +23 -0
- package/vite.config.js +25 -0
@@ -0,0 +1,318 @@
|
|
1
|
+
/* BASE */
|
2
|
+
|
3
|
+
.arkyn_icon_button {
|
4
|
+
background: transparent;
|
5
|
+
border: 1px solid transparent;
|
6
|
+
outline: 1px solid transparent;
|
7
|
+
position: relative;
|
8
|
+
transition: 0.15s all ease-out;
|
9
|
+
}
|
10
|
+
|
11
|
+
.arkyn_icon_button:hover {
|
12
|
+
cursor: pointer;
|
13
|
+
}
|
14
|
+
|
15
|
+
.arkyn_icon_button:disabled {
|
16
|
+
cursor: not-allowed;
|
17
|
+
opacity: 0.5;
|
18
|
+
}
|
19
|
+
|
20
|
+
.arkyn_icon_button .content {
|
21
|
+
display: flex;
|
22
|
+
align-items: center;
|
23
|
+
justify-content: center;
|
24
|
+
}
|
25
|
+
|
26
|
+
/* VARIANTS */
|
27
|
+
.arkyn_icon_button.solid {
|
28
|
+
color: #fff;
|
29
|
+
}
|
30
|
+
|
31
|
+
.arkyn_icon_button.solid:disabled {
|
32
|
+
opacity: 0.4;
|
33
|
+
}
|
34
|
+
|
35
|
+
.arkyn_icon_button.solid.primary {
|
36
|
+
background-color: var(--primary-500);
|
37
|
+
}
|
38
|
+
|
39
|
+
.arkyn_icon_button.solid.primary:hover {
|
40
|
+
background-color: var(--primary-400);
|
41
|
+
}
|
42
|
+
|
43
|
+
.arkyn_icon_button.solid.primary:disabled {
|
44
|
+
background-color: var(--primary-400);
|
45
|
+
}
|
46
|
+
|
47
|
+
.arkyn_icon_button.solid.danger {
|
48
|
+
background-color: var(--danger-600);
|
49
|
+
}
|
50
|
+
|
51
|
+
.arkyn_icon_button.solid.danger:hover {
|
52
|
+
background-color: var(--danger-500);
|
53
|
+
}
|
54
|
+
|
55
|
+
.arkyn_icon_button.solid.danger:disabled {
|
56
|
+
background-color: var(--danger-500);
|
57
|
+
}
|
58
|
+
|
59
|
+
.arkyn_icon_button.solid.success {
|
60
|
+
background-color: var(--success-500);
|
61
|
+
}
|
62
|
+
|
63
|
+
.arkyn_icon_button.solid.success:hover {
|
64
|
+
background-color: var(--success-400);
|
65
|
+
}
|
66
|
+
|
67
|
+
.arkyn_icon_button.solid.success:disabled {
|
68
|
+
background-color: var(--success-400);
|
69
|
+
}
|
70
|
+
|
71
|
+
.arkyn_icon_button.solid.warning {
|
72
|
+
background-color: var(--warning-600);
|
73
|
+
}
|
74
|
+
|
75
|
+
.arkyn_icon_button.solid.warning:hover {
|
76
|
+
background-color: var(--warning-500);
|
77
|
+
}
|
78
|
+
|
79
|
+
.arkyn_icon_button.solid.warning:disabled {
|
80
|
+
background-color: var(--warning-500);
|
81
|
+
}
|
82
|
+
|
83
|
+
.arkyn_icon_button.outline {
|
84
|
+
border-color: var(--secondary-300);
|
85
|
+
}
|
86
|
+
|
87
|
+
.arkyn_icon_button.outline:hover {
|
88
|
+
border-color: var(--secondary-200);
|
89
|
+
}
|
90
|
+
|
91
|
+
.arkyn_icon_button.outline:disabled {
|
92
|
+
border-color: var(--secondary-200);
|
93
|
+
}
|
94
|
+
|
95
|
+
.arkyn_icon_button.outline.primary {
|
96
|
+
color: var(--primary-500);
|
97
|
+
}
|
98
|
+
|
99
|
+
.arkyn_icon_button.outline.primary:hover {
|
100
|
+
color: var(--primary-400);
|
101
|
+
}
|
102
|
+
|
103
|
+
.arkyn_icon_button.outline.primary:disabled {
|
104
|
+
color: var(--primary-400);
|
105
|
+
}
|
106
|
+
|
107
|
+
.arkyn_icon_button.outline.danger {
|
108
|
+
color: var(--danger-600);
|
109
|
+
}
|
110
|
+
|
111
|
+
.arkyn_icon_button.outline.danger:hover {
|
112
|
+
color: var(--danger-500);
|
113
|
+
}
|
114
|
+
|
115
|
+
.arkyn_icon_button.outline.danger:disabled {
|
116
|
+
color: var(--danger-500);
|
117
|
+
}
|
118
|
+
|
119
|
+
.arkyn_icon_button.outline.success {
|
120
|
+
color: var(--success-500);
|
121
|
+
}
|
122
|
+
|
123
|
+
.arkyn_icon_button.outline.success:hover {
|
124
|
+
color: var(--success-400);
|
125
|
+
}
|
126
|
+
|
127
|
+
.arkyn_icon_button.outline.success:disabled {
|
128
|
+
color: var(--success-400);
|
129
|
+
}
|
130
|
+
|
131
|
+
.arkyn_icon_button.outline.warning {
|
132
|
+
color: var(--warning-600);
|
133
|
+
}
|
134
|
+
|
135
|
+
.arkyn_icon_button.outline.warning:hover {
|
136
|
+
color: var(--warning-500);
|
137
|
+
}
|
138
|
+
|
139
|
+
.arkyn_icon_button.outline.warning:disabled {
|
140
|
+
color: var(--warning-500);
|
141
|
+
}
|
142
|
+
|
143
|
+
.arkyn_icon_button.ghost:disabled {
|
144
|
+
opacity: 0.4;
|
145
|
+
}
|
146
|
+
|
147
|
+
.arkyn_icon_button.ghost.primary {
|
148
|
+
color: var(--primary-500);
|
149
|
+
background-color: var(--primary-100);
|
150
|
+
}
|
151
|
+
|
152
|
+
.arkyn_icon_button.ghost.primary:hover {
|
153
|
+
color: var(--primary-400);
|
154
|
+
background-color: var(--primary-50);
|
155
|
+
}
|
156
|
+
|
157
|
+
.arkyn_icon_button.ghost.primary:disabled {
|
158
|
+
color: var(--primary-400);
|
159
|
+
background-color: var(--primary-50);
|
160
|
+
}
|
161
|
+
|
162
|
+
.arkyn_icon_button.ghost.danger {
|
163
|
+
color: var(--danger-600);
|
164
|
+
background-color: var(--danger-100);
|
165
|
+
}
|
166
|
+
|
167
|
+
.arkyn_icon_button.ghost.danger:hover {
|
168
|
+
color: var(--danger-500);
|
169
|
+
background-color: var(--danger-50);
|
170
|
+
}
|
171
|
+
|
172
|
+
.arkyn_icon_button.ghost.danger:disabled {
|
173
|
+
color: var(--danger-500);
|
174
|
+
background-color: var(--danger-50);
|
175
|
+
}
|
176
|
+
|
177
|
+
.arkyn_icon_button.ghost.success {
|
178
|
+
color: var(--success-500);
|
179
|
+
background-color: var(--success-100);
|
180
|
+
}
|
181
|
+
|
182
|
+
.arkyn_icon_button.ghost.success:hover {
|
183
|
+
color: var(--success-400);
|
184
|
+
background-color: var(--success-50);
|
185
|
+
}
|
186
|
+
|
187
|
+
.arkyn_icon_button.ghost.success:disabled {
|
188
|
+
color: var(--success-400);
|
189
|
+
background-color: var(--success-50);
|
190
|
+
}
|
191
|
+
|
192
|
+
.arkyn_icon_button.ghost.warning {
|
193
|
+
color: var(--warning-600);
|
194
|
+
background-color: var(--warning-100);
|
195
|
+
}
|
196
|
+
|
197
|
+
.arkyn_icon_button.ghost.warning:hover {
|
198
|
+
color: var(--warning-500);
|
199
|
+
background-color: var(--warning-50);
|
200
|
+
}
|
201
|
+
|
202
|
+
.arkyn_icon_button.ghost.warning:disabled {
|
203
|
+
color: var(--warning-500);
|
204
|
+
background-color: var(--warning-50);
|
205
|
+
}
|
206
|
+
|
207
|
+
.arkyn_icon_button.invisible:disabled {
|
208
|
+
opacity: 0.4;
|
209
|
+
}
|
210
|
+
|
211
|
+
.arkyn_icon_button.invisible.primary {
|
212
|
+
color: var(--primary-500);
|
213
|
+
}
|
214
|
+
|
215
|
+
.arkyn_icon_button.invisible.primary:hover {
|
216
|
+
color: var(--primary-400);
|
217
|
+
}
|
218
|
+
|
219
|
+
.arkyn_icon_button.invisible.primary:disabled {
|
220
|
+
color: var(--primary-400);
|
221
|
+
}
|
222
|
+
|
223
|
+
.arkyn_icon_button.invisible.danger {
|
224
|
+
color: var(--danger-600);
|
225
|
+
}
|
226
|
+
|
227
|
+
.arkyn_icon_button.invisible.danger:hover {
|
228
|
+
color: var(--danger-500);
|
229
|
+
}
|
230
|
+
|
231
|
+
.arkyn_icon_button.invisible.danger:disabled {
|
232
|
+
color: var(--danger-500);
|
233
|
+
}
|
234
|
+
|
235
|
+
.arkyn_icon_button.invisible.success {
|
236
|
+
color: var(--success-500);
|
237
|
+
}
|
238
|
+
|
239
|
+
.arkyn_icon_button.invisible.success:hover {
|
240
|
+
color: var(--success-400);
|
241
|
+
}
|
242
|
+
|
243
|
+
.arkyn_icon_button.invisible.success:disabled {
|
244
|
+
color: var(--success-400);
|
245
|
+
}
|
246
|
+
|
247
|
+
.arkyn_icon_button.invisible.warning {
|
248
|
+
color: var(--warning-600);
|
249
|
+
}
|
250
|
+
|
251
|
+
.arkyn_icon_button.invisible.warning:hover {
|
252
|
+
color: var(--warning-500);
|
253
|
+
}
|
254
|
+
|
255
|
+
.arkyn_icon_button.invisible.warning:disabled {
|
256
|
+
color: var(--warning-500);
|
257
|
+
}
|
258
|
+
|
259
|
+
/* SIZE */
|
260
|
+
|
261
|
+
.arkyn_icon_button.lg {
|
262
|
+
border-radius: 6px;
|
263
|
+
height: 44px;
|
264
|
+
width: 44px;
|
265
|
+
}
|
266
|
+
|
267
|
+
.arkyn_icon_button.md {
|
268
|
+
border-radius: 6px;
|
269
|
+
height: 40px;
|
270
|
+
width: 40px;
|
271
|
+
}
|
272
|
+
|
273
|
+
.arkyn_icon_button.sm {
|
274
|
+
border-radius: 6px;
|
275
|
+
height: 32px;
|
276
|
+
width: 32px;
|
277
|
+
}
|
278
|
+
|
279
|
+
.arkyn_icon_button.xs {
|
280
|
+
border-radius: 4px;
|
281
|
+
height: 24px;
|
282
|
+
width: 24px;
|
283
|
+
}
|
284
|
+
|
285
|
+
/* SPIN */
|
286
|
+
|
287
|
+
.arkyn_icon_button .spinner {
|
288
|
+
display: flex;
|
289
|
+
align-items: center;
|
290
|
+
justify-content: center;
|
291
|
+
|
292
|
+
position: absolute;
|
293
|
+
left: 50%;
|
294
|
+
top: 50%;
|
295
|
+
transform: translate(-50%, -50%);
|
296
|
+
opacity: 0;
|
297
|
+
}
|
298
|
+
|
299
|
+
.arkyn_icon_button .spinner svg {
|
300
|
+
animation: spin 2s linear infinite;
|
301
|
+
}
|
302
|
+
|
303
|
+
.arkyn_icon_button.loading_true .content {
|
304
|
+
opacity: 0;
|
305
|
+
}
|
306
|
+
|
307
|
+
.arkyn_icon_button.loading_true .spinner {
|
308
|
+
opacity: 1;
|
309
|
+
}
|
310
|
+
|
311
|
+
@keyframes spin {
|
312
|
+
from {
|
313
|
+
transform: rotate(0deg);
|
314
|
+
}
|
315
|
+
to {
|
316
|
+
transform: rotate(360deg);
|
317
|
+
}
|
318
|
+
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import type { CpfCnpjInputProps } from "@arkyn/types";
|
2
|
+
import { Loader2 } from "lucide-react";
|
3
|
+
|
4
|
+
import { morpheme } from "../utils/morpheme";
|
5
|
+
|
6
|
+
function getConfig(props: CpfCnpjInputProps, isFocused: boolean) {
|
7
|
+
const {
|
8
|
+
isLoading,
|
9
|
+
isError,
|
10
|
+
size = "md",
|
11
|
+
className: baseClassName = "",
|
12
|
+
variant = "solid",
|
13
|
+
prefix: basePrefix,
|
14
|
+
sufix: baseSufix,
|
15
|
+
leftIcon: LeftIcon,
|
16
|
+
rightIcon: RightIcon,
|
17
|
+
disabled,
|
18
|
+
readOnly,
|
19
|
+
onFocus,
|
20
|
+
onBlur,
|
21
|
+
title,
|
22
|
+
style,
|
23
|
+
onChange,
|
24
|
+
...rest
|
25
|
+
} = props;
|
26
|
+
|
27
|
+
const loadingPosition = RightIcon ? "right" : "left";
|
28
|
+
|
29
|
+
const hasPrefix = !!basePrefix ? "hasPrefix" : "";
|
30
|
+
const hasSufix = !!baseSufix ? "hasSufix" : "";
|
31
|
+
const errored = isError ? "errored" : "";
|
32
|
+
const opacity = disabled || readOnly || isLoading ? "opacity" : "";
|
33
|
+
const focused = isFocused ? "focused" : "";
|
34
|
+
|
35
|
+
const className = `arkyn_input ${hasPrefix} ${hasSufix} ${variant} ${size} ${opacity} ${errored} ${focused} ${baseClassName}`;
|
36
|
+
const iconSizes = { md: 14, lg: 16 };
|
37
|
+
const iconSize = iconSizes[size];
|
38
|
+
|
39
|
+
return {
|
40
|
+
isLoading,
|
41
|
+
className,
|
42
|
+
prefix: morpheme(basePrefix, iconSize, "prefix"),
|
43
|
+
sufix: morpheme(baseSufix, iconSize, "sufix"),
|
44
|
+
LeftIcon,
|
45
|
+
RightIcon,
|
46
|
+
disabled,
|
47
|
+
readOnly,
|
48
|
+
onFocus,
|
49
|
+
onBlur,
|
50
|
+
title,
|
51
|
+
style,
|
52
|
+
onChange,
|
53
|
+
loadingPosition,
|
54
|
+
iconSize: iconSize,
|
55
|
+
Spinner: <Loader2 className="spinner" size={iconSize} strokeWidth={2.5} />,
|
56
|
+
...rest,
|
57
|
+
};
|
58
|
+
}
|
59
|
+
|
60
|
+
export { getConfig };
|
@@ -0,0 +1,112 @@
|
|
1
|
+
import type { CpfCnpjInputProps } from "@arkyn/types";
|
2
|
+
import type { ChangeEvent, FocusEvent } from "react";
|
3
|
+
|
4
|
+
import { useRef, useState } from "react";
|
5
|
+
|
6
|
+
import { useFormController } from "../../Form/FormController";
|
7
|
+
import { getConfig } from "./getConfig";
|
8
|
+
import { MAX_LENGTH, TYPES, applyMask, clear, getMask } from "./utils";
|
9
|
+
|
10
|
+
function CpfCnpjInput(props: CpfCnpjInputProps) {
|
11
|
+
const [isFocused, setIsFocused] = useState(false);
|
12
|
+
const [inputValue, setInputValue] = useState(
|
13
|
+
clear(props?.defaultValue || "")
|
14
|
+
);
|
15
|
+
|
16
|
+
const baseRef = useRef<HTMLInputElement>(null);
|
17
|
+
|
18
|
+
const { inputRef, id, error } = useFormController();
|
19
|
+
|
20
|
+
const ref = inputRef || baseRef;
|
21
|
+
const isError = props.isError || !!error;
|
22
|
+
|
23
|
+
const {
|
24
|
+
disabled,
|
25
|
+
title,
|
26
|
+
style,
|
27
|
+
className,
|
28
|
+
prefix,
|
29
|
+
sufix,
|
30
|
+
iconSize,
|
31
|
+
loadingPosition,
|
32
|
+
isLoading,
|
33
|
+
LeftIcon,
|
34
|
+
readOnly,
|
35
|
+
onFocus,
|
36
|
+
onBlur,
|
37
|
+
RightIcon,
|
38
|
+
Spinner,
|
39
|
+
onChange,
|
40
|
+
value,
|
41
|
+
defaultValue = "",
|
42
|
+
...rest
|
43
|
+
} = getConfig({ ...props, id, isError }, isFocused);
|
44
|
+
|
45
|
+
const showLeftIcon = LeftIcon && !isLoading;
|
46
|
+
const showRightIcon = RightIcon && !isLoading;
|
47
|
+
|
48
|
+
const showLeftSpinner = loadingPosition === "left" && isLoading;
|
49
|
+
const showRightSpinner = loadingPosition === "right" && isLoading;
|
50
|
+
|
51
|
+
function handleSectionClick() {
|
52
|
+
if (disabled || !ref?.current) return;
|
53
|
+
setIsFocused(true);
|
54
|
+
ref.current.focus();
|
55
|
+
}
|
56
|
+
|
57
|
+
function handleChange(event: ChangeEvent<HTMLInputElement>) {
|
58
|
+
let value = clear(event.target.value);
|
59
|
+
const mask = getMask(value);
|
60
|
+
|
61
|
+
let nextLength = value.length;
|
62
|
+
|
63
|
+
if (nextLength > MAX_LENGTH) return;
|
64
|
+
|
65
|
+
value = applyMask(value, TYPES[mask] as "CPF" | "CNPJ");
|
66
|
+
|
67
|
+
event.target.value = value;
|
68
|
+
|
69
|
+
setInputValue(value);
|
70
|
+
onChange && onChange(event);
|
71
|
+
}
|
72
|
+
|
73
|
+
function handleFocus(e: FocusEvent<HTMLInputElement>) {
|
74
|
+
setIsFocused(true);
|
75
|
+
if (onFocus) onFocus(e);
|
76
|
+
}
|
77
|
+
|
78
|
+
function handleBlur(e: FocusEvent<HTMLInputElement>) {
|
79
|
+
setIsFocused(false);
|
80
|
+
if (onBlur) onBlur(e);
|
81
|
+
}
|
82
|
+
|
83
|
+
return (
|
84
|
+
<section
|
85
|
+
title={title}
|
86
|
+
style={style}
|
87
|
+
onClick={handleSectionClick}
|
88
|
+
className={className}
|
89
|
+
>
|
90
|
+
{prefix}
|
91
|
+
{showLeftSpinner && Spinner}
|
92
|
+
{showLeftIcon && <LeftIcon size={iconSize} strokeWidth={2.5} />}
|
93
|
+
|
94
|
+
<input
|
95
|
+
disabled={disabled || isLoading}
|
96
|
+
readOnly={readOnly}
|
97
|
+
ref={ref}
|
98
|
+
value={value || inputValue}
|
99
|
+
onFocus={handleFocus}
|
100
|
+
onChange={handleChange}
|
101
|
+
onBlur={handleBlur}
|
102
|
+
{...rest}
|
103
|
+
/>
|
104
|
+
|
105
|
+
{showRightIcon && <RightIcon size={iconSize} strokeWidth={2.5} />}
|
106
|
+
{showRightSpinner && Spinner}
|
107
|
+
{sufix}
|
108
|
+
</section>
|
109
|
+
);
|
110
|
+
}
|
111
|
+
|
112
|
+
export { CpfCnpjInput };
|
@@ -0,0 +1,30 @@
|
|
1
|
+
function clear(value: string) {
|
2
|
+
return value && value.replace(/[^0-9]/g, "");
|
3
|
+
}
|
4
|
+
|
5
|
+
function applyMask(value: string, mask: "CPF" | "CNPJ") {
|
6
|
+
let result = "";
|
7
|
+
|
8
|
+
let inc = 0;
|
9
|
+
Array.from(value).forEach((letter, index) => {
|
10
|
+
if (!mask[index + inc].match(/[0-9]/)) {
|
11
|
+
result += mask[index + inc];
|
12
|
+
inc++;
|
13
|
+
}
|
14
|
+
result += letter;
|
15
|
+
});
|
16
|
+
return result;
|
17
|
+
}
|
18
|
+
|
19
|
+
function getMask(value: string): "CNPJ" | "CPF" {
|
20
|
+
return value.length > 11 ? "CNPJ" : "CPF";
|
21
|
+
}
|
22
|
+
|
23
|
+
const TYPES = {
|
24
|
+
CPF: "999.999.999-999",
|
25
|
+
CNPJ: "99.999.999/9999-99",
|
26
|
+
};
|
27
|
+
|
28
|
+
const MAX_LENGTH = clear(TYPES.CNPJ).length;
|
29
|
+
|
30
|
+
export { clear, applyMask, MAX_LENGTH, TYPES, getMask };
|
@@ -0,0 +1,64 @@
|
|
1
|
+
import type { CurrencyInputProps } from "@arkyn/types";
|
2
|
+
import { Loader2 } from "lucide-react";
|
3
|
+
|
4
|
+
import { morpheme } from "../utils/morpheme";
|
5
|
+
|
6
|
+
function getConfig(props: CurrencyInputProps, isFocused: boolean) {
|
7
|
+
const {
|
8
|
+
isLoading,
|
9
|
+
isError,
|
10
|
+
size = "md",
|
11
|
+
className: baseClassName = "",
|
12
|
+
variant = "solid",
|
13
|
+
prefix: basePrefix,
|
14
|
+
sufix: baseSufix,
|
15
|
+
leftIcon: LeftIcon,
|
16
|
+
rightIcon: RightIcon,
|
17
|
+
disabled,
|
18
|
+
readOnly,
|
19
|
+
onFocus,
|
20
|
+
onBlur,
|
21
|
+
title,
|
22
|
+
style,
|
23
|
+
showCents = false,
|
24
|
+
max = 1000000000,
|
25
|
+
onChange,
|
26
|
+
...rest
|
27
|
+
} = props;
|
28
|
+
|
29
|
+
const loadingPosition = RightIcon ? "right" : "left";
|
30
|
+
|
31
|
+
const hasPrefix = !!basePrefix ? "hasPrefix" : "";
|
32
|
+
const hasSufix = !!baseSufix ? "hasSufix" : "";
|
33
|
+
const errored = isError ? "errored" : "";
|
34
|
+
const opacity = disabled || readOnly || isLoading ? "opacity" : "";
|
35
|
+
const focused = isFocused ? "focused" : "";
|
36
|
+
|
37
|
+
const className = `arkyn_input ${hasPrefix} ${hasSufix} ${variant} ${size} ${opacity} ${errored} ${focused} ${baseClassName}`;
|
38
|
+
const iconSizes = { md: 14, lg: 16 };
|
39
|
+
const iconSize = iconSizes[size];
|
40
|
+
|
41
|
+
return {
|
42
|
+
isLoading,
|
43
|
+
className,
|
44
|
+
prefix: morpheme(basePrefix, iconSize, "prefix"),
|
45
|
+
sufix: morpheme(baseSufix, iconSize, "sufix"),
|
46
|
+
LeftIcon,
|
47
|
+
RightIcon,
|
48
|
+
disabled,
|
49
|
+
readOnly,
|
50
|
+
onFocus,
|
51
|
+
onBlur,
|
52
|
+
title,
|
53
|
+
style,
|
54
|
+
max,
|
55
|
+
onChange,
|
56
|
+
showCents,
|
57
|
+
loadingPosition,
|
58
|
+
iconSize: iconSize,
|
59
|
+
Spinner: <Loader2 className="spinner" size={iconSize} strokeWidth={2.5} />,
|
60
|
+
...rest,
|
61
|
+
};
|
62
|
+
}
|
63
|
+
|
64
|
+
export { getConfig };
|
@@ -0,0 +1,103 @@
|
|
1
|
+
import type { CurrencyInputProps } from "@arkyn/types";
|
2
|
+
import type { FocusEvent, KeyboardEvent } from "react";
|
3
|
+
|
4
|
+
import { useRef, useState } from "react";
|
5
|
+
|
6
|
+
import { useFormController } from "../../Form/FormController";
|
7
|
+
import { getConfig } from "./getConfig";
|
8
|
+
import { currencyInputKeyDown, valueDisplay } from "./utils";
|
9
|
+
|
10
|
+
function CurrencyInput(props: CurrencyInputProps) {
|
11
|
+
const [isFocused, setIsFocused] = useState(false);
|
12
|
+
const [currencyValue, setCurrencyValue] = useState(props.defaultValue || 0);
|
13
|
+
|
14
|
+
const baseRef = useRef<HTMLInputElement>(null);
|
15
|
+
|
16
|
+
const { inputRef, id, error } = useFormController();
|
17
|
+
|
18
|
+
const ref = inputRef || baseRef;
|
19
|
+
const isError = props.isError || !!error;
|
20
|
+
|
21
|
+
const {
|
22
|
+
disabled,
|
23
|
+
title,
|
24
|
+
style,
|
25
|
+
className,
|
26
|
+
prefix,
|
27
|
+
sufix,
|
28
|
+
iconSize,
|
29
|
+
loadingPosition,
|
30
|
+
isLoading,
|
31
|
+
LeftIcon,
|
32
|
+
readOnly,
|
33
|
+
onFocus,
|
34
|
+
onBlur,
|
35
|
+
RightIcon,
|
36
|
+
Spinner,
|
37
|
+
value,
|
38
|
+
max,
|
39
|
+
onKeyDown,
|
40
|
+
onChange,
|
41
|
+
showCents,
|
42
|
+
...rest
|
43
|
+
} = getConfig({ ...props, id, isError }, isFocused);
|
44
|
+
|
45
|
+
const showLeftIcon = LeftIcon && !isLoading;
|
46
|
+
const showRightIcon = RightIcon && !isLoading;
|
47
|
+
|
48
|
+
const showLeftSpinner = loadingPosition === "left" && isLoading;
|
49
|
+
const showRightSpinner = loadingPosition === "right" && isLoading;
|
50
|
+
|
51
|
+
function handleSectionClick() {
|
52
|
+
if (disabled || !ref?.current) return;
|
53
|
+
setIsFocused(true);
|
54
|
+
ref.current.focus();
|
55
|
+
}
|
56
|
+
|
57
|
+
function handleKeyDown(event: KeyboardEvent<HTMLInputElement>) {
|
58
|
+
currencyInputKeyDown({ currencyValue, event, max, setCurrencyValue });
|
59
|
+
onChange && onChange(currencyValue);
|
60
|
+
onKeyDown && onKeyDown(event);
|
61
|
+
}
|
62
|
+
|
63
|
+
function handleFocus(e: FocusEvent<HTMLInputElement>) {
|
64
|
+
setIsFocused(true);
|
65
|
+
if (onFocus) onFocus(e);
|
66
|
+
}
|
67
|
+
|
68
|
+
function handleBlur(e: FocusEvent<HTMLInputElement>) {
|
69
|
+
setIsFocused(false);
|
70
|
+
if (onBlur) onBlur(e);
|
71
|
+
}
|
72
|
+
|
73
|
+
return (
|
74
|
+
<section
|
75
|
+
title={title}
|
76
|
+
style={style}
|
77
|
+
onClick={handleSectionClick}
|
78
|
+
className={className}
|
79
|
+
>
|
80
|
+
{prefix}
|
81
|
+
{showLeftSpinner && Spinner}
|
82
|
+
{showLeftIcon && <LeftIcon size={iconSize} strokeWidth={2.5} />}
|
83
|
+
|
84
|
+
<input
|
85
|
+
value={valueDisplay(value || currencyValue, showCents)}
|
86
|
+
onKeyDown={handleKeyDown}
|
87
|
+
disabled={disabled || isLoading}
|
88
|
+
readOnly={readOnly}
|
89
|
+
ref={ref}
|
90
|
+
onFocus={handleFocus}
|
91
|
+
onChange={() => {}}
|
92
|
+
onBlur={handleBlur}
|
93
|
+
{...rest}
|
94
|
+
/>
|
95
|
+
|
96
|
+
{showRightSpinner && Spinner}
|
97
|
+
{showRightIcon && <RightIcon size={iconSize} strokeWidth={2.5} />}
|
98
|
+
{sufix}
|
99
|
+
</section>
|
100
|
+
);
|
101
|
+
}
|
102
|
+
|
103
|
+
export { CurrencyInput };
|