2023-09-02 21:00:20 +08:00
|
|
|
import { JSX, ParentComponent, Show, createMemo } from 'solid-js'
|
2023-08-30 23:02:55 +08:00
|
|
|
import { twMerge } from 'tailwind-merge'
|
2023-09-03 03:26:29 +08:00
|
|
|
import { renderInTwoColumn } from '~/signals'
|
2023-08-30 23:02:55 +08:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
title: JSX.Element
|
|
|
|
content: JSX.Element
|
|
|
|
isOpen: boolean | undefined
|
|
|
|
onCollapse: (collapsed: boolean) => void
|
|
|
|
}
|
|
|
|
|
2023-09-03 03:26:29 +08:00
|
|
|
export const Collapse: ParentComponent<Props> = (props) => {
|
2023-08-30 23:02:55 +08:00
|
|
|
const { title, content, onCollapse } = props
|
|
|
|
|
|
|
|
const getCollapseClassName = () => {
|
2023-08-30 23:36:25 +08:00
|
|
|
const openedClassName = 'collapse-open'
|
|
|
|
const closedClassName = 'collapse-close'
|
|
|
|
return props.isOpen ? openedClassName : closedClassName
|
2023-08-30 23:02:55 +08:00
|
|
|
}
|
2023-08-30 23:36:25 +08:00
|
|
|
|
2023-08-30 23:02:55 +08:00
|
|
|
const getCollapseContentClassName = () => {
|
2023-08-30 23:36:25 +08:00
|
|
|
const openedClassName = 'opacity-100'
|
2023-08-31 02:06:26 +08:00
|
|
|
const closedClassName = 'opacity-0'
|
2023-08-30 23:36:25 +08:00
|
|
|
return props.isOpen ? openedClassName : closedClassName
|
2023-08-30 23:02:55 +08:00
|
|
|
}
|
|
|
|
|
2023-09-02 21:00:20 +08:00
|
|
|
const mediaQueryClassName = createMemo(() => {
|
|
|
|
if (renderInTwoColumn()) {
|
|
|
|
return 'lg:grid-cols-3 xl:grid-cols-4'
|
|
|
|
} else {
|
|
|
|
return 'sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 2xl:grid-cols-7'
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2023-08-30 23:02:55 +08:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
class={twMerge(
|
|
|
|
getCollapseClassName(),
|
2023-09-02 13:50:24 +08:00
|
|
|
'collapse collapse-arrow mb-2 select-none overflow-visible border-secondary bg-base-200',
|
2023-08-30 23:02:55 +08:00
|
|
|
)}
|
|
|
|
>
|
2023-09-01 09:47:22 +08:00
|
|
|
<div
|
2023-09-01 15:23:34 +08:00
|
|
|
class="collapse-title pr-4 text-xl font-medium after:!top-8"
|
2023-09-01 09:47:22 +08:00
|
|
|
onClick={() => onCollapse(!props.isOpen)}
|
|
|
|
>
|
|
|
|
{title}
|
|
|
|
</div>
|
2023-08-30 23:02:55 +08:00
|
|
|
<div
|
|
|
|
class={twMerge(
|
|
|
|
getCollapseContentClassName(),
|
2023-09-02 21:00:20 +08:00
|
|
|
mediaQueryClassName(),
|
|
|
|
'collapse-content grid auto-rows-min grid-cols-2 gap-2 transition-opacity duration-1000',
|
2023-08-30 23:02:55 +08:00
|
|
|
)}
|
|
|
|
>
|
2023-09-01 18:14:48 +08:00
|
|
|
<Show when={props.isOpen}>{content}</Show>
|
2023-08-30 23:02:55 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|