Skip to content

Commit

Permalink
Feature/header (#60)
Browse files Browse the repository at this point in the history
Added the header component, still needs to be made more responsive

Related to #42
  • Loading branch information
j-ferber authored Apr 30, 2024
1 parent 12d07c8 commit f711ecf
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 4 deletions.
41 changes: 41 additions & 0 deletions content/pages/home.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,46 @@
---
title: Home
blocks:
- logo:
src: /inreach-logos/InReach_Logo_Color_RGB.svg
alt: InReach Logo
navBGColor: Green
navLinks:
- linkName: About
linkUrls:
- sectionUrl: Mission
pathURL: /
- sectionUrl: Our Team
pathURL: /example-gallery
- sectionUrl: Our Vetting Process
pathURL: /
- linkName: News
linkUrls:
- sectionUrl: In The News
pathURL: /
- sectionUrl: Awards
pathURL: /
- sectionUrl: Our Blog
pathURL: /
- linkName: Get Help
linkUrls:
- sectionUrl: Get Help For Myself
pathURL: /
- sectionUrl: Get Help For My Client
pathURL: /
- linkName: Take Action
linkUrls:
- sectionUrl: Donate
pathURL: /
- sectionUrl: Multiply Your Support
pathURL: /
- linkName: Contact
linkUrls:
- sectionUrl: Contact Us
pathURL: /
- sectionUrl: Donor Dashboard
pathURL: /
_template: header
- slides:
- backgroundImage: /home/Homepage.jpg
slideTitle: InReach
Expand Down Expand Up @@ -134,3 +174,4 @@ blocks:
disclaimer: 'InReach, Inc. 2023 • All rights reserved • InReach ❤️ Open Source'
_template: footer
---

7 changes: 7 additions & 0 deletions src/components/RenderBlocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CarouselContainer } from './blocks/Carousel'
import { FooterContainer } from './blocks/Footer'
import { LookingForContainer } from './blocks/LookingFor'
import { TitleImageGrid } from './blocks/layout/TitleImageGrid'
import { Header } from './blocks/layout/Header'

export const Blocks = (props: Omit<Page, 'id' | '_sys' | '_values'>) => {
return (
Expand Down Expand Up @@ -55,6 +56,12 @@ export const Blocks = (props: Omit<Page, 'id' | '_sys' | '_values'>) => {
<TitleImageGrid data={block} />
</div>
)
case 'PageBlocksHeader':
return (
<div key={i + block.__typename} className='w-full'>
<Header data={block} />
</div>
)
}
})
: null}
Expand Down
4 changes: 2 additions & 2 deletions src/components/blocks/NewsSupporters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { PageBlocksNewsSupporters, PageBlocksNewsSupportersCompanies } from '~ti

