diff --git a/src/components/Byline/Byline.mdx b/src/components/Byline/Byline.mdx index dbff6ad5..3f812644 100644 --- a/src/components/Byline/Byline.mdx +++ b/src/components/Byline/Byline.mdx @@ -58,7 +58,7 @@ updateTime: 2021-09-12T12:57:00.000Z -## Cutomisation +## Custom byline, published and updated datelines Use [snippets](https://svelte.dev/docs/svelte/snippet) to customise the byline, published and updated datelines. @@ -82,3 +82,25 @@ Use [snippets](https://svelte.dev/docs/svelte/snippet) to customise the byline, ``` + +## Custom author page + +By default, the `Byline` component will hyperlink each author's byline to their Reuters.com page, formatted `https://www.reuters.com/authors/{author-slug}/`. + +To hyperlink to different pages or email addresses, pass a custom function to the `getAuthorPage` prop. + +```svelte + + { + return `mailto:${author.replace(' ', '')}@example.com`; + }} +/> + +``` + + +```` diff --git a/src/components/Byline/Byline.stories.svelte b/src/components/Byline/Byline.stories.svelte index c0cf796a..33705d5a 100644 --- a/src/components/Byline/Byline.stories.svelte +++ b/src/components/Byline/Byline.stories.svelte @@ -18,7 +18,6 @@ + + { + return `mailto:${author.replace(' ', '')}@example.com`; + }, + }} +/> diff --git a/src/components/Byline/Byline.svelte b/src/components/Byline/Byline.svelte index c904e27f..fa8e2558 100644 --- a/src/components/Byline/Byline.svelte +++ b/src/components/Byline/Byline.svelte @@ -1,8 +1,8 @@ + + +``` + + + +## With bylines and dateline + +Optionally, you can add authors and a publish time to the headline, which the `Headline` component internally renders with the [Byline](./?path=/docs/components-text-elements-byline--docs) component. + +> **Note**: Since `Headline` uses `Byline`, you can customise the author page hyperlink and bylines with the `getAuthorPage`, `byline`, `published` and `updated` props. + +```svelte + + + { + return `mailto:${author.replace(' ', '')}@example.com`; + }} +/> +``` + + + +## Custom hed and dek + +Use the `hed` and/or `dek` [snippets](https://svelte.dev/docs/svelte/snippet) to override those elements with custom elements. + +```svelte + + + + + {#snippet hed()} +

+ The secret to + “The Nutcracker's” + success +

