control.tsx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { memo } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import cn from 'classnames'
  4. import {
  5. useNodesReadOnly,
  6. useWorkflow,
  7. } from '../hooks'
  8. import { useStore } from '../store'
  9. import AddBlock from './add-block'
  10. import TipPopup from './tip-popup'
  11. import {
  12. Cursor02C,
  13. Hand02,
  14. } from '@/app/components/base/icons/src/vender/line/editor'
  15. import {
  16. Cursor02C as Cursor02CSolid,
  17. Hand02 as Hand02Solid,
  18. } from '@/app/components/base/icons/src/vender/solid/editor'
  19. import { OrganizeGrid } from '@/app/components/base/icons/src/vender/line/layout'
  20. const Control = () => {
  21. const { t } = useTranslation()
  22. const controlMode = useStore(s => s.controlMode)
  23. const setControlMode = useStore(s => s.setControlMode)
  24. const { handleLayout } = useWorkflow()
  25. const {
  26. nodesReadOnly,
  27. getNodesReadOnly,
  28. } = useNodesReadOnly()
  29. const goLayout = () => {
  30. if (getNodesReadOnly())
  31. return
  32. handleLayout()
  33. }
  34. return (
  35. <div className='flex items-center p-0.5 rounded-lg border-[0.5px] border-gray-100 bg-white shadow-lg text-gray-500'>
  36. <AddBlock />
  37. <div className='mx-[3px] w-[1px] h-3.5 bg-gray-200'></div>
  38. <TipPopup title={t('workflow.common.pointerMode')}>
  39. <div
  40. className={cn(
  41. 'flex items-center justify-center mr-[1px] w-8 h-8 rounded-lg cursor-pointer',
  42. controlMode === 'pointer' ? 'bg-primary-50 text-primary-600' : 'hover:bg-black/5 hover:text-gray-700',
  43. `${nodesReadOnly && '!cursor-not-allowed opacity-50'}`,
  44. )}
  45. onClick={() => setControlMode('pointer')}
  46. >
  47. {
  48. controlMode === 'pointer' ? <Cursor02CSolid className='w-4 h-4' /> : <Cursor02C className='w-4 h-4' />
  49. }
  50. </div>
  51. </TipPopup>
  52. <TipPopup title={t('workflow.common.handMode')}>
  53. <div
  54. className={cn(
  55. 'flex items-center justify-center w-8 h-8 rounded-lg cursor-pointer',
  56. controlMode === 'hand' ? 'bg-primary-50 text-primary-600' : 'hover:bg-black/5 hover:text-gray-700',
  57. `${nodesReadOnly && '!cursor-not-allowed opacity-50'}`,
  58. )}
  59. onClick={() => setControlMode('hand')}
  60. >
  61. {
  62. controlMode === 'hand' ? <Hand02Solid className='w-4 h-4' /> : <Hand02 className='w-4 h-4' />
  63. }
  64. </div>
  65. </TipPopup>
  66. <div className='mx-[3px] w-[1px] h-3.5 bg-gray-200'></div>
  67. <TipPopup title={t('workflow.panel.organizeBlocks')}>
  68. <div
  69. className={cn(
  70. 'flex items-center justify-center w-8 h-8 rounded-lg hover:bg-black/5 hover:text-gray-700 cursor-pointer',
  71. `${nodesReadOnly && '!cursor-not-allowed opacity-50'}`,
  72. )}
  73. onClick={goLayout}
  74. >
  75. <OrganizeGrid className='w-4 h-4' />
  76. </div>
  77. </TipPopup>
  78. </div>
  79. )
  80. }
  81. export default memo(Control)