Convert Figma logo to code with AI

prabhuignoto logoreact-chrono

Modern Timeline Component for React

4,080
223
4,080
56

Top Related Projects

13,522

nivo provides a rich set of dataviz components, built on top of the awesome d3 and React libraries

25,070

Redefined chart library built with React and D3

11,136

A collection of composable React components for building interactive data visualizations

19,977

🐯 visx | visualization components

📊 Interactive JavaScript Charts built on SVG

Quick Overview

React-Chrono is a flexible and customizable timeline component for React applications. It allows developers to create interactive timelines with various layouts, themes, and customization options, making it suitable for displaying historical events, project milestones, or any chronological data.

Pros

  • Highly customizable with multiple layout options (vertical, horizontal, tree)
  • Supports various media types (images, videos, cards) within timeline items
  • Responsive design and mobile-friendly
  • Well-documented with TypeScript support

Cons

  • Limited animation options for timeline transitions
  • May require additional styling for complex use cases
  • Large bundle size compared to simpler timeline libraries
  • Limited built-in accessibility features

Code Examples

  1. Basic timeline setup:
import { Chrono } from "react-chrono";

const items = [
  { title: "May 1940", cardTitle: "Dunkirk", cardSubtitle: "Men of the British Expeditionary Force (BEF) wade out to a destroyer during the evacuation from Dunkirk." },
  { title: "25 July 1940", cardTitle: "The Battle of Britain", cardSubtitle: "RAF Spitfire pilots scramble for their planes" },
  { title: "June 1941", cardTitle: "Operation Barbarossa", cardSubtitle: "A column of Red Army prisoners of war taken during the first days of the German invasion" },
];

const Timeline = () => (
  <Chrono items={items} mode="VERTICAL" />
);
  1. Customizing timeline appearance:
<Chrono
  items={items}
  mode="HORIZONTAL"
  theme={{
    primary: "#0077B6",
    secondary: "#48CAE4",
    cardBgColor: "#CAF0F8",
    titleColor: "#03045E",
  }}
  cardHeight={200}
  slideItemDuration={1000}
/>
  1. Adding media to timeline items:
const itemsWithMedia = [
  {
    title: "1969",
    cardTitle: "Moon Landing",
    cardSubtitle: "Neil Armstrong becomes the first human to step on the Moon",
    media: {
      type: "IMAGE",
      source: {
        url: "https://example.com/moon-landing.jpg"
      }
    }
  },
  // ... more items
];

<Chrono items={itemsWithMedia} mode="VERTICAL_ALTERNATING" />

Getting Started

  1. Install the package:

    npm install react-chrono
    
  2. Import and use in your React component:

    import React from 'react';
    import { Chrono } from 'react-chrono';
    
    const MyTimeline = () => {
      const items = [
        { title: "2020", cardTitle: "Event 1", cardSubtitle: "Event 1 Description" },
        { title: "2021", cardTitle: "Event 2", cardSubtitle: "Event 2 Description" },
        { title: "2022", cardTitle: "Event 3", cardSubtitle: "Event 3 Description" },
      ];
    
      return (
        <div style={{ width: '500px', height: '400px' }}>
          <Chrono items={items} mode="VERTICAL" />
        </div>
      );
    };
    
    export default MyTimeline;
    

Competitor Comparisons

13,522

nivo provides a rich set of dataviz components, built on top of the awesome d3 and React libraries

Pros of nivo

  • Offers a wide variety of chart types and data visualization options
  • Highly customizable with extensive documentation and examples
  • Built with React and D3, providing powerful and interactive visualizations

Cons of nivo

  • Steeper learning curve due to its extensive feature set
  • May be overkill for simple timeline or chronological data representation
  • Larger bundle size compared to more focused libraries

Code Comparison

nivo example (Bar Chart):

import { ResponsiveBar } from '@nivo/bar'

