components: improve layout with css grid, rewrite line rendering

This commit is contained in:
Artur Tamborski 2020-11-28 10:59:56 +01:00
parent 27b824c235
commit fd6a9f52a7
7 changed files with 24 additions and 30 deletions

View File

@ -1,9 +1,9 @@
.App { .App {
max-width: 100vw;
max-height: 100vh; max-height: 100vh;
display: grid; display: grid;
grid-template-columns: repeat(3, 1fr); grid-template-columns: repeat(3, 1fr);
grid-template-rows: 1fr; grid-template-rows: 1fr 1fr 1/2fr;
grid-column-gap: 0; grid-column-gap: 0;
grid-row-gap: 0; grid-row-gap: 0;
} }

View File

@ -9,8 +9,10 @@ export default function App(): JSX.Element {
return ( return (
<div className="App"> <div className="App">
<div /> <div />
<div>
<Logo /> <Logo />
<div />
<div />
<div>
<Board <Board
numRows={10} numRows={10}
numCols={10} numCols={10}

View File

@ -1,6 +1,3 @@
$LetterBaseColor: ghostwhite;
$LetterHoverColor: #d9d9ff;
.Container { .Container {
display: grid; display: grid;
} }
@ -32,20 +29,15 @@ $LetterHoverColor: #d9d9ff;
font-size: x-large; font-size: x-large;
font-family: monospace; font-family: monospace;
padding: 15px; padding: 15px;
background: $LetterBaseColor; background: ghostwhite;
text-align: center; text-align: center;
border: 5px solid #e5e5ea; border: 5px solid #e5e5ea;
border-radius: 100%; border-radius: 100%;
color: brown; color: brown;
cursor: pointer; cursor: pointer;
&:hover { &:focus, &:hover {
border-color: $LetterHoverColor;
}
&:focus {
border-color: #8b8be5; border-color: #8b8be5;
outline: none; outline: none;
} }
} }

View File

@ -46,16 +46,22 @@ export default class Board extends React.Component<IBoardProps, IBoardState> {
handleMouseDown(startPos: Point) { handleMouseDown(startPos: Point) {
const endPos = startPos; const endPos = startPos;
this.setState({...this.state, startPos, endPos, isSelecting: true}); let lines = [...this.state.lines];
lines[0] = true;
this.setState({...this.state, startPos, endPos, lines, isSelecting: true});
} }
handleMouseUp(endPos: Point) { handleMouseUp(endPos: Point) {
if (this.moveIsValid(endPos)) if (!this.moveIsValid(endPos))
return;
this.setState({...this.state, endPos, isSelecting: false}); this.setState({...this.state, endPos, isSelecting: false});
} }
handleMouseOver(endPos: Point) { handleMouseOver(endPos: Point) {
if (this.moveIsValid(endPos)) if (!this.moveIsValid(endPos))
return;
this.setState({...this.state, endPos}); this.setState({...this.state, endPos});
} }
@ -80,7 +86,6 @@ export default class Board extends React.Component<IBoardProps, IBoardState> {
startPos={{...this.state.startPos}} startPos={{...this.state.startPos}}
endPos={{...this.state.endPos}} endPos={{...this.state.endPos}}
cellSize={60} cellSize={60}
isVisible={this.state.lines[0]}
/> />
); );
} }
@ -91,7 +96,7 @@ export default class Board extends React.Component<IBoardProps, IBoardState> {
oy.map((s, x) => oy.map((s, x) =>
this.renderCell(s, {x, y}))); this.renderCell(s, {x, y})));
let lines = this.state.lines.map((ox, x) => let lines = this.state.lines.filter(x => x).map((ox, x) =>
this.renderLine(x)); this.renderLine(x));
return ( return (

View File

@ -8,7 +8,6 @@ interface ILineProps {
startPos: Point; startPos: Point;
endPos: Point; endPos: Point;
cellSize: number; cellSize: number;
isVisible: boolean;
} }
export default function Line(props: ILineProps): JSX.Element { export default function Line(props: ILineProps): JSX.Element {
@ -17,7 +16,6 @@ export default function Line(props: ILineProps): JSX.Element {
return ( return (
<line <line
className="Line" className="Line"
// style={{display: props.isVisible ? 'shown' : 'hidden'}}
x1={`${pos(props.endPos.x)}`} x1={`${pos(props.endPos.x)}`}
y1={`${pos(props.endPos.y)}`} y1={`${pos(props.endPos.y)}`}
x2={`${pos(props.startPos.x)}`} x2={`${pos(props.startPos.x)}`}

View File

@ -1,8 +1,5 @@
.Logo { .Logo {
padding: 40px 0; display: flex;
} justify-content: center;
padding: 20px 0;
.Logo-wide {
width: 50%;
margin-left: 25%;
} }

View File

@ -6,7 +6,7 @@ import './Logo.scss';
export default function Logo(): JSX.Element { export default function Logo(): JSX.Element {
return ( return (
<div className="Logo"> <div className="Logo">
<img alt="Logo" src={Wide} className="Logo-wide"/> <img alt="Logo" src={Wide}/>
</div> </div>
); );
} }