@serkonda7/solid-components 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/README.md +2 -2
- package/dist/data-table.d.ts +8 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +94 -60
- package/dist/styles.css +16 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @serkonda7/solid-components
|
|
2
2
|
[![CI][ci-badge]][ci-status]
|
|
3
3
|
[![npm version][npm-badge]][npm-link]
|
|
4
|
-
[![npm updated][npm-date-badge]][npm-link]
|
|
4
|
+
[![npm updated and downloads][npm-date-dl-badge]][npm-link]
|
|
5
5
|
|
|
6
6
|
Reusable components for [SolidJS](https://www.solidjs.com/).
|
|
7
7
|
|
|
@@ -37,5 +37,5 @@ This repo is licensed under the [MIT License](LICENSE.txt).
|
|
|
37
37
|
[ci-badge]: https://github.com/serkonda7/solid-components/actions/workflows/ci.yml/badge.svg
|
|
38
38
|
[ci-status]: https://github.com/serkonda7/solid-components/actions/workflows/ci.yml
|
|
39
39
|
[npm-badge]: https://nodei.co/npm/@serkonda7/solid-components.png?style=shields&data=v&color=blue
|
|
40
|
-
[npm-date-badge]: https://nodei.co/npm/@serkonda7/solid-components.png?style=shields&data=u&color=blue
|
|
40
|
+
[npm-date-dl-badge]: https://nodei.co/npm/@serkonda7/solid-components.png?style=shields&data=u,d&color=blue
|
|
41
41
|
[npm-link]: https://www.npmjs.com/package/@serkonda7/solid-components
|
package/dist/data-table.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import type { Accessor, JSX } from 'solid-js';
|
|
2
2
|
export type DataTableSortDirection = 'asc' | 'desc';
|
|
3
|
+
export interface DataTableSort {
|
|
4
|
+
key: string;
|
|
5
|
+
direction: DataTableSortDirection;
|
|
6
|
+
}
|
|
3
7
|
export interface DataTableColumn<TRow> {
|
|
4
8
|
key: string;
|
|
5
9
|
label: string;
|
|
6
10
|
sortable?: boolean;
|
|
11
|
+
sortValue?: (row: TRow) => unknown;
|
|
7
12
|
class?: string;
|
|
8
13
|
ariaLabel?: string;
|
|
9
14
|
getValue?: (row: TRow) => JSX.Element;
|
|
@@ -23,7 +28,10 @@ export interface DataTableProps<TRow> {
|
|
|
23
28
|
selectionLabel?: string;
|
|
24
29
|
sortKey?: string | Accessor<string | undefined>;
|
|
25
30
|
sortDirection?: DataTableSortDirection | Accessor<DataTableSortDirection>;
|
|
31
|
+
defaultSort?: DataTableSort;
|
|
26
32
|
onSort?: (key: string) => void;
|
|
33
|
+
onSortClear?: () => void;
|
|
34
|
+
onSortChange?: (sort: DataTableSort | undefined) => void;
|
|
27
35
|
visibleColumns?: string[] | Accessor<string[]>;
|
|
28
36
|
defaultVisibleColumns?: string[];
|
|
29
37
|
onVisibleColumnsChange?: (visibleKeys: string[]) => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* Add components here as they are implemented so consumers can import them
|
|
5
5
|
* from the package root.
|
|
6
6
|
*/
|
|
7
|
-
export { DataTable, type DataTableColumn, type DataTableProps, type DataTableSortDirection, } from './data-table';
|
|
7
|
+
export { DataTable, type DataTableColumn, type DataTableProps, type DataTableSort, type DataTableSortDirection, } from './data-table';
|
package/dist/index.js
CHANGED
|
@@ -1,36 +1,60 @@
|
|
|
1
1
|
import { className as e, createComponent as t, delegateEvents as n, effect as r, insert as i, memo as a, setAttribute as o, template as s, use as c } from "solid-js/web";
|
|
2
2
|
import { For as l, Show as u, createEffect as d, createMemo as f, createSignal as p, createUniqueId as m, onCleanup as h } from "solid-js";
|
|
3
3
|
//#region src/data-table.tsx
|
|
4
|
-
var g = /*#__PURE__*/ s("<div role=dialog class=data-table-customizer-panel><p class=data-table-customizer-title></p><ul class=data-table-customizer-list></ul><div class=data-table-customizer-actions><button type=button></button><button type=button>"),
|
|
5
|
-
function
|
|
4
|
+
var g = /*#__PURE__*/ s("<div role=dialog class=data-table-customizer-panel><p class=data-table-customizer-title></p><ul class=data-table-customizer-list></ul><div class=data-table-customizer-actions><button type=button></button><button type=button>"), ee = /*#__PURE__*/ s("<div class=data-table-toolbar><div class=data-table-customizer><button type=button class=data-table-customizer-button aria-haspopup=dialog><span aria-hidden=true>⚙</span> "), _ = /*#__PURE__*/ s("<th class=data-table-checkbox><span class=data-table-visually-hidden>Select rows</span><input type=checkbox>"), te = /*#__PURE__*/ s("<th>Actions"), v = /*#__PURE__*/ s("<div><div class=data-table-scroll><table class=data-table><thead><tr></tr></thead><tbody>"), y = /*#__PURE__*/ s("<li><label class=data-table-customizer-option><input type=checkbox>"), b = /*#__PURE__*/ s("<button type=button class=data-table-sort>"), ne = /*#__PURE__*/ s("<button type=button class=data-table-sort-clear aria-label=\"Clear sorting\"title=\"Clear sorting\">×"), re = /*#__PURE__*/ s("<th>"), ie = /*#__PURE__*/ s("<td class=data-table-checkbox><input type=checkbox>"), x = /*#__PURE__*/ s("<td>"), ae = /*#__PURE__*/ s("<tr>"), S = /*#__PURE__*/ s("<p class=data-table-status>Loading…"), C = /*#__PURE__*/ s("<p class=data-table-status>No results.");
|
|
5
|
+
function w(e) {
|
|
6
6
|
return typeof e == "function" ? e() : e;
|
|
7
7
|
}
|
|
8
|
-
function
|
|
9
|
-
let s = f(() =>
|
|
10
|
-
let e =
|
|
8
|
+
function T(n) {
|
|
9
|
+
let s = f(() => w(n.rows)), T = () => w(n.loading ?? !1), E = () => w(n.selected ?? []), D = n.sortKey !== void 0 || n.sortDirection !== void 0, [O, k] = p(n.defaultSort), A = () => D ? w(n.sortKey ?? void 0) : O()?.key, j = () => D ? w(n.sortDirection ?? "asc") : O()?.direction ?? "asc", M = () => w(n.showColumnCustomizer ?? !1), N = () => n.selected !== void 0 && n.onSelectionChange !== void 0, P = () => {
|
|
10
|
+
let e = E();
|
|
11
11
|
return s().length > 0 && s().every((t) => e.includes(n.getRowId(t)));
|
|
12
|
-
},
|
|
13
|
-
function
|
|
12
|
+
}, F = f(() => n.defaultVisibleColumns ?? n.columns.filter((e) => e.defaultVisible !== !1).map((e) => e.key)), [I, L] = p(void 0), R = () => n.visibleColumns === void 0 ? I() ?? F() : w(n.visibleColumns), z = f(() => new Set(R())), B = f(() => n.columns.filter((e) => e.toggleable === !1 || z().has(e.key))), V = f(() => n.columns.filter((e) => e.toggleable !== !1)), H = f(() => V().map((e) => e.key));
|
|
13
|
+
function U(e, t) {
|
|
14
|
+
return t.sortValue ? t.sortValue(e) : e[t.key];
|
|
15
|
+
}
|
|
16
|
+
function W(e, t) {
|
|
17
|
+
return e === t ? 0 : e == null ? -1 : t == null ? 1 : typeof e == "number" && typeof t == "number" ? e - t : String(e).localeCompare(String(t), void 0, { numeric: !0 });
|
|
18
|
+
}
|
|
19
|
+
let G = f(() => {
|
|
20
|
+
let e = s(), t = A();
|
|
21
|
+
if (D || !t) return e;
|
|
22
|
+
let r = n.columns.find((e) => e.key === t);
|
|
23
|
+
if (!r) return e;
|
|
24
|
+
let i = j() === "asc" ? 1 : -1;
|
|
25
|
+
return [...e].sort((e, t) => i * W(U(e, r), U(t, r)));
|
|
26
|
+
});
|
|
27
|
+
function K(e) {
|
|
28
|
+
let t = {
|
|
29
|
+
key: e,
|
|
30
|
+
direction: A() === e && j() === "asc" ? "desc" : "asc"
|
|
31
|
+
};
|
|
32
|
+
D || k(t), n.onSort?.(e), n.onSortChange?.(t);
|
|
33
|
+
}
|
|
34
|
+
function q() {
|
|
35
|
+
D || k(void 0), n.onSortClear?.(), n.onSortChange?.(void 0);
|
|
36
|
+
}
|
|
37
|
+
function oe(e) {
|
|
14
38
|
let t = new Map(n.columns.map((e, t) => [e.key, t]));
|
|
15
39
|
return [...e].sort((e, n) => (t.get(e) ?? 0) - (t.get(n) ?? 0));
|
|
16
40
|
}
|
|
17
|
-
function
|
|
18
|
-
let t =
|
|
19
|
-
n.visibleColumns === void 0 &&
|
|
41
|
+
function J(e) {
|
|
42
|
+
let t = oe(e);
|
|
43
|
+
n.visibleColumns === void 0 && L(t), n.onVisibleColumnsChange?.(t);
|
|
20
44
|
}
|
|
21
|
-
function
|
|
22
|
-
let n = new Set(
|
|
23
|
-
t ? n.add(e) : n.delete(e),
|
|
45
|
+
function se(e, t) {
|
|
46
|
+
let n = new Set(R());
|
|
47
|
+
t ? n.add(e) : n.delete(e), J(H().filter((e) => n.has(e)));
|
|
24
48
|
}
|
|
25
|
-
function
|
|
26
|
-
|
|
49
|
+
function ce() {
|
|
50
|
+
J(H());
|
|
27
51
|
}
|
|
28
|
-
function
|
|
29
|
-
|
|
52
|
+
function le() {
|
|
53
|
+
J(F());
|
|
30
54
|
}
|
|
31
55
|
let Y = `${m()}-panel`, [X, Z] = p(!1), Q;
|
|
32
56
|
d(() => {
|
|
33
|
-
if (!X() || !
|
|
57
|
+
if (!X() || !M()) return;
|
|
34
58
|
function e(e) {
|
|
35
59
|
Q && !Q.contains(e.target) && Z(!1);
|
|
36
60
|
}
|
|
@@ -43,32 +67,32 @@ function k(n) {
|
|
|
43
67
|
});
|
|
44
68
|
let $;
|
|
45
69
|
d(() => {
|
|
46
|
-
$ && ($.indeterminate =
|
|
70
|
+
$ && ($.indeterminate = E().length > 0 && !P());
|
|
47
71
|
});
|
|
48
|
-
function
|
|
72
|
+
function ue(e) {
|
|
49
73
|
n.onSelectionChange?.(e ? s().map(n.getRowId) : []);
|
|
50
74
|
}
|
|
51
|
-
function
|
|
52
|
-
let r = n.getRowId(e), i =
|
|
75
|
+
function de(e, t) {
|
|
76
|
+
let r = n.getRowId(e), i = E(), a = t ? [...i, r] : i.filter((e) => e !== r);
|
|
53
77
|
n.onSelectionChange?.(a);
|
|
54
78
|
}
|
|
55
|
-
function
|
|
56
|
-
return
|
|
79
|
+
function fe(e) {
|
|
80
|
+
return E().includes(n.getRowId(e));
|
|
57
81
|
}
|
|
58
|
-
function
|
|
59
|
-
return e.toggleable === !1 ||
|
|
82
|
+
function pe(e) {
|
|
83
|
+
return e.toggleable === !1 || z().has(e.key);
|
|
60
84
|
}
|
|
61
|
-
function
|
|
85
|
+
function me(e, t) {
|
|
62
86
|
return n.getCell?.(e, t) ?? t.getValue?.(e) ?? null;
|
|
63
87
|
}
|
|
64
88
|
return (() => {
|
|
65
|
-
var d =
|
|
89
|
+
var d = v(), f = d.firstChild, p = f.firstChild.firstChild, m = p.firstChild, h = p.nextSibling;
|
|
66
90
|
return i(d, t(u, {
|
|
67
91
|
get when() {
|
|
68
|
-
return
|
|
92
|
+
return M();
|
|
69
93
|
},
|
|
70
94
|
get children() {
|
|
71
|
-
var e =
|
|
95
|
+
var e = ee(), a = e.firstChild, s = a.firstChild;
|
|
72
96
|
s.firstChild.nextSibling;
|
|
73
97
|
var d = Q;
|
|
74
98
|
return typeof d == "function" ? c(d, a) : Q = a, s.$$click = () => Z((e) => !e), o(s, "aria-controls", Y), i(s, () => n.columnCustomizerLabel ?? "Columns", null), i(a, t(u, {
|
|
@@ -82,29 +106,29 @@ function k(n) {
|
|
|
82
106
|
return n.columns;
|
|
83
107
|
},
|
|
84
108
|
children: (e) => (() => {
|
|
85
|
-
var t =
|
|
86
|
-
return a.addEventListener("change", (t) =>
|
|
109
|
+
var t = y(), n = t.firstChild, a = n.firstChild;
|
|
110
|
+
return a.addEventListener("change", (t) => se(e.key, t.currentTarget.checked)), i(n, () => e.ariaLabel ?? e.label, null), r(() => a.disabled = e.toggleable === !1), r(() => a.checked = pe(e)), t;
|
|
87
111
|
})()
|
|
88
|
-
})), c.$$click =
|
|
112
|
+
})), c.$$click = ce, i(c, () => n.columnCustomizerShowAllLabel ?? "Show all"), u.$$click = le, i(u, () => n.columnCustomizerResetLabel ?? "Reset"), r(() => o(e, "aria-label", n.columnCustomizerTitle ?? "Customize columns")), e;
|
|
89
113
|
}
|
|
90
114
|
}), null), r(() => o(s, "aria-expanded", X())), e;
|
|
91
115
|
}
|
|
92
116
|
}), f), i(m, t(u, {
|
|
93
117
|
get when() {
|
|
94
|
-
return
|
|
118
|
+
return N();
|
|
95
119
|
},
|
|
96
120
|
get children() {
|
|
97
|
-
var e =
|
|
98
|
-
t.addEventListener("change", (e) =>
|
|
121
|
+
var e = _(), t = e.firstChild.nextSibling;
|
|
122
|
+
t.addEventListener("change", (e) => ue(e.currentTarget.checked));
|
|
99
123
|
var i = $;
|
|
100
|
-
return typeof i == "function" ? c(i, t) : $ = t, r(() => o(t, "aria-label", n.selectionLabel ?? "Select all rows")), r(() => t.checked =
|
|
124
|
+
return typeof i == "function" ? c(i, t) : $ = t, r(() => o(t, "aria-label", n.selectionLabel ?? "Select all rows")), r(() => t.checked = P()), e;
|
|
101
125
|
}
|
|
102
126
|
}), null), i(m, t(l, {
|
|
103
127
|
get each() {
|
|
104
|
-
return
|
|
128
|
+
return B();
|
|
105
129
|
},
|
|
106
130
|
children: (s) => (() => {
|
|
107
|
-
var c =
|
|
131
|
+
var c = re();
|
|
108
132
|
return i(c, t(u, {
|
|
109
133
|
get when() {
|
|
110
134
|
return a(() => !!s.sortable)() && n.onSort;
|
|
@@ -113,14 +137,24 @@ function k(n) {
|
|
|
113
137
|
return s.label;
|
|
114
138
|
},
|
|
115
139
|
get children() {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
140
|
+
return [(() => {
|
|
141
|
+
var e = b();
|
|
142
|
+
return e.$$click = () => K(s.key), i(e, () => s.label, null), i(e, (() => {
|
|
143
|
+
var e = a(() => A() === s.key);
|
|
144
|
+
return () => e() ? j() === "asc" ? " ▲" : " ▼" : "";
|
|
145
|
+
})(), null), e;
|
|
146
|
+
})(), t(u, {
|
|
147
|
+
get when() {
|
|
148
|
+
return a(() => A() === s.key)() && (!D || n.onSortClear || n.onSortChange);
|
|
149
|
+
},
|
|
150
|
+
get children() {
|
|
151
|
+
var e = ne();
|
|
152
|
+
return e.$$click = q, e;
|
|
153
|
+
}
|
|
154
|
+
})];
|
|
121
155
|
}
|
|
122
156
|
})), r((t) => {
|
|
123
|
-
var n = s.class, r = s.sortable ?
|
|
157
|
+
var n = s.class, r = s.sortable ? A() === s.key ? j() === "asc" ? "ascending" : "descending" : "none" : void 0;
|
|
124
158
|
return n !== t.e && e(c, t.e = n), r !== t.t && o(c, "aria-sort", t.t = r), t;
|
|
125
159
|
}, {
|
|
126
160
|
e: void 0,
|
|
@@ -132,57 +166,57 @@ function k(n) {
|
|
|
132
166
|
return n.rowActions;
|
|
133
167
|
},
|
|
134
168
|
get children() {
|
|
135
|
-
return
|
|
169
|
+
return te();
|
|
136
170
|
}
|
|
137
171
|
}), null), i(h, t(l, {
|
|
138
172
|
get each() {
|
|
139
|
-
return
|
|
173
|
+
return G();
|
|
140
174
|
},
|
|
141
175
|
children: (a) => (() => {
|
|
142
|
-
var s =
|
|
176
|
+
var s = ae();
|
|
143
177
|
return i(s, t(u, {
|
|
144
178
|
get when() {
|
|
145
|
-
return
|
|
179
|
+
return N();
|
|
146
180
|
},
|
|
147
181
|
get children() {
|
|
148
|
-
var e =
|
|
149
|
-
return t.addEventListener("change", (e) =>
|
|
182
|
+
var e = ie(), t = e.firstChild;
|
|
183
|
+
return t.addEventListener("change", (e) => de(a, e.currentTarget.checked)), r(() => o(t, "aria-label", `Select row ${n.getRowId(a)}`)), r(() => t.checked = fe(a)), e;
|
|
150
184
|
}
|
|
151
185
|
}), null), i(s, t(l, {
|
|
152
186
|
get each() {
|
|
153
|
-
return
|
|
187
|
+
return B();
|
|
154
188
|
},
|
|
155
189
|
children: (t) => (() => {
|
|
156
|
-
var n =
|
|
157
|
-
return i(n, () =>
|
|
190
|
+
var n = x();
|
|
191
|
+
return i(n, () => me(a, t)), r(() => e(n, t.class)), n;
|
|
158
192
|
})()
|
|
159
193
|
}), null), i(s, t(u, {
|
|
160
194
|
get when() {
|
|
161
195
|
return n.rowActions;
|
|
162
196
|
},
|
|
163
197
|
get children() {
|
|
164
|
-
var e =
|
|
198
|
+
var e = x();
|
|
165
199
|
return i(e, () => n.rowActions?.(a)), e;
|
|
166
200
|
}
|
|
167
201
|
}), null), s;
|
|
168
202
|
})()
|
|
169
203
|
})), i(d, t(u, {
|
|
170
204
|
get when() {
|
|
171
|
-
return
|
|
205
|
+
return T();
|
|
172
206
|
},
|
|
173
207
|
get children() {
|
|
174
|
-
return n.loadingContent ??
|
|
208
|
+
return n.loadingContent ?? S();
|
|
175
209
|
}
|
|
176
210
|
}), null), i(d, t(u, {
|
|
177
211
|
get when() {
|
|
178
|
-
return a(() => !
|
|
212
|
+
return a(() => !T())() && (n.empty === void 0 ? s().length === 0 : w(n.empty));
|
|
179
213
|
},
|
|
180
214
|
get children() {
|
|
181
|
-
return n.emptyContent ??
|
|
215
|
+
return n.emptyContent ?? C();
|
|
182
216
|
}
|
|
183
217
|
}), null), r(() => e(d, `data-table-wrap${n.class ? ` ${n.class}` : ""}`)), d;
|
|
184
218
|
})();
|
|
185
219
|
}
|
|
186
220
|
n(["click"]);
|
|
187
221
|
//#endregion
|
|
188
|
-
export {
|
|
222
|
+
export { T as DataTable };
|
package/dist/styles.css
CHANGED
|
@@ -118,6 +118,22 @@
|
|
|
118
118
|
text-decoration: underline;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
.data-table-sort-clear {
|
|
122
|
+
margin-left: 0.25rem;
|
|
123
|
+
padding: 0;
|
|
124
|
+
border: none;
|
|
125
|
+
background: transparent;
|
|
126
|
+
color: inherit;
|
|
127
|
+
font: inherit;
|
|
128
|
+
line-height: 1;
|
|
129
|
+
cursor: pointer;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.data-table-sort-clear:hover {
|
|
133
|
+
color: var(--data-table-sort-clear-hover, currentColor);
|
|
134
|
+
opacity: 0.7;
|
|
135
|
+
}
|
|
136
|
+
|
|
121
137
|
.data-table-status {
|
|
122
138
|
color: var(--text-secondary, #616161);
|
|
123
139
|
}
|