-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
453 additions
and
313 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<script> | ||
export let container; | ||
</script> | ||
|
||
<div class="row"> | ||
<div class="id">{container.containerNumber}</div> | ||
<div class="shipname">{container.nameOfShip}</div> | ||
<div class="date">{container.dateContainerShipped}</div> | ||
<div class="size">{container.containerSize}</div> | ||
</div> | ||
|
||
<style> | ||
.row { | ||
display: flex; | ||
background-color: #eee; | ||
} | ||
.id, | ||
.shipname, | ||
.size, | ||
.date { | ||
margin: 5px; | ||
} | ||
.id { | ||
font-weight: bold; | ||
flex: 1; | ||
} | ||
.size { | ||
text-align: right; | ||
flex: 0 0 50px; | ||
} | ||
.date { | ||
flex: 0 0 100px; | ||
text-align: center; | ||
} | ||
.shipname { | ||
flex: 1; | ||
color: #999; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<script> | ||
import ContainerSummaryRow from './ContainerSummaryRow.svelte'; | ||
export let containers = []; | ||
export let onContainerClicked = () => {}; | ||
</script> | ||
|
||
<h3>A PseudoTable Component</h3> | ||
|
||
<p>This is an example of Svelte containers, NOT the best way to create a simple table. It probably should be done in the ContainerTable component so that it it is easy to add callbacks for people clicking the shipname or id or...</p> | ||
|
||
<p>Notice that tab order is set correctly with the index into the container object.</p> | ||
{#each containers as container, ix} | ||
<div | ||
role="button" | ||
tabindex={ix+1} | ||
on:keydown={(e) => e.key === 'Enter' && onContainerClicked(container, e)} | ||
on:click={(e) => onContainerClicked(container, e)}> | ||
|
||
<div class=row> | ||
<ContainerSummaryRow {container}/> | ||
</div> | ||
</div> | ||
{/each} | ||
|
||
<style> | ||
.row { | ||
margin: 5px; | ||
border: 1px solid black; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
import {database_handle} from '$lib/server/database'; | ||
|
||
let db; | ||
|
||
export async function load() { | ||
if (!db) { | ||
db = database_handle(); | ||
} | ||
const sql = ` | ||
SELECT | ||
containerNumber, | ||
nameOfShip, | ||
containerSize, | ||
dateContainerShipped | ||
FROM | ||
containers`; | ||
const stmt = db.prepare(sql); | ||
const rows = stmt.all(); | ||
|
||
console.log({rows}); | ||
|
||
return { containers: rows }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<script> | ||
import ContainerTable from '$lib/ContainerTable.svelte'; | ||
export let data; | ||
let clickedContainerNumber = "none" | ||
function containerClicked(container) { | ||
console.log('Container clicked:', container.containerNumber); | ||
if (container) { | ||
clickedContainerNumber = container.containerNumber | ||
} | ||
} | ||
</script> | ||
|
||
<h1>Leaning into Svelte's approach: Components for UI elements</h1> | ||
|
||
<ContainerTable containers={data.containers} onContainerClicked={containerClicked} /> | ||
|
||
<span class=i>Last container clicked: {clickedContainerNumber}</span> |