dynamic-page-range.tsx


Overview

dynamic-page-range.tsx is a React component implemented with TypeScript and React Hook Form. It provides a user interface for dynamically managing a list of page ranges within a form context. Users can add, edit, and remove page ranges, where each range consists of a "from" and "to" numeric input. This component is designed for use in a larger form that likely configures parsing or document processing settings, specifically under the parser_config.pages field array.

Key features include:


Detailed Explanation

Component: DynamicPageRange

A React functional component that renders a dynamic list of page ranges with inputs for "from" and "to" page numbers.

Usage

import { DynamicPageRange } from './dynamic-page-range';

// Inside a form wrapped with react-hook-form context provider
function ExampleForm() {
  const methods = useForm({
    defaultValues: {
      parser_config: {
        pages: [{ from: 1, to: 10 }],
      },
    },
  });

  const onSubmit = (data) => {
    console.log(data);
  };

  return (
    <FormProvider {...methods}>
      <form onSubmit={methods.handleSubmit(onSubmit)}>
        <DynamicPageRange />
        <button type="submit">Submit</button>
      </form>
    </FormProvider>
  );
}

Parameters

Return Value

Internal Working


Implementation Details


Interaction with Other Parts of the System


Visual Diagram

componentDiagram
    component DynamicPageRange {
        +useFormContext()
        +useFieldArray(name='parser_config.pages')
        +useTranslation()
        +render()
    }

    component UI_Components {
        Button
        FormControl
        FormField
        FormItem
        Input
        Separator
    }

    component ReactHookForm {
        useFormContext
        useFieldArray
    }

    component Localization {
        useTranslation
    }

    DynamicPageRange --> ReactHookForm : form context, field array
    DynamicPageRange --> UI_Components : UI elements
    DynamicPageRange --> Localization : text translation

Summary of Exposed Methods and Properties

Name

Type

Description

DynamicPageRange

React Functional Component

Renders dynamic page range input fields, handles addition/removal.


Example Interaction Scenario

  1. User opens the form containing DynamicPageRange.

  2. The component renders existing page ranges as pairs of numeric inputs.

  3. User can change the "from" and "to" page numbers for each range.

  4. User clicks the "Add Page" button to append a new range initialized as 1 to 100.

  5. User clicks the "X" button next to a range to remove it.

  6. Form state updates accordingly, ready for validation or submission.


End of Documentation for dynamic-page-range.tsx