Skip to content

Commit 7280f54

Browse files
committed
#101 Fix issues related to ordering of items
1 parent 83c9b57 commit 7280f54

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

src/lib/components/Facets/ShowMore.svelte

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,47 @@
2828
handleCancel(group.name);
2929
};
3030
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));
3934
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];
4153
};
4254
</script>
4355

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">
4557
<!-- Header -->
4658
<h2 class="text-xl font-semibold">{group.displayName}</h2>
4759

4860
<!-- Items -->
4961
<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(
5163
Object.keys(selected)
52-
)}"
64+
)} grid grid-flow-col gap-x-10 gap-y-2 py-10 px-2 h-full overflow-x-auto"
5365
>
5466
{#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">
5668
<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"
5872
>{selected[key].displayName}</span
5973
>
6074
</label>

0 commit comments

Comments
 (0)