Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: input tweaks and FieldSwitcher component #6017

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions web-common/src/components/forms/FieldSwitcher.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<script lang="ts">
export let fields: string[];
export let selected: number = -1;
export let onClick: (i: number, value: string) => void = () => {};
</script>

<div class="option-wrapper">
{#each fields as field, i (field)}
<button
on:click={() => onClick(i, field)}
class="-ml-[1px] first-of-type:-ml-0 px-2 border border-gray-300 first-of-type:rounded-l-[2px] last-of-type:rounded-r-[2px]"
class:selected={selected === i}
>
{field}
</button>
{/each}
</div>

<style lang="postcss">
button {
@apply capitalize;
}

.option-wrapper {
@apply flex h-6 text-sm w-fit mb-1 rounded-[2px];
}

.option-wrapper > .selected {
@apply border-primary-500 z-50 text-primary-500;
}
</style>
23 changes: 2 additions & 21 deletions web-common/src/components/forms/Input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { slide } from "svelte/transition";
import Select from "./Select.svelte";
import InputLabel from "./InputLabel.svelte";
import FieldSwitcher from "./FieldSwitcher.svelte";

const voidFunction = () => {};

Expand Down Expand Up @@ -97,19 +98,7 @@
{/if}

{#if fields && fields?.length > 1}
<div class="option-wrapper">
{#each fields as field, i (field)}
<button
on:click={() => {
selected = i;
}}
class="-ml-[1px] first-of-type:-ml-0 px-2 border border-gray-300 first-of-type:rounded-l-[2px] last-of-type:rounded-r-[2px]"
class:selected={selected === i}
>
{field}
</button>
{/each}
</div>
<FieldSwitcher {fields} {selected} />
{/if}

{#if !options}
Expand Down Expand Up @@ -218,10 +207,6 @@
@apply flex flex-col gap-y-1 h-fit justify-center;
}

.option-wrapper {
@apply flex h-6 text-sm w-fit mb-1 rounded-[2px];
}

.sm {
height: 24px;
}
Expand Down Expand Up @@ -282,8 +267,4 @@
.toggle:active {
@apply bg-primary-100;
}

.option-wrapper > .selected {
@apply border-primary-500 z-50 text-primary-500;
}
</style>
2 changes: 1 addition & 1 deletion web-common/src/components/forms/InputLabel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</script>

<div class="label-wrapper">
<label for={id} class="line-clamp-1">
<label for={id} class="line-clamp-1 capitalize">
{label}
{#if optional}
<span class="text-gray-500 text-[12px] font-normal">(optional)</span>
Expand Down
Loading