Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

1.5 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.

import {
  Button,
  cn,
  copyToClipboard,
  Tooltip,
  TooltipContent,
  TooltipTrigger
} from "@carbon/react";
import { useState } from "react";
import { LuCheck, LuCopy } from "react-icons/lu";

const Share = ({
  text,
  className,
  withTextInTooltip = false
}: {
  text: string;
  className?: string;
  withTextInTooltip?: boolean;
}) => {
  const [isCopied, setIsCopied] = useState(false);

  const onCopy = () => {
    copyToClipboard(text);
    setIsCopied(true);
    setTimeout(() => setIsCopied(false), 1500);
  };

  return (
    <Tooltip>
      <TooltipTrigger asChild>
        <Button
          variant="secondary"
          aria-label="Copy"
          className={cn(
            isCopied && "text-ed-green-strong hover:text-ed-green-strong",
            className
          )}
          rightIcon={
            isCopied ? (
              <LuCheck className="w-3 h-3" />
            ) : (
              <LuCopy className="w-3 h-3" />
            )
          }
          onClick={onCopy}
        >
          Share
        </Button>
      </TooltipTrigger>
      <TooltipContent>
        <span>
          {isCopied
            ? "Copied!"
            : withTextInTooltip
              ? text
              : "Copy link to clipboard"}
        </span>
      </TooltipContent>
    </Tooltip>
  );
};

export default Share;