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
|
* @returns
|
||||||
*/
|
*/
|
||||||
const Collapse = props => {
|
const Collapse = ({
|
||||||
const { collapseRef } = props
|
type = 'vertical',
|
||||||
|
isOpen = false,
|
||||||
|
children,
|
||||||
|
onHeightChange,
|
||||||
|
className,
|
||||||
|
collapseRef
|
||||||
|
}) => {
|
||||||
const ref = useRef(null)
|
const ref = useRef(null)
|
||||||
const type = props.type || 'vertical'
|
|
||||||
|
|
||||||
useImperativeHandle(collapseRef, () => {
|
useImperativeHandle(collapseRef, () => {
|
||||||
return {
|
return {
|
||||||
@@ -17,7 +22,7 @@ const Collapse = props => {
|
|||||||
* @param {*} param0
|
* @param {*} param0
|
||||||
*/
|
*/
|
||||||
updateCollapseHeight: ({ height, increase }) => {
|
updateCollapseHeight: ({ height, increase }) => {
|
||||||
if (props.isOpen) {
|
if (isOpen) {
|
||||||
ref.current.style.height = ref.current.scrollHeight
|
ref.current.style.height = ref.current.scrollHeight
|
||||||
ref.current.style.height = 'auto'
|
ref.current.style.height = 'auto'
|
||||||
}
|
}
|
||||||
@@ -76,18 +81,18 @@ const Collapse = props => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (props.isOpen) {
|
if (isOpen) {
|
||||||
expandSection(ref.current)
|
expandSection(ref.current)
|
||||||
} else {
|
} else {
|
||||||
collapseSection(ref.current)
|
collapseSection(ref.current)
|
||||||
}
|
}
|
||||||
// 通知父组件高度变化
|
// 通知父组件高度变化
|
||||||
props?.onHeightChange &&
|
onHeightChange &&
|
||||||
props.onHeightChange({
|
onHeightChange({
|
||||||
height: ref.current.scrollHeight,
|
height: ref.current.scrollHeight,
|
||||||
increase: props.isOpen
|
increase: isOpen
|
||||||
})
|
})
|
||||||
}, [props.isOpen])
|
}, [isOpen])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -97,11 +102,10 @@ const Collapse = props => {
|
|||||||
? { height: '0px', willChange: 'height' }
|
? { height: '0px', willChange: 'height' }
|
||||||
: { width: '0px', willChange: 'width' }
|
: { width: '0px', willChange: 'width' }
|
||||||
}
|
}
|
||||||
className={`${props.className || ''} overflow-hidden duration-300`}>
|
className={`${className || ''} overflow-hidden duration-300`}>
|
||||||
{props.children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Collapse.defaultProps = { isOpen: false }
|
|
||||||
|
|
||||||
export default Collapse
|
export default Collapse
|
||||||
|
|||||||
@@ -142,5 +142,3 @@ export const Draggable = ({ children, stick }) => {
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Draggable.defaultProps = { left: 0, top: 0 }
|
|
||||||
|
|||||||
Reference in New Issue
Block a user