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

feat: updated filters dropdown and created stories for it #3174

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
5eda3ab
updated filters dropdown in tools
devilkiller-ag Aug 29, 2024
08ce480
Merge branch 'master' into update-filters-dropdown
devilkiller-ag Aug 29, 2024
67023b9
added stories for filters dropdown
devilkiller-ag Sep 4, 2024
bf0d3c0
Merge branch 'master' into update-filters-dropdown
devilkiller-ag Sep 4, 2024
5d83bdc
Merge branch 'master' into update-filters-dropdown
asyncapi-bot Sep 6, 2024
8d2b79d
Merge branch 'master' into update-filters-dropdown
devilkiller-ag Sep 14, 2024
88db099
Merge branch 'master' into update-filters-dropdown
devilkiller-ag Sep 15, 2024
bd3efbb
Merge branch 'master' into update-filters-dropdown
devilkiller-ag Sep 17, 2024
09a5c76
Merge branch 'master' of https://github.com/asyncapi/website into upd…
devilkiller-ag Sep 24, 2024
3d94fcd
Merge branch 'asyncapi:master' into update-filters-dropdown
devilkiller-ag Sep 28, 2024
776008a
Merge branch 'asyncapi:master' into update-filters-dropdown
devilkiller-ag Sep 30, 2024
1903c13
Merge branch 'master' of https://github.com/asyncapi/website into upd…
devilkiller-ag Jan 6, 2025
f501d55
fixed ci issue, and updated the design
devilkiller-ag Jan 6, 2025
36dcfd3
Merge branch 'asyncapi:master' into update-filters-dropdown
devilkiller-ag Jan 8, 2025
9971ea0
Merge branch 'master' into update-filters-dropdown
devilkiller-ag Jan 21, 2025
50ea482
Merge branch 'asyncapi:master' into update-filters-dropdown
devilkiller-ag Jan 31, 2025
e4e5a7b
feat: shortened filters dropdown height and added functionality to pe…
devilkiller-ag Jan 31, 2025
ec9aa51
fix: lint issue
devilkiller-ag Jan 31, 2025
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
75 changes: 75 additions & 0 deletions components/tools/FiltersDropdown.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { useArgs } from '@storybook/preview-api';
import type { Meta, StoryObj } from '@storybook/react';

import type { Language, Technology } from '@/types/components/tools/ToolDataType';

import tags from '../../config/all-tags.json';
import FiltersDropdown from './FiltersDropdown';

const meta: Meta<typeof FiltersDropdown> = {
title: 'Components/FiltersDropdown',
component: FiltersDropdown,
argTypes: {
dataList: {
control: false
},
checkedOptions: {
control: {
type: 'object'
}
},
setCheckedOptions: {
control: false
}
}
};

export default meta;

type Story = StoryObj<typeof FiltersDropdown>;

const Dropdown: Story = {
args: {
checkedOptions: []
},

render: (args) => {
const [{ checkedOptions }, updateArgs] = useArgs();

const setCheckedOptions: React.Dispatch<React.SetStateAction<string[]>> = (newValue) => {
if (typeof newValue === 'function') {
const updatedValue = (newValue as (prevState: string[]) => string[])(checkedOptions);

updateArgs({ checkedOptions: updatedValue });
} else {
updateArgs({ checkedOptions: newValue });
}
};

return <FiltersDropdown {...args} checkedOptions={checkedOptions} setCheckedOptions={setCheckedOptions} />;
}
};

const languageList = tags.languages as Language[];

export const LanguageDropdown: Story = {
...Dropdown,

args: {
...Dropdown.args,
dataList: languageList,
checkedOptions: []
}
};

const technologyList = tags.technologies as Technology[];

export const TechnologyDropdown: Story = {
...Dropdown,

args: {
...Dropdown.args,
dataList: technologyList,
checkedOptions: []
}
};
27 changes: 21 additions & 6 deletions components/tools/FiltersDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import { twMerge } from 'tailwind-merge';

import type { Category, Language, Technology } from '@/types/components/tools/ToolDataType';

import Checkbox from './Checkbox';

type DataList = Language[] | Technology[] | Category[];

interface FiltersDropdownProps {
export interface FiltersDropdownProps {
dataList?: DataList;
checkedOptions?: string[];
setCheckedOptions: React.Dispatch<React.SetStateAction<string[]>>;
Expand All @@ -28,7 +26,7 @@ export default function FiltersDropdown({
setCheckedOptions,
className = ''
}: FiltersDropdownProps) {
const handleClickOption = (option: string) => {
const handleClickOption = (event: React.MouseEvent<HTMLDivElement, MouseEvent>, option: string) => {
const isChecked = checkedOptions.includes(option);
const updatedOptions = isChecked ? checkedOptions.filter((item) => item !== option) : [...checkedOptions, option];

Expand All @@ -37,13 +35,30 @@ export default function FiltersDropdown({

return (
<div
className={twMerge(`max-w-lg flex gap-2 flex-wrap p-2 duration-200 delay-150 ${className}`)}
className={twMerge(
`max-w-lg flex flex-col max-h-[40vh] gap-1 overflow-y-auto p-2 px-0 duration-200 delay-150 bg-gray-200 ${className}`
)}
data-testid='FiltersDropdown-div'
>
{dataList.map((data, index) => {
const checked = checkedOptions.includes(data.name);

return <Checkbox key={index} name={data.name} checked={checked} handleClickOption={handleClickOption} />;
return (
<div
key={index}
className={twMerge(
`hover:bg-gray-300 text-black p-1 py-2 gap-1 flex cursor-pointer items-start ${checked ? 'bg-gray-400' : ''}`
)}
onClick={(event) => handleClickOption(event, data.name)}
>
{checked ? (
<img src='/img/illustrations/icons/CheckedIcon.svg' alt='checked' />
) : (
<img src='/img/illustrations/icons/UncheckedIcon.svg' alt='unchecked' />
)}
<div className='-mt-px mb-px text-xs'>{data.name}</div>
</div>
);
Comment on lines +46 to +61
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance accessibility and maintainability.

Several improvements could be made to the rendering logic:

  1. Use semantic HTML:
-          <div
+          <button
             key={index}
             className={twMerge(
-              `hover:bg-gray-300 text-black p-1 py-2 gap-1 flex cursor-pointer items-start ${checked ? 'bg-gray-400' : ''}`
+              `hover:bg-gray-300 text-black p-1 py-2 gap-1 flex items-start ${checked ? 'bg-gray-400' : ''}`
             )}
-            onClick={(event) => handleClickOption(event, data.name)}
+            onClick={() => handleClickOption(data.name)}
-          >
+            type="button"
+            aria-pressed={checked}
+          >
  1. Extract icon paths as constants:
const ICON_PATHS = {
  checked: '/img/illustrations/icons/CheckedIcon.svg',
  unchecked: '/img/illustrations/icons/UncheckedIcon.svg'
} as const;
  1. Consider increasing text size for better readability:
-            <div className='-mt-px mb-px text-xs'>{data.name}</div>
+            <div className='-mt-px mb-px text-sm'>{data.name}</div>

})}
</div>
);
Expand Down
Loading
Loading