From a640703f2da8815dc26ad1600a6f206be1624379 Mon Sep 17 00:00:00 2001
From: ivarlovlie <git@ivarlovlie.no>
Date: Wed, 1 Jun 2022 22:10:32 +0200
Subject: feat: Initial after clean slate

---
 .../web-shared/src/components/form/textarea.svelte | 48 ++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 apps/web-shared/src/components/form/textarea.svelte

(limited to 'apps/web-shared/src/components/form/textarea.svelte')

diff --git a/apps/web-shared/src/components/form/textarea.svelte b/apps/web-shared/src/components/form/textarea.svelte
new file mode 100644
index 0000000..b313d2e
--- /dev/null
+++ b/apps/web-shared/src/components/form/textarea.svelte
@@ -0,0 +1,48 @@
+<script lang="ts">
+    export let id;
+    export let disabled = false;
+    export let loading = false;
+    export let rows = 2;
+    export let cols = 0;
+    export let name;
+    export let placeholder;
+    export let value;
+    export let label;
+    export let errorText;
+
+    $: shared_props = {
+        rows: rows || null,
+        cols: cols || null,
+        name: name || null,
+        id: id || null,
+        disabled: disabled || null,
+        class: [`form-control ${loading ? "c-disabled loading" : ""}`, $$restProps.class ?? ""].filter(Boolean).join(" "),
+    };
+
+    let textarea;
+    let scrollHeight = 0;
+
+    $:if (textarea) {
+        scrollHeight = textarea.scrollHeight;
+    }
+
+    function on_input(event) {
+        event.target.style.height = "auto";
+        event.target.style.height = (this.scrollHeight) + "px";
+    }
+</script>
+
+{#if label}
+    <label for="{id}"
+           class="form-label margin-bottom-xxs">{label}</label>
+{/if}
+<textarea {...shared_props}
+          {placeholder}
+          style="overflow-y:hidden;min-height:calc(1.5em + .75rem + 2px);{scrollHeight ? 'height:{scrollHeight}px' : ''};"
+          bind:value={value}
+          bind:this={textarea}
+          on:input={on_input}
+></textarea>
+{#if errorText}
+    <small class="color-error">{errorText}</small>
+{/if}
-- 
cgit v1.3

