-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b05c6e2
commit 92fb568
Showing
6 changed files
with
157 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
--- | ||
import PortableText, { PortableTextQuery, type PortableTextValue } from '@/components/ui/portable-text' | ||
import Image, { ImageDataQuery, type ImageDataProps } from '@/components/ui/image' | ||
import Button, { ButtonDataQuery, type ButtonDataProps } from '@/components/ui/button' | ||
export const ImagesMarquee_Query = ` | ||
_type == "ImagesMarquee" => { | ||
${PortableTextQuery('heading')} | ||
${PortableTextQuery('paragraph')} | ||
${ButtonDataQuery('ctas[]')} | ||
${ImageDataQuery('images[]')} | ||
}, | ||
` | ||
export type Props = { | ||
index: number | ||
heading: PortableTextValue | ||
paragraph: PortableTextValue | ||
ctas: ButtonDataProps[] | ||
images: ImageDataProps[] | ||
} | ||
const { index, heading, paragraph, ctas, images } = Astro.props | ||
--- | ||
|
||
<section class="ImagesMarquee"> | ||
<div class="images"> | ||
{ | ||
Array.from({ length: 2 }).map((_, index) => ( | ||
<ul aria-hidden={index === 1} style={`animation-duration: ${images.length * 3}s;`}> | ||
{images?.map((img) => { | ||
const aspectRatio = img.asset.metadata.dimensions.width / img.asset.metadata.dimensions.height | ||
const minWidth = Math.round(164 * aspectRatio) | ||
const maxWidth = Math.round(210 * aspectRatio) | ||
const sizes = `(max-width: 768px) ${minWidth}px, ${maxWidth}px` | ||
return ( | ||
<li> | ||
<Image {...img} sizes={sizes} loading={index === 0 ? 'eager' : 'lazy'} /> | ||
</li> | ||
) | ||
})} | ||
</ul> | ||
)) | ||
} | ||
</div> | ||
<header> | ||
<PortableText value={heading} heading={index === 0 ? 'h1' : 'h2'} class="h2" /> | ||
<PortableText value={paragraph} class="paragraph" /> | ||
<div class="cta-wrapper"> | ||
{ctas?.map((cta) => <Button {...cta} />)} | ||
</div> | ||
</header> | ||
</section> | ||
|
||
<style lang="scss"> | ||
.ImagesMarquee { | ||
padding: clamp(4rem, calc(5vw / 0.48), 5rem) 0; | ||
.images { | ||
height: clamp(164px, calc(210vw / 7.68), 210px); | ||
$gap: 1rem; | ||
margin: 0 calc(var(--page-margin) * -1); | ||
overflow: hidden; | ||
display: flex; | ||
gap: $gap; | ||
ul { | ||
flex-shrink: 0; | ||
display: flex; | ||
gap: $gap; | ||
animation: marquee 10s linear infinite; | ||
@keyframes marquee { | ||
0% { | ||
transform: translateX(0); | ||
} | ||
100% { | ||
transform: translateX(calc(-100% - $gap)); | ||
} | ||
} | ||
li { | ||
flex-shrink: 0; | ||
img { | ||
width: auto; | ||
height: 100%; | ||
} | ||
} | ||
} | ||
} | ||
header { | ||
max-width: 28rem; | ||
margin: clamp(2rem, calc(2vw / 0.48), 3rem) auto 0; | ||
text-align: center; | ||
.paragraph { | ||
margin: 1rem 0 clamp(1.5rem, calc(2vw / 0.48), 2rem); | ||
} | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { defineField } from 'sanity'; | ||
import { toPlainText } from '../../utils/to-plain-text'; | ||
|
||
const name = 'ImagesMarquee'; | ||
const title = 'Sekcja z przewijającymi się zdjęciami'; | ||
const icon = () => '🔄'; | ||
|
||
export default defineField({ | ||
name, | ||
type: 'object', | ||
title, | ||
icon, | ||
fields: [ | ||
defineField({ | ||
name: 'heading', | ||
type: 'Heading', | ||
title: 'Nagłówek', | ||
validation: Rule => Rule.required(), | ||
}), | ||
defineField({ | ||
name: 'paragraph', | ||
type: 'PortableText', | ||
title: 'Paragraf', | ||
validation: Rule => Rule.required(), | ||
}), | ||
defineField({ | ||
name: 'ctas', | ||
type: 'array', | ||
of: [{ type: 'cta' }], | ||
title: 'CTAs', | ||
validation: Rule => Rule.required().min(1).max(2) | ||
}), | ||
defineField({ | ||
name: 'images', | ||
type: 'array', | ||
title: 'Zdjęcia', | ||
of: [{ type: 'image' }], | ||
validation: Rule => Rule.required().min(5), | ||
}), | ||
], | ||
preview: { | ||
select: { | ||
heading: 'heading', | ||
media: 'img', | ||
}, | ||
prepare: ({ heading, media }) => ({ | ||
title: title, | ||
subtitle: toPlainText(heading), | ||
media, | ||
icon, | ||
}), | ||
}, | ||
}); |
Binary file not shown.