const MyChart = () => (
  <ResponsiveBar
    data={data}
    keys={['hot dog', 'burger', 'sandwich', 'kebab', 'fries', 'donut']}
    indexBy="country"
    margin={{ top: 50, right: 130, bottom: 50, left: 60 }}
    padding={0.3}
    colors={{ scheme: 'nivo' }}
  />
)

react-chrono example (Timeline):

import { Chrono } from "react-chrono";

const MyTimeline = () => (
  <Chrono
    items={items}
    mode="VERTICAL"
    slideShow
    slideItemDuration={2000}
    slideShowInterval={5000}
  />
)

While nivo provides a comprehensive solution for various data visualizations, react-chrono focuses specifically on timeline representations. nivo offers more flexibility but requires more setup, whereas react-chrono provides a simpler API for creating timelines quickly.

25,070

Redefined chart library built with React and D3

Pros of recharts

  • More comprehensive charting library with various chart types (line, bar, area, etc.)
  • Higher GitHub stars and wider community adoption
  • Extensive documentation and examples

Cons of recharts

  • Steeper learning curve due to more complex API
  • Larger bundle size, which may impact performance for simpler use cases

Code Comparison

react-chrono (Timeline component):

<Chrono items={items} mode="VERTICAL" />

recharts (LineChart component):

<LineChart width={400} height={400} data={data}>
  <Line type="monotone" dataKey="uv" stroke="#8884d8" />
  <CartesianGrid stroke="#ccc" />
  <XAxis dataKey="name" />
  <YAxis />
</LineChart>

Summary

recharts is a more feature-rich charting library suitable for various data visualization needs, while react-chrono focuses specifically on timeline components. recharts offers greater flexibility but may be overkill for simple timeline requirements. react-chrono provides a more straightforward API for timeline creation but lacks the versatility of recharts for other chart types.

11,136

A collection of composable React components for building interactive data visualizations

Pros of Victory

  • Comprehensive charting library with a wide range of chart types
  • Highly customizable with extensive API and theming options
  • Strong community support and regular updates

Cons of Victory

  • Steeper learning curve due to its extensive features
  • Larger bundle size compared to more focused libraries
  • May be overkill for simple timeline or chronological visualizations

Code Comparison

Victory (creating a simple line chart):

import { VictoryChart, VictoryLine, VictoryAxis } from 'victory';

<VictoryChart>
  <VictoryLine data={[{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 5}]} />
  <VictoryAxis />
</VictoryChart>

react-chrono (creating a simple timeline):

import { Chrono } from "react-chrono";

<Chrono items={[
  { title: "May 1940", cardTitle: "Dunkirk", cardSubtitle: "Men of the British Expeditionary Force (BEF) wade out to..." },
  { title: "May 1940", cardTitle: "Dunkirk", cardSubtitle: "Men of the British Expeditionary Force (BEF) wade out to..." },
]} />

While Victory offers a comprehensive solution for various chart types, react-chrono provides a more focused and easier-to-use option for timeline visualizations. Victory's flexibility comes at the cost of complexity, whereas react-chrono offers a simpler API for its specific use case.

19,977

🐯 visx | visualization components

Pros of visx

  • More comprehensive data visualization library with a wide range of chart types and components
  • Highly customizable and flexible, allowing for complex and interactive visualizations
  • Backed by Airbnb, with a larger community and more frequent updates

Cons of visx

  • Steeper learning curve due to its extensive API and lower-level components
  • Requires more setup and configuration for basic use cases
  • May be overkill for simple timeline or chronological visualizations

Code Comparison

react-chrono:

<Chrono items={items} mode="VERTICAL" />

visx:

<XYChart height={300} xScale={{ type: 'band' }} yScale={{ type: 'linear' }}>
  <BarSeries dataKey="bar" data={data} />
  <Axis orientation="bottom" />
  <Axis orientation="left" />
</XYChart>

Summary

