Skip to content

Commit 80cd476

Browse files
committed
[website] improve the draggable-rows example
1 parent 2450b1a commit 80cd476

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

docs/inline-editing.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,5 @@ export default () => (
130130
</>
131131
)
132132
```
133+
134+
Check the live example [here](https://autodesk.github.io/react-base-table/examples/inline-editing).

website/src/components/Header.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const Header = ({ pathname }) => {
7474
<div>
7575
<Title to="/">BaseTable</Title>
7676
<Version
77-
href="https://github.com/Autodesk/react-base-table/releases"
77+
href="https://github.com/Autodesk/react-base-table/blob/master/CHANGELOG.md"
7878
target="_blank"
7979
>
8080
v{pkg.version}
@@ -93,12 +93,6 @@ const Header = ({ pathname }) => {
9393
<NavLink to="/playground" pathname={pathname}>
9494
Playground
9595
</NavLink>
96-
<ExternalLink
97-
href="https://github.com/Autodesk/react-base-table/blob/master/CHANGELOG.md"
98-
target="_blank"
99-
>
100-
CHANGELOG
101-
</ExternalLink>
10296
<ExternalLink last href={pkg.repository.url} target="_blank">
10397
<LinkIcon src={linkIcon} alt="Github" />
10498
</ExternalLink>

website/src/examples/draggable-rows.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@ const Handle = styled.div`
88
flex: none;
99
width: 7.5px;
1010
height: 100%;
11-
background: #888;
11+
12+
&::before {
13+
content: '';
14+
border-left: 4px dotted #ccc;
15+
display: block;
16+
height: 20px;
17+
margin: 15px 3px;
18+
}
19+
20+
&:hover::before {
21+
border-color: #888
22+
}
1223
`
1324

1425
const Row = ({ key, index, children, ...rest }) => (
@@ -28,6 +39,10 @@ const rowProps = ({ rowIndex }) => ({
2839
})
2940

3041
class DraggableTable extends React.PureComponent {
42+
state = {
43+
data: this.props.data,
44+
}
45+
3146
getContainer() {
3247
return document.querySelector('.BaseTable__body')
3348
}
@@ -46,14 +61,27 @@ class DraggableTable extends React.PureComponent {
4661
}
4762
}
4863

64+
handleSortEnd = ({ oldIndex, newIndex }) => {
65+
const data = [...this.state.data]
66+
const [removed] = data.splice(oldIndex, 1)
67+
data.splice(newIndex, 0, removed)
68+
this.setState({ data })
69+
}
70+
4971
render() {
5072
return (
5173
<DraggableContainer
5274
useDragHandle
5375
getContainer={this.getContainer}
5476
helperContainer={this.getHelperContainer}
77+
onSortEnd={this.handleSortEnd}
5578
>
56-
<Table {...this.props} fixed={false} rowProps={this.rowProps} />
79+
<Table
80+
{...this.props}
81+
data={this.state.data}
82+
fixed={false}
83+
rowProps={this.rowProps}
84+
/>
5785
</DraggableContainer>
5886
)
5987
}
@@ -68,10 +96,11 @@ const Hint = styled.div`
6896

6997
const columns = generateColumns(10)
7098
const data = generateData(columns, 200)
99+
columns[0].minWidth = 150
71100

72101
export default () => (
73102
<>
74-
<Hint>Drag the gray handles, only works in flex mode(fixed=false)</Hint>
103+
<Hint>Drag the dots, only works in flex mode(fixed=false)</Hint>
75104
<DraggableTable columns={columns} data={data} />
76105
</>
77106
)

0 commit comments

Comments
 (0)