make tutorial mobile-friendly

pull/2383/head
Richard Harris 6 years ago
parent 648bd176c5
commit b96715f812

@ -0,0 +1,37 @@
<script>
export let offset = 0;
</script>
<style>
.toggle {
width: 100%;
height: 42px;
display: flex;
justify-content: center;
align-items: center;
border-top: 1px solid var(--second);
}
button {
padding: 0.3em 0.6em;
border-radius: 1em;
line-height: 1;
height: 1em;
box-sizing: content-box;
color: #999;
border: 1px solid #f4f4f4;
width: 4em;
margin: 0 0.15em;
}
.selected {
background-color: var(--prime);
color: white;
}
</style>
<div class="toggle">
<button class:selected={offset === 0} on:click={() => offset = 0}>tutorial</button>
<button class:selected={offset === 1} on:click={() => offset = 1}>input</button>
<button class:selected={offset === 2} on:click={() => offset = 2}>output</button>
</div>

@ -15,6 +15,7 @@
<script>
import TableOfContents from './_components/TableOfContents.svelte';
import ScreenToggle from './_components/ScreenToggle.svelte';
import Icon from '../../../components/Icon.svelte';
import Repl from '@sveltejs/svelte-repl';
import { getContext } from 'svelte';
@ -29,6 +30,9 @@
let scrollable;
const lookup = new Map();
let width = process.browser ? window.innerWidth : 1000;
let offset = 0;
sections.forEach(section => {
section.chapters.forEach(chapter => {
const obj = {
@ -70,6 +74,8 @@
});
}
$: mobile = width < 768;
function reset() {
repl.update({
components: chapter.app_a.map(clone)
@ -110,11 +116,27 @@
padding: 0;
/* margin: 0 calc(var(--side-nav) * -1); */
box-sizing: border-box;
}
.viewport {
width: 100%;
height: 100%;
display: grid;
grid-template-columns: minmax(33.333%, 480px) auto;
grid-auto-rows: 100%;
}
.mobile .viewport {
width: 300%;
height: calc(100% - 42px);
grid-template-columns: 33.333% 66.666%;
transition: transform 0.3s;
}
.mobile .offset-1 { transform: translate(-33.333%, 0); }
.mobile .offset-2 { transform: translate(-66.666%, 0); }
.tutorial-text {
display: flex;
flex-direction: column;
@ -215,44 +237,53 @@
<title>{selected.section.title} / {selected.chapter.title} • Svelte Tutorial</title>
</svelte:head>
<div class="tutorial-outer">
<div class="tutorial-text">
<div class="table-of-contents">
<TableOfContents {sections} {slug} {selected}/>
</div>
<svelte:window bind:innerWidth={width}/>
<div class="chapter-markup" bind:this={scrollable}>
{@html chapter.html}
<div class="controls">
{#if chapter.app_b}
<!-- TODO disable this button when the contents of the REPL
matches the expected end result -->
<button class="show" on:click="{() => completed ? reset() : complete()}">
{completed ? 'Reset' : 'Show me'}
</button>
{/if}
{#if selected.next}
<a class="next" href="tutorial/{selected.next.slug}">Next <Icon name="arrow-right" /></a>
{/if}
<div class="tutorial-outer" class:mobile>
<div class="viewport offset-{offset}">
<div class="tutorial-text">
<div class="table-of-contents">
<TableOfContents {sections} {slug} {selected}/>
</div>
<div class="improve-chapter">
<a href={improve_link}><Icon name="edit" size={14}/> Edit this chapter</a>
<div class="chapter-markup" bind:this={scrollable}>
{@html chapter.html}
<div class="controls">
{#if chapter.app_b}
<!-- TODO disable this button when the contents of the REPL
matches the expected end result -->
<button class="show" on:click="{() => completed ? reset() : complete()}">
{completed ? 'Reset' : 'Show me'}
</button>
{/if}
{#if selected.next}
<a class="next" href="tutorial/{selected.next.slug}">Next <Icon name="arrow-right" /></a>
{/if}
</div>
<div class="improve-chapter">
<a href={improve_link}><Icon name="edit" size={14}/> Edit this chapter</a>
</div>
</div>
</div>
</div>
<div class="tutorial-repl">
<Repl
bind:this={repl}
{svelteUrl}
{rollupUrl}
orientation="rows"
on:change={handle_change}
setup={mapbox_setup}
relaxed
/>
<div class="tutorial-repl">
<Repl
bind:this={repl}
{svelteUrl}
{rollupUrl}
orientation={mobile ? 'columns' : 'rows'}
fixed={mobile}
on:change={handle_change}
setup={mapbox_setup}
relaxed
/>
</div>
</div>
{#if mobile}
<ScreenToggle bind:offset/>
{/if}
</div>

Loading…
Cancel
Save