@uniai-fe/uds-templates 0.3.6 → 0.3.7
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/package.json
CHANGED
|
@@ -52,7 +52,11 @@ export function ModalContainer({
|
|
|
52
52
|
|
|
53
53
|
return (
|
|
54
54
|
<ContextProvider>
|
|
55
|
-
<div
|
|
55
|
+
<div
|
|
56
|
+
className={clsx("uds-modal-container", className)}
|
|
57
|
+
// 변경 설명: Dialog 기본 submit 동작에서 현재 스택의 form을 조회하기 위한 식별자다.
|
|
58
|
+
data-modal-stack-key={stackKey}
|
|
59
|
+
>
|
|
56
60
|
{header ? <ModalHeaderContainer>{header}</ModalHeaderContainer> : null}
|
|
57
61
|
<ModalBody style={bodyStyle}>{body}</ModalBody>
|
|
58
62
|
{footer ? <div className="uds-modal-footer">{footer}</div> : null}
|
|
@@ -10,6 +10,30 @@ import {
|
|
|
10
10
|
import type { DialogTemplateOptions, ModalState } from "../../types";
|
|
11
11
|
import type { FieldValues } from "react-hook-form";
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Dialog 기본 submit 핸들러 생성기
|
|
15
|
+
* - formContextOptions가 활성화되고 confirm.onClick이 비어 있을 때에만 사용한다.
|
|
16
|
+
*/
|
|
17
|
+
function createDialogFormSubmitHandler(stackKey: string): () => void {
|
|
18
|
+
return () => {
|
|
19
|
+
const modalContainers = document.querySelectorAll<HTMLElement>(
|
|
20
|
+
"[data-modal-stack-key]",
|
|
21
|
+
);
|
|
22
|
+
const targetContainer = Array.from(modalContainers).find(
|
|
23
|
+
container => container.dataset.modalStackKey === stackKey,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
if (!targetContainer) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const formElement = targetContainer.querySelector("form");
|
|
31
|
+
if (formElement instanceof HTMLFormElement) {
|
|
32
|
+
formElement.requestSubmit();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
13
37
|
/**
|
|
14
38
|
* Modal Dialog Template; Dialog 모달 상태 생성기
|
|
15
39
|
* @component
|
|
@@ -55,6 +79,16 @@ export function createDialogModal<FormContext extends FieldValues>({
|
|
|
55
79
|
formContextOptions,
|
|
56
80
|
}: DialogTemplateOptions<FormContext>): ModalState<FormContext> {
|
|
57
81
|
const primary = resolveDialogPrimaryButton(confirm);
|
|
82
|
+
const hasFormContext = typeof formContextOptions !== "undefined";
|
|
83
|
+
const resolvedPrimary =
|
|
84
|
+
hasFormContext && typeof primary.onClick === "undefined"
|
|
85
|
+
? {
|
|
86
|
+
...primary,
|
|
87
|
+
// 변경 설명: Form.Provider가 있는 Dialog는 confirm 기본동작을 submit으로 연결하고 자동 close는 비활성화한다.
|
|
88
|
+
closeOnClick: primary.closeOnClick ?? false,
|
|
89
|
+
onClick: createDialogFormSubmitHandler(stackKey),
|
|
90
|
+
}
|
|
91
|
+
: primary;
|
|
58
92
|
|
|
59
93
|
const headerNode =
|
|
60
94
|
customHeader ??
|
|
@@ -71,7 +105,11 @@ export function createDialogModal<FormContext extends FieldValues>({
|
|
|
71
105
|
|
|
72
106
|
const footerButtons = footer
|
|
73
107
|
? undefined
|
|
74
|
-
: createDialogFooterButtons({
|
|
108
|
+
: createDialogFooterButtons({
|
|
109
|
+
stackKey,
|
|
110
|
+
primary: resolvedPrimary,
|
|
111
|
+
cancel,
|
|
112
|
+
});
|
|
75
113
|
|
|
76
114
|
return {
|
|
77
115
|
stackKey,
|