Skip to content

Commit 9d60dcc

Browse files
committed
refactor(AnimatedBeam): support vertical beam
1 parent 7f5d5ad commit 9d60dcc

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<template>
2+
<ClientOnly>
3+
<div
4+
ref="containerRef"
5+
class="relative flex h-[500px] w-full items-center justify-center overflow-hidden rounded-lg border bg-background p-10 md:shadow-xl"
6+
>
7+
<div class="flex size-full flex-col items-center justify-between">
8+
<div
9+
ref="div1Ref"
10+
class="z-10 flex size-12 items-center justify-center rounded-full border-2 bg-white p-2 shadow-[0_0_20px_-12px_rgba(0,0,0,0.8)]"
11+
>
12+
<Icon
13+
name="logos:github-icon"
14+
size="24"
15+
/>
16+
</div>
17+
<div
18+
ref="div2Ref"
19+
class="z-10 flex size-12 items-center justify-center rounded-full border-2 bg-white p-2 shadow-[0_0_20px_-12px_rgba(0,0,0,0.8)]"
20+
>
21+
<Icon
22+
name="logos:google-drive"
23+
size="24"
24+
/>
25+
</div>
26+
</div>
27+
28+
<AnimatedBeam
29+
:container-ref="containerRef"
30+
:from-ref="div1Ref"
31+
:to-ref="div2Ref"
32+
/>
33+
</div>
34+
</ClientOnly>
35+
</template>
36+
37+
<script setup lang="ts">
38+
import { ref } from "vue";
39+
40+
const containerRef = ref(null);
41+
const div1Ref = ref(null);
42+
const div2Ref = ref(null);
43+
</script>

components/content/inspira/ui/animated-beam/AnimatedBeam.vue

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
stop-opacity="0"
4646
/>
4747
<animate
48+
v-if="!isVertical"
4849
attributeName="x1"
4950
:values="x1"
5051
:dur="`${duration}s`"
@@ -54,6 +55,7 @@
5455
repeatCount="indefinite"
5556
/>
5657
<animate
58+
v-if="!isVertical"
5759
attributeName="x2"
5860
:values="x2"
5961
:dur="`${duration}s`"
@@ -62,6 +64,26 @@
6264
calcMode="spline"
6365
repeatCount="indefinite"
6466
/>
67+
<animate
68+
v-if="isVertical"
69+
attributeName="y1"
70+
:values="y1"
71+
:dur="`${duration}s`"
72+
keyTimes="0; 1"
73+
keySplines="0.16 1 0.3 1"
74+
calcMode="spline"
75+
repeatCount="indefinite"
76+
/>
77+
<animate
78+
v-if="isVertical"
79+
attributeName="y2"
80+
:values="y2"
81+
:dur="`${duration}s`"
82+
keyTimes="0; 1"
83+
keySplines="0.16 1 0.3 1"
84+
calcMode="spline"
85+
repeatCount="indefinite"
86+
/>
6587
</linearGradient>
6688
</defs>
6789
</svg>
@@ -108,8 +130,11 @@ const props = withDefaults(defineProps<AnimatedBeamProps>(), {
108130
});
109131
110132
const id = "beam-" + Math.random().toString(36).substring(2, 10);
133+
const isVertical = ref(false);
111134
const x1 = props.reverse ? "90%; -10%;" : "10%; 110%;";
112135
const x2 = props.reverse ? "100%; 0%;" : "0%; 100%;";
136+
const y1 = props.reverse ? "90%; -10%;" : "10%; 110%;";
137+
const y2 = props.reverse ? "100%; 0%;" : "0%; 100%;";
113138
114139
const pathD = ref("");
115140
const svgDimensions = ref<{ width: number; height: number }>({
@@ -148,6 +173,9 @@ function updatePath() {
148173
const endX = rectB.left - containerRect.left + rectB.width / 2 + (props.endXOffset ?? 0);
149174
const endY = rectB.top - containerRect.top + rectB.height / 2 + (props.endYOffset ?? 0);
150175
176+
// Check if the light beam is in a vertical direction (the distance in the y-direction is greater than the distance in the x-direction).
177+
isVertical.value = Math.abs(endY - startY) > Math.abs(endX - startX);
178+
151179
const controlY = startY - (props.curvature ?? 0);
152180
const d = `M ${startX},${startY} Q ${(startX + endX) / 2},${controlY} ${endX},${endY}`;
153181
pathD.value = d;

content/2.components/special-effects/animated-beam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ Double-sided beam.
2929
::ComponentLoader{label="Preview" componentName="AnimatedBeamDemo2" type="examples"}
3030
::
3131

32+
Vertical beam.
33+
34+
::ComponentLoader{label="Preview" componentName="AnimatedBeamDemo3" type="examples"}
35+
::
36+
3237
## API
3338

3439
| Prop Name | Type | Default | Description |

0 commit comments

Comments
 (0)