ListGroups.js
4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import React from 'react';
import {
Row, Col,
} from 'reactstrap';
import { SortableContainer, SortableElement, arrayMove } from 'react-sortable-hoc';
import SortableTree from 'react-sortable-tree';
import Widget from '../../../components/Widget';
import './ListGroups.scss';
const SortableItem = SortableElement(({ value }) => <li className="list-group-item">
<i className="fa fa-sort" />
<button className="close flex-last ml-auto" data-dismiss="alert">×</button>
{value.id}
{value.text}
</li>);
const SortableList = SortableContainer(({ items }) => (
<ul className="list-group list-group-sortable mt-xs">
{items.map((value, index) => (
<SortableItem key={`item-${index.toString()}`} index={index} value={value} />
))}
</ul>
));
const NestableItem = SortableElement(({ value }) => {
if (value.children) {
return (
<li className="dd-item">
<div className="dd-handle" data-id={value.id}> {value.text} </div>
<ol className="dd-list">
{value.children.map((child, index) => (
<NestableItem key={`nest-${index.toString()}`} index={index} value={child} />
))}
</ol>
</li>);
}
return (
<li className="dd-item">
<div className="dd-handle" data-id={value.id}> {value.text} </div>
</li>
);
});
class ListGroups extends React.Component {
constructor() {
super();
this.state = {
nestableFirstItems: [{ id: 1, title: 'Item 1' }, {
id: 2,
expanded: true,
title: 'Item 2',
children: [{ id: 3, title: 'Item 3' }, { id: 4, title: 'Item 4' }, {
id: 5,
title: 'Item 5',
expanded: true,
children: [{ id: 6, title: 'Item 6' }, {
id: 7, title: 'Item 7',
}, {
id: 8, title: 'Item 8',
}],
}, { id: 9, title: 'Item 9' }],
}],
nestableSecondItems: [{ id: 13, title: 'Item 13' }, { id: 14, title: 'Item 14' }, {
id: 15,
expanded: true,
title: 'Item 15',
children: [{ id: 16, title: 'Item 16' }, { id: 17, title: 'Item 17' }, {
id: 18, title: 'Item 18',
}],
}],
sortableList: [{
id: '03', text: ' Barnard\'s Star',
}, {
id: '01', text: 'The Sun',
}, {
id: '04', text: 'Wolf 359',
}, {
id: '02', text: 'Proxima Centauri',
}, {
id: '05', text: 'Lalande 21185',
}],
};
}
onSortEnd = ({ oldIndex, newIndex }) => {
this.setState({
sortableList: arrayMove(this.state.sortableList, oldIndex, newIndex),
});
};
render() {
return (
<div>
<ol className="breadcrumb">
<li className="breadcrumb-item">YOU ARE HERE</li>
<li className="breadcrumb-item active">UI List Groups</li>
</ol>
<h1 className="page-title">Lists - <span className="fw-semi-bold">Sortable Groups</span>
</h1>
<Widget
title={<h4> Grouped <span className="fw-semi-bold">Lists</span></h4>}
close refresh settings
>
<h3>Closest <span className="fw-semi-bold">Stars</span></h3>
<p>
Try to play around with this list. Are you ready to pass an exam on astronomy?
</p>
<SortableList items={this.state.sortableList} onSortEnd={this.onSortEnd} />
</Widget>
<Widget
title={<h3>Nestable <span className="fw-semi-bold">List</span></h3>}
close refresh settings
>
<p className="fs-mini">
There is a scientific theory that you can arrange this list in such way that there will
be no more saddness
in the whole world. Can you? Touch devices supported
</p>
<Row className="nestable">
<Col md="6" xs="12" className="mb-xs">
<SortableTree
treeData={this.state.nestableFirstItems}
onChange={nestableFirstItems => this.setState({ nestableFirstItems })}
/>
</Col>
<Col md="6">
<SortableTree
treeData={this.state.nestableSecondItems}
onChange={nestableSecondItems => this.setState({ nestableSecondItems })}
/>
</Col>
</Row>
</Widget>
</div>
);
}
}
export default ListGroups;