Skip to content

Commit 4ceb021

Browse files
authored
Merge pull request #107 from BEXIS2/table
Table
2 parents c2e622d + 159956a commit 4ceb021

File tree

5 files changed

+69
-58
lines changed

5 files changed

+69
-58
lines changed

src/lib/components/Facets/ShowMore.svelte

Lines changed: 35 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
export let handleApply: (group: SelectedFacetGroup) => {};
66
export let handleCancel: (groupName: string) => {};
77
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 }), {});
912
1013
const selectAll = () => {
1114
Object.keys(selected).forEach((key) => (selected[key].selected = true));
@@ -23,67 +26,44 @@
2326
};
2427
2528
const onCancel = () => {
26-
console.log(selected, group.children);
2729
selected = structuredClone(group.children);
2830
handleCancel(group.name);
2931
};
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-
};
5432
</script>
5533

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>
5941

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>
7755

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>
8767
</div>
8868
</div>
8969
</div>

src/lib/components/Table/ColumnsMenu.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
title="Hide or show columns"
1818
class="btn btn-sm variant-filled-primary rounded-full order-last"
1919
aria-label="Open menu to hide/show columns"
20+
title="Open menu to hide/show columns"
2021
use:popup={popupCombobox}>Columns</button
2122
>
2223

@@ -28,10 +29,11 @@
2829
<div class="flex gap-3 items-center">
2930
<label for={column.id} class="cursor-pointer" title={column.label}></label>
3031
<input
31-
aria-label="Toggle column visibility for column {column.label}"
32+
aria-label={`${column.visible ? 'Hide' : 'Show'} ${column.label} column`}
3233
type="checkbox"
3334
id = {column.id}
3435
bind:checked={column.visible}
36+
title={`${column.visible ? 'Hide' : 'Show'} ${column.label} column`}
3537
disabled={columns.filter((c) => c.visible).length === 1 && column.visible}
3638
/>
3739
<span>{column.label}</span>

src/lib/components/Table/TableContent.svelte

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,15 @@
405405
title="Search within all table rows"
406406
bind:value={searchValue}
407407
placeholder="Search rows..."
408+
title="Search rows"
408409
id="{tableId}-search"
409410
/><button
410411
type="reset"
411412
title="Clear search"
412413
id="{tableId}-searchReset"
413414
class="absolute right-3 items-center"
414415
aria-label="Clear search"
416+
title="Clear search"
415417
on:click|preventDefault={() => {
416418
if (serverSide && !sendModel) {
417419
throw new Error('Server-side configuration is missing');
@@ -429,6 +431,7 @@
429431
title="Search"
430432
id="{tableId}-searchSubmit"
431433
class="btn variant-filled-primary"
434+
title="Search"
432435
on:click|preventDefault={() => {
433436
if (serverSide && !sendModel) {
434437
throw new Error('Server-side configuration is missing');
@@ -457,6 +460,10 @@
457460
size="sm"
458461
checked={fitToScreen}
459462
id="{tableId}-toggle"
463+
title={fitToScreen ? 'Fit table data to screen' : `Don't fit table data to screen`}
464+
aria-label={fitToScreen
465+
? 'Fit table data to screen'
466+
: `Don't fit table data to screen`}
460467
on:change={() => (fitToScreen = !fitToScreen)}>Fit to screen</SlideToggle
461468
>
462469
{/if}
@@ -468,6 +475,7 @@
468475
type="button"
469476
title="Reset column and row sizing"
470477
class="btn btn-sm variant-filled-primary rounded-full order-last"
478+
title="Reset sizing of columns and rows"
471479
on:click|preventDefault={() =>
472480
resetResize($headerRows, $pageRows, tableId, columns, resizable)}
473481
>Reset sizing</button
@@ -478,6 +486,7 @@
478486
type="button"
479487
title="Export table data as CSV"
480488
class="btn btn-sm variant-filled-primary rounded-full order-last"
489+
title="Export table data as CSV"
481490
on:click|preventDefault={() => exportAsCsv(tableId, $exportedData)}
482491
>Export as CSV</button
483492
>
@@ -526,6 +535,11 @@
526535
class:cursor-pointer={!props.sort.disabled}
527536
on:click={props.sort.toggle}
528537
on:keydown={props.sort.toggle}
538+
title={props.sort.order === 'asc'
539+
? `Sort by ${cell.label} column in descending order`
540+
: props.sort.order === 'desc'
541+
? `Remove sorting by ${cell.label} column`
542+
: `Sort by ${cell.label} column in ascending order`}
529543
>
530544
{cell.render()}
531545
</span>

src/lib/components/Table/TableFilter.svelte

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@
240240
type="button"
241241
use:popup={popupFeatured}
242242
id="{popupId}-button"
243-
aria-label="Open filter menu for column {id}"
243+
aria-label="Open filter menu for {id} column"
244+
title="Open filter menu for {id} column"
244245
>
245246
<Fa icon={faFilter} size="12" />
246247
</button>
@@ -251,6 +252,7 @@
251252
class="btn variant-filled-primary btn-sm"
252253
type="button"
253254
aria-label="Clear Filters"
255+
title="Clear Filters"
254256
on:click|preventDefault={() => {
255257
// Set the defaults when cleared
256258
clearFilters();
@@ -269,13 +271,15 @@
269271
<select
270272
class="select border border-primary-500 text-sm p-1"
271273
aria-label="Show rows with value that"
274+
title="Show rows with value that"
272275
on:change={(e) => optionChangeHandler(e, index)}
273276
bind:value={dropdown.option}
274277
>
275278
{#each options[type] as option (option)}
276279
<option
277280
value={option.value}
278281
aria-label={option.label}
282+
title={option.label}
279283
selected={dropdown.option === option.value}
280284
disabled={Object.keys($filters[id]).includes(option.value) &&
281285
dropdown.option !== option.value}>{option.label}</option
@@ -288,6 +292,7 @@
288292
tabindex="0"
289293
class="btn variant-filled-warning btn-sm h-full"
290294
aria-label="Remove filter"
295+
title="Remove filter"
291296
on:click|preventDefault={() => removeFilter(dropdown.option)}
292297
on:keydown|preventDefault={() => removeFilter(dropdown.option)}
293298
>
@@ -303,6 +308,7 @@
303308
on:input={(e) => valueChangeHandler(e, index)}
304309
bind:value={dropdown.value}
305310
aria-label="Filter value"
311+
title="Filter value"
306312
/>
307313
{:else}
308314
<input
@@ -311,6 +317,7 @@
311317
on:input={(e) => valueChangeHandler(e, index)}
312318
bind:value={dropdown.formValue}
313319
aria-label="Filter value"
320+
title="Filter value"
314321
/>
315322
{/if}
316323
</div>
@@ -332,6 +339,7 @@
332339
addFilter(remainingFilters[0].value, undefined);
333340
}}
334341
aria-label="Add filter"
342+
title="Add filter"
335343
>
336344
<div class="flex gap-1 items-center"><Fa icon={faPlus} />Add Filter</div>
337345
</div>
@@ -340,6 +348,7 @@
340348
class="btn variant-filled-primary btn-sm"
341349
type="button"
342350
aria-label="Apply filters"
351+
title="Apply filters"
343352
on:click|preventDefault={() => {
344353
$pageIndex = 0;
345354
$filterValue = $filters[id];

src/lib/components/Table/TablePagination.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
</select> -->
6464

6565
<button
66-
aria-label="Open menu to select number of items per page"
66+
aria-label="Open menu to select number of items to display per page"
67+
title="Open menu to select number of items to display per page"
6768
class="btn variant-filled-primary w-20 justify-between"
6869
use:popup={pageSizePopup}
6970
>
@@ -87,6 +88,7 @@
8788
class="btn btn-sm variant-filled-primary"
8889
on:click|preventDefault={goToFirstPage}
8990
aria-label="Go to first page"
91+
title="Go to first page"
9092
disabled={goToFirstPageDisabled}
9193
id="{id}-first"
9294
>
@@ -96,6 +98,7 @@
9698
class="btn btn-sm variant-filled-primary"
9799
id="{id}-previous"
98100
aria-label="Go to previous page"
101+
title="Go to previous page"
99102
on:click|preventDefault={goToPreviousPage}
100103
disabled={goToPreviousPageDisabled}><Fa icon={faAngleLeft} /></button
101104
>
@@ -105,19 +108,22 @@
105108
value={$pageIndex + 1}
106109
max={$pageCount}
107110
aria-label="Current page"
111+
title="Current page"
108112
min={1}
109113
on:change={handleChange}
110114
/>
111115
<button
112116
class="btn btn-sm variant-filled-primary"
113117
id="{id}-next"
114118
aria-label="Go to next page"
119+
title="Go to next page"
115120
on:click|preventDefault={goToNextPage}
116121
disabled={goToNextPageDisabled}><Fa icon={faAngleRight} /></button
117122
>
118123
<button
119124
class="btn btn-sm variant-filled-primary"
120125
aria-label="Go to last page"
126+
title="Go to last page"
121127
id="{id}-last"
122128
on:click|preventDefault={goToLastPage}
123129
disabled={goToLastPageDisabled}><Fa icon={faAnglesRight} /></button

0 commit comments

Comments
 (0)