-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Mitchell Christ
committed
Sep 25, 2024
1 parent
f33e307
commit c402a68
Showing
9 changed files
with
230 additions
and
1 deletion.
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
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,104 @@ | ||
import { defineArrayMember, defineField, defineType } from 'sanity' | ||
import { PiTabs } from 'react-icons/pi' | ||
import { getBlockText } from '@sanity/src/utils' | ||
|
||
export default defineType({ | ||
name: 'tabbed-content', | ||
title: 'Tabbed content', | ||
icon: PiTabs, | ||
type: 'object', | ||
fields: [ | ||
defineField({ | ||
name: 'pretitle', | ||
type: 'string', | ||
}), | ||
defineField({ | ||
name: 'intro', | ||
type: 'array', | ||
of: [{ type: 'block' }], | ||
}), | ||
defineField({ | ||
name: 'tabs', | ||
title: 'Tabs', | ||
type: 'array', | ||
of: [ | ||
defineArrayMember({ | ||
type: 'object', | ||
fields: [ | ||
defineField({ | ||
name: 'label', | ||
type: 'string', | ||
}), | ||
defineField({ | ||
name: 'pretitle', | ||
type: 'string', | ||
}), | ||
defineField({ | ||
name: 'content', | ||
type: 'array', | ||
of: [{ type: 'block' }], | ||
}), | ||
defineField({ | ||
name: 'ctas', | ||
title: 'Call-to-actions', | ||
type: 'array', | ||
of: [{ type: 'cta' }], | ||
}), | ||
defineField({ | ||
name: 'image', | ||
type: 'image', | ||
fields: [ | ||
defineField({ | ||
name: 'alt', | ||
type: 'string', | ||
}), | ||
defineField({ | ||
name: 'onRight', | ||
type: 'boolean', | ||
description: 'Display to the right of the content on desktop', | ||
initialValue: false, | ||
}), | ||
defineField({ | ||
name: 'onBottom', | ||
type: 'boolean', | ||
description: 'Display below the content on mobile', | ||
initialValue: false, | ||
}), | ||
defineField({ | ||
name: 'loading', | ||
type: 'string', | ||
options: { | ||
list: ['lazy', 'eager'], | ||
layout: 'radio', | ||
}, | ||
initialValue: 'lazy', | ||
}), | ||
], | ||
}), | ||
], | ||
preview: { | ||
select: { | ||
content: 'content', | ||
label: 'label', | ||
image: 'image', | ||
}, | ||
prepare: ({ content, label, image }) => ({ | ||
title: getBlockText(content), | ||
subtitle: label, | ||
media: image, | ||
}), | ||
}, | ||
}), | ||
], | ||
}), | ||
], | ||
preview: { | ||
select: { | ||
intro: 'intro', | ||
}, | ||
prepare: ({ intro }) => ({ | ||
title: getBlockText(intro), | ||
subtitle: 'Tabbed content', | ||
}), | ||
}, | ||
}) |
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,29 @@ | ||
'use client' | ||
|
||
import { tabbedContentStore } from './store' | ||
import TabbedContent from '.' | ||
import { cn } from '@/lib/utils' | ||
import type { ComponentProps } from 'react' | ||
|
||
export default function TabList({ | ||
tabs, | ||
}: ComponentProps<typeof TabbedContent>) { | ||
const { active, setActive } = tabbedContentStore() | ||
|
||
return ( | ||
<nav className="max-md:full-bleed flex overflow-x-auto border-b border-accent"> | ||
{tabs?.map((tab, key) => ( | ||
<button | ||
className={cn( | ||
'shrink-0 grow basis-[min(150px,80vw)] rounded-t p-2', | ||
key === active && 'action rounded-b-none', | ||
)} | ||
key={key} | ||
onClick={() => setActive(key)} | ||
> | ||
{tab.label} | ||
</button> | ||
))} | ||
</nav> | ||
) | ||
} |
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,13 @@ | ||
'use client' | ||
|
||
import { tabbedContentStore } from './store' | ||
import type { ComponentProps } from 'react' | ||
|
||
export default function Wrapper({ | ||
index, | ||
...props | ||
}: { index: number } & ComponentProps<'article'>) { | ||
const { active } = tabbedContentStore() | ||
|
||
return <article {...props} hidden={index !== active} /> | ||
} |
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,68 @@ | ||
import Pretitle from '@/ui/Pretitle' | ||
import { PortableText } from 'next-sanity' | ||
import TabList from './TabList' | ||
import Wrapper from './Wrapper' | ||
import CTAList from '@/ui/CTAList' | ||
import Img from '@/ui/Img' | ||
import { cn } from '@/lib/utils' | ||
|
||
export default function TabbedContent({ | ||
pretitle, | ||
intro, | ||
tabs, | ||
}: Partial<{ | ||
pretitle: string | ||
intro: any | ||
tabs: Partial<{ | ||
label: string | ||
pretitle: string | ||
content: any | ||
ctas: Sanity.CTA[] | ||
image: Sanity.Image & { | ||
onRight: boolean | ||
onBottom: boolean | ||
} | ||
}>[] | ||
}>) { | ||
return ( | ||
<section className="section space-y-8"> | ||
{(pretitle || intro) && ( | ||
<header className="richtext text-center"> | ||
<Pretitle>{pretitle}</Pretitle> | ||
<PortableText value={intro} /> | ||
</header> | ||
)} | ||
|
||
<TabList tabs={tabs} /> | ||
|
||
{tabs?.map((tab, index) => ( | ||
<Wrapper | ||
className="grid items-center gap-8 *:mx-auto *:max-w-lg md:grid-cols-2 md:gap-x-12" | ||
index={index} | ||
key={index} | ||
> | ||
<figure | ||
className={cn( | ||
'anim-fade-to-r', | ||
tab.image?.onRight && 'md:anim-fade-to-l md:order-last', | ||
tab.image?.onBottom && 'max-md:order-last', | ||
)} | ||
> | ||
<Img image={tab.image} /> | ||
</figure> | ||
|
||
<div | ||
className={cn( | ||
'richtext anim-fade-to-r w-full', | ||
!tab.image?.onRight && 'md:anim-fade-to-l', | ||
)} | ||
> | ||
<Pretitle>{tab.pretitle}</Pretitle> | ||
<PortableText value={tab.content} /> | ||
<CTAList ctas={tab.ctas} /> | ||
</div> | ||
</Wrapper> | ||
))} | ||
</section> | ||
) | ||
} |
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,9 @@ | ||
import { create } from 'zustand' | ||
|
||
export const tabbedContentStore = create<{ | ||
active: number | ||
setActive: (tab: number) => void | ||
}>((set) => ({ | ||
active: 0, | ||
setActive: (tab) => set({ active: tab }), | ||
})) |
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