toast: add an API to copy to clipboard and show a toast

Summary:
This "copy to clipboard" behavior is widely used. Add a function to make it
easy to copy with a toast message.

Reviewed By: evangrayk

Differential Revision: D52824796

fbshipit-source-id: 08557c3a0f96831e09bc0175caa8a27a742ed504
This commit is contained in:
Jun Wu 2024-01-17 17:52:10 -08:00 committed by Facebook GitHub Bot
parent d5b14ff39f
commit 0f044d5dd5

View File

@ -8,6 +8,8 @@
import type {ReactNode} from 'react';
import type {SetterOrUpdater} from 'recoil';
import {t} from './i18n';
import platform from './platform';
import {List} from 'immutable';
import {DefaultValue, atom, useRecoilState} from 'recoil';
@ -43,6 +45,12 @@ class UseToast {
});
}
/** Show "Copied <text>" toast. Existing "copied' toast will be replaced. */
copyAndShowToast(text: string) {
platform.clipboardCopy(text);
this.show(t('Copied $text', {replace: {$text: text}}), {key: 'copied'});
}
/** List all toasts to display. */
list(): List<ToastProps> {
return this.queue;