-
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
3c97711
commit dd578bf
Showing
6 changed files
with
192 additions
and
6 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
116 changes: 116 additions & 0 deletions
116
apps/astro/src/components/global/FeaturedProjects.astro
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,116 @@ | ||
--- | ||
import PortableText, { PortableTextQuery, type PortableTextValue } from '@/components/ui/portable-text' | ||
import Image, { ImageDataQuery, type ImageDataProps } from '@/src/components/ui/Image' | ||
import Button, { ButtonDataQuery, type ButtonDataProps } from '@/components/ui/Button' | ||
export const ProjectCard_Query = ` | ||
${ImageDataQuery('img')} | ||
name, | ||
"slug": slug.current, | ||
` | ||
export const FeaturedProjects_Query = ` | ||
_type == "FeaturedProjects" => { | ||
${PortableTextQuery('heading')} | ||
${ButtonDataQuery('cta')} | ||
"isSelectedProjects": projects != null, | ||
"projects": select(projects != null => | ||
projects[] -> { | ||
${ProjectCard_Query} | ||
}, | ||
*[_type == "Project_Collection"][] | order(endDate desc)[0..4] { | ||
${ProjectCard_Query} | ||
}, | ||
), | ||
}, | ||
` | ||
export type Props = { | ||
index: number | ||
heading: PortableTextValue | ||
cta: ButtonDataProps | ||
isSelectedProjects: boolean | ||
projects: Array<{ | ||
img: ImageDataProps | ||
name: string | ||
slug: string | ||
}> | ||
excludeSlug?: string | ||
} | ||
const { index, heading, cta, isSelectedProjects, projects: _projects, excludeSlug } = Astro.props | ||
const projects = isSelectedProjects | ||
? _projects.slice(0, 4) | ||
: _projects.filter((project) => project.slug !== excludeSlug).slice(0, 4) | ||
--- | ||
|
||
<section class="FeaturedProjects"> | ||
<header> | ||
<PortableText value={heading} heading={index === 0 ? 'h1' : 'h2'} class="h2 heading" /> | ||
<Button {...cta} /> | ||
</header> | ||
<div class="projects"> | ||
{ | ||
projects.map(({ img, name, slug }) => ( | ||
<article> | ||
<a href={slug} class="project-link"> | ||
<div class="img"> | ||
<Image {...img} sizes="(max-width: 28rem) 100vw, (max-width: 38rem) 19rem, 25vw" priority={index === 0} /> | ||
</div> | ||
<h3 class="h3">{name}</h3> | ||
</a> | ||
</article> | ||
)) | ||
} | ||
</div> | ||
</section> | ||
|
||
<style lang="scss"> | ||
.FeaturedProjects { | ||
padding: clamp(3rem, calc(4vw / 0.48), 5rem) 0; | ||
header { | ||
margin-bottom: clamp(1.25rem, calc(2vw / 0.48), 2rem); | ||
.heading { | ||
margin-bottom: clamp(0.5rem, calc(1vw / 0.48), 1rem); | ||
} | ||
} | ||
.projects { | ||
display: grid; | ||
gap: 0.75rem; | ||
grid-template-columns: 1fr 1fr 1fr 1fr; | ||
.project-link { | ||
display: block; | ||
&:hover, | ||
&:focus-visible { | ||
img { | ||
transform: scale(1.03); | ||
} | ||
} | ||
.img { | ||
aspect-ratio: 48/61; | ||
overflow: hidden; | ||
img { | ||
height: 100%; | ||
transition: transform 800ms var(--easing); | ||
} | ||
} | ||
h2 { | ||
margin-top: 0.25rem; | ||
} | ||
} | ||
} | ||
@media (max-width: 63rem) { | ||
margin: 0 auto; | ||
max-width: 38rem; | ||
.projects { | ||
grid-template-columns: 1fr 1fr; | ||
} | ||
} | ||
@media (max-width: 28rem) { | ||
.projects { | ||
grid-template-columns: 1fr; | ||
} | ||
} | ||
} | ||
</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,62 @@ | ||
import { defineField } from 'sanity'; | ||
import { toPlainText } from '../../utils/to-plain-text'; | ||
import { sectionPreview } from '../../utils/section-preview'; | ||
|
||
const name = 'FeaturedProjects'; | ||
const title = 'Wyróżnione projekty'; | ||
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: 'cta', | ||
type: 'cta', | ||
title: 'Wezwanie do działania', | ||
validation: Rule => Rule.required(), | ||
}), | ||
defineField({ | ||
name: 'projects', | ||
type: 'array', | ||
title: 'Projekty (opcjonalne)', | ||
description: 'Jeśli to pole zostanie puste, zostaną wyświetlone 4 ostatnie projekty (według daty zakończenia).', | ||
of: [{ | ||
type: 'reference', | ||
to: [{ type: 'Project_Collection' }], | ||
options: { | ||
disableNew: true, | ||
filter: ({ parent }) => { | ||
const selectedIds = (parent as { _ref?: string }[])?.filter(item => item._ref).map(item => item._ref) || []; | ||
if (selectedIds.length > 0) { | ||
return { | ||
filter: '!(_id in $selectedIds)', | ||
params: { selectedIds } | ||
} | ||
} | ||
return {} | ||
} | ||
} | ||
}], | ||
validation: Rule => Rule.max(4).error('Rekomendujemy dodanie maksymalnie 4 projektów.'), | ||
}), | ||
], | ||
preview: { | ||
select: { | ||
heading: 'heading', | ||
}, | ||
prepare: ({ heading }) => ({ | ||
title: title, | ||
subtitle: toPlainText(heading), | ||
...sectionPreview({ name, icon: icon() }), | ||
}), | ||
}, | ||
}); |
Binary file not shown.