@pagamio/frontend-commons-lib 0.8.344 → 0.8.346
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.
|
@@ -27,6 +27,6 @@ import Button from './Button';
|
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
29
|
const Modal = ({ title, children, isOpen, onClose, size = 'md', dismissible = false, primaryButton, secondaryButton, headerContent, footerContent, className, ...rest }) => {
|
|
30
|
-
return (_jsxs(FlowbiteModal, { show: isOpen, onClose: onClose, size: size, dismissible: dismissible, className: cn('max-h-[90vh] mt-16 md:mt-0 md:max-h-full', className), ...rest, children: [_jsxs("div", { className: cn('flex items-center justify-between rounded-t border-b border-gray-200 p-4 dark:border-gray-600', !(title ?? headerContent) && 'border-b-0 pb-2'), children: [_jsx("div", { className: "text-xl font-semibold text-gray-900 dark:text-white", children: headerContent ?? title ?? null }), _jsxs("button", { type: "button", "aria-label": "Close", onClick: onClose, className: "ml-auto inline-flex items-center rounded-lg bg-transparent p-1.5 text-sm text-gray-400 hover:bg-gray-200 hover:text-gray-900 dark:hover:bg-gray-600 dark:hover:text-white", children: [_jsx(HiX, { className: "h-5 w-5" }), _jsx("span", { className: "sr-only", children: "Close modal" })] })] }), _jsx(FlowbiteModalBody, { children: _jsx("div", { className: "space-y-4", children: children }) }), (primaryButton || secondaryButton || footerContent) && (_jsx(FlowbiteModalFooter, { children: footerContent ?? (_jsxs("div", { className: "flex w-full justify-end gap-2", children: [secondaryButton && (_jsx(Button, { onClick: secondaryButton.onClick, variant: secondaryButton.variant ?? 'outline-primary', disabled: secondaryButton.loading ?? secondaryButton.disabled, className: secondaryButton.variant, children: secondaryButton.label })), primaryButton && (_jsx(Button, { onClick: primaryButton.onClick, variant: primaryButton.variant ?? 'primary', disabled: primaryButton.loading ?? primaryButton.disabled, className: primaryButton.variant, children: primaryButton.label }))] })) }))] }));
|
|
30
|
+
return (_jsxs(FlowbiteModal, { show: isOpen, onClose: onClose, size: size, dismissible: dismissible, className: cn('!z-[200] max-h-[90vh] mt-16 md:mt-0 md:max-h-full', className), ...rest, children: [_jsxs("div", { className: cn('flex items-center justify-between rounded-t border-b border-gray-200 p-4 dark:border-gray-600', !(title ?? headerContent) && 'border-b-0 pb-2'), children: [_jsx("div", { className: "text-xl font-semibold text-gray-900 dark:text-white", children: headerContent ?? title ?? null }), _jsxs("button", { type: "button", "aria-label": "Close", onClick: onClose, className: "ml-auto inline-flex items-center rounded-lg bg-transparent p-1.5 text-sm text-gray-400 hover:bg-gray-200 hover:text-gray-900 dark:hover:bg-gray-600 dark:hover:text-white", children: [_jsx(HiX, { className: "h-5 w-5" }), _jsx("span", { className: "sr-only", children: "Close modal" })] })] }), _jsx(FlowbiteModalBody, { children: _jsx("div", { className: "space-y-4", children: children }) }), (primaryButton || secondaryButton || footerContent) && (_jsx(FlowbiteModalFooter, { children: footerContent ?? (_jsxs("div", { className: "flex w-full justify-end gap-2", children: [secondaryButton && (_jsx(Button, { onClick: secondaryButton.onClick, variant: secondaryButton.variant ?? 'outline-primary', disabled: secondaryButton.loading ?? secondaryButton.disabled, className: secondaryButton.variant, children: secondaryButton.label })), primaryButton && (_jsx(Button, { onClick: primaryButton.onClick, variant: primaryButton.variant ?? 'primary', disabled: primaryButton.loading ?? primaryButton.disabled, className: primaryButton.variant, children: primaryButton.label }))] })) }))] }));
|
|
31
31
|
};
|
|
32
32
|
export default Modal;
|
|
@@ -8,32 +8,38 @@ import { useFormPersistence } from '../../form-engine/hooks/useFormPersistence';
|
|
|
8
8
|
const DrawerContent = ({ fields, onSubmit, isOpen, initialValues, submitButtonText = 'Submit', cancelButtonText = 'Cancel', showForm = true, showDrawerButtons = true, handleCloseDrawer, onFieldUpdate, onFieldChange, children, updateFieldOptions, updateFieldLabel, setFieldHidden, addField, updateFieldValidation, processInitialFieldUpdates, processingDependencyRef, pendingUpdatesRef, persistenceKey, clearOnClose = false, isDirtyRef, cancelRef, }) => {
|
|
9
9
|
const { saveFormData, restoreFormData, clearPersistedData, hasPersistedData } = useFormPersistence(persistenceKey);
|
|
10
10
|
const { addToast } = useToast();
|
|
11
|
-
//
|
|
12
|
-
// controlled
|
|
13
|
-
// unspecified fields
|
|
14
|
-
//
|
|
15
|
-
//
|
|
11
|
+
// For clearOnClose drawers, seed an `{ fieldName: '' }` baseline so every
|
|
12
|
+
// registered input starts controlled with a defined string value. Without
|
|
13
|
+
// this, RHF leaves unspecified fields as `undefined`, and Radix Select
|
|
14
|
+
// refuses to update its visual state when we reset on close — the
|
|
15
|
+
// controlled→uncontrolled transition is the bug we're fixing.
|
|
16
|
+
// We intentionally only seed empties when clearOnClose is true: legacy
|
|
17
|
+
// drawers that relied on `undefined`-vs-`""` distinctions in their submit
|
|
18
|
+
// payload (e.g. "field omitted means don't update") keep their exact
|
|
19
|
+
// previous behaviour.
|
|
16
20
|
const emptyFieldValues = useMemo(() => {
|
|
21
|
+
if (!clearOnClose)
|
|
22
|
+
return undefined;
|
|
17
23
|
const acc = {};
|
|
18
24
|
for (const f of fields) {
|
|
19
25
|
acc[f.name] = '';
|
|
20
26
|
}
|
|
21
27
|
return acc;
|
|
22
|
-
}, [fields]);
|
|
28
|
+
}, [clearOnClose, fields]);
|
|
23
29
|
// Determine initial values: initialValues take precedence over persisted data.
|
|
24
30
|
// For clearOnClose drawers we always start from the empty baseline so a
|
|
25
31
|
// stale persistence entry from a previous lifetime can't leak in.
|
|
26
32
|
const getEffectiveInitialValues = () => {
|
|
27
33
|
if (initialValues && Object.keys(initialValues).length > 0) {
|
|
28
|
-
return { ...emptyFieldValues, ...initialValues };
|
|
34
|
+
return emptyFieldValues ? { ...emptyFieldValues, ...initialValues } : initialValues;
|
|
29
35
|
}
|
|
30
36
|
if (!clearOnClose && persistenceKey && hasPersistedData()) {
|
|
31
37
|
const persistedData = restoreFormData();
|
|
32
38
|
if (persistedData) {
|
|
33
|
-
return
|
|
39
|
+
return persistedData;
|
|
34
40
|
}
|
|
35
41
|
}
|
|
36
|
-
return emptyFieldValues;
|
|
42
|
+
return emptyFieldValues ?? initialValues ?? {};
|
|
37
43
|
};
|
|
38
44
|
const { control, handleSubmit, watch, setValue, clearErrors, formState: { errors, isSubmitting }, reset, getValues, } = useForm({ mode: 'onBlur', defaultValues: getEffectiveInitialValues() });
|
|
39
45
|
const [pendingUpdateCount, setPendingUpdateCount] = useState(0);
|
|
@@ -68,7 +74,7 @@ const DrawerContent = ({ fields, onSubmit, isOpen, initialValues, submitButtonTe
|
|
|
68
74
|
previousIsOpenRef.current = !!isOpen;
|
|
69
75
|
if (wasOpen && !isOpen && clearOnCloseRef.current) {
|
|
70
76
|
clearPersistedDataRef.current();
|
|
71
|
-
resetRef.current(emptyFieldValuesRef.current);
|
|
77
|
+
resetRef.current(emptyFieldValuesRef.current ?? {});
|
|
72
78
|
}
|
|
73
79
|
}, [isOpen]);
|
|
74
80
|
const password = watch('password');
|
package/lib/styles.css
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagamio/frontend-commons-lib",
|
|
3
3
|
"description": "Pagamio library for Frontend reusable components like the form engine and table container",
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.346",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
7
7
|
"provenance": false
|