Skip to content

Commit

Permalink
dev: Simplified navigation component with context
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-crowell committed Jun 16, 2024
1 parent ee5274c commit a66487d
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 395 deletions.
54 changes: 1 addition & 53 deletions packages/ui/src/components/Navigation/Navigation.tsx
Original file line number Diff line number Diff line change
@@ -1,61 +1,9 @@
import type { Link, ThemeColor, SocialLinks } from '@do-ob/ui/types';
import type { NavigationProps } from './data/NavigationContext';

import { NavigationStandard } from './NavigationStandard';
import { NavigationIsland } from './NavigationIsland';
import { NavigationExtended } from './NavigationExtended';

export interface NavigationProps {
/**
* The brand title to display
*/
title?: string;

/**
* The brand image to display
*/
logo?: string;

/**
* The theme color of the navigation
*/
color?: ThemeColor;

/**
* The links of the navigation
*/
links?: Link[];

/**
* Class name for the navigation
*/
className?: string;

/**
* The search form action URL
*/
search?: string;

/**
* Enable the dark mode toggle
*/
modeToggle?: boolean;

/**
* The social links of the navigation
*/
socials?: SocialLinks;

/**
* Class names to modify.
*/
classNames?: {
/**
* The logo image class name
*/
logo?: string;
}
}

