@catconsult/simplify-modal-control
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -50,3 +50,3 @@ import { ComponentType, Dispatch, SetStateAction, ReactNode, FC } from 'react'; | ||
*/ | ||
declare const makeModalControlSimpler: <TModalProps, TCustomValues, THookValues, TContextModals extends Record<string, UseModalReturnType<any>>, TContextModalsKey extends keyof TContextModals, TModalContextValue extends { [K in TContextModalsKey]: [TContextModals[K][1], TContextModals[K][2]]; }>({ ModalWrapper, mapModalProps, onOpen, onClose, useHookValue, useContextModals, }: MakeModalControlSimplerProps<TModalProps, TCustomValues, THookValues, TContextModals>) => { | ||
declare const makeModalControlSimpler: <TModalProps, TCustomValues, THookValues, TContextModals extends Record<string, UseModalReturnType<any, any>>, TContextModalsKey extends keyof TContextModals, TModalContextValue extends { [K in TContextModalsKey]: [TContextModals[K][1], TContextModals[K][2]]; }>({ ModalWrapper, mapModalProps, onOpen, onClose, useHookValue, useContextModals, }: MakeModalControlSimplerProps<TModalProps, TCustomValues, THookValues, TContextModals>) => { | ||
useModal: UseModalFn<TModalProps, TCustomValues>; | ||
@@ -58,3 +58,3 @@ ModalContextProvider: FC<{ | ||
useModalContextSelector: <K_1 extends TContextModalsKey>(key: K_1) => TModalContextValue[K_1]; | ||
openModal: <K_2 extends TContextModalsKey>(key: K_2, newProps?: Parameters<TModalContextValue[K_2][0]>[0] | undefined) => void; | ||
openModal: <K_2 extends TContextModalsKey>(key: K_2, newProps?: Parameters<TModalContextValue[K_2][0]>[0] | undefined, newModalProps?: Partial<TModalProps> | undefined) => void; | ||
closeModal: <K_3 extends TContextModalsKey>(key: K_3) => void; | ||
@@ -69,6 +69,7 @@ }; | ||
open?: boolean; | ||
setModalProps?: (modalProps: any) => void; | ||
}; | ||
export declare type UseModalReturnType<T = any> = [ | ||
export declare type UseModalReturnType<T = any, TModal = any> = [ | ||
JSX.Element, | ||
(newProps?: NewPropsType<T>) => void, | ||
(newProps?: NewPropsType<T>, newModalProps?: Partial<TModal>) => void, | ||
() => void | ||
@@ -81,3 +82,3 @@ ]; | ||
customValues?: TCustomValues; | ||
}) => UseModalReturnType<T>; | ||
}) => UseModalReturnType<T, TModalProps>; | ||
declare type UseContextModalsFn<TModalProps, TContextModals, TCustomValues> = (useModal: UseModalFn<TModalProps, TCustomValues>) => TContextModals; | ||
@@ -84,0 +85,0 @@ declare type UseHookValueFn<THookValues> = () => THookValues; |
18
index.js
@@ -105,5 +105,9 @@ "use strict"; | ||
const [props, setProps] = (0, react_1.useState)(); | ||
const handleOpen = (0, react_1.useCallback)((newProps) => { | ||
const [modalProps, setModalProps] = (0, react_1.useState)(); | ||
const handleOpen = (0, react_1.useCallback)((newProps, newModalProps) => { | ||
setOpen(true); | ||
setProps(newProps); | ||
if (newProps) | ||
setProps(newProps); | ||
if (newModalProps) | ||
setModalProps(newModalProps); | ||
if (onOpen) | ||
@@ -115,2 +119,3 @@ onOpen(hookValues); | ||
setProps(undefined); | ||
setModalProps(undefined); | ||
if (onClose) | ||
@@ -130,3 +135,3 @@ onClose(hookValues); | ||
]); | ||
const modal = ((0, jsx_runtime_1.jsx)(ModalWrapper, Object.assign({}, mappedModalProps, { children: (0, jsx_runtime_1.jsx)(ModalContentMemo, Object.assign({}, defaultProps, props, { open: open, onClose: handleClose })) }))); | ||
const modal = ((0, jsx_runtime_1.jsx)(ModalWrapper, Object.assign({}, mappedModalProps, modalProps, { children: (0, jsx_runtime_1.jsx)(ModalContentMemo, Object.assign({}, defaultProps, props, { open: open, onClose: handleClose, setModalProps: setModalProps })) }))); | ||
return [modal, handleOpen, handleClose]; | ||
@@ -177,3 +182,4 @@ }; | ||
* @param key modal key | ||
* @param newProps modal props | ||
* @param newProps modal content props | ||
* @param newModalProps modal props | ||
* @example | ||
@@ -184,4 +190,4 @@ * ```ts | ||
*/ | ||
const openModal = (key, newProps) => { | ||
modalContextHandlersRef === null || modalContextHandlersRef === void 0 ? void 0 : modalContextHandlersRef[key][0](newProps); | ||
const openModal = (key, newProps, newModalProps) => { | ||
modalContextHandlersRef === null || modalContextHandlersRef === void 0 ? void 0 : modalContextHandlersRef[key][0](newProps, newModalProps); | ||
}; | ||
@@ -188,0 +194,0 @@ /** |
{ | ||
"name": "@catconsult/simplify-modal-control", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Simplify React modal control flow", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -121,3 +121,3 @@ [![npm version](https://badge.fury.io/js/@catconsult%2Fsimplify-modal-control.svg)](https://badge.fury.io/js/@catconsult%2Fsimplify-modal-control) | ||
openModal('modal0', { customMessage: 'modal0' }); | ||
handleOpenMyModal1({ customMessage: 'modal1' }); | ||
handleOpenMyModal1({ customMessage: 'modal1' }, { maxWidth: 'lg' }); | ||
handleOpenMyModal2({ customMessage: 'modal2' }); | ||
@@ -172,9 +172,10 @@ handleOpenMyModal3({ customMessage: 'modal3' }); | ||
* @param key modal key | ||
* @param newProps modal props | ||
* @param newProps modal content props | ||
* @param newModalProps modal props | ||
* @example | ||
* ```ts | ||
* openModal("fooModal", {fooProp:"pass in props to the modal"}); | ||
* openModal("fooModal", {fooProp:"pass in props to the modal"}, { maxWidth:"lg" }); | ||
* ``` | ||
*/ | ||
openModal(key, newProps); | ||
openModal(key, newProps, newModalProps); | ||
```` | ||
@@ -186,7 +187,7 @@ | ||
/** | ||
* Open modal without using hooks | ||
* Close modal without using hooks | ||
* @param key modal key | ||
* @example | ||
* ```ts | ||
* openModal("fooModal", {fooProp:"pass in props to the modal"}); | ||
* closeModal("fooModal"); | ||
* ``` | ||
@@ -193,0 +194,0 @@ */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27181
337
257