@invopop/popui 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/BaseTable.svelte
CHANGED
|
@@ -4,6 +4,7 @@ import { createEventDispatcher } from "svelte";
|
|
|
4
4
|
import BaseCounter from "./BaseCounter.svelte";
|
|
5
5
|
import BaseTableRow from "./BaseTableRow.svelte";
|
|
6
6
|
import BaseTableCell from "./BaseTableCell.svelte";
|
|
7
|
+
import InputCheckbox from "./InputCheckbox.svelte";
|
|
7
8
|
const dispatch = createEventDispatcher();
|
|
8
9
|
const callback = (entry) => {
|
|
9
10
|
if (entry.intersectionRatio && entry.isIntersecting) {
|
|
@@ -21,6 +22,9 @@ export let groupLabel = void 0;
|
|
|
21
22
|
export let disableRowClick = false;
|
|
22
23
|
export let hideCounter = false;
|
|
23
24
|
export let freeWrap = false;
|
|
25
|
+
export let selectable = false;
|
|
26
|
+
export let selectedRows = [];
|
|
27
|
+
export let selectedTrackedBy = "id";
|
|
24
28
|
$:
|
|
25
29
|
groupedData = groupData(data);
|
|
26
30
|
$:
|
|
@@ -40,6 +44,12 @@ function groupData(rows) {
|
|
|
40
44
|
});
|
|
41
45
|
return groups;
|
|
42
46
|
}
|
|
47
|
+
function toggleAllSelected(selected) {
|
|
48
|
+
selectedRows = [];
|
|
49
|
+
if (!selected)
|
|
50
|
+
return;
|
|
51
|
+
selectedRows = data;
|
|
52
|
+
}
|
|
43
53
|
</script>
|
|
44
54
|
|
|
45
55
|
<svelte:window
|
|
@@ -55,6 +65,16 @@ function groupData(rows) {
|
|
|
55
65
|
<table class="hidden md:table w-full rounded-md">
|
|
56
66
|
<thead>
|
|
57
67
|
<tr class="border-b border-neutral-100 relative">
|
|
68
|
+
{#if selectable}
|
|
69
|
+
<!-- if table is selectable we need to add an extra header with a checkbox -->
|
|
70
|
+
<th scope="col" class="bg-white sticky top-0 z-10 rounded-tr-md pl-1.5">
|
|
71
|
+
<InputCheckbox
|
|
72
|
+
on:change={(event) => {
|
|
73
|
+
toggleAllSelected(event.detail)
|
|
74
|
+
}}
|
|
75
|
+
/>
|
|
76
|
+
</th>
|
|
77
|
+
{/if}
|
|
58
78
|
{#each fields as field, i (i)}
|
|
59
79
|
<BaseTableHeader
|
|
60
80
|
isFirst={i === 0}
|
|
@@ -94,6 +114,9 @@ function groupData(rows) {
|
|
|
94
114
|
{getActions}
|
|
95
115
|
{disableRowClick}
|
|
96
116
|
{freeWrap}
|
|
117
|
+
{selectable}
|
|
118
|
+
{selectedRows}
|
|
119
|
+
{selectedTrackedBy}
|
|
97
120
|
on:click={() => {
|
|
98
121
|
if (disableRowClick) return
|
|
99
122
|
|
|
@@ -106,6 +129,15 @@ function groupData(rows) {
|
|
|
106
129
|
on:contextmenu={() => {
|
|
107
130
|
dispatch('rowRightClick', row)
|
|
108
131
|
}}
|
|
132
|
+
on:checked={(event) => {
|
|
133
|
+
if (event.detail) {
|
|
134
|
+
selectedRows = [...selectedRows, row]
|
|
135
|
+
} else {
|
|
136
|
+
selectedRows = selectedRows.filter(
|
|
137
|
+
(r) => r[selectedTrackedBy] !== row[selectedTrackedBy]
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
}}
|
|
109
141
|
on:action
|
|
110
142
|
on:copied
|
|
111
143
|
/>
|
|
@@ -11,6 +11,9 @@ declare const __propDef: {
|
|
|
11
11
|
disableRowClick?: boolean | undefined;
|
|
12
12
|
hideCounter?: boolean | undefined;
|
|
13
13
|
freeWrap?: boolean | undefined;
|
|
14
|
+
selectable?: boolean | undefined;
|
|
15
|
+
selectedRows?: TableDataRow[] | undefined;
|
|
16
|
+
selectedTrackedBy?: string | undefined;
|
|
14
17
|
};
|
|
15
18
|
events: {
|
|
16
19
|
orderBy: CustomEvent<any>;
|
package/dist/BaseTableRow.svelte
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script>import { createEventDispatcher } from "svelte";
|
|
2
2
|
import BaseTableActions from "./BaseTableActions.svelte";
|
|
3
3
|
import BaseTableCell from "./BaseTableCell.svelte";
|
|
4
|
+
import InputCheckbox from "./InputCheckbox.svelte";
|
|
4
5
|
const dispatch = createEventDispatcher();
|
|
5
6
|
let actionsDropdown;
|
|
6
7
|
export let row;
|
|
@@ -8,8 +9,18 @@ export let getActions = void 0;
|
|
|
8
9
|
export let fields = [];
|
|
9
10
|
export let disableRowClick = false;
|
|
10
11
|
export let freeWrap = false;
|
|
12
|
+
export let selectable = false;
|
|
13
|
+
export let selectedTrackedBy = "id";
|
|
14
|
+
export let selectedRows = [];
|
|
11
15
|
$:
|
|
12
16
|
actions = getActions instanceof Function ? getActions(row) : [];
|
|
17
|
+
$:
|
|
18
|
+
checked = !!selectedRows.find((r) => {
|
|
19
|
+
const field = r[selectedTrackedBy];
|
|
20
|
+
if (field === void 0)
|
|
21
|
+
return false;
|
|
22
|
+
return field === row[selectedTrackedBy];
|
|
23
|
+
});
|
|
13
24
|
</script>
|
|
14
25
|
|
|
15
26
|
<tr
|
|
@@ -22,6 +33,16 @@ $:
|
|
|
22
33
|
actionsDropdown.toggle()
|
|
23
34
|
}}
|
|
24
35
|
>
|
|
36
|
+
{#if selectable}
|
|
37
|
+
<td class="pl-1.5">
|
|
38
|
+
<InputCheckbox
|
|
39
|
+
{checked}
|
|
40
|
+
on:change={(event) => {
|
|
41
|
+
dispatch('checked', event.detail)
|
|
42
|
+
}}
|
|
43
|
+
/>
|
|
44
|
+
</td>
|
|
45
|
+
{/if}
|
|
25
46
|
{#each fields as field, i (i)}
|
|
26
47
|
<BaseTableCell
|
|
27
48
|
currentIndex={i}
|
|
@@ -7,10 +7,14 @@ declare const __propDef: {
|
|
|
7
7
|
fields?: TableField[] | undefined;
|
|
8
8
|
disableRowClick?: boolean | undefined;
|
|
9
9
|
freeWrap?: boolean | undefined;
|
|
10
|
+
selectable?: boolean | undefined;
|
|
11
|
+
selectedTrackedBy?: string | undefined;
|
|
12
|
+
selectedRows?: TableDataRow[] | undefined;
|
|
10
13
|
};
|
|
11
14
|
events: {
|
|
12
15
|
click: MouseEvent;
|
|
13
16
|
copied: CustomEvent<any>;
|
|
17
|
+
checked: CustomEvent<any>;
|
|
14
18
|
action: CustomEvent<any>;
|
|
15
19
|
} & {
|
|
16
20
|
[evt: string]: CustomEvent<any>;
|