File tree Expand file tree Collapse file tree 3 files changed +25
-4
lines changed
Expand file tree Collapse file tree 3 files changed +25
-4
lines changed Original file line number Diff line number Diff line change 11<script context =" module" >
22 import { defineMeta } from ' @storybook/addon-svelte-csf' ;
33 import DesignTokens from ' ../DesignTokens/DesignTokens.svelte' ;
4-
4+ import { expect } from ' @storybook/test ' ;
55 import ChartHeader from ' ./ChartHeader.svelte' ;
66
77 const { Story } = defineMeta ({
1010 });
1111 </script >
1212
13- <Story name =" Default" >
13+ <Story
14+ name =" Default"
15+ play ={async ({ step }) => {
16+ await step (' Container has ID attribute derived from title prop' , async () => {
17+ const containerEl = document .querySelector (' #mehr-uber-60-jahrige-in-allen-berufen' );
18+ expect (containerEl ).toBeTruthy ();
19+ });
20+ }}
21+ >
1422 <DesignTokens >
1523 <ChartHeader
1624 title =" Mehr über-60-Jährige in allen Berufen"
Original file line number Diff line number Diff line change 11<script lang =" ts" >
22 import type { Snippet } from ' svelte' ;
3-
3+ import slugify from " ../utils/slugify.ts"
4+
45 interface ChartHeaderProps {
56 title: string ;
67 subtitle? : string ;
910 let { title, subtitle, children }: ChartHeaderProps = $props ();
1011 </script >
1112
12- <header class =" container" >
13+ <header class ="container" id ={ slugify ( title )} >
1314 <h2 class ="title" >{title }</h2 >
1415 {#if subtitle }
1516 <p class ="subtitle" >{subtitle }</p >
Original file line number Diff line number Diff line change 1+ // Source: https://svelte.dev/playground/b130be5e485441a1842ae97e4ce4f244?version=5.20.0
2+
3+ export default function slugify ( str : string ) : string {
4+ return str
5+ . replace ( / \s + / g, '-' )
6+ . replace ( / - + / g, '-' )
7+ . trim ( )
8+ . normalize ( 'NFKD' )
9+ . replace ( / [ \u0300 - \u036f ] / g, '' )
10+ . toLowerCase ( )
11+ . replace ( / [ ^ a - z 0 - 9 - ] / g, '' )
12+ }
You can’t perform that action at this time.
0 commit comments