The InputField component is a flexible and reusable input wrapper, designed to provide a consistent user experience across different form elements. It encapsulates an input field alongside optional icons, action buttons, and custom focus handling. This component is ideal for use in forms or any UI requiring user input, with accessibility and customization in mind.
npm i @anakin-gbit/input-field
InputField is a composite component that maintains state for input focus, supports unique IDs for accessibility, and allows customization through child components. The following child elements can be passed to InputField to customize its functionality:
import { InputField } from '@anakin-gbit/inputfield'
const Example = () => (
<InputField id="username">
<InputField.Icon>🔍</InputField.Icon>
<InputField.Input label="Input label" />
<InputField.FieldActionButton>Save</InputField.FieldActionButton>
<InputField.FieldActionButton>Cancel</InputField.FieldActionButton>
<InputField.FieldMessage message="Enter the value above" />
<InputField.FieldMessage message="Invalid email" type="error" />
</InputField>
)
The InputField
component accepts the following props:
div
element of the component.InputField.Input
, InputField.Icon
, and InputField.FieldActionButton
.The InputField
component has the following subcomponents, which allow for customizable behavior and appearance: