2.1.4 • Published 10 months ago

react-alternating-timeline v2.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

react-alternating-timeline

A simple and compact, true masonry style alternating timeline react component which is fully customizable and free stylable.

Demonstration

Features

  • 🎛️ Customize everything.
  • 🎨 Consistent (BEM) class naming for easy styling with CSS, emotion...
  • ⏰ Custom date formatting.
  • ⚖️ Alternating, left or right positioning.
  • 🖼️ Render images and custom content.
  • 🪄 Built with Typescript.

Installation

Add the package with the package manager via NPMs or GitHubs registry of choice to your project:

  • yarn: yarn add react-alternating-timeline
  • npm: npm install react-alternating-timeline
  • pnpm: pnpm add react-alternating-timeline
  • npx: npx -p react-alternating-timeline

Usage

import { Timeline, TimelineItemsProps } from 'react-alternating-timeline';

const items: TimelineItemsProps = [
  {
    key: 'first',
    date: new Date(),
    title: 'Special event!',
  },
  {
    key: 'second',
    date: new Date(),
    title: 'Event',
    children: <img src="./test.jpg" alt="test" />,
  },
  ...
];

<Timeline items={items} />;

API

The available properties of the Timeline component:

PropertyTypeDescriptionDefault
itemsTimelineItemsPropsArray of timeline items
positioning?'alternating' \| 'left' \| 'right'How the items should be positioned relative to the timeline'alternating'
minMarkerGap?numberThe minimum gap markers will have between each other50 (px)
formatDate?(date: Date) => stringCallback to format date
customMarker?ReactElementCustom maker element replacing the default
customPointer?ReactElementCustom pointer element replacing the default
styleConfig?StyleConfigStyle config object for customizing timeline by setting css custom properties
className?stringAdditional class name

TimelineItemsProps

An array of the following properties:

PropertyTypeDescription
keyKeyUnique key for each item
title?stringOptional title paragraph displayed bold
dateDate \| stringDate either being formatted according to provided format or passed as a string
children?ReactNodePass custom content as children to the component
formatDate?(date: Date) => stringCallback to format date of specific item
customMarker?ReactElementOverwriting customMarker property of parent Timeline
customPointer?ReactElementOverwriting customPointer property of parent Timeline

Styling

The style can either be passed as an object through the styleConfig property...

{
  line?: {
    width?: CSSProperties['width'];
    color?: CSSProperties['backgroundColor'];
    overhang?: CSSProperties['paddingBlock'];
  };
  item?: {
    gap?: CSSProperties['gap'];
    startOffset?: {
      left?: CSSProperties['marginTop'];
      right?: CSSProperties['marginTop'];
    };
  };
  marker?: {
    size?: CSSProperties['width'];
    color?: CSSProperties['backgroundColor'];
    radius?: CSSProperties['borderRadius'];
  };
  pointer?: {
    height?: CSSProperties['height'];
    width?: CSSProperties['width'];
    minOffset?: CSSProperties['marginTop'];
  };
  card?: {
    background?: CSSProperties['backgroundColor'];
    radius?: CSSProperties['borderRadius'];
    shadow?: CSSProperties['boxShadow'];
    padding?: CSSProperties['padding'];
    offset?: CSSProperties['gap'];
  };
}

...or can be set as custom properties directly in css

.timeline {
  --line-width: 0.2rem;
  --line-color: black;
  --line-overhang: 1rem;
  --item-gap: 1rem;
  --item-start-offset-left: 0;
  --item-start-offset-right: 5rem;
  --marker-size: 1rem;
  --marker-color: var(--line-color);
  --marker-radius: 50%;
  --pointer-height: 2rem;
  --pointer-width: 1rem;
  --pointer-min-offset: 5rem;
  --card-background: whitesmoke;
  --card-radius: 0.1rem;
  --card-shadow: unset;
  --card-padding: 1rem;
  --card-offset: 1rem;
}

StyleConfig

NameDescriptionDefault
LineThe line the timeline items are place around/beside
line-widthWidth of the line0.2rem
line-colorColor of the lineblack
line-overhangHow much the line should overhang the beginning and end of the timeline component1rem
ItemThe timeline item as a whole, including the card, pointer and marker
item-gapThe vertical space between the items1rem
item-start-offset-leftHow much the items on the left side should be offset from the top0
item-start-offset-leftHow much the items on the right side should be offset from the top5rem
MarkerThe markers on the line which marks the chronological order of the timeline items1rem
marker-sizeSize of the default marker1rem
marker-colorColor of the default markerline-color
marker-radiusBorder radius (roundness) of the marker edges50% (round)
PointerThe pointers pointing from the item cards to the markers on the line
pointer-heightHeight of the default pointer2rem
pointer-widthWidth of the default pointer1rem
pointer-min-offsetMinimum offset of the pointer to the top of the card. The actual offset depends on the minMarkerGap property5rem
CardThe cards in which the timeline item content is displayed
card-backgroundBackground color of the cardwhitesmoke
card-radiusBorder radius of the card edges0.1rem
card-shadowConfigure drop shadow of the cardunset
card-paddingPadding of the card content1rem
card-offsetSpace between the card and the timeline line1rem

Demo

View a full demo of component as storybook: Storybook 📚

2.1.4

10 months ago

2.0.1

12 months ago

2.0.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago