Skip to content

Commit

Permalink
add section preview in sanity studio
Browse files Browse the repository at this point in the history
  • Loading branch information
milewskibogumil committed Oct 24, 2024
1 parent 85badf7 commit e2757b7
Show file tree
Hide file tree
Showing 18 changed files with 76 additions and 43 deletions.
2 changes: 2 additions & 0 deletions apps/sanity/schema/Components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import IrregularImagesAndHeader from "./components/IrregularImagesAndHeader";
import HighlightedPerson from "./components/HighlightedPerson";
import PeopleShowcase from "./components/PeopleShowcase";
import ImagesMarquee from "./components/ImagesMarquee";
import TextBlockCtaAndImage from "./components/TextBlockCtaAndImage";

export default defineType({
name: 'components',
Expand All @@ -35,6 +36,7 @@ export default defineType({
HighlightedPerson,
PeopleShowcase,
ImagesMarquee,
TextBlockCtaAndImage,
],
options: {
insertMenu: {
Expand Down
7 changes: 3 additions & 4 deletions apps/sanity/schema/components/BorderedFullImage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineField } from 'sanity';
import { toPlainText } from '../../utils/to-plain-text';
import { sectionPreview } from '../../utils/section-preview';

const name = 'BorderedFullImage';
const title = 'Sekcja z pełnym obrazem i ramką';
Expand Down Expand Up @@ -33,13 +34,11 @@ export default defineField({
preview: {
select: {
heading: 'heading',
media: 'img',
},
prepare: ({ heading, media }) => ({
prepare: ({ heading }) => ({
title: title,
subtitle: toPlainText(heading),
media,
icon,
...sectionPreview({ name, icon: icon() }),
}),
},
});
7 changes: 3 additions & 4 deletions apps/sanity/schema/components/CtaSectionWithShapedImage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineField } from 'sanity';
import { toPlainText } from '../../utils/to-plain-text';
import { sectionPreview } from '../../utils/section-preview';

const name = 'CtaSectionWithShapedImage';
const title = 'Sekcja CTA z dużym zdjęciem';
Expand Down Expand Up @@ -46,13 +47,11 @@ export default defineField({
preview: {
select: {
heading: 'heading',
media: 'img',
},
prepare: ({ heading, media }) => ({
prepare: ({ heading }) => ({
title: title,
subtitle: toPlainText(heading),
media,
icon,
...sectionPreview({ name, icon: icon() }),
}),
},
});
6 changes: 3 additions & 3 deletions apps/sanity/schema/components/Faq.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineField } from 'sanity';
import { toPlainText } from '../../utils/to-plain-text';
import { sectionPreview } from '../../utils/section-preview';

const name = 'Faq';
const title = 'Sekcja FAQ';
Expand Down Expand Up @@ -64,12 +65,11 @@ export default defineField({
preview: {
select: {
heading: 'heading',
media: 'img',
},
prepare: ({ heading, media }) => ({
prepare: ({ heading }) => ({
title: title,
subtitle: toPlainText(heading),
media: media || icon,
...sectionPreview({ name, icon: icon() }),
}),
},
});
7 changes: 3 additions & 4 deletions apps/sanity/schema/components/FeatureAccordionSection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineField } from 'sanity';
import { toPlainText } from '../../utils/to-plain-text';
import { sectionPreview } from '../../utils/section-preview';

const name = 'FeatureAccordionSection';
const title = 'Sekcja z akordeonem cech';
Expand Down Expand Up @@ -63,13 +64,11 @@ export default defineField({
preview: {
select: {
heading: 'heading',
media: 'img',
},
prepare: ({ heading, media }) => ({
prepare: ({ heading }) => ({
title: title,
subtitle: toPlainText(heading),
media,
icon,
...sectionPreview({ name, icon: icon() }),
}),
},
});
7 changes: 3 additions & 4 deletions apps/sanity/schema/components/HighlightedPerson.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineField } from 'sanity';
import { toPlainText } from '../../utils/to-plain-text';
import { sectionPreview } from '../../utils/section-preview';

const name = 'HighlightedPerson';
const title = 'Sekcja z osobą wyróżnioną';
Expand Down Expand Up @@ -67,13 +68,11 @@ export default defineField({
preview: {
select: {
heading: 'heading',
media: 'img',
},
prepare: ({ heading, media }) => ({
prepare: ({ heading }) => ({
title: title,
subtitle: toPlainText(heading),
media,
icon,
...sectionPreview({ name, icon: icon() }),
}),
},
});
3 changes: 2 additions & 1 deletion apps/sanity/schema/components/IconGridWithCtaSection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineField } from 'sanity';
import { toPlainText } from '../../utils/to-plain-text';
import { sectionPreview } from '../../utils/section-preview';

const name = 'IconGridWithCtaSection';
const title = 'Sekcja z siatką ikon i CTA';
Expand Down Expand Up @@ -73,7 +74,7 @@ export default defineField({
prepare: ({ heading }) => ({
title: title,
subtitle: toPlainText(heading),
icon,
...sectionPreview({ name, icon: icon() }),
}),
},
});
7 changes: 3 additions & 4 deletions apps/sanity/schema/components/ImagesMarquee.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineField } from 'sanity';
import { toPlainText } from '../../utils/to-plain-text';
import { sectionPreview } from '../../utils/section-preview';

const name = 'ImagesMarquee';
const title = 'Sekcja z przewijającymi się zdjęciami';
Expand Down Expand Up @@ -41,13 +42,11 @@ export default defineField({
preview: {
select: {
heading: 'heading',
media: 'img',
},
prepare: ({ heading, media }) => ({
prepare: ({ heading }) => ({
title: title,
subtitle: toPlainText(heading),
media,
icon,
...sectionPreview({ name, icon: icon() }),
}),
},
});
3 changes: 2 additions & 1 deletion apps/sanity/schema/components/IrregularImagesAndHeader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineField } from 'sanity';
import { toPlainText } from '../../utils/to-plain-text';
import { sectionPreview } from '../../utils/section-preview';

const name = 'IrregularImagesAndHeader';
const title = 'Sekcja z nieregularnymi zdjęciami i nagłówkiem';
Expand Down Expand Up @@ -45,7 +46,7 @@ export default defineField({
prepare: ({ heading }) => ({
title: title,
subtitle: toPlainText(heading),
icon,
...sectionPreview({ name, icon: icon() }),
}),
},
});
3 changes: 2 additions & 1 deletion apps/sanity/schema/components/MetricsSection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineField } from 'sanity';
import { toPlainText } from '../../utils/to-plain-text';
import { sectionPreview } from '../../utils/section-preview';

const name = 'MetricsSection';
const title = 'Sekcja z metrykami';
Expand Down Expand Up @@ -84,7 +85,7 @@ export default defineField({
prepare: ({ heading }) => ({
title: title,
subtitle: toPlainText(heading),
icon,
...sectionPreview({ name, icon: icon() }),
}),
},
});
3 changes: 2 additions & 1 deletion apps/sanity/schema/components/PeopleShowcase.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineField } from 'sanity';
import { toPlainText } from '../../utils/to-plain-text';
import { sectionPreview } from '../../utils/section-preview';

const name = 'PeopleShowcase';
const title = 'Sekcja z osobami';
Expand Down Expand Up @@ -84,7 +85,7 @@ export default defineField({
prepare: ({ heading }) => ({
title: title,
subtitle: toPlainText(heading),
icon,
...sectionPreview({ name, icon: icon() }),
}),
},
});
3 changes: 2 additions & 1 deletion apps/sanity/schema/components/ServicesOverview.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineField } from 'sanity';
import { toPlainText } from '../../utils/to-plain-text';
import { sectionPreview } from '../../utils/section-preview';

const name = 'ServicesOverview';
const title = 'Sekcja z przeglądem usług';
Expand Down Expand Up @@ -126,7 +127,7 @@ export default defineField({
prepare: ({ heading }) => ({
title: title,
subtitle: toPlainText(heading),
icon,
...sectionPreview({ name, icon: icon() }),
}),
},
});
11 changes: 5 additions & 6 deletions apps/sanity/schema/components/SimpleCtaSection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineField } from 'sanity';
import { toPlainText } from '../../utils/to-plain-text';
import { sectionPreview } from '../../utils/section-preview';

