set up snippets in Headline.svelte, working on docs

This commit is contained in:
MinamiFunakoshiTR 2025-03-18 14:46:42 -07:00
parent 2f7c40f6c1
commit 478f16472a
Failed to extract signature
3 changed files with 20 additions and 25 deletions

View file

@ -52,8 +52,9 @@ The `Headline` component creates the Reuters Graphics headline.
/>
```
## With custom hed
Use the `hed` and/or `dek` named slots to override those elements with completely custom markup.
## With custom hed
Use the `hed` and/or `dek` [snippets](https://svelte.dev/docs/svelte/snippet) to override those elements with completely custom markup.
```svelte
<script>

View file

@ -54,14 +54,14 @@
<Story name="Custom hed" exportName="CustomHed">
<Headline width="wide">
{#snippet customHed()}
{#snippet hed()}
<h1 class="custom-hed">
<span class="small block text-base">The secret to</span>
“The Nutcracker's”
<span class="small block text-base fpt-1">success</span>
</h1>
{/snippet}
{#snippet customDek()}
{#snippet dek()}
<p class="custom-dek !fmt-3">
How “The Nutcracker” ballet became an<span
class="font-medium mx-1 px-1.5 py-1">American holday staple</span

View file

@ -10,20 +10,16 @@
import Markdown from '../Markdown/Markdown.svelte';
interface Props {
/** Headline, parsed as an _inline_ markdown string in an `h1` element. */
hed: string;
/** Headline, parsed as an _inline_ markdown string in an `h1` element OR as a custom snippet. */
hed: string | Snippet;
/** Custom byline snippet */
byline?: Snippet;
/** Custom headline snippet */
customHed?: Snippet;
/** Add extra classes to the block tag to target it with custom CSS. */
class?: string;
/** Headline size: small, normal, big, bigger, biggest */
hedSize?: HeadlineSize;
/** Dek, parsed as a markdown string. */
dek?: string;
/** Custom dek snippet */
customDek?: Snippet;
/** Dek, parsed as a markdown string OR as a custom snippet. */
dek?: string | Snippet;
/** Custom crown snippet */
crown?: Snippet;
/** Section title */
@ -41,11 +37,9 @@
let {
hed = 'Reuters Graphics Interactive',
byline,
customHed,
class: cls = '',
hedSize = 'normal',
dek,
customDek,
crown,
section,
authors = [],
@ -93,23 +87,23 @@
{section}
</p>
{/if}
{#if customHed}
<!-- Headline snippet -->
{@render customHed()}
{:else}
{#if typeof hed === 'string'}
<h1 class={hedClass}>
<Markdown source={hed} parseInline />
</h1>
{:else if hed}
<!-- Headline snippet -->
{@render hed()}
{/if}
{#if customDek}
<!-- Dek snippet-->
<div class="dek fmx-auto fmb-6">
{@render customDek()}
</div>
{:else if dek}
{#if typeof dek === 'string'}
<div class="dek fmx-auto fmb-6">
<Markdown source={dek} />
</div>
{:else if dek}
<!-- Dek snippet-->
<div class="dek fmx-auto fmb-6">
{@render dek()}
</div>
{/if}
</div>
{#if byline}
@ -132,7 +126,7 @@
@use '../../scss/mixins' as mixins;
.headline-wrapper {
:global(.dek) {
max-width: $column-width-normal;
max-width: mixins.$column-width-normal;
}
:global(.dek p) {
@include mixins.fmt-0;