import {
forwardRef,
InputHTMLAttributes,
ForwardedRef,
ElementType,
} from 'react'
import {
getIconProps,
getInputProps,
getInputWrapperProps,
getInputInvalidIconProps,
getInputStartIconProps,
splitClassNameProp,
} from '@pluralsight/headless-styles'
import { PlaceholderIcon, WarningTriangleFilledIcon } from '@pluralsight/icons'
import type { InputOptions } from '@pluralsight/headless-styles/types'
import { Show, useFormControl } from '../index.ts'
//
function StartInputIcon(
props: Required>
) {
const pandoProps = getInputStartIconProps(props.pandoSize)
const DynamicIcon = props.startIcon
return (
)
}
//
function InvalidInputIcon(props: Required>) {
const pandoProps = getInputInvalidIconProps(props.pandoSize)
return (
)
}
//
interface InputProps
extends InputOptions,
Omit, 'id' | 'name'> {
startIcon?: ElementType
}
function InputEl(props: InputProps, ref: ForwardedRef) {
const { describedBy, pandoSize, startIcon, ...nativeProps } = props
const state = useFormControl()
const pandoInputProps = getInputProps({
...state,
...nativeProps,
describedBy,
classNames: splitClassNameProp(nativeProps.className),
kind: startIcon ? 'icon' : 'default',
pandoSize,
})
return (
)
}
export const Input = forwardRef(InputEl)