mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-16 05:56:47 +01:00
27 lines
671 B
TypeScript
27 lines
671 B
TypeScript
import { clear, writeText } from '@tauri-apps/plugin-clipboard-manager';
|
|
import { useCallback } from 'react';
|
|
import { showToast } from '../lib/toast';
|
|
|
|
export function useCopy({ disableToast }: { disableToast?: boolean } = {}) {
|
|
const copy = useCallback(
|
|
(text: string | null) => {
|
|
if (text == null) {
|
|
clear().catch(console.error);
|
|
} else {
|
|
writeText(text).catch(console.error);
|
|
}
|
|
if (text != '' && !disableToast) {
|
|
showToast({
|
|
id: 'copied',
|
|
color: 'success',
|
|
icon: 'copy',
|
|
message: 'Copied to clipboard',
|
|
});
|
|
}
|
|
},
|
|
[disableToast],
|
|
);
|
|
|
|
return copy;
|
|
}
|