-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from danskernesdigitalebibliotek/DDFBRA-127-mo…
…bile-view Filters - mobile view
- Loading branch information
Showing
21 changed files
with
458 additions
and
117 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"use client" | ||
|
||
import * as AccordionPrimitive from "@radix-ui/react-accordion" | ||
import { ChevronDownIcon } from "@radix-ui/react-icons" | ||
import * as React from "react" | ||
|
||
import { cn } from "@/lib/helpers/helper.cn" | ||
|
||
const Accordion = AccordionPrimitive.Root | ||
|
||
const AccordionItem = React.forwardRef< | ||
React.ElementRef<typeof AccordionPrimitive.Item>, | ||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item> | ||
>(({ className, children, ...props }, ref) => ( | ||
<AccordionPrimitive.Item ref={ref} className={cn(className)} {...props}> | ||
{children} | ||
<hr className="mb-1 mt-1 w-full border-foreground opacity-10" /> | ||
</AccordionPrimitive.Item> | ||
)) | ||
AccordionItem.displayName = "AccordionItem" | ||
|
||
const AccordionTrigger = React.forwardRef< | ||
React.ElementRef<typeof AccordionPrimitive.Trigger>, | ||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger> | ||
>(({ className, children, ...props }, ref) => ( | ||
<AccordionPrimitive.Header className="flex"> | ||
<AccordionPrimitive.Trigger | ||
ref={ref} | ||
className={cn( | ||
`text-sm flex flex-1 items-center justify-between rounded-md p-4 text-left text-typo-subtitle-md | ||
font-medium transition-all hover:bg-background-overlay [&[data-state=open]>svg]:rotate-180`, | ||
className | ||
)} | ||
{...props}> | ||
{children} | ||
<ChevronDownIcon className="h-8 w-8 shrink-0 text-muted-foreground transition-transform duration-200" /> | ||
</AccordionPrimitive.Trigger> | ||
</AccordionPrimitive.Header> | ||
)) | ||
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName | ||
|
||
const AccordionContent = React.forwardRef< | ||
React.ElementRef<typeof AccordionPrimitive.Content>, | ||
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content> | ||
>(({ className, children, ...props }, ref) => ( | ||
<AccordionPrimitive.Content | ||
ref={ref} | ||
className="text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down | ||
overflow-hidden p-4 pt-1" | ||
{...props}> | ||
<div className={cn(className)}>{children}</div> | ||
</AccordionPrimitive.Content> | ||
)) | ||
AccordionContent.displayName = AccordionPrimitive.Content.displayName | ||
|
||
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent } |
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
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,27 @@ | ||
import React from "react" | ||
|
||
import { cn } from "@/lib/helpers/helper.cn" | ||
|
||
type BadgeButtonProps = { | ||
onClick: () => void | ||
isActive?: boolean | ||
classNames?: string | ||
children: React.ReactNode | ||
} | ||
|
||
const BadgeButton = ({ onClick, isActive = false, classNames, children }: BadgeButtonProps) => { | ||
return ( | ||
<button | ||
onClick={onClick} | ||
className={cn( | ||
`focus-visible h-[29px] w-auto self-start whitespace-nowrap rounded-full bg-background-overlay px-4 | ||
py-2 text-typo-caption hover:animate-wiggle`, | ||
isActive && "bg-foreground text-background", | ||
classNames, | ||
)}> | ||
{children} | ||
</button> | ||
) | ||
} | ||
|
||
export default BadgeButton |
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
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,91 @@ | ||
import { useRouter, useSearchParams } from "next/navigation" | ||
import React, { useState } from "react" | ||
|
||
import { | ||
Accordion, | ||
AccordionContent, | ||
AccordionItem, | ||
AccordionTrigger, | ||
} from "@/components/accordion/Accordion" | ||
import BadgeButton from "@/components/shared/badge/BadgeButton" | ||
import Icon from "@/components/shared/icon/Icon" | ||
import { | ||
getActiveFilters, | ||
getFacetTranslation, | ||
shouldShowActiveFilters, | ||
toggleFilter, | ||
} from "@/components/shared/searchFilters/helper" | ||
import { Sheet, SheetContent, SheetTrigger } from "@/components/shared/sheet/Sheet" | ||
import { SearchFacetFragment, SearchFiltersInput } from "@/lib/graphql/generated/fbi/graphql" | ||
|
||
type SearchFiltersMobileProps = { | ||
facets: SearchFacetFragment[] | ||
} | ||
|
||
const SearchFiltersMobile = ({ facets }: SearchFiltersMobileProps) => { | ||
const router = useRouter() | ||
const searchParams = useSearchParams() | ||
const [isSheetOpen, setIsSheetOpen] = useState(false) | ||
|
||
return ( | ||
<Sheet open={isSheetOpen} onOpenChange={setIsSheetOpen}> | ||
<SheetTrigger | ||
aria-label="Vis filtreringsmuligheder" | ||
onClick={() => setIsSheetOpen(!isSheetOpen)} | ||
className="flex flex-row items-center gap-1 pr-4 text-typo-link hover:bg-background-overlay"> | ||
<Icon name="adjust" className="h-[40px]" /> | ||
VIS FILTRE | ||
</SheetTrigger> | ||
|
||
{/* Show currently selected filters */} | ||
{shouldShowActiveFilters(facets, searchParams) && ( | ||
<div className="flex flex-row flex-wrap gap-1 pt-2"> | ||
{getActiveFilters(facets, searchParams).map(facet => { | ||
return facet.values.map(value => { | ||
return ( | ||
<BadgeButton | ||
onClick={() => { | ||
toggleFilter(facet.name, value.term, router) | ||
}} | ||
key={value.term} | ||
isActive | ||
classNames="flex flex-row items-center pr-1"> | ||
{value.term} | ||
<Icon name="close" className="w-[25px]" /> | ||
</BadgeButton> | ||
) | ||
}) | ||
})} | ||
</div> | ||
)} | ||
|
||
<SheetContent className="w-full p-grid-edge pt-20" side="bottom"> | ||
<Accordion type="multiple" defaultValue={facets.map(facet => facet.name)}> | ||
{facets.map(facet => { | ||
const facetName = facet.name as keyof SearchFiltersInput | ||
return ( | ||
<AccordionItem key={facetName} value={facetName}> | ||
<AccordionTrigger>{getFacetTranslation(facetName)}</AccordionTrigger> | ||
<AccordionContent className="flex flex-wrap gap-1"> | ||
{facet.values.map((value, index) => ( | ||
<BadgeButton | ||
onClick={() => { | ||
setIsSheetOpen(false) | ||
toggleFilter(facet.name, value.term, router) | ||
}} | ||
isActive={!!searchParams.getAll(facet.name).includes(value.term)} | ||
key={index}> | ||
{value.term} | ||
</BadgeButton> | ||
))} | ||
</AccordionContent> | ||
</AccordionItem> | ||
) | ||
})} | ||
</Accordion> | ||
</SheetContent> | ||
</Sheet> | ||
) | ||
} | ||
|
||
export default SearchFiltersMobile |
Oops, something went wrong.