|
| 1 | +import { $, component$, useSignal, useStyles$ } from '@builder.io/qwik'; |
| 2 | + |
| 3 | +import { |
| 4 | + Carousel, |
| 5 | + CarouselNext, |
| 6 | + CarouselPrev, |
| 7 | + CarouselSlide, |
| 8 | + CarouselView, |
| 9 | + CarouselContainer, |
| 10 | + CarouselPagination, |
| 11 | +} from '@qwik-ui/headless'; |
| 12 | +import carouselStyles from './carousel.css?inline'; |
| 13 | + |
| 14 | +export default component$(() => { |
| 15 | + /* TODO: document this to always have initial state to null. |
| 16 | + Use defaultSlide instead for setting a slide on page load */ |
| 17 | + const currentIndexSig = useSignal<number>(0); |
| 18 | + useStyles$(carouselStyles); |
| 19 | + |
| 20 | + const slideImageMetadata = [ |
| 21 | + { |
| 22 | + id: '10', |
| 23 | + author: 'Paul Jarvis', |
| 24 | + width: 2500, |
| 25 | + height: 1667, |
| 26 | + url: 'https://unsplash.com/photos/6J--NXulQCs', |
| 27 | + download_url: 'https://picsum.photos/id/10/2500/1667', |
| 28 | + }, |
| 29 | + { |
| 30 | + id: '11', |
| 31 | + author: 'Paul Jarvis', |
| 32 | + width: 2500, |
| 33 | + height: 1667, |
| 34 | + url: 'https://unsplash.com/photos/Cm7oKel-X2Q', |
| 35 | + download_url: 'https://picsum.photos/id/11/2500/1667', |
| 36 | + }, |
| 37 | + { |
| 38 | + id: '12', |
| 39 | + author: 'Paul Jarvis', |
| 40 | + width: 2500, |
| 41 | + height: 1667, |
| 42 | + url: 'https://unsplash.com/photos/I_9ILwtsl_k', |
| 43 | + download_url: 'https://picsum.photos/id/12/2500/1667', |
| 44 | + }, |
| 45 | + { |
| 46 | + id: '13', |
| 47 | + author: 'Paul Jarvis', |
| 48 | + width: 2500, |
| 49 | + height: 1667, |
| 50 | + url: 'https://unsplash.com/photos/3MtiSMdnoCo', |
| 51 | + download_url: 'https://picsum.photos/id/13/2500/1667', |
| 52 | + }, |
| 53 | + { |
| 54 | + id: '14', |
| 55 | + author: 'Paul Jarvis', |
| 56 | + width: 2500, |
| 57 | + height: 1667, |
| 58 | + url: 'https://unsplash.com/photos/IQ1kOQTJrOQ', |
| 59 | + download_url: 'https://picsum.photos/id/14/2500/1667', |
| 60 | + }, |
| 61 | + { |
| 62 | + id: '15', |
| 63 | + author: 'Paul Jarvis', |
| 64 | + width: 2500, |
| 65 | + height: 1667, |
| 66 | + url: 'https://unsplash.com/photos/NYDo21ssGao', |
| 67 | + download_url: 'https://picsum.photos/id/15/2500/1667', |
| 68 | + }, |
| 69 | + { |
| 70 | + id: '16', |
| 71 | + author: 'Paul Jarvis', |
| 72 | + width: 2500, |
| 73 | + height: 1667, |
| 74 | + url: 'https://unsplash.com/photos/gkT4FfgHO5o', |
| 75 | + download_url: 'https://picsum.photos/id/16/2500/1667', |
| 76 | + }, |
| 77 | + { |
| 78 | + id: '17', |
| 79 | + author: 'Paul Jarvis', |
| 80 | + width: 2500, |
| 81 | + height: 1667, |
| 82 | + url: 'https://unsplash.com/photos/Ven2CV8IJ5A', |
| 83 | + download_url: 'https://picsum.photos/id/17/2500/1667', |
| 84 | + }, |
| 85 | + { |
| 86 | + id: '18', |
| 87 | + author: 'Paul Jarvis', |
| 88 | + width: 2500, |
| 89 | + height: 1667, |
| 90 | + url: 'https://unsplash.com/photos/Ps2n0rShqaM', |
| 91 | + download_url: 'https://picsum.photos/id/18/2500/1667', |
| 92 | + }, |
| 93 | + { |
| 94 | + id: '19', |
| 95 | + author: 'Paul Jarvis', |
| 96 | + width: 2500, |
| 97 | + height: 1667, |
| 98 | + url: 'https://unsplash.com/photos/P7Lh0usGcuk', |
| 99 | + download_url: 'https://picsum.photos/id/19/2500/1667', |
| 100 | + }, |
| 101 | + ]; |
| 102 | + |
| 103 | + return ( |
| 104 | + <Carousel |
| 105 | + bind:currSlideIndex={currentIndexSig} |
| 106 | + spaceBetweenSlides={30} |
| 107 | + class="carousel" |
| 108 | + > |
| 109 | + <div class="carousel-buttons"> |
| 110 | + <CarouselPrev class="prev-button">Prev</CarouselPrev> |
| 111 | + <CarouselNext class="next-button">Next</CarouselNext> |
| 112 | + </div> |
| 113 | + <CarouselView> |
| 114 | + <CarouselContainer class="carousel-container"> |
| 115 | + {slideImageMetadata.map((data) => ( |
| 116 | + <CarouselSlide key={data.id} class="carousel-slide"> |
| 117 | + <img |
| 118 | + class="carousel-img" |
| 119 | + width="640" |
| 120 | + height="320" |
| 121 | + src={`https://picsum.photos/id/${data.id}/640/320`} |
| 122 | + alt={data.author} |
| 123 | + /> |
| 124 | + </CarouselSlide> |
| 125 | + ))} |
| 126 | + </CarouselContainer> |
| 127 | + </CarouselView> |
| 128 | + <div> |
| 129 | + <CarouselPagination |
| 130 | + class="carousel-pagination" |
| 131 | + renderBullet$={$((i: number) => { |
| 132 | + return ( |
| 133 | + <div |
| 134 | + class={`carousel-pagination-bullet ${ |
| 135 | + currentIndexSig.value === i ? 'pagination-underline' : '' |
| 136 | + }`} |
| 137 | + onClick$={() => (currentIndexSig.value = i)} |
| 138 | + > |
| 139 | + {i} |
| 140 | + </div> |
| 141 | + ); |
| 142 | + })} |
| 143 | + /> |
| 144 | + </div> |
| 145 | + </Carousel> |
| 146 | + ); |
| 147 | +}); |
0 commit comments