You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import type { FC } from 'react'
  2. import { memo } from 'react'
  3. import { useNodes } from 'reactflow'
  4. import type { CommonNodeType } from '../types'
  5. import { Panel as NodePanel } from '../nodes'
  6. import { useStore } from '../store'
  7. import EnvPanel from './env-panel'
  8. import cn from '@/utils/classnames'
  9. export type PanelProps = {
  10. components?: {
  11. left?: React.ReactNode
  12. right?: React.ReactNode
  13. }
  14. }
  15. const Panel: FC<PanelProps> = ({
  16. components,
  17. }) => {
  18. const nodes = useNodes<CommonNodeType>()
  19. const selectedNode = nodes.find(node => node.data.selected)
  20. const showEnvPanel = useStore(s => s.showEnvPanel)
  21. const isRestoring = useStore(s => s.isRestoring)
  22. return (
  23. <div
  24. tabIndex={-1}
  25. className={cn('absolute bottom-2 right-0 top-14 z-10 flex outline-none')}
  26. key={`${isRestoring}`}
  27. >
  28. {
  29. components?.left
  30. }
  31. {
  32. !!selectedNode && (
  33. <NodePanel {...selectedNode!} />
  34. )
  35. }
  36. {
  37. components?.right
  38. }
  39. {
  40. showEnvPanel && (
  41. <EnvPanel />
  42. )
  43. }
  44. </div>
  45. )
  46. }
  47. export default memo(Panel)