@payfit/unity-components
Version:
65 lines (64 loc) • 2.55 kB
TypeScript
import { ReactNode } from 'react';
import { LabelProps } from '../../../../core/components/label/Label.js';
import { DateRangePickerProps } from '../date-range-picker/DateRangePicker.js';
export type DateRangePickerFieldProps = DateRangePickerProps & Pick<LabelProps, 'isRequired' | 'requiredVariant'> & {
/** The label for the date range picker field. */
label: string;
/** Helper text to display below the date range picker field. */
helperText?: ReactNode;
/** A contextual link to display below the date range picker field. */
contextualLink?: ReactNode;
};
/**
* The `DateRangePickerField` component renders a full field (label, date range picker)
* wired to the Form context. It manages state and accessibility via the
* context provided by `useUnityForm` and `<form.AppField name="…">`.
*
* Behavior:
* - Renders `DateRangePicker` with calendar overlay for date range selection.
* - Displays the label (`FormLabel`), helper text (`FormHelperText`),
* feedback messages (`FormFeedbackText`), and an optional contextual link.
*
* Accessibility:
* - Automatically wires `aria-labelledby`, `aria-describedby` (helper/feedback), and
* `aria-details` using identifiers from the `a11y` context.
*
* Example:
* ```tsx
* import { DateRangePickerField } from "@payfit/unity-components"
* import { useUnityForm } from "@payfit/unity-components"
* import { CalendarDate } from '@internationalized/date'
*
* function Example() {
* const schema = z.object({
* period: z.custom<{ start: CalendarDate; end: CalendarDate } | null>()
* .refine(range => range !== null, 'Date range is required'),
* })
*
* const form = useUnityForm({ validators: {
* onBlur: schema,
* } })
* return (
* <form>
* <form.AppField name="period">
* {() => (
* <DateRangePickerField
* label="Period"
* helperText="Select a date range"
* />
* )}
* </form.AppField>
* </form>
* )
* }
* ```
*/
declare const DateRangePickerField: import('react').ForwardRefExoticComponent<DateRangePickerProps & Pick<LabelProps, "isRequired" | "requiredVariant"> & {
/** The label for the date range picker field. */
label: string;
/** Helper text to display below the date range picker field. */
helperText?: ReactNode;
/** A contextual link to display below the date range picker field. */
contextualLink?: ReactNode;
} & import('react').RefAttributes<HTMLDivElement>>;
export { DateRangePickerField };