diff --git a/dashboard/src/components/Filter/CheckboxSection.stories.tsx b/dashboard/src/components/Filter/CheckboxSection.stories.tsx new file mode 100644 index 0000000..a457599 --- /dev/null +++ b/dashboard/src/components/Filter/CheckboxSection.stories.tsx @@ -0,0 +1,49 @@ +import type { Meta, StoryObj } from '@storybook/react'; +import { fn } from '@storybook/test'; + +import CheckboxSection from './CheckboxSection'; + +const ActionsData = { + onClickItem: fn(), +}; + +const meta: Meta = { + title: 'Filter CheckboxSection', + component: CheckboxSection, + parameters: { + layout: 'centered', + }, + tags: ['autodocs'], + args: { + ...ActionsData, + }, +}; + +export default meta; +type Story = StoryObj; + +export const Default: Story = { + args: { + items: ['linux-5.15.y', 'Status:failed', 'Status: Warnings'], + title: 'Branch', + subtitle: 'Please select one or more Branches', + }, +}; + +export const WithSubSections: Story = { + args: { + title: 'Error Summary', + subsections: [ + { + title: 'Errors', + items: ['linux-5.15.y', 'Status:failed', 'Status: Warnings'], + onClickItem: ActionsData.onClickItem, + }, + { + title: 'Warnings', + items: ['linux-5.15.y', 'Status:failed', 'Status: Warnings'], + onClickItem: ActionsData.onClickItem, + }, + ], + }, +}; diff --git a/dashboard/src/components/Filter/CheckboxSection.tsx b/dashboard/src/components/Filter/CheckboxSection.tsx new file mode 100644 index 0000000..74441c0 --- /dev/null +++ b/dashboard/src/components/Filter/CheckboxSection.tsx @@ -0,0 +1,112 @@ +import cls from 'classnames'; + +import { useCallback, useMemo } from 'react'; + +import Checkbox from '../Checkbox/Checkbox'; + +type TOnClickItem = (itemIdx: number, isChecked: boolean) => void; + +interface ICheckboxSectionItem { + text: string; + onClickItem: TOnClickItem; + idx: number; +} + +interface ICheckboxList { + items: string[]; + onClickItem: TOnClickItem; +} + +interface ICheckboxSubsection { + items: string[]; + title: string; + onClickItem: TOnClickItem; +} + +interface ICheckboxSection { + items?: string[]; + title: string; + subtitle?: string; + subsections?: ICheckboxSubsection[]; + onClickItem: TOnClickItem; + className?: string; +} + +const CheckboxSectionItem = ({ + text, + onClickItem, + idx, +}: ICheckboxSectionItem): JSX.Element => { + const handleOnToggle = useCallback( + (isChecked: boolean) => onClickItem(idx, isChecked), + [idx, onClickItem], + ); + return ; +}; + +const CheckboxList = ({ items, onClickItem }: ICheckboxList): JSX.Element => { + const itemComponents = useMemo( + () => + items.map((text, idx) => ( + + )), + [items, onClickItem], + ); + + return ( +
+ {itemComponents} +
+ ); +}; + +const CheckboxSubsection = ({ + title, + items, + onClickItem, +}: ICheckboxSubsection): JSX.Element => { + return ( +
+

{title}

+ +
+ ); +}; + +const CheckboxSection = ({ + items, + title, + subtitle, + onClickItem, + subsections, + className, +}: ICheckboxSection): JSX.Element => { + const subsectionComponents = useMemo( + () => + subsections?.map(subsection => ( + + )), + [subsections], + ); + + return ( +
+

{title}

+

{subtitle}

+ {items && } + {subsectionComponents} +
+ ); +}; + +export default CheckboxSection; diff --git a/dashboard/tailwind.config.js b/dashboard/tailwind.config.js index 32ee143..6e75cf3 100644 --- a/dashboard/tailwind.config.js +++ b/dashboard/tailwind.config.js @@ -39,6 +39,7 @@ module.exports = { "lightGray": '#F4F4F4', "mediumGray": '#EAEAEA', "darkGray": '#D6D6D6', + "dimGray": '#454545', "black": '#000000', "lightRed": '#FFBBBB', "yellow": '#FFD27C',