Merge pull request #227 from reuters-graphics/mf-timeline

Updates SimpleTimeline
This commit is contained in:
MinamiFunakoshiTR 2025-03-12 10:46:35 -05:00 committed by GitHub
commit 916e5c46b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 186 additions and 102 deletions

View file

@ -0,0 +1,119 @@
import { Meta, Canvas } from '@storybook/blocks';
import * as SimpleTimelineStories from './SimpleTimeline.stories.svelte';
<Meta of={SimpleTimelineStories} />
# SimpleTimeline
The `SimpleTimeline` component creates a basic timeline with dates, titles and descriptions of events.
```svelte
<script>
import { SimpleTimeline } from '@reuters-graphics/graphics-components';
const dates = [
{
date: 'May 18',
events: [
{
title: 'A title for the event',
titleLink: 'https://...', // optional
context: 'Lorem ipsum...', // optional
},
// More events...
],
},
// More dates...
];
</script>
<SimpleTimeline {dates} />
```
<Canvas of={SimpleTimelineStories.Demo} />
## Using with ArchieML docs
With the graphics kit, you'll likely get your text value from an ArchieML doc.
```yaml
# Archie ML doc
[timeline]
# date object with events
date: May 18
[.events]
title: Mariupol defenders surrender to Russia but their fate is uncertain
context: More than 250 Ukrainian fighters surrendered to Russian forces at the Azovstal steelworks in Mariupol after weeks of desperate resistance, bringing an end to the most devastating siege of Russia's war in Ukraine and allowing President Vladimir Putin to claim a rare victory in his faltering campaign.
titleLink: https://www.reuters.com/world/europe/ukrainian-troops-evacuate-mariupol-ceding-control-russia-2022-05-17/
# More events...
[]
date: May 10
[.events]
title: U.S. House passes $40 bln bill to bolster Ukraine against Russian invasion
context: The U.S. House of Representatives approved more than $40 billion more aid for Ukraine on Tuesday, as Congress races to keep military aid flowing and boost the government in Kyiv as it grapples with the Russian invasion.
titleLink: https://www.reuters.com/world/us-house-vote-40-billion-ukraine-aid-package-tuesday-pelosi-2022-05-10/
[]
# More dates and events...
[]
```
... which you'll pass to the `SimpleTimeline` component.
```svelte
<!-- Graphics Kit -->
<script>
import { SimpleTimeline } from '@reuters-graphics/graphics-components';
import content from '$locales/en/content.json';
</script>
<EndNotes SimpleTimeline={content.timeline} />
```
<Canvas of={SimpleTimelineStories.Demo} />
# Multiple events
You can add multiple events to a single date by adding objects to the `events` array.
```svelte
<script>
import { SimpleTimeline } from '@reuters-graphics/graphics-components';
const dates = [
{
date: 'Feb. 25',
// Multiple events for this date
events: [
{
title: 'NATO deploys more troops',
context:
'NATO leaders said on Friday they were deploying more troops to eastern Europe after Russia invaded Ukraine, saying that Moscow had lied about its intentions.',
},
{
title: 'Invasion continues',
context:
'Missiles pounded the Ukrainian capital as Russian forces pressed their advance and Ukrainian President Volodymyr Zelenskiy pleaded with the international community to do more, saying sanctions announced so far were not enough.\n\nRussian forces battered Ukrainian cities with artillery and cruise missiles but a defiant Zelenskiy said the capital Kyiv remained in Ukrainian hands.',
},
],
},
{
date: 'Feb. 24',
events: [
{
title: 'Russia invades Ukraine',
},
],
},
];
</script>
<SimpleTimeline {dates} />
```
<Canvas of={SimpleTimelineStories.MultipleEvents} />

View file

