-
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
4
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
4 commits
Select commit
Hold shift + click to select a range
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
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
113 changes: 113 additions & 0 deletions
113
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,113 @@ | ||
| import { useState } from "react"; | ||
| import Button from "../../../settings/components/Button"; | ||
|
|
||
| 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="bg-opacity-0 border-0 hover:border-0 focus:outline-none focus:ring-0 focus:border-0 text-xs font-semibold text-secondary-400 px-0 py-0" | ||
| /> | ||
| </div> | ||
| <div className="flex gap-2"> | ||
| <Button | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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 | ||
| 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.
Is there a reason you added grant-button here?