Skip to content

Commit

Permalink
feat: components with global data (#69)
Browse files Browse the repository at this point in the history
* fix: header footer slugs, moved to components folder

* feat: add ability to create global components and edit them from a single place

* feat: remove utility to resolve header and footer relations, move resolving relations to the component level, reusing useGlobalComponent hook

* feat: rename globalComponent to globalData, update stories, schemas, types

* feat: add globalData to hero for sanity component, change hero query to resolve globalData, add comment to use CSS variables as section background
  • Loading branch information
dogfrogfog authored Dec 16, 2024
1 parent 4c844f4 commit 29d640f
Show file tree
Hide file tree
Showing 30 changed files with 996 additions and 423 deletions.
4 changes: 2 additions & 2 deletions apps/sanity/src/components/SectionContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function SectionContainer({

const cleanMarginTop = stegaClean(marginTop);
const cleanMarginBottom = stegaClean(marginBottom);
const cleanBackgroundColor = stegaClean(backgroundColor);
const cleanBackgroundColor = stegaClean(backgroundColor); // implement using CSS variables
const cleanMaxWidth = stegaClean(maxWidth);

return (
Expand All @@ -45,7 +45,7 @@ export default function SectionContainer({
className={cn(
"bg-bgColor overflow-x-hidden",
className,
cleanBackgroundColor,
cleanBackgroundColor, // implement using CSS variables
{
"mt-0": cleanMarginTop === "none",
"mb-0": cleanMarginBottom === "none",
Expand Down
22 changes: 21 additions & 1 deletion apps/sanity/src/contentSections/Hero/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,31 @@ import type { IHeroSectionProps } from "./types";
export default function HeroSection({ data }: IHeroSectionProps) {
if (!data) return null;

const { title, text, image, links } = data;
const { title, text, image, links, globalData } = data;

if (!title && !text?.text && !image?.image && (!links || links.length === 0))
return <EmptyBlock name="Hero Section" />;

if (globalData) {
const {
title: globalTitle,
text: globalText,
image: globalImage,
links: globalLinks,
} = globalData as any;

return (
<SectionContainer sectionData={globalData as any}>
<Hero
title={globalTitle}
text={prepareRichTextProps(globalText)}
image={prepareImageProps(globalImage)}
links={globalLinks?.map(prepareLinkProps) || []}
/>
</SectionContainer>
);
}

return (
<SectionContainer sectionData={data}>
<Hero
Expand Down
6 changes: 6 additions & 0 deletions apps/sanity/src/contentSections/Hero/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { LINK_FRAGMENT } from "@/lib/api/fragments";

export const HERO_FRAGMENT = `
...,
globalData->{
...,
links[] {
${LINK_FRAGMENT}
},
},
links[] {
${LINK_FRAGMENT}
}
Expand Down
9 changes: 8 additions & 1 deletion apps/sanity/src/contentSections/Hero/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ export default {
options: {},
name: "section.hero",
title: "Hero",
type: "object",
type: "document",
groups: commonGroups,
fields: [
defineField({
name: "globalData",
title: "Global Data",
type: "reference",
to: [{ type: "section.hero" }],
group: CommonGroup.Content,
}),
defineField({
name: "title",
type: "string",
Expand Down
Loading

0 comments on commit 29d640f

Please sign in to comment.