export interface NavigationVariantProps extends NavigationProps {
/**
* The variant of the navigation
Expand Down
52 changes: 23 additions & 29 deletions packages/ui/src/components/Navigation/NavigationExtended.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,36 @@
import { Navbar, NavbarContent } from '@nextui-org/react';
import { twColors } from '@do-ob/ui/utility';
import { clsx, clmg } from '@do-ob/core';
import type { NavigationProps } from './Navigation';
import type { NavigationProps } from './data/NavigationContext';
import { NavigationPart_Brand } from './parts/NavigationPart_Brand';
import { NavigationPart_Links } from './parts/NavigationPart_Links';
import { NavigationPart_Actions } from './parts/NavigationPart_Actions';
import { NavigationProvider } from './data/NavigationProvider';

export function NavigationExtended({
title,
color,
links,
className,
search,
modeToggle,
socials,
}: NavigationProps) {

const [ colors ] = twColors(color);
export function NavigationExtended(props: NavigationProps) {

return (
<Navbar
className={clmg(clsx(color && colors, 'relative border-b-1 border-b-foreground-200/50', className))}
height="4rem"
>
<NavbarContent justify="start">
<NavigationPart_Brand title={title} />
</NavbarContent>
<NavigationProvider {...props}>
{({ color, colors, className }) => (
<Navbar
className={clmg(clsx(color && colors, 'relative border-b-1 border-b-foreground-200/50', className))}
height="4rem"
>
<NavbarContent justify="start">
<NavigationPart_Brand />
</NavbarContent>

<NavbarContent justify="start">
<NavigationPart_Links links={links} colors={colors} />
</NavbarContent>
<NavbarContent justify="start">
<NavigationPart_Links />
</NavbarContent>

<NavbarContent justify="end">
<div className="max-w-64">
<NavigationPart_Actions search={search} modeToggle={modeToggle} socials={socials} />
</div>
</NavbarContent>
<NavbarContent justify="end">
<div className="max-w-64">
<NavigationPart_Actions />
</div>
</NavbarContent>

</Navbar>
</Navbar>
)}
</NavigationProvider>
);
}
48 changes: 20 additions & 28 deletions packages/ui/src/components/Navigation/NavigationIsland.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,31 @@
import { Navbar, NavbarContent } from '@nextui-org/react';
import { twColors } from '@do-ob/ui/utility';
import { clsx, clmg } from '@do-ob/core';

import type { NavigationProps } from './Navigation';
import type { NavigationProps } from './data/NavigationContext';
import { NavigationProvider } from './data/NavigationProvider';
import { NavigationPart_Brand } from './parts/NavigationPart_Brand';
import { NavigationPart_Links } from './parts/NavigationPart_Links';
import { NavigationPart_Actions } from './parts/NavigationPart_Actions';

export function NavigationIsland({
title,
logo,
color,
links,
className,
search,
modeToggle,
socials,
classNames = {}
}: NavigationProps) {

const [ colors ] = twColors(color);
export function NavigationIsland(props: NavigationProps) {

return (
<Navbar className="items-center justify-center bg-transparent backdrop-blur-none backdrop-filter-none" height="5rem">
<NavbarContent justify="start" className="flex items-center">
<NavigationPart_Brand title={title} logo={logo} logoClassName={classNames.logo} />
</NavbarContent>
<NavbarContent justify="center">
<div className={clmg(clsx(color && colors, 'flex rounded-full border-1 border-foreground-200/50 px-4', className))}>
<NavigationPart_Links links={links} colors={colors} />
</div>
</NavbarContent>
<NavbarContent justify="end">
<NavigationPart_Actions search={search} modeToggle={modeToggle} socials={socials} />
</NavbarContent>
</Navbar>
<NavigationProvider {...props}>
{({ color, colors, className }) => (
<Navbar className="items-center justify-center bg-transparent backdrop-blur-none backdrop-filter-none" height="5rem">
<NavbarContent justify="start" className="flex items-center">
<NavigationPart_Brand />
</NavbarContent>
<NavbarContent justify="center">
<div className={clmg(clsx(color && colors, 'flex rounded-full border-1 border-foreground-200/50 px-4', className))}>
<NavigationPart_Links />
</div>
</NavbarContent>
<NavbarContent justify="end">
<NavigationPart_Actions />
</NavbarContent>
</Navbar>
)}
</NavigationProvider>
);
}
53 changes: 23 additions & 30 deletions packages/ui/src/components/Navigation/NavigationStandard.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,36 @@
import { Navbar, NavbarContent } from '@nextui-org/react';
import { twColors } from '@do-ob/ui/utility';
import { clsx, clmg } from '@do-ob/core';
import type { NavigationProps } from './Navigation';
import type { NavigationProps } from './data/NavigationContext';
import { NavigationProvider } from './data/NavigationProvider';
import { NavigationPart_Brand } from './parts/NavigationPart_Brand';
import { NavigationPart_Links } from './parts/NavigationPart_Links';
import { NavigationPart_Actions } from './parts/NavigationPart_Actions';

export function NavigationStandard({
title,
color,
links,
className,
search,
modeToggle,
socials
}: NavigationProps) {

const [ colors ] = twColors(color);

export function NavigationStandard(props: NavigationProps) {
return (
<Navbar
className={clmg(clsx(color && colors, 'border-b-1 border-b-foreground-200/50', className))}
height="4rem"
>
<NavbarContent justify="start">
<NavigationPart_Brand title={title} />
</NavbarContent>
<NavigationProvider {...props}>
{({ color, colors, className }) => (
<Navbar
className={clmg(clsx(color && colors, 'border-b-1 border-b-foreground-200/50', className))}
height="4rem"
>
<NavbarContent justify="start">
<NavigationPart_Brand />
</NavbarContent>

<NavbarContent justify="center">
<NavigationPart_Links links={links} colors={colors} />
</NavbarContent>
<NavbarContent justify="center">
<NavigationPart_Links />
</NavbarContent>

<NavbarContent justify="end">
<div className="max-w-64">
<NavigationPart_Actions search={search} modeToggle={modeToggle} socials={socials} />
</div>
</NavbarContent>
<NavbarContent justify="end">
<div className="max-w-64">
<NavigationPart_Actions />
</div>
</NavbarContent>

</Navbar>
</Navbar>
)}
</NavigationProvider>
);
}

Expand Down
81 changes: 81 additions & 0 deletions packages/ui/src/components/Navigation/data/NavigationContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
'use client';

import { Link, SocialLinks, ThemeColor } from '@do-ob/ui/types';
import { createContext } from 'react';

/**
* Context properties for the do-ob ui provider
*/
export interface NavigationProps {
/**
* The brand title to display
*/
title?: string;

/**
* The brand image to display
*/
logo?: string;

/**
* The theme color of the navigation
*/
color?: ThemeColor;

/**
* The links of the navigation
*/
links?: Link[];

/**
* Class name for the navigation
*/
className?: string;

/**
* The search form action URL
*/
search?: string;

/**
* Enable the dark mode toggle
*/
modeToggle?: boolean;

/**
* The social links of the navigation
*/
socials?: SocialLinks;

/**
* Class names to modify.
*/
classNames?: {
/**
* The logo image class name
*/
logo?: string;
}
}

/**
* The context interface
*/
export interface NavigationContextProps extends NavigationProps {
/**
* Compiled tailwind color classes
*/
colors: [full: string, bg: string, text: string];
}

/**
* Default properties for the do-ob ui context
*/
export const NavigationProps: NavigationContextProps = {
colors: [ '', '', '' ],
};

/**
* The do-ob user interface (ui) context
*/
export const NavigationContext = createContext<NavigationContextProps>(NavigationProps);
25 changes: 25 additions & 0 deletions packages/ui/src/components/Navigation/data/NavigationProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use client';

import { twColors } from '@do-ob/ui/utility';
import { NavigationContext, NavigationContextProps, NavigationProps } from './NavigationContext';

export interface NavigationProviderProps extends NavigationProps {
children: ((props: NavigationContextProps) => React.ReactNode )| React.ReactNode;
}

export function NavigationProvider({
children,
...props
}: NavigationProviderProps) {

const value = {
...props,
colors: twColors(props.color),
};

return (
<NavigationContext.Provider value={value}>
{typeof children === 'function' ? children(value) : children}
</NavigationContext.Provider>
);
}
Loading

0 comments on commit a66487d

Please sign in to comment.