about summary refs log tree commit diff
path: root/client/src/lib/components/Form.svelte
diff options
context:
space:
mode:
authorMelonai <einebeere@gmail.com>2021-03-24 09:51:36 +0100
committerMelonai <einebeere@gmail.com>2021-03-24 09:51:36 +0100
commit42860fa15985401825d8d51e73ec497fe5876710 (patch)
treedaa43dd5f4ac77e46dbdd78b1a07811fa5db755c /client/src/lib/components/Form.svelte
parent5dde1f55d818a74e838afa37b0e20217b1549a83 (diff)
downloadshorest-42860fa15985401825d8d51e73ec497fe5876710.tar.zst
shorest-42860fa15985401825d8d51e73ec497fe5876710.zip
Update SvelteKit to public beta
Diffstat (limited to 'client/src/lib/components/Form.svelte')
-rw-r--r--client/src/lib/components/Form.svelte64
1 files changed, 64 insertions, 0 deletions
diff --git a/client/src/lib/components/Form.svelte b/client/src/lib/components/Form.svelte
new file mode 100644
index 0000000..a05e868
--- /dev/null
+++ b/client/src/lib/components/Form.svelte
@@ -0,0 +1,64 @@
+<script lang="ts">
+    import shorten from "$lib/actions/shorten";
+    import { links } from "$lib/data/links";
+    import checkUrl from "$lib/utils/checkUrl";
+    import debounce from "$lib/utils/debounce";
+    import ArrowIcon from "./icons/ArrowIcon.svelte";
+    import CrossIcon from "./icons/CrossIcon.svelte";
+
+    let value = "";
+    let valid = false;
+
+    function submit() {
+        const url = checkUrl(value);
+        if (url !== null) {
+            links.add(shorten(url));
+        }
+    }
+
+    const check = debounce(() => valid = !!checkUrl(value), 100);
+
+    // @ts-ignore: Value is a dependency
+    $: value, check();
+</script>
+
+<style>
+    form {
+        position: relative;
+        border: 1px solid #aaaabb;
+        box-shadow: 0 4px 6px #aaaabb30;
+        box-sizing: border-box;
+        border-radius: 5px;
+    }
+
+    .field {
+        box-sizing: border-box;
+        width: 100%;
+        border: none;
+        padding: 15px 50px 15px 20px;
+        background: transparent;
+        font-size: 1rem;
+    }
+
+    .button {
+        position: absolute;
+        right: 10px;
+        margin: auto;
+        top: 0;
+        bottom: 0;
+        background: transparent;
+        border: none;
+        cursor: pointer;
+    }
+</style>
+
+<form on:submit|preventDefault={submit}>
+    <input class="field" bind:value type="text"/>
+    <button class="button" type="submit">
+        {#if valid}
+            <ArrowIcon/>
+        {:else}
+            <CrossIcon/>
+        {/if}
+    </button>
+</form>