Skip to content

Commit

Permalink
ClearFiltersButton
Browse files Browse the repository at this point in the history
  • Loading branch information
julihereu committed Jan 1, 2025
1 parent eaba796 commit 812edd4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
2 changes: 2 additions & 0 deletions locales/de/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ CategoriesFilter:
inputPlaceholder: Nach Kategorien filtern
ClearAllButton:
title: Alles löschen
ClearFiltersButton:
title: Filter löschen
ColorSchemeToggle:
buttonToggleTheme: Farbschema wechseln
CopyButton:
Expand Down
2 changes: 2 additions & 0 deletions locales/en/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ CategoriesFilter:
inputPlaceholder: Filter by categories
ClearAllButton:
title: Clear all
ClearFiltersButton:
title: Clear filters
ColorSchemeToggle:
buttonToggleTheme: Toggle theme
CopyButton:
Expand Down
24 changes: 24 additions & 0 deletions src/components/templates/ClearFiltersButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ActionIcon } from "@mantine/core"
import { Eraser as ClearAllIcon } from "lucide-react"
import { useFilter } from "~/contexts/FilterContext"
import { useSiteTranslation } from "~/hooks/useSiteTranslation"

export const ClearFiltersButton = () => {
const { t } = useSiteTranslation()
const filter = useFilter()

return (
<ActionIcon
title={t("ClearFiltersButton.title")}
variant="default"
onClick={() => {
filter.setCategories([])
filter.setLanguage("")
filter.setUsername("")
}}
aria-label="Clear filters"
>
<ClearAllIcon size={20} />
</ActionIcon>
)
}
7 changes: 6 additions & 1 deletion src/components/templates/TemplateFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Paper, Stack } from "@mantine/core"
import { useSiteTranslation } from "~/hooks/useSiteTranslation"
import { PanelToolbar } from "../template/PanelToolbar"
import { CategoriesFilter } from "./CategoriesFilter"
import { ClearFiltersButton } from "./ClearFiltersButton"
import { LanguageFilter } from "./LanguageFilter"
import { TemplatesSorting } from "./TemplatesSorting"
import { UserFilter } from "./UserFilter"
Expand All @@ -18,7 +19,11 @@ export const TemplateFilters = () => {
w="100%"
style={{ flexDirection: "column" }}
>
<PanelToolbar title={t("TemplateFilters.filtersTitle")} />
<PanelToolbar
title={t("TemplateFilters.filtersTitle")}
actions={<ClearFiltersButton />}
actionsPosition="right"
/>
<Stack p="xs" pb="xl" gap="xs">
<LanguageFilter />
<CategoriesFilter />
Expand Down
1 change: 1 addition & 0 deletions src/components/templates/UserFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const UserFilter = () => {
searchValue={prefix}
onSearchChange={(value) => setPrefix(value)}
data={data?.users.map((user) => user.username!) ?? []}
value={filter.username === "" ? null : filter.username}
onChange={(value) => filter.setUsername(value ?? "")}
searchable
clearable
Expand Down

0 comments on commit 812edd4

Please sign in to comment.