Who are we?
What is Svelte?
Why and how do we use it?
Sharon Funke
Manuel Roth
Philip Küng
Roman Karavia
Toolbox Q
Component framework like Vue, React
Vue
Svelte
Requirements for our custom elements
Work efficiently on projects that are completed within a few weeks
Decent page/visualization load performance
Integration with CSS of embedding page
Limit dependency on embedding page
(e.g. Javascript-Framework)
2-3 different versions depending on embedding width
Embedding page: The page that contains the custom element
Dynamic height depending on content
Content is not always a rectangle
(e.g. scrollytelling, popover)
Share resources (fonts, CSS) with embedding page
Content of iframes is loaded last
<style>
.switch-container {
display: flex;
justify-content: center;
}
</style>
<div class="switch-container">
<div class="s-input-switch s-input-switch--secondary">
<input
type="checkbox"
bind:checked={onlySwingStates} />
<label>alle Staaten</label>
<label>nur «Swing States»</label>
</div>
</div>.switch-container.svelte-fv6lk3 {
display: flex;
justify-content: center;
}<svg viewBox={viewBox}>
{#each getHexagons(onlySwingStates)
as { color, width, type, x, y }}
<Hexagon
{color}
{width}
{type}
{x}
{y} />
{/each}
</svg>
<div bind:clientWidth={containerWidth}>
<svg viewBox={viewBox}>
{#each getHexagons(onlySwingStates, containerWidth)
as { color, width, type, x, y }}
<Hexagon
{color}
{width}
{type}
{x}
{y} />
{/each}
</svg>
</div>Interactive visual element thanks to input/width bindings and reactive updates
Custom CSS + style guide
Compressed Javascript bundle size: 30 KiB
No Javascript-dependency on embedding page
See full example on nzz.ch/visuals
👩💻
📊