aotds-docks/src/lib/components/Field.svelte

50 lines
968 B
Svelte
Raw Normal View History

2023-04-20 13:58:52 +00:00
<div class="field label small" class:suffix>
2022-03-01 17:42:33 +00:00
<slot>
2023-04-21 15:17:28 +00:00
<input id={formId} type="text" bind:value on:change />
2022-03-01 17:42:33 +00:00
</slot>
2023-04-20 13:58:52 +00:00
{#if label}
2023-04-21 15:17:28 +00:00
<label for={formId} class:active>{label}</label>
2023-04-20 13:58:52 +00:00
{/if}
2020-07-19 20:21:28 +00:00
</div>
<script>
2023-04-21 15:17:28 +00:00
import { getContext } from "svelte";
2022-03-01 17:42:33 +00:00
export let label = "";
2023-04-20 13:58:52 +00:00
export let value = true;
2023-03-20 20:30:43 +00:00
export let placeholder = label;
2023-04-20 13:58:52 +00:00
export let suffix = false;
2023-04-20 15:54:18 +00:00
export let activeLabel = undefined;
2023-04-21 15:17:28 +00:00
export let idPrefix = "formId";
2023-04-20 15:54:18 +00:00
$: active = typeof activeLabel === "boolean" ? activeLabel : value;
2023-04-21 15:17:28 +00:00
const genUid = getContext("genUid") ?? (() => "genUid missing");
const formId = genUid(idPrefix);
2020-07-19 20:21:28 +00:00
</script>
<style>
2022-03-01 17:42:33 +00:00
div {
font-family: var(--main-font-family);
}
2023-04-20 13:58:52 +00:00
/*
2020-07-28 18:38:40 +00:00
div > :global(*) {
margin-left: 1em;
}
div > label {
margin-left: 0em;
}
2022-03-01 17:42:33 +00:00
label {
2020-07-19 20:21:28 +00:00
font-size: var(--font-scale-8);
2020-07-28 17:26:08 +00:00
font-weight: lighter;
font-family: Dosis;
2022-03-01 17:42:33 +00:00
color: var(--indigo-dye);
}
2023-04-20 13:58:52 +00:00
*/
.field {
margin-bottom: 0px;
}
2020-07-19 20:21:28 +00:00
</style>