-
Notifications
You must be signed in to change notification settings - Fork 0
filter card component #330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yumi520
wants to merge
8
commits into
main
Choose a base branch
from
310/grant-filter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b7b5654
filter card component
yumi520 e9e9e56
Merge branch 'main' into 310/grant-filter
yumi520 75dfe2c
fixed styling
yumi520 cfb0fd6
Remove unused import of React in FilterCard.tsx
yumi520 81eea1f
removed grant-button
yumi520 55ca26e
Merge branch 'main' into 310/grant-filter
yumi520 facae55
Merge branch '310/grant-filter' of https://github.com/Code-4-Communit…
yumi520 797a405
added arrow logo on button
yumi520 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
frontend/src/main-page/grants/filter-bar/components/FilterCard.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| 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> | ||
| ); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.