react-chrono is a specialized library for creating timeline components, offering a simpler API and easier implementation for chronological data visualization. visx, on the other hand, is a more powerful and versatile data visualization library that can be used for various chart types, including timelines. While react-chrono is more suitable for quick timeline implementations, visx provides greater flexibility and customization options for complex data visualizations across different chart types.

📊 Interactive JavaScript Charts built on SVG

Pros of ApexCharts.js

  • Offers a wide variety of chart types and customization options
  • Supports responsive and interactive charts out of the box
  • Has extensive documentation and a large community

Cons of ApexCharts.js

  • Larger file size compared to React Chrono
  • May have a steeper learning curve for complex visualizations
  • Not specifically designed for timeline or chronological data

Code Comparison

React Chrono:

<Chrono items={items} mode="VERTICAL" />

ApexCharts.js:

var options = {
  chart: { type: 'line' },
  series: [{ data: [30, 40, 35, 50, 49, 60, 70] }],
  xaxis: { categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997] }
};
var chart = new ApexCharts(document.querySelector("#chart"), options);
chart.render();

While React Chrono is specifically designed for creating timelines with a simple API, ApexCharts.js offers more versatility for various chart types but requires more configuration. React Chrono is more focused and easier to use for timeline-specific visualizations, while ApexCharts.js provides broader charting capabilities at the cost of increased complexity.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

React Chrono UI Logo

React Chrono

A flexible and modern timeline component for React.

npm version npm downloads npm bundle size License styled with Prettier

Build Status DeepScan grade Codacy Badge react-chrono Known Vulnerabilities Depfu Coverage Status Storybook

React Chrono is a modern timeline component for React that offers a variety of features and customization options. It allows you to render timelines in horizontal, vertical, vertical-alternating, and horizontal-all modes, display images and videos, and much more.

Table of Contents

✨ Features

  • 🚥 Multiple Modes: Render timelines in Horizontal, Vertical, or Vertical-Alternating layouts.
  • 📺 Slideshow: Auto-play the timeline with slideshow functionality.
  • 🖼️ Media Support: Easily display images and videos within timeline cards.
  • ⌨️ Keyboard Accessible: Navigate the timeline using keyboard controls.
  • 🔧 Custom Content: Render custom React components within timeline cards.
  • 🌿 Nested Timelines: Display timelines within timeline cards for complex narratives.
  • ⚡ Data-Driven API: Configure the timeline dynamically using a simple data structure.
  • 🎨 Enhanced Theming: Comprehensive theme customization with 15+ new dark mode properties for complete visual control.
  • 🌙 Advanced Dark Mode: Fully configurable dark mode with brand color integration and accessibility compliance.
  • 🎭 Custom Icons: Use your own icons for timeline points.
  • 💪 TypeScript: Built with TypeScript for robust development.
  • 💅 Styled with Styled Component: Leverages Styled Component for flexible styling.

💾 Installation

# Using yarn
yarn add react-chrono

# Using npm
npm install react-chrono

🚀 Getting Started

Ensure you wrap the Chrono component in a container with a specified width and height.

Basic Horizontal Mode

By default, if no mode is specified, the component renders in HORIZONTAL mode.

import React from 'react';
import { Chrono } from 'react-chrono';

const App = () => {
  const items = [
    {
      title: 'May 1940',
      cardTitle: 'Dunkirk',
      url: 'http://www.history.com',
      cardSubtitle:
        'Men of the British Expeditionary Force (BEF) wade out to a destroyer...',
      cardDetailedText:
        'Men of the British Expeditionary Force (BEF) wade out to a destroyer during the evacuation from Dunkirk.',
      media: {
        type: 'IMAGE',
        source: {
          url: 'http://someurl/image.jpg',
        },
      },
    },
    // ... more items
  ];

  return (
    <div style={{ width: '800px', height: '400px' }}>
      <Chrono items={items} />
    </div>
  );
};

export default App;

Horizontal Timeline Example

Vertical Mode

To render the timeline vertically, set the mode prop to VERTICAL.

<div style={{ width: '300px', height: '950px' }}>
  <Chrono items={items} mode="VERTICAL" />
