Skip to content

Commit 5429d2a

Browse files
Merge pull request #4049 from OneCommunityGlobal/Shravya_bugfix__inline_module.css_3809
Shravya_bugfix/css_module.css/mostWastedMaterials _3675
2 parents b3c95d7 + 530d762 commit 5429d2a

8 files changed

Lines changed: 517 additions & 454 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { useState, useRef, useEffect } from 'react';
2+
import styles from './Dropdown.module.css';
3+
import { useSelector } from 'react-redux';
4+
export default function CustomDropdown({ options, selected, onSelect }) {
5+
const darkMode = useSelector(state => state.theme.darkMode);
6+
const [isOpen, setIsOpen] = useState(false);
7+
const dropdownRef = useRef(null);
8+
9+
useEffect(() => {
10+
const handleClickOutside = event => {
11+
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
12+
setIsOpen(false);
13+
}
14+
};
15+
document.addEventListener('mousedown', handleClickOutside);
16+
return () => document.removeEventListener('mousedown', handleClickOutside);
17+
}, []);
18+
19+
return (
20+
<div className={`${darkMode ? styles.darkMode : ''}`}>
21+
<div className={`${styles.dropdownWrapper}`} ref={dropdownRef}>
22+
<button
23+
type="button"
24+
className={`${styles.dropdownButton}`}
25+
onClick={() => setIsOpen(!isOpen)}
26+
>
27+
<span>{selected.name}</span>
28+
<span className={`${isOpen ? styles.arrowOpen : styles.arrow}`}></span>
29+
</button>
30+
31+
{isOpen && (
32+
<div className={`${styles.dropdownMenu}`}>
33+
{options.map(option => (
34+
<button
35+
type="button"
36+
key={option.id}
37+
className={`${styles.dropdownItem}`}
38+
onClick={() => {
39+
onSelect(option);
40+
setIsOpen(false);
41+
}}
42+
>
43+
{option.name}
44+
</button>
45+
))}
46+
</div>
47+
)}
48+
</div>
49+
</div>
50+
);
51+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
.dropdownWrapper {
2+
position: relative;
3+
width: 100%;
4+
margin-top: 30px;
5+
}
6+
7+
.dropdownButton {
8+
width: 100%;
9+
padding: 8px 16px;
10+
text-align: left;
11+
background-color: #ffffff;
12+
border: 1px solid #d1d5db;
13+
border-radius: 6px;
14+
cursor: pointer;
15+
display: flex;
16+
justify-content: space-between;
17+
align-items: center;
18+
font-size: 14px;
19+
}
20+
21+
.arrow {
22+
transition: transform 0.2s;
23+
}
24+
25+
.arrowOpen {
26+
transform: rotate(180deg);
27+
transition: transform 0.2s;
28+
}
29+
30+
.dropdownMenu {
31+
position: absolute;
32+
z-index: 10;
33+
width: 100%;
34+
margin-top: 4px;
35+
background-color: #ffffff;
36+
border: 1px solid #d1d5db;
37+
border-radius: 6px;
38+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
39+
}
40+
41+
.dropdownButton:hover {
42+
background-color: #3b82f6;
43+
color: #ffffff;
44+
}
45+
46+
.dropdownItem {
47+
width: 100%;
48+
padding: 8px 16px;
49+
text-align: left;
50+
background-color: transparent;
51+
border: none;
52+
cursor: pointer;
53+
font-size: 14px;
54+
transition: background-color 0.2s;
55+
}
56+
57+
.dropdownItem:hover {
58+
background-color: #3b82f6;
59+
color: #ffffff;
60+
}
61+
62+
/* Dark Mode Styles */
63+
.darkMode .dropdownButton {
64+
background-color: #1f2937;
65+
border-color: #4b5563;
66+
color: #f3f4f6;
67+
}
68+
69+
.darkMode .arrow,
70+
.darkMode .arrowOpen {
71+
color: #d1d5db;
72+
}
73+
74+
.darkMode .dropdownMenu {
75+
background-color: #1f2937;
76+
border-color: #4b5563;
77+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4);
78+
}
79+
80+
.darkMode .dropdownButton:hover {
81+
background-color: #2563eb;
82+
color: #ffffff;
83+
}
84+
85+
.darkMode .dropdownItem {
86+
color: #f3f4f6;
87+
}
88+
89+
.darkMode .dropdownItem:hover {
90+
background-color: #2563eb;
91+
color: #ffffff;
92+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Custom Label component for displaying percentages on bars
2+
import { useSelector } from 'react-redux';
3+
4+
export default function CustomLabel(props) {
5+
const { x, y, width, value } = props;
6+
const darkMode = useSelector(state => state.theme.darkMode);
7+
return (
8+
<text
9+
x={x + width / 2}
10+
y={y - 5}
11+
fill={darkMode ? '#ffffff' : '#374151'}
12+
textAnchor="middle"
13+
fontSize="12"
14+
fontWeight="500"
15+
>
16+
{`${value}%`}
17+
</text>
18+
);
19+
}

0 commit comments

Comments
 (0)