const name = 'SimpleCtaSection';
const title = 'Prosta sekcja z CTA';
Expand Down Expand Up @@ -32,14 +33,12 @@ export default defineField({
],
preview: {
select: {
heading: 'heading',
media: 'list.0.img',
name: 'name',
},
prepare: ({ heading, media }) => ({
prepare: ({ name }) => ({
title: title,
subtitle: toPlainText(heading),
media,
icon,
subtitle: toPlainText(name),
...sectionPreview({ name, icon: icon() }),
}),
},
});
7 changes: 3 additions & 4 deletions apps/sanity/schema/components/SimpleHeadingFullImage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineField } from 'sanity';
import { toPlainText } from '../../utils/to-plain-text';
import { sectionPreview } from '../../utils/section-preview';

const name = 'SimpleHeadingFullImage';
const title = 'Prosty nagłówek z pełnym obrazem';
Expand Down Expand Up @@ -39,13 +40,11 @@ export default defineField({
preview: {
select: {
heading: 'heading',
media: 'image',
},
prepare: ({ heading, media }) => ({
prepare: ({ heading }) => ({
title: title,
subtitle: toPlainText(heading),
media,
icon,
...sectionPreview({ name, icon: icon() }),
}),
},
});
3 changes: 2 additions & 1 deletion apps/sanity/schema/components/SplitContentImageGrid.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineField } from 'sanity';
import { toPlainText } from '../../utils/to-plain-text';
import { sectionPreview } from '../../utils/section-preview';

const name = 'SplitContentImageGrid';
const title = 'Sekcja z treścią i siatką obrazów';
Expand Down Expand Up @@ -44,7 +45,7 @@ export default defineField({
prepare: ({ heading }) => ({
title,
subtitle: toPlainText(heading),
icon,
...sectionPreview({ name, icon: icon() }),
}),
},
});
7 changes: 3 additions & 4 deletions apps/sanity/schema/components/TwoColumnTextWithTags.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defineField } from 'sanity';
import { toPlainText } from '../../utils/to-plain-text';
import { sectionPreview } from '../../utils/section-preview';

