From 4a674123df6173c89b0e0699de1509e3f04994a3 Mon Sep 17 00:00:00 2001 From: MinamiFunakoshiTR Date: Tue, 18 Mar 2025 13:44:21 -0700 Subject: [PATCH 01/11] updates graphic block --- src/components/GraphicBlock/AriaHidden.svelte | 20 -- src/components/GraphicBlock/GraphicBlock.mdx | 215 ++++++++++++++++++ .../GraphicBlock/GraphicBlock.stories.svelte | 151 ++++++------ .../GraphicBlock/GraphicBlock.svelte | 190 ++++++++-------- src/components/GraphicBlock/TextBlock.svelte | 21 -- .../GraphicBlock/components/AriaHidden.svelte | 21 ++ .../GraphicBlock/components/TextBlock.svelte | 22 ++ .../ai2svelte/ai-chart.svelte | 0 .../{stories => demo}/imgs/ai-chart-md.png | Bin .../{stories => demo}/imgs/ai-chart-sm.png | Bin .../{stories => demo}/imgs/ai-chart-xs.png | Bin .../{stories => demo}/placeholder.png | Bin .../GraphicBlock/stories/docs/ai2svelte.md | 19 -- .../GraphicBlock/stories/docs/archieML.md | 40 ---- .../GraphicBlock/stories/docs/aria.md | 56 ----- .../GraphicBlock/stories/docs/component.md | 20 -- .../GraphicBlock/stories/docs/customText.md | 14 -- 17 files changed, 438 insertions(+), 351 deletions(-) delete mode 100644 src/components/GraphicBlock/AriaHidden.svelte create mode 100644 src/components/GraphicBlock/GraphicBlock.mdx delete mode 100644 src/components/GraphicBlock/TextBlock.svelte create mode 100644 src/components/GraphicBlock/components/AriaHidden.svelte create mode 100644 src/components/GraphicBlock/components/TextBlock.svelte rename src/components/GraphicBlock/{stories => demo}/ai2svelte/ai-chart.svelte (100%) rename src/components/GraphicBlock/{stories => demo}/imgs/ai-chart-md.png (100%) rename src/components/GraphicBlock/{stories => demo}/imgs/ai-chart-sm.png (100%) rename src/components/GraphicBlock/{stories => demo}/imgs/ai-chart-xs.png (100%) rename src/components/GraphicBlock/{stories => demo}/placeholder.png (100%) delete mode 100644 src/components/GraphicBlock/stories/docs/ai2svelte.md delete mode 100644 src/components/GraphicBlock/stories/docs/archieML.md delete mode 100644 src/components/GraphicBlock/stories/docs/aria.md delete mode 100644 src/components/GraphicBlock/stories/docs/component.md delete mode 100644 src/components/GraphicBlock/stories/docs/customText.md diff --git a/src/components/GraphicBlock/AriaHidden.svelte b/src/components/GraphicBlock/AriaHidden.svelte deleted file mode 100644 index 4379590c..00000000 --- a/src/components/GraphicBlock/AriaHidden.svelte +++ /dev/null @@ -1,20 +0,0 @@ - - -{#if hidden} - -{:else} - {@render children?.()} -{/if} diff --git a/src/components/GraphicBlock/GraphicBlock.mdx b/src/components/GraphicBlock/GraphicBlock.mdx new file mode 100644 index 00000000..14dd3dad --- /dev/null +++ b/src/components/GraphicBlock/GraphicBlock.mdx @@ -0,0 +1,215 @@ +import { Meta, Canvas } from '@storybook/blocks'; + +import * as GraphicBlockStories from './GraphicBlock.stories.svelte'; + + + +# GraphicBlock + +The `GraphicBlock` component is a special derivative of the [Block](./?path=/docs/layout-block) component that wraps around your graphic. It also adds a title, description, notes and other text elements. + +Many other Reuters Graphics components use `GraphicBlock` to wrap graphics with styled text. + +```svelte + + + + +
+ +``` + + + +## Using with ai2svelte and ArchieML docs + +The `GraphicBlock` component is built to handle [ai2svelte](https://github.com/reuters-graphics/ai2svelte) graphics in Graphics Kit. + +You'll likely get your text value from an ArchieML doc... + +```yaml +# ArchieML doc +[blocks] +type: ai-graphic +width: normal +chart: AiMap # IMPORTANT: This must match the name of the ai2svelte chart you import in App.svelte +title: Earthquake in Haiti +description: The 7.2-magnitude earthquake struck at 8:29 a.m. EST, Aug. 14, 2021. +notes: \Note: A shakemap represents the ground shaking produced by an earthquake. + +\Source: USGIS +:end +altText: A map that shows the shake intensity of the earthquake, which was worst in central Haiti. +:end +[] +``` + +... which you'll parse out of a ArchieML block object before passing to the `GraphicBlock` component. + +To pass your ai2svelte graphic into `GraphicBlock` component, import your ai2svelte graphic at the top of `App.svelte` and add it to the `aiCharts` object. + +> **Important❗:** Make sure that the value for `chart` in the ArchieML doc matches the name of the ai2svelte file imported in `App.svelte`. + +```svelte + + + + +{#each content.blocks as block} + {#if block.type === 'ai-graphic'} + {#if !aiCharts[block.chart]} + + + {:else} + + {@const AiChart = aiCharts[block.chart]} + + + + + {/if} + {/if} +{/each} +``` + + + +## Custom text + +You can override the default styles for title and notes by making your own custom elements with the `customTitle` and `customNotes` [snippets](https://svelte.dev/docs/svelte/snippet): + +```svelte + + + {#snippet customTitle()} +
My smaller title
+ {/snippet} + + +
+ + + {#snippet customNotes()} + + {/snippet} +
+``` + + + +## ARIA descriptions + +If the text in your chart isn't easily read by screen readers — for example, a map with annotations that wouldn't make sense without the visual — add an `ariaDescription` that describes the chart. + +The `ariaDescription` string will be processed as markdown, so you can add multiple paragraphs, links, headers, etc. in markdown. + +> **Note:** When you set an `ariaDescription`, your graphic will be automatically wrapped in a div with [aria-hidden="true"](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-hidden), which tells screen readers to read the hidden ARIA description and skip the text in the graphic. + +```svelte + + + + +``` + + + +## Custom ARIA descriptions + +Sometimes, instead of a simple sentence, we want to provide a data table or something more complex as an ARIA description. To do this, use the `customAria` [snippet](https://svelte.dev/docs/svelte/snippet). + +[Read this](https://accessibility.psu.edu/images/charts/) for more information on using screen reader data tables for charts. + +> **Note:** The `customAria` snippet will override the `ariaDescription` and will also hide the text in your graphic from screen readers. + +```svelte + + + + + + {#snippet customAria()} +

+ A shakemap shows the intensity of the 7.2-magnitude earthquake that struck + Haiti at 8:29 a.m. EST, Aug. 14, 2021. +

+ + + + + + + + + + + + + + + +
CityFelt shake strength
Les CayesVery strong
JeremieStrong
+ {/snippet} +
+ + + +``` + + diff --git a/src/components/GraphicBlock/GraphicBlock.stories.svelte b/src/components/GraphicBlock/GraphicBlock.stories.svelte index 6923b855..ef6ad159 100644 --- a/src/components/GraphicBlock/GraphicBlock.stories.svelte +++ b/src/components/GraphicBlock/GraphicBlock.stories.svelte @@ -1,23 +1,10 @@ - - - - - + + + +
+ placeholder +
+
+
+ + + - - - {#snippet title()} -
-
My smaller title
-
- {/snippet} + + +
- placeholder + placeholder
- {#snippet notes()} -