2024-04-12 13:43:51 +02:00
|
|
|
<script lang="ts">
|
2024-04-12 13:58:35 +02:00
|
|
|
import { Label } from '$lib/components/ui/label';
|
|
|
|
import { Checkbox } from '$lib/components/ui/checkbox';
|
|
|
|
|
2024-04-12 13:43:51 +02:00
|
|
|
import { type LayerTreeType } from '$lib/assets/layers';
|
|
|
|
|
|
|
|
export let name: string;
|
|
|
|
export let node: LayerTreeType;
|
|
|
|
export let multiple: boolean = false;
|
|
|
|
|
|
|
|
export let onValueChange: (id: string, checked: boolean) => void;
|
2024-04-12 13:58:35 +02:00
|
|
|
|
|
|
|
let checked: { [key: string]: boolean } = {};
|
|
|
|
|
|
|
|
if (multiple && Array.isArray(node)) {
|
|
|
|
node.forEach((id) => {
|
|
|
|
checked[id] = false;
|
|
|
|
});
|
|
|
|
}
|
2024-04-12 13:43:51 +02:00
|
|
|
</script>
|
|
|
|
|
2024-04-12 15:12:27 +02:00
|
|
|
<div class="flex flex-col gap-1">
|
2024-04-12 13:43:51 +02:00
|
|
|
{#if Array.isArray(node)}
|
|
|
|
{#each node as id}
|
2024-04-12 15:12:27 +02:00
|
|
|
<div class="flex flex-row items-center gap-2">
|
2024-04-12 13:43:51 +02:00
|
|
|
{#if multiple}
|
2024-04-12 13:58:35 +02:00
|
|
|
<Checkbox
|
2024-04-12 13:43:51 +02:00
|
|
|
{id}
|
|
|
|
{name}
|
|
|
|
value={id}
|
2024-04-12 13:58:35 +02:00
|
|
|
bind:checked={checked[id]}
|
|
|
|
on:click={() => {
|
|
|
|
onValueChange(id, !checked[id]);
|
2024-04-12 13:43:51 +02:00
|
|
|
}}
|
2024-04-12 15:12:27 +02:00
|
|
|
class="scale-90"
|
2024-04-12 13:43:51 +02:00
|
|
|
/>
|
|
|
|
{:else}
|
|
|
|
<input
|
|
|
|
type="radio"
|
|
|
|
{id}
|
|
|
|
{name}
|
|
|
|
value={id}
|
|
|
|
on:change={() => {
|
|
|
|
onValueChange(id, true);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{/if}
|
2024-04-12 13:58:35 +02:00
|
|
|
<Label for={id}>{id}</Label>
|
2024-04-12 13:43:51 +02:00
|
|
|
</div>
|
|
|
|
{/each}
|
|
|
|
{:else}
|
|
|
|
{#each Object.keys(node) as id}
|
2024-04-12 15:12:27 +02:00
|
|
|
<div class="ml-2 flex flex-col gap-1">
|
2024-04-12 13:58:35 +02:00
|
|
|
<Label>{id}</Label>
|
2024-04-12 13:43:51 +02:00
|
|
|
<svelte:self node={node[id]} {name} {multiple} {onValueChange} />
|
|
|
|
</div>
|
|
|
|
{/each}
|
|
|
|
{/if}
|
|
|
|
</div>
|
2024-04-12 15:12:27 +02:00
|
|
|
|
|
|
|
<style lang="postcss">
|
|
|
|
div :global(input[type='radio']) {
|
|
|
|
@apply appearance-none;
|
|
|
|
@apply w-4 h-4;
|
|
|
|
@apply border-[1.5px] border-primary;
|
|
|
|
@apply rounded-full;
|
|
|
|
@apply ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2;
|
|
|
|
@apply cursor-pointer;
|
|
|
|
@apply checked:bg-primary;
|
|
|
|
@apply checked:bg-clip-content;
|
|
|
|
@apply checked:p-0.5;
|
|
|
|
}
|
|
|
|
</style>
|