parent
36d2f63607
commit
1862010c5b
@ -1,24 +0,0 @@ |
||||
import React, { useContext } from 'react' |
||||
import { AccordionContext } from 'react-bootstrap' |
||||
import { useAccordionToggle } from 'react-bootstrap/AccordionToggle' |
||||
|
||||
function ContextAwareToggle({ children, eventKey, callback }) { |
||||
const currentEventKey = useContext(AccordionContext) |
||||
|
||||
const decoratedOnClick = useAccordionToggle( |
||||
eventKey, |
||||
() => callback && callback(eventKey), |
||||
); |
||||
|
||||
const isCurrentEventKey = currentEventKey === eventKey; |
||||
|
||||
return ( |
||||
<button |
||||
type="button" |
||||
style={{ backgroundColor: isCurrentEventKey ? 'fas fa-angle-right' : 'fas fa-angle-down' }} |
||||
onClick={decoratedOnClick} |
||||
> |
||||
{children} |
||||
</button> |
||||
); |
||||
} |
@ -0,0 +1,27 @@ |
||||
import React, { useContext, useState } from 'react' |
||||
import { AccordionContext } from 'react-bootstrap' |
||||
import { useAccordionToggle } from 'react-bootstrap/AccordionToggle' |
||||
|
||||
export type CustomAccordionToggleProps = { |
||||
children: React.ReactNode |
||||
eventKey: string |
||||
callback?: any |
||||
} |
||||
|
||||
export default function CustomAccordionToggle({ children, eventKey }: CustomAccordionToggleProps) { |
||||
const [toggleAccordion, setToggleAccordion] = useState(false) |
||||
// <i className={toggleAccordion ? 'fas fa-angle-right' : 'fas fa-angle-down'}></i>
|
||||
|
||||
const decoratedOnClick = useAccordionToggle(eventKey, () => |
||||
setToggleAccordion(!toggleAccordion) |
||||
) |
||||
|
||||
|
||||
return ( |
||||
<div |
||||
onClick={decoratedOnClick} |
||||
> |
||||
{children} |
||||
</div> |
||||
) |
||||
} |
Loading…
Reference in new issue