Skip to content

Commit

Permalink
docs: Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenOutman committed Sep 23, 2020
1 parent bfe23a4 commit 100f236
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ const buyNewPhone = useCallback(async () => {
#### Signatures

```tsx
interface AlertModalProps {
okButtonText?: string;
onOk?: (() => void) | (() => Promise<any>);
}

alert(
message?: React.ReactNode,
modalConfig?: AlertModalProps
): Promise<void>;

interface AlertModalProps {
okButtonText?: string;
onOk?: (() => void) | (() => Promise<any>);
}
```
- `okButtonText`: Customize "OK" button text.
- `onOk`: Callback function when "OK" is clicked. If `onOk` returns a `Promise`, "OK" button shows loading status until the promise finishes.

### `confirm`

Expand All @@ -56,20 +58,26 @@ const confirmSmashPhone = useCallback(async () => {
#### Signatures

```tsx
confirm(
message?: React.ReactNode,
modalConfig?: ConfirmModalProps
): Promise<boolean>;

interface ConfirmModalProps {
okButtonText?: string;
cancelButtonText?: string;
onOk?: (() => void) | (() => Promise<any>);
onCancel?: (isSubmitLoading?: boolean) => any;
canCancelOnLoading?: boolean;
}

confirm(
message?: React.ReactNode,
modalConfig?: ConfirmModalProps
): Promise<boolean>;
```

- `okButtonText`: Customize "OK" button text.
- `cancelButtonText`: Customize "Cancel" button text.
- `onOk`: Callback function when "OK" is clicked. If `onOk` returns a `Promise`, "OK" button shows loading status until the promise finishes.
- `onCancel`: Callback function when "Cancel" is clicked. If not provided, "Cancel" is disabled when "OK" is loading.
- `canCancelOnLoading`: When `onCancel` is set, you can still use this option to force disable "Cancel" button.

### `prompt`

Use it like you are using `window.prompt()` but await its return value.
Expand All @@ -86,21 +94,27 @@ const promptForName = useCallback(async () => {
#### Signatures

```tsx
prompt(
message?: React.ReactNode,
_default?: string,
modalConfig?: PromptModalProps
): Promise<string | null>;

interface PromptModalProps {
okButtonText?: string;
cancelButtonText?: string;
onOk?: ((inputVal?: string) => void) | ((inputVal: string) => Promise<any>);
onCancel?: (isSubmitLoading?: boolean) => any;
canCancelOnLoading?: boolean;
}

prompt(
message?: React.ReactNode,
_default?: string,
modalConfig?: PromptModalProps
): Promise<string | null>;
```

- `okButtonText`: Customize "OK" button text.
- `cancelButtonText`: Customize "Cancel" button text.
- `onOk`: Callback function when "OK" is clicked, receiving a string representing the user input. If `onOk` returns a `Promise`, "OK" button shows loading status until the promise finishes.
- `onCancel`: Callback function when "Cancel" is clicked. If not provided, "Cancel" is disabled when "OK" is loading.
- `canCancelOnLoading`: When `onCancel` is set, you can still use this option to force disable "Cancel" button.

## License

MIT licensed

0 comments on commit 100f236

Please sign in to comment.