change actions to be for any InvExpander or InvSingleAccordion that has id passed in

This commit is contained in:
Mary Hipp
2024-01-17 15:09:44 -05:00
committed by psychedelicious
parent dbd6c9c6ed
commit 84a4836ab7
8 changed files with 31 additions and 59 deletions

View File

@ -6,6 +6,8 @@ import { InvText } from 'common/components/InvText/wrapper';
import { t } from 'i18next';
import { useCallback } from 'react';
import { BiCollapseVertical, BiExpandVertical } from 'react-icons/bi';
import { useAppDispatch } from '../../../app/store/storeHooks';
import { expanderToggled } from '../../../features/parameters/store/actions';
const buttonStyles: SystemStyleObject = {
color: 'base.400',
@ -24,14 +26,18 @@ export const InvExpander = ({
children,
label = t('common.advancedOptions'),
defaultIsOpen = false,
onClick,
id,
}: InvExpanderProps) => {
const { isOpen, onToggle } = useDisclosure({ defaultIsOpen });
const dispatch = useAppDispatch();
const onToggleExpander = useCallback(() => {
onClick && onClick(isOpen);
if (id) {
dispatch(expanderToggled({ id, isOpen }));
}
onToggle();
}, [onClick, onToggle, isOpen]);
}, [id, dispatch, onToggle, isOpen]);
return (
<Flex flexDir="column" w="full">

View File

@ -4,4 +4,5 @@ export type InvExpanderProps = PropsWithChildren<{
label?: string;
defaultIsOpen?: boolean;
onClick?: (isOpen: boolean) => void;
id?: string;
}>;

View File

@ -7,11 +7,16 @@ import {
import { memo, useCallback } from 'react';
import type { InvSingleAccordionProps } from './types';
import { singleAccordionExpanded } from '../../../features/parameters/store/actions';
import { useAppDispatch } from '../../../app/store/storeHooks';
export const InvSingleAccordion = memo((props: InvSingleAccordionProps) => {
const dispatch = useAppDispatch();
const handleAccordionClick = useCallback(
(isExpanded: boolean) => {
props.onClick && props.onClick(isExpanded);
(isOpen: boolean) => {
if (props.id) {
dispatch(singleAccordionExpanded({ id: props.id, isOpen }));
}
},
[props]
);

View File

@ -4,5 +4,5 @@ export type InvSingleAccordionProps = PropsWithChildren<{
label: string;
badges?: (string | number)[];
defaultIsOpen?: boolean;
onClick?: (isOpen?: boolean) => void;
id?: string;
}>;