Skip to content

Commit

Permalink
Merge pull request #6 from twm/layout
Browse files Browse the repository at this point in the history
Vastly improved layout
  • Loading branch information
twm authored Sep 3, 2024
2 parents 8c3b2a9 + 70820b5 commit 73aa390
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 78 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@ To update screenshots, run:
```bash
npx playwright test -u
```

If the screenshots taken in CI don't match you can download the report by running:

```bash
just pr-playwright-report
```
19 changes: 19 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,22 @@ dev:
nvm use || { exit 1; }
set -euxo pipefail
exec npm run dev
pr-playwright-report:
#!/usr/bin/env bash
set -euxo pipefail
commit=$(git rev-parse HEAD)
run_id=$(gh run list --commit "$commit" --limit 1 --json databaseId --jq '.[] | .databaseId')
if [[ -z $run_id ]]; then
printf "Commit %s not found upstream\n" "$commit"
branch=$(git branch --show-current)
run_id=$(gh run list --branch "$branch" --limit 1 --json databaseId --jq '.[] | .databaseId')
fi
if [[ -z $run_id ]]; then
printf "Run for branch %s not found upstream\n" "$branch"
exit 1
fi
printf "Downloading playwright-report for run %s...\n" "$run_id"
target=$(mktemp -d)
gh run download "$run_id" --name playwright-report --dir "$target"
x-www-browser "$target/index.html"
72 changes: 72 additions & 0 deletions src/lib/Form.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<script lang="ts">
import {
artX,
artY,
frameWidth,
stockLength,
material,
MATERIALS,
} from "$lib/stores"
import { frac } from "$lib/frac"
</script>

<h2>Inputs</h2>

<form action="#" method="GET">
<label>
Art width
<input type="number" bind:value={$artX} min="1" step="0.25" required />
</label>
<label>
Art height
<input type="number" bind:value={$artY} min="1" step="0.25" required />
</label>

<label>
Frame width
<input
type="number"
bind:value={$frameWidth}
min="0.25"
step="0.125"
required
/>
</label>

<label>
Material
<select bind:value={$material}>
{#each MATERIALS as material}
<option value={material}>{material.name}</option>
{/each}
</select>
</label>
</form>

<h2>Outputs</h2>

<div class="outputs">
<p class="label">Linear stock <span>{frac($stockLength)}"</span></p>
</div>

<style>
form,
.outputs {
display: grid;
grid-template-columns: 1fr 8rem;
gap: 0.5rem;
}
label,
.label {
display: contents;
}
input,
select {
background: inherit;
color: inherit;
border: 1px solid currentColor;
padding: 1px 4px;
line-height: 1;
}
</style>
32 changes: 32 additions & 0 deletions src/lib/Layout.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="wrapper">
<header>
<h1>Picture Frame Cutlist Calculator</h1>
</header>

<slot></slot>

<footer>
<p>
<!-- TODO a href="/about">About</a> ☙ -->
© 2024 Tom Most ❧
<a href="https://github.com/twm/halo/issues">Report an issue</a>
</p>
</footer>
</div>

<style>
.wrapper {
margin: 0 auto;
padding: 0 0.5rem;
max-width: 80rem;
}
footer {
color: #aaa;
text-align: center;
}
footer :is(:link, :visited) {
color: inherit;
}
</style>
8 changes: 0 additions & 8 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@
<link rel="stylesheet" type="text/css" href={normalizeCss} />
</svelte:head>

<h1>Picture Frame Calculator</h1>

<slot></slot>

<p>
© 2024 Tom Most ☙
<a href="https://github.com/twm/halo/issues">Report an issue</a>
</p>

<style>
@font-face {
font-family: "Zilla Slab";
Expand All @@ -35,6 +28,5 @@
400 1rem / 1.2 "Zilla Slab",
"URW Bookman",
serif;
padding: 0 0.5rem; /* TODO: extract layout as a component.*/
}
</style>
106 changes: 44 additions & 62 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,82 +1,64 @@
<script lang="ts">
import {
artX,
artY,
frameWidth,
stockLength,
material,
MATERIALS,
} from "$lib/stores"
import Layout from "$lib/Layout.svelte"
import Frame from "$lib/Frame.svelte"
import Form from "$lib/Form.svelte"
import PartList from "$lib/PartList.svelte"
import TextureDefs from "$lib/textures/TextureDefs.svelte"
import { frac } from "$lib/frac"
</script>

<svelte:head>
<title>Picture Frame Calculator</title>
<title>Picture Frame Cutlist Calculator</title>
</svelte:head>

<TextureDefs />

<div class="layout">
<Frame />
<div class="right">
<form action="#" method="GET">
<label>
Art width
<input type="number" bind:value={$artX} min="1" step="0.25" required />
</label>
<label>
Art height
<input type="number" bind:value={$artY} min="1" step="0.25" required />
</label>

<label>
Frame width
<input
type="number"
bind:value={$frameWidth}
min="0.25"
step="0.125"
required
/>
</label>

<label>
Material
<select bind:value={$material}>
{#each MATERIALS as material}
<option value={material}>{material.name}</option>
{/each}
</select>
</label>
</form>

<div class="results">
<h2>Materials</h2>

<p>Stock required: {frac($stockLength)}"</p>

<PartList />
</div>
<Layout>
<div class="container">
<main>
<div class="form">
<Form />
</div>
<div class="frame">
<Frame />
</div>
<div class="parts">
<PartList />
</div>
</main>
</div>
</div>
</Layout>

<style>
.layout {
.container {
container-type: inline-size;
}
main {
display: grid;
grid-template-columns: 1fr 20rem;
gap: 1rem;
column-gap: 1rem;
grid-template-areas: "form frame parts";
grid-template-columns: 20rem 1fr 20rem;
}
@container (width < 50rem) and (width >= 40rem) {
main {
grid-template-areas: "form frame" "parts frame";
grid-template-columns: 20rem 1fr;
}
}
@container (width < 40rem) {
main {
grid-template-areas: "form" "frame" "parts";
grid-template-columns: 1fr;
grid-template-rows: min-content 70vh min-content;
}
}
form {
display: grid;
grid-template-columns: 1fr 8rem;
gap: 0.5rem;
.form {
grid-area: form;
}
.frame {
grid-area: frame;
}
label {
display: contents;
.parts {
grid-area: parts;
}
</style>
8 changes: 6 additions & 2 deletions tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import { expect, test } from "@playwright/test"

test("calculator layout", async ({ page }) => {
await page.goto("/")
const title = "Picture Frame Calculator"
const title = "Picture Frame Cutlist Calculator"
await expect(page.locator("h1")).toHaveText(title)
await expect(page).toHaveTitle(title)
await expect(page).toHaveScreenshot()
await expect(page).toHaveScreenshot({
scale: "device",
// The <select> tag doesn't render consistently locally versus on GHA, so mask it away.
mask: [page.locator("select")],
})
})
4 changes: 2 additions & 2 deletions tests/test.ts-snapshots/calculator-layout-1-Desktop-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/test.ts-snapshots/calculator-layout-1-Phone-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests/test.ts-snapshots/calculator-layout-1-Tablet-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 73aa390

Please sign in to comment.