| // src/components/messages/RichStickerPicker.tsx | |
| import { useEffect, useRef, useState, useMemo } from "react"; | |
| import Lottie from "lottie-react"; | |
| import { X, Search, Loader2 } from "lucide-react"; | |
| interface StickerPack { | |
| id: string; | |
| name: string; | |
| stickers: { id: string; src: string | object; name: string; emoji?: string }[]; | |
| } | |
| // Inline sample Lottie stickers โ replace with your hosted .json URLs | |
| const STICKER_PACKS: StickerPack[] = [ | |
| { | |
| id: "favorites", | |
| name: "Favorites", | |
| stickers: [ | |
| { id: "hello", src: "/stickers/lottie/hello.json", name: "Hello", emoji: "๐" }, | |
| { id: "like", src: "/stickers/lottie/like.json", name: "Like", emoji: "๐" }, | |
| { id: "fire", src: "/stickers/lottie/fire.json", name: "Fire", emoji: "๐ฅ" }, | |
| { id: "laugh", src: "/stickers/lottie/laugh.json", name: "Laugh", emoji: "๐" }, | |
| { id: "cry", src: "/stickers/lottie/cry.json", name: "Cry", emoji: "๐ข" }, | |
| { id: "clap", src: "/stickers/lottie/clap.json", name: "Clap", emoji: "๐" }, | |
| { id: "party", src: "/stickers/lottie/party.json", name: "Party", emoji: "๐" }, | |
| { id: "wow", src: "/stickers/lottie/wow.json", name: "Wow", emoji: "๐ฎ" }, | |
| ], | |
| }, | |
| { | |
| id: "reactions", | |
| name: "Reactions", | |
| stickers: [ | |
| { id: "love", src: "/stickers/lottie/love.json", name: "Love", emoji: "โค๏ธ" }, | |
| { id: "angry", src: "/stickers/lottie/angry.json", name: "Angry", emoji: "๐ก" }, | |
| { id: "sleep", src: "/stickers/lottie/sleep.json", name: "Sleep", emoji: "๐ด" }, | |
| { id: "think", src: "/stickers/lottie/think.json", name: "Think", emoji: "๐ค" }, | |
| ], | |
| }, | |
| ]; | |
| interface RichStickerPickerProps { | |
| onSelect: (stickerSrc: string | object, stickerId: string) => void; | |
| onClose: () => void; | |
| } | |
| export function RichStickerPicker({ onSelect, onClose }: RichStickerPickerProps) { | |
| const [activePackId, setActivePackId] = useState(STICKER_PACKS[0]?.id || ""); | |
| const [search, setSearch] = useState(""); | |
| const panelRef = useRef<HTMLDivElement>(null); | |
| const activePack = STICKER_PACKS.find((p) => p.id === activePackId); | |
| const filteredStickers = useMemo(() => { | |
| if (!search.trim()) return activePack?.stickers || []; | |
| const q = search.toLowerCase(); | |
| return (activePack?.stickers || []).filter( | |
| (s) => s.name.toLowerCase().includes(q) || s.emoji?.includes(q) | |
| ); | |
| }, [search, activePack]); | |
| // Close on outside click | |
| useEffect(() => { | |
| const handleClick = (e: MouseEvent) => { | |
| if (panelRef.current && !panelRef.current.contains(e.target as Node)) { | |
| onClose(); | |
| } | |
| }; | |
| document.addEventListener("mousedown", handleClick); | |
| return () => document.removeEventListener("mousedown", handleClick); | |
| }, [onClose]); | |
| return ( | |
| <div | |
| ref={panelRef} | |
| className="absolute bottom-full mb-2 left-0 w-[340px] bg-white dark:bg-gray-800 rounded-2xl shadow-2xl border border-gray-200 dark:border-gray-700 overflow-hidden z-50" | |
| > | |
| {/* Header */} | |
| <div className="flex items-center justify-between p-3 border-b border-gray-100 dark:border-gray-700"> | |
| <h3 className="font-semibold text-sm text-gray-700 dark:text-gray-200">Stickers</h3> | |
| <button onClick={onClose} className="text-gray-400 hover:text-gray-600 dark:hover:text-gray-300"> | |
| <X className="w-4 h-4" /> | |
| </button> | |
| </div> | |
| {/* Search */} | |
| <div className="p-2"> | |
| <div className="relative"> | |
| <Search className="absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-gray-400" /> | |
| <input | |
| type="text" | |
| placeholder="Search stickers..." | |
| value={search} | |
| onChange={(e) => setSearch(e.target.value)} | |
| className="w-full pl-7 pr-3 py-1.5 text-sm bg-gray-100 dark:bg-gray-700 rounded-lg focus:outline-none" | |
| /> | |
| </div> | |
| </div> | |
| {/* Pack tabs */} | |
| <div className="flex gap-1 px-2 pb-1 overflow-x-auto"> | |
| {STICKER_PACKS.map((pack) => ( | |
| <button | |
| key={pack.id} | |
| onClick={() => setActivePackId(pack.id)} | |
| className={`px-3 py-1.5 rounded-full text-xs font-medium whitespace-nowrap transition ${ | |
| activePackId === pack.id | |
| ? "bg-primary text-white" | |
| : "bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300 hover:bg-gray-200" | |
| }`} | |
| > | |
| {pack.name} | |
| </button> | |
| ))} | |
| </div> | |
| {/* Sticker grid */} | |
| <div className="p-3 grid grid-cols-4 gap-2 max-h-[280px] overflow-y-auto"> | |
| {filteredStickers.map((sticker) => ( | |
| <button | |
| key={sticker.id} | |
| onClick={() => onSelect(sticker.src, sticker.id)} | |
| className="aspect-square bg-gray-50 dark:bg-gray-700/50 rounded-xl hover:bg-gray-100 dark:hover:bg-gray-600 transition p-1.5 group relative" | |
| title={sticker.name} | |
| > | |
| <Lottie | |
| animationData={sticker.src as any} | |
| loop={true} | |
| autoplay={true} | |
| className="w-full h-full" | |
| rendererSettings={{ preserveAspectRatio: "xMidYMid slice" }} | |
| /> | |
| <span className="absolute -bottom-1 -right-1 text-[10px] opacity-0 group-hover:opacity-100 transition"> | |
| {sticker.emoji} | |
| </span> | |
| </button> | |
| ))} | |
| {filteredStickers.length === 0 && ( | |
| <div className="col-span-4 py-8 text-center text-gray-400 text-sm"> | |
| No stickers found | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| ); | |
| } |
Xet Storage Details
- Size:
- 5.61 kB
- Xet hash:
- 8ce6231ec727aeec64166eec30bc65357e28acf5625765b37d7563f9bd54b0bb
ยท
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.