|
1 | 1 | import { ReactNode, Dispatch, SetStateAction, CSSProperties } from "react"; |
2 | 2 |
|
| 3 | +/** |
| 4 | + * The return type of the `useModal` hook |
| 5 | + */ |
3 | 6 | export interface IUseModalReturn { |
| 7 | + /** Function to toggle the open state of the modal */ |
4 | 8 | toggleModal: () => void; |
| 9 | + /** Function to show the modal */ |
5 | 10 | showModal: () => void; |
| 11 | + /** Function to hide the modal */ |
6 | 12 | hideModal: () => void; |
| 13 | + /** The current configuration object for the modal */ |
7 | 14 | modalConfig: IExtendedModalConfig; |
| 15 | + /** Function to update the configuration object for the modal (merge with prev state) */ |
8 | 16 | updateModalConfig: (config: Partial<IModalConfig>) => void; |
| 17 | + /** Function to replace the entire configuration object for the modal */ |
9 | 18 | setModalConfig: Dispatch<SetStateAction<IModalConfig>>; |
10 | 19 | } |
| 20 | + |
| 21 | +/** |
| 22 | + * Configuration object for the modal |
| 23 | + */ |
11 | 24 | export interface IModalConfig { |
| 25 | + /** Determines whether the modal is open or closed */ |
12 | 26 | open?: boolean; |
| 27 | + /** The title of the modal */ |
13 | 28 | title?: string; |
| 29 | + /** Determines whether to show the close icon on the modal */ |
14 | 30 | showCloseIcon?: true; |
| 31 | + /** The content to display inside the modal */ |
15 | 32 | children?: ReactNode; |
| 33 | + /** An array of buttons to display at the bottom of the modal */ |
16 | 34 | buttons?: IModalButton[]; |
17 | 35 | } |
18 | 36 |
|
| 37 | +/** |
| 38 | + * An extended version of the `IModalConfig` that includes a `handleClose` function |
| 39 | + */ |
19 | 40 | export interface IExtendedModalConfig extends IModalConfig { |
20 | 41 | handleClose: () => void; |
21 | 42 | } |
| 43 | + |
| 44 | +/** |
| 45 | + * The shape of any buttons you want yo use in the modal |
| 46 | + */ |
22 | 47 | export interface IModalButton { |
| 48 | + /** The text to display on the button */ |
23 | 49 | text: string; |
| 50 | + /** Optional styling for the button */ |
24 | 51 | style?: CSSProperties; |
| 52 | + /** Function to call when the button is clicked */ |
25 | 53 | onClick?: () => void; |
| 54 | + /** Determines whether the button is disabled */ |
26 | 55 | disabled?: boolean; |
| 56 | + /** Determines whether to close the modal when the button is clicked */ |
27 | 57 | disableClose?: boolean; |
28 | 58 | } |
29 | 59 |
|
| 60 | +/** |
| 61 | + * Expose a specific type for your modal compoent props, at the moment identical to `IExtendedModalConfig` |
| 62 | + */ |
30 | 63 | export type ModalProps = IExtendedModalConfig; |
0 commit comments