@mantine/modals 7.0.0 → 7.0.1-alpha.0

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.
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { Box, Group, Button } from '@mantine/core';
3
- import { useModals } from './use-modals/use-modals.js';
3
+ import { useModals } from './use-modals/use-modals.mjs';
4
4
 
5
5
  var __defProp = Object.defineProperty;
6
6
  var __defProps = Object.defineProperties;
@@ -49,4 +49,4 @@ function ConfirmModal({
49
49
  }
50
50
 
51
51
  export { ConfirmModal };
52
- //# sourceMappingURL=ConfirmModal.js.map
52
+ //# sourceMappingURL=ConfirmModal.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfirmModal.mjs","sources":["../src/ConfirmModal.tsx"],"sourcesContent":["import React from 'react';\nimport { Button, Group, Box, ButtonProps, GroupProps } from '@mantine/core';\nimport { ConfirmLabels } from './context';\nimport { useModals } from './use-modals/use-modals';\n\nexport interface ConfirmModalProps {\n id?: string;\n children?: React.ReactNode;\n onCancel?(): void;\n onConfirm?(): void;\n closeOnConfirm?: boolean;\n closeOnCancel?: boolean;\n cancelProps?: ButtonProps & React.ComponentPropsWithoutRef<'button'>;\n confirmProps?: ButtonProps & React.ComponentPropsWithoutRef<'button'>;\n groupProps?: GroupProps;\n labels?: ConfirmLabels;\n}\n\nexport function ConfirmModal({\n id,\n cancelProps,\n confirmProps,\n labels = { cancel: '', confirm: '' },\n closeOnConfirm = true,\n closeOnCancel = true,\n groupProps,\n onCancel,\n onConfirm,\n children,\n}: ConfirmModalProps) {\n const { cancel: cancelLabel, confirm: confirmLabel } = labels;\n const ctx = useModals();\n\n const handleCancel = (event: React.MouseEvent<HTMLButtonElement>) => {\n typeof cancelProps?.onClick === 'function' && cancelProps?.onClick(event);\n typeof onCancel === 'function' && onCancel();\n closeOnCancel && ctx.closeModal(id!);\n };\n\n const handleConfirm = (event: React.MouseEvent<HTMLButtonElement>) => {\n typeof confirmProps?.onClick === 'function' && confirmProps?.onClick(event);\n typeof onConfirm === 'function' && onConfirm();\n closeOnConfirm && ctx.closeModal(id!);\n };\n\n return (\n <>\n {children && <Box mb=\"md\">{children}</Box>}\n\n <Group justify=\"flex-end\" {...groupProps}>\n <Button variant=\"default\" {...cancelProps} onClick={handleCancel}>\n {cancelProps?.children || cancelLabel}\n </Button>\n\n <Button {...confirmProps} onClick={handleConfirm}>\n {confirmProps?.children || confirmLabel}\n </Button>\n </Group>\n </>\n );\n}\n"],"names":[],"mappings":";;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChK,IAAI,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK;AAC/B,EAAE,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;AAChC,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC;AAClC,MAAM,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACxC,EAAE,I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Ref, useCallback } from 'react';
2
2
  import { Modal, getDefaultZIndex } from '@mantine/core';
3
3
  import { randomId } from '@mantine/hooks';
4
- import { ModalsContext } from './context.js';
5
- import { ConfirmModal } from './ConfirmModal.js';
6
- import { modalsReducer } from './reducer.js';
7
- import { useModalsEvents } from './events.js';
4
+ import { ModalsContext } from './context.mjs';
5
+ import { ConfirmModal } from './ConfirmModal.mjs';
6
+ import { modalsReducer } from './reducer.mjs';
7
+ import { useModalsEvents } from './events.mjs';
8
8
 
9
9
  var __defProp = Object.defineProperty;
10
10
  var __defProps = Object.defineProperties;
@@ -220,4 +220,4 @@ function ModalsProvider({ children, modalProps, labels, modals }) {
220
220
  }
221
221
 
222
222
  export { ModalsProvider };
223
- //# sourceMappingURL=ModalsProvider.js.map
223
+ //# sourceMappingURL=ModalsProvider.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ModalsProvider.mjs","sources":["../src/ModalsProvider.tsx"],"sourcesContent":["import React, { useCallback, useReducer, useRef } from 'react';\nimport { Modal, getDefaultZIndex } from '@mantine/core';\nimport { randomId } from '@mantine/hooks';\nimport {\n ModalsContext,\n ModalSettings,\n ConfirmLabels,\n OpenConfirmModal,\n OpenContextModal,\n ContextModalProps,\n ModalsContextProps,\n} from './context';\nimport { ConfirmModal } from './ConfirmModal';\nimport { modalsReducer } from './reducer';\nimport { useModalsEvents } from './events';\n\nexport interface ModalsProviderProps {\n /** Your app */\n children: React.ReactNode;\n\n /** Predefined modals */\n modals?: Record<string, React.FC<ContextModalProps<any>>>;\n\n /** Shared Modal component props, applied for every modal */\n modalProps?: ModalSettings;\n\n /** Confirm modal labels */\n labels?: ConfirmLabels;\n}\n\nfunction separateConfirmModalProps(props: OpenConfirmModal) {\n if (!props) {\n return { confirmProps: {}, modalProps: {} };\n }\n\n const {\n id,\n children,\n onCancel,\n onConfirm,\n closeOnConfirm,\n closeOnCancel,\n cancelProps,\n confirmProps,\n groupProps,\n labels,\n ...others\n } = props;\n\n return {\n confirmProps: {\n id,\n children,\n onCancel,\n onConfirm,\n closeOnConfirm,\n closeOnCancel,\n cancelProps,\n confirmProps,\n groupProps,\n labels,\n },\n modalProps: {\n id,\n ...others,\n },\n };\n}\n\nexport function ModalsProvider({ children, modalProps, labels, modals }: ModalsProviderProps) {\n const [state, dispatch] = useReducer(modalsReducer, { modals: [], current: null });\n const stateRef = useRef(state);\n stateRef.current = state;\n\n const closeAll = useCallback(\n (canceled?: boolean) => {\n dispatch({ type: 'CLOSE_ALL', canceled });\n },\n [stateRef, dispatch]\n );\n\n const openModal = useCallback(\n ({ modalId, ...props }: ModalSettings) => {\n const id = modalId || randomId();\n\n dispatch({\n type: 'OPEN',\n modal: {\n id,\n type: 'content',\n props,\n },\n });\n return id;\n },\n [dispatch]\n );\n\n const openConfirmModal = useCallback(\n ({ modalId, ...props }: OpenConfirmModal) => {\n const id = modalId || randomId();\n dispatch({\n type: 'OPEN',\n modal: {\n id,\n type: 'confirm',\n props,\n },\n });\n return id;\n },\n [dispatch]\n );\n\n const openContextModal = useCallback(\n (modal: string, { modalId, ...props }: OpenContextModal) => {\n const id = modalId || randomId();\n dispatch({\n type: 'OPEN',\n modal: {\n id,\n type: 'context',\n props,\n ctx: modal,\n },\n });\n return id;\n },\n [dispatch]\n );\n\n const closeModal = useCallback(\n (id: string, canceled?: boolean) => {\n dispatch({ type: 'CLOSE', modalId: id, canceled });\n },\n [stateRef, dispatch]\n );\n\n useModalsEvents({\n openModal,\n openConfirmModal,\n openContextModal: ({ modal, ...payload }: any) => openContextModal(modal, payload),\n closeModal,\n closeContextModal: closeModal,\n closeAllModals: closeAll,\n });\n\n const ctx: ModalsContextProps = {\n modals: state.modals,\n openModal,\n openConfirmModal,\n openContextModal,\n closeModal,\n closeContextModal: closeModal,\n closeAll,\n };\n\n const getCurrentModal = () => {\n const currentModal = stateRef.current.current;\n switch (currentModal?.type) {\n case 'context': {\n const { innerProps, ...rest } = currentModal.props;\n const ContextModal = modals![currentModal.ctx];\n\n return {\n modalProps: rest,\n content: <ContextModal innerProps={innerProps} context={ctx} id={currentModal.id} />,\n };\n }\n case 'confirm': {\n const { modalProps: separatedModalProps, confirmProps: separatedConfirmProps } =\n separateConfirmModalProps(currentModal.props);\n\n return {\n modalProps: separatedModalProps,\n content: (\n <ConfirmModal\n {...separatedConfirmProps}\n id={currentModal.id}\n labels={currentModal.props.labels || labels}\n />\n ),\n };\n }\n case 'content': {\n const { children: currentModalChildren, ...rest } = currentModal.props;\n\n return {\n modalProps: rest,\n content: <>{currentModalChildren}</>,\n };\n }\n default: {\n return {\n modalProps: {},\n content: null,\n };\n }\n }\n };\n\n const { modalProps: currentModalProps, content } = getCurrentModal();\n\n return (\n <ModalsContext.Provider value={ctx}>\n <Modal\n zIndex={getDefaultZIndex('modal') + 1}\n {...modalProps}\n {...currentModalProps}\n opened={state.modals.length > 0}\n onClose={() => closeModal(state.current!.id)}\n >\n {content}\n </Modal>\n\n {children}\n </ModalsContext.Provider>\n );\n}\n"],"names":[],"mappings":";;;;;;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChK,IA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,KAAK,EAAE,GAAG,EAAE,kBAAkB,KAAK,CAAC,aAAa;AACxH,IAAI,KAAK;AACT,IAAI,aAAa,CAAC,cAAc,CAAC,cAAc,CAAC;AAChD,MAAM,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC;AAC3C,KAAK,EAAE,UAAU,CAAC,EAAE,iBAAiB,CAAC,EAAE;AACxC,MAAM,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;AACrC,MAAM,OAAO,EAAE,MAAM,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;AACjD,KAAK,CAAC;AACN,IAAI,OAAO;AACX,GAAG,EAAE,QAAQ,CAAC,CAAC;AACf;;;;"}
@@ -4,4 +4,4 @@ const ModalsContext = createContext(null);
4
4
  ModalsContext.displayName = "@mantine/modals/ModalsContext";
5
5
 
6
6
  export { ModalsContext };
7
- //# sourceMappingURL=context.js.map
7
+ //# sourceMappingURL=context.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.mjs","sources":["../src/context.ts"],"sourcesContent":["import { createContext, ReactNode } from 'react';\nimport { ModalProps } from '@mantine/core';\nimport type { ConfirmModalProps } from './ConfirmModal';\n\nexport type ModalSettings = Partial<Omit<ModalProps, 'opened'>> & { modalId?: string };\n\nexport type ConfirmLabels = Record<'confirm' | 'cancel', ReactNode>;\n\nexport interface OpenConfirmModal extends ModalSettings, ConfirmModalProps {}\nexport interface OpenContextModal<CustomProps extends Record<string, any> = {}>\n extends ModalSettings {\n innerProps: CustomProps;\n}\n\nexport interface ContextModalProps<T extends Record<string, any> = {}> {\n context: ModalsContextProps;\n innerProps: T;\n id: string;\n}\n\nexport type ModalState =\n | { id: string; props: ModalSettings; type: 'content' }\n | { id: string; props: OpenConfirmModal; type: 'confirm' }\n | { id: string; props: OpenContextModal; type: 'context'; ctx: string };\n\nexport interface ModalsContextProps {\n modals: ModalState[];\n openModal: (props: ModalSettings) => string;\n openConfirmModal: (props: OpenConfirmModal) => string;\n openContextModal: <TKey extends MantineModal>(\n modal: TKey,\n props: OpenContextModal<Parameters<MantineModals[TKey]>[0]['innerProps']>\n ) => string;\n closeModal: (id: string, canceled?: boolean) => void;\n closeContextModal: <TKey extends MantineModal>(id: TKey, canceled?: boolean) => void;\n closeAll: () => void;\n}\n\nexport type MantineModalsOverride = {};\n\nexport type MantineModalsOverwritten = MantineModalsOverride extends {\n modals: Record<string, React.FC<ContextModalProps<any>>>;\n}\n ? MantineModalsOverride\n : {\n modals: Record<string, React.FC<ContextModalProps<any>>>;\n };\n\nexport type MantineModals = MantineModalsOverwritten['modals'];\n\nexport type MantineModal = keyof MantineModals;\n\nexport const ModalsContext = createContext<ModalsContextProps>(null as any);\nModalsContext.displayName = '@mantine/modals/ModalsContext';\n"],"names":[],"mappings":";;AACY,MAAC,aAAa,GAAG,aAAa,CAAC,IAAI,EAAE;AACjD,aAAa,CAAC,WAAW,GAAG,+BAA+B;;;;"}
@@ -15,4 +15,4 @@ const modals = {
15
15
  };
16
16
 
17
17
  export { closeAllModals, closeModal, createEvent, modals, openConfirmModal, openContextModal, openModal, useModalsEvents };
18
- //# sourceMappingURL=events.js.map
18
+ //# sourceMappingURL=events.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.mjs","sources":["../src/events.ts"],"sourcesContent":["import { createUseExternalEvents } from '@mantine/core';\nimport {\n MantineModal,\n MantineModals,\n ModalSettings,\n OpenConfirmModal,\n OpenContextModal,\n} from './context';\n\ntype ModalsEvents = {\n openModal(payload: ModalSettings): void;\n closeModal(id: string): void;\n closeContextModal<TKey extends MantineModal>(id: TKey): void;\n closeAllModals(): void;\n openConfirmModal(payload: OpenConfirmModal): void;\n openContextModal<TKey extends MantineModal>(\n payload: OpenContextModal<Parameters<MantineModals[TKey]>[0]['innerProps']> & { modal: TKey }\n ): void;\n};\n\nexport const [useModalsEvents, createEvent] =\n createUseExternalEvents<ModalsEvents>('mantine-modals');\n\nexport const openModal = createEvent('openModal');\nexport const closeModal = createEvent('closeModal');\nexport const closeContextModal: ModalsEvents['closeContextModal'] = <TKey extends MantineModal>(\n id: TKey\n) => createEvent('closeContextModal')(id);\nexport const closeAllModals = createEvent('closeAllModals');\nexport const openConfirmModal = createEvent('openConfirmModal');\nexport const openContextModal: ModalsEvents['openContextModal'] = <TKey extends MantineModal>(\n payload: OpenContextModal<Parameters<MantineModals[TKey]>[0]['innerProps']> & { modal: TKey }\n) => createEvent('openContextModal')(payload);\n\nexport const modals = {\n open: openModal,\n close: closeModal,\n closeAll: closeAllModals,\n openConfirmModal,\n openContextModal,\n};\n"],"names":[],"mappings":";;AACY,MAAC,CAAC,eAAe,EAAE,WAAW,CAAC,GAAG,uBAAuB,CAAC,gBAAgB,EAAE;AAC5E,MAAC,SAAS,GAAG,WAAW,CAAC,WAAW,EAAE;AACtC,MAAC,UAAU,GAAG,WAAW,CAAC,YAAY,EAAE;AAExC,MAAC,cAAc,GAAG,WAAW,CAAC,gBAAgB,EAAE;AAChD,MAAC,gBAAgB,GAAG,WAAW,CAAC,kBAAkB,EAAE;AACpD,MAAC,gBAAgB,GAAG,CAAC,OAAO,KAAK,WAAW,CAAC,kBAAkB,CAAC,CAAC,OAAO,EAAE;AAC1E,MAAC,MAAM,GAAG;AACtB,EAAE,IAAI,EAAE,SAAS;AACjB,EAAE,KAAK,EAAE,UAAU;AACnB,EAAE,QAAQ,EAAE,cAAc;AAC1B,EAAE,gBAAgB;AAClB,EAAE,gBAAgB;AAClB;;;;"}
package/esm/index.mjs ADDED
@@ -0,0 +1,4 @@
1
+ export { ModalsProvider } from './ModalsProvider.mjs';
2
+ export { useModals } from './use-modals/use-modals.mjs';
3
+ export { closeAllModals, closeModal, modals, openConfirmModal, openContextModal, openModal } from './events.mjs';
4
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -44,4 +44,4 @@ function modalsReducer(state, action) {
44
44
  }
45
45
 
46
46
  export { modalsReducer };
47
- //# sourceMappingURL=reducer.js.map
47
+ //# sourceMappingURL=reducer.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reducer.mjs","sources":["../src/reducer.ts"],"sourcesContent":["import { ModalState } from './context';\n\ninterface ModalsState {\n modals: ModalState[];\n\n /**\n * Modal that is currently open or was the last open one.\n * Keeping the last one is necessary for providing a clean exit transition.\n */\n current: ModalState | null;\n}\n\ninterface OpenAction {\n type: 'OPEN';\n modal: ModalState;\n}\n\ninterface CloseAction {\n type: 'CLOSE';\n modalId: string;\n canceled?: boolean;\n}\n\ninterface CloseAllAction {\n type: 'CLOSE_ALL';\n canceled?: boolean;\n}\n\nfunction handleCloseModal(modal: ModalState, canceled?: boolean) {\n if (canceled && modal.type === 'confirm') {\n modal.props.onCancel?.();\n }\n\n modal.props.onClose?.();\n}\n\nexport function modalsReducer(\n state: ModalsState,\n action: OpenAction | CloseAction | CloseAllAction\n): ModalsState {\n switch (action.type) {\n case 'OPEN': {\n return {\n current: action.modal,\n modals: [...state.modals, action.modal],\n };\n }\n case 'CLOSE': {\n const modal = state.modals.find((m) => m.id === action.modalId);\n if (!modal) {\n return state;\n }\n\n handleCloseModal(modal, action.canceled);\n\n const remainingModals = state.modals.filter((m) => m.id !== action.modalId);\n\n return {\n current: remainingModals[remainingModals.length - 1] || state.current,\n modals: remainingModals,\n };\n }\n case 'CLOSE_ALL': {\n if (!state.modals.length) {\n return state;\n }\n\n // Resolve modal stack from top to bottom\n state.modals\n .concat()\n .reverse()\n .forEach((modal) => {\n handleCloseModal(modal, action.canceled);\n });\n\n return {\n current: state.current,\n modals: [],\n };\n }\n default: {\n return state;\n }\n }\n}\n"],"names":[],"mappings":"AAAA,SAAS,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE;AAC3C,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;AACrB,EAAE,IAAI,QAAQ,IAAI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AAO;AAC7E,QAAQ,MAAM,EAAE,eAAe;AAC/B,OAAO,CAAC;AACR,KAAK;AACL,IAAI,KAAK,WAAW,EAAE;AACtB,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE;AAChC,QAAQ,OAAO,KAAK,CAAC;AACrB,OAAO;AACP,MAAM,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK;AACzD,QAAQ,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;AACjD,OAAO,CAAC,CAAC;AACT,MAAM,OAAO;AACb,QAAQ,OAAO,EAAE,KAAK,CAAC,OAAO;AAC9B,QAAQ,MAAM,EAAE,EAAE;AAClB,OAAO,CAAC;AACR,KAAK;AACL,IAAI,SAAS;AACb,MAAM,OAAO,KAAK,CAAC;AACnB,KAAK;AACL,GAAG;AACH;;;;"}
@@ -1,5 +1,5 @@
1
1
  import { useContext } from 'react';
2
- import { ModalsContext } from '../context.js';
2
+ import { ModalsContext } from '../context.mjs';
3
3
 
4
4
  function useModals() {
5
5
  const ctx = useContext(ModalsContext);
@@ -12,4 +12,4 @@ function useModals() {
12
12
  }
13
13
 
14
14
  export { useModals };
15
- //# sourceMappingURL=use-modals.js.map
15
+ //# sourceMappingURL=use-modals.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-modals.mjs","sources":["../../src/use-modals/use-modals.ts"],"sourcesContent":["import { useContext } from 'react';\nimport { ModalsContext } from '../context';\n\nexport function useModals() {\n const ctx = useContext(ModalsContext);\n\n if (!ctx) {\n throw new Error(\n '[@mantine/modals] useModals hook was called outside of context, wrap your app with ModalsProvider component'\n );\n }\n\n return ctx;\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,SAAS,GAAG;AAC5B,EAAE,MAAM,GAAG,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;AACxC,EAAE,IAAI,CAAC,GAAG,EAAE;AACZ,IAAI,MAAM,IAAI,KAAK;AACnB,MAAM,6GAA6G;AACnH,KAAK,CAAC;AACN,GAAG;AACH,EAAE,OAAO,GAAG,CAAC;AACb;;;;"}
@@ -0,0 +1,6 @@
1
+ export { ModalsProvider } from './ModalsProvider';
2
+ export { useModals } from './use-modals/use-modals';
3
+ export { openModal, closeModal, closeAllModals, openConfirmModal, openContextModal, modals, } from './events';
4
+ export type { ModalsProviderProps } from './ModalsProvider';
5
+ export type { ContextModalProps, MantineModalsOverride, MantineModals, MantineModal, } from './context';
6
+ //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,14 +1,20 @@
1
1
  {
2
2
  "name": "@mantine/modals",
3
3
  "description": "Modals manager based on Mantine components",
4
- "version": "7.0.0",
4
+ "version": "7.0.1-alpha.0",
5
+ "main": "./cjs/index.js",
5
6
  "types": "./lib/index.d.ts",
6
- "module": "./esm/index.js",
7
+ "module": "./esm/index.mjs",
7
8
  "exports": {
8
9
  ".": {
9
- "import": "./esm/index.js",
10
- "require": "./cjs/index.js",
11
- "types": "./lib/index.d.ts"
10
+ "import": {
11
+ "types": "./lib/index.d.mts",
12
+ "default": "./esm/index.mjs"
13
+ },
14
+ "require": {
15
+ "types": "./lib/index.d.ts",
16
+ "default": "./cjs/index.js"
17
+ }
12
18
  },
13
19
  "./styles.css": "./esm/index.css"
14
20
  },
@@ -34,8 +40,8 @@
34
40
  "confirm"
35
41
  ],
36
42
  "peerDependencies": {
37
- "@mantine/core": "7.0.0",
38
- "@mantine/hooks": "7.0.0",
43
+ "@mantine/core": "7.0.1-alpha.0",
44
+ "@mantine/hooks": "7.0.1-alpha.0",
39
45
  "react": "^18.2.0",
40
46
  "react-dom": "^18.2.0"
41
47
  },
@@ -1 +0,0 @@
1
- {"version":3,"file":"ConfirmModal.js","sources":["../src/ConfirmModal.tsx"],"sourcesContent":["import React from 'react';\nimport { Button, Group, Box, ButtonProps, GroupProps } from '@mantine/core';\nimport { ConfirmLabels } from './context';\nimport { useModals } from './use-modals/use-modals';\n\nexport interface ConfirmModalProps {\n id?: string;\n children?: React.ReactNode;\n onCancel?(): void;\n onConfirm?(): void;\n closeOnConfirm?: boolean;\n closeOnCancel?: boolean;\n cancelProps?: ButtonProps & React.ComponentPropsWithoutRef<'button'>;\n confirmProps?: ButtonProps & React.ComponentPropsWithoutRef<'button'>;\n groupProps?: GroupProps;\n labels?: ConfirmLabels;\n}\n\nexport function ConfirmModal({\n id,\n cancelProps,\n confirmProps,\n labels = { cancel: '', confirm: '' },\n closeOnConfirm = true,\n closeOnCancel = true,\n groupProps,\n onCancel,\n onConfirm,\n children,\n}: ConfirmModalProps) {\n const { cancel: cancelLabel, confirm: confirmLabel } = labels;\n const ctx = useModals();\n\n const handleCancel = (event: React.MouseEvent<HTMLButtonElement>) => {\n typeof cancelProps?.onClick === 'function' && cancelProps?.onClick(event);\n typeof onCancel === 'function' && onCancel();\n closeOnCancel && ctx.closeModal(id!);\n };\n\n const handleConfirm = (event: React.MouseEvent<HTMLButtonElement>) => {\n typeof confirmProps?.onClick === 'function' && confirmProps?.onClick(event);\n typeof onConfirm === 'function' && onConfirm();\n closeOnConfirm && ctx.closeModal(id!);\n };\n\n return (\n <>\n {children && <Box mb=\"md\">{children}</Box>}\n\n <Group justify=\"flex-end\" {...groupProps}>\n <Button variant=\"default\" {...cancelProps} onClick={handleCancel}>\n {cancelProps?.children || cancelLabel}\n </Button>\n\n <Button {...confirmProps} onClick={handleConfirm}>\n {confirmProps?.children || confirmLabel}\n </Button>\n </Group>\n </>\n );\n}\n"],"names":[],"mappings":";;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,C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KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,cAAc,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,UAAU,CAAC,kBAAkB,KAAK,CAAC,aAAa,CAAC,MAAM,EAAE,aAAa,CAAC,cAAc,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,WAAW,CAAC,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC,WAAW,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,WAAW,CAAC,QAAQ,KAAK,WAAW,CAAC,kBAAkB,KAAK,CAAC,aAAa,CAAC,MAAM,EAAE,aAAa,CAAC,cAAc,CAAC,EAAE,EAAE,YAAY,CAAC,EAAE,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,EAAE,CAAC,YAAY,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,YAAY,CAAC,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,CAAC;AACvoB;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"ModalsProvider.js","sources":["../src/ModalsProvider.tsx"],"sourcesContent":["import React, { useCallback, useReducer, useRef } from 'react';\nimport { Modal, getDefaultZIndex } from '@mantine/core';\nimport { randomId } from '@mantine/hooks';\nimport {\n ModalsContext,\n ModalSettings,\n ConfirmLabels,\n OpenConfirmModal,\n OpenContextModal,\n ContextModalProps,\n ModalsContextProps,\n} from './context';\nimport { ConfirmModal } from './ConfirmModal';\nimport { modalsReducer } from './reducer';\nimport { useModalsEvents } from './events';\n\nexport interface ModalsProviderProps {\n /** Your app */\n children: React.ReactNode;\n\n /** Predefined modals */\n modals?: Record<string, React.FC<ContextModalProps<any>>>;\n\n /** Shared Modal component props, applied for every modal */\n modalProps?: ModalSettings;\n\n /** Confirm modal labels */\n labels?: ConfirmLabels;\n}\n\nfunction separateConfirmModalProps(props: OpenConfirmModal) {\n if (!props) {\n return { confirmProps: {}, modalProps: {} };\n }\n\n const {\n id,\n children,\n onCancel,\n onConfirm,\n closeOnConfirm,\n closeOnCancel,\n cancelProps,\n confirmProps,\n groupProps,\n labels,\n ...others\n } = props;\n\n return {\n confirmProps: {\n id,\n children,\n onCancel,\n onConfirm,\n closeOnConfirm,\n closeOnCancel,\n cancelProps,\n confirmProps,\n groupProps,\n labels,\n },\n modalProps: {\n id,\n ...others,\n },\n };\n}\n\nexport function ModalsProvider({ children, modalProps, labels, modals }: ModalsProviderProps) {\n const [state, dispatch] = useReducer(modalsReducer, { modals: [], current: null });\n const stateRef = useRef(state);\n stateRef.current = state;\n\n const closeAll = useCallback(\n (canceled?: boolean) => {\n dispatch({ type: 'CLOSE_ALL', canceled });\n },\n [stateRef, dispatch]\n );\n\n const openModal = useCallback(\n ({ modalId, ...props }: ModalSettings) => {\n const id = modalId || randomId();\n\n dispatch({\n type: 'OPEN',\n modal: {\n id,\n type: 'content',\n props,\n },\n });\n return id;\n },\n [dispatch]\n );\n\n const openConfirmModal = useCallback(\n ({ modalId, ...props }: OpenConfirmModal) => {\n const id = modalId || randomId();\n dispatch({\n type: 'OPEN',\n modal: {\n id,\n type: 'confirm',\n props,\n },\n });\n return id;\n },\n [dispatch]\n );\n\n const openContextModal = useCallback(\n (modal: string, { modalId, ...props }: OpenContextModal) => {\n const id = modalId || randomId();\n dispatch({\n type: 'OPEN',\n modal: {\n id,\n type: 'context',\n props,\n ctx: modal,\n },\n });\n return id;\n },\n [dispatch]\n );\n\n const closeModal = useCallback(\n (id: string, canceled?: boolean) => {\n dispatch({ type: 'CLOSE', modalId: id, canceled });\n },\n [stateRef, dispatch]\n );\n\n useModalsEvents({\n openModal,\n openConfirmModal,\n openContextModal: ({ modal, ...payload }: any) => openContextModal(modal, payload),\n closeModal,\n closeContextModal: closeModal,\n closeAllModals: closeAll,\n });\n\n const ctx: ModalsContextProps = {\n modals: state.modals,\n openModal,\n openConfirmModal,\n openContextModal,\n closeModal,\n closeContextModal: closeModal,\n closeAll,\n };\n\n const getCurrentModal = () => {\n const currentModal = stateRef.current.current;\n switch (currentModal?.type) {\n case 'context': {\n const { innerProps, ...rest } = currentModal.props;\n const ContextModal = modals![currentModal.ctx];\n\n return {\n modalProps: rest,\n content: <ContextModal innerProps={innerProps} context={ctx} id={currentModal.id} />,\n };\n }\n case 'confirm': {\n const { modalProps: separatedModalProps, confirmProps: separatedConfirmProps } =\n separateConfirmModalProps(currentModal.props);\n\n return {\n modalProps: separatedModalProps,\n content: (\n <ConfirmModal\n {...separatedConfirmProps}\n id={currentModal.id}\n labels={currentModal.props.labels || labels}\n />\n ),\n };\n }\n case 'content': {\n const { children: currentModalChildren, ...rest } = currentModal.props;\n\n return {\n modalProps: rest,\n content: <>{currentModalChildren}</>,\n };\n }\n default: {\n return {\n modalProps: {},\n content: null,\n };\n }\n }\n };\n\n const { modalProps: currentModalProps, content } = getCurrentModal();\n\n return (\n <ModalsContext.Provider value={ctx}>\n <Modal\n zIndex={getDefaultZIndex('modal') + 1}\n {...modalProps}\n {...currentModalProps}\n opened={state.modals.length > 0}\n onClose={() => closeModal(state.current!.id)}\n >\n {content}\n </Modal>\n\n {children}\n </ModalsContext.Provider>\n );\n}\n"],"names":[],"mappings":";;;;;;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAA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e,EAAE,CAAC;AACvE,EAAE,uBAAuB,KAAK,CAAC,aAAa,CAAC,aAAa,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,kBAAkB,KAAK,CAAC,aAAa;AACxH,IAAI,KAAK;AACT,IAAI,aAAa,CAAC,cAAc,CAAC,cAAc,CAAC;AAChD,MAAM,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC;AAC3C,KAAK,EAAE,UAAU,CAAC,EAAE,iBAAiB,CAAC,EAAE;AACxC,MAAM,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;AACrC,MAAM,OAAO,EAAE,MAAM,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;AACjD,KAAK,CAAC;AACN,IAAI,OAAO;AACX,GAAG,EAAE,QAAQ,CAAC,CAAC;AACf;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"context.js","sources":["../src/context.ts"],"sourcesContent":["import { createContext, ReactNode } from 'react';\nimport { ModalProps } from '@mantine/core';\nimport type { ConfirmModalProps } from './ConfirmModal';\n\nexport type ModalSettings = Partial<Omit<ModalProps, 'opened'>> & { modalId?: string };\n\nexport type ConfirmLabels = Record<'confirm' | 'cancel', ReactNode>;\n\nexport interface OpenConfirmModal extends ModalSettings, ConfirmModalProps {}\nexport interface OpenContextModal<CustomProps extends Record<string, any> = {}>\n extends ModalSettings {\n innerProps: CustomProps;\n}\n\nexport interface ContextModalProps<T extends Record<string, any> = {}> {\n context: ModalsContextProps;\n innerProps: T;\n id: string;\n}\n\nexport type ModalState =\n | { id: string; props: ModalSettings; type: 'content' }\n | { id: string; props: OpenConfirmModal; type: 'confirm' }\n | { id: string; props: OpenContextModal; type: 'context'; ctx: string };\n\nexport interface ModalsContextProps {\n modals: ModalState[];\n openModal: (props: ModalSettings) => string;\n openConfirmModal: (props: OpenConfirmModal) => string;\n openContextModal: <TKey extends MantineModal>(\n modal: TKey,\n props: OpenContextModal<Parameters<MantineModals[TKey]>[0]['innerProps']>\n ) => string;\n closeModal: (id: string, canceled?: boolean) => void;\n closeContextModal: <TKey extends MantineModal>(id: TKey, canceled?: boolean) => void;\n closeAll: () => void;\n}\n\nexport type MantineModalsOverride = {};\n\nexport type MantineModalsOverwritten = MantineModalsOverride extends {\n modals: Record<string, React.FC<ContextModalProps<any>>>;\n}\n ? MantineModalsOverride\n : {\n modals: Record<string, React.FC<ContextModalProps<any>>>;\n };\n\nexport type MantineModals = MantineModalsOverwritten['modals'];\n\nexport type MantineModal = keyof MantineModals;\n\nexport const ModalsContext = createContext<ModalsContextProps>(null as any);\nModalsContext.displayName = '@mantine/modals/ModalsContext';\n"],"names":[],"mappings":";;AACY,MAAC,aAAa,GAAG,aAAa,CAAC,IAAI,EAAE;AACjD,aAAa,CAAC,WAAW,GAAG,+BAA+B;;;;"}
package/esm/events.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"events.js","sources":["../src/events.ts"],"sourcesContent":["import { createUseExternalEvents } from '@mantine/core';\nimport {\n MantineModal,\n MantineModals,\n ModalSettings,\n OpenConfirmModal,\n OpenContextModal,\n} from './context';\n\ntype ModalsEvents = {\n openModal(payload: ModalSettings): void;\n closeModal(id: string): void;\n closeContextModal<TKey extends MantineModal>(id: TKey): void;\n closeAllModals(): void;\n openConfirmModal(payload: OpenConfirmModal): void;\n openContextModal<TKey extends MantineModal>(\n payload: OpenContextModal<Parameters<MantineModals[TKey]>[0]['innerProps']> & { modal: TKey }\n ): void;\n};\n\nexport const [useModalsEvents, createEvent] =\n createUseExternalEvents<ModalsEvents>('mantine-modals');\n\nexport const openModal = createEvent('openModal');\nexport const closeModal = createEvent('closeModal');\nexport const closeContextModal: ModalsEvents['closeContextModal'] = <TKey extends MantineModal>(\n id: TKey\n) => createEvent('closeContextModal')(id);\nexport const closeAllModals = createEvent('closeAllModals');\nexport const openConfirmModal = createEvent('openConfirmModal');\nexport const openContextModal: ModalsEvents['openContextModal'] = <TKey extends MantineModal>(\n payload: OpenContextModal<Parameters<MantineModals[TKey]>[0]['innerProps']> & { modal: TKey }\n) => createEvent('openContextModal')(payload);\n\nexport const modals = {\n open: openModal,\n close: closeModal,\n closeAll: closeAllModals,\n openConfirmModal,\n openContextModal,\n};\n"],"names":[],"mappings":";;AACY,MAAC,CAAC,eAAe,EAAE,WAAW,CAAC,GAAG,uBAAuB,CAAC,gBAAgB,EAAE;AAC5E,MAAC,SAAS,GAAG,WAAW,CAAC,WAAW,EAAE;AACtC,MAAC,UAAU,GAAG,WAAW,CAAC,YAAY,EAAE;AAExC,MAAC,cAAc,GAAG,WAAW,CAAC,gBAAgB,EAAE;AAChD,MAAC,gBAAgB,GAAG,WAAW,CAAC,kBAAkB,EAAE;AACpD,MAAC,gBAAgB,GAAG,CAAC,OAAO,KAAK,WAAW,CAAC,kBAAkB,CAAC,CAAC,OAAO,EAAE;AAC1E,MAAC,MAAM,GAAG;AACtB,EAAE,IAAI,EAAE,SAAS;AACjB,EAAE,KAAK,EAAE,UAAU;AACnB,EAAE,QAAQ,EAAE,cAAc;AAC1B,EAAE,gBAAgB;AAClB,EAAE,gBAAgB;AAClB;;;;"}
package/esm/index.js DELETED
@@ -1,5 +0,0 @@
1
- 'use client';
2
- export { ModalsProvider } from './ModalsProvider.js';
3
- export { useModals } from './use-modals/use-modals.js';
4
- export { closeAllModals, closeModal, modals, openConfirmModal, openContextModal, openModal } from './events.js';
5
- //# sourceMappingURL=index.js.map
package/esm/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"reducer.js","sources":["../src/reducer.ts"],"sourcesContent":["import { ModalState } from './context';\n\ninterface ModalsState {\n modals: ModalState[];\n\n /**\n * Modal that is currently open or was the last open one.\n * Keeping the last one is necessary for providing a clean exit transition.\n */\n current: ModalState | null;\n}\n\ninterface OpenAction {\n type: 'OPEN';\n modal: ModalState;\n}\n\ninterface CloseAction {\n type: 'CLOSE';\n modalId: string;\n canceled?: boolean;\n}\n\ninterface CloseAllAction {\n type: 'CLOSE_ALL';\n canceled?: boolean;\n}\n\nfunction handleCloseModal(modal: ModalState, canceled?: boolean) {\n if (canceled && modal.type === 'confirm') {\n modal.props.onCancel?.();\n }\n\n modal.props.onClose?.();\n}\n\nexport function modalsReducer(\n state: ModalsState,\n action: OpenAction | CloseAction | CloseAllAction\n): ModalsState {\n switch (action.type) {\n case 'OPEN': {\n return {\n current: action.modal,\n modals: [...state.modals, action.modal],\n };\n }\n case 'CLOSE': {\n const modal = state.modals.find((m) => m.id === action.modalId);\n if (!modal) {\n return state;\n }\n\n handleCloseModal(modal, action.canceled);\n\n const remainingModals = state.modals.filter((m) => m.id !== action.modalId);\n\n return {\n current: remainingModals[remainingModals.length - 1] || state.current,\n modals: remainingModals,\n };\n }\n case 'CLOSE_ALL': {\n if (!state.modals.length) {\n return state;\n }\n\n // Resolve modal stack from top to bottom\n state.modals\n .concat()\n .reverse()\n .forEach((modal) => {\n handleCloseModal(modal, action.canceled);\n });\n\n return {\n current: state.current,\n modals: [],\n };\n }\n default: {\n return state;\n }\n }\n}\n"],"names":[],"mappings":"AAAA,SAAS,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE;AAC3C,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;AACrB,EAAE,IAAI,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE;AAC5C,IAAI,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,KAAK,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACtE,GAAG;AACH,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,KAAK,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,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,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;AACjD,OAAO,CAAC,CAAC;AACT,MAAM,OAAO;AACb,QAAQ,OAAO,EAAE,KAAK,CAAC,OAAO;AAC9B,QAAQ,MAAM,EAAE,EAAE;AAClB,OAAO,CAAC;AACR,KAAK;AACL,IAAI,SAAS;AACb,MAAM,OAAO,KAAK,CAAC;AACnB,KAAK;AACL,GAAG;AACH;;;;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-modals.js","sources":["../../src/use-modals/use-modals.ts"],"sourcesContent":["import { useContext } from 'react';\nimport { ModalsContext } from '../context';\n\nexport function useModals() {\n const ctx = useContext(ModalsContext);\n\n if (!ctx) {\n throw new Error(\n '[@mantine/modals] useModals hook was called outside of context, wrap your app with ModalsProvider component'\n );\n }\n\n return ctx;\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,SAAS,GAAG;AAC5B,EAAE,MAAM,GAAG,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;AACxC,EAAE,IAAI,CAAC,GAAG,EAAE;AACZ,IAAI,MAAM,IAAI,KAAK;AACnB,MAAM,6GAA6G;AACnH,KAAK,CAAC;AACN,GAAG;AACH,EAAE,OAAO,GAAG,CAAC;AACb;;;;"}