@mantine/core
Version:
React components library focused on usability, accessibility and developer experience
41 lines (40 loc) • 1.03 kB
JavaScript
"use client";
import { useCallback, useState } from "react";
//#region packages/@mantine/core/src/components/Modal/use-modals-stack.ts
function useModalsStack(modals) {
const initialState = modals.reduce((acc, modal) => ({
...acc,
[modal]: false
}), {});
const [state, setState] = useState(initialState);
const open = useCallback((modal) => {
setState((current) => ({
...current,
[modal]: true
}));
}, []);
const close = useCallback((modal) => setState((current) => ({
...current,
[modal]: false
})), []);
const toggle = useCallback((modal) => setState((current) => ({
...current,
[modal]: !current[modal]
})), []);
return {
state,
open,
close,
closeAll: useCallback(() => setState(initialState), []),
toggle,
register: useCallback((modal) => ({
opened: state[modal],
onClose: () => close(modal),
stackId: modal
}), [state])
};
}
const useDrawersStack = useModalsStack;
//#endregion
export { useDrawersStack, useModalsStack };
//# sourceMappingURL=use-modals-stack.mjs.map