@jinaan/uikit 0.1.42 → 0.1.43

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jinaan/uikit",
3
- "version": "0.1.42",
3
+ "version": "0.1.43",
4
4
  "description": "Reusable React and Tailwind UI components for Jinaan projects.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -141,6 +141,14 @@ interface DataTableProps<T> {
141
141
  onRowClick?: (row: T) => void;
142
142
 
143
143
  defaultSort?: { id: string; dir: "asc" | "desc" };
144
+ /**
145
+ * Controlled sort state. Pass together with `onSortChange`: header caret
146
+ * clicks then report through the callback instead of mutating internal
147
+ * state, so an external control (e.g. a toolbar "Sort by" select) and the
148
+ * headers can drive one shared state.
149
+ */
150
+ sort?: { id: string; dir: "asc" | "desc" };
151
+ onSortChange?: (sort: { id: string; dir: "asc" | "desc" } | null) => void;
144
152
  pageSize?: number;
145
153
  pageSizeOptions?: number[];
146
154
 
@@ -223,6 +231,8 @@ export function DataTable<T>({
223
231
  rowActions,
224
232
  onRowClick,
225
233
  defaultSort,
234
+ sort: sortProp,
235
+ onSortChange,
226
236
  pageSize: initialPageSize = 25,
227
237
  pageSizeOptions = [10, 25, 50, 100],
228
238
  pagination = "auto",
@@ -240,9 +250,15 @@ export function DataTable<T>({
240
250
  // Column order and runtime pins are per-mount, like `hidden`.
241
251
  const [order, setOrder] = useState<string[] | null>(null);
242
252
  const [dragId, setDragId] = useState<string | null>(null);
243
- const [sort, setSort] = useState<{ id: string; dir: "asc" | "desc" } | null>(
253
+ const [internalSort, setInternalSort] = useState<{ id: string; dir: "asc" | "desc" } | null>(
244
254
  defaultSort ?? null,
245
255
  );
256
+ // Controlled when the caller passes onSortChange; uncontrolled otherwise.
257
+ const sort = onSortChange ? sortProp ?? null : internalSort;
258
+ const setSort = (next: { id: string; dir: "asc" | "desc" } | null) => {
259
+ if (onSortChange) onSortChange(next);
260
+ else setInternalSort(next);
261
+ };
246
262
  const [page, setPage] = useState(0);
247
263
  const [pageSize, setPageSize] = useState(initialPageSize);
248
264
  const [selected, setSelected] = useState<Set<string>>(new Set());
@@ -323,7 +339,8 @@ export function DataTable<T>({
323
339
 
324
340
  const toggleSort = (col: Column<T>) => {
325
341
  if (!col.sortable) return;
326
- setSort((prev) =>
342
+ const prev = sort;
343
+ setSort(
327
344
  prev?.id === col.id
328
345
  ? prev.dir === "asc"
329
346
  ? { id: col.id, dir: "desc" }