Skip to content

Commit

Permalink
feat: Improved navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-crowell committed Jun 13, 2024
1 parent 48a888e commit 2ba4f35
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 27 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"author": "",
"license": "MIT",
"devDependencies": {
"@do-ob/core": "^1.0.0",
"@do-ob/eslint-config": "^2.3.0",
"@do-ob/ts-config": "^2.0.0",
"@do-ob/ui": "workspace:*",
Expand Down
20 changes: 19 additions & 1 deletion packages/ui/src/Navigation/Navigation.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Meta, StoryObj } from '@storybook/react';

import { Navigation } from './Navigation';
import { Link } from '../types';

const meta = {
component: Navigation,
Expand All @@ -13,15 +14,32 @@ export default meta;

type Story = StoryObj<typeof meta>;

const links: Link[] = [
{
title: 'Home',
url: '#',
},
{
title: 'About',
url: '#about',
},
{
title: 'Contact',
url: '#contact',
},
];

export const Standard: Story = {
args: {
title: 'Navigation',
links,
},
};

export const Island: Story = {
args: {
title: 'Navigation',
variant: 'island'
variant: 'island',
links,
},
};
7 changes: 6 additions & 1 deletion packages/ui/src/Navigation/Navigation.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ThemeColor } from '../types';
import type { Link, ThemeColor } from '../types';

import { NavigationStandard } from './NavigationStandard';
import { NavigationIsland } from './NavigationIsland';
Expand All @@ -13,6 +13,11 @@ export interface NavigationProps {
* The theme color of the navigation
*/
color?: ThemeColor;

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

export interface NavigationVariantProps extends NavigationProps {
Expand Down
15 changes: 7 additions & 8 deletions packages/ui/src/Navigation/NavigationIsland.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Navbar, NavbarContent } from '@nextui-org/react';
import { twColors, clsx } from '@do-ob/ui/utility';
import { twColors } from '@do-ob/ui/utility';
import { clsx } from '@do-ob/core';

import type { NavigationProps } from './Navigation';
import { NavigationPart_Brand } from './parts/NavigationPart_Brand';
import { NavigationPart_Links } from './parts/NavigationPart_Links';

export function NavigationIsland({
title,
color,
links,
}: NavigationProps) {

const [ colors ] = twColors(color);
Expand All @@ -16,13 +20,8 @@ export function NavigationIsland({
<NavigationPart_Brand title={title} />
</NavbarContent>
<NavbarContent justify="center">
<div className={clsx(color && colors, 'rounded-full px-8 py-3')}>
<div className="flex space-x-4">
<a href="#" className="text-base">Home</a>
<a href="#" className="text-base">About</a>
<a href="#" className="text-base">Services</a>
<a href="#" className="text-base">Contact</a>
</div>
<div className={clsx(color && colors, 'flex gap-1 rounded-full px-4 py-1')}>
<NavigationPart_Links links={links} />
</div>
</NavbarContent>
<NavbarContent justify="start">
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/Navigation/NavigationStandard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Navbar, NavbarContent } from '@nextui-org/react';
import { clsx, twColors } from '@do-ob/ui/utility';
import { twColors } from '@do-ob/ui/utility';
import { clsx } from '@do-ob/core';
import type { NavigationProps } from './Navigation';
import { NavigationPart_Brand } from './parts/NavigationPart_Brand';

Expand Down
33 changes: 33 additions & 0 deletions packages/ui/src/Navigation/parts/NavigationPart_Links.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { NavbarMenuItem, Link, Button } from '@nextui-org/react';
import { Link as LinkType } from '@do-ob/ui/types';

/**
* Navigation Brand properties
*/
export interface NavigationPart_LinksProps {
/**
* The branding title to display.
*/
links?: LinkType[];
}

/**
* Navigation Links component
*/
export function NavigationPart_Links({
links = [],
}: NavigationPart_LinksProps) {
return links.length ? links.map((link) => (
<NavbarMenuItem>
<Button as={Link} href={link.url} variant="light" className="text-inherit">
{link.title}
</Button>
</NavbarMenuItem>
)) : (
<NavbarMenuItem>
&nbsp;
</NavbarMenuItem>
);
}

export default NavigationPart_Links;
20 changes: 20 additions & 0 deletions packages/ui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,23 @@
* Theem colors.
*/
export type ThemeColor = 'background' | 'foreground' | 'default' | 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info';

/**
* A link to another page.
*/
export interface Link {
/**
* The URL of the link.
*/
url: string;

/**
* The text title of the link.
*/
title: string;

/**
* Nested links.
*/
links?: Link[];
}
16 changes: 0 additions & 16 deletions packages/ui/src/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,3 @@ export function twColors(color?: ThemeColor): [full: string, bg: string, text: s
return [ `bg-${color} [&>*]:text-${color}-foreground`, `bg-${color}`, `text-${color}-foreground` ];
}
}


/**
* Constructs class names conditionally.
*/
export function clsx(...args: unknown[]) {
let i=0, tmp, str='';
const len = args.length;
for (; i < len; i++) {
tmp = args[i];
if (typeof tmp === 'string') {
str += (str && ' ') + tmp;
}
}
return str;
}
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2ba4f35

Please sign in to comment.