diff --git a/src/components/Byline/Byline.mdx b/src/components/Byline/Byline.mdx index c47a7459..a5c8a071 100644 --- a/src/components/Byline/Byline.mdx +++ b/src/components/Byline/Byline.mdx @@ -1,4 +1,4 @@ -import { Meta } from '@storybook/blocks'; +import { Meta, Canvas } from '@storybook/blocks'; import * as BylineStories from './Byline.stories.svelte'; @@ -24,3 +24,28 @@ Easily add a byline and dateline to your story. updateTime="2021-09-12T12:57:00.000Z" /> ``` + +## Cutom byline, published and updated datelines + +You can customise the byline, published and updated datelines using [snippets](https://svelte.dev/docs/svelte/snippet), which are the Svelte 5 version of slots. You can pass any string or html as snippets. + +```svelte + + + {#snippet byline()} + BY REUTERS GRAPHICS + {/snippet} + + + {#snippet published()} + PUBLISHED on some custom date and time + {/snippet} + + + {#snippet updated()} + Updated every 5 minutes + {/snippet} + +``` + + diff --git a/src/components/Byline/Byline.stories.svelte b/src/components/Byline/Byline.stories.svelte index bd27026a..21d67514 100644 --- a/src/components/Byline/Byline.stories.svelte +++ b/src/components/Byline/Byline.stories.svelte @@ -16,7 +16,7 @@ - - `https://www.reuters.com/graphics/`} - publishTime="2021-09-12T00:00:00Z" - updateTime="2021-09-12T13:57:00Z" - > - {#snippet customPublished()} + + + {#snippet byline()} + BY REUTERS GRAPHICS + {/snippet} + {#snippet published()} PUBLISHED on some custom date and time {/snippet} - {#snippet customUpdated()} + {#snippet updated()} Updated every 5 minutes {/snippet} diff --git a/src/components/Byline/Byline.svelte b/src/components/Byline/Byline.svelte index fe58bba1..8be3cb54 100644 --- a/src/components/Byline/Byline.svelte +++ b/src/components/Byline/Byline.svelte @@ -10,7 +10,7 @@ /** * Array of author names, which will be slugified to create links to Reuters author pages */ - authors: string[]; + authors?: string[]; /** * Publish time as a datetime string. */ @@ -39,15 +39,19 @@ * Custom function that returns an author page URL. */ getAuthorPage?: (author: string) => string; + /** + * Optional snippet for a custom byline. + */ + byline?: Snippet | null; /** * Optional snippet for a custom published dateline. */ // Specify that this prop should have the type of a Svelte snippet, i.e. basic html - customPublished?: Snippet | null; + published?: Snippet | null; /** * Optional snippet for a custom updated dateline. */ - customUpdated?: Snippet | null; + updated?: Snippet | null; } let { @@ -61,8 +65,9 @@ const authorSlug = slugify(author.trim(), { lower: true }); return `https://www.reuters.com/authors/${authorSlug}/`; }, - customPublished = null, - customUpdated = null, + byline = null, + published = null, + updated = null, }: Props = $props(); let alignmentClass = $derived(align === 'left' ? 'text-left' : 'text-center'); @@ -92,32 +97,37 @@