Skip to content

Commit

Permalink
better
Browse files Browse the repository at this point in the history
  • Loading branch information
seigler committed Apr 13, 2024
1 parent bd73627 commit 9dd1560
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 26 deletions.
20 changes: 20 additions & 0 deletions src/components/Drawer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useSignal } from "@preact/signals";
import { PropsWithChildren } from "preact/compat";

type DrawerProps = PropsWithChildren<{}>;

export default function Drawer({ children }: DrawerProps) {
const isOpen = useSignal(false);
return (
<div class="drawer" data-open={isOpen}>
<button
onClick={() => {
isOpen.value = !isOpen.value;
}}
>
{isOpen.value ? "Hide 🞃" : "Expand 🞁"}
</button>
{isOpen.value && children}
</div>
);
}
7 changes: 5 additions & 2 deletions src/components/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ReadingBox from "./ReadingBox";
import Reference from "./Reference";
import FontPicker from "./FontPicker";
import DualText from "./DualText";
import Drawer from "./Drawer";

export default function Main() {
useEffect(() => {
Expand All @@ -28,12 +29,14 @@ export default function Main() {
</header>
<main>
<div class="content">
<FontPicker />
<ReadingBox />
</div>
</main>
<footer>
<Reference />
<Drawer>
<FontPicker />
<Reference />
</Drawer>
</footer>
</>
);
Expand Down
56 changes: 32 additions & 24 deletions src/components/ReadingBox.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useSignal } from "@preact/signals";
import localforage from "localforage";
import { useEffect } from "preact/hooks";
import { useEffect, useRef } from "preact/hooks";
import DualText from "./DualText";

export default function ReadingBox() {
const isEditing = useSignal(false);
const editModalRef = useRef<HTMLDialogElement>(null);
const contents =
useSignal(`It is a period of civil war. Rebel spaceships, striking from a hidden base, have won their first victory against the evil Galactic Empire.
Expand All @@ -25,32 +25,40 @@ Pursued by the Empire's sinister agents, Princess Leia races home aboard her sta
}, []);
return (
<div class="readingbox">
<span>
<label>
Edit{" "}
<input
type="checkbox"
id="edit-toggle"
selected={isEditing}
<dialog ref={editModalRef} title="Update text">
<div className="edit-modal-contents">
<h2>Update text</h2>
<textarea
autofocus
class="readingbox-textarea"
id="reading-material"
value={contents}
onChange={(event) => {
isEditing.value = event.currentTarget.checked;
const newValue = event.currentTarget.value;
contents.value = newValue;
localforage.setItem("aurebesh-text", newValue);
}}
spellCheck={false}
/>
</label>
</span>
{isEditing.value && (
<textarea
class="readingbox-textarea"
id="reading-material"
value={contents}
onChange={(event) => {
const newValue = event.currentTarget.value;
contents.value = newValue;
localforage.setItem("aurebesh-text", newValue);
<button
onClick={() => {
editModalRef.current?.close();
}}
>
Save
</button>
</div>
</dialog>

<div>
<button
onClick={() => {
editModalRef.current?.showModal();
}}
spellCheck={false}
/>
)}
>
Edit
</button>
</div>
<div class="readingbox-text aurebesh">
<DualText text={contents.value} hover />
</div>
Expand Down
57 changes: 57 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
--color-text-light: #0009;
--color-background1: #eed;
--color-background2: #bba;
--color-backdrop: #eed3;
--color-accent1: #900;
--color-accent2: #b50;
--font-aurebesh: Droidobesh;
Expand Down Expand Up @@ -115,6 +116,38 @@ input[type="checkbox"] {
width: 0.75em;
}

.visually-hidden {
clip: rect(0 0 0 0);
clip-path: inset(50%);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}

.buttonlike {
appearance: button;
}

dialog {
position: fixed;
inset: 0;
z-index: 4;
background-color: var(--color-background2);
border: 1px solid var(--color-background1);
padding: 1rem;
}
dialog::backdrop {
position: fixed;
inset: 0;
width: "100%";
height: "100%";
z-index: 3;
background-color: var(--color-backdrop);
backdrop-filter: blur(10px);
}

#app {
flex-grow: 1;
display: flex;
Expand Down Expand Up @@ -142,9 +175,23 @@ h1 {
--color-text-light: #fff9;
--color-background1: #111;
--color-background2: #333;
--color-backdrop: #1113;
}
}

.edit-modal-contents {
display: flex;
flex-direction: column;
justify-content: center;
width: 30rem;
max-width: 90vw;
max-height: 90vh;
}
.edit-modal-contents textarea {
flex-shrink: 1;
height: 40rem;
}

.dualtext-word {
position: relative;
display: inline-block;
Expand Down Expand Up @@ -255,3 +302,13 @@ main {
transform: translateX(-50%) translateY(0%);
opacity: 1;
}

footer {
width: "100%";
}
.drawer {
width: "100%";
display: flex;
flex-direction: column;
align-items: stretch;
}

0 comments on commit 9dd1560

Please sign in to comment.