Skip to content

Commit cf6a73f

Browse files
committed
tweak table heights
1 parent bfb8a38 commit cf6a73f

File tree

6 files changed

+334
-42
lines changed

6 files changed

+334
-42
lines changed

example/src/App.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Example7, Source as Example7Code } from "./examples/07-controlled";
1111
import { Example8, Source as Example8Code } from "./examples/08-header";
1212
import { Example9, Source as Example9Code } from "./examples/09-scroll";
1313
import { Example10, Source as Example10Code } from "./examples/10-footer";
14+
import { Example11, Source as Example11Code } from "./examples/11-heights";
1415

1516
const router = createHashRouter([
1617
{
@@ -93,6 +94,14 @@ const router = createHashRouter([
9394
</Page>
9495
)
9596
},
97+
{
98+
path: "/heights",
99+
element: (
100+
<Page title="Table Heights" code={Example11Code}>
101+
<Example11 />
102+
</Page>
103+
)
104+
},
96105
{
97106
path: "/props",
98107
element: (

example/src/Page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ const LinkContainer = () => (
9696
<Menu.Item as={Link} to="/scroll">
9797
Methods
9898
</Menu.Item>
99+
<Menu.Item as={Link} to="/heights">
100+
Table Heights
101+
</Menu.Item>
99102
<Menu.Item as={Link} to="/footer">
100103
Footer
101104
</Menu.Item>

example/src/examples/11-heights.tsx

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
import { useEffect, useRef, useState } from "react";
2+
import { ColumnProps, Table } from "react-fluid-table";
3+
import { Button, Form, Icon, Input } from "semantic-ui-react";
4+
import styled from "styled-components";
5+
import { TestData, testData } from "../data";
6+
7+
const StyledTable = styled(Table)`
8+
margin-top: 10px;
9+
`;
10+
11+
const columns: ColumnProps<TestData>[] = [
12+
{
13+
key: "id",
14+
header: "ID",
15+
width: 50
16+
},
17+
{
18+
key: "firstName",
19+
header: "First",
20+
width: 120
21+
},
22+
{
23+
key: "lastName",
24+
header: "Last",
25+
width: 120
26+
},
27+
{
28+
key: "email",
29+
header: "Email",
30+
width: 250
31+
}
32+
];
33+
34+
const Example11 = () => {
35+
// hooks
36+
const ref = useRef(0);
37+
const [size, setSize] = useState(1);
38+
const [running, setRunning] = useState(false);
39+
const [tableHeight, setTableHeight] = useState(400);
40+
const [minTableHeight, setMinTableHeight] = useState(0);
41+
const [maxTableHeight, setMaxTableHeight] = useState(0);
42+
43+
useEffect(() => {
44+
const m = ref.current;
45+
return () => {
46+
window.clearInterval(m);
47+
};
48+
}, []);
49+
50+
return (
51+
<>
52+
<Form>
53+
<h4>Change height properties</h4>
54+
<Form.Field>
55+
<Input
56+
label="table height"
57+
placeholder="specify table height (<= 0 to disable)"
58+
type="number"
59+
value={tableHeight.toString()}
60+
onChange={e => {
61+
setTableHeight(/-?\d+/.test(e.target.value) ? parseInt(e.target.value) : 0);
62+
}}
63+
/>
64+
</Form.Field>
65+
<Form.Field>
66+
<Input
67+
label="min table height"
68+
placeholder="specify min table height (<= 0 to disable)"
69+
type="number"
70+
value={minTableHeight.toString()}
71+
onChange={e => {
72+
setMinTableHeight(/-?\d+/.test(e.target.value) ? parseInt(e.target.value) : 0);
73+
}}
74+
/>
75+
</Form.Field>
76+
<Form.Field>
77+
<Input
78+
label="max table height"
79+
placeholder="specify max table height (<= 0 to disable)"
80+
type="number"
81+
value={maxTableHeight.toString()}
82+
onChange={e => {
83+
setMaxTableHeight(/-?\d+/.test(e.target.value) ? parseInt(e.target.value) : 0);
84+
}}
85+
/>
86+
</Form.Field>
87+
<div>
88+
<Button
89+
onClick={() => {
90+
window.clearInterval(ref.current);
91+
setSize(1);
92+
setRunning(true);
93+
ref.current = window.setInterval(() => {
94+
setSize(prev => prev + 1);
95+
}, 1000);
96+
}}
97+
>
98+
Start
99+
</Button>
100+
<Button
101+
onClick={() => {
102+
window.clearInterval(ref.current);
103+
setRunning(false);
104+
}}
105+
>
106+
Stop
107+
</Button>
108+
{running && <Icon loading name="spinner" />}
109+
</div>
110+
</Form>
111+
<StyledTable
112+
borders
113+
data={testData.slice(0, size)}
114+
columns={columns}
115+
tableHeight={tableHeight}
116+
minTableHeight={minTableHeight}
117+
maxTableHeight={maxTableHeight}
118+
/>
119+
</>
120+
);
121+
};
122+
123+
const Source = `
124+
const data = [/* ... */];
125+
126+
const Footer = ({ children }) => (
127+
<div style={{ backgroundColor: "white" }}>
128+
{children}
129+
</div>
130+
);
131+
132+
const SimpleFooter = ({ stickyFooter }) => {
133+
return (
134+
<StyledTable
135+
borders
136+
data={data}
137+
columns={columns}
138+
tableHeight={400}
139+
stickyFooter={stickyFooter}
140+
footerStyle={{ backgroundColor: "white" }}
141+
footerComponent={() => <Footer>Hello, World</Footer>}
142+
/>
143+
);
144+
};
145+
146+
const ComplexFooter = ({ stickyFooter }) => {
147+
return (
148+
<StyledTable
149+
borders
150+
data={data}
151+
columns={columns}
152+
tableHeight={400}
153+
stickyFooter={stickyFooter}
154+
footerStyle={{ backgroundColor: "white" }}
155+
footerComponent={({ widths }) => (
156+
<Footer>
157+
<div style={{ display: "flex" }}>
158+
{columns.map((c, i) => {
159+
const width = \`\${widths[i]}px\`;
160+
const style: React.CSSProperties = {
161+
width,
162+
minWidth: width,
163+
padding: "8px"
164+
};
165+
return (
166+
<div key={c.key} style={style}>
167+
Footer Cell
168+
</div>
169+
);
170+
})}
171+
</div>
172+
</Footer>
173+
)}
174+
/>
175+
);
176+
};
177+
`;
178+
179+
export { Example11, Source };

0 commit comments

Comments
 (0)