</div>

Vertical Timeline Example

Vertical Alternating Mode

For a layout where cards alternate sides, use VERTICAL_ALTERNATING.

<div style={{ width: '500px', height: '950px' }}>
  <Chrono items={items} mode="VERTICAL_ALTERNATING" />
</div>

Vertical Alternating Timeline Example

⚙️ Props

React Chrono offers a wide range of props for customization.

Core Props

NameTypeDefaultDescription
itemsTimelineItemModel[][]An array of Timeline Item objects to display.
mode'HORIZONTAL', 'VERTICAL', 'VERTICAL_ALTERNATING', 'HORIZONTAL_ALL''HORIZONTAL'Sets the layout mode of the timeline. HORIZONTAL_ALL shows all cards simultaneously in horizontal mode.
themeTheme{...}Enhanced theming with 15+ new dark mode properties for complete visual customization. See Theming & Styling for details.

Timeline Item Model

Each object in the items array can have the following properties:

PropertyTypeDescription
titlestring or ReactNodeTitle of the timeline item (often a date or short label).
cardTitlestring or ReactNodeTitle displayed on the timeline card.
cardSubtitlestring or ReactNodeSubtitle text displayed on the timeline card.
cardDetailedTextstring, string[], ReactNode, or ReactNode[]Detailed text for the card. An array of strings will render each string as a separate paragraph.
mediaMediaObject to configure image or video display. See Media Handling.
urlstringURL associated with the timeline item's title. Clicking the title will navigate to this URL.
dateDate, string, or numberDate to be used in the title. If provided, this will override the title property for display purposes.
timelineContentReactNodeCustom React content to render inside the card. Overrides cardDetailedText. See Rendering Custom Content.
itemsTimelineItemModel[]Array of timeline items for creating Nested Timelines.
hasNestedItemsbooleanNew: Automatically set to indicate if this item contains nested sub-items. Used internally for optimized rendering.
activebooleanIf true, this item will be initially active (only for the first matching item).
idstringA unique identifier for the timeline item.
visiblebooleanControls the visibility of the timeline item.

Example TimelineItemModel:

{
  title: "May 1940",
  cardTitle: "Dunkirk",
  cardSubtitle: "Evacuation of Allied soldiers from the beaches and harbour of Dunkirk, France.",
  cardDetailedText: ["Paragraph one about Dunkirk.", "Paragraph two providing more details."],
  media: {
    type: "IMAGE", // "VIDEO"
    source: {
      url: "http://someurl/dunkirk.jpg"
    },
    name: "Dunkirk Evacuation"
  },
  url: "https://en.wikipedia.org/wiki/Dunkirk_evacuation",
  // For nested timeline:
  // items: [{ cardTitle: 'Sub-event 1' }, { cardTitle: 'Sub-event 2' }]
}

Navigation & Interaction

NameTypeDefaultDescription
activeItemIndexnumber0Index of the timeline item to be active on load.
disableNavOnKeybooleanfalseDisables keyboard navigation (LEFT/RIGHT for Horizontal, UP/DOWN for Vertical).
disableClickOnCirclebooleanfalseDisables click action on timeline points/circles.
disableAutoScrollOnClickbooleanfalsePrevents auto-scrolling to the active card when a timeline card or point is clicked.
onItemSelectedfunctionCallback function invoked when a timeline item is selected. Passes item data and index.
onScrollEndfunctionCallback function invoked when the end of the timeline is reached during scrolling.
focusActiveItemOnLoadbooleanfalseAutomatically scrolls to and focuses on the activeItemIndex when the timeline loads.
disableInteractionbooleanfalseDisables all user interactions with the timeline (clicks, keyboard navigation).
enableQuickJumpbooleantrueAllows quick jumping to a timeline item via controls (if toolbar is enabled).
enableLayoutSwitchbooleantrueEnables layout switching controls in the toolbar, allowing users to switch between different timeline modes.
useReadMorebooleantrueEnables a "read more" button if card content exceeds available space. Set to false to always show all text.

