Search Results Tabs
gaia/search-results-tabsFreeComponent
A beautiful component for displaying search results with web pages, images, and news in an organized, interactive layout.
Install it
npx shadcn@latest add https://ui.heygaia.io/r/search-results-tabs.jsonSource
1"use client";23import { motion } from "framer-motion";4import Image from "next/image";5import { useCallback, useEffect, useState } from "react";6import { HugeiconsIcon, News01Icon } from "@/components/icons";78import { Button } from "@/components/ui/button";9import {10 Popover,11 PopoverContent,12 PopoverTrigger,13} from "@/components/ui/popover";14import { Skeleton } from "@/components/ui/skeleton";1516export interface ImageResult {17 url: string;18 title?: string;19}2021export interface WebResult {22 title: string;23 url: string;24 content: string;25 date?: string;26}2728export interface NewsResult {29 title: string;30 url: string;31 content: string;32 score?: number;33 date?: string;34}3536export interface SearchResults {37 web?: WebResult[];38 images?: string[] | ImageResult[];39 news?: NewsResult[];40}4142interface SearchResultsTabsProps {43 search_results: SearchResults;44 onImageClick?: (imageUrl: string) => void;45}4647export function SearchResultsTabs({48 search_results,49 onImageClick,50}: SearchResultsTabsProps) {51 return (52 <div className="w-full">53 <div className="space-y-6">54 {search_results.web && search_results.web?.length > 0 && (55 <SourcesButton web={search_results.web} />56 )}5758 {search_results.images && search_results.images?.length > 0 && (59 <ImageResults60 images={search_results.images}61 onImageClick={onImageClick}62 />63 )}6465 {search_results.news && search_results.news?.length > 0 && (66 <NewsResults news={search_results.news} />67 )}68 </div>69 </div>70 );71}7273interface ImageResultsProps {74 images: string[] | ImageResult[];75 onImageClick?: (imageUrl: string) => void;76}7778function ImageResults({ images, onImageClick }: ImageResultsProps) {79 const [validImages, setValidImages] = useState<string[]>([]);8081 useEffect(() => {82 const validateImages = async () => {83 // Convert to string array if needed84 const imageUrls = images.map((img) =>85 typeof img === "string" ? img : img.url,86 );8788 // Filter out obviously invalid images first89 const potentiallyValidImages = imageUrls.filter(90 (imageUrl) => imageUrl && typeof imageUrl === "string",91 );9293 // Test each image by trying to load it94 const validationPromises = potentiallyValidImages.map(95 (imageUrl) =>96 new Promise<string | null>((resolve) => {97 const img = new window.Image();9899 const timeoutId = setTimeout(() => {100 resolve(null); // Timeout after 5 seconds101 }, 5000);102103 img.onload = () => {104 clearTimeout(timeoutId);105// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from gaia
All 26 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Area Chartarea-chart | gaia | Components | Free | 1 dep | |
| Author Tooltipauthor-tooltip | gaia | Components | Free | no deps | |
| Bar Chartbar-chart | gaia | Components | Free | 1 dep | |
| Composercomposer | gaia | Components | Free | no deps | |
| Email Compose Cardemail-compose-card | gaia | Components | Free | no deps | |
| Gauge Chartgauge-chart | gaia | Components | Free | 1 dep | |
| GitHub Stars Buttongithub-stars-button | gaia | Components | Free | 1 dep | |
| Holo Cardholo-card | gaia | Components | Free | 1 dep · 2 files |
