content.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { Copy } from 'lucide-react'
  2. import { useMemo, useState } from 'react'
  3. import { Button, copyToClipboard } from 'ui'
  4. import type { StepContentProps } from '@/components/interfaces/ConnectSheet/Connect.types'
  5. function getShadcnCommand(state: StepContentProps['state']): string | null {
  6. if (state.framework === 'nextjs') {
  7. return 'npx shadcn@latest add @supabase/supabase-client-nextjs'
  8. }
  9. if (state.framework === 'react') {
  10. return 'npx shadcn@latest add @supabase/supabase-client-react-router'
  11. }
  12. return null
  13. }
  14. function ShadcnCommandContent({ state }: StepContentProps) {
  15. const command = useMemo(() => getShadcnCommand(state), [state])
  16. const [copyLabel, setCopyLabel] = useState('Copy')
  17. if (!command) return null
  18. const handleCopy = () => {
  19. copyToClipboard(command, () => {
  20. setCopyLabel('Copied')
  21. setTimeout(() => setCopyLabel('Copy'), 2000)
  22. })
  23. }
  24. return (
  25. <div className="relative group">
  26. <div className="bg-surface-75 border rounded-lg p-3 pr-20 font-mono text-sm text-foreground-light overflow-x-auto">
  27. <code>{command}</code>
  28. </div>
  29. <div className="absolute right-2 top-1/2 -translate-y-1/2">
  30. <Button
  31. type="default"
  32. size="tiny"
  33. icon={<Copy size={14} />}
  34. onClick={handleCopy}
  35. className="opacity-0 group-hover:opacity-100 transition-opacity"
  36. >
  37. {copyLabel}
  38. </Button>
  39. </div>
  40. </div>
  41. )
  42. }
  43. export default ShadcnCommandContent