export const NewsSupporters = ({ data }: { data: PageBlocksNewsSupporters }) => {
return (
<Container fluid className='max-w-7xl'>
<Container fluid className='max-w-7xl' py={32}>
<Stack justify='center' align='center' gap={0}>
{data.title && (
<div className='prose text-center prose-stone prose-headings:m-0 prose-p:m-0 p-4'>
<div className='prose text-center prose-stone prose-headings:m-0 prose-p:m-0 mb-4'>
<TinaMarkdown content={data.title} />
</div>
)}
Expand Down
148 changes: 148 additions & 0 deletions src/components/blocks/layout/Header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import { Menu, Burger, Group } from '@mantine/core'
import Image from 'next/image'
import React from 'react'
import { Template } from 'tinacms'
import {
PageBlocksHeader,
PageBlocksHeaderNavLinks,
PageBlocksHeaderNavLinksLinkUrls,
} from '~tina/__generated__/types'
import { cn } from '../../../lib/utils'
import { ColorSelector } from '../../../components/fields/ColorSelector/ColorSelector'
import { inputClasses } from '../../../components/fields/ColorSelector/colors'
import { useDisclosure } from '@mantine/hooks'

export const Header = ({ data }: { data: PageBlocksHeader }) => {

const items = data.navLinks ?
data.navLinks.map((item, i) => {
return (
<Menu key={item?.linkName} trigger='hover' withinPortal>
{item?.linkName && (
<Menu.Target>
<p className='font-bold'>{item?.linkName}</p>
</Menu.Target>
)}
<Menu.Dropdown>
{item &&
item.linkUrls &&
item.linkUrls.map((link, i) => {
if (link && link.sectionUrl && link.pathURL)
return (
<Menu.Item key={link.sectionUrl}>
<a href={`${link.pathURL}`}>{link.sectionUrl}</a>
</Menu.Item>
)
})}
</Menu.Dropdown>
</Menu>
)
})
:
null

const [opened, { toggle }] = useDisclosure(false)

return (
<header
className={cn(
'w-full h-20 flex justify-center items-center',
data.navBGColor ? inputClasses[data.navBGColor] : 'bg-white'
)}
>
<div className='flex max-w-7xl justify-between items-center w-full p-4'>
{data.logo && data.logo.src && data.logo.alt && (
<Image src={data.logo?.src} alt={data.logo.alt} width={200} height={60} />
)}
{data.navLinks && (
<>
<Group className='md:w-1/2 flex justify-between' visibleFrom='sm'>
{items}
</Group>
<Burger opened={opened} onClick={toggle} size="sm" hiddenFrom="sm" />
</>
)}
</div>
</header>
)
}

export const headerTemplate: Template = {
name: 'header',
label: 'Header',
fields: [
{
name: 'logo',
type: 'object',
label: 'Logo',
fields: [
{
name: 'src',
label: 'Logo Source',
type: 'image',
},
{
name: 'alt',
label: 'Logo Alt',
type: 'string',
},
],
},
{
name: 'navBGColor',
label: 'Background Color',
type: 'string',
ui: {
component: ColorSelector,
},
},
{
name: 'navLinks',
label: 'Links',
list: true,
type: 'object',
ui: {
itemProps: (item: PageBlocksHeaderNavLinks) => {
return {
label: item.linkName ? item.linkName : 'New Link',
}
},
},
fields: [
{
name: 'linkName',
label: 'Link Name',
description: 'The name of the link shown in the navbar',
type: 'string',
},
{
name: 'linkUrls',
label: 'Link URLs',
type: 'object',
list: true,
ui: {
itemProps: (item: PageBlocksHeaderNavLinksLinkUrls) => {
return {
label: item.sectionUrl ? item.sectionUrl : 'New Link',
}
},
},
fields: [
{
name: 'sectionUrl',
label: 'Sub URLs',
type: 'string',
description: 'This is the name of the URL to be shown in the hover dropdown',
},
{
name: 'pathURL',
label: 'Path URL',
type: 'string',
description: 'This is the path URL to the page',
},
],
},
],
},
],
}
2 changes: 1 addition & 1 deletion src/components/blocks/layout/TitleImageGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const TitleImageGrid = ({ data }: { data: PageBlocksTitleImageGrid }) =>
{data.titleImageGridHeader && (
<div
className={cn(
'w-full prose prose-headings:m-0 prose-p:m-0 max-w-none text-center mb-4',
'w-full prose prose-headings:m-0 prose-p:m-0 max-w-none text-center mb-4 pt-4',
data.titleImageGridHeader.titleTextColor &&
inputProseClasses[data.titleImageGridHeader.titleTextColor]
)}
Expand Down
2 changes: 2 additions & 0 deletions tina/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { carouselTemplate } from '../src/components/blocks/Carousel'
import { footerTemplate } from '../src/components/blocks/Footer'
import { lookingForTemplate } from '../src/components/blocks/LookingFor'
import { titleImageGridTemplate } from '../src/components/blocks/layout/TitleImageGrid'
import { headerTemplate } from '../src/components/blocks/layout/Header'

const isLocal = process.env.TINA_PUBLIC_IS_LOCAL === 'true'
// Your hosting provider likely exposes this as an environment variable
Expand Down Expand Up @@ -82,6 +83,7 @@ export default defineConfig({
footerTemplate,
lookingForTemplate,
titleImageGridTemplate,
headerTemplate,
],
},
],
Expand Down
2 changes: 1 addition & 1 deletion tina/tina-lock.json

Large diffs are not rendered by default.

1 comment on commit f711ecf

@vercel
Copy link

@vercel vercel bot commented on f711ecf Apr 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.