@4alldigital/foundation-ui--gamma 1.24.0 → 1.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +46 -41
- package/dist/index.js +45 -40
- package/dist/types/fui/components/Form/Form.d.ts +1 -1
- package/dist/types/fui/components/Form/Form.stories.d.ts +1 -0
- package/dist/types/fui/components/Form/Form.types.d.ts +5 -5
- package/dist/types/fui/components/FormField/FormField.types.d.ts +3 -4
- package/dist/types/fui/components/FormSelect/FormSelect.d.ts +1 -4
- package/dist/types/fui/components/FormSelect/FormSelect.types.d.ts +2 -3
- package/package.json +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import cx from 'classnames';
|
|
3
3
|
import { Icon as Icon$1 } from '@iconify/react';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
4
|
+
import React, { useEffect } from 'react';
|
|
5
|
+
import { useForm, FormProvider, useFormContext, Controller } from 'react-hook-form';
|
|
6
6
|
|
|
7
7
|
var Blockquote = function (_a) {
|
|
8
8
|
var text = _a.text, citation = _a.citation, className = _a.className, citationAttribute = _a.citationAttribute, _b = _a.showIcon, showIcon = _b === void 0 ? true : _b;
|
|
@@ -165,7 +165,6 @@ Heading.displayName = 'Heading';
|
|
|
165
165
|
*/
|
|
166
166
|
var Icon = function (_a) {
|
|
167
167
|
var name = _a.name, _b = _a.size, size = _b === void 0 ? 24 : _b, color = _a.color, id = _a.id, className = _a.className, testID = _a.testID;
|
|
168
|
-
console.log('Icon name', name, color);
|
|
169
168
|
if (color) {
|
|
170
169
|
return (jsx(Icon$1, { "data-testid": testID || id || 'Icon', icon: name, width: size, height: size, color: color, className: className, fill: color || 'currentColor' }));
|
|
171
170
|
}
|
|
@@ -298,17 +297,6 @@ var ContentRowsLayout = function (_a) {
|
|
|
298
297
|
};
|
|
299
298
|
ContentRowsLayout.displayName = 'ContentRowsLayout';
|
|
300
299
|
|
|
301
|
-
var Form = function (_a) {
|
|
302
|
-
var children = _a.children, className = _a.className, submit = _a.submit, onSubmit = _a.onSubmit, hideSubmit = _a.hideSubmit, ariaSubmitLabel = _a.ariaSubmitLabel, submitID = _a.submitID, initialValues = _a.initialValues, _b = _a.submitVariant, submitVariant = _b === void 0 ? BTN_VARIANTS.PRIMARY : _b;
|
|
303
|
-
var _c = useForm({
|
|
304
|
-
defaultValues: initialValues,
|
|
305
|
-
}), handleSubmit = _c.handleSubmit, formState = _c.formState;
|
|
306
|
-
var submitClasses = cx({ 'sr-only': hideSubmit });
|
|
307
|
-
console.log('FORM formState', formState);
|
|
308
|
-
return (jsx("div", { "data-testid": "Form", className: "w-full max-w-s @form @containers", children: jsxs("form", { onSubmit: handleSubmit(onSubmit), className: cx('form px-8 pt-6 pb-8 mb-4 w-2xs', className), children: [children, jsx("div", { className: 'flex items-center justify-end py-2', children: jsx(Button, { id: submitID || submit, className: submitClasses, ariaLabel: ariaSubmitLabel || submit || 'Submit', type: BTN_TYPES.SUBMIT, variant: submitVariant, children: submit }) })] }) }));
|
|
309
|
-
};
|
|
310
|
-
Form.displayName = 'Form';
|
|
311
|
-
|
|
312
300
|
/******************************************************************************
|
|
313
301
|
Copyright (c) Microsoft Corporation.
|
|
314
302
|
|
|
@@ -354,6 +342,22 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
354
342
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
355
343
|
};
|
|
356
344
|
|
|
345
|
+
var Form = function (_a) {
|
|
346
|
+
var children = _a.children, className = _a.className, submit = _a.submit, _b = _a.onSubmit, onSubmit = _b === void 0 ? function () { } : _b, onChange = _a.onChange, hideSubmit = _a.hideSubmit, ariaSubmitLabel = _a.ariaSubmitLabel, submitID = _a.submitID, _c = _a.submitVariant, submitVariant = _c === void 0 ? BTN_VARIANTS.PRIMARY : _c, _d = _a.initialValues, initialValues = _d === void 0 ? {} : _d;
|
|
347
|
+
var methods = useForm({
|
|
348
|
+
defaultValues: initialValues,
|
|
349
|
+
});
|
|
350
|
+
useEffect(function () {
|
|
351
|
+
if (onChange && typeof onChange === 'function') {
|
|
352
|
+
var subscription_1 = methods.watch(function (value) { return onChange(value); });
|
|
353
|
+
return function () { return subscription_1.unsubscribe(); };
|
|
354
|
+
}
|
|
355
|
+
}, []);
|
|
356
|
+
var submitClasses = cx({ 'sr-only': hideSubmit });
|
|
357
|
+
return (jsx(FormProvider, __assign({}, methods, { children: jsx("div", { "data-testid": "Form", className: "w-full max-w-s @form @containers", children: jsxs("form", { onSubmit: methods.handleSubmit(onSubmit), className: cx('form px-8 pt-6 pb-8 mb-4 w-2xs', className), children: [children, submit && (jsx("div", { className: "flex items-center justify-end py-2", children: jsx(Button, { id: submitID || submit, className: submitClasses, ariaLabel: ariaSubmitLabel || submit || 'Submit', type: BTN_TYPES.SUBMIT, variant: submitVariant, children: submit }) }))] }) }) })));
|
|
358
|
+
};
|
|
359
|
+
Form.displayName = 'Form';
|
|
360
|
+
|
|
357
361
|
var FieldTypes;
|
|
358
362
|
(function (FieldTypes) {
|
|
359
363
|
FieldTypes["TEXT"] = "text";
|
|
@@ -400,7 +404,7 @@ var InputType;
|
|
|
400
404
|
})(InputType || (InputType = {}));
|
|
401
405
|
|
|
402
406
|
var TextInput = React.forwardRef(function MyInput(_a, ref) {
|
|
403
|
-
var _b = _a.type, type = _b === void 0 ? InputType.TEXT : _b,
|
|
407
|
+
var _b = _a.type, type = _b === void 0 ? InputType.TEXT : _b, _c = _a.required, required = _c === void 0 ? false : _c, className = _a.className, onChange = _a.onChange, placeholder = _a.placeholder, icon = _a.icon, _d = _a.disabled, disabled = _d === void 0 ? false : _d, rest = __rest(_a, ["type", "required", "className", "onChange", "placeholder", "icon", "disabled"]);
|
|
404
408
|
React.useEffect(function () {
|
|
405
409
|
if (typeof window !== 'undefined') {
|
|
406
410
|
// eslint-disable-next-line global-require
|
|
@@ -409,6 +413,7 @@ var TextInput = React.forwardRef(function MyInput(_a, ref) {
|
|
|
409
413
|
}, []);
|
|
410
414
|
var format = 'dd/mm/yyyy';
|
|
411
415
|
var placeholderSet = type === 'date' ? format.toUpperCase() : placeholder;
|
|
416
|
+
// console.log('TextInput', rest);
|
|
412
417
|
if (type === InputType.TEXTAREA) {
|
|
413
418
|
return (jsx("div", { "data-testid": "TextInput", className: "relative", children: jsx("textarea", __assign({ ref: ref, required: required, "aria-required": required, disabled: disabled, placeholder: placeholderSet, onChange: onChange, rows: 4, className: cx('form-item text-input resize-none', className) }, rest)) }));
|
|
414
419
|
}
|
|
@@ -418,7 +423,7 @@ TextInput.displayName = 'TextInput';
|
|
|
418
423
|
|
|
419
424
|
var Checkbox = React.forwardRef(function MyInput(_a, ref) {
|
|
420
425
|
var id = _a.id, label = _a.label, required = _a.required, className = _a.className, disabled = _a.disabled, rest = __rest(_a, ["id", "label", "required", "className", "disabled"]);
|
|
421
|
-
return (jsxs("div", { "data-testid": "Checkbox", className: cx('flex items-center', className), children: [jsxs("div",
|
|
426
|
+
return (jsxs("div", { "data-testid": "Checkbox", className: cx('flex items-center', className), children: [jsxs("div", { className: "relative bg-none w-5 h-5 flex justify-center items-center", "aria-label": label, children: [jsx("input", __assign({ id: id, ref: ref, disabled: disabled, type: "checkbox", className: "form-item checkbox m-0 appearance-none peer h-full w-full shrink-0 focus:ring-2", required: required }, rest)), jsx("span", { className: "absolute transition-opacity opacity-0 pointer-events-none peer-checked:opacity-100 w-full h-full flex items-center justify-center top-0 left-0", children: jsx(Icon, { name: "mdi:check-bold", size: 12 }) })] }), label && (jsx("label", { className: "label pl-2 leading-none", htmlFor: id, children: label }))] }));
|
|
422
427
|
});
|
|
423
428
|
Checkbox.displayName = 'Checkbox';
|
|
424
429
|
|
|
@@ -428,15 +433,18 @@ var Label = function (_a) {
|
|
|
428
433
|
};
|
|
429
434
|
Label.displayName = 'Label';
|
|
430
435
|
|
|
431
|
-
var FormSelect = function (_a) {
|
|
432
|
-
var id = _a.id, name = _a.name, options = _a.options, required = _a.required, className = _a.className, disabled = _a.disabled;
|
|
433
|
-
|
|
434
|
-
|
|
436
|
+
var FormSelect = React.forwardRef(function MyInput(_a, ref) {
|
|
437
|
+
var id = _a.id, name = _a.name, options = _a.options, required = _a.required, className = _a.className, disabled = _a.disabled, rest = __rest(_a, ["id", "name", "options", "required", "className", "disabled"]);
|
|
438
|
+
if (!options) {
|
|
439
|
+
throw new Error('FormSelect requires options prop');
|
|
440
|
+
}
|
|
441
|
+
return (jsx("div", { id: id, className: cx('pb-2', className), children: jsxs("div", { className: "relative", children: [jsx("select", __assign({ ref: ref, id: id, name: name, disabled: disabled, required: required, className: "form-item text-input" }, rest, { children: options.map(function (option) { return (jsx("option", { value: option.value, disabled: option.disabled, children: option.label }, option.value)); }) })), jsx("div", { className: "form-icon absolute inset-0 z-10 pointer-events-none h-full w-12 items-center justify-center top-0 right-0 left-auto flex", children: jsx(Icon, { name: "mdi:chevron-down", size: 24, className: "pointer-events-none" }) })] }) }));
|
|
442
|
+
});
|
|
435
443
|
FormSelect.displayName = 'FormSelect';
|
|
436
444
|
|
|
437
445
|
var Radio = React.forwardRef(function MyInput(_a, ref) {
|
|
438
446
|
var id = _a.id, name = _a.name, label = _a.label, required = _a.required, className = _a.className, options = _a.options, rest = __rest(_a, ["id", "name", "label", "required", "className", "options"]);
|
|
439
|
-
return (jsx("div", { "data-testid": "Radio", className: cx('flex items-center', className), children: jsx("div",
|
|
447
|
+
return (jsx("div", { "data-testid": "Radio", className: cx('flex items-center', className), children: jsx("div", { className: cx('flex flex-col gap-2', className), "aria-label": label, id: id, children: options === null || options === void 0 ? void 0 : options.map(function (option) { return (jsxs("div", { className: "flex items-center relative", children: [jsxs("div", { className: "relative flex items-center", children: [jsx("input", __assign({ id: option.value, ref: ref, name: name, type: "radio", value: option.value, required: required, className: "form-item radio peer appearance-none m-0 p-0 w-4 h-4" }, rest)), jsx("div", { className: "form-icon opacity-0 peer-checked:opacity-100 absolute w-4 h-4 flex items-center justify-center top-0 left-0 pointer-events-none", children: jsx(Icon, { name: "mdi:circle", size: 12 }) })] }), jsx("label", { className: "label pl-2 leading-none", htmlFor: option.value, children: option.label })] }, option.value)); }) }) }));
|
|
440
448
|
});
|
|
441
449
|
Radio.displayName = 'Radio';
|
|
442
450
|
|
|
@@ -454,47 +462,44 @@ FileUpload.displayName = 'FileUpload';
|
|
|
454
462
|
|
|
455
463
|
var FormField = function (_a) {
|
|
456
464
|
var name = _a.name, type = _a.type, label = _a.label, required = _a.required, className = _a.className, icon = _a.icon, options = _a.options, disabled = _a.disabled, description = _a.description, showPasswordLabel = _a.showPasswordLabel, hidePasswordLabel = _a.hidePasswordLabel;
|
|
457
|
-
var _b =
|
|
458
|
-
var _c =
|
|
459
|
-
var renderType = function (type
|
|
465
|
+
var _b = React.useState(false), passwordShowStatus = _b[0], setPasswordShow = _b[1];
|
|
466
|
+
var _c = useFormContext(), control = _c.control, register = _c.register;
|
|
467
|
+
var renderType = function (type) {
|
|
460
468
|
switch (type) {
|
|
461
469
|
case FieldTypes.TEXT:
|
|
462
|
-
return (jsx(TextInput, __assign({ type: InputType.TEXT, required: required, icon: icon, className: className, disabled: disabled },
|
|
470
|
+
return (jsx(TextInput, __assign({ type: InputType.TEXT, required: required, icon: icon, className: className, disabled: disabled }, register(name))));
|
|
463
471
|
case FieldTypes.PASSWORD: {
|
|
464
472
|
var toggleType = passwordShowStatus ? InputType.TEXT : InputType.PASSWORD;
|
|
465
473
|
var btnClass = 'appearance-none border-none bg-transparent flex items-center';
|
|
466
|
-
return (jsxs("div", { className: "relative", children: [jsx("span", { className: "absolute right-0 top-0 flex items-center justify-center h-full z-10 pr-2", onClick: function () { return setPasswordShow(function (pS) { return !pS; }); }, role: "button", tabIndex: 0, children: passwordShowStatus ? (jsx("button", { type: "button", "aria-label": hidePasswordLabel, className: cx(btnClass, 'form-icon'), children: jsx(Icon, { name: "mdi:eye-off", size: 24 }) })) : (jsx("button", { type: "button", "aria-label": showPasswordLabel, className: cx(btnClass, 'form-icon'), children: jsx(Icon, { name: "mdi:eye", size: 24 }) })) }), jsx(TextInput, __assign({ type: toggleType, required: required, icon: icon, className: className, disabled: disabled },
|
|
474
|
+
return (jsxs("div", { className: "relative", children: [jsx("span", { className: "absolute right-0 top-0 flex items-center justify-center h-full z-10 pr-2", onClick: function () { return setPasswordShow(function (pS) { return !pS; }); }, role: "button", tabIndex: 0, children: passwordShowStatus ? (jsx("button", { type: "button", "aria-label": hidePasswordLabel, className: cx(btnClass, 'form-icon'), children: jsx(Icon, { name: "mdi:eye-off", size: 24 }) })) : (jsx("button", { type: "button", "aria-label": showPasswordLabel, className: cx(btnClass, 'form-icon'), children: jsx(Icon, { name: "mdi:eye", size: 24 }) })) }), jsx(TextInput, __assign({ type: toggleType, required: required, icon: icon, className: className, disabled: disabled }, register(name)))] }));
|
|
467
475
|
}
|
|
468
476
|
case FieldTypes.TEXTAREA:
|
|
469
|
-
return (jsx(TextInput, __assign({ type: InputType.TEXTAREA, required: required, icon: icon, className: className, disabled: disabled },
|
|
477
|
+
return (jsx(TextInput, __assign({ type: InputType.TEXTAREA, required: required, icon: icon, className: className, disabled: disabled }, register(name))));
|
|
470
478
|
case FieldTypes.EMAIL:
|
|
471
|
-
return (jsx(TextInput, __assign({ type: InputType.EMAIL, required: required, icon: icon, className: className, disabled: disabled },
|
|
479
|
+
return (jsx(TextInput, __assign({ type: InputType.EMAIL, required: required, icon: icon, className: className, disabled: disabled }, register(name))));
|
|
472
480
|
case FieldTypes.DATE:
|
|
473
|
-
return (jsx(TextInput, __assign({ type: InputType.DATE, required: required, icon: icon, className: className, disabled: disabled },
|
|
481
|
+
return (jsx(TextInput, __assign({ type: InputType.DATE, required: required, icon: icon, className: className, disabled: disabled }, register(name))));
|
|
474
482
|
case FieldTypes.DATETIME:
|
|
475
|
-
return (jsx(TextInput, __assign({ type: InputType.DATETIME, required: required, icon: icon, className: className, disabled: disabled },
|
|
483
|
+
return (jsx(TextInput, __assign({ type: InputType.DATETIME, required: required, icon: icon, className: className, disabled: disabled }, register(name))));
|
|
476
484
|
case FieldTypes.NUMBER:
|
|
477
|
-
return (jsx(TextInput, __assign({ type: InputType.NUMBER, required: required, icon: icon, className: className, disabled: disabled },
|
|
485
|
+
return (jsx(TextInput, __assign({ type: InputType.NUMBER, required: required, icon: icon, className: className, disabled: disabled }, register(name))));
|
|
478
486
|
case FieldTypes.CHECKBOX:
|
|
479
|
-
return (jsx(Checkbox, __assign({ required: required, id: name, className: className, label: label, disabled: disabled },
|
|
487
|
+
return (jsx(Checkbox, __assign({ required: required, id: name, className: className, label: label, disabled: disabled }, register(name))));
|
|
480
488
|
case FieldTypes.RADIO:
|
|
481
|
-
return (jsx(Radio, __assign({ required: required, id: name, className: className, label: label, options: options, disabled: disabled },
|
|
489
|
+
return (jsx(Radio, __assign({ required: required, id: name, className: className, label: label, options: options, disabled: disabled }, register(name))));
|
|
482
490
|
case FieldTypes.SWITCH:
|
|
483
|
-
return jsx(Switch, __assign({ required: required, className: className, disabled: disabled },
|
|
491
|
+
return jsx(Switch, __assign({ id: name, required: required, className: className, disabled: disabled }, register(name)));
|
|
484
492
|
case FieldTypes.SELECT:
|
|
485
|
-
return (jsx(FormSelect, __assign({ required: required, id: name, className: className, disabled: disabled, label: label, options: options },
|
|
493
|
+
return (jsx(FormSelect, __assign({ required: required, id: name, className: className, disabled: disabled, label: label, options: options }, register(name))));
|
|
486
494
|
case FieldTypes.FILE:
|
|
487
|
-
return (jsx(FileUpload, __assign({ required: required, id: name, className: className, disabled: disabled },
|
|
495
|
+
return (jsx(FileUpload, __assign({ required: required, id: name, className: className, disabled: disabled }, register(name))));
|
|
488
496
|
default:
|
|
489
|
-
return (jsx(TextInput, __assign({ type: InputType.TEXT, required: required, disabled: disabled, icon: icon, className: className },
|
|
497
|
+
return (jsx(TextInput, __assign({ type: InputType.TEXT, required: required, disabled: disabled, icon: icon, className: className }, register(name))));
|
|
490
498
|
}
|
|
491
499
|
};
|
|
492
500
|
// TODO: HELPER CLASSES : data-[invalid=true]:bg-error data-[valid]:bg-success
|
|
493
501
|
var showLabel = label && type !== FieldTypes.CHECKBOX;
|
|
494
|
-
return (jsx("div", { className: "relative", children: jsxs("div", { "data-testid": "FormField", className: "mb-4", children: [showLabel && (jsx("div", { className: "flex items-baseline justify-between", children: jsx(Label, { label: label, id: name }) })), jsx(Controller, { name:
|
|
495
|
-
var field = _a.field;
|
|
496
|
-
return renderType(type, field);
|
|
497
|
-
} }), description && jsx(Copy, { size: SIZE$1.SMALL, children: description })] }) }));
|
|
502
|
+
return (jsx("div", { className: "relative", children: jsxs("div", { "data-testid": "FormField", className: "mb-4", children: [showLabel && (jsx("div", { className: "flex items-baseline justify-between", children: jsx(Label, { label: label, id: name }) })), jsx(Controller, { name: name, control: control, rules: { required: required }, render: function () { return renderType(type); } }), description && jsx(Copy, { size: SIZE$1.SMALL, children: description })] }) }));
|
|
498
503
|
};
|
|
499
504
|
FormField.displayName = 'FormField';
|
|
500
505
|
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var cx = require('classnames');
|
|
5
5
|
var react = require('@iconify/react');
|
|
6
|
-
var reactHookForm = require('react-hook-form');
|
|
7
6
|
var React = require('react');
|
|
7
|
+
var reactHookForm = require('react-hook-form');
|
|
8
8
|
|
|
9
9
|
var Blockquote = function (_a) {
|
|
10
10
|
var text = _a.text, citation = _a.citation, className = _a.className, citationAttribute = _a.citationAttribute, _b = _a.showIcon, showIcon = _b === void 0 ? true : _b;
|
|
@@ -167,7 +167,6 @@ Heading.displayName = 'Heading';
|
|
|
167
167
|
*/
|
|
168
168
|
var Icon = function (_a) {
|
|
169
169
|
var name = _a.name, _b = _a.size, size = _b === void 0 ? 24 : _b, color = _a.color, id = _a.id, className = _a.className, testID = _a.testID;
|
|
170
|
-
console.log('Icon name', name, color);
|
|
171
170
|
if (color) {
|
|
172
171
|
return (jsxRuntime.jsx(react.Icon, { "data-testid": testID || id || 'Icon', icon: name, width: size, height: size, color: color, className: className, fill: color || 'currentColor' }));
|
|
173
172
|
}
|
|
@@ -300,17 +299,6 @@ var ContentRowsLayout = function (_a) {
|
|
|
300
299
|
};
|
|
301
300
|
ContentRowsLayout.displayName = 'ContentRowsLayout';
|
|
302
301
|
|
|
303
|
-
var Form = function (_a) {
|
|
304
|
-
var children = _a.children, className = _a.className, submit = _a.submit, onSubmit = _a.onSubmit, hideSubmit = _a.hideSubmit, ariaSubmitLabel = _a.ariaSubmitLabel, submitID = _a.submitID, initialValues = _a.initialValues, _b = _a.submitVariant, submitVariant = _b === void 0 ? BTN_VARIANTS.PRIMARY : _b;
|
|
305
|
-
var _c = reactHookForm.useForm({
|
|
306
|
-
defaultValues: initialValues,
|
|
307
|
-
}), handleSubmit = _c.handleSubmit, formState = _c.formState;
|
|
308
|
-
var submitClasses = cx({ 'sr-only': hideSubmit });
|
|
309
|
-
console.log('FORM formState', formState);
|
|
310
|
-
return (jsxRuntime.jsx("div", { "data-testid": "Form", className: "w-full max-w-s @form @containers", children: jsxRuntime.jsxs("form", { onSubmit: handleSubmit(onSubmit), className: cx('form px-8 pt-6 pb-8 mb-4 w-2xs', className), children: [children, jsxRuntime.jsx("div", { className: 'flex items-center justify-end py-2', children: jsxRuntime.jsx(Button, { id: submitID || submit, className: submitClasses, ariaLabel: ariaSubmitLabel || submit || 'Submit', type: BTN_TYPES.SUBMIT, variant: submitVariant, children: submit }) })] }) }));
|
|
311
|
-
};
|
|
312
|
-
Form.displayName = 'Form';
|
|
313
|
-
|
|
314
302
|
/******************************************************************************
|
|
315
303
|
Copyright (c) Microsoft Corporation.
|
|
316
304
|
|
|
@@ -356,6 +344,22 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
356
344
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
357
345
|
};
|
|
358
346
|
|
|
347
|
+
var Form = function (_a) {
|
|
348
|
+
var children = _a.children, className = _a.className, submit = _a.submit, _b = _a.onSubmit, onSubmit = _b === void 0 ? function () { } : _b, onChange = _a.onChange, hideSubmit = _a.hideSubmit, ariaSubmitLabel = _a.ariaSubmitLabel, submitID = _a.submitID, _c = _a.submitVariant, submitVariant = _c === void 0 ? BTN_VARIANTS.PRIMARY : _c, _d = _a.initialValues, initialValues = _d === void 0 ? {} : _d;
|
|
349
|
+
var methods = reactHookForm.useForm({
|
|
350
|
+
defaultValues: initialValues,
|
|
351
|
+
});
|
|
352
|
+
React.useEffect(function () {
|
|
353
|
+
if (onChange && typeof onChange === 'function') {
|
|
354
|
+
var subscription_1 = methods.watch(function (value) { return onChange(value); });
|
|
355
|
+
return function () { return subscription_1.unsubscribe(); };
|
|
356
|
+
}
|
|
357
|
+
}, []);
|
|
358
|
+
var submitClasses = cx({ 'sr-only': hideSubmit });
|
|
359
|
+
return (jsxRuntime.jsx(reactHookForm.FormProvider, __assign({}, methods, { children: jsxRuntime.jsx("div", { "data-testid": "Form", className: "w-full max-w-s @form @containers", children: jsxRuntime.jsxs("form", { onSubmit: methods.handleSubmit(onSubmit), className: cx('form px-8 pt-6 pb-8 mb-4 w-2xs', className), children: [children, submit && (jsxRuntime.jsx("div", { className: "flex items-center justify-end py-2", children: jsxRuntime.jsx(Button, { id: submitID || submit, className: submitClasses, ariaLabel: ariaSubmitLabel || submit || 'Submit', type: BTN_TYPES.SUBMIT, variant: submitVariant, children: submit }) }))] }) }) })));
|
|
360
|
+
};
|
|
361
|
+
Form.displayName = 'Form';
|
|
362
|
+
|
|
359
363
|
var FieldTypes;
|
|
360
364
|
(function (FieldTypes) {
|
|
361
365
|
FieldTypes["TEXT"] = "text";
|
|
@@ -402,7 +406,7 @@ var InputType;
|
|
|
402
406
|
})(InputType || (InputType = {}));
|
|
403
407
|
|
|
404
408
|
var TextInput = React.forwardRef(function MyInput(_a, ref) {
|
|
405
|
-
var _b = _a.type, type = _b === void 0 ? InputType.TEXT : _b,
|
|
409
|
+
var _b = _a.type, type = _b === void 0 ? InputType.TEXT : _b, _c = _a.required, required = _c === void 0 ? false : _c, className = _a.className, onChange = _a.onChange, placeholder = _a.placeholder, icon = _a.icon, _d = _a.disabled, disabled = _d === void 0 ? false : _d, rest = __rest(_a, ["type", "required", "className", "onChange", "placeholder", "icon", "disabled"]);
|
|
406
410
|
React.useEffect(function () {
|
|
407
411
|
if (typeof window !== 'undefined') {
|
|
408
412
|
// eslint-disable-next-line global-require
|
|
@@ -411,6 +415,7 @@ var TextInput = React.forwardRef(function MyInput(_a, ref) {
|
|
|
411
415
|
}, []);
|
|
412
416
|
var format = 'dd/mm/yyyy';
|
|
413
417
|
var placeholderSet = type === 'date' ? format.toUpperCase() : placeholder;
|
|
418
|
+
// console.log('TextInput', rest);
|
|
414
419
|
if (type === InputType.TEXTAREA) {
|
|
415
420
|
return (jsxRuntime.jsx("div", { "data-testid": "TextInput", className: "relative", children: jsxRuntime.jsx("textarea", __assign({ ref: ref, required: required, "aria-required": required, disabled: disabled, placeholder: placeholderSet, onChange: onChange, rows: 4, className: cx('form-item text-input resize-none', className) }, rest)) }));
|
|
416
421
|
}
|
|
@@ -420,7 +425,7 @@ TextInput.displayName = 'TextInput';
|
|
|
420
425
|
|
|
421
426
|
var Checkbox = React.forwardRef(function MyInput(_a, ref) {
|
|
422
427
|
var id = _a.id, label = _a.label, required = _a.required, className = _a.className, disabled = _a.disabled, rest = __rest(_a, ["id", "label", "required", "className", "disabled"]);
|
|
423
|
-
return (jsxRuntime.jsxs("div", { "data-testid": "Checkbox", className: cx('flex items-center', className), children: [jsxRuntime.jsxs("div",
|
|
428
|
+
return (jsxRuntime.jsxs("div", { "data-testid": "Checkbox", className: cx('flex items-center', className), children: [jsxRuntime.jsxs("div", { className: "relative bg-none w-5 h-5 flex justify-center items-center", "aria-label": label, children: [jsxRuntime.jsx("input", __assign({ id: id, ref: ref, disabled: disabled, type: "checkbox", className: "form-item checkbox m-0 appearance-none peer h-full w-full shrink-0 focus:ring-2", required: required }, rest)), jsxRuntime.jsx("span", { className: "absolute transition-opacity opacity-0 pointer-events-none peer-checked:opacity-100 w-full h-full flex items-center justify-center top-0 left-0", children: jsxRuntime.jsx(Icon, { name: "mdi:check-bold", size: 12 }) })] }), label && (jsxRuntime.jsx("label", { className: "label pl-2 leading-none", htmlFor: id, children: label }))] }));
|
|
424
429
|
});
|
|
425
430
|
Checkbox.displayName = 'Checkbox';
|
|
426
431
|
|
|
@@ -430,15 +435,18 @@ var Label = function (_a) {
|
|
|
430
435
|
};
|
|
431
436
|
Label.displayName = 'Label';
|
|
432
437
|
|
|
433
|
-
var FormSelect = function (_a) {
|
|
434
|
-
var id = _a.id, name = _a.name, options = _a.options, required = _a.required, className = _a.className, disabled = _a.disabled;
|
|
435
|
-
|
|
436
|
-
|
|
438
|
+
var FormSelect = React.forwardRef(function MyInput(_a, ref) {
|
|
439
|
+
var id = _a.id, name = _a.name, options = _a.options, required = _a.required, className = _a.className, disabled = _a.disabled, rest = __rest(_a, ["id", "name", "options", "required", "className", "disabled"]);
|
|
440
|
+
if (!options) {
|
|
441
|
+
throw new Error('FormSelect requires options prop');
|
|
442
|
+
}
|
|
443
|
+
return (jsxRuntime.jsx("div", { id: id, className: cx('pb-2', className), children: jsxRuntime.jsxs("div", { className: "relative", children: [jsxRuntime.jsx("select", __assign({ ref: ref, id: id, name: name, disabled: disabled, required: required, className: "form-item text-input" }, rest, { children: options.map(function (option) { return (jsxRuntime.jsx("option", { value: option.value, disabled: option.disabled, children: option.label }, option.value)); }) })), jsxRuntime.jsx("div", { className: "form-icon absolute inset-0 z-10 pointer-events-none h-full w-12 items-center justify-center top-0 right-0 left-auto flex", children: jsxRuntime.jsx(Icon, { name: "mdi:chevron-down", size: 24, className: "pointer-events-none" }) })] }) }));
|
|
444
|
+
});
|
|
437
445
|
FormSelect.displayName = 'FormSelect';
|
|
438
446
|
|
|
439
447
|
var Radio = React.forwardRef(function MyInput(_a, ref) {
|
|
440
448
|
var id = _a.id, name = _a.name, label = _a.label, required = _a.required, className = _a.className, options = _a.options, rest = __rest(_a, ["id", "name", "label", "required", "className", "options"]);
|
|
441
|
-
return (jsxRuntime.jsx("div", { "data-testid": "Radio", className: cx('flex items-center', className), children: jsxRuntime.jsx("div",
|
|
449
|
+
return (jsxRuntime.jsx("div", { "data-testid": "Radio", className: cx('flex items-center', className), children: jsxRuntime.jsx("div", { className: cx('flex flex-col gap-2', className), "aria-label": label, id: id, children: options === null || options === void 0 ? void 0 : options.map(function (option) { return (jsxRuntime.jsxs("div", { className: "flex items-center relative", children: [jsxRuntime.jsxs("div", { className: "relative flex items-center", children: [jsxRuntime.jsx("input", __assign({ id: option.value, ref: ref, name: name, type: "radio", value: option.value, required: required, className: "form-item radio peer appearance-none m-0 p-0 w-4 h-4" }, rest)), jsxRuntime.jsx("div", { className: "form-icon opacity-0 peer-checked:opacity-100 absolute w-4 h-4 flex items-center justify-center top-0 left-0 pointer-events-none", children: jsxRuntime.jsx(Icon, { name: "mdi:circle", size: 12 }) })] }), jsxRuntime.jsx("label", { className: "label pl-2 leading-none", htmlFor: option.value, children: option.label })] }, option.value)); }) }) }));
|
|
442
450
|
});
|
|
443
451
|
Radio.displayName = 'Radio';
|
|
444
452
|
|
|
@@ -456,47 +464,44 @@ FileUpload.displayName = 'FileUpload';
|
|
|
456
464
|
|
|
457
465
|
var FormField = function (_a) {
|
|
458
466
|
var name = _a.name, type = _a.type, label = _a.label, required = _a.required, className = _a.className, icon = _a.icon, options = _a.options, disabled = _a.disabled, description = _a.description, showPasswordLabel = _a.showPasswordLabel, hidePasswordLabel = _a.hidePasswordLabel;
|
|
459
|
-
var _b =
|
|
460
|
-
var _c =
|
|
461
|
-
var renderType = function (type
|
|
467
|
+
var _b = React.useState(false), passwordShowStatus = _b[0], setPasswordShow = _b[1];
|
|
468
|
+
var _c = reactHookForm.useFormContext(), control = _c.control, register = _c.register;
|
|
469
|
+
var renderType = function (type) {
|
|
462
470
|
switch (type) {
|
|
463
471
|
case FieldTypes.TEXT:
|
|
464
|
-
return (jsxRuntime.jsx(TextInput, __assign({ type: InputType.TEXT, required: required, icon: icon, className: className, disabled: disabled },
|
|
472
|
+
return (jsxRuntime.jsx(TextInput, __assign({ type: InputType.TEXT, required: required, icon: icon, className: className, disabled: disabled }, register(name))));
|
|
465
473
|
case FieldTypes.PASSWORD: {
|
|
466
474
|
var toggleType = passwordShowStatus ? InputType.TEXT : InputType.PASSWORD;
|
|
467
475
|
var btnClass = 'appearance-none border-none bg-transparent flex items-center';
|
|
468
|
-
return (jsxRuntime.jsxs("div", { className: "relative", children: [jsxRuntime.jsx("span", { className: "absolute right-0 top-0 flex items-center justify-center h-full z-10 pr-2", onClick: function () { return setPasswordShow(function (pS) { return !pS; }); }, role: "button", tabIndex: 0, children: passwordShowStatus ? (jsxRuntime.jsx("button", { type: "button", "aria-label": hidePasswordLabel, className: cx(btnClass, 'form-icon'), children: jsxRuntime.jsx(Icon, { name: "mdi:eye-off", size: 24 }) })) : (jsxRuntime.jsx("button", { type: "button", "aria-label": showPasswordLabel, className: cx(btnClass, 'form-icon'), children: jsxRuntime.jsx(Icon, { name: "mdi:eye", size: 24 }) })) }), jsxRuntime.jsx(TextInput, __assign({ type: toggleType, required: required, icon: icon, className: className, disabled: disabled },
|
|
476
|
+
return (jsxRuntime.jsxs("div", { className: "relative", children: [jsxRuntime.jsx("span", { className: "absolute right-0 top-0 flex items-center justify-center h-full z-10 pr-2", onClick: function () { return setPasswordShow(function (pS) { return !pS; }); }, role: "button", tabIndex: 0, children: passwordShowStatus ? (jsxRuntime.jsx("button", { type: "button", "aria-label": hidePasswordLabel, className: cx(btnClass, 'form-icon'), children: jsxRuntime.jsx(Icon, { name: "mdi:eye-off", size: 24 }) })) : (jsxRuntime.jsx("button", { type: "button", "aria-label": showPasswordLabel, className: cx(btnClass, 'form-icon'), children: jsxRuntime.jsx(Icon, { name: "mdi:eye", size: 24 }) })) }), jsxRuntime.jsx(TextInput, __assign({ type: toggleType, required: required, icon: icon, className: className, disabled: disabled }, register(name)))] }));
|
|
469
477
|
}
|
|
470
478
|
case FieldTypes.TEXTAREA:
|
|
471
|
-
return (jsxRuntime.jsx(TextInput, __assign({ type: InputType.TEXTAREA, required: required, icon: icon, className: className, disabled: disabled },
|
|
479
|
+
return (jsxRuntime.jsx(TextInput, __assign({ type: InputType.TEXTAREA, required: required, icon: icon, className: className, disabled: disabled }, register(name))));
|
|
472
480
|
case FieldTypes.EMAIL:
|
|
473
|
-
return (jsxRuntime.jsx(TextInput, __assign({ type: InputType.EMAIL, required: required, icon: icon, className: className, disabled: disabled },
|
|
481
|
+
return (jsxRuntime.jsx(TextInput, __assign({ type: InputType.EMAIL, required: required, icon: icon, className: className, disabled: disabled }, register(name))));
|
|
474
482
|
case FieldTypes.DATE:
|
|
475
|
-
return (jsxRuntime.jsx(TextInput, __assign({ type: InputType.DATE, required: required, icon: icon, className: className, disabled: disabled },
|
|
483
|
+
return (jsxRuntime.jsx(TextInput, __assign({ type: InputType.DATE, required: required, icon: icon, className: className, disabled: disabled }, register(name))));
|
|
476
484
|
case FieldTypes.DATETIME:
|
|
477
|
-
return (jsxRuntime.jsx(TextInput, __assign({ type: InputType.DATETIME, required: required, icon: icon, className: className, disabled: disabled },
|
|
485
|
+
return (jsxRuntime.jsx(TextInput, __assign({ type: InputType.DATETIME, required: required, icon: icon, className: className, disabled: disabled }, register(name))));
|
|
478
486
|
case FieldTypes.NUMBER:
|
|
479
|
-
return (jsxRuntime.jsx(TextInput, __assign({ type: InputType.NUMBER, required: required, icon: icon, className: className, disabled: disabled },
|
|
487
|
+
return (jsxRuntime.jsx(TextInput, __assign({ type: InputType.NUMBER, required: required, icon: icon, className: className, disabled: disabled }, register(name))));
|
|
480
488
|
case FieldTypes.CHECKBOX:
|
|
481
|
-
return (jsxRuntime.jsx(Checkbox, __assign({ required: required, id: name, className: className, label: label, disabled: disabled },
|
|
489
|
+
return (jsxRuntime.jsx(Checkbox, __assign({ required: required, id: name, className: className, label: label, disabled: disabled }, register(name))));
|
|
482
490
|
case FieldTypes.RADIO:
|
|
483
|
-
return (jsxRuntime.jsx(Radio, __assign({ required: required, id: name, className: className, label: label, options: options, disabled: disabled },
|
|
491
|
+
return (jsxRuntime.jsx(Radio, __assign({ required: required, id: name, className: className, label: label, options: options, disabled: disabled }, register(name))));
|
|
484
492
|
case FieldTypes.SWITCH:
|
|
485
|
-
return jsxRuntime.jsx(Switch, __assign({ required: required, className: className, disabled: disabled },
|
|
493
|
+
return jsxRuntime.jsx(Switch, __assign({ id: name, required: required, className: className, disabled: disabled }, register(name)));
|
|
486
494
|
case FieldTypes.SELECT:
|
|
487
|
-
return (jsxRuntime.jsx(FormSelect, __assign({ required: required, id: name, className: className, disabled: disabled, label: label, options: options },
|
|
495
|
+
return (jsxRuntime.jsx(FormSelect, __assign({ required: required, id: name, className: className, disabled: disabled, label: label, options: options }, register(name))));
|
|
488
496
|
case FieldTypes.FILE:
|
|
489
|
-
return (jsxRuntime.jsx(FileUpload, __assign({ required: required, id: name, className: className, disabled: disabled },
|
|
497
|
+
return (jsxRuntime.jsx(FileUpload, __assign({ required: required, id: name, className: className, disabled: disabled }, register(name))));
|
|
490
498
|
default:
|
|
491
|
-
return (jsxRuntime.jsx(TextInput, __assign({ type: InputType.TEXT, required: required, disabled: disabled, icon: icon, className: className },
|
|
499
|
+
return (jsxRuntime.jsx(TextInput, __assign({ type: InputType.TEXT, required: required, disabled: disabled, icon: icon, className: className }, register(name))));
|
|
492
500
|
}
|
|
493
501
|
};
|
|
494
502
|
// TODO: HELPER CLASSES : data-[invalid=true]:bg-error data-[valid]:bg-success
|
|
495
503
|
var showLabel = label && type !== FieldTypes.CHECKBOX;
|
|
496
|
-
return (jsxRuntime.jsx("div", { className: "relative", children: jsxRuntime.jsxs("div", { "data-testid": "FormField", className: "mb-4", children: [showLabel && (jsxRuntime.jsx("div", { className: "flex items-baseline justify-between", children: jsxRuntime.jsx(Label, { label: label, id: name }) })), jsxRuntime.jsx(reactHookForm.Controller, { name:
|
|
497
|
-
var field = _a.field;
|
|
498
|
-
return renderType(type, field);
|
|
499
|
-
} }), description && jsxRuntime.jsx(Copy, { size: SIZE$1.SMALL, children: description })] }) }));
|
|
504
|
+
return (jsxRuntime.jsx("div", { className: "relative", children: jsxRuntime.jsxs("div", { "data-testid": "FormField", className: "mb-4", children: [showLabel && (jsxRuntime.jsx("div", { className: "flex items-baseline justify-between", children: jsxRuntime.jsx(Label, { label: label, id: name }) })), jsxRuntime.jsx(reactHookForm.Controller, { name: name, control: control, rules: { required: required }, render: function () { return renderType(type); } }), description && jsxRuntime.jsx(Copy, { size: SIZE$1.SMALL, children: description })] }) }));
|
|
500
505
|
};
|
|
501
506
|
FormField.displayName = 'FormField';
|
|
502
507
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Props } from './Form.types';
|
|
3
3
|
declare const Form: {
|
|
4
|
-
({ children, className, submit, onSubmit, hideSubmit, ariaSubmitLabel, submitID,
|
|
4
|
+
({ children, className, submit, onSubmit, onChange, hideSubmit, ariaSubmitLabel, submitID, submitVariant, initialValues, }: Props): React.ReactElement;
|
|
5
5
|
displayName: string;
|
|
6
6
|
};
|
|
7
7
|
export default Form;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { BTN_VARIANTS } from
|
|
2
|
+
import { BTN_VARIANTS } from '../Button/Button.types';
|
|
3
3
|
export interface Props {
|
|
4
4
|
/** The form inputs and content. */
|
|
5
5
|
children: React.ReactNode;
|
|
@@ -8,9 +8,9 @@ export interface Props {
|
|
|
8
8
|
/** Disable form inputs validation. */
|
|
9
9
|
noValidate?: boolean;
|
|
10
10
|
/** The submit handler that will fire once the form is submitted. */
|
|
11
|
-
onSubmit
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
onSubmit?: (values: any) => void;
|
|
12
|
+
/** The on change handler that will fire once the form is updated. */
|
|
13
|
+
onChange?: (values: any) => void;
|
|
14
14
|
/** The label for the submit button. */
|
|
15
15
|
submit?: string;
|
|
16
16
|
/** Hide submit button. */
|
|
@@ -21,7 +21,7 @@ export interface Props {
|
|
|
21
21
|
submitID?: string;
|
|
22
22
|
/** Initial form values. */
|
|
23
23
|
initialValues?: {
|
|
24
|
-
[k: string]:
|
|
24
|
+
[k: string]: any;
|
|
25
25
|
};
|
|
26
26
|
submitVariant?: BTN_VARIANTS;
|
|
27
27
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { OptionsType } from "../FormSelect/FormSelect.types";
|
|
1
2
|
export declare enum FieldTypes {
|
|
2
3
|
TEXT = "text",
|
|
3
4
|
TEXTAREA = "textarea",
|
|
@@ -23,12 +24,10 @@ export interface Props {
|
|
|
23
24
|
label?: string;
|
|
24
25
|
required?: boolean;
|
|
25
26
|
icon?: string;
|
|
26
|
-
options?:
|
|
27
|
-
value: string;
|
|
28
|
-
label: string;
|
|
29
|
-
}[];
|
|
27
|
+
options?: Array<OptionsType>;
|
|
30
28
|
disabled?: boolean;
|
|
31
29
|
description?: string;
|
|
32
30
|
showPasswordLabel?: string;
|
|
33
31
|
hidePasswordLabel?: string;
|
|
32
|
+
onChange?: (e: any) => void;
|
|
34
33
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Props } from './FormSelect.types';
|
|
3
|
-
declare const FormSelect:
|
|
4
|
-
({ id, name, options, required, className, disabled }: Props): React.ReactElement;
|
|
5
|
-
displayName: string;
|
|
6
|
-
};
|
|
3
|
+
declare const FormSelect: React.ForwardRefExoticComponent<Props & React.RefAttributes<unknown>>;
|
|
7
4
|
export default FormSelect;
|
|
8
5
|
export type { Props };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
type OptionsType = {
|
|
2
|
+
export type OptionsType = {
|
|
3
3
|
value: string;
|
|
4
4
|
label: string;
|
|
5
5
|
/** The selected option's value. */
|
|
@@ -8,7 +8,7 @@ type OptionsType = {
|
|
|
8
8
|
};
|
|
9
9
|
export interface Props {
|
|
10
10
|
/** The selected option's value. */
|
|
11
|
-
options
|
|
11
|
+
options?: Array<OptionsType>;
|
|
12
12
|
/** Unique id for the field, required for a11y. */
|
|
13
13
|
id: string;
|
|
14
14
|
/** The select visible default label value. */
|
|
@@ -38,4 +38,3 @@ export interface ItemProps {
|
|
|
38
38
|
itemIcon: string;
|
|
39
39
|
iconColor?: string;
|
|
40
40
|
}
|
|
41
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@4alldigital/foundation-ui--gamma",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.26.0",
|
|
4
4
|
"description": "Foundation UI Component library with GAMMA theme. ",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"publishConfig": {
|
|
25
25
|
"access": "public"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "4af02638666f2cbee201e3f1b2c4cf412fd84e86",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@headlessui/react": "^1.7.8",
|
|
30
30
|
"@heroicons/react": "^2.0.14",
|