Create props for ShopModule content
Allows to customize content if for a specific one for instance
This commit is contained in:
@@ -8,12 +8,6 @@
|
|||||||
import Button from '$components/atoms/Button.svelte'
|
import Button from '$components/atoms/Button.svelte'
|
||||||
import Image from '$components/atoms/Image.svelte'
|
import Image from '$components/atoms/Image.svelte'
|
||||||
|
|
||||||
interface Location {
|
|
||||||
slug: string
|
|
||||||
name: string
|
|
||||||
has_poster: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
const { locations, shop } = getContext('global')
|
const { locations, shop } = getContext('global')
|
||||||
const locationsWithPoster = locations
|
const locationsWithPoster = locations
|
||||||
// Filter locations with posters only
|
// Filter locations with posters only
|
||||||
@@ -23,22 +17,43 @@
|
|||||||
// Return name only
|
// Return name only
|
||||||
.map((loc: Location) => loc.name)
|
.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
|
// Image rotation
|
||||||
let imagesLoop: ReturnType<typeof setTimeout>
|
let imagesLoop: ReturnType<typeof setTimeout>
|
||||||
let currentImageIndex = 0
|
let currentImageIndex = 0
|
||||||
|
|
||||||
const incrementCurrentImageIndex = () => {
|
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)
|
imagesLoop = setTimeout(() => requestAnimationFrame(incrementCurrentImageIndex), 3000)
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
incrementCurrentImageIndex()
|
if (images.length > 1) {
|
||||||
|
incrementCurrentImageIndex()
|
||||||
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
// Clear rotating words timeout
|
// Clear rotating words timeout
|
||||||
clearTimeout(imagesLoop)
|
if (imagesLoop) {
|
||||||
|
clearTimeout(imagesLoop)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@@ -46,9 +61,9 @@
|
|||||||
<div class="shop shadow-box-dark">
|
<div class="shop shadow-box-dark">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="shop__images">
|
<div class="shop__images">
|
||||||
{#if shop.module_images}
|
{#if images}
|
||||||
<a href="/shop" title="Visit our shop" sveltekit:noscroll sveltekit:prefetch>
|
<a href={enabled ? url : undefined} title="Visit our shop" sveltekit:noscroll sveltekit:prefetch>
|
||||||
{#each shop.module_images as { directus_files_id: { id, title }}, index}
|
{#each images as { directus_files_id: { id, title }}, index}
|
||||||
<Image
|
<Image
|
||||||
class={index === currentImageIndex ? 'is-visible' : null}
|
class={index === currentImageIndex ? 'is-visible' : null}
|
||||||
{id}
|
{id}
|
||||||
@@ -65,14 +80,14 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="shop__content">
|
<div class="shop__content">
|
||||||
<h2 class="title-medium">{shop.module_title}</h2>
|
<h2 class="title-medium">{title}</h2>
|
||||||
<p class="text-small">{shop.module_text}</p>
|
<p class="text-small">{text}</p>
|
||||||
{#if shop.enabled}
|
{#if enabled}
|
||||||
<Button url="/shop" text="Shop" color="pinklight" />
|
<Button {url} text={buttonText} color="pinklight" />
|
||||||
|
{/if}
|
||||||
|
{#if textBottom}
|
||||||
|
<p class="detail">{textBottom}</p>
|
||||||
{/if}
|
{/if}
|
||||||
<p class="detail">
|
|
||||||
Posters available for {locationsWithPoster.join(', ').replace(/,(?!.*,)/gmi, ' and')}.
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -18,12 +18,19 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Images
|
// Images
|
||||||
&__images {
|
&__images {
|
||||||
position: relative;
|
position: relative;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
min-height: 256px;
|
min-height: 256px;
|
||||||
|
|
||||||
|
a {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
:global(picture) {
|
:global(picture) {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
@@ -34,6 +41,9 @@
|
|||||||
transform: scale3d(1.075, 1.075, 1.075);
|
transform: scale3d(1.075, 1.075, 1.075);
|
||||||
transition: opacity 0.8s, transform 1.6s var(--ease-quart);
|
transition: opacity 0.8s, transform 1.6s var(--ease-quart);
|
||||||
}
|
}
|
||||||
|
:global(img) {
|
||||||
|
object-position: center 32%;
|
||||||
|
}
|
||||||
|
|
||||||
:global(.is-visible) {
|
:global(.is-visible) {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user