// // Copyright 2023 DXOS.org // import React, { createContext, type PropsWithChildren, useCallback, useContext, useState } from 'react'; export type ClipboardContextValue = { textValue: string; setTextValue: (nextValue: string) => Promise; }; export const ClipboardContext = createContext({ textValue: '', setTextValue: async (_) => {}, }); export const useClipboard = () => useContext(ClipboardContext); export const ClipboardProvider = ({ children }: PropsWithChildren<{}>) => { const [textValue, setInternalTextValue] = useState(''); const setTextValue = useCallback(async (nextValue: string) => { await navigator.clipboard.writeText(nextValue); return setInternalTextValue(nextValue); }, []); return {children}; };