@taiv/ui 1.10.1 → 1.10.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.
@@ -3,7 +3,10 @@ interface ColumnConfig {
3
3
  heading?: string;
4
4
  style?: CSSProperties;
5
5
  }
6
- interface TableProps<T> {
6
+ interface TableItem {
7
+ key: string | number;
8
+ }
9
+ interface TableProps<T extends TableItem> {
7
10
  columnConfigs: ColumnConfig[];
8
11
  data: T[];
9
12
  ListItem: React.ComponentType<{
@@ -11,7 +14,9 @@ interface TableProps<T> {
11
14
  }>;
12
15
  placeholder?: React.ReactNode;
13
16
  shadow?: boolean;
17
+ divider?: boolean;
14
18
  }
15
- declare const Table: <T>({ columnConfigs, data, ListItem, placeholder, shadow }: TableProps<T>) => import("react/jsx-runtime").JSX.Element;
16
- export { Table, type ColumnConfig, type TableProps };
19
+ declare const TableComponent: <T extends TableItem>({ columnConfigs, data, ListItem, placeholder, shadow, divider }: TableProps<T>) => import("react/jsx-runtime").JSX.Element;
20
+ export declare const Table: typeof TableComponent;
21
+ export { type ColumnConfig, type TableProps };
17
22
  //# sourceMappingURL=Table.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Table.d.ts","sourceRoot":"","sources":["../../../../src/components/Layout/Table/Table.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAqB,MAAM,OAAO,CAAC;AAIhE,UAAU,YAAY;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB;AAED,UAAU,UAAU,CAAC,CAAC;IACpB,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,QAAQ,EAAE,KAAK,CAAC,aAAa,CAAC;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,CAAC;IAC3C,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,QAAA,MAAM,KAAK,GAAI,CAAC,EAAG,wDAAgE,UAAU,CAAC,CAAC,CAAC,4CAsE/F,CAAC;AAEF,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,EAAE,KAAK,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"Table.d.ts","sourceRoot":"","sources":["../../../../src/components/Layout/Table/Table.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAA2B,MAAM,OAAO,CAAC;AAItE,UAAU,YAAY;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB;AAED,UAAU,SAAS;IACjB,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACtB;AAED,UAAU,UAAU,CAAC,CAAC,SAAS,SAAS;IACtC,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,QAAQ,EAAE,KAAK,CAAC,aAAa,CAAC;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,CAAC;IAC3C,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,QAAA,MAAM,cAAc,GAAI,CAAC,SAAS,SAAS,EAAE,iEAAgF,UAAU,CAAC,CAAC,CAAC,4CA4EzI,CAAC;AAEF,eAAO,MAAM,KAAK,EAA2B,OAAO,cAAc,CAAC;AAEnE,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,UAAU,EAAE,CAAC"}
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useEffect, useRef } from 'react';
2
+ import { memo, useEffect, useRef } from 'react';
3
3
  import { Box } from '../Box/Box';
4
4
  import { fontWeight, neutral } from '../../../constants';
5
- const Table = ({ columnConfigs, data, ListItem, placeholder, shadow = false }) => {
5
+ const TableComponent = ({ columnConfigs, data, ListItem, placeholder, shadow = false, divider = true }) => {
6
6
  const tableRef = useRef(null);
7
7
  /**
8
8
  * Apply column styles to the table cells.
@@ -17,7 +17,7 @@ const Table = ({ columnConfigs, data, ListItem, placeholder, shadow = false }) =
17
17
  const rows = tbody.querySelectorAll('tr');
18
18
  if (!rows || !rows.length)
19
19
  return;
20
- rows.forEach((row) => {
20
+ rows.forEach((row, rowIndex) => {
21
21
  const cells = row.querySelectorAll('td');
22
22
  cells.forEach((cell, columnIndex) => {
23
23
  var _a;
@@ -26,8 +26,11 @@ const Table = ({ columnConfigs, data, ListItem, placeholder, shadow = false }) =
26
26
  Object.assign(cell.style, columnStyle);
27
27
  }
28
28
  });
29
+ const showDivider = divider && rowIndex < rows.length - 1;
30
+ const borderStyle = { borderBottom: showDivider ? `1px solid ${neutral[100]}` : 'none' };
31
+ Object.assign(row.style, borderStyle);
29
32
  });
30
- }, [columnConfigs, data]);
33
+ }, [columnConfigs, data, divider]);
31
34
  return (_jsx(Box, { sx: {
32
35
  borderTopLeftRadius: '8px',
33
36
  borderTopRightRadius: '8px',
@@ -35,6 +38,7 @@ const Table = ({ columnConfigs, data, ListItem, placeholder, shadow = false }) =
35
38
  overflow: 'hidden',
36
39
  }, children: _jsxs("table", { ref: tableRef, style: {
37
40
  width: '100%',
41
+ borderCollapse: 'collapse',
38
42
  }, children: [_jsx("thead", { children: _jsx("tr", { children: columnConfigs.map((column, index) => (_jsx("th", { style: {
39
43
  backgroundColor: neutral[50],
40
44
  color: neutral[300],
@@ -43,6 +47,6 @@ const Table = ({ columnConfigs, data, ListItem, placeholder, shadow = false }) =
43
47
  paddingBottom: '9px',
44
48
  paddingTop: '9px',
45
49
  ...column.style,
46
- }, children: column.heading }, column.heading || `column-${index}`))) }) }), _jsx("tbody", { children: (!data || data.length === 0) && placeholder ? _jsx("tr", { children: _jsx("td", { colSpan: columnConfigs.length, children: placeholder }) }) : data.map((item) => (_jsx(ListItem, { data: item }, String(item).slice(0, 10)))) })] }) }));
50
+ }, children: column.heading }, column.heading || `column-${index}`))) }) }), _jsx("tbody", { children: (!data || data.length === 0) && placeholder ? _jsx("tr", { children: _jsx("td", { colSpan: columnConfigs.length, children: placeholder }) }) : data.map((item) => (_jsx(ListItem, { data: item }, item.key))) })] }) }));
47
51
  };
48
- export { Table };
52
+ export const Table = memo(TableComponent);
@@ -10,4 +10,5 @@ export declare const StyledColumns: Story;
10
10
  export declare const TableWithPlaceholder: Story;
11
11
  export declare const TableWithoutPlaceholder: Story;
12
12
  export declare const TableWithShadow: Story;
13
+ export declare const TableWithoutDivider: Story;
13
14
  //# sourceMappingURL=Table.stories.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Table.stories.d.ts","sourceRoot":"","sources":["../../../../src/components/Layout/Table/Table.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAUhC,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,KAAK,CAyB5B,CAAC;AAEF,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAyPnC,eAAO,MAAM,UAAU,EAAE,KAmBxB,CAAC;AAEF,eAAO,MAAM,yBAAyB,EAAE,KAqBvC,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,KAoBnC,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,KAmB3B,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,KAsBlC,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,KAerC,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,KAa7B,CAAC"}
1
+ {"version":3,"file":"Table.stories.d.ts","sourceRoot":"","sources":["../../../../src/components/Layout/Table/Table.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAUhC,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,KAAK,CA6B5B,CAAC;AAEF,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAuQnC,eAAO,MAAM,UAAU,EAAE,KAmBxB,CAAC;AAEF,eAAO,MAAM,yBAAyB,EAAE,KAqBvC,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,KAoBnC,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,KAmB3B,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,KAsBlC,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,KAerC,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,KAa7B,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,KAajC,CAAC"}
@@ -31,12 +31,17 @@ const meta = {
31
31
  control: { type: 'boolean' },
32
32
  description: 'Adds shadow to the table',
33
33
  },
34
+ divider: {
35
+ control: { type: 'boolean' },
36
+ description: 'Adds divider between rows to the table',
37
+ },
34
38
  },
35
39
  };
36
40
  export default meta;
37
41
  // Mock data
38
42
  const userData = [
39
43
  {
44
+ key: 'user-1',
40
45
  id: '1',
41
46
  name: 'John Doe',
42
47
  email: 'john.doe@example.com',
@@ -45,6 +50,7 @@ const userData = [
45
50
  lastLogin: '2024-01-15',
46
51
  },
47
52
  {
53
+ key: 'user-2',
48
54
  id: '2',
49
55
  name: 'Jane Smith',
50
56
  email: 'jane.smith@example.com',
@@ -53,6 +59,7 @@ const userData = [
53
59
  lastLogin: '2024-01-14',
54
60
  },
55
61
  {
62
+ key: 'user-3',
56
63
  id: '3',
57
64
  name: 'Bob Johnson',
58
65
  email: 'bob.johnson@example.com',
@@ -61,6 +68,7 @@ const userData = [
61
68
  lastLogin: '2024-01-10',
62
69
  },
63
70
  {
71
+ key: 'user-4',
64
72
  id: '4',
65
73
  name: 'Alice Williams',
66
74
  email: 'alice.williams@example.com',
@@ -71,6 +79,7 @@ const userData = [
71
79
  ];
72
80
  const productData = [
73
81
  {
82
+ key: 'product-1',
74
83
  id: '1',
75
84
  name: 'Premium Widget',
76
85
  category: 'Electronics',
@@ -79,6 +88,7 @@ const productData = [
79
88
  status: 'in-stock',
80
89
  },
81
90
  {
91
+ key: 'product-2',
82
92
  id: '2',
83
93
  name: 'Standard Widget',
84
94
  category: 'Electronics',
@@ -87,6 +97,7 @@ const productData = [
87
97
  status: 'low-stock',
88
98
  },
89
99
  {
100
+ key: 'product-3',
90
101
  id: '3',
91
102
  name: 'Basic Widget',
92
103
  category: 'Accessories',
@@ -95,6 +106,7 @@ const productData = [
95
106
  status: 'out-of-stock',
96
107
  },
97
108
  {
109
+ key: 'product-4',
98
110
  id: '4',
99
111
  name: 'Deluxe Widget',
100
112
  category: 'Electronics',
@@ -105,6 +117,7 @@ const productData = [
105
117
  ];
106
118
  const projectData = [
107
119
  {
120
+ key: 'project-1',
108
121
  id: '1',
109
122
  title: 'Website Redesign',
110
123
  team: ['Alice', 'Bob', 'Charlie'],
@@ -113,6 +126,7 @@ const projectData = [
113
126
  priority: 'high',
114
127
  },
115
128
  {
129
+ key: 'project-2',
116
130
  id: '2',
117
131
  title: 'Mobile App Update',
118
132
  team: ['David', 'Eve'],
@@ -121,6 +135,7 @@ const projectData = [
121
135
  priority: 'medium',
122
136
  },
123
137
  {
138
+ key: 'project-3',
124
139
  id: '3',
125
140
  title: 'API Documentation',
126
141
  team: ['Frank', 'Grace'],
@@ -314,3 +329,17 @@ export const TableWithShadow = {
314
329
  shadow: true,
315
330
  },
316
331
  };
332
+ export const TableWithoutDivider = {
333
+ args: {
334
+ columnConfigs: [
335
+ { heading: 'Name', style: { width: '25%', paddingLeft: '20px', fontWeight: '600' } },
336
+ { heading: 'Email', style: { width: '30%', textAlign: 'left' } },
337
+ { heading: 'Role', style: { width: '20%', textAlign: 'center' } },
338
+ { heading: 'Status', style: { width: '15%', textAlign: 'center' } },
339
+ { heading: 'Last Login', style: { width: '10%', textAlign: 'right', paddingRight: '20px' } },
340
+ ],
341
+ data: userData,
342
+ ListItem: UserListItem,
343
+ divider: false,
344
+ },
345
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taiv/ui",
3
- "version": "1.10.1",
3
+ "version": "1.10.3",
4
4
  "author": "Taiv",
5
5
  "description": "Taiv's web UI Toolkit built on Mantine v6",
6
6
  "main": "dist/index.js",