import React, { useRef, type InputHTMLAttributes } from 'react' import { useIntl } from '@cultureamp/i18n-react-intl' import classnames from 'classnames' import { ClearButton } from '~components/ClearButton' import { Icon } from '~components/Icon' import { LoadingSpinner } from '~components/Loading' import { type OverrideClassName } from '~components/types/OverrideClassName' import styles from './InputSearch.module.scss' export type InputSearchProps = { // id is enforced here as there's no label included in this component id: string reversed?: boolean loading?: boolean secondary?: boolean onClear?: () => void } & OverrideClassName, 'defaultValue'>> export const InputSearch = (props: InputSearchProps): JSX.Element => { const { value, onChange, onClear, classNameOverride, disabled, reversed = false, loading = false, secondary = false, ...restProps } = props const { formatMessage } = useIntl() const inputRef = useRef(null) const handleOnClear = (): void => { inputRef.current?.focus() onClear?.() } const clearButtonLabel = formatMessage({ id: 'inputSearch.clear', defaultMessage: 'Clear search', description: 'Label for the clear search button', }) return (
{loading ? ( ) : ( )}
{value && ( )}
) } InputSearch.displayName = 'InputSearch'