import React, { createContext, useContext, useState } from "react" import { AnimatePresence, motion } from "framer-motion" import { PlaygroundIodRelevant } from "@/components/Common/Playground/IodRelevant.tsx" import { PlaygroundData } from "@/components/Common/Playground/Data.tsx" import { PlaygroundScene } from "@/components/Common/Playground/Scene.tsx" import { PlaygroundTeam } from "@/components/Common/Playground/Team.tsx" import { Card } from "antd" import { CloseOutlined } from "@ant-design/icons" // 定义 Context 类型 interface IodPlaygroundContextType { showPlayground: boolean setShowPlayground: React.Dispatch> detailHeader: React.ReactNode setDetailHeader: React.Dispatch> detailMain: React.ReactNode setDetailMain: React.Dispatch> } // 创建 Context const PlaygroundContext = createContext( undefined ) // 创建自定义 hook 以便子组件使用 export const useIodPlaygroundContext = () => { const context = useContext(PlaygroundContext) if (context === undefined) { throw new Error( "usePlaygroundContext must be used within a PlaygroundProvider" ) } return context } export const PlaygroundIod = () => { const [showPlayground, setShowPlayground] = useState(true) const [detailHeader, setDetailHeader] = useState(<>) const [detailMain, setDetailMain] = useState(<>) return (
) } // 子组件使用修改card的默认样式 const classNames = "h-full [&_.ant-card-body]:h-full [&_.ant-card-body]:!p-[20px] overflow-y-hidden !bg-[rgba(240,245,255,0.3)] backdrop-blur-sm border border-white/30 shadow-xl rounded-2xl" // 将原来的返回内容移到这个组件中 const PlaygroundContent = () => { const { showPlayground, detailMain, detailHeader, setShowPlayground } = useIodPlaygroundContext() return ( {showPlayground ? (
) : (
{detailHeader}
setShowPlayground(true)} />
{detailMain}
)}
) }