import { useState } from 'react'
import { CloseIcon } from 'shared/components/icons.mjs'
const OpenTitleButton = ({ title, toggle, color = 'primary', openButtons = [] }) => (
)
export const Collapse = ({
title,
openTitle = false,
children = [],
buttons = [],
top = true,
bottom = false,
color = 'primary',
opened = false,
toggle = false,
toggleClasses = '',
toggleIcon = '',
onClick = false,
openButtons = null,
}) => {
const [open, setOpen] = useState(opened)
const titleBtn = open ? (
setOpen(false)}
{...{ color, openButtons }}
/>
) : null
return open ? (
{top ? titleBtn : null}
{children}
{bottom ? titleBtn : null}
) : (
setOpen(true)}
>
{title}
{toggle ? (
) : (
buttons
)}
)
}
export const useCollapseButton = (props) => {
// Shared state
const [open, setOpen] = useState(false)
// Method to allow closing the button
const close = () => setOpen(false)
// The component
const CollapseButton = ({
title,
openTitle = false,
children = [],
className = 'btn btn-lg btn-primary',
top = true,
bottom = false,
color = 'primary',
}) => {
const titleBtn = open ? (
setOpen(false)} color={color} />
) : null
return open ? (
{top ? titleBtn : null}
{children}
{bottom ? titleBtn : null}
) : (
)
}
return { CollapseButton, closeCollapseButton: close }
}