diff --git a/src/components/SvelteScroller/Background.svelte b/src/components/SvelteScroller/Background.svelte new file mode 100644 index 00000000..337a3c15 --- /dev/null +++ b/src/components/SvelteScroller/Background.svelte @@ -0,0 +1,42 @@ + + +{#each steps as step, i} + + + {#if preload === 0 || (i >= (stackBackground ? 0 : index - preload) && i <= index + preload)} +
index : i !== index} + > + +
+ {/if} +{/each} + + diff --git a/src/components/SvelteScroller/Embedded/Background.svelte b/src/components/SvelteScroller/Embedded/Background.svelte new file mode 100644 index 00000000..b7bc244d --- /dev/null +++ b/src/components/SvelteScroller/Embedded/Background.svelte @@ -0,0 +1,18 @@ + + + + + diff --git a/src/components/SvelteScroller/Embedded/Foreground.svelte b/src/components/SvelteScroller/Embedded/Foreground.svelte new file mode 100644 index 00000000..a5e5c601 --- /dev/null +++ b/src/components/SvelteScroller/Embedded/Foreground.svelte @@ -0,0 +1,48 @@ + + +{#if step.foreground === '' || !step.foreground} + +
+ + {#if typeof step.altText === 'string'} +
+ +
+ {/if} +{:else if typeof step.foreground === 'string'} + +
+ +
+ + {#if typeof step.altText === 'string'} +
+ +
+ {/if} +
+{:else} +
+ +
+{/if} + + diff --git a/src/components/SvelteScroller/Embedded/index.svelte b/src/components/SvelteScroller/Embedded/index.svelte new file mode 100644 index 00000000..11484017 --- /dev/null +++ b/src/components/SvelteScroller/Embedded/index.svelte @@ -0,0 +1,31 @@ + + +{#each steps as step, index} + + {#if embeddedLayout === 'bf'} + + + + {:else} + + + {/if} +{/each} diff --git a/src/components/SvelteScroller/Foreground.svelte b/src/components/SvelteScroller/Foreground.svelte new file mode 100644 index 00000000..f0f26f90 --- /dev/null +++ b/src/components/SvelteScroller/Foreground.svelte @@ -0,0 +1,64 @@ + + +{#each steps as step, i} +
+ {#if step.foreground === '' || !step.foreground} + +
+ {#if typeof step.altText === 'string'} +
+ +
+ {/if} + {:else} +
+ {#if typeof step.foreground === 'string'} + + {:else} + + {/if} +
+ {#if typeof step.altText === 'string'} +
+ +
+ {/if} + {/if} +
+{/each} + + diff --git a/src/components/SvelteScroller/ScrollerBase/index.svelte b/src/components/SvelteScroller/ScrollerBase/index.svelte new file mode 100644 index 00000000..807f05ff --- /dev/null +++ b/src/components/SvelteScroller/ScrollerBase/index.svelte @@ -0,0 +1,270 @@ + + + + + + + + + + + {@render backgroundSnippet()} + + + + + {@render foregroundSnippet()} + + + + diff --git a/src/components/SvelteScroller/SvelteScroller.mdx b/src/components/SvelteScroller/SvelteScroller.mdx new file mode 100644 index 00000000..f8905f34 --- /dev/null +++ b/src/components/SvelteScroller/SvelteScroller.mdx @@ -0,0 +1,279 @@ +import { Meta } from '@storybook/blocks'; + +import * as SvelteScrollerStories from './SvelteScroller.stories.svelte'; + + + +# SvelteScroller + +The `SvelteScroller` component creates a basic scrollytelling graphic with layout options. + +> This component is designed to handle most common layouts for scrollytelling. To make something more complex, customise [ScrollerBase](https://github.com/reuters-graphics/graphics-components/blob/main/src/components/Scroller/ScrollerBase/index.svelte), which is a Svelte 5 version of the [svelte-scroller](https://github.com/sveltejs/svelte-scroller). + +[Demo](?path=/story/components-graphics-scroller--demo) + +```svelte + + + +``` + +## Using with ArchieML and ai2svelte + +[Demo](?path=/story/components-graphics-scroller--archie-ml) + +In your graphics kit project, import your ai2svelte graphics in `App.svelte` and add them to the `aiCharts` object: + +```svelte + + +``` + +Then add the following structure to your ArchieML Doc, making sure that the names of your charts in the `aiCharts` object match the names of each step's `background` in the ArchieML doc: + +```yaml +# ArchieML doc +[blocks] +type: ai-scroller +id: my-map-scroller +width: fluid +foregroundPosition: right +stackBackground: true + +# Array of step objects + [.steps] + background: AiMap1 + foreground: #### Step 1 + + Here's where something happend. + :end + altText: A map showing the Upper West side in New York City. + + Can add paragraphs of alt text if you want to break up sentences. + :end + + background: AiMap2 + foreground: #### Step 2 + + Something happened on some street... + :end + altText: The same map now highlights 98th Street. + :end + + background: AiMap3 + foreground: #### Step 3 + + ... and now there are multiple protests. + :end + altText: The same map now highlights three locations near 98th Street where something particulary important happened. + :end + [] +[] +``` + +Then parse the relevant ArchieML block object before passing to the `Scroller` component. + +```svelte + +{#each content.blocks as block} + {#if block.type === 'ai-scroller'} + ({ + background: aiCharts[step.background], + backgroundProps: { assetsPath: assets || '/' }, + foreground: step.foreground, + altText: step.altText, + }))} + /> + {/if} +{/each} +``` + +> **Note:** Some props, like `stackBackground`, expect boolean values. If you're using the graphics kit, use the `truthy()` util function to convert a string value to a boolean. + +> **Note:** In the graphics kit, the image source paths in ai2svelte components have to be fixed by passing `assets` to each step object, like in the example above. + +## Custom foreground + +[Demo](?path=/story/components-graphics-scroller--custom-foreground) + +Instead of just text, you can use components as foregrounds, and optionally pass props to it. + +If you're customising your own foreground component, remember to add alt text that describes the background graphic. + +```svelte + + + +``` + +## Custom foreground with ArchieML + +[Demo](?path=/story/components-graphics-scroller--customforeground-archie-ml) + +You can use custom foreground components with ArchieML with a few additional steps. + +In your graphics kit project's `App.svelte`, import your custom foregroud components and add them to a `foregroundComponents` object, just as you import ai2svelte background graphics and add them to the `aiCharts` object: + +```svelte + + +``` + +Then add the following structure to your ArchieML Doc, making sure that the names of your charts in the `aiCharts` and `foregroundComponents` objects match the names of each step's `background` and `foreground` in the ArchieML doc: + +```yaml +# ArchieML doc +[blocks] +type: ai-scroller +id: my-map-scroller +foregroundPosition: left +stackBackground: true + +# Array of step objects + [.steps] + background: AiMap1 + # You can still use a markdown string even if other step/s use a custom foreground component + foreground: #### Step 1 + + Here's where something happend. + :end + altText: A map showing the Upper West side in New York City. + :end + + background: AiMap2 + foreground: Foreground1 # The name of your custom foreground component + altText: The same map now highlights 98th Street. + :end + background: AiMap3 + foreground: #### Step 3 + + ... and now there are multiple protests. + :end + altText: The same map now highlights three locations near 98th Street where something particulary important happened. + :end + [] +[] +``` + +Then parse the relevant ArchieML block object before passing to the `Scroller` component. + +```svelte + +{#each content.blocks as block} + {#if block.type === 'ai-scroller'} + ({ + background: aiCharts[step.background], + backgroundProps: { assetsPath: assets || '/' }, + foreground: foregroundComponents[step.foreground] || step.foreground, + foregroundProps: { assetsPath: assets || '/' }, + altText: step.altText, + }))} + /> + {/if} +{/each} +``` + +> **Note:** You only need to pass `foregroundProps: { assetsPath: assets || '/' }` in the graphics kit if your foreground components are ai2svelte graphicss. diff --git a/src/components/SvelteScroller/SvelteScroller.stories.svelte b/src/components/SvelteScroller/SvelteScroller.stories.svelte new file mode 100644 index 00000000..a0f661b5 --- /dev/null +++ b/src/components/SvelteScroller/SvelteScroller.stories.svelte @@ -0,0 +1,177 @@ + + + + + + + + ({ + background: step.background, + foreground: step.foreground, + altText: step.altText, + }))} + /> + + + + + + ({ + background: step.background, + foreground: step.foreground, + altText: step.altText, + }))} + /> + diff --git a/src/components/SvelteScroller/SvelteScroller.svelte b/src/components/SvelteScroller/SvelteScroller.svelte new file mode 100644 index 00000000..777cef59 --- /dev/null +++ b/src/components/SvelteScroller/SvelteScroller.svelte @@ -0,0 +1,189 @@ + + + +{#if !embedded} + + + {#snippet backgroundSnippet()} + + {/snippet} + {#snippet foregroundSnippet()} +
+ +
+ {/snippet} +
+
+{:else} + + + +{/if} + + diff --git a/src/components/SvelteScroller/demo/components/ai2svelte/ai-foreground.svelte b/src/components/SvelteScroller/demo/components/ai2svelte/ai-foreground.svelte new file mode 100644 index 00000000..6af40a5d --- /dev/null +++ b/src/components/SvelteScroller/demo/components/ai2svelte/ai-foreground.svelte @@ -0,0 +1,112 @@ + + +
+ + {#if width && width >= 0} +
+
+
+
+

Likelihood of something happening

+
+ +
+

0-25%

+
+
+

50-75%

+
+
+

75-100%

+
+
+

25-50%

+
+
+ {/if} +
+ + + + + + diff --git a/src/components/SvelteScroller/demo/components/ai2svelte/ai-scroller-1.svelte b/src/components/SvelteScroller/demo/components/ai2svelte/ai-scroller-1.svelte new file mode 100644 index 00000000..df60d003 --- /dev/null +++ b/src/components/SvelteScroller/demo/components/ai2svelte/ai-scroller-1.svelte @@ -0,0 +1,121 @@ + + + + +
+ + {#if width && width >= 1200} +
+
+
+
+ {/if} + + {#if width && width >= 930 && width < 1200} +
+
+
+
+ {/if} + + {#if width && width >= 660 && width < 930} +
+
+
+
+ {/if} + + {#if width && width >= 510 && width < 660} +
+
+
+
+ {/if} + + {#if width && width >= 0 && width < 510} +
+
+
+
+ {/if} +
+ + + + + + + diff --git a/src/components/SvelteScroller/demo/components/ai2svelte/ai-scroller-2.svelte b/src/components/SvelteScroller/demo/components/ai2svelte/ai-scroller-2.svelte new file mode 100644 index 00000000..18a5870f --- /dev/null +++ b/src/components/SvelteScroller/demo/components/ai2svelte/ai-scroller-2.svelte @@ -0,0 +1,310 @@ + + + + +
+ + {#if width && width >= 1200} +
+
+
+
+

This thing here is

+

particularly important

+
+
+ {/if} + + {#if width && width >= 930 && width < 1200} +
+
+
+
+

This thing here is

+

particularly important

+
+
+ {/if} + + {#if width && width >= 660 && width < 930} +
+
+
+
+

This thing here is

+

particularly important

+
+
+ {/if} + + {#if width && width >= 510 && width < 660} +
+
+
+
+

This thing here is

+

particularly important

+
+
+ {/if} + + {#if width && width >= 0 && width < 510} +
+
+
+
+

This thing here is

+

particularly important

+
+
+ {/if} +
+ + + + + + diff --git a/src/components/SvelteScroller/demo/components/ai2svelte/ai-scroller-3.svelte b/src/components/SvelteScroller/demo/components/ai2svelte/ai-scroller-3.svelte new file mode 100644 index 00000000..33538e06 --- /dev/null +++ b/src/components/SvelteScroller/demo/components/ai2svelte/ai-scroller-3.svelte @@ -0,0 +1,310 @@ + + + + +
+ + {#if width && width >= 1200} +
+
+
+
+

Something

+

happened here

+
+
+ {/if} + + {#if width && width >= 930 && width < 1200} +
+
+
+
+

Something

+

happened here

+
+
+ {/if} + + {#if width && width >= 660 && width < 930} +
+
+
+
+

Something

+

happened here

+
+
+ {/if} + + {#if width && width >= 510 && width < 660} +
+
+
+
+

Something

+

happened here

+
+
+ {/if} + + {#if width && width >= 0 && width < 510} +
+
+
+
+

Something

+

happened here

+
+
+ {/if} +
+ + + + + + diff --git a/src/components/SvelteScroller/demo/components/ai2svelte/images/Body-issues-key-xs.png b/src/components/SvelteScroller/demo/components/ai2svelte/images/Body-issues-key-xs.png new file mode 100644 index 00000000..e03e5e19 Binary files /dev/null and b/src/components/SvelteScroller/demo/components/ai2svelte/images/Body-issues-key-xs.png differ diff --git a/src/components/SvelteScroller/demo/components/ai2svelte/images/step-1-lg.png b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-1-lg.png new file mode 100644 index 00000000..de1888e1 Binary files /dev/null and b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-1-lg.png differ diff --git a/src/components/SvelteScroller/demo/components/ai2svelte/images/step-1-md.png b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-1-md.png new file mode 100644 index 00000000..ead091c1 Binary files /dev/null and b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-1-md.png differ diff --git a/src/components/SvelteScroller/demo/components/ai2svelte/images/step-1-sm.png b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-1-sm.png new file mode 100644 index 00000000..dada63ca Binary files /dev/null and b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-1-sm.png differ diff --git a/src/components/SvelteScroller/demo/components/ai2svelte/images/step-1-xl.png b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-1-xl.png new file mode 100644 index 00000000..55823fb4 Binary files /dev/null and b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-1-xl.png differ diff --git a/src/components/SvelteScroller/demo/components/ai2svelte/images/step-1-xs.png b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-1-xs.png new file mode 100644 index 00000000..26e44491 Binary files /dev/null and b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-1-xs.png differ diff --git a/src/components/SvelteScroller/demo/components/ai2svelte/images/step-2-lg.png b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-2-lg.png new file mode 100644 index 00000000..96196438 Binary files /dev/null and b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-2-lg.png differ diff --git a/src/components/SvelteScroller/demo/components/ai2svelte/images/step-2-md.png b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-2-md.png new file mode 100644 index 00000000..37450dcb Binary files /dev/null and b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-2-md.png differ diff --git a/src/components/SvelteScroller/demo/components/ai2svelte/images/step-2-sm.png b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-2-sm.png new file mode 100644 index 00000000..e2368628 Binary files /dev/null and b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-2-sm.png differ diff --git a/src/components/SvelteScroller/demo/components/ai2svelte/images/step-2-xl.png b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-2-xl.png new file mode 100644 index 00000000..fa157444 Binary files /dev/null and b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-2-xl.png differ diff --git a/src/components/SvelteScroller/demo/components/ai2svelte/images/step-2-xs.png b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-2-xs.png new file mode 100644 index 00000000..0fef62ac Binary files /dev/null and b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-2-xs.png differ diff --git a/src/components/SvelteScroller/demo/components/ai2svelte/images/step-3-lg.png b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-3-lg.png new file mode 100644 index 00000000..9e4f0377 Binary files /dev/null and b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-3-lg.png differ diff --git a/src/components/SvelteScroller/demo/components/ai2svelte/images/step-3-md.png b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-3-md.png new file mode 100644 index 00000000..91cfa1a1 Binary files /dev/null and b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-3-md.png differ diff --git a/src/components/SvelteScroller/demo/components/ai2svelte/images/step-3-sm.png b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-3-sm.png new file mode 100644 index 00000000..876a388d Binary files /dev/null and b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-3-sm.png differ diff --git a/src/components/SvelteScroller/demo/components/ai2svelte/images/step-3-xl.png b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-3-xl.png new file mode 100644 index 00000000..03e47dde Binary files /dev/null and b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-3-xl.png differ diff --git a/src/components/SvelteScroller/demo/components/ai2svelte/images/step-3-xs.png b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-3-xs.png new file mode 100644 index 00000000..26223ca8 Binary files /dev/null and b/src/components/SvelteScroller/demo/components/ai2svelte/images/step-3-xs.png differ diff --git a/src/components/SvelteScroller/demo/components/basic/InteractiveForeground.svelte b/src/components/SvelteScroller/demo/components/basic/InteractiveForeground.svelte new file mode 100644 index 00000000..769ec63b --- /dev/null +++ b/src/components/SvelteScroller/demo/components/basic/InteractiveForeground.svelte @@ -0,0 +1,17 @@ + + +

Interactive step

+ +

The count is {count}

+ + diff --git a/src/components/SvelteScroller/demo/components/basic/Step.svelte b/src/components/SvelteScroller/demo/components/basic/Step.svelte new file mode 100644 index 00000000..d914ec8a --- /dev/null +++ b/src/components/SvelteScroller/demo/components/basic/Step.svelte @@ -0,0 +1,18 @@ + + +
+ + diff --git a/src/index.ts b/src/index.ts index f5c4197d..67eb9f22 100644 --- a/src/index.ts +++ b/src/index.ts @@ -40,6 +40,7 @@ export { default as SiteFooter } from './components/SiteFooter/SiteFooter.svelte export { default as SiteHeader } from './components/SiteHeader/SiteHeader.svelte'; export { default as SiteHeadline } from './components/SiteHeadline/SiteHeadline.svelte'; export { default as Spinner } from './components/Spinner/Spinner.svelte'; +export { default as SvelteScroller } from './components/SvelteScroller/SvelteScroller.svelte'; export { default as SponsorshipAd } from './components/AdSlot/SponsorshipAd.svelte'; export { default as Table } from './components/Table/Table.svelte'; export { default as Theme, themes } from './components/Theme/Theme.svelte';