1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-12-02 05:57:29 +01:00
market/src/components/molecules/SearchBar.tsx
Matthias Kretschmann 3505db21da
Owner/publisher search (#187)
* make owner search work

* owner/publisher search from asset details

* copy & cleanup

* style tweaks

* timing

* make search combinations work again

* remove account search highjacking

* switch owner source

* search route fixes

* eth address truncation in text search titles
2020-11-03 14:57:40 +01:00

53 lines
1.3 KiB
TypeScript

import React, { useState, ChangeEvent, FormEvent, ReactElement } from 'react'
import { useNavigate } from '@reach/router'
import styles from './SearchBar.module.css'
import Button from '../atoms/Button'
import Input from '../atoms/Input'
import InputGroup from '../atoms/Input/InputGroup'
export default function SearchBar({
placeholder,
initialValue,
filters,
size
}: {
placeholder?: string
initialValue?: string
filters?: boolean
size?: 'small' | 'large'
}): ReactElement {
const navigate = useNavigate()
const [value, setValue] = useState(initialValue || '')
function handleChange(e: ChangeEvent<HTMLInputElement>) {
setValue(e.target.value)
}
function startSearch(e: FormEvent<HTMLButtonElement>) {
e.preventDefault()
if (value === '') return
navigate(`/search/?text=${value}`)
}
return (
<form className={styles.form}>
<InputGroup>
<Input
type="search"
name="search"
placeholder={placeholder || 'What are you looking for?'}
value={value}
onChange={handleChange}
required
size={size}
/>
<Button onClick={(e: FormEvent<HTMLButtonElement>) => startSearch(e)}>
Search
</Button>
</InputGroup>
{filters && <fieldset className={styles.filters}>Type, Price</fieldset>}
</form>
)
}