Skip to content

Commit c3fbe11

Browse files
UI Updates
1 parent 9c009fe commit c3fbe11

File tree

9 files changed

+155
-31
lines changed

9 files changed

+155
-31
lines changed

src/App.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
.App *,
2+
.App {
3+
box-sizing: border-box;
4+
padding: 0;
5+
margin: 0;
6+
}
7+
18
.App {
29
text-align: center;
310
}

src/App.js

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import "./App.css";
22
import { useState } from "react";
33
import Chart from "./components/Chart/Chart";
4-
import Select from "./components/Select/Select";
54
import Button from "./components/Button/Button";
5+
import Navbar from "./components/Navbar/Navbar";
66
import { useEffect } from "react";
77

88
import generateArray from "./helpers/generateArray";
@@ -81,38 +81,22 @@ function App() {
8181

8282
return (
8383
<div className="App">
84-
<h1>Sorting Visualizer</h1>
84+
<Navbar
85+
isSorting={isSorting}
86+
randomizeClickHandler={randomizeClickHandler}
87+
algType={algType}
88+
algChangeHandler={algChangeHandler}
89+
sizeChangeHandler={sizeChangeHandler}
90+
size={size}
91+
speed={speed}
92+
speedChangeHandler={speedChangeHandler}
93+
/>
8594
<Chart data={data} currIJ={currIJ} completed={completed} />
8695
<Button
8796
btnName="Sort"
8897
onClickHandler={sortClickHandler}
8998
isDisabled={isSorting}
90-
/>
91-
<Button
92-
btnName="Randomize"
93-
onClickHandler={randomizeClickHandler}
94-
isDisabled={isSorting}
95-
/>
96-
<Select
97-
value={algType}
98-
onChangeHandler={algChangeHandler}
99-
values={[0, 1]}
100-
options={["Bubble Sort", "Selection Sort"]}
101-
isDisabled={isSorting}
102-
/>
103-
<Select
104-
value={size}
105-
onChangeHandler={sizeChangeHandler}
106-
values={[5, 10, 25, 50, 75, 100]}
107-
options={[5, 10, 25, 50, 75, 100]}
108-
isDisabled={isSorting}
109-
/>
110-
<Select
111-
value={speed}
112-
onChangeHandler={speedChangeHandler}
113-
values={[0.25, 0.5, 1, 2, 4]}
114-
options={["0.25x", "0.5x", "1x", "2x", "4x"]}
115-
isDisabled={isSorting}
99+
className="sort"
116100
/>
117101
</div>
118102
);

src/components/Button/Button.css

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
.button {
2+
width: 10rem;
3+
height: 3rem;
4+
border-radius: 10px;
5+
border: none;
6+
background-color: rgba(199, 199, 204, 0.8);
7+
cursor: pointer;
8+
font-size: 1rem;
9+
}
10+
11+
.button:hover {
12+
background-color: rgba(199, 199, 204, 1);
13+
}
14+
15+
.sort {
16+
background-color: rgba(255, 69, 140, 0.8);
17+
color: white;
18+
font-size: 1.5rem;
19+
}
20+
21+
.sort:hover {
22+
background-color: rgba(255, 69, 140, 1);
23+
}
24+
25+
.button:disabled {
26+
background-color: rgb(142, 142, 147);
27+
color: black;
28+
cursor: not-allowed;
29+
}

src/components/Button/Button.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import "./Button.css";
22

33
const Button = (props) => {
44
return (
5-
<button onClick={props.onClickHandler} disabled={props.isDisabled}>
5+
<button
6+
className={`button ${props.className}`}
7+
onClick={props.onClickHandler}
8+
disabled={props.isDisabled}
9+
>
610
{props.btnName}
711
</button>
812
);

src/components/Chart/Chart.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.chart {
22
width: 95%;
3-
margin: 0 auto;
3+
margin: 2% auto;
44
height: 350px;
55
background-color: rgb(199, 199, 204);
66
border: 1px solid lightgray;

src/components/Navbar/Navbar.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.navbar {
2+
background-color: rgb(255, 255, 255);
3+
box-shadow: 1px 4px 15px 0px rgba(0, 0, 0, 0.66);
4+
-webkit-box-shadow: 1px 4px 15px 0px rgba(0, 0, 0, 0.66);
5+
-moz-box-shadow: 1px 4px 15px 0px rgba(0, 0, 0, 0.66);
6+
display: flex;
7+
align-items: center;
8+
justify-content: space-between;
9+
padding: 0 1%;
10+
margin-bottom: 2%;
11+
}
12+
13+
.navbar div {
14+
width: 60%;
15+
display: flex;
16+
align-items: center;
17+
justify-content: space-around;
18+
}
19+
20+
@media (max-width: 800px) {
21+
.navbar {
22+
display: block;
23+
text-align: left;
24+
}
25+
26+
.navbar div {
27+
display: grid;
28+
width: 100%;
29+
grid-template-columns: 1fr 1fr;
30+
}
31+
}
32+
33+
@media (max-width: 400px) {
34+
.navbar div {
35+
grid-template-columns: 1fr;
36+
}
37+
}

src/components/Navbar/Navbar.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import "./Navbar.css";
2+
import Button from "../Button/Button";
3+
import Select from "../Select/Select";
4+
5+
const Navbar = (props) => {
6+
return (
7+
<div className="navbar">
8+
<h1>Sort Visualizer</h1>
9+
<div>
10+
<Button
11+
btnName="Randomize"
12+
onClickHandler={props.randomizeClickHandler}
13+
isDisabled={props.isSorting}
14+
/>
15+
<Select
16+
value={props.algType}
17+
onChangeHandler={props.algChangeHandler}
18+
values={[0, 1]}
19+
options={["Bubble Sort", "Selection Sort"]}
20+
isDisabled={props.isSorting}
21+
/>
22+
<Select
23+
value={props.size}
24+
onChangeHandler={props.sizeChangeHandler}
25+
values={[5, 10, 25, 50, 75, 100]}
26+
options={[5, 10, 25, 50, 75, 100]}
27+
isDisabled={props.isSorting}
28+
/>
29+
<Select
30+
value={props.speed}
31+
onChangeHandler={props.speedChangeHandler}
32+
values={[0.25, 0.5, 1, 2, 4]}
33+
options={["0.25x", "0.5x", "1x", "2x", "4x"]}
34+
isDisabled={props.isSorting}
35+
/>
36+
</div>
37+
</div>
38+
);
39+
};
40+
41+
export default Navbar;

src/components/Select/Select.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.select {
2+
/* background-color: rgb(218, 218, 218); */
3+
background-color: transparent;
4+
border-radius: 10px;
5+
padding-left: 1%;
6+
height: 3rem;
7+
font-size: 1rem;
8+
width: 10rem;
9+
border: 1px solid rgb(218, 218, 218);
10+
margin: 1%;
11+
outline: none;
12+
cursor: pointer;
13+
}
14+
15+
.select:disabled {
16+
cursor: not-allowed;
17+
}

src/components/Select/Select.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ import "./Select.css";
22

33
const Select = (props) => {
44
let options = props.options.map((option, i) => {
5-
return <option value={props.values[i]}>{option}</option>;
5+
return (
6+
<option value={props.values[i]} key={option}>
7+
{option}
8+
</option>
9+
);
610
});
711
return (
812
<select
913
value={props.value}
1014
onChange={props.onChangeHandler}
1115
disabled={props.isDisabled}
16+
className="select"
1217
>
1318
{options}
1419
</select>

0 commit comments

Comments
 (0)