import type { FormEvent, InputHTMLAttributes, ReactNode } from 'react'
import React, { forwardRef, useRef } from 'react'
import Button from '../../atoms/Button'
import Icon from '../../atoms/Icon'
import Input from '../../atoms/Input'
const SearchIcon = () => (
)
type InputProps = Omit, 'onSubmit'>
export interface SearchInputProps extends InputProps {
/**
* Callback function when submitted.
*/
onSubmit: (value: string) => void
/**
* Custom icon inside the submit button.
*/
icon?: ReactNode
/**
* ID to find this component in testing tools (e.g.: cypress, testing library, and jest).
*/
testId?: string
}
const SearchInput = forwardRef(
function SearchInput(
{ onSubmit, icon, testId = 'store-search-input', ...props },
ref
) {
const valueRef = useRef(null)
const handleSubmit = (event: FormEvent) => {
event.preventDefault()
if (valueRef.current?.value !== '') {
onSubmit(valueRef.current!.value)
}
}
return (
)
}
)
export default SearchInput