{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"shadcn-studio/popover-10","type":"registry:component","title":"Popover 10","description":"A user search popover with debounced input, loading states, and avatar display","dependencies":["lucide-react"],"registryDependencies":["avatar","button","input","popover"],"files":[{"path":"src/registry/new-york/components/popover/popover-10.tsx","content":"'use client'\n\nimport { useEffect, useState } from 'react'\n\nimport { LoaderCircleIcon, SearchIcon } from 'lucide-react'\n\nimport { Avatar, AvatarFallback, AvatarImage } from '@/registry/new-york/ui/avatar'\nimport { Button } from '@/registry/new-york/ui/button'\nimport { Input } from '@/registry/new-york/ui/input'\nimport { Popover, PopoverContent, PopoverTrigger } from '@/registry/new-york/ui/popover'\n\nconst users = [\n  {\n    image: 'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-3.png',\n    name: 'Howard Lloyd',\n    fallback: 'HL',\n    notifications: 3\n  },\n  {\n    image: 'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-6.png',\n    name: 'Olivia Sparks',\n    fallback: 'OS'\n  },\n  {\n    image: 'https://cdn.shadcnstudio.com/ss-assets/avatar/avatar-5.png',\n    name: 'Hallie Richards',\n    fallback: 'HR',\n    notifications: 1\n  }\n]\n\nconst useDebounce = (value: string, delay: number = 300) => {\n  const [debouncedValue, setDebouncedValue] = useState(value)\n\n  useEffect(() => {\n    const timer = setTimeout(() => {\n      setDebouncedValue(value)\n    }, delay)\n\n    return () => {\n      clearTimeout(timer)\n    }\n  }, [value, delay])\n\n  return debouncedValue\n}\n\nconst PopoverSearchDemo = () => {\n  const [inputValue, setInputValue] = useState('')\n  const [isLoading, setIsLoading] = useState(false)\n  const debouncedSearch = useDebounce(inputValue)\n  const [filteredUsers, setFilteredUsers] = useState(users)\n\n  // Handle loading state when input changes\n  useEffect(() => {\n    if (inputValue) {\n      setIsLoading(true)\n    } else {\n      setIsLoading(false)\n    }\n  }, [inputValue])\n\n  // Apply filtering after debounce and update loading state\n  useEffect(() => {\n    if (debouncedSearch.trim() === '') {\n      setFilteredUsers(users)\n      setIsLoading(false)\n    } else {\n      const searchTerm = debouncedSearch.toLowerCase()\n\n      const filtered = users.filter(user => user.name.toLowerCase().includes(searchTerm))\n\n      setFilteredUsers(filtered)\n      setIsLoading(false)\n    }\n  }, [debouncedSearch])\n\n  return (\n    <Popover>\n      <PopoverTrigger asChild>\n        <Button variant='outline' size='icon'>\n          <SearchIcon />\n          <span className='sr-only'>Search users</span>\n        </Button>\n      </PopoverTrigger>\n      <PopoverContent className='w-80'>\n        <div className='grid gap-4'>\n          <div className='relative'>\n            <div className='text-muted-foreground pointer-events-none absolute inset-y-0 left-0 flex items-center justify-center pl-3 peer-disabled:opacity-50'>\n              <SearchIcon className='size-4' />\n              <span className='sr-only'>Search</span>\n            </div>\n            <Input\n              type='search'\n              placeholder='Search users'\n              value={inputValue}\n              onChange={e => setInputValue(e.target.value)}\n              className='peer px-9 [&::-webkit-search-cancel-button]:appearance-none [&::-webkit-search-decoration]:appearance-none [&::-webkit-search-results-button]:appearance-none [&::-webkit-search-results-decoration]:appearance-none'\n            />\n            {isLoading && (\n              <div className='text-muted-foreground pointer-events-none absolute inset-y-0 right-0 flex items-center justify-center pr-3 peer-disabled:opacity-50'>\n                <LoaderCircleIcon className='size-4 animate-spin' />\n                <span className='sr-only'>Loading...</span>\n              </div>\n            )}\n          </div>\n          <ul className='space-y-2'>\n            {filteredUsers.length > 0 ? (\n              filteredUsers.map((user, index) => (\n                <li key={index} className='flex items-center gap-2'>\n                  <Avatar className='size-6'>\n                    <AvatarImage src={user.image} alt={user.name} />\n                    <AvatarFallback className='text-xs'>{user.fallback}</AvatarFallback>\n                  </Avatar>\n                  <div className='flex-1 text-sm font-medium'>{user.name}</div>\n                  {user.notifications && (\n                    <span className='text-muted-foreground text-xs'>{`${user.notifications} Notification${user.notifications > 1 ? 's' : ''}`}</span>\n                  )}\n                </li>\n              ))\n            ) : (\n              <li className='py-2 text-center text-sm'>No users found</li>\n            )}\n          </ul>\n        </div>\n      </PopoverContent>\n    </Popover>\n  )\n}\n\nexport default PopoverSearchDemo\n","type":"registry:component","target":"components/shadcn-studio/popover/popover-10.tsx"}]}