|
5 | 5 | export let handleApply: (group: SelectedFacetGroup) => {}; |
6 | 6 | export let handleCancel: (groupName: string) => {}; |
7 | 7 |
|
8 | | - let selected = structuredClone(group.children); |
| 8 | + let selected = Object.keys(group.children) |
| 9 | + .sort((a, b) => group.children[a].displayName.localeCompare(group.children[b].displayName)) |
| 10 | + .map((key) => ({ [key]: { ...group.children[key] } })) |
| 11 | + .reduce((acc, val) => ({ ...acc, ...val }), {}); |
9 | 12 |
|
10 | 13 | const selectAll = () => { |
11 | 14 | Object.keys(selected).forEach((key) => (selected[key].selected = true)); |
|
23 | 26 | }; |
24 | 27 |
|
25 | 28 | const onCancel = () => { |
26 | | - console.log(selected, group.children); |
27 | 29 | selected = structuredClone(group.children); |
28 | 30 | handleCancel(group.name); |
29 | 31 | }; |
30 | | -
|
31 | | - const gridClass = (items: any[]) => { |
32 | | - const ceil = Math.ceil(Math.sqrt(items.length)); |
33 | | - const max = Math.max(ceil, Math.floor(items.length / 3)); |
34 | | -
|
35 | | - const classes = [ |
36 | | - 'grid-rows-1', |
37 | | - 'grid-rows-2', |
38 | | - 'grid-rows-3', |
39 | | - 'grid-rows-4', |
40 | | - 'grid-rows-5', |
41 | | - 'grid-rows-6', |
42 | | - 'grid-rows-7', |
43 | | - 'grid-rows-8', |
44 | | - 'grid-rows-9', |
45 | | - 'grid-rows-10', |
46 | | - 'grid-rows-11', |
47 | | - 'grid-rows-12' |
48 | | - ]; |
49 | | -
|
50 | | - if (max > 12) { |
51 | | - return 'grid-rows-12'; |
52 | | - } else return classes[max - 1 || 1]; |
53 | | - }; |
54 | 32 | </script> |
55 | 33 |
|
56 | | -<div class="p-5 rounded-md max-w-6xl bg-surface-50 dark:bg-surface-800 border-primary-500 border-2"> |
57 | | - <!-- Header --> |
58 | | - <h2 class="text-xl font-semibold">{group.displayName}</h2> |
| 34 | +<div class="w-full flex justify-center max-w-[800px]"> |
| 35 | + <div class="grow max-h-[500px]"> |
| 36 | + <div |
| 37 | + class="p-5 rounded-md w-full bg-surface-50 dark:bg-surface-800 border-primary-500 border-2" |
| 38 | + > |
| 39 | + <!-- Header --> |
| 40 | + <h2 class="text-xl font-semibold">{group.displayName}</h2> |
59 | 41 |
|
60 | | - <!-- Items --> |
61 | | - <div |
62 | | - class="{gridClass( |
63 | | - Object.keys(selected) |
64 | | - )} grid grid-flow-col gap-x-10 gap-y-2 py-10 px-2 h-full overflow-x-auto" |
65 | | - > |
66 | | - {#each Object.keys(selected) as key} |
67 | | - <label class="flex gap-3 items-center w-48"> |
68 | | - <input type="checkbox" class="checkbox" bind:checked={selected[key].selected} /> |
69 | | - <span |
70 | | - title={selected[key].displayName} |
71 | | - class="whitespace-nowrap break-before-avoid break-after-avoid truncate" |
72 | | - >{selected[key].displayName}</span |
73 | | - > |
74 | | - </label> |
75 | | - {/each} |
76 | | - </div> |
| 42 | + <!-- Items --> |
| 43 | + <div class="gap-x-10 space-y-2 py-6 px-[2px] max-h-[500px] columns-[192px] overflow-auto min-h"> |
| 44 | + {#each Object.keys(selected) as key} |
| 45 | + <label class="flex gap-3 items-center w-48"> |
| 46 | + <input type="checkbox" class="checkbox" bind:checked={selected[key].selected} /> |
| 47 | + <span |
| 48 | + title={selected[key].displayName} |
| 49 | + class="whitespace-nowrap break-before-avoid break-after-avoid truncate" |
| 50 | + >{selected[key].displayName}</span |
| 51 | + > |
| 52 | + </label> |
| 53 | + {/each} |
| 54 | + </div> |
77 | 55 |
|
78 | | - <!-- Footer --> |
79 | | - <div class="flex w-full justify-between gap-5"> |
80 | | - <div class="flex gap-3"> |
81 | | - <button class="btn btn-sm variant-filled-tertiary" on:click={selectNone}>None</button> |
82 | | - <button class="btn btn-sm variant-filled-tertiary" on:click={selectAll}>All</button> |
83 | | - </div> |
84 | | - <div class="flex gap-3"> |
85 | | - <button class="btn btn-sm variant-filled-primary" on:click={onApply}>Apply</button> |
86 | | - <button class="btn btn-sm variant-filled-secondary" on:click={onCancel}>Cancel</button> |
| 56 | + <!-- Footer --> |
| 57 | + <div class="flex w-full justify-between gap-5"> |
| 58 | + <div class="flex gap-3"> |
| 59 | + <button class="btn btn-sm variant-filled-tertiary" on:click={selectNone}>None</button> |
| 60 | + <button class="btn btn-sm variant-filled-tertiary" on:click={selectAll}>All</button> |
| 61 | + </div> |
| 62 | + <div class="flex gap-3"> |
| 63 | + <button class="btn btn-sm variant-filled-primary" on:click={onApply}>Apply</button> |
| 64 | + <button class="btn btn-sm variant-filled-secondary" on:click={onCancel}>Cancel</button> |
| 65 | + </div> |
| 66 | + </div> |
87 | 67 | </div> |
88 | 68 | </div> |
89 | 69 | </div> |
0 commit comments