|
1 | 1 | <script context="module" lang="ts">
|
| 2 | + import AddField from "./AddField.svelte"; |
| 3 | + import PivotChip from "./PivotChip.svelte"; |
2 | 4 | import { dndzone } from "svelte-dnd-action";
|
3 | 5 | import { flip } from "svelte/animate";
|
4 | 6 | import { createEventDispatcher } from "svelte";
|
5 | 7 | import type { PivotChipData } from "./types";
|
6 | 8 | import { PivotChipType } from "./types";
|
7 |
| - import PivotChip from "./PivotChip.svelte"; |
8 | 9 | import type { TimeGrain } from "@rilldata/web-common/lib/time/types";
|
9 | 10 | </script>
|
10 | 11 |
|
11 | 12 | <script lang="ts">
|
12 | 13 | export let items: PivotChipData[] = [];
|
13 |
| - export let style: "vertical" | "horizontal" = "vertical"; |
14 |
| - export let removable = false; |
| 14 | + export let placeholder: string | null = null; |
| 15 | + export let type: "rows" | "columns" | null = null; |
| 16 | +
|
| 17 | + const removable = Boolean(type); |
| 18 | + const horizontal = Boolean(type); |
15 | 19 |
|
16 | 20 | const dispatch = createEventDispatcher();
|
17 | 21 | const flipDurationMs = 200;
|
18 | 22 |
|
19 |
| - let listClasses: string; |
20 |
| -
|
21 |
| - $: if (style === "horizontal") { |
22 |
| - listClasses = "flex flex-row bg-slate-50 w-full p-2 gap-x-2 h-10"; |
23 |
| - } else { |
24 |
| - listClasses = "flex flex-col gap-y-2 py-2"; |
25 |
| - } |
26 |
| -
|
27 | 23 | function handleConsider(e: CustomEvent<{ items: PivotChipData[] }>) {
|
28 | 24 | items = e.detail.items;
|
29 | 25 | }
|
|
49 | 45 | </script>
|
50 | 46 |
|
51 | 47 | <div
|
52 |
| - class="{listClasses} rounded-sm" |
| 48 | + class="container" |
| 49 | + class:horizontal |
53 | 50 | use:dndzone={{ items, flipDurationMs }}
|
54 | 51 | on:consider={handleConsider}
|
55 | 52 | on:finalize={handleFinalize}
|
56 | 53 | >
|
| 54 | + {#if !items.length && placeholder} |
| 55 | + <p class="text-gray-500">{placeholder}</p> |
| 56 | + {/if} |
57 | 57 | {#each items as item (item.id)}
|
58 | 58 | <div class="item" animate:flip={{ duration: flipDurationMs }}>
|
59 | 59 | <PivotChip
|
|
69 | 69 | />
|
70 | 70 | </div>
|
71 | 71 | {/each}
|
| 72 | + {#if removable} |
| 73 | + <AddField {type} /> |
| 74 | + {/if} |
72 | 75 | </div>
|
73 | 76 |
|
74 | 77 | <style type="postcss">
|
75 | 78 | .item {
|
76 | 79 | @apply text-center h-6;
|
77 | 80 | }
|
78 | 81 |
|
| 82 | + .container { |
| 83 | + @apply flex flex-col gap-y-2 py-2 rounded-sm; |
| 84 | + } |
| 85 | +
|
| 86 | + .horizontal { |
| 87 | + @apply flex flex-row bg-slate-50 w-full p-2 gap-x-2 h-10; |
| 88 | + @apply items-center; |
| 89 | + } |
| 90 | +
|
79 | 91 | div {
|
80 | 92 | outline: none !important;
|
81 | 93 | }
|
|
0 commit comments