import React, { useImperativeHandle, useState } from 'react' import SideBar from '@/components/SideBar' /** * 侧边栏抽屉面板,可以从侧面拉出 * @returns {JSX.Element} * @constructor */ const SideBarDrawer = ({ post, currentTag, cRef, tags, posts, categories, currentCategory }) => { // 暴露给父组件 通过cRef.current.handleMenuClick 调用 useImperativeHandle(cRef, () => { return { handleSwitchSideDrawerVisible: () => switchSideDrawerVisible() } }) const [isShow, changeHiddenStatus] = useState(false) // 点击按钮更改侧边抽屉状态 const switchSideDrawerVisible = () => { const showStatus = !isShow changeHiddenStatus(showStatus) if (window) { const sideBarDrawer = window.document.getElementById('sidebar-drawer') const sideBarDrawerBackground = window.document.getElementById('sidebar-drawer-background') if (showStatus) { sideBarDrawer.classList.replace('-ml-80', 'ml-0') sideBarDrawerBackground.classList.replace('hidden', 'block') } else { sideBarDrawer.classList.replace('ml-0', '-ml-80') sideBarDrawerBackground.classList.replace('block', 'hidden') } } } return <> {/* 背景蒙版 */}