Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions frontend/src/main-page/grants/filter-bar/components/FilterCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import { useState } from "react";
import Button from "../../../../components/Button.tsx";
import { faAngleDown, faAngleUp } from "@fortawesome/free-solid-svg-icons";

type SortDirection = "increasing" | "decreasing";

interface FilterCardProps {
directionFirst?: boolean;
initialDirection?: SortDirection;
initialStartDate?: string;
initialEndDate?: string;
onClearAll?: () => void;
onDirectionChange?: (direction: SortDirection) => void;
onDateRangeChange?: (startDate: string, endDate: string) => void;
}

export default function FilterCard({
directionFirst = true, //if true, direction section is shown before date range section
initialDirection = "increasing", //default sort direction is increasing
initialStartDate = "", //default start date is empty string (no filter)
initialEndDate = "", //default end date is empty string (no filter)
onClearAll, //optional callback for when "Clear all" is clicked
onDirectionChange, //optional callback for when sort direction changes
onDateRangeChange, //optional callback for when date range changes
}: FilterCardProps) {
const [direction, setDirection] = useState<SortDirection>(initialDirection);
const [startDate, setStartDate] = useState(initialStartDate);
const [endDate, setEndDate] = useState(initialEndDate);

const handleClearAll = () => {
setDirection("increasing");
setStartDate("");
setEndDate("");
onClearAll?.();
};

const directionSection = (
<div className="flex flex-col gap-2">
<div className="text-sm font-semibold flex justify-between items-center">
<span>Direction</span>
<Button
text="Clear all"
onClick={handleClearAll}
className="text-xs font-semibold text-secondary-400 border-0 hover:text-secondary-400 hover:bg-opacity-0 hover:border hover:border-white"
/>
</div>
<div className="flex gap-2">
<Button
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the original design there were arrows for these buttons as well? I liked how they looked so might be good to add in since it was in the original design

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could look at camila's pr to see basically copy paste the arrow functionality

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2026-02-26 at 1 25 39 PM

logo={faAngleUp}
logoPosition="left"
text="Increasing"
onClick={() => {
setDirection("increasing");
onDirectionChange?.("increasing");
}}
className={
direction === "increasing"
? "bg-primary-900 text-white px-3 py-1 text-sm"
: "bg-white px-3 py-1 text-sm border-1 border-grey-600"
}
/>
<span className="text-sm font-semibold pt-2"> or </span>
<Button
logo={faAngleDown}
logoPosition="left"
text="Decreasing"
onClick={() => {
setDirection("decreasing");
onDirectionChange?.("decreasing");
}}
className={
direction === "decreasing"
? "bg-primary-900 text-white px-3 py-1 text-sm"
: "bg-white px-3 py-1 text-sm border-1 border-grey-600"
}
/>
</div>
</div>
);

// date format: "YYYY-MM-DD"
const dateRangeSection = (
<div className="flex flex-col gap-2">
<div className="text-sm font-semibold flex justify-start">Date Range</div>
<div className="flex gap-2">
<input
className="w-full rounded border border-grey-600 px-2 py-1 text-sm bg-white"
type="date"
value={startDate}
onChange={(e) => {
setStartDate(e.target.value);
onDateRangeChange?.(e.target.value, endDate);
}}
/>
<span className="text-sm font-semibold pt-2"> to </span>
<input
className="w-full rounded border border-grey-600 px-2 py-1 text-sm bg-white"
type="date"
value={endDate}
onChange={(e) => {
setEndDate(e.target.value);
onDateRangeChange?.(startDate, e.target.value);
}}
/>
</div>
</div>
);

const sections = directionFirst
? [directionSection, dateRangeSection]
: [dateRangeSection, directionSection];

return (
<div className="flex flex-col gap-2 rounded-[1rem] border-[0.13rem] border-primary-900 p-4">
{sections}
</div>
);
}