Semantic Tags Configuration:

NameTypeDefaultDescription
semanticTagsSemanticTagsConfigConfigure semantic HTML tags for card elements to improve accessibility and SEO.

The semanticTags object allows you to specify HTML tags for card elements:

interface SemanticTagsConfig {
  cardTitle?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'span' | 'div';
  cardSubtitle?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'span' | 'div';
}

Example:

<Chrono
  items={items}
  semanticTags={{
    cardTitle: 'h2',
    cardSubtitle: 'h3',
  }}
/>

Keyboard Navigation:

  • Horizontal Mode: Use LEFT and RIGHT arrow keys.
  • Vertical/Vertical Alternating Mode: Use UP and DOWN arrow keys.
  • HOME: Jump to the first item.
  • END: Jump to the last item.

Layout & Sizing

NameTypeDefaultDescription
cardHeightnumber200Minimum height (in pixels) of timeline cards.
cardWidthnumber450Maximum width (in pixels) of timeline cards.
itemWidthnumber200Width (in pixels) of each timeline section in HORIZONTAL mode.
contentDetailsHeightnumber150Height (in pixels) of the detailed content area within a card if cardDetailedText is used.
lineWidthnumber3Width (in pixels) of the main timeline track line.
timelinePointDimensionnumber16Diameter (in pixels) of the circular points on the timeline.
nestedCardHeightnumber150Height (in pixels) of cards within a nested timeline.
mediaHeightnumber200Minimum height (in pixels) of media elements (images and videos) in timeline cards.
scrollableboolean or { scrollbar: boolean }{ scrollbar: false }Makes VERTICAL and VERTICAL_ALTERNATING modes scrollable. Set to { scrollbar: true } to show the scrollbar.
enableBreakPointbooleantrueIf true, VERTICAL_ALTERNATING mode automatically switches to VERTICAL mode when responsiveBreakPoint is reached.
responsiveBreakPointnumber768Viewport width (in pixels) at which VERTICAL_ALTERNATING mode switches to VERTICAL if enableBreakPoint is true.
cardPositionHorizontal'TOP' or 'BOTTOM'Positions the card above or below the timeline in HORIZONTAL mode.
flipLayoutbooleanfalseReverses the layout direction (e.g., Right-to-Left for horizontal, or swaps sides for vertical alternating).
showAllCardsHorizontalbooleanfalseIn HORIZONTAL mode, displays all cards simultaneously instead of only the active one.

Media Handling

The media object within a Timeline Item configures images or videos.

media PropertyTypeDescription
type'IMAGE' or 'VIDEO'Specifies the type of media.
source{ url: string, type?: string }url: URL of the image or video. type (for video): e.g., 'mp4', 'webm'.
namestringAlt text for images or a descriptive name for videos.
activeboolean(Video only) If true, video will attempt to play when its card becomes active.
idstringA unique ID for the media element.

Image Example:

media: {
  type: "IMAGE",
  name: "dunkirk beach",
  source: {
    url: "http://someurl/image.jpg"
  }
}

Video Example (auto-plays when active, muted):

media: {
  type: "VIDEO",
  name: "Pearl Harbor",
  source: {
    url: "/pearl-harbor.mp4", // or "https://www.youtube.com/embed/f6cz9gtMTeI"
    type: "mp4" // Optional for local files if extension is clear, useful for YouTube embeds
  }
}

Timeline with Media

Media Settings Prop (mediaSettings): This top-level prop on <Chrono> controls global media display:

NameTypeDefaultDescription
align'left', 'right', 'center''left'Alignment of media within the card.
fit'cover', 'contain', 'fill', 'none', 'scale-down''cover'CSS object-fit property for images.
<Chrono items={items} mediaSettings={{ align: 'right', fit: 'contain' }} />

Content & Display

