chore(docs): update custom node example
This commit is contained in:
@@ -1,35 +1,26 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { MiniMap } from '@vue-flow/minimap'
|
|
||||||
import { Position, VueFlow, useVueFlow } from '@vue-flow/core'
|
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
|
import { MiniMap } from '@vue-flow/minimap'
|
||||||
|
import { Position, VueFlow, useNodesData, useVueFlow } from '@vue-flow/core'
|
||||||
import ColorSelectorNode from './ColorSelectorNode.vue'
|
import ColorSelectorNode from './ColorSelectorNode.vue'
|
||||||
|
import OutputNode from './OutputNode.vue'
|
||||||
import { presets } from './presets.js'
|
import { presets } from './presets.js'
|
||||||
|
|
||||||
const { findNode } = useVueFlow()
|
useVueFlow()
|
||||||
|
|
||||||
const gradient = ref(false)
|
const nodeData = useNodesData('1')
|
||||||
|
|
||||||
const bgColor = ref(presets.ayame)
|
|
||||||
|
|
||||||
const bgName = ref('AYAME')
|
|
||||||
|
|
||||||
const nodes = ref([
|
const nodes = ref([
|
||||||
{
|
{
|
||||||
id: '1',
|
id: '1',
|
||||||
type: 'color-selector',
|
type: 'color-selector',
|
||||||
data: { color: bgColor.value },
|
data: { color: presets.ayame },
|
||||||
position: { x: 0, y: 50 },
|
position: { x: 0, y: 50 },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '2',
|
id: '2',
|
||||||
type: 'output',
|
type: 'output',
|
||||||
position: { x: 350, y: 25 },
|
position: { x: 350, y: 114 },
|
||||||
targetPosition: Position.Left,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: '3',
|
|
||||||
type: 'output',
|
|
||||||
position: { x: 350, y: 200 },
|
|
||||||
targetPosition: Position.Left,
|
targetPosition: Position.Left,
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
@@ -42,25 +33,12 @@ const edges = ref([
|
|||||||
target: '2',
|
target: '2',
|
||||||
animated: true,
|
animated: true,
|
||||||
style: () => ({
|
style: () => ({
|
||||||
stroke: bgColor.value,
|
stroke: nodeData.value?.color,
|
||||||
filter: 'invert(100%)',
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'e1b-3',
|
|
||||||
source: '1',
|
|
||||||
sourceHandle: 'b',
|
|
||||||
target: '3',
|
|
||||||
animated: true,
|
|
||||||
style: () => ({
|
|
||||||
stroke: bgColor.value,
|
|
||||||
filter: 'invert(100%)',
|
filter: 'invert(100%)',
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
const connectionLineStyle = { stroke: '#fff' }
|
|
||||||
|
|
||||||
// minimap stroke color functions
|
// minimap stroke color functions
|
||||||
function nodeStroke(n) {
|
function nodeStroke(n) {
|
||||||
switch (n.type) {
|
switch (n.type) {
|
||||||
@@ -77,27 +55,11 @@ function nodeStroke(n) {
|
|||||||
|
|
||||||
function nodeColor(n) {
|
function nodeColor(n) {
|
||||||
if (n.type === 'color-selector') {
|
if (n.type === 'color-selector') {
|
||||||
return bgColor.value
|
return nodeData.value?.color
|
||||||
}
|
}
|
||||||
|
|
||||||
return '#fff'
|
return '#fff'
|
||||||
}
|
}
|
||||||
|
|
||||||
function onChange(color) {
|
|
||||||
gradient.value = false
|
|
||||||
bgColor.value = color.value
|
|
||||||
bgName.value = color.name
|
|
||||||
|
|
||||||
findNode('3').hidden = false
|
|
||||||
}
|
|
||||||
|
|
||||||
function onGradient() {
|
|
||||||
gradient.value = true
|
|
||||||
bgColor.value = null
|
|
||||||
bgName.value = 'gradient'
|
|
||||||
|
|
||||||
findNode('3').hidden = true
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -105,9 +67,8 @@ function onGradient() {
|
|||||||
:nodes="nodes"
|
:nodes="nodes"
|
||||||
:edges="edges"
|
:edges="edges"
|
||||||
class="custom-node-flow"
|
class="custom-node-flow"
|
||||||
:class="[gradient ? 'animated-bg-gradient' : '']"
|
:class="[nodeData?.isGradient ? 'animated-bg-gradient' : '']"
|
||||||
:style="{ backgroundColor: bgColor }"
|
:style="{ backgroundColor: nodeData?.color }"
|
||||||
:connection-line-style="connectionLineStyle"
|
|
||||||
:default-viewport="{ zoom: 1.5 }"
|
:default-viewport="{ zoom: 1.5 }"
|
||||||
fit-view-on-init
|
fit-view-on-init
|
||||||
>
|
>
|
||||||
@@ -115,6 +76,10 @@ function onGradient() {
|
|||||||
<ColorSelectorNode :data="data" />
|
<ColorSelectorNode :data="data" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template #node-output="{ data }">
|
||||||
|
<OutputNode :data="data" />
|
||||||
|
</template>
|
||||||
|
|
||||||
<MiniMap :node-stroke-color="nodeStroke" :node-color="nodeColor" />
|
<MiniMap :node-stroke-color="nodeStroke" :node-color="nodeColor" />
|
||||||
</VueFlow>
|
</VueFlow>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,60 +1,42 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { Handle, Position, useVueFlow } from '@vue-flow/core'
|
import { Handle, Position, useNodeId, useVueFlow } from '@vue-flow/core'
|
||||||
import { colors } from './presets.js'
|
import { colors } from './presets.js'
|
||||||
|
|
||||||
const props = defineProps({
|
defineProps({
|
||||||
id: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
data: {
|
data: {
|
||||||
type: Object,
|
type: Object,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const nodeId = useNodeId()
|
||||||
|
|
||||||
const { updateNodeData } = useVueFlow()
|
const { updateNodeData } = useVueFlow()
|
||||||
|
|
||||||
function onSelect(color) {
|
function onSelect(color) {
|
||||||
updateNodeData(props.id, { color: color.value }, { replace: true })
|
updateNodeData(nodeId, { color }, { replace: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
function onGradient() {
|
function onGradient() {
|
||||||
updateNodeData(props.id, { isGradient: true }, { replace: true })
|
updateNodeData(nodeId, { isGradient: true }, { replace: true })
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>Select a color</div>
|
<div>Select a color</div>
|
||||||
|
|
||||||
<div
|
<div class="color-selector nodrag nopan">
|
||||||
class="color-selector"
|
<button
|
||||||
style="display: flex; flex-direction: row; flex-wrap: wrap; justify-content: center; max-width: 90%; margin: auto; gap: 4px"
|
v-for="{ name: colorName, value: color } of colors"
|
||||||
>
|
:key="colorName"
|
||||||
<template v-for="color of colors" :key="color.name">
|
:title="colorName"
|
||||||
<button :title="color.name" :style="{ backgroundColor: color.value }" type="button" @click="onSelect(color)" />
|
:style="{ backgroundColor: color }"
|
||||||
</template>
|
type="button"
|
||||||
|
@click="onSelect(color)"
|
||||||
|
/>
|
||||||
|
|
||||||
<button class="animated-bg-gradient" title="gradient" type="button" @click="onGradient" />
|
<button class="animated-bg-gradient" title="gradient" type="button" @click="onGradient" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- When using multiple handles of the same type, each handle should have a unique id -->
|
<Handle id="a" type="source" :position="Position.Right" />
|
||||||
<Handle
|
|
||||||
id="a"
|
|
||||||
type="source"
|
|
||||||
:position="Position.Right"
|
|
||||||
:style="{ backgroundColor: data.color, filter: 'invert(100%)', top: '10px' }"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Handle
|
|
||||||
id="b"
|
|
||||||
type="source"
|
|
||||||
:position="Position.Right"
|
|
||||||
:style="{
|
|
||||||
backgroundColor: data.color,
|
|
||||||
filter: 'invert(100%)',
|
|
||||||
bottom: '10px',
|
|
||||||
top: 'auto',
|
|
||||||
}"
|
|
||||||
/>
|
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,17 +1,21 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { useHandleConnections, useNodesData } from '@vue-flow/core'
|
import { Handle, Position, useHandleConnections, useNodesData } from '@vue-flow/core'
|
||||||
|
|
||||||
const props = defineProps({
|
defineProps({
|
||||||
id: {
|
data: {
|
||||||
type: String,
|
type: Object,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const connections = useHandleConnections({
|
const connections = useHandleConnections({
|
||||||
nodeId: props.id,
|
|
||||||
type: 'target',
|
type: 'target',
|
||||||
})
|
})
|
||||||
|
|
||||||
const data = useNodesData()
|
const data = useNodesData(() => connections.value[0]?.source)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Handle type="target" :position="Position.Left" :style="{ backgroundColor: data?.color, filter: 'invert(100%)' }" />
|
||||||
|
{{ data?.isGradient ? 'GRADIENT' : data?.color }}
|
||||||
|
</template>
|
||||||
|
|||||||
@@ -22,19 +22,19 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.custom-node-flow .vue-flow__node-color-selector .color-selector button {
|
.custom-node-flow .vue-flow__node-color-selector .color-selector button {
|
||||||
border: none;
|
border: 1px solid #777;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
width: 25px;
|
width: 25px;
|
||||||
height: 25px;
|
height: 25px;
|
||||||
border-radius: 25px;
|
border-radius: 25px;
|
||||||
-webkit-box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.3);
|
|
||||||
box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.3);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.custom-node-flow .vue-flow__node-color-selector .color-selector button:hover {
|
.custom-node-flow .vue-flow__node-color-selector .color-selector button:hover {
|
||||||
-webkit-box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.5);
|
-webkit-box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.5);
|
||||||
box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.5);
|
box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.5);
|
||||||
|
transform: scale(105%);
|
||||||
|
transition: 250ms all ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.animated-bg-gradient {
|
.animated-bg-gradient {
|
||||||
|
|||||||
Reference in New Issue
Block a user