-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d48b42d
commit 910053a
Showing
12 changed files
with
802 additions
and
68 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
94 changes: 94 additions & 0 deletions
94
packages/ui/fern-docs-search-ui/src/components/desktop/FilterDropdownMenu.tsx
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,94 @@ | ||
import { useFacets } from "@/hooks/useFacets"; | ||
import { FacetName, toFilterLabel } from "@/utils/facet"; | ||
import { getFacetDisplay } from "@/utils/facet-display"; | ||
import { FilterX } from "lucide-react"; | ||
import { ReactElement } from "react"; | ||
import { Badge } from "../ui/badge"; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuGroup, | ||
DropdownMenuItem, | ||
DropdownMenuLabel, | ||
DropdownMenuRadioGroup, | ||
DropdownMenuRadioItem, | ||
DropdownMenuSeparator, | ||
DropdownMenuShortcut, | ||
DropdownMenuTrigger, | ||
} from "../ui/dropdown"; | ||
|
||
export function FilterDropdownMenu({ | ||
appId, | ||
apiKey, | ||
domain, | ||
filter, | ||
filters, | ||
removeFilter, | ||
updateFilter, | ||
}: { | ||
appId: string; | ||
apiKey: string; | ||
domain: string; | ||
filter: { | ||
facet: FacetName; | ||
value: string; | ||
}; | ||
removeFilter?: () => void; | ||
updateFilter?: (value: string) => void; | ||
filters: { facet: FacetName; value: string }[]; | ||
}): ReactElement { | ||
const otherFilters = filters.filter((f) => f.facet !== filter.facet); | ||
|
||
const { data: facets } = useFacets({ appId, apiKey, domain, filters: otherFilters }); | ||
|
||
const options = facets?.[filter.facet] ?? []; | ||
|
||
return ( | ||
<DropdownMenu key={`${filter.facet}:${filter.value}`}> | ||
<DropdownMenuTrigger asChild> | ||
<Badge variant="outline" asChild> | ||
<button>{getFacetDisplay(filter.facet, filter.value, { small: true, titleCase: true })}</button> | ||
</Badge> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent | ||
onKeyDownCapture={(e) => { | ||
if (e.key === "Backspace") { | ||
removeFilter?.(); | ||
} | ||
}} | ||
> | ||
<DropdownMenuLabel>{toFilterLabel(filter.facet)}</DropdownMenuLabel> | ||
<DropdownMenuSeparator /> | ||
{options.length > 0 && ( | ||
<> | ||
<DropdownMenuRadioGroup | ||
value={filter.value} | ||
onValueChange={(value) => { | ||
updateFilter?.(value); | ||
}} | ||
> | ||
{options.map((option) => ( | ||
<DropdownMenuRadioItem key={option.value} value={option.value}> | ||
{getFacetDisplay(filter.facet, option.value, { small: true, titleCase: true })} | ||
<DropdownMenuShortcut>{option.count}</DropdownMenuShortcut> | ||
</DropdownMenuRadioItem> | ||
))} | ||
</DropdownMenuRadioGroup> | ||
<DropdownMenuSeparator /> | ||
</> | ||
)} | ||
<DropdownMenuGroup> | ||
<DropdownMenuItem | ||
onSelect={() => { | ||
removeFilter?.(); | ||
}} | ||
> | ||
<FilterX className="size-4" /> | ||
Remove filter | ||
<DropdownMenuShortcut>del</DropdownMenuShortcut> | ||
</DropdownMenuItem> | ||
</DropdownMenuGroup> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
); | ||
} |
36 changes: 36 additions & 0 deletions
36
packages/ui/fern-docs-search-ui/src/components/ui/badge.tsx
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,36 @@ | ||
import { cva, type VariantProps } from "class-variance-authority"; | ||
import * as React from "react"; | ||
|
||
import { Slot } from "@radix-ui/react-slot"; | ||
import { cn } from "./cn"; | ||
|
||
const badgeVariants = cva( | ||
"inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2", | ||
{ | ||
variants: { | ||
variant: { | ||
default: "border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80", | ||
secondary: "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80", | ||
destructive: | ||
"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80", | ||
outline: "text-foreground", | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: "default", | ||
}, | ||
}, | ||
); | ||
|
||
export interface BadgeProps extends React.HTMLAttributes<HTMLDivElement>, VariantProps<typeof badgeVariants> { | ||
asChild?: boolean; | ||
} | ||
|
||
const Badge = React.forwardRef<HTMLDivElement, BadgeProps>(({ className, variant, asChild = false, ...props }, ref) => { | ||
const Comp = asChild ? Slot : "div"; | ||
return <Comp ref={ref} className={cn(badgeVariants({ variant }), className)} {...props} />; | ||
}); | ||
|
||
Badge.displayName = "Badge"; | ||
|
||
export { Badge, badgeVariants }; |
Oops, something went wrong.