input.tsx


Overview

The input.tsx file provides a set of reusable, customizable React input components designed to handle various input scenarios with consistent styling and enhanced functionalities. It includes a base Input component with controlled and uncontrolled value handling, and several extended components:

These components enable consistent UI/UX patterns for input fields across the application, integrating with utility functions and icons, and support forwarding refs for integration with forms or external libraries.


Components and Exports

1. Input

Description

The core input component wrapping a native HTML <input> element, supporting controlled and uncontrolled usage. It normalizes numeric input changes by converting string values to numbers before propagating changes.

Declaration

const Input = React.forwardRef<HTMLInputElement, InputProps>(
  ({ className, type, value, onChange, ...props }, ref) => { ... }
);

Props

InputProps extends standard React input attributes (React.InputHTMLAttributes<HTMLInputElement>) with optional:

Parameters

Behavior

Usage Example

<Input
  type="text"
  value={textValue}
  onChange={(e) => setTextValue(e.target.value)}
  className="custom-input"
/>

2. ExpandedInput

Description

An enhanced input wrapper that allows injecting prefix and suffix React nodes (e.g., icons or buttons) inside the input field container, positioned absolutely within the input wrapper.

Declaration

const ExpandedInput = ({
  prefix,
  suffix,
  className,
  ...props
}: ExpandedInputProps) => { ... }

Props

Behavior

Usage Example

<ExpandedInput
  prefix={<SomeIcon />}
  suffix={<ClearButton />}
  value={value}
  onChange={handleChange}
/>

3. SearchInput

Description

A specialized input component for search functionality. It composes ExpandedInput with a search icon as a prefix.

Declaration

const SearchInput = (props: InputProps) => { ... }

Props

Behavior

Usage Example

<SearchInput
  value={searchTerm}
  onChange={(e) => setSearchTerm(e.target.value)}
/>

4. InnerBlurInput / BlurInput

Description

An input component that delays propagating changes to the parent until the input loses focus (onBlur event). This avoids frequent updates while typing.

BlurInput is a memoized version of InnerBlurInput for optimization.

Declaration

const InnerBlurInput = React.forwardRef<
  HTMLInputElement,
  InputProps & { value: Value; onChange(value: Value): void }
>(({ value, onChange, ...props }, ref) => { ... });

export const BlurInput = React.memo(InnerBlurInput);

Props

Behavior

Usage Example

const [value, setValue] = React.useState('');

<BlurInput
  value={value}
  onChange={(val) => setValue(val)}
/>

5. NumberInput

Description

A numeric input component that ensures the value passed to onChange is a number, converting from string input.

Declaration

const NumberInput = React.forwardRef<
  HTMLInputElement,
  NumberInputProps & { value: Value; onChange(value: Value): void }
>(function NumberInput({ onChange, ...props }, ref) { ... });

Props

Behavior

Usage Example

const [num, setNum] = React.useState<number>(0);

<NumberInput
  value={num}
  onChange={(val) => setNum(val)}
/>

Important Implementation Details


Interaction with Other Parts of the System


Visual Diagram

classDiagram
    class Input {
        +value: string | number | readonly string[] | undefined
        +onChange(event: React.ChangeEvent<HTMLInputElement>): void
        +ref: React.Ref<HTMLInputElement>
        +handleChange(e: React.ChangeEvent<HTMLInputElement>): void
    }

    class ExpandedInput {
        +prefix?: React.ReactNode
        +suffix?: React.ReactNode
        +className?: string
        +props: InputProps
    }

    class SearchInput {
        +props: InputProps
    }

    class InnerBlurInput {
        +value: string | number | readonly string[] | undefined
        +onChange(value: string | number | readonly string[] | undefined): void
        +ref: React.Ref<HTMLInputElement>
        +handleChange(e: React.ChangeEvent<HTMLInputElement>): void
        +handleBlur(e: React.FocusEvent<HTMLInputElement>): void
        -val: string | number | readonly string[] | undefined (state)
    }

    class BlurInput {
        <<memoized>> InnerBlurInput
    }

    class NumberInput {
        +value: string | number | readonly string[] | undefined
        +onChange(value: number): void
        +ref: React.Ref<HTMLInputElement>
    }

    ExpandedInput --> Input : uses >
    SearchInput --> ExpandedInput : uses >
    InnerBlurInput --> Input : uses >
    BlurInput --|> InnerBlurInput
    NumberInput --> Input : uses >

Summary

The input.tsx file provides a modular, extensible set of React input components with advanced features such as controlled/uncontrolled modes, input value normalization, prefix/suffix adornments, delayed update on blur, and numeric input handling. These components ensure consistent styling and behavior across the application, improve usability, and support integration with form libraries via ref forwarding.

They interact with utility functions and icon libraries and are designed for easy extension and reuse.


End of Documentation for input.tsx