mirror of
https://github.com/facebook/sapling.git
synced 2024-10-26 19:11:50 +03:00
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:
parent
d5b14ff39f
commit
0f044d5dd5
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user