|
28 | 28 | handleCancel(group.name);
|
29 | 29 | };
|
30 | 30 |
|
31 |
| - const maxHeightClass = (items: any[]) => { |
32 |
| - if (items.length >= 50) { |
33 |
| - return 'max-h-[500px]'; |
34 |
| - } else if (items.length >= 30) { |
35 |
| - return 'max-h-[400px]'; |
36 |
| - } else if (items.length >= 20) { |
37 |
| - return 'max-h-[300px]'; |
38 |
| - } |
| 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)); |
39 | 34 |
|
40 |
| - return 'max-h-[200px]'; |
| 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]; |
41 | 53 | };
|
42 | 54 | </script>
|
43 | 55 |
|
44 |
| -<div class="p-5 rounded-md bg-surface-50 dark:bg-surface-800 border-primary-500 border-2"> |
| 56 | +<div class="p-5 rounded-md max-w-6xl bg-surface-50 dark:bg-surface-800 border-primary-500 border-2"> |
45 | 57 | <!-- Header -->
|
46 | 58 | <h2 class="text-xl font-semibold">{group.displayName}</h2>
|
47 | 59 |
|
48 | 60 | <!-- Items -->
|
49 | 61 | <div
|
50 |
| - class="flex flex-wrap flex-col overflow-x-auto !gap-x-20 gap-y-2 py-10 px-2 max-w-6xl h-min {maxHeightClass( |
| 62 | + class="{gridClass( |
51 | 63 | Object.keys(selected)
|
52 |
| - )}" |
| 64 | + )} grid grid-flow-col gap-x-10 gap-y-2 py-10 px-2 h-full overflow-x-auto" |
53 | 65 | >
|
54 | 66 | {#each Object.keys(selected) as key}
|
55 |
| - <label class="flex gap-3 items-center w-52"> |
| 67 | + <label class="flex gap-3 items-center w-48"> |
56 | 68 | <input type="checkbox" class="checkbox" bind:checked={selected[key].selected} />
|
57 |
| - <span title={selected[key].displayName} class="whitespace-nowrap break-before-avoid break-after-avoid truncate" |
| 69 | + <span |
| 70 | + title={selected[key].displayName} |
| 71 | + class="whitespace-nowrap break-before-avoid break-after-avoid truncate" |
58 | 72 | >{selected[key].displayName}</span
|
59 | 73 | >
|
60 | 74 | </label>
|
|
0 commit comments