Make layout responsive

This commit is contained in:
Leonardo Murça 2022-11-11 16:53:42 -03:00
parent ce5601bde2
commit d1f8c094ce
4 changed files with 109 additions and 8 deletions

View file

@ -1,11 +1,24 @@
<script> <script>
import FileViewer from "./lib/FileViewer.svelte"; import FileViewer from "./lib/FileViewer.svelte";
import MediaQuery from "./lib/MediaQuery.svelte";
import logo from "./assets/logo.webp"; import logo from "./assets/logo.webp";
import logoMobile from "./assets/logo-mobile.webp";
</script> </script>
<header> <header>
<a href="/"> <a href="/">
<img src={logo} alt="Embroidery viewer logo." width="460" height="200" /> <MediaQuery query="(min-width: 481px) and (max-width: 812px)" let:matches>
{@const configs = matches
? { src: logoMobile, width: 350, height: 96 }
: { src: logo, width: 460, height: 200 }}
<img
class="logo"
alt="Embroidery viewer logo."
src={configs.src}
width={configs.width}
height={configs.height}
/>
</MediaQuery>
</a> </a>
</header> </header>
<main> <main>
@ -22,11 +35,22 @@
</footer> </footer>
<style> <style>
.logo {
background-image: logo;
}
main { main {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
width: 100%; width: 100%;
box-sizing: border-box; box-sizing: border-box;
padding: 15px;
}
@media only screen and (max-device-width: 812px) {
.logo {
width: 100%;
padding: 20px;
}
} }
</style> </style>

BIN
src/assets/logo-mobile.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -98,13 +98,8 @@
{#if files && files.length !== 0 && filesRendered} {#if files && files.length !== 0 && filesRendered}
<div id="canvas-container" style="width: 100%; heigth: 100vh;"> <div id="canvas-container" style="width: 100%; heigth: 100vh;">
{#each Array.from(files) as file, i} {#each Array.from(files) as file, i}
<div <div class="card-canvas">
style="display: flex; flex-direction: column; justify-content: center; align-items: center; width: 550px; height: 550px; margin-bottom: 15px; border: 2px solid black;" <canvas bind:this={filesRefs[i]} class="canvas" />
>
<canvas
bind:this={filesRefs[i]}
style="height: 80%; width: fit-content;"
/>
<p>{file.name}</p> <p>{file.name}</p>
</div> </div>
{filesRefs[i] && startFileRead(file, filesRefs[i])} {filesRefs[i] && startFileRead(file, filesRefs[i])}
@ -113,6 +108,20 @@
{/if} {/if}
<style> <style>
.canvas {
height: 80%;
width: fit-content;
}
.card-canvas {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 550px;
height: 550px;
margin-bottom: 15px;
border: 2px solid black;
}
input[type="submit"] { input[type="submit"] {
width: 100%; width: 100%;
font-size: 20px; font-size: 20px;
@ -121,6 +130,8 @@
font-weight: 700; font-weight: 700;
color: white; color: white;
padding: 10px; padding: 10px;
-webkit-appearance: none;
border-radius: 0;
} }
input[type="submit"]:hover { input[type="submit"]:hover {
@ -167,4 +178,31 @@
border: 5px dotted #05345f; border: 5px dotted #05345f;
color: #05345f; color: #05345f;
} }
@media only screen and (max-device-width: 812px) {
#form {
width: 100%;
}
#dropzone {
width: 100%;
}
#selected-files-container {
width: 100%;
}
#selected-file-card {
width: 100%;
}
#canvas-container {
width: 100%;
}
.card-canvas {
width: 100%;
height: 400px;
}
}
</style> </style>

39
src/lib/MediaQuery.svelte Normal file
View file

@ -0,0 +1,39 @@
<script>
import { onMount } from "svelte";
export let query;
let mql;
let mqlListener;
let wasMounted = false;
let matches = false;
onMount(() => {
wasMounted = true;
return () => {
removeActiveListener();
};
});
$: {
if (wasMounted) {
removeActiveListener();
addNewListener(query);
}
}
function addNewListener(query) {
mql = window.matchMedia(query);
mqlListener = (v) => (matches = v.matches);
mql.addListener(mqlListener);
matches = mql.matches;
}
function removeActiveListener() {
if (mql && mqlListener) {
mql.removeListener(mqlListener);
}
}
</script>
<slot {matches} />