@geoinsight/react-components 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.css +76 -54
- package/dist/cjs/index.js +39 -9
- package/dist/esm/index.css +76 -54
- package/dist/esm/index.js +39 -10
- package/package.json +1 -1
package/dist/cjs/index.css
CHANGED
|
@@ -291,6 +291,20 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
|
|
|
291
291
|
padding: var(--spacing-16);
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
+
.form {
|
|
295
|
+
align-items: center;
|
|
296
|
+
display: flex;
|
|
297
|
+
flex-direction: column;
|
|
298
|
+
gap: var(--spacing-32);
|
|
299
|
+
padding: var(--spacing-32) 0;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
.form__message {
|
|
303
|
+
align-items: center;
|
|
304
|
+
display: flex;
|
|
305
|
+
justify-content: center;
|
|
306
|
+
gap: var(--spacing-16);
|
|
307
|
+
}
|
|
294
308
|
.input-group {
|
|
295
309
|
display: flex;
|
|
296
310
|
flex-direction: column;
|
|
@@ -309,7 +323,7 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
|
|
|
309
323
|
width: 100%;
|
|
310
324
|
}
|
|
311
325
|
|
|
312
|
-
.input:hover {
|
|
326
|
+
.input:enabled:hover {
|
|
313
327
|
border: 3px solid var(--color-primary-700);
|
|
314
328
|
}
|
|
315
329
|
|
|
@@ -318,6 +332,10 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
|
|
|
318
332
|
outline: none;
|
|
319
333
|
}
|
|
320
334
|
|
|
335
|
+
.input:disabled {
|
|
336
|
+
opacity: 0.5;
|
|
337
|
+
}
|
|
338
|
+
|
|
321
339
|
.input--error {
|
|
322
340
|
border: 3px solid var(--color-danger);
|
|
323
341
|
}
|
|
@@ -332,6 +350,57 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
|
|
|
332
350
|
color: var(--color-danger);
|
|
333
351
|
}
|
|
334
352
|
|
|
353
|
+
.loading {
|
|
354
|
+
align-items: center;
|
|
355
|
+
display: flex;
|
|
356
|
+
flex-direction: column;
|
|
357
|
+
height: 100%;
|
|
358
|
+
justify-content: center;;
|
|
359
|
+
position: relative;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
.modal-overlay {
|
|
363
|
+
background: rgba(0, 0, 0, 0.3);
|
|
364
|
+
bottom: 0;
|
|
365
|
+
left: 0;
|
|
366
|
+
position: fixed;
|
|
367
|
+
right: 0;
|
|
368
|
+
top: 0;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
.modal {
|
|
372
|
+
background: white;
|
|
373
|
+
border-radius: var(--spacing-8);
|
|
374
|
+
border: 1px solid var(--color-neutral-600);
|
|
375
|
+
color: var(--color-black);
|
|
376
|
+
left: 50%;
|
|
377
|
+
padding: var(--spacing-4) var(--spacing-4);
|
|
378
|
+
position: absolute;
|
|
379
|
+
right: var(--spacing-16);
|
|
380
|
+
top: 50%;
|
|
381
|
+
transform: translate(-50%, -50%);
|
|
382
|
+
z-index: 5;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
.modal__close {
|
|
386
|
+
position: absolute;
|
|
387
|
+
right: calc(var(--spacing-16) * -1);
|
|
388
|
+
top: calc(var(--spacing-16) * -1);
|
|
389
|
+
z-index: 5;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
.modal__content {
|
|
393
|
+
border: 1px solid var(--color-neutral-100);
|
|
394
|
+
border-radius: var(--spacing-8);
|
|
395
|
+
display: flex;
|
|
396
|
+
flex-direction: column;
|
|
397
|
+
gap: var(--spacing-16);
|
|
398
|
+
padding: 0 var(--spacing-16);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
.modal__footer {
|
|
402
|
+
padding-bottom: var(--spacing-16);
|
|
403
|
+
}
|
|
335
404
|
.textarea {
|
|
336
405
|
margin-bottom: var(--spacing-8);
|
|
337
406
|
position: relative;
|
|
@@ -351,10 +420,14 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
|
|
|
351
420
|
width: 100%;
|
|
352
421
|
}
|
|
353
422
|
|
|
354
|
-
.textarea__input:hover {
|
|
423
|
+
.textarea__input:enabled:hover {
|
|
355
424
|
border: 3px solid var(--color-primary-700);
|
|
356
425
|
}
|
|
357
426
|
|
|
427
|
+
.textarea__input:disabled {
|
|
428
|
+
opacity: 0.5;
|
|
429
|
+
}
|
|
430
|
+
|
|
358
431
|
.textarea__button {
|
|
359
432
|
background: var(--color-primary);
|
|
360
433
|
border: 2px solid var(--color-secondary);
|
|
@@ -378,7 +451,7 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
|
|
|
378
451
|
pointer-events: none;
|
|
379
452
|
}
|
|
380
453
|
|
|
381
|
-
.textarea__button:hover {
|
|
454
|
+
.textarea__button:enabled:hover {
|
|
382
455
|
background: var(--color-secondary);
|
|
383
456
|
color: var(--color-neutral-100);
|
|
384
457
|
}
|
|
@@ -387,54 +460,3 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
|
|
|
387
460
|
background: var(--color-primary-700);
|
|
388
461
|
color: var(--color-neutral-100);
|
|
389
462
|
}
|
|
390
|
-
|
|
391
|
-
.modal-overlay {
|
|
392
|
-
background: rgba(0, 0, 0, 0.3);
|
|
393
|
-
bottom: 0;
|
|
394
|
-
left: 0;
|
|
395
|
-
position: fixed;
|
|
396
|
-
right: 0;
|
|
397
|
-
top: 0;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
.modal {
|
|
401
|
-
background: white;
|
|
402
|
-
border-radius: var(--spacing-8);
|
|
403
|
-
border: 1px solid var(--color-neutral-600);
|
|
404
|
-
color: var(--color-black);
|
|
405
|
-
left: 50%;
|
|
406
|
-
padding: var(--spacing-4) var(--spacing-4);
|
|
407
|
-
position: absolute;
|
|
408
|
-
right: var(--spacing-16);
|
|
409
|
-
top: 50%;
|
|
410
|
-
transform: translate(-50%, -50%);
|
|
411
|
-
z-index: 5;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
.modal__close {
|
|
415
|
-
position: absolute;
|
|
416
|
-
right: calc(var(--spacing-16) * -1);
|
|
417
|
-
top: calc(var(--spacing-16) * -1);
|
|
418
|
-
z-index: 5;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
.modal__content {
|
|
422
|
-
border: 1px solid var(--color-neutral-100);
|
|
423
|
-
border-radius: var(--spacing-8);
|
|
424
|
-
display: flex;
|
|
425
|
-
flex-direction: column;
|
|
426
|
-
gap: var(--spacing-16);
|
|
427
|
-
padding: 0 var(--spacing-16);
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
.modal__footer {
|
|
431
|
-
padding-bottom: var(--spacing-16);
|
|
432
|
-
}
|
|
433
|
-
.loading {
|
|
434
|
-
align-items: center;
|
|
435
|
-
display: flex;
|
|
436
|
-
flex-direction: column;
|
|
437
|
-
height: 100%;
|
|
438
|
-
justify-content: center;;
|
|
439
|
-
position: relative;
|
|
440
|
-
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -4,8 +4,10 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
4
4
|
var react = require('react');
|
|
5
5
|
var clsx = require('clsx');
|
|
6
6
|
var tfi = require('react-icons/tfi');
|
|
7
|
-
var
|
|
7
|
+
var bs = require('react-icons/bs');
|
|
8
|
+
var reactHookForm = require('react-hook-form');
|
|
8
9
|
var io5 = require('react-icons/io5');
|
|
10
|
+
var tb = require('react-icons/tb');
|
|
9
11
|
|
|
10
12
|
function recursiveChildren(children, i = 0) {
|
|
11
13
|
return react.Children.map(children, (child, index) => {
|
|
@@ -177,6 +179,33 @@ const AccordionContent = function AccordionContent({ children, label, toggle, })
|
|
|
177
179
|
toggle[label].isToggle && (jsxRuntime.jsx("div", { className: "accordion-content", children: children })));
|
|
178
180
|
};
|
|
179
181
|
|
|
182
|
+
function Form({ children, onSubmit, submitButton = {
|
|
183
|
+
label: "Submit",
|
|
184
|
+
}, ...rest }) {
|
|
185
|
+
const { handleSubmit, control, formState: { errors, isValid }, } = reactHookForm.useForm();
|
|
186
|
+
const [result, setResult] = react.useState({
|
|
187
|
+
message: "",
|
|
188
|
+
isSuccess: false,
|
|
189
|
+
});
|
|
190
|
+
return (jsxRuntime.jsxs("form", { className: "form", onSubmit: handleSubmit(async (data) => await onSubmit(data, setResult)), ...rest, children: [react.Children.map(children, (child) => {
|
|
191
|
+
const { props: { name, error, isRequired, ...rest }, } = child;
|
|
192
|
+
return (jsxRuntime.jsx(reactHookForm.Controller, { name: name, control: control, rules: {
|
|
193
|
+
...(isRequired ? {
|
|
194
|
+
required: error?.message || "Field is required",
|
|
195
|
+
} : {}),
|
|
196
|
+
}, render: ({ field }) => react.cloneElement(child, {
|
|
197
|
+
error: {
|
|
198
|
+
is: Object.keys(errors).length > 0 && !!errors[name],
|
|
199
|
+
message: errors &&
|
|
200
|
+
Object.keys(errors).length > 0 &&
|
|
201
|
+
errors[name]?.message,
|
|
202
|
+
},
|
|
203
|
+
...field,
|
|
204
|
+
...rest,
|
|
205
|
+
}) }));
|
|
206
|
+
}), result.message && (jsxRuntime.jsxs("div", { className: "form__message", children: [result.isSuccess ? (jsxRuntime.jsx(bs.BsCheckCircleFill, { color: "var(--color-success)", size: 48 })) : (jsxRuntime.jsx(bs.BsXCircleFill, { color: "var(--color-danger)", size: 48 })), result.message] })), jsxRuntime.jsx(Button, { type: "submit", disabled: !isValid, children: submitButton.label })] }));
|
|
207
|
+
}
|
|
208
|
+
|
|
180
209
|
function Input({ className = "", classNameGroup = "", error = {
|
|
181
210
|
is: false,
|
|
182
211
|
message: "",
|
|
@@ -184,6 +213,14 @@ function Input({ className = "", classNameGroup = "", error = {
|
|
|
184
213
|
return (jsxRuntime.jsxs("div", { className: clsx("input-group", classNameGroup), style: styleGroup, children: [jsxRuntime.jsx("input", { ref: inputRef, className: clsx("input", error.is ? "input--error" : "", className), placeholder: placeholder, ...rest }), error && error.is && jsxRuntime.jsx("span", { className: "error", children: error.message })] }));
|
|
185
214
|
}
|
|
186
215
|
|
|
216
|
+
function Loading({ img, children }) {
|
|
217
|
+
return (jsxRuntime.jsxs("div", { className: "loading", children: [jsxRuntime.jsx("img", { src: img ? img : "../../stories/assets/loading.gif" }), children] }));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function Modal({ modalref, children, title, subtitle, footer, hasCloseButton = true, handleClose, }) {
|
|
221
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: "modal-overlay" }), jsxRuntime.jsxs("div", { ref: modalref, className: "modal", children: [hasCloseButton && (jsxRuntime.jsx(Button, { mode: "secondary", className: "modal__close", size: "small", onClick: handleClose, children: jsxRuntime.jsx(io5.IoClose, {}) })), jsxRuntime.jsxs("div", { className: "modal__content", children: [title && (jsxRuntime.jsxs("div", { className: "modal__header", children: [jsxRuntime.jsx("h3", { children: title }), jsxRuntime.jsx("h6", { children: subtitle })] })), jsxRuntime.jsx("div", { className: "modal__children", children: children }), footer && jsxRuntime.jsx("div", { className: "modal__footer", children: footer })] })] })] }));
|
|
222
|
+
}
|
|
223
|
+
|
|
187
224
|
function TextArea({ className = "", disabled = true, hasToggleButton = true, hideHeight = "5rem", placeholder = "Insert value", showHeight = "10rem", style = {}, textareaClassName = "", ...rest }) {
|
|
188
225
|
const ref = react.useRef();
|
|
189
226
|
const [isShow, setIsShow] = react.useState(false);
|
|
@@ -203,14 +240,6 @@ function TextArea({ className = "", disabled = true, hasToggleButton = true, hid
|
|
|
203
240
|
}, placeholder: placeholder, disabled: disabled, ...rest }), hasToggleButton && (jsxRuntime.jsx("button", { type: "button", className: clsx("textarea__button", isShow && "textarea__button--show"), onClick: handleClickToggle, disabled: disabled, children: jsxRuntime.jsx(tb.TbArrowsDiagonal2, { size: "1.5rem" }) }))] }));
|
|
204
241
|
}
|
|
205
242
|
|
|
206
|
-
function Modal({ modalref, children, title, subtitle, footer, hasCloseButton = true, handleClose, }) {
|
|
207
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: "modal-overlay" }), jsxRuntime.jsxs("div", { ref: modalref, className: "modal", children: [hasCloseButton && (jsxRuntime.jsx(Button, { mode: "secondary", className: "modal__close", size: "small", onClick: handleClose, children: jsxRuntime.jsx(io5.IoClose, {}) })), jsxRuntime.jsxs("div", { className: "modal__content", children: [title && (jsxRuntime.jsxs("div", { className: "modal__header", children: [jsxRuntime.jsx("h3", { children: title }), jsxRuntime.jsx("h6", { children: subtitle })] })), jsxRuntime.jsx("div", { className: "modal__children", children: children }), footer && jsxRuntime.jsx("div", { className: "modal__footer", children: footer })] })] })] }));
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function Loading({ img, children }) {
|
|
211
|
-
return (jsxRuntime.jsxs("div", { className: "loading", children: [jsxRuntime.jsx("img", { src: img ? img : "../../stories/assets/loading.gif" }), children] }));
|
|
212
|
-
}
|
|
213
|
-
|
|
214
243
|
const LoadingContext = react.createContext(undefined);
|
|
215
244
|
function loadingReducer(state, action) {
|
|
216
245
|
switch (action.type) {
|
|
@@ -337,6 +366,7 @@ exports.AccordionButton = AccordionButton;
|
|
|
337
366
|
exports.AccordionContent = AccordionContent;
|
|
338
367
|
exports.AccordionItem = AccordionItem;
|
|
339
368
|
exports.Button = Button;
|
|
369
|
+
exports.Form = Form;
|
|
340
370
|
exports.Input = Input;
|
|
341
371
|
exports.Loading = Loading;
|
|
342
372
|
exports.LoadingContext = LoadingContext;
|
package/dist/esm/index.css
CHANGED
|
@@ -291,6 +291,20 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
|
|
|
291
291
|
padding: var(--spacing-16);
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
+
.form {
|
|
295
|
+
align-items: center;
|
|
296
|
+
display: flex;
|
|
297
|
+
flex-direction: column;
|
|
298
|
+
gap: var(--spacing-32);
|
|
299
|
+
padding: var(--spacing-32) 0;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
.form__message {
|
|
303
|
+
align-items: center;
|
|
304
|
+
display: flex;
|
|
305
|
+
justify-content: center;
|
|
306
|
+
gap: var(--spacing-16);
|
|
307
|
+
}
|
|
294
308
|
.input-group {
|
|
295
309
|
display: flex;
|
|
296
310
|
flex-direction: column;
|
|
@@ -309,7 +323,7 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
|
|
|
309
323
|
width: 100%;
|
|
310
324
|
}
|
|
311
325
|
|
|
312
|
-
.input:hover {
|
|
326
|
+
.input:enabled:hover {
|
|
313
327
|
border: 3px solid var(--color-primary-700);
|
|
314
328
|
}
|
|
315
329
|
|
|
@@ -318,6 +332,10 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
|
|
|
318
332
|
outline: none;
|
|
319
333
|
}
|
|
320
334
|
|
|
335
|
+
.input:disabled {
|
|
336
|
+
opacity: 0.5;
|
|
337
|
+
}
|
|
338
|
+
|
|
321
339
|
.input--error {
|
|
322
340
|
border: 3px solid var(--color-danger);
|
|
323
341
|
}
|
|
@@ -332,6 +350,57 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
|
|
|
332
350
|
color: var(--color-danger);
|
|
333
351
|
}
|
|
334
352
|
|
|
353
|
+
.loading {
|
|
354
|
+
align-items: center;
|
|
355
|
+
display: flex;
|
|
356
|
+
flex-direction: column;
|
|
357
|
+
height: 100%;
|
|
358
|
+
justify-content: center;;
|
|
359
|
+
position: relative;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
.modal-overlay {
|
|
363
|
+
background: rgba(0, 0, 0, 0.3);
|
|
364
|
+
bottom: 0;
|
|
365
|
+
left: 0;
|
|
366
|
+
position: fixed;
|
|
367
|
+
right: 0;
|
|
368
|
+
top: 0;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
.modal {
|
|
372
|
+
background: white;
|
|
373
|
+
border-radius: var(--spacing-8);
|
|
374
|
+
border: 1px solid var(--color-neutral-600);
|
|
375
|
+
color: var(--color-black);
|
|
376
|
+
left: 50%;
|
|
377
|
+
padding: var(--spacing-4) var(--spacing-4);
|
|
378
|
+
position: absolute;
|
|
379
|
+
right: var(--spacing-16);
|
|
380
|
+
top: 50%;
|
|
381
|
+
transform: translate(-50%, -50%);
|
|
382
|
+
z-index: 5;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
.modal__close {
|
|
386
|
+
position: absolute;
|
|
387
|
+
right: calc(var(--spacing-16) * -1);
|
|
388
|
+
top: calc(var(--spacing-16) * -1);
|
|
389
|
+
z-index: 5;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
.modal__content {
|
|
393
|
+
border: 1px solid var(--color-neutral-100);
|
|
394
|
+
border-radius: var(--spacing-8);
|
|
395
|
+
display: flex;
|
|
396
|
+
flex-direction: column;
|
|
397
|
+
gap: var(--spacing-16);
|
|
398
|
+
padding: 0 var(--spacing-16);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
.modal__footer {
|
|
402
|
+
padding-bottom: var(--spacing-16);
|
|
403
|
+
}
|
|
335
404
|
.textarea {
|
|
336
405
|
margin-bottom: var(--spacing-8);
|
|
337
406
|
position: relative;
|
|
@@ -351,10 +420,14 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
|
|
|
351
420
|
width: 100%;
|
|
352
421
|
}
|
|
353
422
|
|
|
354
|
-
.textarea__input:hover {
|
|
423
|
+
.textarea__input:enabled:hover {
|
|
355
424
|
border: 3px solid var(--color-primary-700);
|
|
356
425
|
}
|
|
357
426
|
|
|
427
|
+
.textarea__input:disabled {
|
|
428
|
+
opacity: 0.5;
|
|
429
|
+
}
|
|
430
|
+
|
|
358
431
|
.textarea__button {
|
|
359
432
|
background: var(--color-primary);
|
|
360
433
|
border: 2px solid var(--color-secondary);
|
|
@@ -378,7 +451,7 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
|
|
|
378
451
|
pointer-events: none;
|
|
379
452
|
}
|
|
380
453
|
|
|
381
|
-
.textarea__button:hover {
|
|
454
|
+
.textarea__button:enabled:hover {
|
|
382
455
|
background: var(--color-secondary);
|
|
383
456
|
color: var(--color-neutral-100);
|
|
384
457
|
}
|
|
@@ -387,54 +460,3 @@ transition: var(--transition-bg-cubic-bezier), var(--transition-box-shadow-cubic
|
|
|
387
460
|
background: var(--color-primary-700);
|
|
388
461
|
color: var(--color-neutral-100);
|
|
389
462
|
}
|
|
390
|
-
|
|
391
|
-
.modal-overlay {
|
|
392
|
-
background: rgba(0, 0, 0, 0.3);
|
|
393
|
-
bottom: 0;
|
|
394
|
-
left: 0;
|
|
395
|
-
position: fixed;
|
|
396
|
-
right: 0;
|
|
397
|
-
top: 0;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
.modal {
|
|
401
|
-
background: white;
|
|
402
|
-
border-radius: var(--spacing-8);
|
|
403
|
-
border: 1px solid var(--color-neutral-600);
|
|
404
|
-
color: var(--color-black);
|
|
405
|
-
left: 50%;
|
|
406
|
-
padding: var(--spacing-4) var(--spacing-4);
|
|
407
|
-
position: absolute;
|
|
408
|
-
right: var(--spacing-16);
|
|
409
|
-
top: 50%;
|
|
410
|
-
transform: translate(-50%, -50%);
|
|
411
|
-
z-index: 5;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
.modal__close {
|
|
415
|
-
position: absolute;
|
|
416
|
-
right: calc(var(--spacing-16) * -1);
|
|
417
|
-
top: calc(var(--spacing-16) * -1);
|
|
418
|
-
z-index: 5;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
.modal__content {
|
|
422
|
-
border: 1px solid var(--color-neutral-100);
|
|
423
|
-
border-radius: var(--spacing-8);
|
|
424
|
-
display: flex;
|
|
425
|
-
flex-direction: column;
|
|
426
|
-
gap: var(--spacing-16);
|
|
427
|
-
padding: 0 var(--spacing-16);
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
.modal__footer {
|
|
431
|
-
padding-bottom: var(--spacing-16);
|
|
432
|
-
}
|
|
433
|
-
.loading {
|
|
434
|
-
align-items: center;
|
|
435
|
-
display: flex;
|
|
436
|
-
flex-direction: column;
|
|
437
|
-
height: 100%;
|
|
438
|
-
justify-content: center;;
|
|
439
|
-
position: relative;
|
|
440
|
-
}
|
package/dist/esm/index.js
CHANGED
|
@@ -2,8 +2,10 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
|
2
2
|
import { Children, isValidElement, cloneElement, createContext, useState, useContext, useEffect, useRef, useReducer } from 'react';
|
|
3
3
|
import clsx from 'clsx';
|
|
4
4
|
import { TfiAngleDown, TfiAngleUp } from 'react-icons/tfi';
|
|
5
|
-
import {
|
|
5
|
+
import { BsCheckCircleFill, BsXCircleFill } from 'react-icons/bs';
|
|
6
|
+
import { useForm, Controller } from 'react-hook-form';
|
|
6
7
|
import { IoClose } from 'react-icons/io5';
|
|
8
|
+
import { TbArrowsDiagonal2 } from 'react-icons/tb';
|
|
7
9
|
|
|
8
10
|
function recursiveChildren(children, i = 0) {
|
|
9
11
|
return Children.map(children, (child, index) => {
|
|
@@ -175,6 +177,33 @@ const AccordionContent = function AccordionContent({ children, label, toggle, })
|
|
|
175
177
|
toggle[label].isToggle && (jsx("div", { className: "accordion-content", children: children })));
|
|
176
178
|
};
|
|
177
179
|
|
|
180
|
+
function Form({ children, onSubmit, submitButton = {
|
|
181
|
+
label: "Submit",
|
|
182
|
+
}, ...rest }) {
|
|
183
|
+
const { handleSubmit, control, formState: { errors, isValid }, } = useForm();
|
|
184
|
+
const [result, setResult] = useState({
|
|
185
|
+
message: "",
|
|
186
|
+
isSuccess: false,
|
|
187
|
+
});
|
|
188
|
+
return (jsxs("form", { className: "form", onSubmit: handleSubmit(async (data) => await onSubmit(data, setResult)), ...rest, children: [Children.map(children, (child) => {
|
|
189
|
+
const { props: { name, error, isRequired, ...rest }, } = child;
|
|
190
|
+
return (jsx(Controller, { name: name, control: control, rules: {
|
|
191
|
+
...(isRequired ? {
|
|
192
|
+
required: error?.message || "Field is required",
|
|
193
|
+
} : {}),
|
|
194
|
+
}, render: ({ field }) => cloneElement(child, {
|
|
195
|
+
error: {
|
|
196
|
+
is: Object.keys(errors).length > 0 && !!errors[name],
|
|
197
|
+
message: errors &&
|
|
198
|
+
Object.keys(errors).length > 0 &&
|
|
199
|
+
errors[name]?.message,
|
|
200
|
+
},
|
|
201
|
+
...field,
|
|
202
|
+
...rest,
|
|
203
|
+
}) }));
|
|
204
|
+
}), result.message && (jsxs("div", { className: "form__message", children: [result.isSuccess ? (jsx(BsCheckCircleFill, { color: "var(--color-success)", size: 48 })) : (jsx(BsXCircleFill, { color: "var(--color-danger)", size: 48 })), result.message] })), jsx(Button, { type: "submit", disabled: !isValid, children: submitButton.label })] }));
|
|
205
|
+
}
|
|
206
|
+
|
|
178
207
|
function Input({ className = "", classNameGroup = "", error = {
|
|
179
208
|
is: false,
|
|
180
209
|
message: "",
|
|
@@ -182,6 +211,14 @@ function Input({ className = "", classNameGroup = "", error = {
|
|
|
182
211
|
return (jsxs("div", { className: clsx("input-group", classNameGroup), style: styleGroup, children: [jsx("input", { ref: inputRef, className: clsx("input", error.is ? "input--error" : "", className), placeholder: placeholder, ...rest }), error && error.is && jsx("span", { className: "error", children: error.message })] }));
|
|
183
212
|
}
|
|
184
213
|
|
|
214
|
+
function Loading({ img, children }) {
|
|
215
|
+
return (jsxs("div", { className: "loading", children: [jsx("img", { src: img ? img : "../../stories/assets/loading.gif" }), children] }));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function Modal({ modalref, children, title, subtitle, footer, hasCloseButton = true, handleClose, }) {
|
|
219
|
+
return (jsxs(Fragment, { children: [jsx("div", { className: "modal-overlay" }), jsxs("div", { ref: modalref, className: "modal", children: [hasCloseButton && (jsx(Button, { mode: "secondary", className: "modal__close", size: "small", onClick: handleClose, children: jsx(IoClose, {}) })), jsxs("div", { className: "modal__content", children: [title && (jsxs("div", { className: "modal__header", children: [jsx("h3", { children: title }), jsx("h6", { children: subtitle })] })), jsx("div", { className: "modal__children", children: children }), footer && jsx("div", { className: "modal__footer", children: footer })] })] })] }));
|
|
220
|
+
}
|
|
221
|
+
|
|
185
222
|
function TextArea({ className = "", disabled = true, hasToggleButton = true, hideHeight = "5rem", placeholder = "Insert value", showHeight = "10rem", style = {}, textareaClassName = "", ...rest }) {
|
|
186
223
|
const ref = useRef();
|
|
187
224
|
const [isShow, setIsShow] = useState(false);
|
|
@@ -201,14 +238,6 @@ function TextArea({ className = "", disabled = true, hasToggleButton = true, hid
|
|
|
201
238
|
}, placeholder: placeholder, disabled: disabled, ...rest }), hasToggleButton && (jsx("button", { type: "button", className: clsx("textarea__button", isShow && "textarea__button--show"), onClick: handleClickToggle, disabled: disabled, children: jsx(TbArrowsDiagonal2, { size: "1.5rem" }) }))] }));
|
|
202
239
|
}
|
|
203
240
|
|
|
204
|
-
function Modal({ modalref, children, title, subtitle, footer, hasCloseButton = true, handleClose, }) {
|
|
205
|
-
return (jsxs(Fragment, { children: [jsx("div", { className: "modal-overlay" }), jsxs("div", { ref: modalref, className: "modal", children: [hasCloseButton && (jsx(Button, { mode: "secondary", className: "modal__close", size: "small", onClick: handleClose, children: jsx(IoClose, {}) })), jsxs("div", { className: "modal__content", children: [title && (jsxs("div", { className: "modal__header", children: [jsx("h3", { children: title }), jsx("h6", { children: subtitle })] })), jsx("div", { className: "modal__children", children: children }), footer && jsx("div", { className: "modal__footer", children: footer })] })] })] }));
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
function Loading({ img, children }) {
|
|
209
|
-
return (jsxs("div", { className: "loading", children: [jsx("img", { src: img ? img : "../../stories/assets/loading.gif" }), children] }));
|
|
210
|
-
}
|
|
211
|
-
|
|
212
241
|
const LoadingContext = createContext(undefined);
|
|
213
242
|
function loadingReducer(state, action) {
|
|
214
243
|
switch (action.type) {
|
|
@@ -330,4 +359,4 @@ function useModal({} = {}) {
|
|
|
330
359
|
return context;
|
|
331
360
|
}
|
|
332
361
|
|
|
333
|
-
export { Accordion, AccordionButton, AccordionContent, AccordionItem, Button, Input, Loading, LoadingContext, LoadingProvider, Modal, ModalContext, ModalProvider, TextArea, ThemeContext, ThemeProvider, useLoading, useModal, useTheme };
|
|
362
|
+
export { Accordion, AccordionButton, AccordionContent, AccordionItem, Button, Form, Input, Loading, LoadingContext, LoadingProvider, Modal, ModalContext, ModalProvider, TextArea, ThemeContext, ThemeProvider, useLoading, useModal, useTheme };
|