import { FunctionComponent, Ref } from 'preact'; import { JSXInternal } from 'preact/src/jsx'; import { forwardRef } from 'preact/compat'; import { Icon, IconType } from './Icon'; import { IconButton } from './IconButton'; type ToggleProps = { toggleOnIcon: IconType; toggleOffIcon: IconType; title: string; toggled: boolean; onClick: (toggled: boolean) => void; }; type Props = { icon: IconType; inputType: 'text' | 'email' | 'password'; className?: string; iconClassName?: string; value: string | undefined; onChange: JSXInternal.GenericEventHandler; onFocus?: JSXInternal.GenericEventHandler; onKeyDown?: JSXInternal.KeyboardEventHandler; disabled?: boolean; placeholder: string; toggle?: ToggleProps; }; const DISABLED_CLASSNAME = 'bg-grey-5 cursor-not-allowed'; export const InputWithIcon: FunctionComponent = forwardRef( ( { icon, inputType, className, iconClassName, value, onChange, onFocus, onKeyDown, disabled, toggle, placeholder, }: Props, ref: Ref ) => { const handleToggle = () => { if (toggle) toggle.onClick(!toggle?.toggled); }; return (
{toggle ? (
) : null}
); } );