Skip to content

Commit

Permalink
#62 added missing .ts types (#63)
Browse files Browse the repository at this point in the history
* #62 added missing ts types

* #62 upd ci
  • Loading branch information
Quernest authored Jul 27, 2022
1 parent a5d3f82 commit d4103aa
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.0.0",
"version": "2.0.1",
"license": "MIT",
"name": "mui-modal-provider",
"author": "Quernest",
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
4 changes: 2 additions & 2 deletions src/modal-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions src/modal-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<UpdateFn>(
Expand Down
4 changes: 2 additions & 2 deletions src/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export enum Types {
UNKNOWN = 'UNKNOWN',
}

type Payload = {
interface Payload {
[Types.SHOW]: StateElement & {
id: string;
};
Expand All @@ -33,7 +33,7 @@ type Payload = {
rootId: string;
};
[Types.UNKNOWN]: undefined;
};
}

type Action = ActionMap<Payload>[keyof ActionMap<Payload>];

Expand Down
4 changes: 2 additions & 2 deletions src/test-utils/legacy-modal.tsx
Original file line number Diff line number Diff line change
@@ -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<LegacyModalProps> = ({
open,
Expand Down
20 changes: 10 additions & 10 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ export type ModalComponent<P> = ComponentType<P>;

export type ModalComponentProps<P> = Omit<P, 'open'>;

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<any>;
props?: Props;
options?: Options;
};
}

export type ActionMap<M extends { [index: string]: any }> = {
[Key in keyof M]: M[Key] extends undefined
Expand Down Expand Up @@ -50,9 +50,9 @@ export type ShowFn = <P extends Props>(
options?: Options
) => ShowFnOutput<P>;

export type ShowFnOutput<P> = {
export interface ShowFnOutput<P> {
id: string;
hide: () => void;
destroy: () => void;
update: (newProps: Partial<ModalComponentProps<P>>) => void;
};
}
8 changes: 4 additions & 4 deletions src/use-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d4103aa

Please sign in to comment.