Skip to content

Commit ebe06ca

Browse files
committed
Pass down preSelected, isCellValid and solved to sudokuBoard and childrens. Update function that returns cell's className
1 parent 01eadf2 commit ebe06ca

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/components/board/Board.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import React from 'react';
22
import Row from './row/Row';
33

4-
const Board = ({ board, onCellChange }) => (
4+
const Board = ({ board, valid, preSelected, solved, onCellChange }) => (
55
<div className="sudoku-board">
66
{board.map( (row,index) => (
77
<Row
88
row={row}
99
onCellChange={(row,column,input) => onCellChange(row,column,input)}
10+
valid={valid[index]}
11+
solved={solved}
12+
preSelected={preSelected[index]}
1013
rowIndex={index}
1114
key={index}
1215
/>

src/components/board/row/Row.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import React from 'react';
22
import Cell from './cell';
33
//import './styles.css';
44

5-
const Row = ({row, rowIndex, onCellChange}) => (
5+
const Row = ({row, rowIndex, valid, preSelected, solved, onCellChange}) => (
66
<div className="sudoku-row">
77
{row.map( (num,columnIndex) => (
88
<Cell
99
data={num}
1010
row={rowIndex}
1111
column={columnIndex}
12+
cellValid={valid[columnIndex]}
13+
preSelected={preSelected[columnIndex]}
14+
solved={solved}
1215
key={`${rowIndex}${columnIndex}`}
1316
onChange={(row,column,input) => onCellChange(row,column,input)}
1417
/>

src/components/board/row/cell/cell.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
const computeClassName = (row,column) => {
3+
const computeClassName = (row,column,cellValid,preSelected,solved) => {
44
let className = '';
55
if( column===2 || column===5 ){
66
className += 'borderRight';
@@ -11,11 +11,23 @@ const computeClassName = (row,column) => {
1111
}
1212
className += 'borderBottom';
1313
}
14+
if(preSelected && solved){
15+
if(className!==''){
16+
className +=' ';
17+
}
18+
className += 'preSelected';
19+
}
20+
if( !cellValid ){
21+
if(className!==''){
22+
className +=' ';
23+
}
24+
className += 'notValidCell';
25+
}
1426
return className;
1527
}
1628

17-
const Cell = ({data, row, column, onChange}) => (
18-
<div className={`sudoku-cell ${computeClassName(row,column)}`}>
29+
const Cell = ({data, row, column, cellValid, preSelected, solved, onChange}) => (
30+
<div className={`sudoku-cell ${computeClassName(row,column,cellValid,preSelected,solved)}`}>
1931
<input
2032
value={(data!==0) ? data : '' }
2133
onChange={(e) => onChange(row,column,e.target.value.slice(-1))}

0 commit comments

Comments
 (0)