search.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { SearchIcon } from 'lucide-react'
  2. import { cn } from '@/lib/utils'
  3. import { useSearch } from '@/context/search-provider'
  4. import { Button } from './ui/button'
  5. export function Search({
  6. className = '',
  7. placeholder = 'Search',
  8. ...props
  9. }: React.ComponentProps<'button'> & { placeholder?: string }) {
  10. const { setOpen } = useSearch()
  11. return (
  12. <Button
  13. {...props}
  14. variant='outline'
  15. className={cn(
  16. 'group relative h-8 w-full flex-1 justify-start rounded-md bg-muted/25 text-sm font-normal text-muted-foreground shadow-none hover:bg-accent sm:w-40 sm:pe-12 md:flex-none lg:w-52 xl:w-64',
  17. className
  18. )}
  19. aria-keyshortcuts='Meta+K Control+K'
  20. onClick={() => setOpen(true)}
  21. >
  22. <SearchIcon
  23. aria-hidden='true'
  24. className='absolute start-1.5 top-1/2 -translate-y-1/2'
  25. size={16}
  26. />
  27. <span className='ms-4'>{placeholder}</span>
  28. <kbd className='pointer-events-none absolute end-[0.3rem] top-[0.3rem] hidden h-5 items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium opacity-100 select-none group-hover:bg-accent sm:flex'>
  29. <span className='text-xs'>⌘</span>K
  30. </kbd>
  31. </Button>
  32. )
  33. }