Skip to content

Commit 8d0ba76

Browse files
committed
partially fix snap grid example
1 parent 6e5f052 commit 8d0ba76

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

docs/.vitepress/components/v2/Examples/SnapGrid/Example.vue

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@
4040
:step-x="40"
4141
:step-y="40"
4242
>
43-
<SnapChip>Drag me</SnapChip>
43+
<SnapChip
44+
:style="{
45+
height: '40px',
46+
width: '80px'
47+
}">
48+
Drag
49+
</SnapChip>
4450
</GridCanvas>
4551
</DnDProvider>
4652
</div>
@@ -58,7 +64,13 @@
5864
:step-x="80"
5965
:step-y="40"
6066
>
61-
<SnapChip>Drag me</SnapChip>
67+
<SnapChip
68+
:style="{
69+
height: '40px',
70+
width: '80px'
71+
}">
72+
Drag
73+
</SnapChip>
6274
</GridCanvas>
6375
</DnDProvider>
6476
</div>

docs/.vitepress/components/v2/Examples/SnapGrid/GridCanvas.vue

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
11
<script setup lang="ts">
2+
import {computed, useTemplateRef} from 'vue'
3+
24
const props = defineProps<{
35
stepX: number;
46
stepY: number;
57
}>();
8+
9+
const canvasRef = useTemplateRef('canvasRef');
10+
11+
/** Workaround for example
12+
* snap on DragPreview must be handle "round" logic, based on parent position
13+
*/
14+
const canvasPadding = computed(() => {
15+
const rect = canvasRef.value?.getBoundingClientRect()
16+
if(!rect)
17+
return { pX: 0, pY: 0 }
18+
19+
const pX = rect.left % props.stepX * -1
20+
const pY = rect.top % props.stepY * -1
21+
22+
return { pX, pY }
23+
})
624
</script>
725

826
<template>
927
<div
28+
ref="canvasRef"
1029
class="canvas"
11-
:style="{ '--gx': `${props.stepX}px`, '--gy': `${props.stepY}px` }"
30+
:style="{
31+
'--gx': `${props.stepX}px`,
32+
'--gy': `${props.stepY}px`,
33+
'--px': `${canvasPadding.pX}px`,
34+
'--py': `${canvasPadding.pY}px`
35+
}"
1236
>
1337
<slot />
1438
</div>
@@ -25,6 +49,7 @@
2549
linear-gradient(rgba(62, 175, 124, 0.15) 1px, transparent 1px),
2650
linear-gradient(90deg, rgba(62, 175, 124, 0.15) 1px, transparent 1px);
2751
background-size: var(--gx) var(--gy);
52+
background-position: var(--px) var(--py);
2853
display: flex;
2954
align-items: center;
3055
justify-content: center;

docs/.vitepress/components/v2/Examples/SnapGrid/SnapChip.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
cursor: grab;
2828
display: inline-flex;
2929
align-items: center;
30+
justify-content: center;
3031
gap: 0.5rem;
3132
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
3233
transition: box-shadow 0.15s;

0 commit comments

Comments
 (0)