@gobolt/genesis 0.2.2 → 0.2.3

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.
@@ -23,9 +23,6 @@ export declare const useTableWithControls: (tableConfig: UseTableConfig) => {
23
23
  rowSelection: {
24
24
  type: import('../Table').SelectionType;
25
25
  onChange: (selectedRowKeys: React.Key[], selectedRows: Record<string, any>[]) => void;
26
- getCheckboxProps: (record: Record<string, any>) => {
27
- disabled: boolean;
28
- name: any;
29
- };
26
+ getCheckboxProps: (record: any) => unknown;
30
27
  };
31
28
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),o=require("../../Badge/Badge.cjs"),a=e=>e&&e.replace(/([A-Z])/g," $1").replace(/^./,t=>t.toUpperCase()),c=[{key:"number",title:"Number",dataIndex:"number"},{key:"timeslot",title:"Timeslot",dataIndex:"timerange"},{key:"status",title:"Status",dataIndex:"status",render:e=>{const t={in_progress:"warning",scheduled:"generic",completed:"success"},r=e==="in_progress"?"in progress":e;return n.createElement(o,{label:a(r),state:t[e]})}},{key:"address",title:"Address",render:e=>{const{address:{nickname:t,address:r}}=e;return t?`${t} (${r})`:r}},{title:"Type",dataIndex:"job_subtype",render:e=>{const t={delivery:"info",pickup:"success"};return n.createElement(o,{label:a(e),state:t[e]})}}],s=c.map(e=>({...e}));s[1].sorter=!0;s[2].sorter=!0;s[4].sorter=!0;exports.mockColumns=c;exports.mockColumnsWithSort=s;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),o=require("../../Badge/Badge.cjs"),a=e=>e&&e.replace(/([A-Z])/g," $1").replace(/^./,t=>t.toUpperCase()),c=[{key:"number",title:"Id",dataIndex:"number"},{key:"timeslot",title:"Timeslot",dataIndex:"timerange"},{key:"status",title:"Status",dataIndex:"status",render:e=>{const t={in_progress:"warning",scheduled:"generic",completed:"success"},r=e==="in_progress"?"in progress":e;return n.createElement(o,{label:a(r),state:t[e]})}},{key:"address",title:"Address",render:e=>{const{address:{nickname:t,address:r}}=e;return t?`${t} (${r})`:r}},{title:"Type",dataIndex:"job_subtype",render:e=>{const t={delivery:"info",pickup:"success"};return n.createElement(o,{label:a(e),state:t[e]})}}],s=c.map(e=>({...e}));s[1].sorter=!0;s[2].sorter=!0;s[4].sorter=!0;exports.mockColumns=c;exports.mockColumnsWithSort=s;
@@ -1,9 +1,9 @@
1
1
  import a from "react";
2
2
  import n from "../../Badge/Badge.js";
3
- const o = (e) => e && e.replace(/([A-Z])/g, " $1").replace(/^./, (t) => t.toUpperCase()), c = [
3
+ const o = (e) => e && e.replace(/([A-Z])/g, " $1").replace(/^./, (t) => t.toUpperCase()), d = [
4
4
  {
5
5
  key: "number",
6
- title: "Number",
6
+ title: "Id",
7
7
  dataIndex: "number"
8
8
  },
9
9
  {
@@ -51,13 +51,13 @@ const o = (e) => e && e.replace(/([A-Z])/g, " $1").replace(/^./, (t) => t.toUppe
51
51
  });
52
52
  }
53
53
  }