NameTypeDefaultDescription
borderLessCardsbooleanfalseRemoves borders and shadows from timeline cards for a flatter look.
cardLessbooleanfalseHides timeline cards, showing only titles/points. Useful for a very compact timeline.
disableTimelinePointbooleanfalseHides the circular points on the timeline track.
timelinePointShape'circle', 'square', 'diamond''circle'Configures the shape of the points on the timeline.
textOverlaybooleanfalseDisplays text content as an overlay on top of media elements. Requires text property in timeline items.
parseDetailsAsHTMLbooleanfalseIf true, cardDetailedText will be parsed as HTML. Use with caution due to XSS risks if content is user-supplied.
titleDateFormatstring'MMM DD, YYYY'Date format for item titles when using the date property in items. Supports all day.js formats.
textDensity'LOW' or 'HIGH''HIGH'Configures the amount of text displayed in cards. 'LOW' might truncate more aggressively.

Text Overlay Mode: Enable textOverlay and provide a text property in your items.

const items = [
  {
    title: 'First item',
    media: { type: 'IMAGE', source: { url: 'https://example.com/image.jpg' } },
    text: 'This is the caption for the first item, appearing over the image.',
  },
];
<Chrono items={items} textOverlay />;

Text Overlay Example

Theming & Styling

NameTypeDescription
cardBgColorstringBackground color for timeline cards
cardDetailsBackGroundstringBackground color for card details section
cardDetailsColorstringText color for card details
cardMediaBgColorstringBackground color for media section in cards
cardSubtitleColorstringColor for card subtitles
cardTitleColorstringColor for card titles
detailsColorstringColor for detailed text
iconBackgroundColorstringBackground color for timeline icons
nestedCardBgColorstringBackground color for nested timeline cards
nestedCardDetailsBackGroundstringBackground color for nested card details section
nestedCardDetailsColorstringText color for nested card details
nestedCardSubtitleColorstringColor for nested card subtitles
nestedCardTitleColorstringColor for nested card titles
primarystringPrimary color for the timeline
secondarystringSecondary color for the timeline
textColorstringDefault text color
titleColorstringColor for timeline titles
titleColorActivestringColor for active timeline titles
toolbarBgColorstringBackground color for the toolbar
toolbarBtnBgColorstringBackground color for toolbar buttons
toolbarTextColorstringText color for toolbar elements
timelineBgColorstringBackground color for the timeline

Dark Mode Properties

NameTypeDescription
iconColorstringColor for icons in dark mode
buttonHoverBgColorstringBackground color for buttons on hover
buttonActiveBgColorstringBackground color for active buttons
buttonActiveIconColorstringIcon color for active buttons
buttonBorderColorstringBorder color for buttons
buttonHoverBorderColorstringBorder color for buttons on hover
buttonActiveBorderColorstringBorder color for active buttons
shadowColorstringColor for shadows and depth effects
glowColorstringColor for glow effects and focus states
searchHighlightColorstringColor for search result highlighting
darkToggleActiveBgColorstringBackground color when dark mode toggle is active
darkToggleActiveIconColorstringIcon color when dark mode toggle is active
darkToggleActiveBorderColorstringBorder color when dark mode toggle is active
darkToggleGlowColorstringGlow effect color for dark mode toggle

🎨 Custom Theme Examples

Brand Color Integration:

const customDarkTheme = {
  // Base colors
  cardBgColor: '#2d3748',
  toolbarBgColor: '#1a202c',
  toolbarBtnBgColor: '#4a5568',

  // Enhanced dark mode properties
  iconColor: '#63b3ed', // Bright blue for icons
  buttonHoverBgColor: '#718096', // Gray hover
  buttonActiveBgColor: '#ed8936', // Orange active state
  buttonActiveIconColor: '#1a202c', // Dark icon on orange

  // Borders and effects
  buttonBorderColor: 'rgba(255, 255, 255, 0.2)',
  buttonHoverBorderColor: '#63b3ed',
  shadowColor: 'rgba(0, 0, 0, 0.6)',
  glowColor: 'rgba(237, 137, 54, 0.4)',

  // Search and dark toggle
  searchHighlightColor: 'rgba(99, 179, 237, 0.3)',
  darkToggleActiveBgColor: '#2b6cb0',
  darkToggleActiveIconColor: '#f7fafc',
};

