3.2.13 • Published 4 years ago

react-image-timeline v3.2.13

Weekly downloads
768
License
MIT
Repository
github
Last release
4 years ago

CircleCI

React Image Timeline

An image-centric timeline component for React.js. View chronological events in a pleasant way.

View Sample Timeline

Features:

  • Responsive layout
  • Graceful handling of non-uniform content
  • Customizable (use your own CSS and components)
  • Memoized, pure, & typed (Typescript definitions included)
  • Only 32kb
  • Zero extra dependencies

screenshot

How to Use

npm install react-image-timeline --save

import React from 'react';
import ReactDOM from 'react-dom';
import Timeline from 'react-image-timeline';
require('react-image-timeline/dist/timeline.css'); // .scss also available

const events = [
    {
        date: new Date(2013, 9, 27),
        text: "Sed leo elit, pellentesque sit amet congue quis, ornare nec lorem.",
        title: "Cairo, Egypt",
        buttonText: 'Click Me',
        imageUrl: "http://github.com/aaron9000/react-image-timeline/blob/master/src/assets/cairo.jpg?raw=true",
        onClick: console.log,
    }
];

ReactDOM.render(<Timeline events={events} />, document.getElementById('root'));

Customization

Custom Styles

To customize the timeline, add your own CSS to override the default styles.

Event Metadata

To pass extra data into custom components, use extras on TimelineEvent.

Custom Dot Pattern

The dots are defined in CSS using a base64-encoded image. Encode a new image and override the corresponding CSS class.

Custom Components

For more advanced customization, you can pass in custom components to replace the defaults. Custom components will be passed a TimelineEvent model in props.

const CustomHeader = (props) => {

    const {title, extras} = props.event;
    const {customField} = extras;

    return <div className="custom-header">
        <h1>{title}</h1>
        <p>{customField}</p>
    </div>;
};

ReactDOM.render(<Timeline events={events} customComponents={{header: CustomHeader}}/>, document.getElementById('root'));

Run Example Project (you will need create-react-app to run)

*install create-react-app*
*clone repository*
yarn
yarn --debug
yarn start

Run Tests

*clone repository*
yarn test

TypeScript & Models

Typescript definitions are included in the library.


Importing TypeScript Definitions

import {
    TimelineProps, 
    TimelineEventProps, 
    TimelineEvent, 
    TimelineCustomComponents
} from 'react-image-timeline';

TimelineProps

export interface TimelineProps {
    customComponents?: TimelineCustomComponents | null;
    events: Array<TimelineEvent>;
    reverseOrder?: boolean;
    denseLayout?: boolean;
}
KeyTypeRequired?
eventsArrayYes
customComponentsTimelineCustomComponents
reverseOrderboolean
denseLayoutboolean

TimelineCustomComponents

export interface TimelineCustomComponents {
    topLabel?: React.PureComponent<TimelineEventProps> | React.ReactNode | null;
    bottomLabel?: React.PureComponent<TimelineEventProps> | React.ReactNode | null;
    header?: React.PureComponent<TimelineEventProps> | React.ReactNode | null;
    imageBody?: React.PureComponent<TimelineEventProps> | React.ReactNode | null;
    textBody?: React.PureComponent<TimelineEventProps> | React.ReactNode | null;
    footer?: React.PureComponent<TimelineEventProps> | React.ReactNode | null;
}
KeyTypeRequired?
topLabelcomponent
bottomLabelcomponent
headercomponent
imageBodycomponent
textBodycomponent
footercomponent

TimelineEventProps

export interface TimelineEventProps {
    event: TimelineEvent;
}
KeyTypeRequired?
eventTimelineEventYes

TimelineEvent

export interface TimelineEvent {
    date: Date;
    title: string;
    imageUrl: string;
    text: string;
    onClick?: TimelineEventClickHandler | null;
    buttonText?: string | null;
    extras?: object | null;
}
KeyTypeRequired?
datedateYes
titlestringYes
imageUrlstringYes
textstringYes
onClickfunction
buttonTextstring
extrasobject
3.2.13

4 years ago

3.2.11

4 years ago

3.2.7

4 years ago

3.2.6

4 years ago

3.2.0

4 years ago

3.1.9

4 years ago

3.1.8

4 years ago

3.1.3

4 years ago

3.1.7

4 years ago

3.1.6

4 years ago

3.1.5

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.9

8 years ago

0.1.8

8 years ago

0.1.7

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.0

8 years ago