import { format } from "date-fns"; import React, { forwardRef } from "react"; import { BodyShort } from "../typography/BodyShort"; import { cl } from "../utils/helpers"; import { useI18n } from "../utils/i18n/i18n.hooks"; import { PeriodContext } from "./hooks/usePeriodContext"; import { useRowContext } from "./hooks/useRowContext"; import { useTimelineContext } from "./hooks/useTimelineContext"; import Period from "./period"; import { PositionedPeriod, TimelineComponentTypes, } from "./utils/types.internal"; type TimelineRowBaseProps = React.HTMLAttributes; export type TimelineRowProps = TimelineRowBaseProps & ( | { /** * Label for the timeline row as either `string` or `React.ReactNode` * * * **Note**: When using `React.ReactNode`, `icon` and `headingTag` props are not available */ label: string; /** * Heading level for the label e.g h2, h3... * @default "h3" */ headingTag?: "h2" | "h3" | "h4" | "h5" | "h6"; /** * Icon next to label */ icon?: React.ReactNode; } | { label: Exclude; headingTag?: never; icon?: never; } ); export interface TimelineRowType extends React.ForwardRefExoticComponent< TimelineRowProps & React.RefAttributes > { componentType: TimelineComponentTypes; } export const TimelineRow = forwardRef( ({ label, className, headingTag = "h3", icon, ...rest }, ref) => { const { periods, active } = useRowContext(); const { setActiveRow } = useTimelineContext(); const translate = useI18n("Timeline"); const latest = periods.reduce((a, b) => { return a.end > b.end ? a : b; }, {} as PositionedPeriod); const earliest = periods.reduce((a, b) => { return a.end < b.end ? a : b; }, {} as PositionedPeriod); const firstFocusable = periods.find( (p) => !!p.children || !!p.onSelectPeriod, ); return ( <> {label && (typeof label === "string" ? ( {icon} {label} ) : (
{label}
))}
{/* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */}
    { if (e.key === "ArrowDown" || e.key === "ArrowUp") { e.preventDefault(); setActiveRow(e.key); } }} > {periods?.map((period) => { return (
  1. ); })}
); }, ) as TimelineRowType; TimelineRow.componentType = "row"; export default TimelineRow;