Create props for ShopModule content

Allows to customize content if for a specific one for instance
This commit is contained in:
2022-07-30 10:27:58 +02:00
parent 6a7c4a0c75
commit 31351ae095
2 changed files with 44 additions and 19 deletions

View File

@@ -8,12 +8,6 @@
import Button from '$components/atoms/Button.svelte'
import Image from '$components/atoms/Image.svelte'
interface Location {
slug: string
name: string
has_poster: boolean
}
const { locations, shop } = getContext('global')
const locationsWithPoster = locations
// Filter locations with posters only
@@ -23,22 +17,43 @@
// Return name only
.map((loc: Location) => loc.name)
export let images: any[] = shop.module_images
export let title: string = shop.module_title
export let text: string = shop.module_text
export let textBottom: string = undefined
export let buttonText: string = 'Shop'
export let url: string = '/shop'
export let enabled: boolean = true
if (textBottom !== null && textBottom !== undefined) {
textBottom = `Posters available for ${locationsWithPoster.join(', ').replace(/,(?!.*,)/gmi, ' and')}.`
}
interface Location {
slug: string
name: string
has_poster: boolean
}
// Image rotation
let imagesLoop: ReturnType<typeof setTimeout>
let currentImageIndex = 0
const incrementCurrentImageIndex = () => {
currentImageIndex = currentImageIndex === shop.module_images.length - 1 ? 0 : currentImageIndex + 1
currentImageIndex = currentImageIndex === images.length - 1 ? 0 : currentImageIndex + 1
imagesLoop = setTimeout(() => requestAnimationFrame(incrementCurrentImageIndex), 3000)
}
onMount(() => {
incrementCurrentImageIndex()
if (images.length > 1) {
incrementCurrentImageIndex()
}
return () => {
// Clear rotating words timeout
clearTimeout(imagesLoop)
if (imagesLoop) {
clearTimeout(imagesLoop)
}
}
})
</script>
@@ -46,9 +61,9 @@
<div class="shop shadow-box-dark">
<div class="content">
<div class="shop__images">
{#if shop.module_images}
<a href="/shop" title="Visit our shop" sveltekit:noscroll sveltekit:prefetch>
{#each shop.module_images as { directus_files_id: { id, title }}, index}
{#if images}
<a href={enabled ? url : undefined} title="Visit our shop" sveltekit:noscroll sveltekit:prefetch>
{#each images as { directus_files_id: { id, title }}, index}
<Image
class={index === currentImageIndex ? 'is-visible' : null}
{id}
@@ -65,14 +80,14 @@
</div>
<div class="shop__content">
<h2 class="title-medium">{shop.module_title}</h2>
<p class="text-small">{shop.module_text}</p>
{#if shop.enabled}
<Button url="/shop" text="Shop" color="pinklight" />
<h2 class="title-medium">{title}</h2>
<p class="text-small">{text}</p>
{#if enabled}
<Button {url} text={buttonText} color="pinklight" />
{/if}
{#if textBottom}
<p class="detail">{textBottom}</p>
{/if}
<p class="detail">
Posters available for {locationsWithPoster.join(', ').replace(/,(?!.*,)/gmi, ' and')}.
</p>
</div>
</div>
</div>