mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-11-15 06:45:36 +08:00
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import { JSX, ParentComponent } from 'solid-js'
|
|
import { twMerge } from 'tailwind-merge'
|
|
|
|
type Props = {
|
|
title: JSX.Element
|
|
content: JSX.Element
|
|
isOpen: boolean | undefined
|
|
onCollapse: (collapsed: boolean) => void
|
|
}
|
|
|
|
const Collapse: ParentComponent<Props> = (props) => {
|
|
const { title, content, onCollapse } = props
|
|
|
|
const getCollapseClassName = () => {
|
|
const openedClassName = 'collapse-open'
|
|
const closedClassName = 'collapse-close'
|
|
return props.isOpen ? openedClassName : closedClassName
|
|
}
|
|
|
|
const getCollapseContentClassName = () => {
|
|
const openedClassName = 'opacity-100'
|
|
const closedClassName = 'opacity-0'
|
|
return props.isOpen ? openedClassName : closedClassName
|
|
}
|
|
|
|
return (
|
|
<div
|
|
class={twMerge(
|
|
getCollapseClassName(),
|
|
'collapse collapse-arrow overflow-visible border-secondary bg-base-200',
|
|
)}
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
onChange={(e) => onCollapse(e.target.checked)}
|
|
checked={props.isOpen}
|
|
/>
|
|
<div class="collapse-title text-xl font-medium">{title}</div>
|
|
<div
|
|
class={twMerge(
|
|
getCollapseContentClassName(),
|
|
'collapse-content grid auto-rows-min grid-cols-2 gap-2 transition-opacity duration-1000 lg:grid-cols-3 xl:grid-cols-4',
|
|
)}
|
|
>
|
|
{content}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default Collapse
|