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';
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.
*
* This is like an async version of `window.confirm` except that:
*
* - It can be used inside iframes (browsers are starting to prevent this
* for the native `window.confirm` dialog)
* - It can be used inside iframes (browsers are starting to prevent this for
* the native `window.confirm` dialog)
* - The visual style of the dialog matches the Hypothesis design system
*
* @param {object} options - Options for the `ConfirmModal`
* @param {string} [options.title]
* @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.
* @return - Promise that resolves with `true` if the user confirmed the action
* or `false` if they canceled it.
*/
export async function confirm({
title = 'Confirm',
message,
confirmAction = 'Yes',
}) {
}: ConfirmModalProps): Promise<boolean> {
const container = document.createElement('div');
container.setAttribute('data-testid', 'confirm-container');
......@@ -34,8 +36,7 @@ export async function confirm({
document.body.appendChild(container);
return new Promise(resolve => {
/** @param {boolean} result */
const close = result => {
const close = (result: boolean) => {
render(null, container);
container.remove();
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