diff --git a/lib/components/accordion/standalone-accordion.stories.tsx b/lib/components/accordion/standalone-accordion.stories.tsx index b389286..8ff380a 100644 --- a/lib/components/accordion/standalone-accordion.stories.tsx +++ b/lib/components/accordion/standalone-accordion.stories.tsx @@ -1,3 +1,4 @@ +import { useDisclosure } from '@chakra-ui/react'; import type { Meta, StoryObj } from '@storybook/react'; import { Tab, TabList, TabPanel, TabPanels, Tabs } from '../tabs'; @@ -15,12 +16,14 @@ export default meta; type Story = StoryObj; const Component = (props: StandaloneAccordionProps) => { + const { isOpen, onToggle } = useDisclosure(); return ( diff --git a/lib/components/accordion/standalone-accordion.tsx b/lib/components/accordion/standalone-accordion.tsx index 619753d..e1a41a0 100644 --- a/lib/components/accordion/standalone-accordion.tsx +++ b/lib/components/accordion/standalone-accordion.tsx @@ -1,5 +1,5 @@ -import type { PropsWithChildren } from 'react'; -import { memo } from 'react'; +import type { MouseEventHandler, PropsWithChildren } from 'react'; +import { memo, useCallback } from 'react'; import { AccordionButton } from './accordion-button'; import { Accordion, AccordionItem, AccordionPanel } from './wrapper'; @@ -7,14 +7,24 @@ import { Accordion, AccordionItem, AccordionPanel } from './wrapper'; export type StandaloneAccordionProps = PropsWithChildren<{ label: string; badges?: (string | number)[]; - defaultIsOpen?: boolean; + isOpen: boolean; + onToggle: () => void; }>; export const StandaloneAccordion = memo((props: StandaloneAccordionProps) => { + const onClick = useCallback>( + (e) => { + e.preventDefault(); + props.onToggle(); + }, + [props] + ); return ( - + - {props.label} + + {props.label} + {props.children}