import { BodyShort } from "@navikt/ds-react"; import { format } from "date-fns"; import React, { forwardRef } from "react"; 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"; import cl from "clsx"; export interface TimelineRowProps extends React.HTMLAttributes { /** * Label for the timeline row */ 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; } export interface TimelineRowType extends React.ForwardRefExoticComponent< TimelineRowProps & React.RefAttributes > { componentType: TimelineComponentTypes; } export const TimelineRow = forwardRef( ({ label, className, headingTag = "h3", icon, ...rest }, ref) => { const { periods, id, active } = useRowContext(); const { setActiveRow } = useTimelineContext(); 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 && ( {icon} {label} )}
    { if (e.key === "ArrowDown" || e.key === "ArrowUp") { e.preventDefault(); setActiveRow(e.key); } }} > {periods && periods.map((period) => { return (
  1. ); })}
); } ) as TimelineRowType; TimelineRow.componentType = "row"; export default TimelineRow;