Skip to content

Commit 58eefaa

Browse files
committed
move chrome into separate component
1 parent 48d7c7a commit 58eefaa

File tree

2 files changed

+76
-39
lines changed

2 files changed

+76
-39
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<script>
2+
import { createEventDispatcher } from 'svelte';
3+
import refresh from './refresh.svg';
4+
5+
/** @type {string} */
6+
export let path;
7+
8+
const dispatch = createEventDispatcher();
9+
</script>
10+
11+
<div class="chrome">
12+
<button on:click={() => dispatch('refresh')} aria-label="reload">
13+
<img src={refresh} alt="Reload icon" />
14+
</button>
15+
16+
<input
17+
aria-label="URL"
18+
value={path}
19+
on:change={(e) => {
20+
dispatch('change', { value: e.currentTarget.value });
21+
}}
22+
/>
23+
</div>
24+
25+
<style>
26+
.chrome {
27+
width: 100%;
28+
height: 4rem;
29+
display: flex;
30+
gap: 0.5rem;
31+
padding: 0.4rem;
32+
background: #f9f9f9;
33+
}
34+
35+
.chrome button {
36+
padding: 0.5rem;
37+
}
38+
39+
.chrome button img {
40+
height: 100%;
41+
width: auto;
42+
transition: 0.2s ease-out;
43+
transform: none;
44+
}
45+
46+
.chrome button:active img {
47+
transform: rotate(-180deg);
48+
transition: none;
49+
}
50+
51+
.chrome input {
52+
flex: 1;
53+
padding: 0.5rem 1rem 0.4rem 1rem;
54+
border-radius: 0.5rem;
55+
border: 1px solid rgba(0, 0, 0, 0.1);
56+
box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.1);
57+
font-family: inherit;
58+
font-size: 1.6rem;
59+
}
60+
</style>

src/routes/tutorial/[slug]/index.svelte

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
import SplitPane from '$lib/components/SplitPane.svelte';
1818
import Editor from './_/Editor.svelte';
1919
import Folder from './_/Folder.svelte';
20-
import refresh from './_/refresh.svg';
2120
import { dev } from '$app/env';
2221
import ImageViewer from './_/ImageViewer.svelte';
2322
import Sidebar from './_/Sidebar.svelte';
23+
import Chrome from './_/Chrome.svelte';
2424
2525
/** @type {import('$lib/types').PartStub[]} */
2626
export let index;
@@ -347,7 +347,19 @@
347347
</section>
348348
349349
<section class="preview" slot="b">
350-
<div class="chrome">
350+
<Chrome
351+
{path}
352+
on:refresh={() => {
353+
set_iframe_src('/loading.html');
354+
set_iframe_src(adapter.base + path);
355+
}}
356+
on:change={(e) => {
357+
const url = new URL(e.detail.value, adapter.base);
358+
path = url.pathname + url.search + url.hash;
359+
set_iframe_src(adapter.base + path);
360+
}}
361+
/>
362+
<!-- <div class="chrome">
351363
<button
352364
on:click={() => {
353365
set_iframe_src('/loading.html');
@@ -367,7 +379,7 @@
367379
set_iframe_src(adapter.base + path);
368380
}}
369381
/>
370-
</div>
382+
</div> -->
371383
372384
<iframe bind:this={iframe} title="Output" src="/loading.html" />
373385
</section>
@@ -394,7 +406,7 @@
394406
}
395407
396408
.navigator {
397-
background: #f9f9f9;
409+
background: white;
398410
display: flex;
399411
flex-direction: column;
400412
padding: 1rem;
@@ -427,41 +439,6 @@
427439
flex-direction: column;
428440
}
429441
430-
.chrome {
431-
width: 100%;
432-
height: 4rem;
433-
display: flex;
434-
gap: 0.5rem;
435-
padding: 0.4rem;
436-
background: #f9f9f9;
437-
}
438-
439-
.chrome button {
440-
padding: 0.5rem;
441-
}
442-
443-
.chrome button img {
444-
height: 100%;
445-
width: auto;
446-
transition: 0.2s ease-out;
447-
transform: none;
448-
}
449-
450-
.chrome button:active img {
451-
transform: rotate(-180deg);
452-
transition: none;
453-
}
454-
455-
.chrome input {
456-
flex: 1;
457-
padding: 0.5rem 1rem 0.4rem 1rem;
458-
border-radius: 0.5rem;
459-
border: 1px solid rgba(0, 0, 0, 0.1);
460-
box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.1);
461-
font-family: inherit;
462-
font-size: 1.6rem;
463-
}
464-
465442
iframe {
466443
width: 100%;
467444
height: 100%;

0 commit comments

Comments
 (0)