Skip to content

Commit 58d3d22

Browse files
authored
Merge pull request #94 from mckervinc/feature/refactor
Feature: Refactor
2 parents 03db961 + 284457e commit 58d3d22

35 files changed

+1680
-3529
lines changed

CHANGELOG.md

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

3+
## 1.0.0
4+
5+
_2024-12-12_
6+
7+
### Features
8+
9+
- **BREAKING:** Removed the following props: `borders`, `rowContainerStyle`, `rowContainerClassname`, `forceReset`, `ref`.
10+
- **BREAKING:** Renamed the following props: `tableStyle` -> `style`.
11+
- no more need for `clearSizeCache` in CellProps or SubComponentProps
12+
- `onExpandRow` now includes the mouse event as an optional parameter
13+
- all jitter should be removed
14+
315
## 0.6.4
416

517
_2024-12-09_

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# react-fluid-table
22

3-
> A React table inspired by react-window
4-
5-
(Note: This project is under construction)
3+
> A React table inspired by [@tanstack/react-virtual](https://github.com/TanStack/virtual)
64
75
[![NPM](https://img.shields.io/npm/v/react-fluid-table?style=flat-square)](https://www.npmjs.com/package/react-fluid-table) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square)](https://standardjs.com)
86

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@
6060
},
6161
"volta": {
6262
"node": "18.18.0",
63-
"yarn": "1.22.19"
63+
"yarn": "1.22.22"
6464
}
6565
}

example/src/ColumnProps.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,10 @@ const data: PropData[] = [
124124

125125
const ColumnPropsTable = () => (
126126
<Table
127-
borders
128127
data={data}
129128
columns={columns}
130129
tableHeight={400}
131-
className="border border-solid border-[#ececec] [&_.rft-cell:last]:border-none [&_.rft-cell]:border-r [&_.rft-cell]:border-solid [&_.rft-cell]:border-r-[#ececec] [&_.rft-header-cell-text]:text-[#ff79c5] [&_.rft-header-cell:last]:border-none [&_.rft-header-cell]:border-r [&_.rft-header-cell]:border-solid [&_.rft-header-cell]:border-r-[#ececec] [&_.rft-header]:bg-[#282a36]"
130+
className="border border-solid border-[#ececec] [&_.rft-cell:last]:border-none [&_.rft-cell]:border-r [&_.rft-cell]:border-solid [&_.rft-cell]:border-r-[#ececec] [&_.rft-header-cell-text]:text-[#ff79c5] [&_.rft-header-cell:last]:border-none [&_.rft-header-cell]:border-r [&_.rft-header-cell]:border-solid [&_.rft-header-cell]:border-r-[#ececec] [&_.rft-header]:bg-[#282a36] [&_.rft-row-container]:border-b [&_.rft-row-container]:border-b-[#ececec] last:[&_.rft-row-container]:border-b-0"
132131
/>
133132
);
134133

example/src/Props.tsx

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,7 @@ const data: PropData[] = [
152152
)
153153
},
154154
{
155-
prop: "borders",
156-
type: "boolean",
157-
description: "Controls whether or not there is a bottom border for each row",
158-
default: "false"
159-
},
160-
{
161-
prop: "tableStyle",
155+
prop: "style",
162156
type: "object",
163157
description: "Add custom css styles to the outer table element"
164158
},
@@ -184,18 +178,6 @@ const data: PropData[] = [
184178
description:
185179
"Add custom css className to each row element. One can also pass in a function that takes in the row number in order to provide custom styling for particular rows."
186180
},
187-
{
188-
prop: "rowContainerStyle",
189-
type: "object | (index: number) => object",
190-
description:
191-
"Add custom css styles to each row container element. One can also pass in a function that takes in the row number in order to provide custom styling for particular rows."
192-
},
193-
{
194-
prop: "rowContainerClassname",
195-
type: "string | (index: number) => string",
196-
description:
197-
"Add custom css className to each row container element. One can also pass in a function that takes in the row number in order to provide custom styling for particular rows."
198-
},
199181
{
200182
prop: "subComponent",
201183
type: "Element",
@@ -256,8 +238,7 @@ const Example = () => <Table data={data} columns={columns} />;
256238
`;
257239

258240
const cellSnippet = `
259-
const Contact = ({ row, index, style, clearSizeCache }) => {
260-
const mounted = useRef(false);
241+
const Contact = ({ row, style }) => {
261242
const [showInfo, setShowInfo] = useState(false);
262243
263244
const label = \`\${showInfo ? "hide" : "show"} contact info\`;
@@ -268,15 +249,6 @@ const Contact = ({ row, index, style, clearSizeCache }) => {
268249
269250
const onChange = () => setShowInfo(!showInfo);
270251
271-
// after something that might cause the row height to change,
272-
// you should call this function to get the new row height.
273-
useLayoutEffect(() => {
274-
if (mounted.current) {
275-
clearSizeCache(index, true);
276-
}
277-
mounted.current = true;
278-
}, [showInfo]);
279-
280252
return <Accordion style={style} label={label} options={options} onChange={onChange} />;
281253
};
282254
@@ -319,7 +291,6 @@ const Props = () => {
319291
</div>
320292
</div>
321293
<Table
322-
borders
323294
data={data}
324295
columns={columns}
325296
tableHeight={500}
@@ -366,12 +337,7 @@ const Props = () => {
366337
className="list-item w-full table-fixed list-none border-t border-solid border-[rgba(34,36,38,.15)] py-[.21428571em] leading-[1.14285714em] first:border-t-0 first:pt-0"
367338
>
368339
<div className="font-bold text-[rgba(0,0,0,.87)]">
369-
<code>CellElement</code>:{" "}
370-
<code>
371-
{
372-
"({ row: object, index: number, style?: React.CSSProperties, clearSizeCache: (index: number, forceUpdate?: boolean = false) => void }) => React.Element"
373-
}
374-
</code>
340+
<code>CellElement</code>: <code>{"({ row: object, index: number, style?: React.CSSProperties"}</code>
375341
</div>
376342
<div className="leading-[1.14285714em]">
377343
The CellElement is an element that takes in props that contains the row object itself, the index in the data

example/src/examples/02-sort.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ const Example = () => {
5555
5656
return (
5757
<Table
58-
borders
5958
data={data}
6059
columns={columns}
6160
itemKey={row => row.id}
@@ -85,7 +84,6 @@ const Example2 = () => {
8584

8685
return (
8786
<Table
88-
borders
8987
data={data}
9088
columns={columns}
9189
itemKey={row => row.id}

example/src/examples/03-sub.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ const Example = () => {
6060
6161
return (
6262
<Table
63-
borders
6463
data={data}
6564
columns={columns}
6665
tableHeight={400}
@@ -91,7 +90,6 @@ const Example3 = () => {
9190

9291
return (
9392
<Table
94-
borders
9593
data={data}
9694
columns={columns}
9795
tableHeight={400}

example/src/examples/04-custom.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,6 @@ const columns: ColumnProps<TestData>[] = [
363363
364364
const Example = () => (
365365
<Table
366-
borders
367366
data={data}
368367
columns={columns}
369368
tableHeight={400}
@@ -375,7 +374,7 @@ const Example = () => (
375374
const Example4 = () => {
376375
useTitle("Cell Content");
377376
useSource(Source);
378-
return <Table borders data={testData} columns={columns} tableHeight={400} rowHeight={150} />;
377+
return <Table data={testData} columns={columns} tableHeight={400} rowHeight={150} />;
379378
};
380379

381380
export { Example4 };

example/src/examples/05-variable.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const columns: ColumnProps<TestData>[] = [
3535
3636
const Example = () => (
3737
<Table
38-
borders
3938
data={data}
4039
columns={columns}
4140
tableHeight={400}
@@ -46,7 +45,7 @@ const Example = () => (
4645
const Example5 = () => {
4746
useTitle("Variable Row Size");
4847
useSource(Source);
49-
return <Table borders data={testData} columns={columns} tableHeight={400} />;
48+
return <Table data={testData} columns={columns} tableHeight={400} />;
5049
};
5150

5251
export { Example5 };

example/src/examples/06-expanded.tsx

Lines changed: 11 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
import {
2-
Accordion,
3-
AccordionContent,
4-
AccordionItem,
5-
AccordionTrigger
6-
} from "@/components/ui/accordion";
1+
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion";
72
import { useSource, useTitle } from "@/hooks/useTitle";
8-
import { useLayoutEffect, useRef, useState } from "react";
3+
import { useState } from "react";
94
import { ColumnProps, SubComponentProps, Table } from "react-fluid-table";
105
import { TestData, testData } from "../data";
116

@@ -37,55 +32,26 @@ const columns: ColumnProps<TestData>[] = [
3732
}
3833
];
3934

40-
const SubComponent = ({
41-
row,
42-
index,
43-
clearSizeCache
44-
}: SubComponentProps<TestData>) => {
35+
const SubComponent = ({ row }: SubComponentProps<TestData>) => {
4536
// hooks
46-
const prev = useRef("");
4737
const [value, setValue] = useState("");
4838

49-
// effects
50-
useLayoutEffect(() => {
51-
if (prev.current !== value) {
52-
clearSizeCache(index, { forceUpdate: true });
53-
clearSizeCache(index, { timeout: 200 });
54-
}
55-
prev.current = value;
56-
}, [value, index, clearSizeCache]);
57-
5839
return (
5940
<div className="bg-[#1b1c1d] px-3.5 py-2.5 text-white">
60-
<Accordion
61-
type="single"
62-
collapsible
63-
value={value}
64-
onValueChange={setValue}
65-
>
41+
<Accordion type="single" collapsible value={value} onValueChange={setValue}>
6642
<AccordionItem value="item-1">
67-
<AccordionTrigger>
68-
What is the address for this user?
69-
</AccordionTrigger>
70-
<AccordionContent>
71-
{`${row.address}, ${row.city}, ${row.state} ${row.zipCode}`}
72-
</AccordionContent>
43+
<AccordionTrigger>What is the address for this user?</AccordionTrigger>
44+
<AccordionContent>{`${row.address}, ${row.city}, ${row.state} ${row.zipCode}`}</AccordionContent>
7345
</AccordionItem>
7446
<AccordionItem value="item-2">
75-
<AccordionTrigger>
76-
What are the random sentences when you select this option?
77-
</AccordionTrigger>
47+
<AccordionTrigger>What are the random sentences when you select this option?</AccordionTrigger>
7848
<AccordionContent>{row.sentence}</AccordionContent>
7949
</AccordionItem>
8050
<AccordionItem value="item-3">
81-
<AccordionTrigger>
82-
What famous poem was included in Breaking Bad that referenced a
83-
king?
84-
</AccordionTrigger>
51+
<AccordionTrigger>What famous poem was included in Breaking Bad that referenced a king?</AccordionTrigger>
8552
<AccordionContent>
8653
<p>
87-
The poem is called <b>Ozymandias</b> by <b>Percy Bryce Shelley</b>
88-
. You can find the poem below:
54+
The poem is called <b>Ozymandias</b> by <b>Percy Bryce Shelley</b>. You can find the poem below:
8955
</p>
9056
<div>I met a traveller from an antique land,</div>
9157
<div>Who said—“Two vast and trunkless legs of stone</div>
@@ -119,24 +85,10 @@ const columns: ColumnProps<TestData>[] = [
11985
{ key: "email", header: "Email", width: 250 }
12086
];
12187
122-
const SubComponent = ({
123-
row,
124-
index,
125-
clearSizeCache
126-
}: SubComponentProps<TestData>) => {
88+
const SubComponent = ({ row }: SubComponentProps<TestData>) => {
12789
// hooks
128-
const prev = useRef("");
12990
const [value, setValue] = useState("");
13091
131-
// effects
132-
useLayoutEffect(() => {
133-
if (prev.current !== value) {
134-
clearSizeCache(index, { forceUpdate: true });
135-
clearSizeCache(index, { timeout: 200 });
136-
}
137-
prev.current = value;
138-
}, [value, index, clearSizeCache]);
139-
14092
return (
14193
<div className="bg-[#1b1c1d] px-3.5 py-2.5 text-white">
14294
<Accordion
@@ -192,7 +144,6 @@ const SubComponent = ({
192144
193145
const Example = () => (
194146
<Table
195-
borders
196147
data={data}
197148
columns={columns}
198149
subComponent={SubComponent}
@@ -204,15 +155,7 @@ const Example = () => (
204155
const Example6 = () => {
205156
useTitle("Expanded Row Height");
206157
useSource(Source);
207-
return (
208-
<Table
209-
borders
210-
data={testData}
211-
columns={columns}
212-
tableHeight={400}
213-
subComponent={SubComponent}
214-
/>
215-
);
158+
return <Table data={testData} columns={columns} tableHeight={400} subComponent={SubComponent} />;
216159
};
217160

218161
export { Example6, Source };

example/src/examples/07-controlled.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ const Controlled = ({ data, height, columns: variableColumns }: ControlledProps)
8888

8989
return (
9090
<Table
91-
borders
9291
data={rows}
9392
columns={variableColumns}
9493
tableHeight={height}
@@ -137,15 +136,16 @@ const Controlled = ({ data, columns: variableColumns }) => {
137136
}, [data]);
138137
139138
return (
140-
<StyledTable
141-
borders
139+
<Table
142140
data={rows}
143141
columns={variableColumns}
144142
tableHeight={400}
145143
rowHeight={35}
146144
onSort={onSort}
147145
sortColumn="firstName"
148146
sortDirection="ASC"
147+
className="border border-solid border-[#ececec]"
148+
headerClassname="bg-[#dedede]"
149149
/>
150150
);
151151
};

example/src/examples/08-header.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const Example = () => {
100100
sortColumn="firstName"
101101
sortDirection="ASC"
102102
rowStyle={rowStyle}
103-
tableStyle={{ backgroundColor: "#33be54" }}
103+
style={{ backgroundColor: "#33be54" }}
104104
headerStyle={{ backgroundColor: "#1e9f3f" }}
105105
/>
106106
);
@@ -136,7 +136,7 @@ const Example8 = () => {
136136
sortColumn="firstName"
137137
sortDirection="ASC"
138138
rowStyle={rowStyle}
139-
tableStyle={{ backgroundColor: "#33be54" }}
139+
style={{ backgroundColor: "#33be54" }}
140140
headerStyle={{ backgroundColor: "#1e9f3f" }}
141141
/>
142142
);

example/src/examples/09-scroll.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ const Example = () => {
7373
</Group>
7474
</Form>
7575
</Wrapper>
76-
<Table borders tableHeight={400} ref={ref} data={data} columns={columns} />
76+
<Table tableHeight={400} ref={ref} data={data} columns={columns} />
7777
</>
7878
);
7979
};
@@ -125,7 +125,7 @@ const Example9 = () => {
125125
</form>
126126
</Col>
127127
</Row>
128-
<Table borders ref={ref} data={testData} columns={columns} tableHeight={400} />
128+
<Table ref={ref} data={testData} columns={columns} tableHeight={400} />
129129
</>
130130
);
131131
};

0 commit comments

Comments
 (0)