一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
49 行
1.1 KiB
TypeScript
49 行
1.1 KiB
TypeScript
import { LocalizationResult } from '../../../types';
|
|
import createButton from './createButton';
|
|
|
|
interface Options {
|
|
content: HTMLElement;
|
|
doneLabel: LocalizationResult;
|
|
onDismiss: ()=> void;
|
|
}
|
|
|
|
const showModal = ({ content, doneLabel, onDismiss }: Options) => {
|
|
const dialog = document.createElement('dialog');
|
|
dialog.classList.add('joplin-dialog', '-visible');
|
|
document.body.appendChild(dialog);
|
|
|
|
dialog.onclose = () => {
|
|
onDismiss();
|
|
dialog.remove();
|
|
};
|
|
|
|
const onClose = () => {
|
|
if (dialog.close) {
|
|
dialog.close();
|
|
} else {
|
|
// Handle the case where the dialog element is not supported by the
|
|
// browser/testing environment.
|
|
dialog.onclose(new Event('close'));
|
|
}
|
|
};
|
|
|
|
dialog.appendChild(content);
|
|
|
|
const submitButton = createButton(doneLabel, onClose);
|
|
submitButton.classList.add('done');
|
|
dialog.appendChild(submitButton);
|
|
|
|
// .showModal is not defined in JSDOM and some older (pre-2022) browsers
|
|
if (dialog.showModal) {
|
|
dialog.showModal();
|
|
} else {
|
|
dialog.classList.add('-fake-modal');
|
|
}
|
|
|
|
return {
|
|
dismiss: onClose,
|
|
};
|
|
};
|
|
|
|
export default showModal;
|