54
- ], s = c.map((e) => ({
54
+ ], s = d.map((e) => ({
55
55
  ...e
56
56
  }));
57
57
  s[1].sorter = !0;
58
58
  s[2].sorter = !0;
59
59
  s[4].sorter = !0;
60
60
  export {
61
- c as mockColumns,
61
+ d as mockColumns,
62
62
  s as mockColumnsWithSort
63
63
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react"),D=(a,e)=>{if(!e||Array.isArray(e)&&e.length===0)return[...a];if(Array.isArray(e))return[...a].sort((s,i)=>{for(const r of e){if(!r.field)continue;const n=r.field,o=s[n],u=i[n];if(o<u)return r.order==="ascend"?-1:1;if(o>u)return r.order==="ascend"?1:-1}return 0});if(e.field){const s=e.field;return[...a].sort((i,r)=>{const n=i[s],o=r[s];return e.order==="ascend"?n<o?-1:n>o?1:0:e.order==="descend"?n<o?1:n>o?-1:0:0})}return[...a]},w=a=>{const{columns:e,filters:s=null,fetchUrl:i="/table/data",fetchOptions:r={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)},selectionType:n="checkbox",simulateDelay:o=0}=a,[u,b]=l.useState([]),[h,f]=l.useState({dataSource:[],columns:[],error:null}),[y,g]=l.useState([]);l.useEffect(()=>{(async()=>{try{const S=(await(await fetch(i,r)).json()).data||[];b(S),f({dataSource:S,columns:e,error:null})}catch(t){console.error("Error fetching table data:",t),f({dataSource:[],columns:e,error:t instanceof Error?t:new Error(String(t))})}})()},[r]),l.useCallback(c=>{setTimeout(()=>{const t=D(u,c);f(d=>({...d,dataSource:t}))},o)},[u]);const p=l.useCallback((c,t)=>{console.log("Row Selected:",c,t),g(t)},[]);return{...h,rowSelection:{type:n,onChange:p,getCheckboxProps:c=>({disabled:!1,name:c.id})},selectedRows:y}};exports.useTable=w;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),m=a=>({disabled:!1,name:a.id}),T=a=>{const[i,u]=t.useState(!0),{columns:s,filters:d=null,fetchUrl:S="/table/data",fetchOptions:n={method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(d)},selectionType:f="checkbox",simulateDelay:r=0,disableRowSelection:b=m}=a,[D,g]=t.useState([]),[h,c]=t.useState({dataSource:[],columns:[],error:null}),[y,p]=t.useState([]);t.useEffect(()=>{const o=async()=>{try{const l=(await(await fetch(S,n)).json()).data||[];g(l),c({dataSource:l,columns:s,error:null})}catch(e){console.error("Error fetching table data:",e),c({dataSource:[],columns:s,error:e instanceof Error?e:new Error(String(e))})}finally{u(!1)}};r>0?setTimeout(o,r):o()},[n]);const w=t.useCallback((o,e)=>{console.log("Row Selected:",o,e),p(e)},[]);return{...h,isLoading:i,rowSelection:{type:f,onChange:w,getCheckboxProps:b},selectedRows:y}};exports.useTable=T;
@@ -7,15 +7,14 @@ export type UseTableConfig = {
7
7
  fetchOptions?: RequestInit;
8
8
  selectionType?: SelectionType;
9
9
  simulateDelay?: number;
10
+ disableRowSelection?: (record: any) => unknown;
10
11
  };
11
12
  export declare const useTable: <T extends Record<string, any>>(useTableConfig: any) => {
13
+ isLoading: boolean;
12
14
  rowSelection: {
13
15
  type: SelectionType;
14
16
  onChange: (selectedRowKeys: React.Key[], selectedRows: T[]) => void;
15
- getCheckboxProps: (record: T) => {
16
- disabled: boolean;
17
- name: any;
18
- };
17
+ getCheckboxProps: (record: any) => unknown;
19
18
  };
20
19
  selectedRows: T[];
21
20
  dataSource: T[];
@@ -1,93 +1,66 @@
1
- import { useState as f, useEffect as m, useCallback as S } from "react";
2
- const w = (a, e) => {
3
- if (!e || Array.isArray(e) && e.length === 0)
4
- return [...a];
5
- if (Array.isArray(e))
6
- return [...a].sort((c, i) => {
7
- for (const r of e) {
8
- if (!r.field) continue;
9
- const n = r.field, o = c[n], l = i[n];
10
- if (o < l) return r.order === "ascend" ? -1 : 1;
11
- if (o > l) return r.order === "ascend" ? 1 : -1;
12
- }
13
- return 0;
14
- });
15
- if (e.field) {
16
- const c = e.field;
17
- return [...a].sort((i, r) => {
18
- const n = i[c], o = r[c];
19
- return e.order === "ascend" ? n < o ? -1 : n > o ? 1 : 0 : e.order === "descend" ? n < o ? 1 : n > o ? -1 : 0 : 0;
20
- });
21
- }
22
- return [...a];
23
- }, C = (a) => {
24
- const {
25
- columns: e,
26
- filters: c = null,
27
- fetchUrl: i = "/table/data",
28
- fetchOptions: r = {
1
+ import { useState as o, useEffect as m, useCallback as D } from "react";
2
+ const R = (a) => ({
3
+ disabled: !1,
4
+ // Add your disable logic here
5
+ name: a.id
6
+ }), k = (a) => {
7
+ const [i, d] = o(!0), {
8
+ columns: n,
9
+ filters: u = null,
10
+ fetchUrl: f = "/table/data",
11
+ fetchOptions: s = {
29
12
  method: "POST",
30
13
  headers: {
31
14
  "Content-Type": "application/json"
32
15
  },
33
- body: JSON.stringify(c)
16
+ body: JSON.stringify(u)
34
17
  },
35
- selectionType: n = "checkbox",
36
- simulateDelay: o = 0
37
- } = a, [l, y] = f([]), [p, u] = f({
18
+ selectionType: S = "checkbox",
19
+ simulateDelay: r = 0,
20
+ disableRowSelection: h = R
21
+ } = a, [T, p] = o([]), [g, c] = o({
38
22
  dataSource: [],
39
23
  columns: [],
40
24
  error: null
41
- }), [b, g] = f([]);
25
+ }), [w, b] = o([]);
42
26
  m(() => {
43
- (async () => {
27
+ const t = async () => {
44
28
  try {
45
- const h = (await (await fetch(i, r)).json()).data || [];
46
- y(h), u({
47
- dataSource: h,
48
- columns: e,
29
+ const l = (await (await fetch(f, s)).json()).data || [];
30
+ p(l), c({
31
+ dataSource: l,
32
+ columns: n,
49
33
  error: null
50
34
  });
51
- } catch (t) {
52
- console.error("Error fetching table data:", t), u({
35
+ } catch (e) {
36
+ console.error("Error fetching table data:", e), c({
53
37
  dataSource: [],
54
- columns: e,
55
- error: t instanceof Error ? t : new Error(String(t))
38
+ columns: n,
39
+ error: e instanceof Error ? e : new Error(String(e))
56
40
  });
41
+ } finally {
42
+ d(!1);
57
43
  }
58
- })();
59
- }, [r]), S(
60
- (s) => {
61
- setTimeout(() => {
62
- const t = w(l, s);
63
- u((d) => ({
64
- ...d,
65
- dataSource: t
66
- }));
67
- }, o);
68
- },
69
- [l]
70
- );
71
- const D = S(
72
- (s, t) => {
73
- console.log("Row Selected:", s, t), g(t);
44
+ };
45
+ r > 0 ? setTimeout(t, r) : t();
46
+ }, [s]);
47
+ const y = D(
48
+ (t, e) => {
49
+ console.log("Row Selected:", t, e), b(e);
74
50
  },
75
51
  []
76
52
  );
77
53
  return {
78
- ...p,
54
+ ...g,
55
+ isLoading: i,
79
56
  rowSelection: {
80
- type: n,
81
- onChange: D,
82
- getCheckboxProps: (s) => ({
83
- disabled: !1,
84
- // Add your disable logic here
85
- name: s.id
86
- })
57
+ type: S,
58
+ onChange: y,
59
+ getCheckboxProps: h
87
60
  },
88
- selectedRows: b
61
+ selectedRows: w
89
62
  };
90
63
  };
91
64
  export {
92
- C as useTable
65
+ k as useTable
93
66
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gobolt/genesis",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "genesis design system",
5
5
  "author": "gobolt",
6
6
  "license": "MIT",