Skip to content

Instantly share code, notes, and snippets.

@goldensunliu
Last active March 5, 2018 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goldensunliu/2212a32e1f25f067200e2119d559ac23 to your computer and use it in GitHub Desktop.
Save goldensunliu/2212a32e1f25f067200e2119d559ac23 to your computer and use it in GitHub Desktop.
const Cell = (props) => {
const {
value, onClick, isPeer, isSelected, sameValue, prefilled, notes, conflict,
} = props;
const backgroundColor = getBackGroundColor({
conflict, isPeer, sameValue, isSelected,
});
const fontColor = getFontColor({ conflict, prefilled, value });
return (
<div className="cell" onClick={onClick}>
{
notes ?
range(9).map(i =>
(
<div key={i} className="note-number">
{notes.has(i + 1) && (i + 1)}
</div>
)) :
value && value
}
{/* language=CSS */}
<style jsx>{CellStyle}</style>
<style jsx>{`
.cell {
background-color: ${backgroundColor || 'initial'};
color: ${fontColor || 'initial'};
}
`}
</style>
</div>
);
};
Cell.propTypes = {
// current number value
value: PropTypes.number,
// cell click handler
onClick: PropTypes.func.isRequired,
// if the cell is a peer of the selected cell
isPeer: PropTypes.bool.isRequired,
// if the cell is selected by the user
isSelected: PropTypes.bool.isRequired,
// current cell has the same value if the user selected cell
sameValue: PropTypes.bool.isRequired,
// if this was prefilled as a part of the puzzle
prefilled: PropTypes.bool.isRequired,
// current notes taken on the cell
notes: PropTypes.instanceOf(Set),
// if the current cell does not satisfy the game constraint
conflict: PropTypes.bool.isRequired,
};
Cell.defaultProps = {
notes: null,
value: null,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment