diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8ab4aa1..6cc6d1a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: borales/actions-yarn@v2.3.0 + - uses: borales/actions-yarn@v3.0.0 with: cmd: install - run: yarn lint diff --git a/package.json b/package.json index a3a788f..7473a23 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "2.0.0", + "version": "2.0.1", "license": "MIT", "name": "mui-modal-provider", "author": "Quernest", diff --git a/src/index.ts b/src/index.ts index ae9560b..dc69365 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,3 @@ -export { default } from './modal-provider'; -export { default as useModal } from './use-modal'; +export { default, ModalProviderProps } from './modal-provider'; +export { default as useModal, UseModalOptions } from './use-modal'; +export * from './types'; diff --git a/src/modal-context.ts b/src/modal-context.ts index 3cc624b..64ccc1f 100644 --- a/src/modal-context.ts +++ b/src/modal-context.ts @@ -9,14 +9,14 @@ import { UpdateFn, } from './types'; -export type ModalContextState = { +export interface ModalContextState { state: State; updateModal: UpdateFn; hideModal: HideFn; destroyModal: DestroyFn; destroyModalsByRootId: DestroyByRootIdFn; showModal: ShowFn; -}; +} export const initialContextState = { state: initialState, diff --git a/src/modal-provider.tsx b/src/modal-provider.tsx index 7e8c050..52fbfc9 100644 --- a/src/modal-provider.tsx +++ b/src/modal-provider.tsx @@ -14,15 +14,18 @@ import { } from './constants'; import { uid } from './utils'; -type Props = { +export interface ModalProviderProps { children: React.ReactNode; /** * Enable it if you want to use mui < 5 version */ legacy?: boolean; -}; +} -export default function ModalProvider({ children, legacy = false }: Props) { +export default function ModalProvider({ + children, + legacy = false, +}: ModalProviderProps) { const [state, dispatch] = React.useReducer(reducer, initialState); const update = React.useCallback( diff --git a/src/reducer.ts b/src/reducer.ts index e6e7f01..592b418 100644 --- a/src/reducer.ts +++ b/src/reducer.ts @@ -15,7 +15,7 @@ export enum Types { UNKNOWN = 'UNKNOWN', } -type Payload = { +interface Payload { [Types.SHOW]: StateElement & { id: string; }; @@ -33,7 +33,7 @@ type Payload = { rootId: string; }; [Types.UNKNOWN]: undefined; -}; +} type Action = ActionMap[keyof ActionMap]; diff --git a/src/test-utils/legacy-modal.tsx b/src/test-utils/legacy-modal.tsx index 95ab381..f1c7bdd 100644 --- a/src/test-utils/legacy-modal.tsx +++ b/src/test-utils/legacy-modal.tsx @@ -1,12 +1,12 @@ import React from 'react'; import { OnExitedEvent, OnCloseEvent } from './index'; -export type LegacyModalProps = { +export interface LegacyModalProps { open?: boolean; text: string; onExited?: (args: any) => void; onClose?: (args: any) => void; -}; +} const LegacyModal: React.FC = ({ open, diff --git a/src/types.ts b/src/types.ts index 0386534..bdb4fc9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -4,25 +4,25 @@ export type ModalComponent

= ComponentType

; export type ModalComponentProps

= Omit; -export type Props = { +export interface Props { open?: Boolean; [key: string]: any; -}; +} -export type Options = { +export interface Options { destroyOnClose?: boolean; rootId?: string; -}; +} -export type State = { +export interface State { [id: string]: StateElement; -}; +} -export type StateElement = { +export interface StateElement { component: ComponentType; props?: Props; options?: Options; -}; +} export type ActionMap = { [Key in keyof M]: M[Key] extends undefined @@ -50,9 +50,9 @@ export type ShowFn =

( options?: Options ) => ShowFnOutput

; -export type ShowFnOutput

= { +export interface ShowFnOutput

{ id: string; hide: () => void; destroy: () => void; update: (newProps: Partial>) => void; -}; +} diff --git a/src/use-modal.ts b/src/use-modal.ts index dc45593..1c0f97f 100644 --- a/src/use-modal.ts +++ b/src/use-modal.ts @@ -4,15 +4,15 @@ import { ShowFn } from './types'; import ModalContext from './modal-context'; import { uid } from './utils'; -type Options = { +export interface UseModalOptions { disableAutoDestroy?: boolean; -}; +} -const defaultOptions: Options = { +const defaultOptions: UseModalOptions = { disableAutoDestroy: false, }; -export default function useModal(options: Options = defaultOptions) { +export default function useModal(options: UseModalOptions = defaultOptions) { const { disableAutoDestroy } = { ...defaultOptions, ...options }; const { showModal,