Skip to content

Commit 616ab93

Browse files
feat: that dropdown was annoying me
1 parent 5de920d commit 616ab93

File tree

4 files changed

+55
-145
lines changed

4 files changed

+55
-145
lines changed

src/components/SortDropdown.tsx

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,36 @@
1-
import React, { useState } from "react";
21
import "../styles/components/SortDropdown.css";
3-
import { FaChevronDown } from "react-icons/fa";
4-
import { FaChevronUp } from "react-icons/fa6";
52
import { SortDropdownProps } from "../utils/types";
3+
import { FaArrowDownShortWide, FaArrowDownWideShort } from "react-icons/fa6";
64
const SortDropdown: React.FC<SortDropdownProps> = ({
75
setSortField,
86
setSortType,
97
sortField,
108
sortType,
119
}) => {
12-
const [showMenu, setShowMenu] = useState(false);
13-
1410
const toggleSort = () => {
1511
setSortType(sortType === "desc" ? "asc" : "desc");
1612
}
17-
const toggleDropdown = () => {
18-
setShowMenu(!showMenu);
19-
};
20-
const handleSortField = (field: string) => {
21-
setSortField(field);
22-
};
23-
13+
14+
const handleSortChange: React.ChangeEventHandler<HTMLSelectElement> = (e) => {
15+
e.preventDefault();
16+
setSortField(e.target.value);
17+
}
18+
2419
return (
25-
<div className={`dropdown ${showMenu ? "show" : ""}`}>
20+
<div className="dropdown">
2621
<div className="sort-container">
27-
<button disabled={window.innerWidth >= 1200} onClick={toggleDropdown} >
28-
Sort by:{" "}{sortField.charAt(0).toUpperCase()+sortField.slice(1)}
29-
</button>
30-
31-
<div className="sort-Arrow-container" onClick={toggleSort}>
32-
{sortType==="desc"?<FaChevronDown/>:<FaChevronUp/>}
33-
</div>
34-
</div>
35-
36-
37-
<div className={`dropdown-content ${showMenu ? "show" : "hidden"}`}>
38-
<div className={`dropdown-item ${"name" === sortField ? "selected" : ""}`} onClick={() => handleSortField("name")}>
39-
{" "}
40-
41-
Name
42-
</div>
43-
<div className={`dropdown-item ${"forks" === sortField ? "selected" : ""}`} onClick={() => handleSortField("forks")}>
44-
<span
45-
46-
></span>
47-
Forks
48-
</div>
49-
<div className={`dropdown-item ${"stars" === sortField ? "selected" : ""}`} onClick={() => handleSortField("stars")}>
50-
51-
Stars
52-
</div>
53-
<div className={`dropdown-item ${"activity" === sortField ? "selected" : ""}`} onClick={() => handleSortField("activity")}>
54-
55-
Activity
56-
</div>
57-
58-
22+
<label htmlFor="sort-select">Sort by:</label>
23+
24+
<select className="sort-select" onChange={handleSortChange} value={sortField}>
25+
<option value="name">Name</option>
26+
<option value="forks">Forks</option>
27+
<option value="stars">Stars</option>
28+
<option value="activity">Activity</option>
29+
</select>
30+
</div>
31+
32+
<div className="sort-Arrow-container" onClick={toggleSort}>
33+
{sortType === "asc" ? <><FaArrowDownShortWide /> Ascending</> : <><FaArrowDownWideShort /> Descending</>}
5934
</div>
6035
</div>
6136
);

src/pages/Projects.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import SortDropdown from "../components/SortDropdown";
77
import PaginatedCardGrid from "../sections/CardGrid";
88
const Projects = () => {
99
const repoList: REPO_DATA_TYPE[] = RepoData as REPO_DATA_TYPE[]
10-
const [sortField, setSortField] = useState("activity");
10+
const [sortField, setSortField] = useState("stars");
1111
const [sortType, setSortType] = useState("desc")
1212
const languages = [...new Set(repoList.map(repo => repo.language))];
1313
const [selectedLanguage, setSelectedLanguage] = useState<string[]>([]);
1414
const [FilteredRepos, setFilteredRepos] = useState<REPO_DATA_TYPE[]>(repoList);
1515

1616

1717
//sorting based on STARS ,FORKS , NAME
18-
// and Also filtered by Language
18+
// and Also filtered by Language
1919
useEffect(() => {
2020
let result = repoList.filter((repo) =>
2121
selectedLanguage.length === 0 || selectedLanguage.includes(repo.language)
@@ -98,7 +98,6 @@ const Projects = () => {
9898
sortType={sortType}
9999
/>
100100

101-
102101
</div>
103102
<PaginatedCardGrid repos={FilteredRepos} displayMode="all" />
104103
</div>
Lines changed: 23 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,42 @@
11
.dropdown {
2-
position: relative;
3-
display: inline-block;
4-
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
5-
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
6-
width: 250px;
7-
padding: 10px;
2+
display: flex;
3+
gap: 0.5rem;
4+
height: fit-content;
85
}
96

10-
.selected {
11-
background-color: #393737;
12-
border-radius: 0 0 5px 5px;
13-
}
147
.sort-container {
15-
border-radius: 5px;
16-
cursor: pointer;
17-
transition: background 300ms, color 300ms, scale 300ms;
188
display: flex;
9+
gap: 5px;
1910
}
20-
.sort-container button{
21-
color: #fcfcfc;
22-
background-color: #2f2f2f;
23-
width: 200px;
24-
border-radius: 5px 0 0 5px;
25-
text-align: left;
26-
border: none;
27-
padding: 8px 15px ;
2811

12+
.sort-container label {
13+
align-content: center;
2914
}
30-
.sort-Arrow-container{
15+
16+
.sort-Arrow-container {
3117
display: flex;
18+
gap: 5px;
19+
padding: 0 0.5rem;
20+
3221
justify-content: center;
3322
align-items: center;
3423
background-color: #2f2f2f;
35-
width: 30px;
36-
border-radius: 0 5px 5px 0;
37-
border-left: 1px solid #4e4d4d;
38-
}
39-
24+
border-radius: 5px;
4025

41-
.dropdown-content {
42-
opacity: 0;
43-
transition: opacity 0.3s ease, transform 0.3s ease;
44-
position: absolute;
45-
border-radius: 0 0 5px 5px;
46-
background-color: #2f2f2f;
47-
color: #fcfcfc;
48-
width: 200px;
49-
50-
z-index: 1;
26+
user-select: none;
5127
}
5228

53-
.dropdown-content div {
54-
padding: 10px 20px;
29+
.sort-Arrow-container:hover {
5530
cursor: pointer;
56-
display: flex;
57-
58-
align-items: center;
59-
}
60-
61-
.dropdown-item {
62-
text-align: center;
63-
font-size: small;
64-
transition: background 300ms, color 300ms, scale 300ms;
65-
}
66-
.dropdown-item:hover {
67-
background-color: #393737;
68-
border-radius: 0 0 5px 5px;
6931
}
7032

33+
.sort-select {
34+
transition: opacity 0.3s ease, transform 0.3s ease;
35+
border-radius: 5px;
36+
background-color: #2f2f2f;
37+
color: #fcfcfc;
38+
width: 200px;
39+
border: none;
7140

72-
/*
73-
for large screens toggle on hover */
74-
.dropdown:hover .dropdown-content {
75-
opacity: 1;
76-
transform: translateY(0);
77-
}
78-
79-
.dropdown:hover .sort-container button{
80-
border-radius: 5px 0 0 0;
81-
}
82-
83-
/*
84-
for small screens toggling on click */
85-
.dropdown-content.show {
86-
opacity: 1;
87-
transform: translateY(0);
88-
89-
}
90-
.dropdown.show .sort-container button{
91-
border-radius: 5px 0 0 0 ;
92-
93-
}
94-
95-
96-
97-
98-
99-
100-
101-
@media (max-width: 1200px) {
102-
.hidden {
103-
display: none;
104-
}
105-
106-
}
41+
padding: 8px 15px;
42+
}

src/styles/pages/Projects.css

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
display: flex;
33
flex-wrap: wrap;
44
gap: 0.5rem;
5-
margin-bottom: 20px;
6-
padding: 10px;
7-
/* background: #f5f5f5; */
8-
border-radius: 10px;
95
overflow-x: auto;
106
white-space: nowrap;
117
}
12-
.filter-container{
138

14-
display: flex;
15-
justify-content: space-between;
9+
.filter-container {
10+
display: flex;
11+
width: 100%;
12+
gap: 0.8rem;
13+
padding: 10px 0;
14+
flex-direction: column;
1615
}
16+
1717
.filter-button {
1818
border: none;
1919
padding: 8px 15px;
20-
box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.3);
20+
/* box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.3); */
2121
font-size: 14px;
2222
cursor: pointer;
2323
background-color: #2f2f2f;
@@ -35,8 +35,8 @@ justify-content: space-between;
3535
font-weight: bold;
3636
}
3737

38-
@media (max-width:1024px){
39-
.filter-container{
38+
@media (max-width:1024px) {
39+
.filter-container {
4040
flex-direction: column;
4141
}
4242
}

0 commit comments

Comments
 (0)