Introduction
Vertical Timeline is a graphical representation of a period of time, on which important events are marked. In this article we will learn how to implement vertical timeline in our SPFX webpart component.
Steps
Open a command prompt and create a directory for the SPFx solution.
md spfx-ReactTimeline
Navigate to the above-created directory.
cd spfx-ReactTimeline
Run the Yeoman SharePoint Generator to create the solution.
yo @microsoft/sharepoint
Solution Name
Hit Enter for the default name (spfx-ReactTimeline in this case) or type in any other name for your solution.
Selected choice - Hit Enter
Target for the component
Here,
we can select the target environment where we are planning to deploy
the client web part; i.e., SharePoint Online or SharePoint OnPremise
(SharePoint 2016 onwards).
Selected choice - SharePoint Online only (latest).
Place of files
We may choose to use the same folder or create a subfolder for our solution.
Selected choice - same folder.
Deployment option
Selecting Y will allow the app to be deployed instantly to all sites and be accessible everywhere.
Selected choice - N (install on each site explicitly).
Permissions to access web APIs
Choose
if the components in the solution require permission to access web APIs
that are unique and not shared with other components in the tenant.
Selected choice - N (solution contains unique permissions)
Type of client-side component to create
We can choose to create a client-side web part or an extension. Choose the web part option.
Selected choice - WebPart
Web part name
Hit Enter to select the default name or type in any other name.
Selected choice - ReactTimeline
Web part description
Hit Enter to select the default description or type in any other value.
Framework to use
Select any JavaScript framework to develop the component. Available choices are - No JavaScript Framework, React, and Knockout.
Selected choice - React
The
Yeoman generator will perform a scaffolding process to generate the
solution. The scaffolding process will take a significant amount of
time.
Once the scaffolding process is completed, lock down the version of project dependencies by running the below command:
npm shrinkwrap
In the command prompt, type the below command to open the solution in the code editor of your choice.
- npm i react-vertical-timeline-component
- npm i csstype
- npm install @material-ui/icons
VerticalTimeline Props
animate={ Boolean } |
Enable or disable animations on elements (default: true). |
className={ String } |
Add extra class name to root div element.
|
layout={ String } |
Choose if you want '1-column' or '2-columns' (default: '2-columns').
|
VerticalTimelineElement Props
className={ String } |
Add extra class name to root div element.
|
contentArrowStyle={ Object }
|
Add extra style to content arrow div element. |
contentStyle={ Object }
|
Add extra style to content div element.
|
date={ String }
|
Date of the element.
|
dateClassName={ String }
|
Add extra class name to the element’s date.
|
icon={ String }
|
Icon of the element.
|
iconClassName={ String }
|
Add extra class name to the element’s icon.
|
iconOnClick={ Function }
|
onClick handler of the element’s icon.
|
onTimelineElementClick={ Function }
|
onClick handler of the vertical timeline element’s div.
|
iconStyle={ Object } |
Style of the element’s icon.
|
position={ String }
|
Position of the element (left or right).
|
style={ Object }
|
Add extra style to root div element.
|
textClassName={ String }
|
Add extra class name to the text container. |
in ReactTimeline.tsx,
- import * as React from 'react';
- import { IReactTimelineProps } from './IReactTimelineProps';
- import { VerticalTimeline, VerticalTimelineElement } from 'react-vertical-timeline-component';
- import 'react-vertical-timeline-component/style.min.css';
- import SchoolIcon from '@material-ui/icons/School';
- import WorkIcon from '@material-ui/icons/Work';
- import StarIcon from '@material-ui/icons/Star';
- import LoyaltyIcon from '@material-ui/icons/Loyalty';
-
- import './mystyle.css';
- import * as CSS from 'csstype';
- var divStyle: CSS.Properties<string | number> = {
- background: 'rgb(227, 227, 227)'
- };
- export default class ReactTimeline extends React.Component<IReactTimelineProps, {}> {
- public render(): React.ReactElement<IReactTimelineProps> {
- return (
- <div style={divStyle}>
- <VerticalTimeline>
- <VerticalTimelineElement
- className="vertical-timeline-element--work"
- contentStyle={{ background: 'rgb(33, 150, 243)', color: '#fff' }}
- contentArrowStyle={{ borderRight: '7px solid rgb(33, 150, 243)' }}
- date="2019 - 2020"
- iconStyle={{ background: 'rgb(33, 150, 243)', color: '#fff' }}
- icon={<LoyaltyIcon />}
- >
- <h3 className="vertical-timeline-element-title">Most Valuable Proffesional</h3>
- <h4 className="vertical-timeline-element-subtitle">MVP</h4>
- <p>
- 1St time awarded as a C#Corner MVP
- </p>
- </VerticalTimelineElement>
-
- <VerticalTimelineElement
- className="vertical-timeline-element--work"
- date="2019 - Till Date"
- iconStyle={{ background: 'rgb(33, 150, 243)', color: '#fff' }}
- icon={<WorkIcon />}
- >
- <h3 className="vertical-timeline-element-title">Software Engineer,Smartek21</h3>
- <h4 className="vertical-timeline-element-subtitle">SharePoint Developer</h4>
- <p>
- SharePoint Online ,Onpremise,M365 Development
- </p>
- </VerticalTimelineElement>
- <VerticalTimelineElement
- className="vertical-timeline-element--work"
- date="2016 - 2019"
- iconStyle={{ background: 'rgb(33, 150, 243)', color: '#fff' }}
- icon={<WorkIcon />}
- >
- <h3 className="vertical-timeline-element-title">Junior Software Engineer,Zylog Systems</h3>
- <h4 className="vertical-timeline-element-subtitle">SharePoint Developer</h4>
- <p>
- SharePoint Online ,Onpremise,M365 Development
- </p>
- </VerticalTimelineElement>
- <VerticalTimelineElement
- className="vertical-timeline-element--education"
- date="2012 - 2014"
- iconStyle={{ background: 'rgb(233, 30, 99)', color: '#fff' }}
- icon={<SchoolIcon />}
- >
- <h3 className="vertical-timeline-element-title">Master of Engineering</h3>
- <h4 className="vertical-timeline-element-subtitle">M.E.</h4>
- <p>
- Computer and Communication
- </p>
- </VerticalTimelineElement>
- <VerticalTimelineElement
- className="vertical-timeline-element--education"
- date="2009 - 2012"
- iconStyle={{ background: 'rgb(233, 30, 99)', color: '#fff' }}
- icon={<SchoolIcon />}
- >
- <h3 className="vertical-timeline-element-title">Bachelor of Engineering</h3>
- <h4 className="vertical-timeline-element-subtitle">B.E.</h4>
- <p>
- Computer Science and Engineering
- </p>
- </VerticalTimelineElement>
- <VerticalTimelineElement
- className="vertical-timeline-element--education"
- date="2007 - 2009"
- iconStyle={{ background: 'rgb(233, 30, 99)', color: '#fff' }}
- icon={<SchoolIcon />}
- >
- <h3 className="vertical-timeline-element-title">Diploma in Computer Engineering</h3>
- <h4 className="vertical-timeline-element-subtitle">Diploma Degree</h4>
- <p>
- Computer Technology
- </p>
- </VerticalTimelineElement>
- <VerticalTimelineElement
- iconStyle={{ background: 'rgb(16, 204, 82)', color: '#fff' }}
- icon={<StarIcon />}
- />
- </VerticalTimeline>
- </div>
- );
- }
- }
in mystyle.css,
- .vertical-timeline::before {
- content: "";
- position: absolute;
- top: 0px;
- left: 18px;
- height: 100%;
- width: 4px;
- background:black!important;
- }
Expected Output
In this article, we
learned how to implement Vertical timeline in our spfx component.
I hope this helps someone. Happy coding :)