feat: popover close icon

This commit is contained in:
Ayo 2023-07-25 22:41:49 +02:00 committed by Ayo Ayco
parent d794633ed5
commit 8339b2b4ea
2 changed files with 86 additions and 30 deletions

View file

@ -1,67 +1,95 @@
--- ---
import Icon from 'astro-iconify'; import Icon from "astro-iconify";
import SettingsPopover from './SettingsPopover.astro'; import SettingsPopover from "./SettingsPopover.astro";
export interface Props { export interface Props {
url: string | null; url: string | null;
} }
const placeholder = 'Type the article URL here'; const placeholder = "Type the article URL here";
const { url } = Astro.props; const { url } = Astro.props;
--- ---
<div class="address-bar"> <div class="address-bar">
<form> <form>
<button aria-label="Back" class="btn left-buttons" type="button" id="app-back" name="app-back" onclick="history.go(-1); return false;" hidden> <button
aria-label="Back"
class="btn left-buttons"
type="button"
id="app-back"
name="app-back"
onclick="history.go(-1); return false;"
hidden
>
<Icon name="ic:round-arrow-back-ios" /> <Icon name="ic:round-arrow-back-ios" />
</button> </button>
<input type="url" id="app-url" name="url" value={url ?? ''} placeholder={placeholder} required /> <input
<button aria-label="Submit" class="btn right-buttons" type="submit" id="submit"> type="url"
id="app-url"
name="url"
value={url ?? ""}
placeholder={placeholder}
required
/>
<button
aria-label="Submit"
class="btn right-buttons"
type="submit"
id="submit"
>
<Icon name="ri:ai-generate" /> <Icon name="ri:ai-generate" />
</button> </button>
<a aria-label="Home" class="btn right-buttons" type="button" id="app-home" href="/" hidden> <a
aria-label="Home"
class="btn right-buttons"
type="button"
id="app-home"
href="/"
hidden
>
<Icon name="mdi:home" /> <Icon name="mdi:home" />
</a> </a>
<div aria-label="Settings" class="btn right-buttons"> <div aria-label="Settings" class="btn right-buttons">
<input type="checkbox" id="settings-toggle" hidden> <input type="checkbox" id="settings-toggle" hidden />
<label for="settings-toggle"><Icon name="mdi:cog" /></label> <label for="settings-toggle"><Icon name="mdi:cog" /></label>
</div> </div>
</form> </form>
<SettingsPopover toggle="settings-toggle" />
</div> </div>
<SettingsPopover toggleId="settings-toggle" />
<script> <script>
const backLink = document.querySelector<HTMLButtonElement>('#app-back'); const backLink = document.querySelector<HTMLButtonElement>("#app-back");
const submitBtn = document.querySelector<HTMLButtonElement>('#submit'); const submitBtn = document.querySelector<HTMLButtonElement>("#submit");
const urlInput = document.querySelector<HTMLInputElement>('#app-url'); const urlInput = document.querySelector<HTMLInputElement>("#app-url");
// if js is enabled, show the back button and github link // if js is enabled, show the back button and github link
backLink?.removeAttribute('hidden'); backLink?.removeAttribute("hidden");
if (urlInput?.value === '') { if (urlInput?.value === "") {
backLink?.setAttribute('disabled', 'true'); backLink?.setAttribute("disabled", "true");
submitBtn?.setAttribute('disabled', 'true'); submitBtn?.setAttribute("disabled", "true");
} }
urlInput?.addEventListener('input', (e) => { urlInput?.addEventListener("input", (e) => {
const target = e.target as HTMLInputElement; const target = e.target as HTMLInputElement;
if (target.value === '') { if (target.value === "") {
submitBtn?.setAttribute('disabled', 'true'); submitBtn?.setAttribute("disabled", "true");
} else { } else {
submitBtn?.removeAttribute('disabled'); submitBtn?.removeAttribute("disabled");
} }
}); });
const toggle = document.querySelector<HTMLInputElement>('#settings-toggle'); document
console.log(toggle); .getElementById("settings-toggle")
toggle?.addEventListener('change', e => console.log(e.currentTarget?.['checked'])); ?.addEventListener("change", (e) =>
console.log(e.currentTarget?.["checked"])
);
</script> </script>
<style lang="scss"> <style lang="scss">
.address-bar { .address-bar {
text-align: center;
width: 100%; width: 100%;
position: relative;
} }
form { form {

View file

@ -1,13 +1,41 @@
--- ---
import Icon from "astro-iconify";
export interface Props { export interface Props {
toggleId: string; toggle: string;
} }
const { toggleId } = Astro.props;
const { toggle } = Astro.props;
--- ---
<form hidden> <form id="settings-form">
<label for={toggle}>
<Icon name="mdi:close" />
</label>
<div class="field"> <div class="field">
<input type="checkbox" id="settings-1" name="settings-1" checked /> <input type="checkbox" id="settings-1" name="settings-1" checked />
<label for="settings-1">Option 1</label> <label for="settings-1">Option 1</label>
</div> </div>
</form> </form>
<style lang="scss">
#settings-form {
border: 1px solid #ccc;
border-radius: 5px;
background-color: white;
padding: 1em;
width: 300px;
position: absolute;
top: 0.5em;
right: 0.5em;
box-shadow: 0 1px 3px 1px #eee;
svg {
width: 24px;
height: 24px;
position: absolute;
top: 0.5em;
right: 0.5em;
cursor: pointer;
}
}
</style>