import classnames from 'classnames'; import type { ComponentChildren } from 'preact'; import type { EditorProps } from './Editor'; import { Editor } from './Editor'; import { HStack, VStack } from './Stacks'; interface Props { name: string; label: string; hideLabel?: boolean; labelClassName?: string; containerClassName?: string; onChange?: (value: string) => void; useEditor?: Pick; defaultValue?: string; leftSlot?: ComponentChildren; rightSlot?: ComponentChildren; size?: 'sm' | 'md'; className?: string; placeholder?: string; autoFocus?: boolean; } export function Input({ label, hideLabel, className, containerClassName, labelClassName, onChange, placeholder, size = 'md', useEditor, name, leftSlot, rightSlot, defaultValue, ...props }: Props) { const id = `input-${name}`; const inputClassName = classnames( className, '!bg-transparent pl-3 pr-2 min-w-0 h-full w-full focus:outline-none placeholder:text-placeholder', !!leftSlot && '!pl-0.5', !!rightSlot && '!pr-0.5', ); return ( {leftSlot} {useEditor ? ( ) : ( onChange?.(e.currentTarget.value)} placeholder={placeholder} defaultValue={defaultValue} className={inputClassName} {...props} /> )} {rightSlot} ); }