replace-datetime API - v5.0.1
    Preparing search index...

    Interface DateTimeProps

    Props accepted by the Datetime component.

    Every prop is optional; sensible defaults are applied for all of them.

    interface DateTimeProps {
        className?: string | string[];
        closeOnClickOutside?: boolean;
        closeOnSelect?: boolean;
        closeOnTab?: boolean;
        dateFormat?: string | boolean;
        displayTimeZone?: string;
        initialValue?: string | Dayjs | Date;
        initialViewDate?: string | Dayjs | Date;
        initialViewMode?: ViewMode;
        input?: boolean;
        inputProps?: InputHTMLAttributes<HTMLInputElement> & Record<string, any>;
        isValidDate?: (date: Dayjs) => boolean;
        locale?: string;
        onBeforeNavigate?: (
            nextView: ViewMode,
            currentView: ViewMode,
            viewDate: Dayjs,
        ) => ViewMode;
        onChange?: (value: string | Dayjs) => void;
        onClose?: (value: string | Dayjs) => void;
        onNavigate?: (view: ViewMode) => void;
        onNavigateBack?: (amount: number, type: string) => void;
        onNavigateForward?: (amount: number, type: string) => void;
        onOpen?: () => void;
        open?: boolean;
        renderDay?: (props: any, date: Dayjs, selectedDate?: Dayjs) => ReactNode;
        renderInput?: (
            props: any,
            openCalendar: () => void,
            closeCalendar: () => void,
        ) => ReactNode;
        renderMonth?: (
            props: any,
            month: number,
            year: number,
            selectedDate?: Dayjs,
        ) => ReactNode;
        renderView?: (view: ViewMode, renderDefault: () => ReactNode) => ReactNode;
        renderYear?: (props: any, year: number, selectedDate?: Dayjs) => ReactNode;
        strictParsing?: boolean;
        timeConstraints?: any;
        timeFormat?: string | boolean;
        updateOnView?: ViewMode;
        utc?: boolean;
        value?: string | Dayjs | Date;
    }
    Index

    Properties

    className?: string | string[]

    One or more CSS class names appended to the root <div> wrapper.

    <Datetime className="my-picker" />
    <Datetime className={['theme-dark', 'compact']} />
    closeOnClickOutside?: boolean

    When true, clicking outside the picker closes the calendar.

    true
    
    closeOnSelect?: boolean

    When true, the calendar closes automatically as soon as the user selects a value from the final view (day for a date picker, etc.).

    false
    
    closeOnTab?: boolean

    When true, pressing the Tab key closes the calendar.

    true
    
    dateFormat?: string | boolean

    Day.js format string for the date portion (e.g. 'YYYY-MM-DD'). Pass false to hide the date part entirely (time-only picker). Pass true to use the locale default.

    true (locale default)
    
    <Datetime timeFormat={false} />
    
    displayTimeZone?: string

    A timezone zone name (e.g. 'America/New_York').

    initialValue?: string | Dayjs | Date

    Initial value for the picker in uncontrolled mode. Accepts a dayjs object, a native Date, or a date string.

    initialViewDate?: string | Dayjs | Date

    The date/time that the calendar initially navigates to (i.e. the month shown when the picker first opens). Defaults to value, initialValue, or today if neither is set.

    initialViewMode?: ViewMode

    Which calendar view to show first.

    Determined automatically from dateFormat.

    input?: boolean

    When true, the picker is displayed inside an <input> field that opens a floating calendar. When false, the calendar is always visible (static / inline mode).

    true
    
    inputProps?: InputHTMLAttributes<HTMLInputElement> & Record<string, any>

    Props forwarded directly to the underlying <input> element. Any standard React.InputHTMLAttributes are accepted in addition to arbitrary data attributes.

    <Datetime inputProps={{ placeholder: 'Pick a date…', id: 'my-date' }} />
    
    isValidDate?: (date: Dayjs) => boolean

    Return true for dates that should be selectable, false to disable them.

    Type Declaration

      • (date: Dayjs): boolean
      • Parameters

        • date: Dayjs

          The dayjs date being evaluated.

        Returns boolean

        true if the date is valid/selectable.

    <Datetime isValidDate={(d) => d.isSameOrAfter(dayjs(), 'day')} />
    
    locale?: string

    A dayjs locale identifier string (e.g. 'es', 'fr', 'de'). Applied to month/day names and the default date/time format.

    <Datetime locale="es" />
    
    onBeforeNavigate?: (
        nextView: ViewMode,
        currentView: ViewMode,
        viewDate: Dayjs,
    ) => ViewMode

    Called before the view changes, allowing the host to veto or redirect navigation. Return nextView to allow, or a different ViewMode to redirect.

    Type Declaration

      • (nextView: ViewMode, currentView: ViewMode, viewDate: Dayjs): ViewMode
      • Parameters

        • nextView: ViewMode

          The view the user is trying to navigate to.

        • currentView: ViewMode

          The view currently displayed.

        • viewDate: Dayjs

          The dayjs date currently in focus.

        Returns ViewMode

        The ViewMode that should actually be shown.

    onChange?: (value: string | Dayjs) => void

    Called every time the user changes the selected value, whether by clicking a day/month/year, adjusting the time spinner, or typing in the input field.

    Type Declaration

      • (value: string | Dayjs): void
      • Parameters

        • value: string | Dayjs

          A valid dayjs object when the input is parseable, or the raw string when it cannot be parsed.

        Returns void

    <Datetime onChange={(v) => {
    if (dayjs.isDayjs(v)) console.log(v.toISOString());
    }} />
    onClose?: (value: string | Dayjs) => void

    Called when the calendar/time-picker overlay is closed.

    Type Declaration

      • (value: string | Dayjs): void
      • Parameters

        • value: string | Dayjs

          The currently selected value at close time.

        Returns void

    onNavigate?: (view: ViewMode) => void

    Called when the user navigates to a different view (e.g. from days to months).

    Type Declaration

      • (view: ViewMode): void
      • Parameters

        • view: ViewMode

          The new active view mode.

        Returns void

    onNavigateBack?: (amount: number, type: string) => void

    Called when the user clicks the "previous" navigation arrow.

    Type Declaration

      • (amount: number, type: string): void
      • Parameters

        • amount: number

          Number of units navigated back.

        • type: string

          Unit of navigation (e.g. 'months', 'years').

        Returns void

    onNavigateForward?: (amount: number, type: string) => void

    Called when the user clicks the "next" navigation arrow.

    Type Declaration

      • (amount: number, type: string): void
      • Parameters

        • amount: number

          Number of units navigated forward.

        • type: string

          Unit of navigation (e.g. 'months', 'years').

        Returns void

    onOpen?: () => void

    Called when the calendar/time-picker overlay is opened.

    open?: boolean

    Programmatically control whether the calendar overlay is open. When set, the component becomes fully controlled — use onOpen/onClose to manage the state externally.

    renderDay?: (props: any, date: Dayjs, selectedDate?: Dayjs) => ReactNode

    Custom render function for each day cell in the calendar grid.

    Type Declaration

      • (props: any, date: Dayjs, selectedDate?: Dayjs): ReactNode
      • Parameters

        • props: any

          Props to spread on the <td> element (includes click handlers).

        • date: Dayjs

          The dayjs date for this cell.

        • OptionalselectedDate: Dayjs

          The currently selected date, if any.

        Returns ReactNode

    <Datetime
    renderDay={(props, date) => (
    <td {...props} style={{ color: date.day() === 0 ? 'red' : undefined }}>
    {date.date()}
    </td>
    )}
    />
    renderInput?: (
        props: any,
        openCalendar: () => void,
        closeCalendar: () => void,
    ) => ReactNode

    Custom render function for the text input.

    Type Declaration

      • (props: any, openCalendar: () => void, closeCalendar: () => void): ReactNode
      • Parameters

        • props: any

          Props to spread on your custom input element.

        • openCalendar: () => void

          Call to open the calendar programmatically.

        • closeCalendar: () => void

          Call to close the calendar programmatically.

        Returns ReactNode

    <Datetime
    renderInput={(props, open) => (
    <button onClick={open}>{props.value || 'Pick a date'}</button>
    )}
    />
    renderMonth?: (
        props: any,
        month: number,
        year: number,
        selectedDate?: Dayjs,
    ) => ReactNode

    Custom render function for each month cell in the month-selection view.

    Type Declaration

      • (props: any, month: number, year: number, selectedDate?: Dayjs): ReactNode
      • Parameters

        • props: any

          Props to spread on the <td> element.

        • month: number

          Zero-based month index (0 = January).

        • year: number

          Full four-digit year.

        • OptionalselectedDate: Dayjs

          The currently selected date, if any.

        Returns ReactNode

    renderView?: (view: ViewMode, renderDefault: () => ReactNode) => ReactNode

    Custom render function that wraps (or replaces) the default calendar view.

    Type Declaration

      • (view: ViewMode, renderDefault: () => ReactNode): ReactNode
      • Parameters

        • view: ViewMode

          The current view mode.

        • renderDefault: () => ReactNode

          Call this to render the built-in view.

        Returns ReactNode

        Any React node.

    <Datetime
    renderView={(mode, renderDefault) => (
    <div>
    {renderDefault()}
    <p>Select a date above</p>
    </div>
    )}
    />
    renderYear?: (props: any, year: number, selectedDate?: Dayjs) => ReactNode

    Custom render function for each year cell in the year-selection view.

    Type Declaration

      • (props: any, year: number, selectedDate?: Dayjs): ReactNode
      • Parameters

        • props: any

          Props to spread on the <td> element.

        • year: number

          Full four-digit year.

        • OptionalselectedDate: Dayjs

          The currently selected date, if any.

        Returns ReactNode

    strictParsing?: boolean

    When true, only dates that strictly match dateFormat are accepted as valid when typing in the input field.

    true
    
    timeConstraints?: any

    Fine-grained constraints for the time spinner. Each key corresponds to a time unit; each value may contain min, max, and step.

    <Datetime timeConstraints={{ minutes: { min: 0, max: 45, step: 15 } }} />
    
    timeFormat?: string | boolean

    Day.js format string for the time portion (e.g. 'HH:mm:ss'). Pass false to hide the time part entirely (date-only picker). Pass true to use the locale default.

    true (locale default)
    
    <Datetime timeFormat={false} />
    
    updateOnView?: ViewMode

    Which calendar view triggers an onChange call. By default, determined from dateFormat (e.g. 'days' for a full date format). Set to 'months' to only fire onChange when a month is picked.

    utc?: boolean

    When true, all dates/times are interpreted and displayed in UTC.

    false
    
    value?: string | Dayjs | Date

    The currently selected date/time value (controlled mode). Accepts a dayjs object, a native Date, or a date string. When provided the picker becomes a controlled component.