Skip to content

Commit 19263de

Browse files
committed
Update README.md
1 parent 60663fc commit 19263de

13 files changed

Lines changed: 33 additions & 27 deletions

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ Create a basic modal component:
3737

3838
```tsx
3939
function Modal({
40-
data,
40+
title,
41+
message,
4142
close,
4243
isOpen,
4344
}) {
@@ -46,8 +47,8 @@ function Modal({
4647
return (
4748
<div className="modal-backdrop">
4849
<div className="modal">
49-
<strong>{data.title}</strong>
50-
<p>{data.message}</p>
50+
<strong>{title}</strong>
51+
<p>{message}</p>
5152
<button onClick={() => close()}>OK</button>
5253
</div>
5354
<style jsx>{`

dist/context.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/context.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
"use client";
21
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
32
import { createContext, useContext } from "react";
4-
import { useModalManager } from "./use-modal-manager";
53
import { ModalItemProvider } from "./item-context";
4+
import { useModalManager } from "./use-modal-manager";
65
const ModalContext = createContext(null);
76
export function ModalProvider({ children, backdrop, loading, modal, }) {
87
const modalManager = useModalManager();
@@ -11,7 +10,7 @@ export function ModalProvider({ children, backdrop, loading, modal, }) {
1110
function Modals({ backdrop, loading, modal, }) {
1211
const modalManager = useModals();
1312
const { stack, isLoading } = modalManager;
14-
return (_jsxs(_Fragment, { children: [isLoading && loading && loading(modalManager), stack.map((modalInstance) => (_jsx(ModalItemProvider, { modal: modalInstance, children: modal ? (modal(modalInstance, modalManager)) : (_jsx(modalInstance.component, { data: modalInstance.data, close: modalInstance.close, isOpen: modalInstance.isOpen, id: modalInstance.id, index: modalInstance.index })) }, modalInstance.id))), (isLoading || stack.length > 0) && backdrop && backdrop(modalManager)] }));
13+
return (_jsxs(_Fragment, { children: [isLoading && loading && loading(modalManager), stack.map((modalInstance) => (_jsx(ModalItemProvider, { modal: modalInstance, children: modal ? (modal(modalInstance, modalManager)) : (_jsx(modalInstance.component, { ...modalInstance.props, close: modalInstance.close, isOpen: modalInstance.isOpen, id: modalInstance.id, index: modalInstance.index })) }, modalInstance.id))), (isLoading || stack.length > 0) && backdrop && backdrop(modalManager)] }));
1514
}
1615
export function useModals() {
1716
const context = useContext(ModalContext);

dist/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { ModalProvider, useModals } from "./context";
2-
export { useModalManager } from "./use-modal-manager";
32
export { useBeforeClose } from "./item-context";
43
export type { ModalProps } from "./types";
4+
export { useModalManager } from "./use-modal-manager";
55
//# sourceMappingURL=index.d.ts.map

dist/index.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export { ModalProvider, useModals } from "./context";
2-
export { useModalManager } from "./use-modal-manager";
32
export { useBeforeClose } from "./item-context";
3+
export { useModalManager } from "./use-modal-manager";

dist/item-context.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ModalInstance } from "./types";
2-
export declare function useModal(): ModalInstance<any>;
2+
export declare function useModal(): ModalInstance<any, any>;
33
export declare function useBeforeClose(callback: () => boolean): void;
44
export declare function ModalItemProvider({ modal, children, }: {
55
modal: ModalInstance;

dist/item-context.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/item-context.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
"use client";
21
import { jsx as _jsx } from "react/jsx-runtime";
32
import { createContext, useContext, useEffect } from "react";
43
const ModalItemContext = createContext(null);

dist/types.d.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,31 @@ export interface ModalProviderProps {
99
loading?: (modals: ModalManager) => ReactElement | null;
1010
modal?: (modal: ModalInstance, modals: ModalManager) => ReactElement;
1111
}
12-
export interface ModalProps<ReturnValue = any> extends Record<string, any> {
12+
export interface ModalProps<ReturnValue = any> {
1313
index: number;
1414
id: string;
1515
isOpen: boolean;
1616
close: (value?: ReturnValue) => void;
1717
}
18-
export interface ModalInstance<ReturnValue = any> {
19-
component: ComponentType<any>;
18+
export type ModalComponent<T = any, ReturnValue = any> = ComponentType<ModalProps<ReturnValue> & T>;
19+
export interface ModalInstance<T = any, ReturnValue = any> {
20+
component: ModalComponent<T, ReturnValue>;
2021
id: string;
21-
data?: any;
22+
props?: Omit<T, keyof ModalProps<ReturnValue>>;
2223
isOpen: boolean;
2324
close: (value?: ReturnValue) => void;
2425
index: number;
2526
onBeforeClose: (callback: () => boolean) => void;
2627
}
2728
export interface ModalManager {
28-
open: <T = any, R = any>(component: ComponentType<T> | (() => Promise<{
29-
default: ComponentType<T>;
30-
}>), data?: any, options?: ModalOptions) => Promise<R>;
29+
open: {
30+
<T extends Record<string, never>, R = any>(component: ModalComponent<T, R> | (() => Promise<{
31+
default: ModalComponent<T, R>;
32+
}>), options?: ModalOptions): Promise<R>;
33+
<T, R = any>(component: ModalComponent<T, R> | (() => Promise<{
34+
default: ModalComponent<T, R>;
35+
}>), props: Omit<T, keyof ModalProps<R>>, options?: ModalOptions): Promise<R>;
36+
};
3137
close: (n?: number) => boolean;
3238
closeById: (id: string) => boolean;
3339
closeAll: () => boolean;

0 commit comments

Comments
 (0)