Spaces:
Running
Running
File size: 8,308 Bytes
8af739b 2a1df12 467789d 2a1df12 8af739b 2a1df12 467789d 2a1df12 467789d 8af739b 467789d 8af739b 7f6d612 8af739b 7f6d612 8af739b 7f6d612 8af739b 7f6d612 8af739b 7f6d612 8af739b 7f6d612 8af739b 7f6d612 2a1df12 8af739b 2a1df12 7f6d612 2a1df12 7f6d612 8af739b 7f6d612 8af739b 7f6d612 8af739b 7f6d612 8af739b 7f6d612 8af739b 7f6d612 8af739b 7f6d612 8af739b |
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
'use client'
import React, { useState, useRef, useEffect } from 'react'
import {
MagnifyingGlass,
X,
Folder,
Calendar,
Clock,
Sparkle,
Globe,
DeviceMobile,
Function as FunctionIcon,
Brain
} from '@phosphor-icons/react'
import { motion, AnimatePresence } from 'framer-motion'
interface SpotlightSearchProps {
isOpen: boolean
onClose: () => void
onOpenApp: (appId: string) => void
}
interface SearchResult {
id: string
name: string
type: 'app' | 'file' | 'setting'
icon?: React.ReactNode
}
export function SpotlightSearch({ isOpen, onClose, onOpenApp }: SpotlightSearchProps) {
const [query, setQuery] = useState('')
const [results, setResults] = useState<SearchResult[]>([])
const inputRef = useRef<HTMLInputElement>(null)
const apps: SearchResult[] = [
{ id: 'files', name: 'Files', type: 'app', icon: <div className="w-6 h-6 bg-gradient-to-br from-blue-400 to-cyan-200 rounded-md flex items-center justify-center border border-white/30"><Folder size={16} weight="fill" className="text-blue-900" /></div> },
{ id: 'calendar', name: 'Calendar', type: 'app', icon: <div className="w-6 h-6 bg-white rounded-md flex items-center justify-center border border-gray-200"><Calendar size={16} weight="regular" className="text-red-500" /></div> },
{ id: 'clock', name: 'Clock', type: 'app', icon: <div className="w-6 h-6 bg-white rounded-full flex items-center justify-center border border-gray-200"><Clock size={16} weight="regular" className="text-black" /></div> },
{ id: 'gemini', name: 'Gemini Chat', type: 'app', icon: <div className="w-6 h-6 bg-gradient-to-b from-white to-blue-50 rounded-md flex items-center justify-center border border-white/50"><Sparkle size={16} weight="fill" className="text-blue-500" /></div> },
{ id: 'flutter-editor', name: 'Flutter IDE', type: 'app', icon: <div className="w-6 h-6 bg-gradient-to-b from-[#54C5F8] to-[#29B6F6] rounded-md flex items-center justify-center border border-white/20"><DeviceMobile size={16} weight="fill" className="text-white" /></div> },
{ id: 'latex-editor', name: 'LaTeX Studio', type: 'app', icon: <div className="w-6 h-6 bg-gradient-to-b from-slate-700 to-slate-900 rounded-md flex items-center justify-center border border-white/20"><FunctionIcon size={16} weight="bold" className="text-green-400" /></div> },
{ id: 'quiz', name: 'Quiz Master', type: 'app', icon: <div className="w-6 h-6 bg-gradient-to-br from-teal-400 to-emerald-500 rounded-md flex items-center justify-center border border-white/20"><Brain size={16} weight="fill" className="text-white" /></div> },
]
const files: SearchResult[] = [
{ id: 'document', name: 'Document.pdf', type: 'file' },
{ id: 'resume', name: 'Resume.docx', type: 'file' },
{ id: 'budget', name: 'Budget.xlsx', type: 'file' },
{ id: 'presentation', name: 'Presentation.pptx', type: 'file' },
]
const settings: SearchResult[] = [
{ id: 'wallpaper', name: 'Change Wallpaper', type: 'setting' },
{ id: 'theme', name: 'Dark Mode', type: 'setting' },
{ id: 'display', name: 'Display Settings', type: 'setting' },
]
const allItems = [...apps, ...files, ...settings]
useEffect(() => {
if (isOpen) {
setQuery('')
setResults([])
setTimeout(() => inputRef.current?.focus(), 100)
}
}, [isOpen])
useEffect(() => {
if (query.trim() === '') {
setResults([])
return
}
const filtered = allItems.filter(item =>
item.name.toLowerCase().includes(query.toLowerCase())
)
setResults(filtered.slice(0, 8))
}, [query])
const handleSelect = (result: SearchResult) => {
if (result.type === 'app') {
onOpenApp(result.id)
}
onClose()
setQuery('')
}
const handleKeyDown = (e: React.KeyboardEvent) => {
if (e.key === 'Escape') {
onClose()
} else if (e.key === 'Enter' && results.length > 0) {
handleSelect(results[0])
}
}
return (
<AnimatePresence>
{isOpen && (
<>
{/* Backdrop */}
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
className="fixed inset-0 bg-black/20 z-[9998]"
onClick={onClose}
/>
{/* Search Box */}
<motion.div
initial={{ opacity: 0, scale: 0.95, y: -20 }}
animate={{ opacity: 1, scale: 1, y: 0 }}
exit={{ opacity: 0, scale: 0.95, y: -20 }}
transition={{ duration: 0.15, ease: 'easeOut' }}
className="fixed top-[15%] sm:top-[20%] left-1/2 -translate-x-1/2 w-[95vw] sm:w-[600px] max-w-[600px] glass rounded-xl shadow-2xl z-[9999]"
>
<div className="flex items-center px-3 sm:px-4 py-2.5 sm:py-3 gap-2 sm:gap-3 border-b border-gray-200/20">
<MagnifyingGlass size={20} weight="regular" className="text-gray-600 sm:w-6 sm:h-6 flex-shrink-0" />
<input
ref={inputRef}
type="text"
value={query}
onChange={(e) => setQuery(e.target.value)}
onKeyDown={handleKeyDown}
className="flex-1 bg-transparent text-base sm:text-xl focus:outline-none text-gray-800 placeholder-gray-400 min-w-0"
placeholder="Spotlight Search"
autoComplete="off"
spellCheck={false}
/>
<button
onClick={onClose}
className="text-gray-500 hover:text-gray-700 transition-colors flex-shrink-0"
>
<X size={18} weight="regular" className="sm:w-5 sm:h-5" />
</button>
</div>
{/* Results */}
{results.length > 0 && (
<div className="max-h-64 sm:max-h-96 overflow-y-auto p-1.5 sm:p-2">
{results.map((result, index) => (
<div
key={result.id}
onClick={() => handleSelect(result)}
className={`flex items-center px-2 sm:px-3 py-2 sm:py-2.5 hover:bg-blue-500 hover:text-white rounded-lg cursor-pointer transition-colors gap-2 sm:gap-3 ${index === 0 ? 'bg-blue-500/10' : ''
}`}
>
{result.icon && (
<div className="w-7 h-7 sm:w-8 sm:h-8 flex items-center justify-center flex-shrink-0">
{result.icon}
</div>
)}
<div className="flex-1 flex flex-col min-w-0">
<span className="font-medium text-sm sm:text-base truncate">{result.name}</span>
<span className="text-[10px] sm:text-xs opacity-70 capitalize">{result.type}</span>
</div>
{result.type === 'app' && (
<span className="text-[10px] sm:text-xs opacity-50 hidden xs:inline flex-shrink-0">⌘ Enter</span>
)}
</div>
))}
</div>
)}
{/* No results */}
{query.trim() !== '' && results.length === 0 && (
<div className="p-3 sm:p-4 text-center text-gray-500 text-sm sm:text-base">
No results found for "{query}"
</div>
)}
{/* Quick Actions (when no query) */}
{query === '' && (
<div className="p-3 sm:p-4">
<div className="text-[10px] sm:text-xs font-semibold text-gray-500 uppercase tracking-wider mb-2">
Suggestions
</div>
<div className="grid grid-cols-2 gap-1.5 sm:gap-2">
{apps.slice(0, 4).map(app => (
<div
key={app.id}
onClick={() => handleSelect(app)}
className="flex items-center px-2 sm:px-3 py-1.5 sm:py-2 hover:bg-gray-100 rounded-lg cursor-pointer transition-colors"
>
<span className="text-xs sm:text-sm truncate">{app.name}</span>
</div>
))}
</div>
</div>
)}
</motion.div>
</>
)}
</AnimatePresence>
)
} |