46 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-06-08 11:48:22 +08:00
import { css, cx } from '@emotion/css'
import Icon from '../../Icon'
2022-06-11 00:19:07 +08:00
import { breakpoint as bp } from '@/web/utils/const'
2022-06-25 13:47:07 +08:00
import { useNavigate } from 'react-router-dom'
import { useState } from 'react'
2022-06-08 11:48:22 +08:00
const SearchBox = () => {
2022-06-25 13:47:07 +08:00
const navigate = useNavigate()
const [searchText, setSearchText] = useState('')
2022-06-08 11:48:22 +08:00
return (
2022-06-11 00:19:07 +08:00
<div
className={cx(
'app-region-no-drag flex items-center rounded-full bg-day-600 p-2.5 text-neutral-500 dark:bg-night-600',
css`
${bp.lg} {
min-width: 284px;
}
`
)}
>
2022-06-08 11:48:22 +08:00
<Icon name='search' className='mr-2.5 h-7 w-7' />
<input
2022-06-11 00:19:07 +08:00
placeholder='Search'
className={cx(
'flex-shrink bg-transparent font-medium placeholder:text-neutral-500 dark:text-neutral-200',
css`
2022-06-14 23:23:34 +08:00
@media (max-width: 420px) {
2022-06-11 00:19:07 +08:00
width: 142px;
}
`
)}
2022-06-25 13:47:07 +08:00
value={searchText}
onChange={e => setSearchText(e.target.value)}
onKeyDown={e => {
if (e.key !== 'Enter') return
e.preventDefault()
navigate(`/search/${searchText}`)
}}
2022-06-08 11:48:22 +08:00
/>
</div>
)
}
export default SearchBox