mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
change actions to be for any InvExpander or InvSingleAccordion that has id passed in
This commit is contained in:
committed by
psychedelicious
parent
dbd6c9c6ed
commit
84a4836ab7
@ -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">
|
||||
|
@ -4,4 +4,5 @@ export type InvExpanderProps = PropsWithChildren<{
|
||||
label?: string;
|
||||
defaultIsOpen?: boolean;
|
||||
onClick?: (isOpen: boolean) => void;
|
||||
id?: string;
|
||||
}>;
|
||||
|
@ -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]
|
||||
);
|
||||
|
@ -4,5 +4,5 @@ export type InvSingleAccordionProps = PropsWithChildren<{
|
||||
label: string;
|
||||
badges?: (string | number)[];
|
||||
defaultIsOpen?: boolean;
|
||||
onClick?: (isOpen?: boolean) => void;
|
||||
id?: string;
|
||||
}>;
|
||||
|
Reference in New Issue
Block a user