From 5d2ccd712f3c4fc7891d71b979f182791808adfb Mon Sep 17 00:00:00 2001 From: mckervinc Date: Fri, 13 Dec 2024 12:56:19 -0500 Subject: [PATCH] deploy 1.1.0 --- CHANGELOG.md | 10 ++++++++++ index.d.ts | 16 ++++++++++++---- package.json | 2 +- src/components/Header.tsx | 17 ++++++++++------- src/components/Row.tsx | 35 +++++++++++++++++++++++------------ 5 files changed, 56 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da46e86..3e1460b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # CHANGELOG +## 1.1.0 + +_2024-12-13_ + +### Features + +- **BREAKING:** `headerCellClassname` and `contentCellClassname` are renamed to `headerClassname` and `contentClassname`. +- For columns, added `headerStyle` and `contentStyle` +- (chore)Fix index.d.ts typos + ## 1.0.3 _2024-12-12_ diff --git a/index.d.ts b/index.d.ts index 33e222a..89e2c9c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -136,9 +136,13 @@ export type ColumnProps = { */ header?: string | ((props: HeaderProps) => JSX.Element); /** - * specify a custom classNsme for the header. If `header` is NOT a strins, this is ignored. + * specify a custom className for the header. If `header` is NOT a string, this is ignored. */ - headerCellClassname?: string; + headerClassname?: string; + /** + * specify a custom style for the header. If `header` is NOT a string, this is ignored. + */ + headerStyle?: CSSProperties; /** * The width of a column in pixels. If this is set, the column will not resize. */ @@ -172,9 +176,13 @@ export type ColumnProps = { */ content?: string | number | ((props: CellProps) => ReactNode | JSX.Element); /** - * specify a custom classNsme for the content. If `cell` is specified, this is ignored. + * specify a custom className for the content. If `cell` is specified, this is ignored. + */ + contentClassname?: string | ((props: { row: T; index: number }) => string | undefined); + /** + * specify a custom style for the content. If `cell` is specified, this is ignored. */ - contentCellClassname?: string | ((props: { row: T; index: number }) => string); + contentStyle?: CSSProperties | ((props: { row: T; index: number }) => CSSProperties | undefined); /** * An advanced feature, this is used to render an entire cell, including the cell container. * The `content` prop is ignored if this property is enabled. diff --git a/package.json b/package.json index 9fabefc..cd0ee3b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-fluid-table", - "version": "1.0.3", + "version": "1.1.0", "description": "A React table inspired by @tanstack/react-virtual", "author": "Mckervin Ceme ", "license": "MIT", diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 72c9b8a..230f3ab 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -19,30 +19,33 @@ const HeaderCell = memo(function ({ sortedDir, onHeaderClick }: HeaderCellProps) { + // instance + const { key, sortable, frozen } = column; const style: React.CSSProperties = { - cursor: column.sortable ? "pointer" : undefined, + cursor: sortable ? "pointer" : undefined, width: width || undefined, minWidth: width || undefined, - left: column.frozen ? prevWidth : undefined + left: frozen ? prevWidth : undefined }; if (!column.header || typeof column.header === "string") { + const { headerStyle = {}, headerClassname } = column; return (
onHeaderClick(column)} - className={cx("rft-header-cell", column.frozen && "frozen", column.headerCellClassname)} + className={cx("rft-header-cell", frozen && "frozen", headerClassname)} > {column.header ?
{column.header}
: null} - {column.key !== sortedCol ? null : ( + {key !== sortedCol ? null : (
)}
); } - const headerDir = column.key === sortedCol ? sortedDir || null : null; - const frozenStyle: React.CSSProperties = column.frozen ? { position: "sticky", zIndex: 1 } : {}; + const headerDir = key === sortedCol ? sortedDir || null : null; + const frozenStyle: React.CSSProperties = frozen ? { position: "sticky", zIndex: 1 } : {}; return ( onHeaderClick(column)} diff --git a/src/components/Row.tsx b/src/components/Row.tsx index 19c0853..11d7136 100644 --- a/src/components/Row.tsx +++ b/src/components/Row.tsx @@ -23,33 +23,36 @@ const TableCell = memo(function ({ prevWidth, onExpanderClick }: TableCellProps) { - // cell style + // instance + const { frozen, contentClassname, contentStyle } = column; const style: React.CSSProperties = { width: width || undefined, minWidth: width || undefined, - left: column.frozen ? prevWidth : undefined + left: frozen ? prevWidth : undefined }; - // cell classname - const cellClass = column.contentCellClassname - ? typeof column.contentCellClassname === "string" - ? column.contentCellClassname - : column.contentCellClassname({ row, index }) - : null; - // expander if (column.expander) { + // cell classname + const cellClass = + typeof contentClassname === "function" ? contentClassname({ row, index }) : contentClassname; + if (typeof column.expander === "boolean") { const Logo = isExpanded ? Minus : Plus; + const cellStyle = + (typeof contentStyle === "function" ? contentStyle({ row, index }) : contentStyle) || {}; return ( -
+
); } - const frozenStyle: React.CSSProperties = column.frozen ? { position: "sticky", zIndex: 2 } : {}; + const frozenStyle: React.CSSProperties = frozen ? { position: "sticky", zIndex: 2 } : {}; return ( ({ // basic styling if (!column.cell) { + // cell classname/style + const cellClass = + typeof contentClassname === "function" ? contentClassname({ row, index }) : contentClassname; + const cellStyle = + (typeof contentStyle === "function" ? contentStyle({ row, index }) : contentStyle) || {}; let content = (row[column.key as keyof T] || null) as React.ReactNode; if (column.content) { if (typeof column.content === "string" || typeof column.content === "number") { @@ -73,7 +81,10 @@ const TableCell = memo(function ({ } return ( -
+
{content}
);