Skip to content

Commit 49428ee

Browse files
authored
Merge pull request #386 from Code-4-Community/#384/change/cost-revenue-buttons
Fixed cost/revenue button highlights
2 parents 51c0633 + 52db716 commit 49428ee

1 file changed

Lines changed: 25 additions & 5 deletions

File tree

‎frontend/src/main-page/cash-flow/components/CashCreateLineItem.tsx‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,39 @@ import CashAddCosts from "./CashAddCosts";
55

66
export default function CashCreateLineItem() {
77
const [showCosts, setShowCosts] = useState<boolean>(false);
8+
const [pressedTab, setPressedTab] = useState<"Revenue" | "Costs" | null>(null);
9+
10+
const highlightedRevenue =
11+
pressedTab === "Revenue" || (!showCosts && pressedTab !== "Costs");
12+
const highlightedCosts =
13+
pressedTab === "Costs" || (showCosts && pressedTab !== "Revenue");
14+
15+
const setPressedFromEvent = (target: EventTarget | null) => {
16+
const button = (target as HTMLElement | null)?.closest("button");
17+
const text = button?.textContent?.trim();
18+
if (text === "Revenue" || text === "Costs") {
19+
setPressedTab(text);
20+
}
21+
};
822

923
return (
1024
<div className="chart-container col-span-2 h-full">
11-
<div className="flex flex-row rounded-4xl p-1 border border-grey-500 mb-2 text-sm lg:text-base">
25+
<div
26+
className="flex flex-row rounded-4xl p-1 border border-grey-500 mb-2 text-sm lg:text-base"
27+
onPointerDownCapture={(event) => setPressedFromEvent(event.target)}
28+
onPointerUpCapture={() => setPressedTab(null)}
29+
onPointerLeave={() => setPressedTab(null)}
30+
onPointerCancelCapture={() => setPressedTab(null)}
31+
>
1232
<Button
1333
text="Revenue"
14-
onClick={() => setShowCosts(!showCosts)}
15-
className={`w-1/2 font-semibold ${!showCosts ? "bg-primary-900 text-white" : "bg-white"}`}
34+
onClick={() => setShowCosts(false)}
35+
className={`w-1/2 font-semibold ${highlightedRevenue ? "bg-primary-900 text-white" : "bg-white"}`}
1636
/>
1737
<Button
1838
text="Costs"
19-
onClick={() => setShowCosts(!showCosts)}
20-
className={`w-1/2 font-semibold ${showCosts ? "bg-primary-900 text-white" : "bg-white"}`}
39+
onClick={() => setShowCosts(true)}
40+
className={`w-1/2 font-semibold ${highlightedCosts ? "bg-primary-900 text-white" : "bg-white"}`}
2141
/>
2242
</div>
2343

0 commit comments

Comments
 (0)