-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from UrbanInstitute/feature-loading-component
Feature: loading wrapper component
- Loading branch information
Showing
8 changed files
with
177 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<script context="module"> | ||
import { onMount } from "svelte"; | ||
import LoadingWrapper from "./LoadingWrapper.svelte"; | ||
import LogoUrbanWide from "../LogoUrbanWide/LogoUrbanWide.svelte"; | ||
import DatawrapperIframe from "../DatawrapperIframe/DatawrapperIframe.svelte"; | ||
export const meta = { | ||
title: "Components/LoadingWrapper", | ||
description: "Wrapper to display a loading spinner graphic while content is loading", | ||
component: LoadingWrapper, | ||
tags: ["autodocs"], | ||
parameters: { | ||
docs: { | ||
description: { | ||
component: | ||
'Wrapper to display a loading spinner graphic while content is loading. Exposes `setChildLoading()` and `setChildLoaded()` to be used by children as an alternative method of setting `isChildLoading` boolean. Accepts an alternative graphic for the "graphic" named slot.' | ||
} | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<script> | ||
import { Story } from "@storybook/addon-svelte-csf"; | ||
// function to create a fake await for 2sec | ||
function sleep(ms) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
// set loading for paragraph examples, sleep for 2.5 sec on mount | ||
$: isChildLoading = true; | ||
onMount(() => { | ||
sleep(2500).then(() => { | ||
isChildLoading = false; | ||
}); | ||
}); | ||
</script> | ||
|
||
<Story name="Default"> | ||
<LoadingWrapper {isChildLoading}> | ||
<span | ||
>Amet est Lorem qui ullamco laboris velit. Incididunt est sunt exercitation qui ea. Officia | ||
Lorem est labore amet irure nostrud. Exercitation Lorem do consectetur enim esse quis mollit | ||
cupidatat aliqua magna. Ipsum irure anim commodo Lorem. | ||
</span> | ||
</LoadingWrapper> | ||
</Story> | ||
|
||
<Story name="Custom graphic"> | ||
<LoadingWrapper {isChildLoading}> | ||
<LogoUrbanWide slot="graphic" /> | ||
<span | ||
>Amet est Lorem qui ullamco laboris velit. Incididunt est sunt exercitation qui ea. Officia | ||
Lorem est labore amet irure nostrud. Exercitation Lorem do consectetur enim esse quis mollit | ||
cupidatat aliqua magna. Ipsum irure anim commodo Lorem. | ||
</span> | ||
</LoadingWrapper> | ||
</Story> | ||
|
||
<Story name="Datawrapper example"> | ||
<LoadingWrapper let:setChildLoading let:setChildLoaded> | ||
<DatawrapperIframe | ||
title="This is a title for the visualization" | ||
ariaLabel="This is an accessible title for the visualization" | ||
datawrapperId="qF5No" | ||
on:startrender={setChildLoading} | ||
on:visrendered={setChildLoaded} | ||
/> | ||
</LoadingWrapper> | ||
</Story> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<script> | ||
import urbanColors from "../utils/urbanColors.js"; | ||
import LogoUrbanAnimated from "../LogoUrbanAnimated/LogoUrbanAnimated.svelte"; | ||
/** | ||
* Boolean indicating whether the child component is loading or not | ||
* @type {boolean} | ||
*/ | ||
export let isChildLoading = true; | ||
/** | ||
* The background color of the loading container (can be null for transparent background) | ||
* @type {string | null} ["white"] | ||
*/ | ||
export let backgroundColor = urbanColors.white; | ||
// define functions to expose that set isChildLoading | ||
let setChildLoaded = () => { | ||
isChildLoading = false; | ||
}; | ||
let setChildLoading = () => { | ||
isChildLoading = true; | ||
}; | ||
</script> | ||
|
||
<div class="container"> | ||
{#if isChildLoading} | ||
<div class="loading" id="loading" style:background-color={backgroundColor}> | ||
<slot name="graphic"> | ||
<LogoUrbanAnimated width={50} duration="1500ms" /> | ||
</slot> | ||
</div> | ||
{/if} | ||
<slot {setChildLoading} {setChildLoaded} /> | ||
</div> | ||
|
||
<style> | ||
.container { | ||
position: relative; | ||
width: 100%; | ||
} | ||
.loading { | ||
/* absolute position */ | ||
left: 0; | ||
position: absolute; | ||
top: 0; | ||
/* take full size */ | ||
height: 100%; | ||
width: 100%; | ||
/* center */ | ||
align-items: center; | ||
display: flex; | ||
justify-content: center; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters