import * as React from "react"; import classNames from "classnames"; import styles from "./Snippet.module.scss"; import { IconButton } from "../IconButton"; import { Typography } from "../Typography"; import { MdContentCopy } from "react-icons/md"; import { Popup } from "../Popup/Popup"; export interface SnippetProps extends React.ComponentPropsWithoutRef<"div"> { /** * The content for the Snippet */ children: string; /** * If the Popup has an indicator * * @default false */ hasIndicator?: boolean; } /** * @public * * @description * * The Snippet is a piece of text that the user can copy. */ export const Snippet: React.FC = (props) => { const { children, className, hasIndicator = false, ...rest } = props; const [isOpen, setIsOpen] = React.useState(false); const [popupText, setPopupText] = React.useState("Copy"); return (
$ {children} setIsOpen(false)} onOpen={() => setIsOpen(true)} text={popupText} > } onClick={() => { navigator.clipboard.writeText(children); setPopupText("Copied!"); }} variant="primary" />
); }; Snippet.displayName = "Snippet";