UNPKG

dynamic-modal

Version:

The dynamic-modal is a solution of creation different modals into project using a json configuration file

29 lines (28 loc) 893 B
'use client'; "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useModalHandler = useModalHandler; const react_1 = require("react"); function useModalHandler() { const initialState = { modalProps: { config: {}, close: () => { }, open: false, }, openModal: () => { }, }; const [modalConfig, setModalConfig] = (0, react_1.useState)(initialState); const openModal = (config) => { if (!config) { alert(`¡WARNING! this modal was not returned config, please check before use`); return; } setModalConfig({ openModal, modalProps: { config, open: true, close } }); }; const closeModal = () => setModalConfig(initialState); return { openModal, modalProps: { ...modalConfig.modalProps, close: closeModal }, }; }