2026-04-17 18:01:24 +03:00
< script module >
import { defineMeta } from '@storybook/addon-svelte-csf' ;
import FontApplicator from './FontApplicator.svelte' ;
const { Story } = defineMeta ({
title : 'Entities/FontApplicator' ,
component : FontApplicator ,
tags : [ 'autodocs' ],
parameters : {
docs : {
description : {
component :
2026-06-01 12:06:30 +03:00
'Applies a font to its children based on the supplied load `status`. Renders the skeleton (or system font) until status is `loaded`/`error`, then reveals the font. The status is provided by the composing widget — the component does not read the lifecycle store itself.' ,
2026-04-17 18:01:24 +03:00
},
story : { inline : false },
},
layout : 'centered' ,
},
argTypes : {
2026-06-01 12:06:30 +03:00
status : { control : 'select' , options : [ 'loading' , 'loaded' , 'error' ] },
2026-04-17 18:01:24 +03:00
},
});
</ script >
< script lang = "ts" >
2026-05-31 14:08:25 +03:00
import { mockUnifiedFont } from '$entities/Font/testing' ;
2026-04-17 18:01:24 +03:00
import type { ComponentProps } from 'svelte' ;
const fontUnknown = mockUnifiedFont ({ id : 'nonexistent-font-xk92z' , name : 'Nonexistent Font Xk92z' });
const fontArial = mockUnifiedFont ({ id : 'arial' , name : 'Arial' });
const fontArialBold = mockUnifiedFont ({ id : 'arial-bold' , name : 'Arial' });
</ script >
< Story
name = "Loading State"
parameters = {{
docs : {
description : {
story :
2026-06-01 12:06:30 +03:00
'Status is `loading`: the font file has not resolved yet, so children render in the skeleton (or system font) fallback rather than the target font.' ,
2026-04-17 18:01:24 +03:00
},
},
}}
2026-06-01 12:06:30 +03:00
args= {{ font : fontUnknown , status : 'loading' }}
2026-04-17 18:01:24 +03:00
>
{ # snippet template ( args : ComponentProps < typeof FontApplicator >)}
< FontApplicator {... args }>
< p class = "text-xl" > The quick brown fox jumps over the lazy dog</ p >
</ FontApplicator >
{ /snippet }
</ Story >
< Story
name = "Loaded State"
parameters = {{
docs : {
description : {
story :
2026-06-01 12:06:30 +03:00
'Status is `loaded`: the component reveals the font, applying it to its children (Arial here, available in all browsers).' ,
2026-04-17 18:01:24 +03:00
},
},
}}
2026-06-01 12:06:30 +03:00
args= {{ font : fontArial , status : 'loaded' }}
2026-04-17 18:01:24 +03:00
>
{ # snippet template ( args : ComponentProps < typeof FontApplicator >)}
< FontApplicator {... args }>
< p class = "text-xl" > The quick brown fox jumps over the lazy dog</ p >
</ FontApplicator >
{ /snippet }
</ Story >
< Story
2026-06-01 12:06:30 +03:00
name = "Error State"
2026-04-17 18:01:24 +03:00
parameters = {{
docs : {
description : {
story :
2026-06-01 12:06:30 +03:00
'Status is `error`: the font failed to load. The component still reveals (it treats `error` like `loaded` for reveal purposes) so children are not stuck behind the skeleton — they fall back to the system font.' ,
2026-04-17 18:01:24 +03:00
},
},
}}
2026-06-01 12:06:30 +03:00
args= {{ font : fontArialBold , status : 'error' }}
2026-04-17 18:01:24 +03:00
>
{ # snippet template ( args : ComponentProps < typeof FontApplicator >)}
< FontApplicator {... args }>
< p class = "text-xl" > The quick brown fox jumps over the lazy dog</ p >
</ FontApplicator >
{ /snippet }
</ Story >