const name = 'TwoColumnTextWithTags';
const title = 'Sekcja Kolumnowa z Tagami';
Expand Down Expand Up @@ -46,13 +47,11 @@ export default defineField({
preview: {
select: {
heading: 'heading',
media: 'img',
},
prepare: ({ heading, media }) => ({
prepare: ({ heading }) => ({
title: title,
subtitle: toPlainText(heading),
media,
icon,
...sectionPreview({ name, icon: icon() }),
}),
},
});
Binary file added apps/sanity/static/TextBlockCtaAndImage.webp
Binary file not shown.
33 changes: 33 additions & 0 deletions apps/sanity/utils/section-preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Box, Text, Tooltip } from '@sanity/ui';

export const sectionPreview = ({ name, icon, label }: { name: string; icon: string; label?: string }) => ({
media: () => (
<Tooltip
animate
placement="top"
portal
content={
<Box padding={2}>
<img src={`/static/${name}.webp`} width={610} alt="" style={{ maxWidth: '100%' }} />
{label && (
<Text
style={{
fontSize: '0.875rem',
padding: '1rem',
display: 'block',
textAlign: 'center',
borderTop: '1px solid rgba(255,255,255,0.13)',
textTransform: 'uppercase',
fontWeight: '600',
}}
>
{label}
</Text>
)}
</Box>
}
>
<span>{icon}</span>
</Tooltip>
),
});

0 comments on commit e2757b7

Please sign in to comment.