@serkonda7/solid-components 0.0.1 → 0.0.2

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 CHANGED
@@ -1,36 +1,51 @@
1
- # solid-components
1
+ # @serkonda7/solid-components
2
+ [![CI][ci-badge]][ci-status]
3
+ [![npm version][npm-badge]][npm-link]
4
+ [![npm updated][npm-date-badge]][npm-link]
2
5
 
3
6
  Reusable components for [SolidJS](https://www.solidjs.com/).
4
7
 
5
- ## Installation
6
8
 
9
+ ## 📦 Installation
7
10
  ```sh
8
- bun add solid-components solid-js
9
- # or: npm install solid-components solid-js
11
+ bun install @serkonda7/solid-components solid-js
10
12
  ```
11
13
 
12
- ## Usage
13
-
14
- Import components from the package root:
15
14
 
15
+ ## 🚀 Usage
16
16
  ```tsx
17
- import { /* Component */ } from 'solid-components';
17
+ import { /* Component */ } from 'solid-components'
18
+ import '@serkonda7/solid-components/styles.css'
18
19
  ```
19
20
 
20
- The package is currently a foundation for the component library. Components
21
- will be added to `src/` and re-exported from `src/index.ts`.
21
+ These components are available:
22
+ - `DataTable` - generic table with optional sorting, row selection, actions, loading, and empty states.
22
23
 
23
- ## Development
24
24
 
25
- Install [Bun](https://bun.sh/), then run:
25
+ ## Components
26
+ ### DataTable
27
+ The table does not fetch data or perform navigation.
28
+ Consumers provide the rows, cell rendering, and callbacks:
26
29
 
27
- ```sh
28
- bun install
29
- bun run test # type-check, build, and run tests
30
- bun run lint:ci # check formatting and lint rules
31
- bun run build # create the production package in dist/
30
+ ```tsx
31
+ <DataTable
32
+ rows={items}
33
+ getRowId={(item) => item.id}
34
+ columns={[{ key: 'name', label: 'Name', sortable: true }]}
35
+ sortKey={sortKey}
36
+ sortDirection={sortDirection}
37
+ onSort={setSortKey}
38
+ getCell={(item, column) => column.key === 'name' ? item.name : null}
39
+ />
32
40
  ```
33
41
 
34
- ## License
35
42
 
36
- MIT
43
+ ## 📜 License
44
+ This repo is licensed under the [MIT License](LICENSE.txt).
45
+
46
+
47
+ [ci-badge]: https://github.com/serkonda7/solid-components/actions/workflows/ci.yml/badge.svg
48
+ [ci-status]: https://github.com/serkonda7/solid-components/actions/workflows/ci.yml
49
+ [npm-badge]: https://nodei.co/npm/@serkonda7/solid-components.png?style=shields&data=v&color=blue
50
+ [npm-date-badge]: https://nodei.co/npm/@serkonda7/solid-components.png?style=shields&data=u&color=blue
51
+ [npm-link]: https://www.npmjs.com/package/@serkonda7/solid-components
@@ -0,0 +1,34 @@
1
+ import type { Accessor, JSX } from 'solid-js';
2
+ export type DataTableSortDirection = 'asc' | 'desc';
3
+ export interface DataTableColumn<TRow> {
4
+ key: string;
5
+ label: string;
6
+ sortable?: boolean;
7
+ class?: string;
8
+ ariaLabel?: string;
9
+ getValue?: (row: TRow) => JSX.Element;
10
+ }
11
+ export interface DataTableProps<TRow> {
12
+ rows: TRow[] | Accessor<TRow[]>;
13
+ columns: DataTableColumn<TRow>[];
14
+ getRowId: (row: TRow) => string | number;
15
+ getCell?: (row: TRow, column: DataTableColumn<TRow>) => JSX.Element;
16
+ rowActions?: (row: TRow) => JSX.Element;
17
+ selected?: string[] | number[] | Accessor<string[] | number[]>;
18
+ onSelectionChange?: (ids: (string | number)[]) => void;
19
+ selectionLabel?: string;
20
+ sortKey?: string | Accessor<string | undefined>;
21
+ sortDirection?: DataTableSortDirection | Accessor<DataTableSortDirection>;
22
+ onSort?: (key: string) => void;
23
+ loading?: boolean | Accessor<boolean>;
24
+ empty?: boolean | Accessor<boolean>;
25
+ loadingContent?: JSX.Element;
26
+ emptyContent?: JSX.Element;
27
+ class?: string;
28
+ }
29
+ /**
30
+ * Generic accessible data table. Data fetching, navigation, and cell content
31
+ * stay with the consuming app; this component owns table structure and the
32
+ * repeated selection/sort/loading states.
33
+ */
34
+ export declare function DataTable<TRow>(props: DataTableProps<TRow>): JSX.Element;
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 {};
7
+ export { DataTable, type DataTableColumn, type DataTableProps, type DataTableSortDirection, } from './data-table';
package/dist/index.js CHANGED
@@ -1,2 +1,127 @@
1
-
2
- //# debugId=1B152D275122871864756E2164756E21
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
+ import { For as l, Show as u, createEffect as d, createMemo as f } from "solid-js";
3
+ //#region src/data-table.tsx
4
+ var p = /*#__PURE__*/ s("<th class=data-table-checkbox><span class=data-table-visually-hidden>Select rows</span><input type=checkbox>"), m = /*#__PURE__*/ s("<th>Actions"), h = /*#__PURE__*/ s("<div><table class=data-table><thead><tr></tr></thead><tbody>"), g = /*#__PURE__*/ s("<button type=button class=data-table-sort>"), _ = /*#__PURE__*/ s("<th>"), v = /*#__PURE__*/ s("<td class=data-table-checkbox><input type=checkbox>"), y = /*#__PURE__*/ s("<td>"), b = /*#__PURE__*/ s("<tr>"), x = /*#__PURE__*/ s("<p class=data-table-status>Loading…"), S = /*#__PURE__*/ s("<p class=data-table-status>No results.");
5
+ function C(e) {
6
+ return typeof e == "function" ? e() : e;
7
+ }
8
+ function w(n) {
9
+ let s = f(() => C(n.rows)), w = () => C(n.loading ?? !1), T = () => C(n.selected ?? []), E = () => C(n.sortKey ?? void 0), D = () => C(n.sortDirection ?? "asc"), O = () => n.selected !== void 0 && n.onSelectionChange !== void 0, k = () => {
10
+ let e = T();
11
+ return s().length > 0 && s().every((t) => e.includes(n.getRowId(t)));
12
+ }, A;
13
+ d(() => {
14
+ A && (A.indeterminate = T().length > 0 && !k());
15
+ });
16
+ function j(e) {
17
+ n.onSelectionChange?.(e ? s().map(n.getRowId) : []);
18
+ }
19
+ function M(e, t) {
20
+ let r = n.getRowId(e), i = T(), a = t ? [...i, r] : i.filter((e) => e !== r);
21
+ n.onSelectionChange?.(a);
22
+ }
23
+ function N(e) {
24
+ return T().includes(n.getRowId(e));
25
+ }
26
+ function P(e, t) {
27
+ return n.getCell?.(e, t) ?? t.getValue?.(e) ?? null;
28
+ }
29
+ return (() => {
30
+ var d = h(), f = d.firstChild.firstChild, T = f.firstChild, F = f.nextSibling;
31
+ return i(T, t(u, {
32
+ get when() {
33
+ return O();
34
+ },
35
+ get children() {
36
+ var e = p(), t = e.firstChild.nextSibling;
37
+ t.addEventListener("change", (e) => j(e.currentTarget.checked));
38
+ var i = A;
39
+ return typeof i == "function" ? c(i, t) : A = t, r(() => o(t, "aria-label", n.selectionLabel ?? "Select all rows")), r(() => t.checked = k()), e;
40
+ }
41
+ }), null), i(T, t(l, {
42
+ get each() {
43
+ return n.columns;
44
+ },
45
+ children: (s) => (() => {
46
+ var c = _();
47
+ return i(c, t(u, {
48
+ get when() {
49
+ return a(() => !!s.sortable)() && n.onSort;
50
+ },
51
+ get fallback() {
52
+ return s.label;
53
+ },
54
+ get children() {
55
+ var e = g();
56
+ return e.$$click = () => n.onSort?.(s.key), i(e, () => s.label, null), i(e, (() => {
57
+ var e = a(() => E() === s.key);
58
+ return () => e() ? D() === "asc" ? " ▲" : " ▼" : "";
59
+ })(), null), e;
60
+ }
61
+ })), r((t) => {
62
+ var n = s.class, r = s.sortable ? E() === s.key ? D() === "asc" ? "ascending" : "descending" : "none" : void 0;
63
+ return n !== t.e && e(c, t.e = n), r !== t.t && o(c, "aria-sort", t.t = r), t;
64
+ }, {
65
+ e: void 0,
66
+ t: void 0
67
+ }), c;
68
+ })()
69
+ }), null), i(T, t(u, {
70
+ get when() {
71
+ return n.rowActions;
72
+ },
73
+ get children() {
74
+ return m();
75
+ }
76
+ }), null), i(F, t(l, {
77
+ get each() {
78
+ return s();
79
+ },
80
+ children: (a) => (() => {
81
+ var s = b();
82
+ return i(s, t(u, {
83
+ get when() {
84
+ return O();
85
+ },
86
+ get children() {
87
+ var e = v(), t = e.firstChild;
88
+ return t.addEventListener("change", (e) => M(a, e.currentTarget.checked)), r(() => o(t, "aria-label", `Select row ${n.getRowId(a)}`)), r(() => t.checked = N(a)), e;
89
+ }
90
+ }), null), i(s, t(l, {
91
+ get each() {
92
+ return n.columns;
93
+ },
94
+ children: (t) => (() => {
95
+ var n = y();
96
+ return i(n, () => P(a, t)), r(() => e(n, t.class)), n;
97
+ })()
98
+ }), null), i(s, t(u, {
99
+ get when() {
100
+ return n.rowActions;
101
+ },
102
+ get children() {
103
+ var e = y();
104
+ return i(e, () => n.rowActions?.(a)), e;
105
+ }
106
+ }), null), s;
107
+ })()
108
+ })), i(d, t(u, {
109
+ get when() {
110
+ return w();
111
+ },
112
+ get children() {
113
+ return n.loadingContent ?? x();
114
+ }
115
+ }), null), i(d, t(u, {
116
+ get when() {
117
+ return a(() => !w())() && (n.empty === void 0 ? s().length === 0 : C(n.empty));
118
+ },
119
+ get children() {
120
+ return n.emptyContent ?? S();
121
+ }
122
+ }), null), r(() => e(d, `data-table-wrap${n.class ? ` ${n.class}` : ""}`)), d;
123
+ })();
124
+ }
125
+ n(["click"]);
126
+ //#endregion
127
+ export { w as DataTable };
@@ -0,0 +1,44 @@
1
+ .data-table-wrap {
2
+ overflow-x: auto;
3
+ }
4
+
5
+ .data-table {
6
+ width: 100%;
7
+ max-width: 100%;
8
+ border-collapse: collapse;
9
+ }
10
+
11
+ .data-table-checkbox {
12
+ width: 2rem;
13
+ }
14
+
15
+ .data-table-sort {
16
+ padding: 0;
17
+ border: none;
18
+ background: transparent;
19
+ color: inherit;
20
+ font: inherit;
21
+ text-transform: inherit;
22
+ letter-spacing: inherit;
23
+ cursor: pointer;
24
+ white-space: nowrap;
25
+ }
26
+
27
+ .data-table-sort:hover {
28
+ background: transparent;
29
+ color: inherit;
30
+ text-decoration: underline;
31
+ }
32
+
33
+ .data-table-status {
34
+ color: var(--text-secondary, #616161);
35
+ }
36
+
37
+ .data-table-visually-hidden {
38
+ position: absolute;
39
+ width: 1px;
40
+ height: 1px;
41
+ overflow: hidden;
42
+ clip: rect(0 0 0 0);
43
+ white-space: nowrap;
44
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serkonda7/solid-components",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Reusable components for SolidJS",
5
5
  "license": "MIT",
6
6
  "author": "serkonda7",
@@ -18,7 +18,8 @@
18
18
  ".": {
19
19
  "types": "./dist/index.d.ts",
20
20
  "import": "./dist/index.js"
21
- }
21
+ },
22
+ "./styles.css": "./dist/styles.css"
22
23
  },
23
24
  "main": "./dist/index.js",
24
25
  "types": "./dist/index.d.ts",
@@ -27,6 +28,7 @@
27
28
  "lint": "biome check --write",
28
29
  "lint:ci": "biome ci",
29
30
  "check": "tsc --noEmit",
31
+ "examples": "vite --config examples/vite.config.ts",
30
32
  "build:dev": "bun run scripts/build.ts --dev",
31
33
  "build": "bun run check && bun run scripts/build.ts --prod",
32
34
  "prepack": "bun run build"
@@ -42,6 +44,8 @@
42
44
  "@biomejs/biome": "2.5.14",
43
45
  "@types/bun": "1.4.2",
44
46
  "solid-js": "~1.9.15",
45
- "typescript": "~7.0.2"
47
+ "typescript": "~7.0.2",
48
+ "vite": "~8.3.0",
49
+ "vite-plugin-solid": "~2.11.14"
46
50
  }
47
51
  }
package/dist/index.js.map DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": [],
4
- "sourcesContent": [
5
- ],
6
- "mappings": "",
7
- "debugId": "1B152D275122871864756E2164756E21",
8
- "names": []
9
- }