use shadcn in layer control
This commit is contained in:
parent
02bfc3b07b
commit
f38d5b7a75
1 changed files with 17 additions and 6 deletions
|
@ -1,4 +1,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { Label } from '$lib/components/ui/label';
|
||||||
|
import { Checkbox } from '$lib/components/ui/checkbox';
|
||||||
|
|
||||||
import { type LayerTreeType } from '$lib/assets/layers';
|
import { type LayerTreeType } from '$lib/assets/layers';
|
||||||
|
|
||||||
export let name: string;
|
export let name: string;
|
||||||
|
@ -6,6 +9,14 @@
|
||||||
export let multiple: boolean = false;
|
export let multiple: boolean = false;
|
||||||
|
|
||||||
export let onValueChange: (id: string, checked: boolean) => void;
|
export let onValueChange: (id: string, checked: boolean) => void;
|
||||||
|
|
||||||
|
let checked: { [key: string]: boolean } = {};
|
||||||
|
|
||||||
|
if (multiple && Array.isArray(node)) {
|
||||||
|
node.forEach((id) => {
|
||||||
|
checked[id] = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
|
@ -13,13 +24,13 @@
|
||||||
{#each node as id}
|
{#each node as id}
|
||||||
<div>
|
<div>
|
||||||
{#if multiple}
|
{#if multiple}
|
||||||
<input
|
<Checkbox
|
||||||
type="checkbox"
|
|
||||||
{id}
|
{id}
|
||||||
{name}
|
{name}
|
||||||
value={id}
|
value={id}
|
||||||
on:change={(e) => {
|
bind:checked={checked[id]}
|
||||||
onValueChange(id, e.target.checked);
|
on:click={() => {
|
||||||
|
onValueChange(id, !checked[id]);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{:else}
|
{:else}
|
||||||
|
@ -33,13 +44,13 @@
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
<label for={id}>{id}</label>
|
<Label for={id}>{id}</Label>
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
{:else}
|
{:else}
|
||||||
{#each Object.keys(node) as id}
|
{#each Object.keys(node) as id}
|
||||||
<div class="ml-2">
|
<div class="ml-2">
|
||||||
<span>{id}</span>
|
<Label>{id}</Label>
|
||||||
<svelte:self node={node[id]} {name} {multiple} {onValueChange} />
|
<svelte:self node={node[id]} {name} {multiple} {onValueChange} />
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
Loading…
Reference in a new issue