mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-13 15:09:13 +00:00
编译警告修复
This commit is contained in:
@@ -2,13 +2,18 @@ import { useEffect, useImperativeHandle, useRef } from 'react'
|
||||
|
||||
/**
|
||||
* 折叠面板组件,支持水平折叠、垂直折叠
|
||||
* @param {type:['horizontal','vertical'],isOpen} props
|
||||
* @param {type:['horizontal','vertical'], isOpen} props
|
||||
* @returns
|
||||
*/
|
||||
const Collapse = props => {
|
||||
const { collapseRef } = props
|
||||
const Collapse = ({
|
||||
type = 'vertical',
|
||||
isOpen = false,
|
||||
children,
|
||||
onHeightChange,
|
||||
className,
|
||||
collapseRef
|
||||
}) => {
|
||||
const ref = useRef(null)
|
||||
const type = props.type || 'vertical'
|
||||
|
||||
useImperativeHandle(collapseRef, () => {
|
||||
return {
|
||||
@@ -17,7 +22,7 @@ const Collapse = props => {
|
||||
* @param {*} param0
|
||||
*/
|
||||
updateCollapseHeight: ({ height, increase }) => {
|
||||
if (props.isOpen) {
|
||||
if (isOpen) {
|
||||
ref.current.style.height = ref.current.scrollHeight
|
||||
ref.current.style.height = 'auto'
|
||||
}
|
||||
@@ -76,18 +81,18 @@ const Collapse = props => {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (props.isOpen) {
|
||||
if (isOpen) {
|
||||
expandSection(ref.current)
|
||||
} else {
|
||||
collapseSection(ref.current)
|
||||
}
|
||||
// 通知父组件高度变化
|
||||
props?.onHeightChange &&
|
||||
props.onHeightChange({
|
||||
onHeightChange &&
|
||||
onHeightChange({
|
||||
height: ref.current.scrollHeight,
|
||||
increase: props.isOpen
|
||||
increase: isOpen
|
||||
})
|
||||
}, [props.isOpen])
|
||||
}, [isOpen])
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -97,11 +102,10 @@ const Collapse = props => {
|
||||
? { height: '0px', willChange: 'height' }
|
||||
: { width: '0px', willChange: 'width' }
|
||||
}
|
||||
className={`${props.className || ''} overflow-hidden duration-300`}>
|
||||
{props.children}
|
||||
className={`${className || ''} overflow-hidden duration-300`}>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Collapse.defaultProps = { isOpen: false }
|
||||
|
||||
export default Collapse
|
||||
|
||||
@@ -142,5 +142,3 @@ export const Draggable = ({ children, stick }) => {
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Draggable.defaultProps = { left: 0, top: 0 }
|
||||
|
||||
Reference in New Issue
Block a user