Skip to content

Commit 4e5d245

Browse files
committed
feat: add panel component
1 parent 5efe36f commit 4e5d245

File tree

5 files changed

+50
-3
lines changed

5 files changed

+50
-3
lines changed

packages/elements/src/canvas/Canvas.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { FlowEmits, FlowProps, FlowSlots } from '@vue-flow/core'
33
import { Background } from '@vue-flow/background'
44
import { VueFlow } from '@vue-flow/core'
55
import { useForwardPropsEmits } from 'reka-ui'
6-
import { Controls } from '../controls'
76
import '@vue-flow/core/dist/style.css'
87
import '@vue-flow/core/dist/theme-default.css'
98
@@ -24,10 +23,15 @@ const forwarded = useForwardPropsEmits(props, emits)
2423
<template>
2524
<VueFlow data-slot="canvas" v-bind="forwarded">
2625
<Background />
27-
<Controls />
2826

2927
<template v-if="slots['connection-line']" #connection-line="connectionLineProps">
3028
<slot name="connection-line" v-bind="connectionLineProps" />
3129
</template>
30+
31+
<template v-if="slots['zoom-pane']" #zoom-pane>
32+
<slot name="zoom-pane" />
33+
</template>
34+
35+
<slot />
3236
</VueFlow>
3337
</template>

packages/elements/src/controls/Controls.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ const delegatedProps = reactiveOmit(props, 'class')
1616
<ControlsPrimitive
1717
data-slot="controls"
1818
v-bind="delegatedProps"
19-
:class="cn('gap-px overflow-hidden rounded-md border bg-card p-1 shadow-none! [&>button]:rounded-md [&>button]:border-none! [&>button]:bg-transparent! [&>button]:hover:bg-secondary!', props.class)"
19+
:class="cn(
20+
'gap-px overflow-hidden rounded-md border bg-card p-1 shadow-none!',
21+
'[&>button]:rounded-md [&>button]:border-none! [&>button]:bg-transparent! [&>button]:hover:bg-secondary!',
22+
props.class,
23+
)"
2024
/>
2125
</template>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<script setup lang="ts">
2+
import type { PanelPositionType } from '@vue-flow/core'
3+
import type { HTMLAttributes } from 'vue'
4+
import { cn } from '@repo/shadcn-vue/lib/utils'
5+
import { Panel as PanelPrimitive } from '@vue-flow/core'
6+
import { reactiveOmit } from '@vueuse/core'
7+
8+
interface PanelProps {
9+
class?: HTMLAttributes['class']
10+
position?: PanelPositionType
11+
}
12+
13+
const props = withDefaults(defineProps<PanelProps>(), {
14+
position: 'top-right',
15+
})
16+
17+
const delegatedProps = reactiveOmit(props, 'class')
18+
</script>
19+
20+
<template>
21+
<PanelPrimitive
22+
data-slot="panel"
23+
v-bind="delegatedProps"
24+
:class="cn('m-4 overflow-hidden rounded-md border bg-card p-1', props.class)"
25+
>
26+
<slot />
27+
</PanelPrimitive>
28+
</template>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as Panel } from './Panel.vue'

packages/examples/src/workflow.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
import type { Edge, Node } from '@vue-flow/core'
33
import { Canvas } from '@repo/elements/canvas'
44
import { Connection } from '@repo/elements/connection'
5+
import { Controls } from '@repo/elements/controls'
6+
import { Panel } from '@repo/elements/panel'
7+
import { Button } from '@repo/shadcn-vue/components/ui/button'
58
import { nanoid } from 'nanoid'
69
import { ref } from 'vue'
710
@@ -38,6 +41,13 @@ const edges = ref<Edge[]>([
3841
<template #connection-line="connectionLineProps">
3942
<Connection v-bind="connectionLineProps" />
4043
</template>
44+
45+
<Controls />
46+
<Panel position="top-right">
47+
<Button size="sm" variant="secondary">
48+
Export
49+
</Button>
50+
</Panel>
4151
</Canvas>
4252
</div>
4353
</template>

0 commit comments

Comments
 (0)