Skip to content
This repository was archived by the owner on Feb 6, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions demo.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ button {
padding: 0.3rem 0.5rem;
}

.int-demo {
margin-bottom: 0.5rem;
}

.int-demo button {
float: none;
margin-left: 0.5rem;
}

.flash {
animation-name: flash;
animation-duration: 0.5s;
Expand Down Expand Up @@ -63,6 +72,15 @@ button {
.table-drag-select td.cell-selected {
background-color: #FBD5D4;
}
.table-drag-select td.foo {
background-color: #FF0000;
}
.table-drag-select td.bar {
background-color: #00FF00;
}
.table-drag-select td.baz {
background-color: #0000ff;
}

.table-drag-select td.cell-being-selected {
background-color: #EACA96;
Expand Down
145 changes: 135 additions & 10 deletions demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,21 @@ class App extends React.Component {
[false, false, false, false, false, false, false],
[false, false, false, false, false, false, false],
[false, false, false, false, false, false, false]
]
],
intCells: [
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0]
],
setValue: 0
};

render = () => (
render = () =>
<div>
<h1>
<a href="https://github.com/mcjohnalds/react-table-drag-select">
Expand Down Expand Up @@ -334,24 +345,126 @@ class App extends React.Component {
<td>overtime</td>
</tr>
</TableDragSelect>
<h2>
<code>{"onChange={cells => ...}"}</code> callback
</h2>
<pre ref="output">
cells = {stringifyBoolMatrix(this.state.cells)}
</pre>
<button onClick={this.handleReset}>Reset</button>
<h3>Int value mode</h3>
<div className="int-demo">
<strong>Current `setValue`:</strong> {this.state.setValue}
<button onClick={this.updateSetValue}>Rotate value</button>
</div>
<TableDragSelect
value={this.state.intCells}
onChange={this.handleIntChange}
setValue={this.state.setValue}
classNameMap={{
0: "",
1: "foo",
2: "bar",
3: "baz"
}}
>
<tr>
<td disabled />
<td disabled>Monday</td>
<td disabled>Tuesday</td>
<td disabled>Wednesday</td>
<td disabled>Thursday</td>
<td disabled>Friday</td>
<td disabled>Saturday</td>
</tr>
<tr>
<td disabled>10:00</td>
<td />
<td />
<td />
<td />
<td />
<td>overtime</td>
</tr>
<tr>
<td disabled>11:00</td>
<td />
<td />
<td />
<td />
<td />
<td>overtime</td>
</tr>
<tr>
<td disabled>12:00</td>
<td />
<td />
<td />
<td />
<td />
<td>overtime</td>
</tr>
<tr>
<td disabled>13:00</td>
<td />
<td />
<td />
<td />
<td />
<td>overtime</td>
</tr>
<tr>
<td disabled>14:00</td>
<td />
<td />
<td />
<td />
<td />
<td>overtime</td>
</tr>
<tr>
<td disabled>15:00</td>
<td />
<td />
<td />
<td />
<td />
<td>overtime</td>
</tr>
<tr>
<td disabled>16:00</td>
<td />
<td />
<td />
<td />
<td />
<td>overtime</td>
</tr>
</TableDragSelect>
</div>
<button onClick={this.handleReset}>Reset</button>
<h2>
<code>{"onChange={cells => ...}"}</code> callback
</h2>
<pre ref="output">cells = {stringifyBoolMatrix(this.state.cells)}</pre>
<pre ref="output">
intCells = {stringifyIntMatrix(this.state.intCells)}
</pre>
<h2>Javascript</h2>
<pre>{jsCode}</pre>
<pre>
{jsCode}
</pre>
<h2>Optional styling</h2>
<p>
This isn't required, but changing the colors can really spruce things
up.
</p>
<pre>{cssCode}</pre>
<pre>
{cssCode}
</pre>
<h2>Resulting DOM</h2>
<pre>{resultingDOM}</pre>
</div>
);
<pre>
{resultingDOM}
</pre>
</div>;

handleChange = cells => {
if (!equal(this.state.cells, cells)) {
Expand All @@ -360,6 +473,10 @@ class App extends React.Component {
}
};

handleIntChange = intCells => this.setState({ intCells });
updateSetValue = () =>
this.setState(state => ({ setValue: (state.setValue + 1) % 4 }));

handleReset = () => {
const cells = [
[false, false, false, false, false, false, false],
Expand Down Expand Up @@ -389,9 +506,17 @@ const stringifyBoolMatrix = matrix => {
return row.map(cell => (cell ? " true" : "false")).join(", ");
};

return "[\n [" + matrix.map(row2Str).join("],\n [") + "]\n]";
return prettyPrintMatrix(matrix, row2Str);
};

const stringifyIntMatrix = matrix => {
const row2Str = row => row.join(", ");
return prettyPrintMatrix(matrix, row2Str);
};

const prettyPrintMatrix = (matrix, rowFn) =>
"[\n [" + matrix.map(rowFn).join("],\n [") + "]\n]";

const div = document.createElement("div");
document.body.appendChild(div);
ReactDOM.render(<App />, div);
Loading