import React, { FunctionComponent } from 'react'; import { ButtonProps, type FormGroupProps } from '@patternfly/react-core'; /** * Defines the helpers passed to the children render prop. * This provides accessibility labels and focus management for each row. */ export interface FieldRowHelpers { /** * Ref callback to attach to the first focusable element in the row. * This enables automatic focus management when rows are added/removed. */ focusRef: (element: HTMLElement | null) => void; /** * Unique ID for this row group */ rowGroupId: string; /** * Complete aria-label string for the first column that includes both row and column context */ firstColumnAriaLabel: string; /** * Complete aria-label string for the second column that includes both row and column context */ secondColumnAriaLabel?: string; } /** * Extends FormGroupProps to inherit standard functionality like * label, helperText, isRequired, and validation states. */ export interface FieldBuilderProps extends Omit { /** Provides an accessible name for the field builder table via a human readable string. */ 'aria-label'?: string; /** Provides an accessible name for the field builder table via a space separated list of IDs. */ 'aria-labelledby'?: string; /** Label for the first column */ firstColumnLabel: React.ReactNode; /** Label for the second column in a two-column layout */ secondColumnLabel?: React.ReactNode; /** The total number of rows to render. This should be derived from the length of the state array managed by the parent. */ rowCount: number; /** * A function that returns the content for each row. This "render prop" provides * maximum flexibility for defining the inputs within each row. * Can return 1 child (single-column) or 2 children (two-column). * The second parameter provides the 0-based index of the current row. */ children: (helpers: FieldRowHelpers, index: number) => React.ReactNode; /** A callback triggered when the "Add" button is clicked. */ onAddRow: (event: React.MouseEvent) => void; /** A callback triggered when a "Remove" button is clicked, which receives the index of the row to remove. */ onRemoveRow: (event: React.MouseEvent, index: number) => void; /** Additional props to customize the "Add" button. */ addButtonProps?: Omit; /** Content for the "Add" button. Defaults to "Add another". */ addButtonContent?: React.ReactNode; /** Additional props to customize the "Remove" buttons. */ removeButtonProps?: Omit; /** * Callback to customize the aria-label for remove buttons. * If not provided, defaults to "Remove {rowGroupLabelPrefix} {rowNumber}". */ removeButtonAriaLabel?: (rowNumber: number, rowGroupLabelPrefix: string) => string; /** * Label prefix for each row group. Defaults to "Row". This is also used to create a default * Table accessible name when the aria-label nor aria-labelledby are not provided. */ rowGroupLabelPrefix?: string; /** * Unique ID prefix for this FieldBuilder instance. * This ensures unique IDs when multiple FieldBuilders exist on the same page. */ fieldBuilderIdPrefix?: string; /** * Callback to customize the announcement message when a row is added. * If not provided, defaults to "New {rowGroupLabelPrefix} added. {rowGroupLabelPrefix} {newRowNumber}." */ onAddRowAnnouncement?: (rowNumber: number, rowGroupLabelPrefix: string) => string; /** * Callback to customize the announcement message when a row is removed. * If not provided, defaults to "{rowGroupLabelPrefix} {removedRowNumber} removed." */ onRemoveRowAnnouncement?: (rowNumber: number, rowGroupLabelPrefix: string) => string; } /** * FieldBuilder is a component group that simplifies the creation of dynamic, * multi-row forms with a consistent layout. It manages the layout and actions * for adding and removing rows, while giving the consumer full control over the fields themselves. */ export declare const FieldBuilder: FunctionComponent; export default FieldBuilder;