Skip to content

Commit 5d2ccd7

Browse files
committed
deploy 1.1.0
1 parent 6629a6d commit 5d2ccd7

File tree

5 files changed

+56
-24
lines changed

5 files changed

+56
-24
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# CHANGELOG
22

3+
## 1.1.0
4+
5+
_2024-12-13_
6+
7+
### Features
8+
9+
- **BREAKING:** `headerCellClassname` and `contentCellClassname` are renamed to `headerClassname` and `contentClassname`.
10+
- For columns, added `headerStyle` and `contentStyle`
11+
- (chore)Fix index.d.ts typos
12+
313
## 1.0.3
414

515
_2024-12-12_

index.d.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,13 @@ export type ColumnProps<T> = {
136136
*/
137137
header?: string | ((props: HeaderProps) => JSX.Element);
138138
/**
139-
* specify a custom classNsme for the header. If `header` is NOT a strins, this is ignored.
139+
* specify a custom className for the header. If `header` is NOT a string, this is ignored.
140140
*/
141-
headerCellClassname?: string;
141+
headerClassname?: string;
142+
/**
143+
* specify a custom style for the header. If `header` is NOT a string, this is ignored.
144+
*/
145+
headerStyle?: CSSProperties;
142146
/**
143147
* The width of a column in pixels. If this is set, the column will not resize.
144148
*/
@@ -172,9 +176,13 @@ export type ColumnProps<T> = {
172176
*/
173177
content?: string | number | ((props: CellProps<T>) => ReactNode | JSX.Element);
174178
/**
175-
* specify a custom classNsme for the content. If `cell` is specified, this is ignored.
179+
* specify a custom className for the content. If `cell` is specified, this is ignored.
180+
*/
181+
contentClassname?: string | ((props: { row: T; index: number }) => string | undefined);
182+
/**
183+
* specify a custom style for the content. If `cell` is specified, this is ignored.
176184
*/
177-
contentCellClassname?: string | ((props: { row: T; index: number }) => string);
185+
contentStyle?: CSSProperties | ((props: { row: T; index: number }) => CSSProperties | undefined);
178186
/**
179187
* An advanced feature, this is used to render an entire cell, including the cell container.
180188
* The `content` prop is ignored if this property is enabled.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-fluid-table",
3-
"version": "1.0.3",
3+
"version": "1.1.0",
44
"description": "A React table inspired by @tanstack/react-virtual",
55
"author": "Mckervin Ceme <mckervinc@live.com>",
66
"license": "MIT",

src/components/Header.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,33 @@ const HeaderCell = memo(function <T>({
1919
sortedDir,
2020
onHeaderClick
2121
}: HeaderCellProps<T>) {
22+
// instance
23+
const { key, sortable, frozen } = column;
2224
const style: React.CSSProperties = {
23-
cursor: column.sortable ? "pointer" : undefined,
25+
cursor: sortable ? "pointer" : undefined,
2426
width: width || undefined,
2527
minWidth: width || undefined,
26-
left: column.frozen ? prevWidth : undefined
28+
left: frozen ? prevWidth : undefined
2729
};
2830

2931
if (!column.header || typeof column.header === "string") {
32+
const { headerStyle = {}, headerClassname } = column;
3033
return (
3134
<div
32-
style={style}
35+
style={{ ...headerStyle, ...style }}
3336
onClick={() => onHeaderClick(column)}
34-
className={cx("rft-header-cell", column.frozen && "frozen", column.headerCellClassname)}
37+
className={cx("rft-header-cell", frozen && "frozen", headerClassname)}
3538
>
3639
{column.header ? <div className="rft-header-cell-text">{column.header}</div> : null}
37-
{column.key !== sortedCol ? null : (
40+
{key !== sortedCol ? null : (
3841
<div className={cx("rft-header-cell-arrow", sortedDir?.toLowerCase())}></div>
3942
)}
4043
</div>
4144
);
4245
}
4346

44-
const headerDir = column.key === sortedCol ? sortedDir || null : null;
45-
const frozenStyle: React.CSSProperties = column.frozen ? { position: "sticky", zIndex: 1 } : {};
47+
const headerDir = key === sortedCol ? sortedDir || null : null;
48+
const frozenStyle: React.CSSProperties = frozen ? { position: "sticky", zIndex: 1 } : {};
4649
return (
4750
<column.header
4851
onClick={() => onHeaderClick(column)}

src/components/Row.tsx

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,36 @@ const TableCell = memo(function <T>({
2323
prevWidth,
2424
onExpanderClick
2525
}: TableCellProps<T>) {
26-
// cell style
26+
// instance
27+
const { frozen, contentClassname, contentStyle } = column;
2728
const style: React.CSSProperties = {
2829
width: width || undefined,
2930
minWidth: width || undefined,
30-
left: column.frozen ? prevWidth : undefined
31+
left: frozen ? prevWidth : undefined
3132
};
3233

33-
// cell classname
34-
const cellClass = column.contentCellClassname
35-
? typeof column.contentCellClassname === "string"
36-
? column.contentCellClassname
37-
: column.contentCellClassname({ row, index })
38-
: null;
39-
4034
// expander
4135
if (column.expander) {
36+
// cell classname
37+
const cellClass =
38+
typeof contentClassname === "function" ? contentClassname({ row, index }) : contentClassname;
39+
4240
if (typeof column.expander === "boolean") {
4341
const Logo = isExpanded ? Minus : Plus;
42+
const cellStyle =
43+
(typeof contentStyle === "function" ? contentStyle({ row, index }) : contentStyle) || {};
4444

4545
return (
46-
<div className={cx("rft-cell", column.frozen && "frozen", cellClass)} style={style}>
46+
<div
47+
className={cx("rft-cell", frozen && "frozen", cellClass)}
48+
style={{ ...cellStyle, ...style }}
49+
>
4750
<Logo className="rft-expander" onClick={onExpanderClick} />
4851
</div>
4952
);
5053
}
5154

52-
const frozenStyle: React.CSSProperties = column.frozen ? { position: "sticky", zIndex: 2 } : {};
55+
const frozenStyle: React.CSSProperties = frozen ? { position: "sticky", zIndex: 2 } : {};
5356
return (
5457
<column.expander
5558
row={row}
@@ -63,6 +66,11 @@ const TableCell = memo(function <T>({
6366

6467
// basic styling
6568
if (!column.cell) {
69+
// cell classname/style
70+
const cellClass =
71+
typeof contentClassname === "function" ? contentClassname({ row, index }) : contentClassname;
72+
const cellStyle =
73+
(typeof contentStyle === "function" ? contentStyle({ row, index }) : contentStyle) || {};
6674
let content = (row[column.key as keyof T] || null) as React.ReactNode;
6775
if (column.content) {
6876
if (typeof column.content === "string" || typeof column.content === "number") {
@@ -73,7 +81,10 @@ const TableCell = memo(function <T>({
7381
}
7482

7583
return (
76-
<div className={cx("rft-cell", column.frozen && "frozen", cellClass)} style={style}>
84+
<div
85+
className={cx("rft-cell", frozen && "frozen", cellClass)}
86+
style={{ ...cellStyle, ...style }}
87+
>
7788
{content}
7889
</div>
7990
);

0 commit comments

Comments
 (0)