Skip to content

Commit

Permalink
timeline module wip
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewsmawfield committed Dec 7, 2023
1 parent 6cd9d10 commit 26ac546
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 55 deletions.
3 changes: 2 additions & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"homepage": "https://github.com/the-deep/reporting-module-map-vizzard#readme",
"dependencies": {
"@babel/runtime-corejs3": "^7.22.3",
"@rollup/plugin-image": "^3.0.3"
"@rollup/plugin-image": "^3.0.3",
"@knight-lab/timelinejs": "^3.9.3"
},
"peerDependencies": {
"react": "^18.2.0",
Expand Down
1 change: 0 additions & 1 deletion lib/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import image from '@rollup/plugin-image';
import postcssPresetEnv from 'postcss-preset-env';
import postcssNested from 'postcss-nested';
import postcssNormalize from 'postcss-normalize';

import pkg from './package.json' assert { type: 'json' };

const INPUT_FILE_PATH = 'src/index.ts';
Expand Down
File renamed without changes.
57 changes: 57 additions & 0 deletions lib/src/Timeline/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React, { useEffect } from 'react';
import { Timeline as TL } from '@knight-lab/timelinejs';
import '@knight-lab/timelinejs/dist/css/timeline.css';

This comment has been minimized.

Copy link
@tnagorra

tnagorra Dec 7, 2023

Member

Instead of importing the CSS file here. We should import the CSS in
storybook/src/App.jsx

We can even make @knight-lab/timelinejs a peer dependency.

This comment has been minimized.

Copy link
@matthewsmawfield

matthewsmawfield Dec 7, 2023

Author Collaborator

i found a way to get round this by moving the CSS import to the top of Timeline.css

import './Timeline.css';

export interface Props {
data: {
Date: string;
Category: string;
Details: string;
Source: string;
Link: string;
}[],
}

function Timeline({ data }: Props) {
const timelineoptions = {
// initial_zoom: 2,
scale_factor: 1.4,
timenav_position: 'top',
height: '500',
width: '100%',
lang: 'en',
start_at_end: true,
font: 'Roboto Slab',
};

// eslint-disable-next-line
const evt = data.map((d:any) => (
{
start_date: new Date(d.Date),
display_date: (new Date(d.Date)).toDateString(),
group: d.Category,
text: {
headline: d['Main events'],
text: d.Details,
},
}
));

const events = { events: evt };

useEffect(() => {
// eslint-disable-next-line
const timeline = new TL(
'timeline-embed',
events,
timelineoptions,
);
});

return (
<div id="timeline-embed" className="container" style={{ height: 500 }} />
);
}

export default Timeline;
1 change: 1 addition & 0 deletions lib/src/Timeline/timelinejs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '@knight-lab/timelinejs';

This comment has been minimized.

Copy link
@tnagorra

tnagorra Dec 7, 2023

Member

Any reason we are adding an empty declaration file

This comment has been minimized.

Copy link
@matthewsmawfield

matthewsmawfield Dec 7, 2023

Author Collaborator

there is no existing @types/knight-lab... and so the advice i found about the error on stackoverflow was to create an empty declaration file: https://stackoverflow.com/a/50516783 - please advise if this should be done differently

5 changes: 5 additions & 0 deletions lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ export {
default as KPIs,
type Props as KPIsProps,
} from './KPIs';

export {
default as Timeline,
// type Props as TimelineProps,
} from './Timeline';
2 changes: 1 addition & 1 deletion lib/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
"sourceMap": true,
"baseUrl": "."
},
"include": ["./src/index.ts", "./src/declarations"]
"include": ["./src/index.ts", "./src/declarations", "src/Timeline/timelinejs.d.ts"]

This comment has been minimized.

Copy link
@tnagorra

tnagorra Dec 7, 2023

Member

We can add a general rule to include all the declarations files

src/**/*.d.ts

}
2 changes: 1 addition & 1 deletion storybook/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { KPIs } from '@the-deep/reporting-module-components';
import '@the-deep/reporting-module-components/build/esm/index.css';

import MapVizzard from './components/MapVizzard';
import Timeline from './components/Timeline/Timeline';
import Timeline from '@the-deep/reporting-module-components/src/Timeline/Timeline';
import timelineData from './stories/Timeline.json';
import kpiData from './stories/KPIs.json';
import styles from './App.module.css';
Expand Down
49 changes: 0 additions & 49 deletions storybook/src/components/Timeline/Timeline.jsx

This file was deleted.

3 changes: 2 additions & 1 deletion storybook/src/stories/Timeline.stories.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Timeline from '../components/Timeline/Timeline';
import { Timeline } from '@the-deep/reporting-module-components';

import data from './Timeline.json';

// Story Config
Expand Down
2 changes: 1 addition & 1 deletion storybook/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
},
"include": [
"src"
]
, "../lib/src/Timeline" ]

This comment has been minimized.

Copy link
@tnagorra

tnagorra Dec 7, 2023

Member

Storybook should not directly import from lib.
We should build the library and then use it as a package.

}

0 comments on commit 26ac546

Please sign in to comment.