Extract cards to external component

This commit is contained in:
Leonardo Murça 2022-11-18 11:48:00 -03:00
parent d204618acd
commit 46c3fe3354
2 changed files with 43 additions and 31 deletions

41
src/lib/CanvasCard.svelte Normal file
View file

@ -0,0 +1,41 @@
<script>
import { startFileRead } from "../utils/main";
export let files = [];
let canvasRefs = [];
</script>
{#each Array.from(files) as file, i}
<div class="container">
<canvas bind:this={canvasRefs[i]} class="canvas" />
<p>{file.name}</p>
</div>
{canvasRefs[i] && startFileRead(file, canvasRefs[i])}
{/each}
<style>
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 550px;
height: 550px;
margin-bottom: 15px;
padding: 10px;
border: 2px solid black;
}
.canvas {
height: 80%;
width: 100%;
object-fit: contain;
}
@media only screen and (max-device-width: 812px) {
.container {
width: 100%;
height: 400px;
}
}
</style>

View file

@ -1,9 +1,8 @@
<script> <script>
import { startFileRead } from "../utils/main"; import CanvasCard from "./CanvasCard.svelte";
let files; let files;
let filesRendered = false; let filesRendered = false;
let filesRefs = [];
const acceptedFiles = [".pes"]; const acceptedFiles = [".pes"];
const maxFileSize = 700000; const maxFileSize = 700000;
@ -17,7 +16,6 @@
const onChange = (evt) => { const onChange = (evt) => {
files = null; files = null;
filesRefs = [];
filesRendered = false; filesRendered = false;
const changedFiles = evt.dataTransfer const changedFiles = evt.dataTransfer
@ -97,33 +95,11 @@
{#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} <CanvasCard {files} />
<div class="card-canvas">
<canvas bind:this={filesRefs[i]} class="canvas" />
<p>{file.name}</p>
</div>
{filesRefs[i] && startFileRead(file, filesRefs[i])}
{/each}
</div> </div>
{/if} {/if}
<style> <style>
.canvas {
height: 80%;
width: 100%;
object-fit: contain;
}
.card-canvas {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 550px;
height: 550px;
margin-bottom: 15px;
padding: 10px;
border: 2px solid black;
}
input[type="submit"] { input[type="submit"] {
width: 100%; width: 100%;
font-size: 20px; font-size: 20px;
@ -201,10 +177,5 @@
#canvas-container { #canvas-container {
width: 100%; width: 100%;
} }
.card-canvas {
width: 100%;
height: 400px;
}
} }
</style> </style>