Skip to content

Commit

Permalink
feat: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Luqmaan Essop committed May 8, 2024
1 parent bee3b2c commit 7b58f2e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Meta } from '@storybook/react';
import React from 'react';

import { Default as FrameStory } from '../Routes/Frame.stories';
import BreadCrumbs from './Breadcrumbs';
import { BreadCrumbs } from './Breadcrumbs';

export default {
component: BreadCrumbs,
Expand Down
9 changes: 3 additions & 6 deletions packages/ui/src/components/Molecules/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@ import React from 'react';
import { isTruthy } from '../../utils/isTruthy';
import { useBreadcrumbs } from '../Routes/Menu';

export default function BreadCrumbs({ className }: { className?: string }) {
export function BreadCrumbs({ className }: { className?: string }) {
const breadcrumbs = useBreadcrumbs();

if (!breadcrumbs.length) {
return null;
}

return (
<nav
className={clsx('pt-5 max-w-screen-xl mx-auto', className)}
aria-label="Breadcrumb"
>
<ol className={'rounded-lg inline-block p-2.5'}>
<nav className={clsx('pt-5', className)} aria-label="Breadcrumb">
<ol className={'rounded-lg inline-block py-2.5'}>
{breadcrumbs?.filter(isTruthy).map(({ title, target, id }, index) => (
<li className="inline-flex items-center" key={id}>
{index > 0 ? (
Expand Down
10 changes: 9 additions & 1 deletion packages/ui/src/components/Organisms/PageDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react';

import { isTruthy } from '../../utils/isTruthy';
import { UnreachableCaseError } from '../../utils/unreachable-case-error';
import { BreadCrumbs } from '../Molecules/Breadcrumbs';
import { PageTransition } from '../Molecules/PageTransition';
import { BlockCta } from './PageContent/BlockCta';
import { BlockForm } from './PageContent/BlockForm';
Expand All @@ -15,7 +16,14 @@ export function PageDisplay(page: PageFragment) {
return (
<PageTransition>
<div>
{page.hero ? <PageHero {...page.hero} /> : null}
{page.hero ? (
<>
<PageHero {...page.hero} />
<BreadCrumbs className="mx-auto max-w-3xl" />
</>
) : (
<BreadCrumbs />
)}
<div className="bg-white pt-5 pb-12 lg:px-8">
<div className="mx-auto max-w-3xl text-base leading-7 text-gray-700">
{page?.content?.filter(isTruthy).map((block, index) => {
Expand Down
4 changes: 3 additions & 1 deletion packages/ui/src/components/Routes/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function useCurrentPath() {

export function useMenuItem(path: string, menuName: MenuNameType) {
const menus = useMenus();

return (
menus &&
menus[menuName]?.items.find((menuItem) => menuItem?.target === path)
Expand Down Expand Up @@ -61,7 +62,8 @@ export function useMenuAncestors(path: string, menuName: MenuNameType) {

// Set current page breadcrumb
if (typeof processingMenuItem !== 'undefined') {
ancestors.push(processingMenuItem);
// If not home path then only push into breadcrumbs array
processingMenuItem.target !== '/' && ancestors.push(processingMenuItem);
}

while (
Expand Down
25 changes: 19 additions & 6 deletions packages/ui/src/components/Routes/Page.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ export const Default = {
},
],
path: '/test' as Url,
hero: {
headline: 'Page Hero Headline',
lead: 'A longer lead text that even might break into multiple lines.',
ctaUrl: '/test' as Url,
ctaText: 'Call to action',
},
content: [
{
__typename: 'BlockMarkup',
Expand All @@ -62,6 +56,25 @@ export const Default = {
] as Exclude<ViewPageQuery['page'], undefined>['content'],
},
},
parameters: {
location: new URL('local:/drupal'),
},
} satisfies StoryObj<ViewPageQuery>;

export const Hero = {
...Default,
args: {
...Default.args,
page: {
...Default.args.page,
hero: {
headline: 'Page Hero Headline',
lead: 'A longer lead text that even might break into multiple lines.',
ctaUrl: '/test' as Url,
ctaText: 'Call to action',
},
},
},
} satisfies StoryObj<ViewPageQuery>;

export const FullHero = {
Expand Down

0 comments on commit 7b58f2e

Please sign in to comment.