@uniai-fe/uds-templates 0.3.12 → 0.3.14

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniai-fe/uds-templates",
3
- "version": "0.3.12",
3
+ "version": "0.3.14",
4
4
  "description": "UNIAI Design System; UI Templates Package",
5
5
  "type": "module",
6
6
  "private": false,
@@ -42,33 +42,30 @@ export function ModalContainer({
42
42
  "--modal-dialog-body-padding": stylePaddingSize("rem", padding),
43
43
  } as CSSProperties)
44
44
  : undefined;
45
+ // 변경: 인라인 함수 컴포넌트 대신 조건부 JSX wrapper로 감싸 form subtree 리마운트를 막는다.
46
+ const container = (
47
+ <div
48
+ className={clsx("uds-modal-container", className)}
49
+ // 변경 설명: Dialog 기본 submit 동작에서 현재 스택의 form을 조회하기 위한 식별자다.
50
+ data-modal-stack-key={stackKey}
51
+ >
52
+ {header ? <ModalHeaderContainer>{header}</ModalHeaderContainer> : null}
53
+ <ModalBody style={bodyStyle}>{body}</ModalBody>
54
+ {footer ? <div className="uds-modal-footer">{footer}</div> : null}
55
+ {!footer && footerButtons && footerButtons.length ? (
56
+ <div className="uds-modal-footer">
57
+ <ModalFooterButtonWrapper
58
+ stackKey={stackKey}
59
+ buttons={footerButtons}
60
+ />
61
+ </div>
62
+ ) : null}
63
+ </div>
64
+ );
45
65
 
46
- const ContextProvider = ({ children }: { children: React.ReactNode }) =>
47
- typeof formContextOptions !== "undefined" ? (
48
- <Form.Provider options={formContextOptions}>{children}</Form.Provider>
49
- ) : (
50
- children
51
- );
52
-
53
- return (
54
- <ContextProvider>
55
- <div
56
- className={clsx("uds-modal-container", className)}
57
- // 변경 설명: Dialog 기본 submit 동작에서 현재 스택의 form을 조회하기 위한 식별자다.
58
- data-modal-stack-key={stackKey}
59
- >
60
- {header ? <ModalHeaderContainer>{header}</ModalHeaderContainer> : null}
61
- <ModalBody style={bodyStyle}>{body}</ModalBody>
62
- {footer ? <div className="uds-modal-footer">{footer}</div> : null}
63
- {!footer && footerButtons && footerButtons.length ? (
64
- <div className="uds-modal-footer">
65
- <ModalFooterButtonWrapper
66
- stackKey={stackKey}
67
- buttons={footerButtons}
68
- />
69
- </div>
70
- ) : null}
71
- </div>
72
- </ContextProvider>
66
+ return typeof formContextOptions !== "undefined" ? (
67
+ <Form.Provider options={formContextOptions}>{container}</Form.Provider>
68
+ ) : (
69
+ container
73
70
  );
74
71
  }
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
 
3
- import { useCallback } from "react";
3
+ import { useCallback, useEffect, useRef } from "react";
4
4
 
5
5
  import { useAtom } from "jotai";
6
6
 
@@ -28,6 +28,12 @@ const ensureDelay = (value?: number): number =>
28
28
  */
29
29
  export function useModal(): UseModalReturn {
30
30
  const [modalStacks, updateModalStack] = useAtom(modalStackAtom);
31
+ const modalStacksRef = useRef(modalStacks);
32
+
33
+ useEffect(() => {
34
+ // 변경 설명: closeModal이 최신 stack 상태를 기준으로 대상을 찾도록 현재 스냅샷 ref를 동기화한다.
35
+ modalStacksRef.current = modalStacks;
36
+ }, [modalStacks]);
31
37
 
32
38
  const newModal = useCallback(
33
39
  <FormContext extends FieldValues>(newStack: ModalState<FormContext>) => {
@@ -87,7 +93,7 @@ export function useModal(): UseModalReturn {
87
93
 
88
94
  const closeModal = useCallback(
89
95
  ({ stackKey, callback }: ModalCloseRequest) => {
90
- const targetStack = modalStacks.find(
96
+ const targetStack = modalStacksRef.current.find(
91
97
  stack => stack.stackKey === stackKey,
92
98
  );
93
99
 
@@ -121,7 +127,7 @@ export function useModal(): UseModalReturn {
121
127
  callback?.();
122
128
  }, resolvedDelay);
123
129
  },
124
- [modalStacks, updateModalStack],
130
+ [updateModalStack],
125
131
  );
126
132
 
127
133
  return { modalStacks, newModal, updateModal, closeModal };