-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: created filter and resizable table columns (#1748)
* enhance: add resize columns * enhance: add created table filter * Update DataTable.tsx * use daterange instead * renamed start->createdStart, end->createdEnd
- Loading branch information
1 parent
ebff364
commit c505de6
Showing
10 changed files
with
313 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,75 @@ | ||
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"; | ||
import * as React from "react"; | ||
import { DayPicker } from "react-day-picker"; | ||
|
||
import { cn } from "~/lib/utils"; | ||
|
||
import { buttonVariants } from "~/components/ui/button"; | ||
|
||
export type CalendarProps = React.ComponentProps<typeof DayPicker>; | ||
|
||
function Calendar({ | ||
className, | ||
classNames, | ||
showOutsideDays = true, | ||
...props | ||
}: CalendarProps) { | ||
return ( | ||
<DayPicker | ||
showOutsideDays={showOutsideDays} | ||
className={cn("p-3", className)} | ||
classNames={{ | ||
months: "flex flex-col space-y-4 sm:flex-row sm:space-x-4 sm:space-y-0", | ||
month: "space-y-4", | ||
caption: "relative flex items-center justify-center pt-1", | ||
caption_label: "text-sm font-medium", | ||
nav: "flex items-center space-x-1", | ||
nav_button: cn( | ||
buttonVariants({ variant: "outline" }), | ||
"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100" | ||
), | ||
nav_button_previous: "absolute left-1", | ||
nav_button_next: "absolute right-1", | ||
table: "w-full border-collapse space-y-1", | ||
head_row: "flex", | ||
head_cell: | ||
"w-8 rounded-md text-[0.8rem] font-normal text-muted-foreground", | ||
row: "mt-2 flex w-full", | ||
cell: cn( | ||
"relative p-0 text-center text-sm focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-accent [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected].day-range-end)]:rounded-r-md", | ||
props.mode === "range" | ||
? "[&:has(>.day-range-end)]:rounded-r-md [&:has(>.day-range-start)]:rounded-l-md first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md" | ||
: "[&:has([aria-selected])]:rounded-md" | ||
), | ||
day: cn( | ||
buttonVariants({ variant: "ghost" }), | ||
"h-8 w-8 p-0 font-normal aria-selected:opacity-100" | ||
), | ||
day_range_start: "day-range-start", | ||
day_range_end: "day-range-end", | ||
day_selected: | ||
"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground", | ||
day_today: "bg-accent text-accent-foreground", | ||
day_outside: | ||
"day-outside text-muted-foreground aria-selected:bg-accent/50 aria-selected:text-muted-foreground", | ||
day_disabled: "text-muted-foreground opacity-50", | ||
day_range_middle: | ||
"aria-selected:bg-accent aria-selected:text-accent-foreground", | ||
day_hidden: "invisible", | ||
...classNames, | ||
}} | ||
components={{ | ||
IconLeft: ({ className, ...props }) => ( | ||
<ChevronLeftIcon className={cn("h-4 w-4", className)} {...props} /> | ||
), | ||
IconRight: ({ className, ...props }) => ( | ||
<ChevronRightIcon className={cn("h-4 w-4", className)} {...props} /> | ||
), | ||
}} | ||
{...props} | ||
/> | ||
); | ||
} | ||
Calendar.displayName = "Calendar"; | ||
|
||
export { Calendar }; |
This file contains 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
This file contains 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,22 @@ | ||
import { isAfter, isBefore, isSameDay } from "date-fns"; | ||
|
||
export const filterByCreatedRange = <T extends { created: string }>( | ||
items: T[], | ||
start: string, | ||
end?: string | null | ||
) => { | ||
const startDate = new Date(start); | ||
const endDate = end ? new Date(end) : undefined; | ||
return items.filter((item) => { | ||
const createdDate = new Date(item.created); | ||
|
||
if (endDate) { | ||
const withinStart = | ||
isAfter(createdDate, startDate) || isSameDay(createdDate, startDate); | ||
const withinEnd = | ||
isBefore(createdDate, endDate) || isSameDay(createdDate, endDate); | ||
return withinStart && withinEnd; | ||
} | ||
return isSameDay(createdDate, startDate); | ||
}); | ||
}; |
This file contains 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
Oops, something went wrong.