Skip to content

Commit

Permalink
Masonry grid styling and add carousel dots
Browse files Browse the repository at this point in the history
  • Loading branch information
Lindsey Zylstra committed Nov 15, 2024
1 parent 1b92f46 commit c3dfc1f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
3 changes: 3 additions & 0 deletions components/Block/Carousel/Carousel.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import Carousel from '@/components/Carousel/Carousel.vue';
import CarouselControls from '@/components/Carousel/CarouselControls.vue';
import CarouselDots from '~/components/Carousel/CarouselDots.vue';
import ClassNames from 'embla-carousel-class-names';
const { $directus, $readItem } = useNuxtApp();
Expand Down Expand Up @@ -48,6 +49,7 @@ onMounted(async () => {
aria-label="Previous slide"
@click="scrollPrev"
/>
<CarouselDots />
<BaseButton
color="secondary"
outline
Expand Down Expand Up @@ -107,6 +109,7 @@ onMounted(async () => {
justify-content: center;
gap: 60px;
margin-top: 65px;
align-items: center;
}
&__button {
Expand Down
4 changes: 2 additions & 2 deletions components/Block/MasonryGrid/MasonryGridCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ const isExternal = computed(() => !!cardData.value?.external_url);
width: 100%;
height: 100%;
object-fit: cover;
filter: grayscale(100%);
filter: grayscale(100%) opacity(40%);
transition: filter 0.3s ease-in-out;
&:hover {
filter: grayscale(0%);
filter: grayscale(0%) opacity(100%);
}
}
Expand Down
39 changes: 39 additions & 0 deletions components/Carousel/CarouselDots.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<script setup lang="ts">
import { useCarousel } from './useCarousel';
const { scrollTo, selectedIndex, scrollSnaps } = useCarousel();
</script>

<template>
<div class="carousel__dots">
<button
v-for="(snap, index) in scrollSnaps"
:key="index"
class="carousel__dot"
:class="{ 'carousel__dot--active': index === selectedIndex }"
aria-label="'Go to slide ' + (index + 1)"
@click="scrollTo(index)"
></button>
</div>
</template>

<style lang="scss" scoped>
.carousel__dots {
display: flex;
gap: 8px;
}
.carousel__dot {
width: 10px;
height: 10px;
background-color: #f1f3f7;
border: none;
border-radius: 50%;
cursor: pointer;
transition: background-color 0.3s;
}
.carousel__dot--active {
background-color: #42566e;
}
</style>
11 changes: 11 additions & 0 deletions components/Carousel/useCarousel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,20 @@ const [useProvideCarousel, useInjectCarousel] = createInjectionState(
emblaApi.value?.scrollNext();
}

function scrollTo(index: number) {
emblaApi.value?.scrollTo(index);
}

const canScrollNext = ref(false);
const canScrollPrev = ref(false);
const selectedIndex = ref(0);
const scrollSnaps = ref<number[]>([]);

function onSelect(api: CarouselApi) {
canScrollNext.value = api?.canScrollNext() || false;
canScrollPrev.value = api?.canScrollPrev() || false;
selectedIndex.value = api?.selectedScrollSnap() || 0;
scrollSnaps.value = api?.scrollSnapList() || [];
}

const totalCount = ref(0);
Expand Down Expand Up @@ -62,6 +70,9 @@ const [useProvideCarousel, useInjectCarousel] = createInjectionState(
scrollPrev,
scrollNext,
orientation,
scrollTo,
scrollSnaps,
selectedIndex,
current,
totalCount,
};
Expand Down

0 comments on commit c3dfc1f

Please sign in to comment.