Skip to content

Commit 7748dbb

Browse files
authored
Merge pull request #81 from mckervinc/feature/footer
update footer props
2 parents 748b56a + bfb8a38 commit 7748dbb

13 files changed

+264
-51
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ rollup.config.js
3434
.env.test.local
3535
.env.production.local
3636
.travis.yml
37+
.github

CHANGELOG.md

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

3+
## 0.4.6
4+
5+
_2023-09-28_
6+
7+
### Features
8+
9+
- added `minTableHeight` and `maxTableHeight`
10+
- added footer styling with `footerStyle` and `footerClassname`
11+
- expose column widths to `footerComponent` to help expose widths
12+
313
## 0.4.5
414

515
_2023-09-27_

example/src/Props.tsx

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ const data: PropData[] = [
121121
description:
122122
"The height of the table in pixels. If no height is specified, this will try to fill the height of the parent. If the parent node does not have a height specified, a height for the table will be calculated based on the default header height and the rowHeight or the defaultRowHeight (37)."
123123
},
124+
{
125+
prop: "minTableHeight",
126+
type: "number",
127+
description: "The min height of the table in pixels."
128+
},
129+
{
130+
prop: "maxTableHeight",
131+
type: "number",
132+
description:
133+
"The max height of the table in pixels. If tableHeight is specified, this is ignored."
134+
},
124135
{
125136
prop: "tableWidth",
126137
type: "number",
@@ -179,7 +190,7 @@ const data: PropData[] = [
179190
},
180191
{
181192
prop: "headerClassname",
182-
type: "object",
193+
type: "string",
183194
description: "Add custom css className to the table header"
184195
},
185196
{
@@ -212,9 +223,19 @@ const data: PropData[] = [
212223
},
213224
{
214225
prop: "footerComponent",
215-
type: "() => Element",
226+
type: "(props: FooterProps) => Element",
216227
description: "You can provide an optional footer"
217228
},
229+
{
230+
prop: "footerStyle",
231+
type: "object",
232+
description: "Add custom css styles to the table footer"
233+
},
234+
{
235+
prop: "footerClassname",
236+
type: "string",
237+
description: "Add custom css className to the table footer"
238+
},
218239
{
219240
prop: "stickyFooter",
220241
type: "boolean",
@@ -266,7 +287,7 @@ const Contact = ({ row, index, style, clearSizeCache }) => {
266287
mounted.current = true;
267288
}, [showInfo]);
268289
269-
return <Accordion label={label} options={options} onChange={onChange} />;
290+
return <Accordion style={style} label={label} options={options} onChange={onChange} />;
270291
};
271292
272293
const columns = [{
@@ -336,7 +357,7 @@ const Props = () => (
336357
The HeaderElement is an element that takes in props that contains a style, onclick, and
337358
sortDirection. See below for an example:
338359
</List.Content>
339-
<Snippet copy={false} edit={false} code={headerSnippet} />
360+
<Snippet copy={false} code={headerSnippet} />
340361
</Item>
341362
<Item>
342363
<List.Header>
@@ -352,7 +373,7 @@ const Props = () => (
352373
index in the data array, and a function to reset the rowHeight (if needed). See below for
353374
an example:
354375
</List.Content>
355-
<Snippet copy={false} edit={false} code={cellSnippet} />
376+
<Snippet copy={false} code={cellSnippet} />
356377
</Item>
357378
<Item>
358379
<List.Header>
@@ -363,7 +384,7 @@ const Props = () => (
363384
The ExpandedElement is an element that takes in props that contains whether or not the row
364385
is expanded, as well as a function to toggle the row expansion. See below for an example:
365386
</List.Content>
366-
<Snippet copy={false} edit={false} code={expanderSnippet} />
387+
<Snippet copy={false} code={expanderSnippet} />
367388
</Item>
368389
</List>
369390
<Header dividing size="small" color="grey">

example/src/Snippet.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { useRef, useState } from "react";
22
import { PrismLight as SyntaxHighlighter } from "react-syntax-highlighter";
3-
import jsx from "react-syntax-highlighter/dist/esm/languages/prism/jsx";
3+
import tsx from "react-syntax-highlighter/dist/esm/languages/prism/tsx";
44
import okaidia from "react-syntax-highlighter/dist/esm/styles/prism/okaidia";
55
import { Icon, Menu, Popup } from "semantic-ui-react";
66
import styled from "styled-components";
77
import { copy } from "./util";
88

9-
SyntaxHighlighter.registerLanguage("jsx", jsx);
9+
SyntaxHighlighter.registerLanguage("tsx", tsx);
1010

1111
const Container = styled.div`
1212
position: relative;
@@ -56,7 +56,7 @@ interface SnippetProps {
5656
edit?: boolean;
5757
}
5858

59-
const Snippet = ({ code, copy: showCopy = true, edit = true }: SnippetProps) => {
59+
const Snippet = ({ code, copy: showCopy = true, edit = false }: SnippetProps) => {
6060
const ref = useRef(0);
6161
const [open, setOpen] = useState(false);
6262
const onOpen = () => {
@@ -98,7 +98,7 @@ const Snippet = ({ code, copy: showCopy = true, edit = true }: SnippetProps) =>
9898
</MenuItem>
9999
)}
100100
</Group>
101-
<Highligher language="jsx" style={okaidia}>
101+
<Highligher language="tsx" style={okaidia}>
102102
{code.trim()}
103103
</Highligher>
104104
</Container>

example/src/examples/04-custom.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,29 +336,29 @@ const columns: ColumnProps<TestData>[] = [
336336
key: "avatar",
337337
header: "Profile Photo",
338338
width: 150,
339-
content: ({ row}) => <ProfPic size="small" src={row.avatar} />
339+
content: ({ row }) => <ProfPic size="small" src={row.avatar} />
340340
},
341341
{
342342
key: "email",
343343
header: "Email",
344-
content: ({ row}) => <Email email={row.email} />
344+
content: ({ row }) => <Email email={row.email} />
345345
},
346346
{
347347
key: "firstName",
348348
header: "First",
349349
width: 100,
350-
content: ({ row}) => <TextStyle>{row.firstName}</TextStyle>
350+
content: ({ row }) => <TextStyle>{row.firstName}</TextStyle>
351351
},
352352
{
353353
key: "lastName",
354354
header: "Last",
355355
width: 100,
356-
content: ({ row}) => <TextStyle>{row.lastName}</TextStyle>
356+
content: ({ row }) => <TextStyle>{row.lastName}</TextStyle>
357357
},
358358
{
359359
key: "country",
360360
header: "Country",
361-
content: ({ row}) =>
361+
content: ({ row }) =>
362362
!countryMap[row.country] ? (
363363
\`No flag for this country: \${row.country.toUpperCase()}\`
364364
) : (

example/src/examples/10-footer.tsx

Lines changed: 79 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,49 +19,54 @@ const columns: ColumnProps<TestData>[] = [
1919
{
2020
key: "id",
2121
header: "ID",
22-
sortable: true,
2322
width: 50
2423
},
2524
{
2625
key: "firstName",
2726
header: "First",
28-
sortable: true,
2927
width: 120
3028
},
3129
{
3230
key: "lastName",
3331
header: "Last",
34-
sortable: true,
3532
width: 120
3633
},
3734
{
3835
key: "email",
3936
header: "Email",
40-
sortable: true,
4137
width: 250
4238
}
4339
];
4440

4541
const Footer = styled.div`
4642
background-color: white;
47-
padding: 8px;
4843
`;
4944

5045
const Example10 = () => {
5146
// hooks
5247
const [sticky, setSticky] = useState(true);
48+
const [simple, setSimple] = useState(true);
5349

5450
return (
5551
<>
5652
<Grid stackable columns={2}>
5753
<Grid.Row>
5854
<Grid.Column width={8}>
5955
<Form>
60-
<h4>Change footer stickyness</h4>
56+
<h4>Change footer properties</h4>
6157
<Form.Field>
6258
<Checkbox
6359
toggle
64-
label="sticky - change footer stick value"
60+
label="change footer type"
61+
value={simple.toString()}
62+
checked={simple}
63+
onChange={() => setSimple(prev => !prev)}
64+
/>
65+
</Form.Field>
66+
<Form.Field>
67+
<Checkbox
68+
toggle
69+
label="change footer sticky value"
6570
value={sticky.toString()}
6671
checked={sticky}
6772
onChange={() => setSticky(prev => !prev)}
@@ -73,7 +78,9 @@ const Example10 = () => {
7378
<h4>Controlled Props:</h4>
7479
<Background>
7580
<pre>
76-
{"{\n stickyFooter: "}
81+
{"{\n simpleFooter: "}
82+
<span style={{ color: "rgb(102, 217, 239)" }}>{simple.toString()}</span>
83+
{",\n stickyFooter: "}
7784
<span style={{ color: "rgb(102, 217, 239)" }}>{sticky.toString()}</span>
7885
{"\n}"}
7986
</pre>
@@ -87,7 +94,30 @@ const Example10 = () => {
8794
columns={columns}
8895
stickyFooter={sticky}
8996
tableHeight={400}
90-
footerComponent={() => <Footer>Footer content</Footer>}
97+
footerStyle={{ backgroundColor: "white" }}
98+
footerComponent={({ widths }) => (
99+
<Footer>
100+
{simple ? (
101+
"Hello, World"
102+
) : (
103+
<div style={{ display: "flex" }}>
104+
{columns.map((c, i) => {
105+
const width = `${widths[i]}px`;
106+
const style: React.CSSProperties = {
107+
width,
108+
minWidth: width,
109+
padding: "8px"
110+
};
111+
return (
112+
<div key={c.key} style={style}>
113+
Footer Cell
114+
</div>
115+
);
116+
})}
117+
</div>
118+
)}
119+
</Footer>
120+
)}
91121
/>
92122
</>
93123
);
@@ -96,20 +126,54 @@ const Example10 = () => {
96126
const Source = `
97127
const data = [/* ... */];
98128
99-
const Footer = styled.div\`
100-
background-color: white;
101-
padding: 8px;
102-
\`;
129+
const Footer = ({ children }) => (
130+
<div style={{ backgroundColor: "white" }}>
131+
{children}
132+
</div>
133+
);
134+
135+
const SimpleFooter = ({ stickyFooter }) => {
136+
return (
137+
<StyledTable
138+
borders
139+
data={data}
140+
columns={columns}
141+
tableHeight={400}
142+
stickyFooter={stickyFooter}
143+
footerStyle={{ backgroundColor: "white" }}
144+
footerComponent={() => <Footer>Hello, World</Footer>}
145+
/>
146+
);
147+
};
103148
104-
const Controlled = ({ stickyFooter }) => {
149+
const ComplexFooter = ({ stickyFooter }) => {
105150
return (
106151
<StyledTable
107152
borders
108153
data={data}
109154
columns={columns}
110155
tableHeight={400}
111156
stickyFooter={stickyFooter}
112-
footerComponent={() => <Footer>Footer content</Footer>}
157+
footerStyle={{ backgroundColor: "white" }}
158+
footerComponent={({ widths }) => (
159+
<Footer>
160+
<div style={{ display: "flex" }}>
161+
{columns.map((c, i) => {
162+
const width = \`\${widths[i]}px\`;
163+
const style: React.CSSProperties = {
164+
width,
165+
minWidth: width,
166+
padding: "8px"
167+
};
168+
return (
169+
<div key={c.key} style={style}>
170+
Footer Cell
171+
</div>
172+
);
173+
})}
174+
</div>
175+
</Footer>
176+
)}
113177
/>
114178
);
115179
};

index.d.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ export interface SubComponentProps<T> {
104104
clearSizeCache: CacheFunction;
105105
}
106106

107+
export interface FooterProps {
108+
/**
109+
* exposes the widths of each column to the footer
110+
*/
111+
widths: number[];
112+
}
113+
107114
export interface ColumnProps<T> {
108115
/**
109116
* The unique identifier for a particular column. This is also used as an index
@@ -190,6 +197,14 @@ export interface TableProps<T> {
190197
* Specify the height of the table in pixels.
191198
*/
192199
tableHeight?: number;
200+
/**
201+
* Specify the minimum height of the table in pixels.
202+
*/
203+
minTableHeight?: number;
204+
/**
205+
* Specify the maximum height of the table in pixels.
206+
*/
207+
maxTableHeight?: number;
193208
/**
194209
* Specify the width of the table in pixels.
195210
*/
@@ -234,6 +249,14 @@ export interface TableProps<T> {
234249
* a function that takes the index of the row and returns an object.
235250
*/
236251
rowClassname?: string | ((index: number) => string);
252+
/**
253+
* React styles used for customizing the footer.
254+
*/
255+
footerStyle?: CSSProperties;
256+
/**
257+
* a className used to customize the footer
258+
*/
259+
footerClassname?: string;
237260
/**
238261
* generates a unique identifier for the row
239262
* @param row the row
@@ -248,7 +271,7 @@ export interface TableProps<T> {
248271
/**
249272
* optionally add a footer
250273
*/
251-
footerComponent?: () => React.ReactNode;
274+
footerComponent?: (props: FooterProps) => React.ReactNode;
252275
/**
253276
* When a column has `expander`, this component will be rendered under the row.
254277
*/

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": "0.4.5",
3+
"version": "0.4.6",
44
"description": "A React table inspired by react-window",
55
"author": "Mckervin Ceme <mckervinc@live.com>",
66
"license": "MIT",

0 commit comments

Comments
 (0)