<Chrono items={items} theme={customDarkTheme} enableDarkToggle />;

High Contrast Theme:

const highContrastTheme = {
  cardBgColor: '#000000',
  toolbarBgColor: '#111111',
  iconColor: '#00ff00', // Bright green for accessibility
  buttonActiveBgColor: '#ffff00', // Bright yellow
  buttonBorderColor: 'rgba(255, 255, 255, 0.5)',
  shadowColor: 'rgba(0, 0, 0, 0.8)',
  searchHighlightColor: 'rgba(0, 255, 0, 0.5)',
};

🔧 Complete Theme Reference: For a complete list of all themeable properties, refer to the Theme type definition in the source code or explore the Storybook examples.

♿ Accessibility: All default colors maintain WCAG AA compliance (4.5:1 contrast ratio). When customizing themes, ensure sufficient contrast ratios for accessibility.

Dark Mode Toggle:

NameTypeDefaultDescription
enableDarkTogglebooleanfalseAdds a toggle switch to the toolbar for enabling dark mode (if dark theme is configured).
onThemeChangefunctionCallback invoked when the theme changes, e.g., via the dark mode toggle. Passes the new theme object.

Slideshow

NameTypeDefaultDescription
slideShowbooleanfalseEnables slideshow mode and shows play/pause controls in the toolbar.
slideItemDurationnumber2000Duration (in milliseconds) each timeline item remains active during a slideshow.
slideShowType'reveal', 'slide_from_sides', 'slide_in'Varies by modeType of animation for slideshow transitions. Defaults: VERTICAL -> 'reveal', VERTICAL_ALTERNATING -> 'slide_from_sides', HORIZONTAL -> 'slide_in'.
showProgressOnSlideshowbooleanfalseShows a progress bar on individual timeline cards during slideshow mode to indicate the current slide's progress.
showOverallSlideshowProgressbooleantrue (when slideShow is enabled)Shows a line-based progress bar at the top of the screen during slideshow mode, indicating overall progress across all timeline items.
<Chrono
  items={items}
  slideShow
  slideItemDuration={3000}
  showProgressOnSlideshow={true}
  showOverallSlideshowProgress={true}
/>

Slideshow can be stopped by clicking the stop button or pressing ESC. The overall progress bar shows the global progress across all timeline items and can be disabled by setting showOverallSlideshowProgress={false}.

Search

NameTypeDefaultDescription
searchPlaceholderstring"Search..."Placeholder text for the search input in the toolbar.
searchAriaLabelstring"Search timeline"ARIA label for the search input for accessibility.
clearSearchstring"Clear search"Text/ARIA label for the clear search button.
<Chrono items={data} searchPlaceholder="Find in timeline..." />

Search functionality is part of the toolbar. To hide search (and the toolbar), set disableToolbar={true}.

Miscellaneous

NameTypeDefaultDescription
allowDynamicUpdatebooleanfalseEnables dynamic updates of timeline items. If true, changes to the items prop will re-render the timeline.
noUniqueIdbooleanfalsePrevents generating a unique ID for the timeline wrapper. Use with uniqueId if you need to set a specific ID.
uniqueIdstringSets a custom unique ID for the timeline wrapper. Useful with noUniqueId={true}.
disableToolbarbooleanfalseHides the entire toolbar/control panel.
toolbarPosition'top' or 'bottom''top'Positions the toolbar at the top or bottom of the timeline.
highlightCardsOnHoverbooleanfalseHighlights timeline cards on mouse hover.

🎨 Customization

Rendering Custom Content

Pass React elements as children to <Chrono>. Each child will be rendered into a timeline card. This can be combined with the items prop to provide titles or other metadata.