+ {/snippet} + + + {#snippet dek()} +

+ How “The Nutcracker” ballet became anAmerican holday stapleand a financial pillar of ballet companies across the country +

+ {/snippet} +
+ + + +``` + + + +## With crown image + +To add a crown image, use the `crown` [snippet](https://svelte.dev/docs/svelte/snippet). + +```svelte + + + + + {#snippet crown()} + Illustration of Europe + {/snippet} + +``` + + + +## With crown graphic + +Add a full graphic or any other component in the crown. + +```svelte + + + + + {#snippet crown()} + + + {/snippet} + +``` + + diff --git a/src/components/Headline/Headline.stories.svelte b/src/components/Headline/Headline.stories.svelte index 720d119b..0b48df75 100644 --- a/src/components/Headline/Headline.stories.svelte +++ b/src/components/Headline/Headline.stories.svelte @@ -1,28 +1,10 @@ - - - + { + return `mailto:${author.replace(' ', '')}@example.com`; + }} /> - - - - - + {#snippet hed()} -

+

The secret to “The Nutcracker's” success

- {/snippet} + {/snippet} {#snippet dek()} -

+

How “The Nutcracker” ballet became anAmerican holday stapleand a financial pillar of ballet companies across the country

- {/snippet} + {/snippet}
-
- - + + {#snippet crown()} - Illustration of Europe - {/snippet} - - {#snippet hed()} -

Europa

- {/snippet} + {/snippet}
- + {#snippet crown()} -
- -
- {/snippet} + + {/snippet}
+ + diff --git a/src/components/Headline/Headline.svelte b/src/components/Headline/Headline.svelte index ef10aa1b..07e77005 100644 --- a/src/components/Headline/Headline.svelte +++ b/src/components/Headline/Headline.svelte @@ -1,60 +1,76 @@ -
- {#if $$slots.crown} + {#if crown}
- - + + {@render crown()}
{/if}
@@ -91,53 +107,56 @@ {section}

{/if} - {#if $$slots.hed} - - - {:else} -

- + {#if typeof hed === 'string'} +

+

+ {:else if hed} + + {@render hed()} {/if} - {#if $$slots.dek} - + {#if typeof dek === 'string'}
- +
{:else if dek} +
- + {@render dek()}
{/if}

- {#if $$slots.byline} - - - {:else if authors.length > 0 || publishTime} + {#if authors.length > 0 || publishTime} + {:else if byline} + + {@render byline()} {/if}
diff --git a/src/components/Headline/stories/crown.png b/src/components/Headline/demo/crown.png similarity index 100% rename from src/components/Headline/stories/crown.png rename to src/components/Headline/demo/crown.png diff --git a/src/components/Headline/stories/graphic-lg.png b/src/components/Headline/demo/graphic-lg.png similarity index 100% rename from src/components/Headline/stories/graphic-lg.png rename to src/components/Headline/demo/graphic-lg.png diff --git a/src/components/Headline/stories/graphic-md.png b/src/components/Headline/demo/graphic-md.png similarity index 100% rename from src/components/Headline/stories/graphic-md.png rename to src/components/Headline/demo/graphic-md.png diff --git a/src/components/Headline/stories/graphic-sm.png b/src/components/Headline/demo/graphic-sm.png similarity index 100% rename from src/components/Headline/stories/graphic-sm.png rename to src/components/Headline/demo/graphic-sm.png diff --git a/src/components/Headline/stories/graphic-xl.png b/src/components/Headline/demo/graphic-xl.png similarity index 100% rename from src/components/Headline/stories/graphic-xl.png rename to src/components/Headline/demo/graphic-xl.png diff --git a/src/components/Headline/stories/graphic-xs.png b/src/components/Headline/demo/graphic-xs.png similarity index 100% rename from src/components/Headline/stories/graphic-xs.png rename to src/components/Headline/demo/graphic-xs.png diff --git a/src/components/Headline/stories/graphic.svelte b/src/components/Headline/demo/graphic.svelte similarity index 98% rename from src/components/Headline/stories/graphic.svelte rename to src/components/Headline/demo/graphic.svelte index 28a6b06c..bfccbab4 100644 --- a/src/components/Headline/stories/graphic.svelte +++ b/src/components/Headline/demo/graphic.svelte @@ -14,7 +14,7 @@ let width = $state(null); -
+
{#if width && width >= 0 && width < 510}
@@ -22,7 +22,7 @@
- import { Headline } from '@reuters-graphics/graphics-components'; - - - -``` diff --git a/src/components/Headline/stories/docs/customHed.md b/src/components/Headline/stories/docs/customHed.md deleted file mode 100644 index 25228bd3..00000000 --- a/src/components/Headline/stories/docs/customHed.md +++ /dev/null @@ -1,31 +0,0 @@ -Use the `hed` and/or `dek` named slots to override those elements with completely custom markup. - -```svelte - - - -

- The secret to - “The Nutcracker's” - success -

-

- How “The Nutcracker” ballet became anAmerican holday stapleand a financial pillar of ballet companies across the country -

-
- - -``` diff --git a/src/components/Headline/stories/docs/withByline.md b/src/components/Headline/stories/docs/withByline.md deleted file mode 100644 index eff73515..00000000 --- a/src/components/Headline/stories/docs/withByline.md +++ /dev/null @@ -1,13 +0,0 @@ -```svelte - - - -``` diff --git a/src/components/Headline/stories/docs/withCrownGraphic.md b/src/components/Headline/stories/docs/withCrownGraphic.md deleted file mode 100644 index 48a7099a..00000000 --- a/src/components/Headline/stories/docs/withCrownGraphic.md +++ /dev/null @@ -1,24 +0,0 @@ -Add a full graphic or any other component in the crown. - -```svelte - - - - -
- -
-
-``` diff --git a/src/components/Headline/stories/docs/withCrownImage.md b/src/components/Headline/stories/docs/withCrownImage.md deleted file mode 100644 index f705d9cb..00000000 --- a/src/components/Headline/stories/docs/withCrownImage.md +++ /dev/null @@ -1,21 +0,0 @@ -Add a crown image in the `crown` named slot and override the headline in the `hed` named slot. - -```svelte - - - - - Illustration of Europe - -

Europa

-
-``` diff --git a/src/components/Headline/stories/docs/withDek.md b/src/components/Headline/stories/docs/withDek.md deleted file mode 100644 index 63b808c7..00000000 --- a/src/components/Headline/stories/docs/withDek.md +++ /dev/null @@ -1,11 +0,0 @@ -```svelte - - - -``` diff --git a/src/utils/index.ts b/src/utils/index.ts new file mode 100644 index 00000000..0760531d --- /dev/null +++ b/src/utils/index.ts @@ -0,0 +1,9 @@ +import slugify from 'slugify'; + +/** + * Custom function that returns an author page URL. + */ +export const getAuthorPageUrl = (author: string): string => { + const authorSlug = slugify(author.trim(), { lower: true }); + return `https://www.reuters.com/authors/${authorSlug}/`; +};