@ehfuse/forma
Version:
Advanced React state management library with individual field subscriptions - supports both forms and general state management with useFormaState
82 lines • 3.22 kB
TypeScript
/**
* useModal.ts
*
* 모달 상태 관리 및 뒤로가기 처리를 위한 React Hook
* Modal state management and back navigation handling React Hook
*
* @license MIT License
* @copyright 2025 KIM YOUNG JIN (ehfuse@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import { UseModalProps, UseModalReturn } from "../types/modal";
/**
* useModal - 모달 상태 관리 및 뒤로가기 처리 훅
*
* 모바일 환경에서 모달이 열려있을 때 뒤로가기를 누르면
* 페이지가 뒤로 가는 것이 아니라 모달이 닫히도록 처리합니다.
*
* 같은 modalId를 사용하면 여러 컴포넌트에서 같은 모달 상태를 공유합니다.
*
* Handles modal state and back navigation.
* When a modal is open and user presses back button,
* the modal closes instead of navigating back.
*
* Using the same modalId shares modal state across multiple components.
*
* @param props - modalId: 모달 ID (같은 ID면 공유), initialOpen: 초기 열림 상태, onClose: 닫힐 때 콜백
* @returns isOpen, open, close, toggle, modalId
*
* @example
* ```tsx
* // 독립적인 모달 (modalId 자동 생성)
* function MyComponent() {
* const modal = useModal({
* onClose: () => console.log('Modal closed')
* });
*
* return (
* <>
* <button onClick={modal.open}>Open Modal</button>
* <Dialog open={modal.isOpen} onClose={modal.close}>
* <DialogTitle>My Modal</DialogTitle>
* <DialogContent>Content here</DialogContent>
* </Dialog>
* </>
* );
* }
*
* // 공유 모달 (같은 modalId 사용)
* function ComponentA() {
* const modal = useModal({ modalId: 'shared-modal' });
* return <button onClick={modal.open}>Open from A</button>;
* }
*
* function ComponentB() {
* const modal = useModal({ modalId: 'shared-modal' });
* return (
* <Dialog open={modal.isOpen} onClose={modal.close}>
* <DialogTitle>Shared Modal</DialogTitle>
* </Dialog>
* );
* }
* ```
*/
export declare function useModal({ modalId: providedModalId, initialOpen, onClose: externalOnClose, }?: UseModalProps): UseModalReturn;
//# sourceMappingURL=useModal.d.ts.map