handle resetting search field

This commit is contained in:
Kévin Cocchi
2022-02-06 12:17:29 +01:00
parent 99ced8878a
commit 41f0432e8d
4 changed files with 39 additions and 24 deletions

View File

@ -15,12 +15,19 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import { html } from "../lib/htm/preact.js"
export const SearchBox = ({ onKeyUp, placeholder = 'Find stickers' }) => {
const component = html`
export const SearchBox = ({ onKeyUp, resetSearch, value }) => {
const className = `icon-display ${value ? 'reset-click-zone' : null}`
const title = value ? 'Click to reset' : null
const onClick = value ? resetSearch : null
const iconToDisplay = `icon-${!value ? 'search' : 'reset'}`
return html`
<div class="search-box">
<input type="text" placeholder=${placeholder} onKeyUp=${onKeyUp} />
<span class="icon icon-search" />
<input value=${value} placeholder="Find stickers" onKeyUp=${onKeyUp} />
<div class=${className} title=${title} onClick=${onClick}>
<span class="icon ${iconToDisplay}" />
</div>
</div>
`
return component
}