-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
82 lines (75 loc) · 2.43 KB
/
index.js
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
/* React */
import React, { useState } from "react";
import ReactDom from "react-dom";
/* Muuri-react */
import { MuuriComponent, useGrid } from "muuri-react";
/* Utils & components */
import { boardOptions, columnOptions, getRandomWord, useSend } from "./utils";
import { Column, Header, Demo } from "./components";
/* Style */
import "./style.css";
// App.
const App = () => {
// Items state.
const [items, setItems] = useState({
todo: ["4", "6", "5", "10"],
working: ["1", "3", "8"],
done: ["2", "7", "9"]
});
// UseSend is used when a item changes grid
// to sync the items state.
const onSend = useSend(setItems);
// Children.
const children = {
todo: items.todo.map((id) => <Item id={id} key={id} />),
done: items.done.map((id) => <Item id={id} key={id} />),
working: items.working.map((id) => <Item id={id} key={id} />)
};
return (
<Demo>
<Header />
{/* Columns container */}
<MuuriComponent {...boardOptions}>
{/* 'To do' column */}
<Column actionClass="todo" title="To do">
{/* Column content */}
<MuuriComponent id={"TODO"} onSend={onSend} {...columnOptions}>
{children.todo}
</MuuriComponent>
</Column>
{/* 'Working' column */}
<Column actionClass="working" title="Working">
{/* Column content */}
<MuuriComponent id={"WORKING"} onSend={onSend} {...columnOptions}>
{children.working}
</MuuriComponent>
</Column>
{/* 'Done' column */}
<Column actionClass="done" title="Done">
{/* Column content */}
<MuuriComponent id={"DONE"} onSend={onSend} {...columnOptions}>
{children.done}
</MuuriComponent>
</Column>
</MuuriComponent>
</Demo>
);
};
// Item component.
// Some memoization to make the app lighter.
const Item = React.memo(({ id }) => {
// State is manteined when an item change parent.
const [tag] = useState(getRandomWord);
// Get the MuuriComponent parent id.
const gridId = useGrid().id.toLowerCase();
return (
<div className="board-item">
<div className="board-item-content">
<span>Item </span>
{`${id} - ${tag}`}
<div className={`tab-item ${gridId}-tab-item`} />
</div>
</div>
);
});
ReactDom.render(<App />, document.getElementById("root"));