@ -1,25 +1,18 @@
<script module lang="ts">
// @ts-ignore raw
import componentDocs from './stories/docs/component.md?raw';
import { defineMeta } from '@storybook/addon-svelte-csf';
import SimpleTimeline from './SimpleTimeline.svelte';
import { withComponentDocs } from '$lib/docs/utils/withParams.js';
export const meta = {
const { Story } = defineMeta({
title: 'Components/Text elements/SimpleTimeline',
component: SimpleTimeline,
...withComponentDocs(componentDocs),
argTypes: {
symbolColour: { control: 'color' },
dateColour: { control: 'color' },
},
};
});
</script>
<script>
import { Template, Story } from '@storybook/addon-svelte-csf';
<script lang="ts">
const dates = [
{
date: 'May 18',
@ -56,20 +49,9 @@
},
],
},
{
date: 'Feb. 27',
events: [
{
title: 'Russians push into Kharkiv',
titleLink:
'https://www.reuters.com/world/europe/western-allies-expel-key-russian-banks-global-system-ukraine-fights-2022-02-27/',
},
{
title:
'Human rights groups and Ukrainian ambassador accuse Russia of using cluster and vacuum bombs',
},
],
},
];
const datesMultipleEvents = [
{
date: 'Feb. 25',
events: [
@ -96,15 +78,18 @@
];
</script>
<Template >
{#snippet children({ args })}
<SimpleTimeline {...args} />
{/snippet}
</Template>
<Story
name="Demo"
args={{
dates,
}}
/>
<Story
name="Default"
args="{{
dates,
}}"
name="Multiple events"
exportName="MultipleEvents"
tags={['!autodocs', '!dev']}
args={{
dates: datesMultipleEvents,
}}
/>

View file

@ -1,6 +1,10 @@
<!-- @migration-task Error while migrating Svelte code: Cannot set properties of undefined (setting 'next') -->
<!-- @component `SimpleTimeline` [Read the docs.](https://reuters-graphics.github.io/graphics-components/?path=/docs/components-text-elements-simpletimeline--docs) -->
<script lang="ts">
import Fa from 'svelte-fa/src/fa.svelte';
import { faLink } from '@fortawesome/free-solid-svg-icons';
import Block from '../Block/Block.svelte';
import Markdown from '../Markdown/Markdown.svelte';
interface Event {
title: string;
titleLink?: string;
@ -10,37 +14,37 @@
date: string;
events: Event[];
}
/**
* An array of dates with events.
* @required
*/
export let dates: EventDate[];
/**
* Set a colour for the timeline bullet symbols and line.
* @type {string}
*/
export let symbolColour: string = 'var(--theme-colour-brand-rules)';
/**
* Set a colour for the date headings in the timeline.
* @type {string}
*/
export let dateColour: string = 'var(--theme-colour-accent, red)';
/**
* Set a class to target with SCSS.
* @type {string}
*/
let cls: string = '';
export { cls as class };
/**
* Set an ID to target with SCSS.
* @type {string}
*/
export let id: string = '';
import Block from '../Block/Block.svelte';
import Fa from 'svelte-fa/src/fa.svelte';
import { faLink } from '@fortawesome/free-solid-svg-icons';
import Markdown from '../Markdown/Markdown.svelte';
interface Props {
/**
* An array of dates with events.
*/
dates: EventDate[];
/**
* Set a colour for the timeline bullet symbols and line.
*/
symbolColour?: string;
/**
* Set a colour for the date headings in the timeline.
*/
dateColour?: string;
/**
* Set a class to target with SCSS.
*/
class?: string;
/**
* Set an ID to target with SCSS.
*/
id?: string;
}
let {
dates,
symbolColour = 'var(--theme-colour-brand-rules)',
dateColour = 'var(--theme-colour-accent, red)',
class: cls = '',
id = '',
}: Props = $props();
</script>
<Block width="normal" {id} class="simple-timeline-container fmy-6 {cls}">
@ -52,24 +56,24 @@
cx="10"
cy="12"
r="5"
stroke="{symbolColour}"
stroke={symbolColour}
stroke-width="2"
fill="transparent"
></circle>
</svg>
<div
class="timeline-date font-note text-xs uppercase font-black tracking-wide fmb-0"
style:color="{dateColour}"
style:color={dateColour}
>
{date.date}
</div>
{#each date.events as event}
<div class="event pb-2">
{#if event.titleLink}
<a href="{event.titleLink}" target="_blank">
<a href={event.titleLink} target="_blank">
<div class="title h3">
{event.title}
<span class="text-sm"><Fa fw icon="{faLink}" /></span>
<span class="text-sm"><Fa fw icon={faLink} /></span>
</div>
</a>
{:else}
@ -78,7 +82,7 @@
</div>
{/if}
{#if event.context}
<Markdown source="{event.context}" />
<Markdown source={event.context} />
{/if}
</div>
{/each}
@ -88,13 +92,13 @@
</Block>
<style lang="scss">
@use '../../scss/mixins' as *;
@use '../../scss/mixins' as mixins;
.timeline {
.date {
border-left: 1px solid var(--symbol-colour);
&:last-child {
border-left: 1px solid $theme-colour-background;
@include fpb-0;
border-left: 1px solid mixins.$theme-colour-background;
@include mixins.fpb-0;
}
}
svg {
@ -102,9 +106,9 @@
left: -10px;
}
div.title {
@include fmt-2;
@include fmb-1;
@include font-medium;
@include mixins.fmt-2;
@include mixins.fmb-1;
@include mixins.font-medium;
}
div.event {
@ -123,8 +127,8 @@
}
}
:global(p) {
@include body-note;
@include font-light;
@include mixins.body-note;
@include mixins.font-light;
}
}
}

View file

@ -1,24 +0,0 @@
A simple, clean text timeline.
```svelte
<script>
import { SimpleTimeline } from '@reuters-graphics/graphics-components';
const dates = [
{
date: 'May 18',
events: [
{
title: 'A title for the event',
titleLink: 'https://...', // optional
context: 'Lorem ipsum...', // optional
},
// More events...
],
},
// More dates...
];
</script>
<SimpleTimeline dates="{dates}" />
```