File size: 1,526 Bytes
297c500
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import React, { useState } from 'react';
import { Clipboard, Check } from 'lucide-react';

const InstallLine: React.FC<{ packageName: string }> = ({ packageName }) => {
  const [hasCopied, setHasCopied] = useState(false);
  const command = `npm i ${packageName}`;

  const copyToClipboard = () => {
    navigator.clipboard.writeText(command);
    setHasCopied(true);
    setTimeout(() => setHasCopied(false), 2000);
  };

  return (
    <div className="flex items-center justify-center p-2">
      <div 
        className="flex max-w-sm w-full items-center justify-between bg-white border border-gray-200 rounded-md py-1.5 px-2 font-mono text-xs shadow-sm hover:shadow transition-all duration-200 ease-in-out cursor-pointer"
        onClick={copyToClipboard}
        role="button"
        tabIndex={0}
        aria-label="Copy npm install command"
      >
        <div className="flex items-center font-bold space-x-2 overflow-x-auto">
          <span className="text-gray-400 select-none">$</span>
          <span className="text-blue-500 font-semibold">npm</span>
          <span className="text-green-600">i</span>
          <span className="text-pink-500">{packageName}</span>
        </div>
        <div className="p-1 flex-shrink-0" aria-hidden="true">
          {hasCopied ? (
            <Check className="size-4 text-emerald-500" />
          ) : (
            <Clipboard className="size-4 text-gray-400 hover:text-gray-600" />
          )}
        </div>
      </div>
    </div>
  );
};

export default InstallLine;