tabulify 1.0.5 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.cjs.js CHANGED
@@ -4,7 +4,7 @@ var React = require('react');
4
4
 
5
5
  // Table Component
6
6
  var Table = function (_a) {
7
- var columns = _a.columns, dataSource = _a.dataSource, rowSelection = _a.rowSelection, pagination = _a.pagination;
7
+ var columns = _a.columns, dataSource = _a.dataSource, rowSelection = _a.rowSelection, pagination = _a.pagination, key = _a.key;
8
8
  var _b = React.useState((pagination === null || pagination === void 0 ? void 0 : pagination.current) || 1), currentPage = _b[0], setCurrentPage = _b[1];
9
9
  var pageSize = (pagination === null || pagination === void 0 ? void 0 : pagination.pageSize) || dataSource.length;
10
10
  // Handle pagination
@@ -22,8 +22,8 @@ var Table = function (_a) {
22
22
  React.createElement("thead", null,
23
23
  React.createElement("tr", null,
24
24
  rowSelection && React.createElement("th", null),
25
- columns.map(function (column) { return (React.createElement("th", { key: column.key }, column.title)); }))),
26
- React.createElement("tbody", null, paginatedData.map(function (record, index) { return (React.createElement("tr", { key: record.key }, columns.map(function (column) { return (React.createElement("td", { key: column.key }, column.render
25
+ columns.map(function (column) { return (React.createElement("th", { key: [column.key, Math.random].join('-') }, column.title)); }))),
26
+ React.createElement("tbody", null, paginatedData.map(function (record, index) { return (React.createElement("tr", { key: [record[key], Math.random].join('-') }, columns.map(function (column) { return (React.createElement("td", { key: [column.key, Math.random].join('-') }, column.render
27
27
  ? column.render(record[column.dataIndex], record, index)
28
28
  : record[column.dataIndex])); }))); }))),
29
29
  pagination && (React.createElement("div", { className: "pagination" }, Array.from({ length: Math.ceil(pagination.total / pageSize) }, function (_, i) { return i + 1; }).map(function (page) { return (React.createElement("button", { key: page, className: currentPage === page ? 'active' : '', onClick: function () { return handlePageChange(page); } }, page)); })))));
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/components/Table.tsx"],"sourcesContent":["import React, { useState } from 'react';\nimport { TableProps } from './Table.types';\n\n// Table Component\nconst Table = <T extends { key: React.Key }>({\n columns,\n dataSource,\n rowSelection,\n pagination,\n}: TableProps<T>) => {\n const [currentPage, setCurrentPage] = useState(pagination?.current || 1);\n\n const pageSize = pagination?.pageSize || dataSource.length;\n\n // Handle pagination\n const handlePageChange = (page: number) => {\n setCurrentPage(page);\n pagination?.onChange?.(page);\n };\n\n // Paginate data\n const paginatedData = pagination\n ? dataSource.slice((currentPage - 1) * pageSize, currentPage * pageSize)\n : dataSource;\n\n return (\n <div>\n <table>\n <thead>\n <tr>\n {rowSelection && <th></th>}\n {columns.map((column) => (\n <th key={column.key}>{column.title}</th>\n ))}\n </tr>\n </thead>\n <tbody>\n {paginatedData.map((record, index) => (\n <tr key={record.key}>\n {columns.map((column) => (\n <td key={column.key}>\n {column.render\n ? column.render(record[column.dataIndex], record, index)\n : (record[column.dataIndex] as React.ReactNode)}\n </td>\n ))}\n </tr>\n ))}\n </tbody>\n </table>\n {pagination && (\n <div className=\"pagination\">\n {Array.from(\n { length: Math.ceil(pagination.total / pageSize) },\n (_, i) => i + 1\n ).map((page) => (\n <button\n key={page}\n className={currentPage === page ? 'active' : ''}\n onClick={() => handlePageChange(page)}\n >\n {page}\n </button>\n ))}\n </div>\n )}\n </div>\n );\n};\n\nexport default Table;\n"],"names":["useState"],"mappings":";;;;AAGA;AACM,IAAA,KAAK,GAAG,UAA+B,EAK7B,EAAA;QAJd,OAAO,GAAA,EAAA,CAAA,OAAA,EACP,UAAU,GAAA,EAAA,CAAA,UAAA,EACV,YAAY,GAAA,EAAA,CAAA,YAAA,EACZ,UAAU,GAAA,EAAA,CAAA,UAAA;IAEJ,IAAA,EAAA,GAAgCA,cAAQ,CAAC,CAAA,UAAU,KAAV,IAAA,IAAA,UAAU,uBAAV,UAAU,CAAE,OAAO,KAAI,CAAC,CAAC,EAAjE,WAAW,QAAA,EAAE,cAAc,QAAsC;AAExE,IAAA,IAAM,QAAQ,GAAG,CAAA,UAAU,aAAV,UAAU,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAA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AA,EAAK,QACvB,KAAA,CAAA,aAAA,CAAA,IAAA,EAAA,EAAI,GAAG,EAAE,MAAM,CAAC,GAAG,EAChB,EAAA,MAAM,CAAC;AACN,kBAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK;AACvD,kBAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAqB,CAC9C,EALkB,EAMxB,CAAC,CACC,IACN,CAAC,CACI,CACF;AACP,QAAA,UAAU,KACT,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,YAAY,IACxB,KAAK,CAAC,IAAI,CACT,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,GAAG,QAAQ,CAAC,EAAE,EAClD,UAAC,CAAC,EAAE,CAAC,EAAA,EAAK,OAAA,CAAC,GAAG,CAAC,CAAL,EAAK,CAChB,CAAC,GAAG,CAAC,UAAC,IAAI,EAAK,EAAA,QACd,KACE,CAAA,aAAA,CAAA,QAAA,EAAA,EAAA,GAAG,EAAE,IAAI,EACT,SAAS,EAAE,WAAW,KAAK,IAAI,GAAG,QAAQ,GAAG,EAAE,EAC/C,OAAO,EAAE,cAAM,OAAA,gBAAgB,CAAC,IAAI,CAAC,GAAA,EAAA,EAEpC,IAAI,CACE,IACV,CAAC,CACE,CACP,CACG;AAEV;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/components/Table.tsx"],"sourcesContent":["import React, { useState } from 'react';\nimport { TableProps } from './Table.types';\n\n// Table Component\nconst Table = <T,>({\n columns,\n dataSource,\n rowSelection,\n pagination,\n key,\n}: TableProps<T>) => {\n const [currentPage, setCurrentPage] = useState(pagination?.current || 1);\n\n const pageSize = pagination?.pageSize || dataSource.length;\n\n // Handle pagination\n const handlePageChange = (page: number) => {\n setCurrentPage(page);\n pagination?.onChange?.(page);\n };\n\n // Paginate data\n const paginatedData = pagination\n ? dataSource.slice((currentPage - 1) * pageSize, currentPage * pageSize)\n : dataSource;\n\n return (\n <div>\n <table>\n <thead>\n <tr>\n {rowSelection && <th></th>}\n {columns.map((column) => (\n <th key={[column.key, Math.random].join('-')}>{column.title}</th>\n ))}\n </tr>\n </thead>\n <tbody>\n {paginatedData.map((record, index) => (\n <tr key={[record[key], Math.random].join('-')}>\n {columns.map((column) => (\n <td key={[column.key, Math.random].join('-')}>\n {column.render\n ? column.render(record[column.dataIndex], record, index)\n : (record[column.dataIndex] as React.ReactNode)}\n </td>\n ))}\n </tr>\n ))}\n </tbody>\n </table>\n {pagination && (\n <div className=\"pagination\">\n {Array.from(\n { length: Math.ceil(pagination.total / pageSize) },\n (_, i) => i + 1\n ).map((page) => (\n <button\n key={page}\n className={currentPage === page ? 'active' : ''}\n onClick={() => handlePageChange(page)}\n >\n {page}\n </button>\n ))}\n </div>\n )}\n </div>\n );\n};\n\nexport default Table;\n"],"names":["useState"],"mappings":";;;;AAGA;AACM,IAAA,KAAK,GAAG,UAAK,EAMH,EAAA;AALd,IAAA,IAAA,OAAO,GAAA,EAAA,CAAA,OAAA,EACP,UAAU,GAAA,EAAA,CAAA,UAAA,EACV,YAAY,GAAA,EAAA,CAAA,YAAA,EACZ,UAAU,GAAA,EAAA,CAAA,UAAA,EACV,GAAG,GAAA,EAAA,CAAA,GAAA;IAEG,IAAA,EAAA,GAAgCA,cAAQ,CAAC,CAAA,UAAU,KAAV,IAAA,IAAA,UAAU,uBAAV,UAAU,CAAE,OAAO,KAAI,CAAC,CAAC,EAAjE,WAAW,QAAA,EAAE,cAAc,QAAsC;AAExE,IAAA,IAAM,QAAQ,GAAG,CAAA,UAAU,aAAV,UAAU,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAV,UAAU,CAAE,QAAQ,KAAI,UAAU,CAAC,MAAM;;IAG1D,IAAM,gBAAgB,GAAG,UAAC,IAAY,EAAA;;QACpC,cAAc,CAAC,IAAI,CAAC;QACpB,CAAA,EAAA,GAAA,UA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AAK,QACvB,KAAI,CAAA,aAAA,CAAA,IAAA,EAAA,EAAA,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAA,EACzC,MAAM,CAAC;AACN,kBAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK;AACvD,kBAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAqB,CAC9C,EALkB,EAMxB,CAAC,CACC,IACN,CAAC,CACI,CACF;AACP,QAAA,UAAU,KACT,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,YAAY,IACxB,KAAK,CAAC,IAAI,CACT,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,GAAG,QAAQ,CAAC,EAAE,EAClD,UAAC,CAAC,EAAE,CAAC,EAAA,EAAK,OAAA,CAAC,GAAG,CAAC,CAAL,EAAK,CAChB,CAAC,GAAG,CAAC,UAAC,IAAI,EAAK,EAAA,QACd,KACE,CAAA,aAAA,CAAA,QAAA,EAAA,EAAA,GAAG,EAAE,IAAI,EACT,SAAS,EAAE,WAAW,KAAK,IAAI,GAAG,QAAQ,GAAG,EAAE,EAC/C,OAAO,EAAE,cAAM,OAAA,gBAAgB,CAAC,IAAI,CAAC,GAAA,EAAA,EAEpC,IAAI,CACE,IACV,CAAC,CACE,CACP,CACG;AAEV;;;;"}
package/dist/index.esm.js CHANGED
@@ -2,7 +2,7 @@ import React, { useState } from 'react';
2
2
 
3
3
  // Table Component
4
4
  var Table = function (_a) {
5
- var columns = _a.columns, dataSource = _a.dataSource, rowSelection = _a.rowSelection, pagination = _a.pagination;
5
+ var columns = _a.columns, dataSource = _a.dataSource, rowSelection = _a.rowSelection, pagination = _a.pagination, key = _a.key;
6
6
  var _b = useState((pagination === null || pagination === void 0 ? void 0 : pagination.current) || 1), currentPage = _b[0], setCurrentPage = _b[1];
7
7
  var pageSize = (pagination === null || pagination === void 0 ? void 0 : pagination.pageSize) || dataSource.length;
8
8
  // Handle pagination
@@ -20,8 +20,8 @@ var Table = function (_a) {
20
20
  React.createElement("thead", null,
21
21
  React.createElement("tr", null,
22
22
  rowSelection && React.createElement("th", null),
23
- columns.map(function (column) { return (React.createElement("th", { key: column.key }, column.title)); }))),
24
- React.createElement("tbody", null, paginatedData.map(function (record, index) { return (React.createElement("tr", { key: record.key }, columns.map(function (column) { return (React.createElement("td", { key: column.key }, column.render
23
+ columns.map(function (column) { return (React.createElement("th", { key: [column.key, Math.random].join('-') }, column.title)); }))),
24
+ React.createElement("tbody", null, paginatedData.map(function (record, index) { return (React.createElement("tr", { key: [record[key], Math.random].join('-') }, columns.map(function (column) { return (React.createElement("td", { key: [column.key, Math.random].join('-') }, column.render
25
25
  ? column.render(record[column.dataIndex], record, index)
26
26
  : record[column.dataIndex])); }))); }))),
27
27
  pagination && (React.createElement("div", { className: "pagination" }, Array.from({ length: Math.ceil(pagination.total / pageSize) }, function (_, i) { return i + 1; }).map(function (page) { return (React.createElement("button", { key: page, className: currentPage === page ? 'active' : '', onClick: function () { return handlePageChange(page); } }, page)); })))));
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/components/Table.tsx"],"sourcesContent":["import React, { useState } from 'react';\nimport { TableProps } from './Table.types';\n\n// Table Component\nconst Table = <T extends { key: React.Key }>({\n columns,\n dataSource,\n rowSelection,\n pagination,\n}: TableProps<T>) => {\n const [currentPage, setCurrentPage] = useState(pagination?.current || 1);\n\n const pageSize = pagination?.pageSize || dataSource.length;\n\n // Handle pagination\n const handlePageChange = (page: number) => {\n setCurrentPage(page);\n pagination?.onChange?.(page);\n };\n\n // Paginate data\n const paginatedData = pagination\n ? dataSource.slice((currentPage - 1) * pageSize, currentPage * pageSize)\n : dataSource;\n\n return (\n <div>\n <table>\n <thead>\n <tr>\n {rowSelection && <th></th>}\n {columns.map((column) => (\n <th key={column.key}>{column.title}</th>\n ))}\n </tr>\n </thead>\n <tbody>\n {paginatedData.map((record, index) => (\n <tr key={record.key}>\n {columns.map((column) => (\n <td key={column.key}>\n {column.render\n ? column.render(record[column.dataIndex], record, index)\n : (record[column.dataIndex] as React.ReactNode)}\n </td>\n ))}\n </tr>\n ))}\n </tbody>\n </table>\n {pagination && (\n <div className=\"pagination\">\n {Array.from(\n { length: Math.ceil(pagination.total / pageSize) },\n (_, i) => i + 1\n ).map((page) => (\n <button\n key={page}\n className={currentPage === page ? 'active' : ''}\n onClick={() => handlePageChange(page)}\n >\n {page}\n </button>\n ))}\n </div>\n )}\n </div>\n );\n};\n\nexport default Table;\n"],"names":[],"mappings":";;AAGA;AACM,IAAA,KAAK,GAAG,UAA+B,EAK7B,EAAA;QAJd,OAAO,GAAA,EAAA,CAAA,OAAA,EACP,UAAU,GAAA,EAAA,CAAA,UAAA,EACV,YAAY,GAAA,EAAA,CAAA,YAAA,EACZ,UAAU,GAAA,EAAA,CAAA,UAAA;IAEJ,IAAA,EAAA,GAAgC,QAAQ,CAAC,CAAA,UAAU,KAAV,IAAA,IAAA,UAAU,uBAAV,UAAU,CAAE,OAAO,KAAI,CAAC,CAAC,EAAjE,WAAW,QAAA,EAAE,cAAc,QAAsC;AAExE,IAAA,IAAM,QAAQ,GAAG,CAAA,UAAU,aAAV,UAAU,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAV,UAAU,CAAE,QAAQ,KAAI,UAAU,CAAC,MAAM;;IAG1D,IAAM,gBAAgB,GAAG,UAAC,IAAY,EAAA;;QACpC,cAAc,CAAC,IAAI,CAAC;QACpB,CAAA,EAAA,GAAA,UAAU,KAAV,IAAA,IAAA,UAAU,KAAV,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,UAAU,CAAE,QAAQ,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,IAAA,CAAA,UAAA,EAAG,IA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aAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,YAAY,IACxB,KAAK,CAAC,IAAI,CACT,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,GAAG,QAAQ,CAAC,EAAE,EAClD,UAAC,CAAC,EAAE,CAAC,EAAA,EAAK,OAAA,CAAC,GAAG,CAAC,CAAL,EAAK,CAChB,CAAC,GAAG,CAAC,UAAC,IAAI,EAAK,EAAA,QACd,KACE,CAAA,aAAA,CAAA,QAAA,EAAA,EAAA,GAAG,EAAE,IAAI,EACT,SAAS,EAAE,WAAW,KAAK,IAAI,GAAG,QAAQ,GAAG,EAAE,EAC/C,OAAO,EAAE,cAAM,OAAA,gBAAgB,CAAC,IAAI,CAAC,GAAA,EAAA,EAEpC,IAAI,CACE,IACV,CAAC,CACE,CACP,CACG;AAEV;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/components/Table.tsx"],"sourcesContent":["import React, { useState } from 'react';\nimport { TableProps } from './Table.types';\n\n// Table Component\nconst Table = <T,>({\n columns,\n dataSource,\n rowSelection,\n pagination,\n key,\n}: TableProps<T>) => {\n const [currentPage, setCurrentPage] = useState(pagination?.current || 1);\n\n const pageSize = pagination?.pageSize || dataSource.length;\n\n // Handle pagination\n const handlePageChange = (page: number) => {\n setCurrentPage(page);\n pagination?.onChange?.(page);\n };\n\n // Paginate data\n const paginatedData = pagination\n ? dataSource.slice((currentPage - 1) * pageSize, currentPage * pageSize)\n : dataSource;\n\n return (\n <div>\n <table>\n <thead>\n <tr>\n {rowSelection && <th></th>}\n {columns.map((column) => (\n <th key={[column.key, Math.random].join('-')}>{column.title}</th>\n ))}\n </tr>\n </thead>\n <tbody>\n {paginatedData.map((record, index) => (\n <tr key={[record[key], Math.random].join('-')}>\n {columns.map((column) => (\n <td key={[column.key, Math.random].join('-')}>\n {column.render\n ? column.render(record[column.dataIndex], record, index)\n : (record[column.dataIndex] as React.ReactNode)}\n </td>\n ))}\n </tr>\n ))}\n </tbody>\n </table>\n {pagination && (\n <div className=\"pagination\">\n {Array.from(\n { length: Math.ceil(pagination.total / pageSize) },\n (_, i) => i + 1\n ).map((page) => (\n <button\n key={page}\n className={currentPage === page ? 'active' : ''}\n onClick={() => handlePageChange(page)}\n >\n {page}\n </button>\n ))}\n </div>\n )}\n </div>\n );\n};\n\nexport default Table;\n"],"names":[],"mappings":";;AAGA;AACM,IAAA,KAAK,GAAG,UAAK,EAMH,EAAA;AALd,IAAA,IAAA,OAAO,GAAA,EAAA,CAAA,OAAA,EACP,UAAU,GAAA,EAAA,CAAA,UAAA,EACV,YAAY,GAAA,EAAA,CAAA,YAAA,EACZ,UAAU,GAAA,EAAA,CAAA,UAAA,EACV,GAAG,GAAA,EAAA,CAAA,GAAA;IAEG,IAAA,EAAA,GAAgC,QAAQ,CAAC,CAAA,UAAU,KAAV,IAAA,IAAA,UAAU,uBAAV,UAAU,CAAE,OAAO,KAAI,CAAC,CAAC,EAAjE,WAAW,QAAA,EAAE,cAAc,QAAsC;AAExE,IAAA,IAAM,QAAQ,GAAG,CAAA,UAAU,aAAV,UAAU,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAV,UAAU,CAAE,QAAQ,KAAI,UAAU,CAAC,MAAM;;IAG1D,IAAM,gBAAgB,GAAG,UAAC,IAAY,EAAA;;QACpC,cAAc,CAAC,IAAI,CAAC;QACpB,CAAA,EAAA,GAAA,UAAU,KAAV,IAAA,IAAA,UAAU,KAAV,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,UAAU,CAAE,QAAQ,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,IAAA,CAAA,UAAA,EAAG,IAAI,CAAC;AAC9B,KAAC;;IAGD,IAAM,aAAa,GAAG;AACpB,UAAE,UAAU,CAAC,KAAK,CAAC,CAAC,WAAW,GAAG,CAAC,IAAI,QAAQ,EAAE,WAAW,GAAG,QAAQ;UACrE,UAAU;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ACN,CAAC,CACI,CACF;AACP,QAAA,UAAU,KACT,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,YAAY,IACxB,KAAK,CAAC,IAAI,CACT,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,GAAG,QAAQ,CAAC,EAAE,EAClD,UAAC,CAAC,EAAE,CAAC,EAAA,EAAK,OAAA,CAAC,GAAG,CAAC,CAAL,EAAK,CAChB,CAAC,GAAG,CAAC,UAAC,IAAI,EAAK,EAAA,QACd,KACE,CAAA,aAAA,CAAA,QAAA,EAAA,EAAA,GAAG,EAAE,IAAI,EACT,SAAS,EAAE,WAAW,KAAK,IAAI,GAAG,QAAQ,GAAG,EAAE,EAC/C,OAAO,EAAE,cAAM,OAAA,gBAAgB,CAAC,IAAI,CAAC,GAAA,EAAA,EAEpC,IAAI,CACE,IACV,CAAC,CACE,CACP,CACG;AAEV;;;;"}
@@ -1,6 +1,4 @@
1
1
  import React from 'react';
2
2
  import { TableProps } from './Table.types';
3
- declare const Table: <T extends {
4
- key: React.Key;
5
- }>({ columns, dataSource, rowSelection, pagination, }: TableProps<T>) => React.JSX.Element;
3
+ declare const Table: <T>({ columns, dataSource, rowSelection, pagination, key, }: TableProps<T>) => React.JSX.Element;
6
4
  export default Table;
@@ -1,10 +1,10 @@
1
1
  import React from 'react';
2
- export interface Column<T> {
2
+ export interface Column<T, K extends keyof T = keyof T> {
3
3
  title: string;
4
- dataIndex: keyof T;
5
- key: string;
4
+ dataIndex: K;
5
+ key: K;
6
6
  sorter?: (a: T, b: T) => number;
7
- render?: (value: T[keyof T], record: T, index: number) => React.ReactNode;
7
+ render?: (value: T[K], record: T, index: number) => React.ReactNode;
8
8
  }
9
9
  export interface RowSelection<T> {
10
10
  type: 'checkbox' | 'radio';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tabulify",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "type": "module",
5
5
  "description": "A lightweight and customizable React table component.",
6
6
  "main": "dist/index.js",