/** The Copy controls of the app, with one shared behaviour: the control itself shows that the copy worked (#4748). */ import { createContext, useContext } from 'react'; import { tr } from '../lib/i18n'; import { cx } from '../lib/format'; import { COPIED_MENU_MS, useCopy } from '../lib/use-copy'; import { Icon } from './ui'; type Source = string | (() => string | Promise); /** A round icon button that copies `text`: the icon turns into a check mark for a moment, and a screen reader hears "Copied". */ export function CopyBtn({ text, label, title, disabled, size = 19 }: { text: Source; label: string; title: string; disabled?: boolean; size?: number }) { const { copied, copy } = useCopy(); return ; } /** What closes the menu a menu item is in; Chat's message menu provides it. */ export const MenuCloseContext = createContext<() => void>(() => {}); /** A menu item that copies `text`: it says "Copied" for a moment, and then the menu closes. */ export function CopyMenuItem({ text, label, children, disabled, onClose }: { text: Source; label: string; children: string; disabled?: boolean; onClose?: () => void }) { const { copied, copy } = useCopy(COPIED_MENU_MS); const close = useContext(MenuCloseContext); return ; }