Commit 1a2e36f2 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Convert `prompts` to TSX

parent 90af4bb7
...@@ -2,27 +2,29 @@ import { render } from 'preact'; ...@@ -2,27 +2,29 @@ import { render } from 'preact';
import { ConfirmModal } from '@hypothesis/frontend-shared'; import { ConfirmModal } from '@hypothesis/frontend-shared';
export type ConfirmModalProps = {
title?: string;
message: string;
confirmAction?: string;
};
/** /**
* Show the user a prompt asking them to confirm an action. * Show the user a prompt asking them to confirm an action.
* *
* This is like an async version of `window.confirm` except that: * This is like an async version of `window.confirm` except that:
* *
* - It can be used inside iframes (browsers are starting to prevent this * - It can be used inside iframes (browsers are starting to prevent this for
* for the native `window.confirm` dialog) * the native `window.confirm` dialog)
* - The visual style of the dialog matches the Hypothesis design system * - The visual style of the dialog matches the Hypothesis design system
* *
* @param {object} options - Options for the `ConfirmModal` * @return - Promise that resolves with `true` if the user confirmed the action
* @param {string} [options.title] * or `false` if they canceled it.
* @param {string} options.message
* @param {string} [options.confirmAction]
* @return {Promise<boolean>} - Promise that resolves with `true` if the user
* confirmed the action or `false` if they canceled it.
*/ */
export async function confirm({ export async function confirm({
title = 'Confirm', title = 'Confirm',
message, message,
confirmAction = 'Yes', confirmAction = 'Yes',
}) { }: ConfirmModalProps): Promise<boolean> {
const container = document.createElement('div'); const container = document.createElement('div');
container.setAttribute('data-testid', 'confirm-container'); container.setAttribute('data-testid', 'confirm-container');
...@@ -34,8 +36,7 @@ export async function confirm({ ...@@ -34,8 +36,7 @@ export async function confirm({
document.body.appendChild(container); document.body.appendChild(container);
return new Promise(resolve => { return new Promise(resolve => {
/** @param {boolean} result */ const close = (result: boolean) => {
const close = result => {
render(null, container); render(null, container);
container.remove(); container.remove();
resolve(result); resolve(result);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment