'use client'; import React, { useState, useRef } from 'react'; import Link from 'next/link'; import { QRCodeSVG } from 'qrcode.react'; import { Twitter, Download, Check, Sparkles, MessageCircle } from 'lucide-react'; import { Button } from '@/components/ui/Button'; import { Input } from '@/components/ui/Input'; import { cn } from '@/lib/utils'; // Brand Colors const BRAND = { paleGrey: '#EBEBDF', richBlue: '#1A1265', richBlueLight: '#2A2275', }; // QR Color Options - X Theme const QR_COLORS = [ { name: 'X Black', value: '#000000' }, { name: 'X Blue', value: '#1DA1F2' }, { name: 'Dark Blue', value: '#1A1265' }, { name: 'Teal', value: '#0D9488' }, { name: 'Coral', value: '#F43F5E' }, { name: 'Grey', value: '#374151' }, { name: 'Emerald', value: '#10B981' }, { name: 'Rose', value: '#F43F5E' }, ]; // Frame Options const FRAME_OPTIONS = [ { id: 'none', label: 'No Frame' }, { id: 'scanme', label: 'Scan Me' }, { id: 'follow', label: 'Follow' }, { id: 'connect', label: 'Connect' }, ]; export default function TwitterGenerator() { const [username, setUsername] = useState(''); const [qrColor, setQrColor] = useState('#000000'); const [frameType, setFrameType] = useState('none'); const qrRef = useRef(null); // Twitter URL construction const getUrl = () => { const cleanUser = username.replace(/^@/, '').replace(/https?:\/\/(www\.)?(twitter|x)\.com\//, '').replace(/\/$/, ''); return cleanUser ? `https://x.com/${cleanUser}` : 'https://x.com'; }; const handleDownload = async (format: 'png' | 'svg') => { if (!qrRef.current) return; try { if (format === 'png') { const { toPng } = await import('html-to-image'); const dataUrl = await toPng(qrRef.current, { cacheBust: true, pixelRatio: 3 }); const link = document.createElement('a'); link.download = `twitter-qr-code.png`; link.href = dataUrl; link.click(); } else { const svgData = qrRef.current.querySelector('svg')?.outerHTML; if (svgData) { const blob = new Blob([svgData], { type: 'image/svg+xml;charset=utf-8' }); const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = `twitter-qr-code.svg`; link.click(); } } } catch (err) { console.error('Download failed', err); } }; const getFrameLabel = () => { const frame = FRAME_OPTIONS.find(f => f.id === frameType); return frame?.id !== 'none' ? frame?.label : null; }; return (
{/* Main Generator Card */}
{/* LEFT: Input Section */}
{/* Twitter Details */}

X (Twitter) Username

setUsername(e.target.value)} className="h-12 text-base rounded-xl border-slate-200 focus:border-black focus:ring-black" />

Enter your X (Twitter) handle to create a profile link.

{/* Design Options */}

Design Options

{/* Color Picker */}
{QR_COLORS.map((c) => ( ))}
{/* Frame Selector */}
{FRAME_OPTIONS.map((frame) => ( ))}
{/* RIGHT: Preview Section */}
{/* QR Card with Frame */}
{/* Frame Label */} {getFrameLabel() && (
{getFrameLabel()}
)} {/* QR Code */}
{/* Info Preview */}

{username || '@username'}

Opens in X (Twitter)
{/* Download Buttons */}

Scanning redirects directly to the X profile.

{/* Upsell Banner */}

Cross-promote your channels

Use a single Dynamic QR Code to link to all your social media profiles at once.

); }