Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement sitewide notification #43

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion components/Layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ import { PrimaryNavigation } from '@/components/PrimaryNavigation'
import { Prose } from '@/components/Prose'
import { SiteFooter } from '@/components/SiteFooter'
import { SiteHeader } from '@/components/SiteHeader'
import { SitewideNotice } from '@/components/SitewideNotice'
import { collectHeadings } from '@/lib/utils'

Layout.fragment = gql`
fragment LayoutFragment on RootQuery {
...SitewideNoticeFragment
...PrimaryNavigationFragment
...DocsSidebarNavigationFragment
...FooterNavigationFragment
}
${SitewideNotice.fragment}
${PrimaryNavigation.fragment}
${DocsSidebarNavigation.fragment}
${FooterNavigation.fragment}
Expand Down Expand Up @@ -124,7 +127,8 @@ export function Layout({ data, children, toc, title }) {

return (
<>
<SiteHeader navigation={primaryNavigation} />
<SitewideNotice displayNotice={data.sitewideNotice.sitewideNoticeFields.displayNotice} message={data.sitewideNotice.sitewideNoticeFields.message} />
<SiteHeader navigation={primaryNavigation} isNoticeVisible={data.sitewideNotice.sitewideNoticeFields.displayNotice} />

<main className='content'>
<div className="relative mx-auto flex max-w-8xl justify-center sm:px-2 lg:px-8 xl:px-12">
Expand Down
6 changes: 5 additions & 1 deletion components/LayoutArchive.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import { DocsSidebarNavigation } from '@/components/DocsSidebarNavigation'
import { Prose } from '@/components/Prose'
import { SiteFooter } from '@/components/SiteFooter'
import { SiteHeader } from '@/components/SiteHeader'
import { SitewideNotice } from '@/components/SitewideNotice'

LayoutArchive.fragment = gql`
fragment LayoutArchiveFragment on RootQuery {
...SitewideNoticeFragment
...PrimaryNavigationFragment
...DocsSidebarNavigationFragment
...FooterNavigationFragment
}
${SitewideNotice.fragment}
${PrimaryNavigation.fragment}
${DocsSidebarNavigation.fragment}
${FooterNavigation.fragment}
Expand Down Expand Up @@ -53,7 +56,8 @@ export function LayoutArchive({ data, children, title }) {

return (
<>
<SiteHeader navigation={primaryNavigation} />
<SitewideNotice displayNotice={data.sitewideNotice.sitewideNoticeFields.displayNotice} message={data.sitewideNotice.sitewideNoticeFields.message} />
<SiteHeader navigation={primaryNavigation} isNoticeVisible={data.sitewideNotice.sitewideNoticeFields.displayNotice} />
<main className='content'>
<div className="relative mx-auto flex max-w-8xl justify-center sm:px-2 lg:px-8 xl:px-12">
<div className="hidden lg:relative lg:block lg:flex-none">
Expand Down
6 changes: 5 additions & 1 deletion components/LayoutFrontPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import { SiteFooter } from './SiteFooter'

import { PrimaryNavigation } from '@/components/PrimaryNavigation'
import { SiteHeader } from '@/components/SiteHeader'
import { SitewideNotice } from '@/components/SitewideNotice'


LayoutFrontPage.fragment = gql`
fragment LayoutFrontPageFragment on RootQuery {
...SitewideNoticeFragment
...PrimaryNavigationFragment
...FooterNavigationFragment
}
${SitewideNotice.fragment}
${PrimaryNavigation.fragment}
${FooterNavigation.fragment}
`
Expand All @@ -36,7 +39,8 @@ export function LayoutFrontPage({ data, children }) {
: []
return (
<>
<SiteHeader navigation={primaryNavigation} data={data} />
<SitewideNotice displayNotice={data.sitewideNotice.sitewideNoticeFields.displayNotice} message={data.sitewideNotice.sitewideNoticeFields.message} />
<SiteHeader navigation={primaryNavigation} data={data} isNoticeVisible={data.sitewideNotice.sitewideNoticeFields.displayNotice} />
<main className='content'>
{children}
</main>
Expand Down
8 changes: 6 additions & 2 deletions components/SiteHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import { PrimaryNavigation } from '@/components/PrimaryNavigation'
import { Search } from '@/components/Search'
import { ModeToggle } from '@/components/ThemeSelector'

export function SiteHeader({ navigation }) {
export function SiteHeader({ navigation, isNoticeVisible = false }) {
let [isScrolled, setIsScrolled] = useState(false)

const headerTopPosition = isNoticeVisible ? 'top-12' : 'top-0';

useEffect(() => {
function onScroll() {
setIsScrolled(window.scrollY > 0)
Expand All @@ -27,7 +29,9 @@ export function SiteHeader({ navigation }) {
return (
<header
className={clsx(
'sticky top-0 z-50 flex flex-wrap items-center justify-between bg-white px-4 py-5 shadow-md shadow-slate-900/5 transition duration-500 dark:shadow-none sm:px-6 lg:px-8',
'sticky',
headerTopPosition,
'z-40 flex flex-wrap items-center justify-between bg-white px-4 py-5 shadow-md shadow-slate-900/5 transition duration-500 dark:shadow-none sm:px-6 lg:px-8',
isScrolled
? 'dark:bg-slate-900/95 dark:backdrop-blur dark:[@supports(backdrop-filter:blur(0))]:bg-slate-900/75'
: 'dark:bg-transparent',
Expand Down
22 changes: 22 additions & 0 deletions components/SitewideNotice.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { gql } from '@apollo/client'

SitewideNotice.fragment = gql`
fragment SitewideNoticeFragment on RootQuery {
sitewideNotice {
sitewideNoticeFields {
displayNotice
message
}
}
}
`

export function SitewideNotice({ displayNotice = false, message = '' }) {
if (displayNotice) {
return (
<div className="fixed inset-x-0 top-0 z-50 inline h-12 bg-sky-100 p-3 text-sky-900 dark:bg-sky-800 dark:text-sky-200">
<p className="text-center text-sm font-medium">{message}</p>
</div>
)
}
}
7 changes: 3 additions & 4 deletions wp-blocks/AcfFieldTypeSettingsBlock.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { gql } from '@apollo/client';
import clsx from 'clsx'
import React, { useState } from 'react';

import { Button } from "@/components/ui/button";
Expand All @@ -8,7 +7,7 @@ import { Card, CardFooter, CardHeader } from "@/components/ui/card";
const AccordionItem = ({ title, content, isOpen, onClick }) => {
return (
<>
<Button onClick={onClick} variant="primary" className="py-2 w-full text-left flex justify-between items-center">
<Button onClick={onClick} variant="primary" className="flex w-full items-center justify-between py-2 text-left">
{title}
<svg
xmlns="http://www.w3.org/2000/svg"
Expand All @@ -22,7 +21,7 @@ const AccordionItem = ({ title, content, isOpen, onClick }) => {
</svg>
</Button>
{isOpen && (
<div className="dark:bg-dark-muted bg-muted px-4 py-4">
<div className="dark:bg-dark-muted bg-muted p-4">
{content}
</div>
)}
Expand Down Expand Up @@ -75,7 +74,7 @@ export function AcfFieldTypeSettingsBlock({ fieldTypeSettingsBlockFields }) {
})}
</CardHeader>
<CardFooter>
<div className="flex justify-center items-center space-x-4 w-full">
<div className="flex w-full items-center justify-center space-x-4">
<Button variant="ghost" onClick={toggleAll} className="w-full">
{openItems.length === fieldTypeSettings.nodes.length ? 'Collapse All' : 'Expand All'}
</Button>
Expand Down