import * as fui from "@fluentui/react-components"; import { bundleIcon, Copy32Regular, CopyFilled, CopyRegular } from "@fluentui/react-icons"; import { ReactElement } from "react"; import { useStyles } from "./PasswordList.styles"; export default function PasswordList({ passwords, className }: PasswordListProps): ReactElement { const toaster = fui.useToastController(); const CopyIcon = bundleIcon(CopyFilled, CopyRegular); const cls = useStyles(); const copy = (password?: string) => { navigator.clipboard.writeText(password ?? passwords.join("\n")); toaster.dispatchToast( { i18n.t("advanced.copied_msg") } , { intent: "success", timeout: 1000 } ); }; return (
{ passwords.length > 0 && <> } onClick={ () => copy() }> { i18n.t("advanced.actions.copy_all") } { passwords.map((password, index) => copy(password) }> { password } ) } }
); } export type PasswordListProps = { className?: string; passwords: string[]; };