Skip to content

Commit b786419

Browse files
committed
[website] update style
1 parent b7bc817 commit b786419

10 files changed

Lines changed: 178 additions & 15 deletions

File tree

docs/advance.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
## Advance
1+
# Advance
22

33
BaseTable is designed to be the base component to build your own complex table component
44

5-
### Styling
5+
## Styling
66

77
The simplest way is overriding the default styles (assuming you are using `scss`)
88

@@ -40,7 +40,7 @@ $show-frozen-columns-shadow: true;
4040

4141
You can write your own styles from scratch or use CSS-in-JS solutions to achieve that
4242

43-
### Custom components
43+
## Custom components
4444

4545
```jsx
4646
<BaseTable
@@ -55,6 +55,6 @@ You can write your own styles from scratch or use CSS-in-JS solutions to achieve
5555
/>
5656
```
5757

58-
### Custom renderers & props
58+
## Custom renderers & props
5959

6060
There are a lot of highly flexible props like `xxxRenderer` and `xxxProps` for you to build your own table component, please check the [api](https://autodesk.github.io/react-base-table/api) and [examples](https://autodesk.github.io/react-base-table/examples) for more details

docs/get-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Get Started
1+
# Get Started
22

33
BaseTable is a react table component to display large data set with high performance and flexibility
44

docs/inline-editing.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Inline Editing
2+
3+
WIP

docs/selection.md

Lines changed: 154 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,160 @@
1-
## Selection
1+
# Selection
22

33
There is a [PR](https://github.com/Autodesk/react-base-table/pull/39) to add selection feature, but I don't want to merge it with [good reasons](https://github.com/Autodesk/react-base-table/pull/39#pullrequestreview-241987600), so I'd like to share a recipe here for reference
44

5+
## Recipe
6+
7+
```jsx
8+
const StyledTable = styled(BaseTable)`
9+
.row-selected {
10+
background-color: #e3e3e3;
11+
}
12+
`;
13+
14+
class SelectionCell extends React.PureComponent {
15+
_handleChange = e => {
16+
const { rowData, rowIndex, column } = this.props;
17+
const { onChange } = column;
18+
19+
onChange({ selected: e.target.checked, rowData, rowIndex });
20+
};
21+
22+
render() {
23+
const { rowData, column } = this.props;
24+
const { selectedRowKeys, rowKey } = column;
25+
const checked = selectedRowKeys.includes(rowData[rowKey]);
26+
27+
return <input type="checkbox" checked={checked} onChange={this._handleChange} />;
28+
}
29+
}
30+
31+
class SelectableTable extends React.PureComponent {
32+
constructor(props) {
33+
super(props);
34+
35+
const { selectedRowKeys, defaultSelectedRowKeys, expandedRowKeys, defaultExpandedRowKeys } = props;
36+
this.state = {
37+
selectedRowKeys: (selectedRowKeys !== undefined ? selectedRowKeys : defaultSelectedRowKeys) || [],
38+
expandedRowKeys: (expandedRowKeys !== undefined ? expandedRowKeys : defaultExpandedRowKeys) || [],
39+
};
40+
}
41+
42+
/**
43+
* Set `selectedRowKeys` manually.
44+
* This method is available only if `selectedRowKeys` is uncontrolled.
45+
*
46+
* @param {array} selectedRowKeys
47+
*/
48+
setSelectedRowKeys(selectedRowKeys) {
49+
// if `selectedRowKeys` is controlled
50+
if (this.props.selectedRowKeys !== undefined) return;
51+
52+
this.setState({
53+
selectedRowKeys: cloneArray(selectedRowKeys),
54+
});
55+
}
56+
57+
/**
58+
* See BaseTable#setExpandedRowKeys
59+
*/
60+
setExpandedRowKeys(expandedRowKeys) {
61+
// if `expandedRowKeys` is controlled
62+
if (this.props.expandedRowKeys !== undefined) return;
63+
64+
this.setState({
65+
expandedRowKeys: cloneArray(expandedRowKeys),
66+
});
67+
}
68+
69+
/* some other custom methods and proxy methods */
70+
71+
/**
72+
* Remove rowKeys from inner state manually, it's useful to purge dirty state after rows removed.
73+
* This method is available only if `selectedRowKeys` or `expandedRowKeys` is uncontrolled.
74+
*
75+
* @param {array} rowKeys
76+
*/
77+
removeRowKeysFromState(rowKeys) {
78+
if (!Array.isArray(rowKeys)) return;
79+
80+
const state = {};
81+
if (this.props.selectedRowKeys === undefined && this.state.selectedRowKeys.length > 0) {
82+
state.selectedRowKeys = this.state.selectedRowKeys.filter(key => !rowKeys.includes(key));
83+
}
84+
if (this.props.expandedRowKeys === undefined && this.state.expandedRowKeys.length > 0) {
85+
state.expandedRowKeys = this.state.expandedRowKeys.filter(key => !rowKeys.includes(key));
86+
}
87+
if (state.selectedRowKeys || state.expandedRowKeys) {
88+
this.setState(state);
89+
}
90+
}
91+
92+
_handleSelectChange = ({ selected, rowData, rowIndex }) => {
93+
const selectedRowKeys = [...this.state.selectedRowKeys];
94+
const key = rowData[this.props.rowKey];
95+
96+
if (selected) {
97+
if (!selectedRowKeys.includes(key)) selectedRowKeys.push(key);
98+
} else {
99+
const index = selectedRowKeys.indexOf(key);
100+
if (index > -1) {
101+
selectedRowKeys.splice(index, 1);
102+
}
103+
}
104+
105+
// if `selectedRowKeys` is uncontrolled, update internal state
106+
if (this.props.selectedRowKeys === undefined) {
107+
this.setState({ selectedRowKeys });
108+
}
109+
this.props.onRowSelect({ selected, rowData, rowIndex });
110+
this.props.onSelectedRowsChange(selectedRowKeys);
111+
};
112+
113+
_rowClassName = ({ rowData, rowIndex }) => {
114+
const { rowClassName, rowKey } = this.props;
115+
const { selectedRowKeys } = this.state;
116+
117+
const rowClass = rowClassName ? callOrReturn(rowClassName, { rowData, rowIndex }) : '';
118+
const key = rowData[rowKey];
119+
120+
return [rowClass, selectedRowKeys.includes(key) && 'row-selected'].filter(Boolean).concat(' ');
121+
};
122+
123+
render() {
124+
const { columns, children, selectable, selectionColumnProps, ...rest } = this.props;
125+
const { selectedRowKeys } = this.state;
126+
127+
// you'd better memoize this operation
128+
let _columns = columns || normalizeColumns(children);
129+
if (selectable) {
130+
const selectionColumn = {
131+
width: 40,
132+
flexShrink: 0,
133+
resizable: false,
134+
frozen: Column.FrozenDirection.LEFT,
135+
cellRenderer: SelectionCell,
136+
...selectionColumnProps,
137+
key: '__selection__',
138+
rowKey: this.props.rowKey,
139+
selectedRowKeys: selectedRowKeys,
140+
onChange: this._handleSelectChange,
141+
};
142+
_columns = [selectionColumn, ..._columns];
143+
}
144+
145+
return <StyledTable {...rest} columns={_columns} rowClassName={this._rowClassName} />;
146+
}
147+
}
148+
149+
SelectableTable.defaultProps = {
150+
...BaseTable.defaultProps,
151+
onRowSelect: noop,
152+
onSelectedRowsChange: noop,
153+
};
154+
```
155+
156+
## Playground
157+
5158
```jsx live editorHeight=400
6159
const StyledTable = styled(BaseTable)`
7160
.row-selected {

website/siteConfig.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ module.exports = {
1212
title: 'Selection',
1313
path: '/docs/selection',
1414
},
15+
{
16+
title: 'Inline Editing',
17+
path: '/docs/inline-editing',
18+
},
1519
{
1620
title: 'Glossary',
1721
path: '/docs/glossary',

website/src/components/Header.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const Container = styled.div`
1515

1616
const Nav = styled.div`
1717
margin: 0 auto;
18-
max-width: 960px;
18+
max-width: 1000px;
1919
height: 50px;
2020
padding: 0 20px;
2121
display: flex;

website/src/components/Page.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'react-base-table/styles.css'
1111

1212
const pagelMixin = css`
1313
margin: 0 auto;
14-
max-width: 960px;
14+
max-width: 1000px;
1515
`
1616

1717
const Container = styled.div`
@@ -21,7 +21,7 @@ const Container = styled.div`
2121
`
2222

2323
const Content = styled.div`
24-
margin-left: 200px;
24+
margin-left: 240px;
2525
`
2626

2727
const Page = ({ title, location = {}, children, links, ...rest }) => (

website/src/components/Sidebar.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ const Container = styled.div`
99
top: 70px;
1010
bottom: 20px;
1111
overflow-y: auto;
12-
width: 180px;
13-
min-width: 180px;
12+
width: 220px;
13+
min-width: 220px;
1414
padding-right: 20px;
1515
border-right: 1px solid #edf0f2;
1616
`
@@ -25,16 +25,19 @@ const Li = styled.li`
2525
`
2626

2727
const StyledLink = styled(Link).attrs({
28+
partiallyActive: true,
2829
activeStyle: {
29-
borderRight: '3px solid',
30+
fontWeight: 700,
31+
borderRight: '3px solid #0696d7',
3032
},
3133
})`
3234
display: block;
3335
text-decoration: none;
3436
white-space: nowrap;
3537
text-overflow: ellipsis;
3638
overflow: hidden;
37-
font-size: 14px;
39+
font-size: 16px;
40+
color: #222;
3841
`
3942

4043
const ExternalLink = StyledLink.withComponent('a')

website/src/templates/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const links = siteConfig.api.map(item => ({
1818
const Title = styled.div`
1919
font-size: 16px;
2020
font-weight: 700;
21-
margin-bottom: 10px;
21+
margin-top: 16px;
2222
`
2323

2424
const Block = styled(Html)`

website/src/templates/example.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const links = siteConfig.examples.map(item => ({
1717
const Title = styled.div`
1818
font-size: 16px;
1919
font-weight: 700;
20-
margin-bottom: 10px;
20+
margin-top: 16px;
2121
`
2222

2323
class ComponentTemplate extends React.Component {

0 commit comments

Comments
 (0)