|
1 | | -import { proxy, useSnapshot } from 'valtio' |
2 | | -import { LucideExpand, LucideMagnet, LucideShrink } from 'lucide-react' |
| 1 | +import { useSnapshot } from 'valtio' |
| 2 | +import { |
| 3 | + LucideExpand, |
| 4 | + LucideMagnet, |
| 5 | + LucideMoveHorizontal, |
| 6 | + LucideMoveVertical, |
| 7 | + LucideShrink, |
| 8 | + LucideSparkles, |
| 9 | + LucideWorkflow |
| 10 | +} from 'lucide-react' |
3 | 11 | import { Button } from '@nextui-org/button' |
4 | | -import { Tooltip } from '@nextui-org/react' |
| 12 | +import { Tab, Tabs, Tooltip } from '@nextui-org/react' |
5 | 13 | import { useTheme } from 'next-themes' |
| 14 | +import { |
| 15 | + compactMode, |
| 16 | + connectionsLineType, |
| 17 | + connectionsOrientation, |
| 18 | + enableConnectionAnimation, |
| 19 | + enableConnections, |
| 20 | + snapToGridEnabled |
| 21 | +} from '@/app/hs/stacks/components/blocks/Blocks.state' |
| 22 | +import { ConnectionLineType } from 'reactflow' |
6 | 23 |
|
7 | | -export const compactMode = proxy({ value: false }) |
8 | | -export const snapToGridEnabled = proxy({ value: false }) |
9 | | -export default function BlocksToolbar() { |
| 24 | +interface BlocksToolbarProps { |
| 25 | + publishConnectionsConfigChange?: () => void |
| 26 | + onLineTypeChange?: (lineType: ConnectionLineType) => void |
| 27 | + onAnimatedChange?: (animated: boolean) => void |
| 28 | + viewOnly?: boolean |
| 29 | +} |
| 30 | +export default function BlocksToolbar({ |
| 31 | + publishConnectionsConfigChange, |
| 32 | + onLineTypeChange, |
| 33 | + onAnimatedChange, |
| 34 | + viewOnly |
| 35 | +}: BlocksToolbarProps) { |
10 | 36 | const { theme } = useTheme() |
11 | 37 | const isCompactMode = useSnapshot(compactMode) |
12 | 38 | const snapToGrid = useSnapshot(snapToGridEnabled) |
| 39 | + const withConnections = useSnapshot(enableConnections) |
| 40 | + const connOrientation = useSnapshot(connectionsOrientation) |
| 41 | + const lineType = useSnapshot(connectionsLineType) |
| 42 | + const connectionAnimation = useSnapshot(enableConnectionAnimation) |
13 | 43 |
|
14 | 44 | const activeColor = theme === 'dark' ? 'primary' : 'secondary' |
15 | 45 | return ( |
16 | | - <div className="absolute right-4 top-4 z-10 bg-white dark:bg-black flex items-center gap-2 p-1 border-1 border-default-100 rounded-large"> |
| 46 | + <div className="absolute right-4 top-4 z-10 bg-white dark:bg-black flex items-center flex-row-reverse gap-2 p-1 border-1 border-default-100 rounded-large"> |
17 | 47 | <Tooltip size="sm" content={'Compact mode'}> |
18 | 48 | <Button |
19 | 49 | onClick={() => { |
@@ -46,6 +76,85 @@ export default function BlocksToolbar() { |
46 | 76 | <LucideMagnet size={18} strokeWidth={1.5} /> |
47 | 77 | </Button> |
48 | 78 | </Tooltip> |
| 79 | + {!viewOnly && ( |
| 80 | + <> |
| 81 | + <Tooltip size="sm" content={'Enable connections'}> |
| 82 | + <Button |
| 83 | + onClick={() => { |
| 84 | + enableConnections.value = !withConnections.value |
| 85 | + publishConnectionsConfigChange?.() |
| 86 | + }} |
| 87 | + size="sm" |
| 88 | + radius="md" |
| 89 | + color={withConnections.value ? activeColor : 'default'} |
| 90 | + variant={withConnections.value ? 'flat' : 'light'} |
| 91 | + isIconOnly |
| 92 | + > |
| 93 | + <LucideWorkflow size={18} strokeWidth={1.5} /> |
| 94 | + </Button> |
| 95 | + </Tooltip> |
| 96 | + {withConnections.value && ( |
| 97 | + <div className="flex items-center flex-row-reverse gap-1"> |
| 98 | + <div className="bg-white dark:bg-black flex items-center gap-2"> |
| 99 | + <Tabs |
| 100 | + size="sm" |
| 101 | + variant="light" |
| 102 | + radius="lg" |
| 103 | + selectedKey={lineType.value} |
| 104 | + onSelectionChange={(key) => { |
| 105 | + const lineType = key as ConnectionLineType |
| 106 | + connectionsLineType.value = lineType |
| 107 | + onLineTypeChange?.(lineType) |
| 108 | + }} |
| 109 | + > |
| 110 | + <Tab key={ConnectionLineType.Step} title="Step" /> |
| 111 | + <Tab key={ConnectionLineType.SmoothStep} title="Smooth" /> |
| 112 | + <Tab key={ConnectionLineType.Straight} title="Straight" /> |
| 113 | + <Tab key={ConnectionLineType.Bezier} title="Simple" /> |
| 114 | + </Tabs> |
| 115 | + <Tooltip size="sm" content={'Animated'}> |
| 116 | + <Button |
| 117 | + onClick={() => { |
| 118 | + const animated = !connectionAnimation.value |
| 119 | + enableConnectionAnimation.value = animated |
| 120 | + onAnimatedChange?.(animated) |
| 121 | + }} |
| 122 | + size="sm" |
| 123 | + radius="md" |
| 124 | + color={connectionAnimation.value ? activeColor : 'default'} |
| 125 | + variant={connectionAnimation.value ? 'flat' : 'light'} |
| 126 | + isIconOnly |
| 127 | + > |
| 128 | + <LucideSparkles size={18} strokeWidth={1.5} /> |
| 129 | + </Button> |
| 130 | + </Tooltip> |
| 131 | + <Tooltip size="sm" content={'Orientation'}> |
| 132 | + <Button |
| 133 | + onClick={() => { |
| 134 | + connectionsOrientation.value = |
| 135 | + connOrientation.value === 'vertical' |
| 136 | + ? 'horizontal' |
| 137 | + : 'vertical' |
| 138 | + publishConnectionsConfigChange?.() |
| 139 | + }} |
| 140 | + size="sm" |
| 141 | + radius="md" |
| 142 | + color={activeColor} |
| 143 | + variant="flat" |
| 144 | + isIconOnly |
| 145 | + > |
| 146 | + {connOrientation.value === 'vertical' ? ( |
| 147 | + <LucideMoveVertical size={18} /> |
| 148 | + ) : ( |
| 149 | + <LucideMoveHorizontal size={18} /> |
| 150 | + )} |
| 151 | + </Button> |
| 152 | + </Tooltip> |
| 153 | + </div> |
| 154 | + </div> |
| 155 | + )} |
| 156 | + </> |
| 157 | + )} |
49 | 158 | </div> |
50 | 159 | ) |
51 | 160 | } |
0 commit comments