Skip to content

Commit e5f721c

Browse files
committed
refactor: improve handling of component props
1 parent 9947c61 commit e5f721c

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/components/Timeline.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import './Timeline.css';
22
import { Key, ReactElement, useEffect, useRef } from 'react';
3-
import { PropsWithKey, TimelineItem, TimelineItemProps, TimelineItemRefs } from './TimelineItem';
3+
import { TimelineItem, TimelineItemRefs, TimelineItemsProps } from './TimelineItem';
44
import { OffsetConfig, resolveOffsets } from '../models/offset';
55
import { Positioning } from '../models/positioning';
66
import { convertToCssVariable, StyleConfig } from '../models/style';
77

88
export type TimelineProps = {
9-
items: PropsWithKey<TimelineItemProps>[];
9+
items: TimelineItemsProps;
1010
positioning: Positioning;
1111
gap?: number;
1212
offset?: OffsetConfig;

src/components/TimelineItem.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { forwardRef, Key, PropsWithChildren, ReactElement, useRef, useImperativeHandle } from 'react';
22
import { format } from 'date-fns';
33

4-
export type PropsWithKey<T> = T & {
4+
type PropsWithKey<T> = T & {
55
key: Key;
66
};
77

88
export type TimelineItemRefs = { pointer: HTMLDivElement | null; item: HTMLDivElement | null; marker: HTMLDivElement | null };
99

10+
export type TimelineItemsProps = PropsWithKey<TimelineItemProps>[];
11+
1012
export type TimelineItemProps = PropsWithChildren<{
1113
className?: string;
14+
title?: string;
1215
date: Date | string;
1316
dateFormat?: string;
1417
dateLocale?: Locale;
15-
title: string;
1618
customMarker?: ReactElement;
1719
customPointer?: ReactElement;
1820
}>;
@@ -39,7 +41,7 @@ export const TimelineItem = forwardRef<TimelineItemRefs, TimelineItemProps>(
3941
{customPointer}
4042
</div>
4143
<p className="timeline-card__date">{date instanceof Date ? format(date, dateFormat ?? 'P', { locale: dateLocale }) : date}</p>
42-
<p className="timeline-card__title">{title}</p>
44+
{title && <p className="timeline-card__title">{title}</p>}
4345
{children}
4446
</div>
4547
</div>

src/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
export { Timeline } from './components/Timeline';
1+
export { Timeline, TimelineProps } from './components/Timeline';
2+
export { TimelineItemsProps } from './components/TimelineItem';

0 commit comments

Comments
 (0)