Skip to content
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

Added dynamic icons to filters in tools page[Closes #1260] #1309

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions pages/tools/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React, { Dispatch, SetStateAction, useRef } from 'react';
import FilterIcon from '~/public/icons/filter.svg';
import LanguageIcon from '~/public/icons/language.svg';
import ToolingIcon from '~/public/icons/tooling.svg';
import EnvironmentIcon from '~/public/icons/environment.svg';
import DialectIcon from '~/public/icons/dialect.svg';
import LicenseIcon from '~/public/icons/license.svg';
import DropdownMenu from './ui/DropdownMenu';
import Checkbox from './ui/Checkbox';
import SearchBar from './SearchBar';
Expand All @@ -8,6 +12,14 @@ import type { Transform } from '../hooks/useToolsTransform';
import type { FilterCriteriaFields } from '../index.page';
import { postAnalytics } from '../lib/postAnalytics';

const filterIcons = {
languages: LanguageIcon,
toolingTypes: ToolingIcon,
environments: EnvironmentIcon,
drafts: DialectIcon,
licenses: LicenseIcon,
};

interface SidebarProps {
filterCriteria: Record<FilterCriteriaFields, string[]>;
transform: Transform;
Expand Down Expand Up @@ -79,8 +91,14 @@ export default function Sidebar({
<SearchBar transform={transform} />
{filters.map(({ label, accessorKey }) => {
const checkedValues = transform[accessorKey as keyof Transform] || [];
const IconComponent =
filterIcons[accessorKey as keyof typeof filterIcons];
return (
<DropdownMenu key={accessorKey} label={label} icon={<FilterIcon />}>
<DropdownMenu
key={accessorKey}
label={label}
icon={<IconComponent />}
>
{filterCriteria[accessorKey as FilterCriteriaFields]
?.map(String)
.map((filterOption) => (
Expand Down
4 changes: 2 additions & 2 deletions pages/tools/components/ui/DropdownMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ export default function DropdownMenu({
}, [router]);

return (
<div className='my-2 bg-slate-200 dark:bg-slate-900 p-2 rounded'>
<div className='my-2 bg-slate-200 dark:bg-slate-900 p-2 rounded cursor-pointer'>
<div
className='w-full flex justify-between items-center align-middle cursor-pointer'
onClick={() => {
setIsDropdownOpen((prev) => !prev);
}}
>
{React.cloneElement(icon, {
className: 'mr-2',
className: 'mr-2 ml-2',
})}
<div className='text-slate-900 dark:text-slate-300 font-bold mr-auto'>
{label}
Expand Down
1 change: 1 addition & 0 deletions public/icons/dialect.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/environment.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/language.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions public/icons/license.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/icons/tooling.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.