const customItems = [
  { title: '2023-01-01', cardTitle: 'Event One' },
  { title: '2023-02-15', cardTitle: 'Event Two' },
];

<Chrono mode="VERTICAL" items={customItems}>
  <div>
    <h4>Custom Content for Event One</h4>
    <p>This is fully custom JSX rendered in the first card.</p>
  </div>
  <div>
    <img src="<url_to_image>" alt="Custom Image" style={{ width: '100%' }} />
    <p>An image in the second card.</p>
  </div>
</Chrono>;

Custom Icons

Provide images for timeline points by wrapping them in a div with className="chrono-icons" as a child of <Chrono>. Icons are applied sequentially.

<Chrono items={items} mode="VERTICAL_ALTERNATING">
  {/* Custom content for cards (optional) */}
  <div>Card 1 Content</div>
  <div>Card 2 Content</div>

  {/* Custom icons for timeline points */}
  <div className="chrono-icons">
    <img src="image1.svg" alt="icon1" />
    <img src="image2.svg" alt="icon2" />
    {/* Add more images for more items */}
  </div>
</Chrono>

Nested Timelines

Create timelines within timeline cards by providing an items array within a parent timeline item.

const itemsWithNested = [
  {
    title: 'Main Event 1',
    cardTitle: 'Chapter 1',
    items: [
      // Nested timeline
      { cardTitle: 'Sub-event 1.1', cardSubtitle: 'Details for 1.1' },
      {
        cardTitle: 'Sub-event 1.2',
        media: { type: 'IMAGE', source: { url: '...' } },
      },
    ],
  },
  { title: 'Main Event 2', cardTitle: 'Chapter 2' },
];

<Chrono mode="VERTICAL" items={itemsWithNested} nestedCardHeight={120} />;

Custom Class Names

Apply your own CSS classes to various parts of the timeline using the classNames prop.

<Chrono
  items={items}
  classNames={{
    card: 'my-custom-card',
    cardMedia: 'my-card-media',
    cardSubTitle: 'my-card-subtitle',
    cardText: 'my-card-text',
    cardTitle: 'my-card-title',
    controls: 'my-timeline-controls', // Class for the toolbar
    title: 'my-timeline-title', // Class for the item titles (e.g., dates)
    timelinePoint: 'my-timeline-point',
    timelineTrack: 'my-timeline-track',
  }}
/>

Custom Font Sizes

Adjust font sizes for card elements using the fontSizes prop.

<Chrono
  items={items}
  fontSizes={{
    cardSubtitle: '0.85rem',
    cardText: '1rem',
    cardTitle: '1.25rem',
    title: '1.5rem',
  }}
/>

Custom Button Alt Text

Customize button text and accessibility labels:

<Chrono
  items={items}
  buttonTexts={{
    first: 'Go to Beginning',
    last: 'Go to End',
    next: 'Next Event',
    previous: 'Previous Event',
    play: 'Start Auto-play',
    stop: 'Stop Auto-play',
  }}
/>

📦 Examples & Demos

CodeSandbox Examples

Edit react-chrono

Storybook

Interactive component documentation

🛠️ Build Setup

# Clone the repository
git clone https://github.com/prabhuignoto/react-chrono.git
cd react-chrono

# Install dependencies
pnpm install

# Start development server
pnpm run dev

# Build for production
pnpm run build

# Run tests
pnpm test

🧪 Tests

The project uses Vitest for testing with comprehensive coverage:

# Run all tests
pnpm test

# Run tests in watch mode
pnpm test:watch

# Generate coverage report
pnpm test:coverage

🤝 Contributing

Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.

🧱 Built With

💖 Support & Meta

  • Star this repo on GitHub
  • Follow the author on Twitter
  • Create issues for bug reports and feature requests
  • Contribute to make this library better

✨ Contributors

Thanks goes to these wonderful people (emoji key):

NPM DownloadsLast 30 Days