@mantine/modals
Advanced tools
Comparing version 3.7.0-alpha.0 to 3.7.0-alpha.1
@@ -83,6 +83,9 @@ 'use strict'; | ||
}); | ||
const closeAll = () => { | ||
const closeAll = (canceled) => { | ||
state.forEach((modal) => { | ||
var _a2, _b; | ||
return (_b = (_a2 = modal.props) == null ? void 0 : _a2.onClose) == null ? void 0 : _b.call(_a2); | ||
var _a2, _b, _c, _d; | ||
if (modal.type === "confirm" && canceled) { | ||
(_b = (_a2 = modal.props) == null ? void 0 : _a2.onCancel) == null ? void 0 : _b.call(_a2); | ||
} | ||
(_d = (_c = modal.props) == null ? void 0 : _c.onClose) == null ? void 0 : _d.call(_c); | ||
}); | ||
@@ -109,10 +112,13 @@ handlers.setState([]); | ||
}; | ||
const closeModal = (id) => { | ||
var _a2, _b; | ||
const closeModal = (id, canceled) => { | ||
var _a2, _b, _c, _d; | ||
const index = state.findIndex((item) => item.id === id); | ||
if (state.length <= 1) { | ||
closeAll(); | ||
closeAll(canceled); | ||
} else { | ||
const modal = state.find((item) => item.id === id); | ||
(_b = (_a2 = modal == null ? void 0 : modal.props) == null ? void 0 : _a2.onClose) == null ? void 0 : _b.call(_a2); | ||
if ((modal == null ? void 0 : modal.type) === "confirm" && canceled) { | ||
(_b = (_a2 = modal.props) == null ? void 0 : _a2.onCancel) == null ? void 0 : _b.call(_a2); | ||
} | ||
(_d = (_c = modal == null ? void 0 : modal.props) == null ? void 0 : _c.onClose) == null ? void 0 : _d.call(_c); | ||
index !== -1 && handlers.remove(index); | ||
@@ -146,3 +152,3 @@ setCurrentModal(state[state.length - 2] || { | ||
opened: state.length > 0, | ||
onClose: () => closeModal(currentModal == null ? void 0 : currentModal.id) | ||
onClose: () => closeModal(currentModal == null ? void 0 : currentModal.id, true) | ||
}), content), children); | ||
@@ -149,0 +155,0 @@ } |
@@ -75,6 +75,9 @@ import React, { useState } from 'react'; | ||
}); | ||
const closeAll = () => { | ||
const closeAll = (canceled) => { | ||
state.forEach((modal) => { | ||
var _a2, _b; | ||
return (_b = (_a2 = modal.props) == null ? void 0 : _a2.onClose) == null ? void 0 : _b.call(_a2); | ||
var _a2, _b, _c, _d; | ||
if (modal.type === "confirm" && canceled) { | ||
(_b = (_a2 = modal.props) == null ? void 0 : _a2.onCancel) == null ? void 0 : _b.call(_a2); | ||
} | ||
(_d = (_c = modal.props) == null ? void 0 : _c.onClose) == null ? void 0 : _d.call(_c); | ||
}); | ||
@@ -101,10 +104,13 @@ handlers.setState([]); | ||
}; | ||
const closeModal = (id) => { | ||
var _a2, _b; | ||
const closeModal = (id, canceled) => { | ||
var _a2, _b, _c, _d; | ||
const index = state.findIndex((item) => item.id === id); | ||
if (state.length <= 1) { | ||
closeAll(); | ||
closeAll(canceled); | ||
} else { | ||
const modal = state.find((item) => item.id === id); | ||
(_b = (_a2 = modal == null ? void 0 : modal.props) == null ? void 0 : _a2.onClose) == null ? void 0 : _b.call(_a2); | ||
if ((modal == null ? void 0 : modal.type) === "confirm" && canceled) { | ||
(_b = (_a2 = modal.props) == null ? void 0 : _a2.onCancel) == null ? void 0 : _b.call(_a2); | ||
} | ||
(_d = (_c = modal == null ? void 0 : modal.props) == null ? void 0 : _c.onClose) == null ? void 0 : _d.call(_c); | ||
index !== -1 && handlers.remove(index); | ||
@@ -138,3 +144,3 @@ setCurrentModal(state[state.length - 2] || { | ||
opened: state.length > 0, | ||
onClose: () => closeModal(currentModal == null ? void 0 : currentModal.id) | ||
onClose: () => closeModal(currentModal == null ? void 0 : currentModal.id, true) | ||
}), content), children); | ||
@@ -141,0 +147,0 @@ } |
@@ -29,3 +29,3 @@ /// <reference types="react" /> | ||
openContextModal: (modal: string, props: Record<string, any>) => string; | ||
closeModal: (id: string) => void; | ||
closeModal: (id: string, canceled?: boolean) => void; | ||
closeAll: () => void; | ||
@@ -32,0 +32,0 @@ } |
{ | ||
"name": "@mantine/modals", | ||
"description": "Modals manager based on Mantine components", | ||
"version": "3.7.0-alpha.0", | ||
"version": "3.7.0-alpha.1", | ||
"main": "cjs/index.js", | ||
@@ -17,5 +17,17 @@ "module": "esm/index.js", | ||
}, | ||
"keywords": [ | ||
"react", | ||
"next", | ||
"nextjs", | ||
"ui", | ||
"components", | ||
"ui-kit", | ||
"library", | ||
"frontend", | ||
"modal", | ||
"confirm" | ||
], | ||
"peerDependencies": { | ||
"@mantine/core": "3.7.0-alpha.0", | ||
"@mantine/hooks": "3.7.0-alpha.0", | ||
"@mantine/core": "3.7.0-alpha.1", | ||
"@mantine/hooks": "3.7.0-alpha.1", | ||
"react": ">=16.8.0", | ||
@@ -22,0 +34,0 @@ "react-dom": ">=16.8.0" |
@@ -1,6 +0,6 @@ | ||
# Mantine Notifications | ||
# Mantine modals manager | ||
Modals manager built on top of [Mantine](https://mantine.dev/) components library. | ||
Manage modals state | ||
[Documentation](https://mantine.dev/others/modals/) | ||
[View documentation](https://mantine.dev/) | ||
@@ -11,9 +11,6 @@ ## Installation | ||
# With yarn | ||
yarn add @mantine/modals @mantine/core @mantine/hooks | ||
yarn add @mantine/hooks @mantine/core @mantine/modals | ||
# With npm | ||
npm install @mantine/modals @mantine/core @mantine/hooks | ||
# With install-peerdeps | ||
npx install-peerdeps @mantine/modals | ||
npm install @mantine/hooks @mantine/core @mantine/modals | ||
``` | ||
@@ -23,2 +20,2 @@ | ||
All Mantine packages have MIT license. All @mantine/modals dependencies also have MIT license. | ||
MIT |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
62732
551
20