|
1 | 1 | <script lang="ts"> |
| 2 | + import { fly } from 'svelte/transition'; |
2 | 3 | const testimonials = [ |
3 | 4 |
|
4 | 5 | { |
|
46 | 47 | image: "", |
47 | 48 | }, |
48 | 49 | ]; |
| 50 | + let currentSlide = 0; |
| 51 | + let isAnimating = false; |
| 52 | + function nextSlide() { |
| 53 | + if (isAnimating) return; |
| 54 | + isAnimating = true; |
| 55 | + currentSlide = (currentSlide + 1) % testimonials.length; |
| 56 | + setTimeout(() => { isAnimating = false; }, 300); |
| 57 | + } |
| 58 | + function prevSlide() { |
| 59 | + if (isAnimating) return; |
| 60 | + isAnimating = true; |
| 61 | + currentSlide = currentSlide === 0 ? testimonials.length - 1 : currentSlide - 1; |
| 62 | + setTimeout(() => { isAnimating = false; }, 300); |
| 63 | + } |
| 64 | + function goToSlide(index: number) { |
| 65 | + if (isAnimating) return; |
| 66 | + isAnimating = true; |
| 67 | + currentSlide = index; |
| 68 | + setTimeout(() => { isAnimating = false; }, 300); |
| 69 | + } |
49 | 70 | </script> |
50 | 71 |
|
51 | 72 |
|
52 | 73 | <section class="relative py-20 bg-background overflow-auto"> |
53 | | - <div class="container max-w-7xl mx-auto"> |
54 | | - <div class=" h-[400px] md:h-[800px] overflow-y-auto relative [&::-webkit-scrollbar]:w-2 |
55 | | - [&::-webkit-scrollbar-track]:rounded-full |
56 | | - [&::-webkit-scrollbar-track]:bg-background |
57 | | - [&::-webkit-scrollbar-thumb]:rounded-full |
58 | | - [&::-webkit-scrollbar-thumb]:bg-muted"> |
| 74 | + <div class="container max-w-7xl mx-auto"> |
| 75 | + <!-- Mobile: Carousel --> |
| 76 | + <div class="md:hidden relative"> |
| 77 | + <div class="h-[400px] relative overflow-hidden"> |
| 78 | + {#each testimonials as testimonial, index} |
| 79 | + {#if index === currentSlide} |
| 80 | + <div |
| 81 | + class="absolute inset-0 w-full" |
| 82 | + transition:fly={{ x: 300, duration: 300 }} |
| 83 | + > |
| 84 | + <div class="w-full max-w-sm mx-auto bg-background border rounded-lg p-6 h-full flex flex-col"> |
| 85 | + <p class="text-foreground mb-4 text-left whitespace-pre-line flex-grow">{testimonial.text}</p> |
| 86 | + <div class="flex items-center gap-3 pt-4 border-t mt-4 flex-none"> |
| 87 | + {#if testimonial.image} |
| 88 | + <div class="w-12 h-12 rounded-full overflow-hidden bottom-0 flex-shrink-0"> |
| 89 | + <img |
| 90 | + src={testimonial.image} |
| 91 | + alt={testimonial.author} |
| 92 | + class="w-full h-full object-cover" |
| 93 | + /> |
| 94 | + </div> |
| 95 | + {:else} |
| 96 | + <div class="w-12 h-12 rounded-full bg-primary/10 flex items-center justify-center flex-shrink-0"> |
| 97 | + <span class="text-xl font-bold text-primary"> |
| 98 | + {testimonial.author[0]} |
| 99 | + </span> |
| 100 | + </div> |
| 101 | + {/if} |
| 102 | + <div class="text-left"> |
| 103 | + <div class="font-semibold text-foreground">{testimonial.author}</div> |
| 104 | + <div class="text-xs text-muted-foreground">{testimonial.role} {testimonial.company}</div> |
| 105 | + </div> |
| 106 | + </div> |
| 107 | + </div> |
| 108 | + </div> |
| 109 | + {/if} |
| 110 | + {/each} |
| 111 | + </div> |
| 112 | + |
| 113 | + <!-- Navigation Buttons --> |
| 114 | + <button |
| 115 | + class="absolute left-2 top-1/2 transform -translate-y-1/2 bg-background/80 hover:bg-background border rounded-full p-2 shadow-lg transition-all" |
| 116 | + on:click={prevSlide} |
| 117 | + aria-label="Previous testimonial" |
| 118 | + > |
| 119 | + <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"> |
| 120 | + <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" /> |
| 121 | + </svg> |
| 122 | + </button> |
| 123 | + |
| 124 | + <button |
| 125 | + class="absolute right-2 top-1/2 transform -translate-y-1/2 bg-background/80 hover:bg-background border rounded-full p-2 shadow-lg transition-all" |
| 126 | + on:click={nextSlide} |
| 127 | + aria-label="Next testimonial" |
| 128 | + > |
| 129 | + <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"> |
| 130 | + <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" /> |
| 131 | + </svg> |
| 132 | + </button> |
| 133 | + |
| 134 | + <!-- Slide Indicators --> |
| 135 | + <div class="flex justify-center gap-2 mt-4"> |
| 136 | + {#each testimonials as _, index} |
| 137 | + <button |
| 138 | + class="w-2 h-2 rounded-full transition-all {index === currentSlide ? 'bg-primary' : 'bg-muted'}" |
| 139 | + on:click={() => goToSlide(index)} |
| 140 | + aria-label="Go to slide {index + 1}" |
| 141 | + ></button> |
| 142 | + {/each} |
| 143 | + </div> |
| 144 | + </div> |
| 145 | + |
| 146 | + <!-- Desktop: Masonry Layout --> |
| 147 | + <div class="hidden md:block h-[800px] overflow-y-auto relative [&::-webkit-scrollbar]:w-2 [&::-webkit-scrollbar-track]:rounded-full [&::-webkit-scrollbar-track]:bg-background [&::-webkit-scrollbar-thumb]:rounded-full [&::-webkit-scrollbar-thumb]:bg-muted"> |
59 | 148 |
|
60 | 149 | <div class="columns-1 md:columns-2 lg:columns-3 gap-6"> |
61 | 150 | {#each testimonials as testimonial} |
62 | | - <div class="mb-6 break-inside-avoid bg-background border rounded-lg p-6"> |
63 | | - <p class="text-foreground mb-4 text-left whitespace-pre-line">{testimonial.text}</p> |
| 151 | + <div class="mb-6 break-inside-avoid bg-background border rounded-lg p-6 flex flex-col h-full"> |
| 152 | + <p class="text-foreground mb-4 text-left whitespace-pre-line flex-grow">{testimonial.text}</p> |
64 | 153 | <div class="flex items-center gap-3 pt-4 border-t mt-4 flex-none"> |
65 | 154 | {#if testimonial.image} |
66 | 155 | <div class="w-12 h-12 rounded-full overflow-hidden flex-shrink-0"> |
|
0 commit comments