Skip to content

Commit d71de0a

Browse files
committed
chore(docs): update example styles (#1469)
* chore(docs): update basic example styles * chore(docs): update confirm delete example styles * chore(docs): update dnd example styles * chore(docs): update hidden example * chore(docs): update update node example * chore(docs): update node toolbar example styles * chore(docs): update transition example styles * chore(docs): cleanup basic example els * chore(docs): cleanup examples
1 parent 5dc8711 commit d71de0a

File tree

34 files changed

+527
-243
lines changed

34 files changed

+527
-243
lines changed

docs/examples/basic/App.vue

+13-10
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import { initialEdges, initialNodes } from './initial-elements.js'
88
import Icon from './Icon.vue'
99
1010
/**
11-
* useVueFlow provides all event handlers and store properties
12-
* You can pass the composable an object that has the same properties as the VueFlow component props
11+
* `useVueFlow` provides:
12+
* 1. a set of methods to interact with the VueFlow instance (like `fitView`, `setViewport`, `addEdges`, etc)
13+
* 2. a set of event-hooks to listen to VueFlow events (like `onInit`, `onNodeDragStop`, `onConnect`, etc)
14+
* 3. the internal state of the VueFlow instance (like `nodes`, `edges`, `viewport`, etc)
1315
*/
14-
const { onPaneReady, onNodeDragStop, onConnect, addEdges, setViewport, toObject } = useVueFlow()
16+
const { onInit, onNodeDragStop, onConnect, addEdges, setViewport, toObject } = useVueFlow()
1517
1618
const nodes = ref(initialNodes)
1719
@@ -24,10 +26,11 @@ const dark = ref(false)
2426
* This is a Vue Flow event-hook which can be listened to from anywhere you call the composable, instead of only on the main component
2527
* Any event that is available as `@event-name` on the VueFlow component is also available as `onEventName` on the composable and vice versa
2628
*
27-
* onPaneReady is called when viewpane & nodes have visible dimensions
29+
* onInit is called when the VueFlow viewport is initialized
2830
*/
29-
onPaneReady(({ fitView }) => {
30-
fitView()
31+
onInit((vueFlowInstance) => {
32+
// instance is the same as the return of `useVueFlow`
33+
vueFlowInstance.fitView()
3134
})
3235
3336
/**
@@ -39,8 +42,8 @@ onPaneReady(({ fitView }) => {
3942
* 3. the node that initiated the drag
4043
* 4. any intersections with other nodes
4144
*/
42-
onNodeDragStop(({ event, nodes, node, intersections }) => {
43-
console.log('Node Drag Stop', { event, nodes, node, intersections })
45+
onNodeDragStop(({ event, nodes, node }) => {
46+
console.log('Node Drag Stop', { event, nodes, node })
4447
})
4548
4649
/**
@@ -94,7 +97,7 @@ function toggleDarkMode() {
9497
:nodes="nodes"
9598
:edges="edges"
9699
:class="{ dark }"
97-
class="basicflow"
100+
class="basic-flow"
98101
:default-viewport="{ zoom: 1.5 }"
99102
:min-zoom="0.2"
100103
:max-zoom="4"
@@ -103,7 +106,7 @@ function toggleDarkMode() {
103106

104107
<MiniMap />
105108

106-
<Controls position="top-right">
109+
<Controls position="top-left">
107110
<ControlButton title="Reset Transform" @click="resetTransform">
108111
<Icon name="reset" />
109112
</ControlButton>
+54-9
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,69 @@
11
import { MarkerType } from '@vue-flow/core'
22

33
export const initialNodes = [
4-
{ id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 0 }, class: 'light' },
5-
{ id: '2', type: 'output', label: 'Node 2', position: { x: 100, y: 100 }, class: 'light' },
6-
{ id: '3', label: 'Node 3', position: { x: 400, y: 100 }, class: 'light' },
7-
{ id: '4', label: 'Node 4', position: { x: 150, y: 200 }, class: 'light' },
8-
{ id: '5', type: 'output', label: 'Node 5', position: { x: 300, y: 300 }, class: 'light' },
4+
{
5+
id: '1',
6+
type: 'input',
7+
data: { label: 'Node 1' },
8+
position: { x: 250, y: 0 },
9+
class: 'light',
10+
},
11+
{
12+
id: '2',
13+
type: 'output',
14+
data: { label: 'Node 2' },
15+
position: { x: 100, y: 100 },
16+
class: 'light',
17+
},
18+
{
19+
id: '3',
20+
data: { label: 'Node 3' },
21+
position: { x: 400, y: 100 },
22+
class: 'light',
23+
},
24+
{
25+
id: '4',
26+
data: { label: 'Node 4' },
27+
position: { x: 150, y: 200 },
28+
class: 'light',
29+
},
30+
{
31+
id: '5',
32+
type: 'output',
33+
data: { label: 'Node 5' },
34+
position: { x: 300, y: 300 },
35+
class: 'light',
36+
},
937
]
1038

1139
export const initialEdges = [
12-
{ id: 'e1-2', source: '1', target: '2', animated: true },
13-
{ id: 'e1-3', label: 'edge with arrowhead', source: '1', target: '3', markerEnd: MarkerType.ArrowClosed },
40+
{
41+
id: 'e1-2',
42+
source: '1',
43+
target: '2',
44+
animated: true,
45+
},
46+
{
47+
id: 'e1-3',
48+
source: '1',
49+
target: '3',
50+
label: 'edge with arrowhead',
51+
markerEnd: MarkerType.ArrowClosed,
52+
},
1453
{
1554
id: 'e4-5',
1655
type: 'step',
17-
label: 'step-edge',
1856
source: '4',
1957
target: '5',
58+
label: 'Node 2',
2059
style: { stroke: 'orange' },
2160
labelBgStyle: { fill: 'orange' },
2261
},
23-
{ id: 'e3-4', type: 'smoothstep', label: 'smoothstep-edge', source: '3', target: '4' },
62+
{
63+
id: 'e3-4',
64+
type: 'smoothstep',
65+
source: '3',
66+
target: '4',
67+
label: 'smoothstep-edge',
68+
},
2469
]

docs/examples/basic/style.css

+17-13
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,52 @@
1-
.basicflow.dark {
2-
background: #000000;
1+
.basic-flow.dark {
2+
background: #2d3748;
33
color: #FFFFFB;
44
}
55

6-
.basicflow.dark .vue-flow__node {
7-
background: hsl(0, 0%, 10%);
6+
.basic-flow.dark .vue-flow__node {
7+
background: #4a5568;
88
color: #FFFFFB;
99
}
1010

11-
.basicflow.dark .vue-flow__node.selected {
11+
.basic-flow.dark .vue-flow__node.selected {
1212
background: hsl(0, 0%, 20%);
13-
border: 1px solid hotpink;
13+
box-shadow: 0 0 0 2px #2563eb;
1414
}
1515

16-
.basicflow .vue-flow__controls {
16+
.basic-flow .vue-flow__controls {
1717
display: flex;
1818
flex-wrap: wrap;
1919
justify-content: center;
2020
}
2121

22-
.basicflow.dark .vue-flow__controls {
22+
.basic-flow.dark .vue-flow__controls {
2323
border: 1px solid #FFFFFB;
2424
}
2525

26-
.basicflow .vue-flow__controls .vue-flow__controls-button {
26+
.basic-flow .vue-flow__controls .vue-flow__controls-button {
2727
border: none;
2828
border-right: 1px solid #eee;
2929
}
3030

31+
.basic-flow .vue-flow__controls .vue-flow__controls-button svg {
32+
height: 100%;
33+
width: 100%;
34+
}
3135

32-
.basicflow.dark .vue-flow__controls .vue-flow__controls-button {
36+
.basic-flow.dark .vue-flow__controls .vue-flow__controls-button {
3337
background: hsl(0, 0%, 20%);
3438
fill: #FFFFFB;
3539
border: none;
3640
}
3741

38-
.basicflow.dark .vue-flow__controls .vue-flow__controls-button:hover {
42+
.basic-flow.dark .vue-flow__controls .vue-flow__controls-button:hover {
3943
background: hsl(0, 0%, 30%);
4044
}
4145

42-
.basicflow.dark .vue-flow__edge-textbg {
46+
.basic-flow.dark .vue-flow__edge-textbg {
4347
fill: #292524;
4448
}
4549

46-
.basicflow.dark .vue-flow__edge-text {
50+
.basic-flow.dark .vue-flow__edge-text {
4751
fill: #FFFFFB;
4852
}

docs/examples/confirm-delete/App.vue

+22-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup>
2-
import { ref } from 'vue'
2+
import { h, ref } from 'vue'
33
import { VueFlow, useVueFlow } from '@vue-flow/core'
44
import { Background } from '@vue-flow/background'
55
import { useDialog } from './useDialog'
@@ -10,16 +10,26 @@ const { onConnect, addEdges, onNodesChange, onEdgesChange, applyNodeChanges, app
1010
const dialog = useDialog()
1111
1212
const nodes = ref([
13-
{ id: '1', type: 'input', label: 'Node 1', position: { x: 250, y: 5 }, class: 'light' },
14-
{ id: '2', label: 'Node 2', position: { x: 100, y: 100 }, class: 'light' },
15-
{ id: '3', label: 'Node 3', position: { x: 400, y: 100 }, class: 'light' },
16-
{ id: '4', label: 'Node 4', position: { x: 400, y: 200 }, class: 'light' },
13+
{ id: '1', type: 'input', data: { label: 'Click me and' }, position: { x: 0, y: 0 } },
14+
{ id: '2', data: { label: `press 'Backspace' to delete me` }, position: { x: 0, y: 100 } },
1715
])
1816
19-
const edges = ref([
20-
{ id: 'e1-2', source: '1', target: '2', animated: true },
21-
{ id: 'e1-3', source: '1', target: '3' },
22-
])
17+
const edges = ref([{ id: 'e1-2', source: '1', target: '2' }])
18+
19+
function dialogMsg(id) {
20+
return h(
21+
'span',
22+
{
23+
style: {
24+
display: 'flex',
25+
flexDirection: 'column',
26+
alignItems: 'center',
27+
gap: '8px',
28+
},
29+
},
30+
[`Are you sure?`, h('br'), h('span', `[ELEMENT_ID: ${id}]`)],
31+
)
32+
}
2333
2434
onConnect(addEdges)
2535
@@ -28,7 +38,7 @@ onNodesChange(async (changes) => {
2838
2939
for (const change of changes) {
3040
if (change.type === 'remove') {
31-
const isConfirmed = await dialog.confirm(`Do you really want to delete this node: ${change.id}?`)
41+
const isConfirmed = await dialog.confirm(dialogMsg(change.id))
3242
3343
if (isConfirmed) {
3444
nextChanges.push(change)
@@ -46,7 +56,7 @@ onEdgesChange(async (changes) => {
4656
4757
for (const change of changes) {
4858
if (change.type === 'remove') {
49-
const isConfirmed = await dialog.confirm(`Do you really want to delete this edge: ${change.id}?`)
59+
const isConfirmed = await dialog.confirm(dialogMsg(change.id))
5060
5161
if (isConfirmed) {
5262
nextChanges.push(change)
@@ -61,7 +71,7 @@ onEdgesChange(async (changes) => {
6171
</script>
6272

6373
<template>
64-
<VueFlow :nodes="nodes" :edges="edges" :apply-default="false" fit-view-on-init class="vue-flow-basic-example">
74+
<VueFlow :nodes="nodes" :edges="edges" :apply-default="false" fit-view-on-init class="confirm-flow">
6575
<Background />
6676

6777
<Dialog />

docs/examples/confirm-delete/Dialog.vue

+30-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,17 @@ function cancel() {
1717
<template>
1818
<div v-if="isVisible" class="dialog-overlay">
1919
<div class="dialog">
20-
<p>{{ message }}</p>
20+
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24">
21+
<path
22+
fill="#e53e3e"
23+
d="M7 21q-.825 0-1.412-.587T5 19V6H4V4h5V3h6v1h5v2h-1v13q0 .825-.587 1.413T17 21zm2-4h2V8H9zm4 0h2V8h-2z"
24+
/>
25+
</svg>
2126

22-
<div class="dialog-actions">
27+
<p v-if="typeof message === 'string'">{{ message }}</p>
28+
<component :is="message" v-else />
29+
30+
<div class="actions">
2331
<button @click="confirm">Confirm</button>
2432
<button @click="cancel">Cancel</button>
2533
</div>
@@ -42,16 +50,34 @@ function cancel() {
4250
}
4351
4452
.dialog {
45-
background: white;
53+
background: #2d3748;
4654
padding: 20px;
4755
border-radius: 5px;
4856
text-align: center;
57+
color: white;
4958
}
5059
51-
.dialog-actions {
60+
.dialog .actions {
5261
margin-top: 20px;
5362
display: flex;
5463
justify-content: center;
5564
gap: 8px;
5665
}
66+
67+
.dialog .actions button {
68+
background: #4a5568;
69+
color: white;
70+
border: none;
71+
padding: 8px 16px;
72+
border-radius: 5px;
73+
cursor: pointer;
74+
}
75+
76+
.dialog .actions button:first-of-type:hover {
77+
background: #2563eb;
78+
}
79+
80+
.dialog .actions button:last-of-type:hover {
81+
background: #e53e3e;
82+
}
5783
</style>

docs/examples/confirm-delete/useDialog.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { ref } from 'vue'
22

3+
/**
4+
* In a real world example you would want to avoid creating refs in a global scope like this
5+
*/
36
const isVisible = ref(false)
47
const message = ref('')
58
let resolveCallback

docs/examples/connection-radius/App.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ import ConnectionLine from './SnappableConnectionLine.vue'
66
const nodes = ref([
77
{
88
id: '1',
9-
label: 'Node 1',
9+
data: { label: 'Node 1' },
1010
position: { x: 0, y: 0 },
1111
},
1212
{
1313
id: '2',
14-
label: 'Node 2',
14+
data: { label: 'Node 2' },
1515
position: { x: 100, y: 100 },
1616
},
1717
{
1818
id: '3',
19-
label: 'Node 3',
19+
data: { label: 'Node 3' },
2020
position: { x: 200, y: 0 },
2121
},
2222
])

docs/examples/connectionline/App.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const nodes = ref([
77
{
88
id: '1',
99
type: 'input',
10-
label: 'Node 1',
10+
data: { label: 'Node 1' },
1111
position: { x: 250, y: 5 },
1212
},
1313
])

0 commit comments

Comments
 (0)