Skip to content
This repository has been archived by the owner on Jan 7, 2025. It is now read-only.

Commit

Permalink
Navbar, heading and menu updates
Browse files Browse the repository at this point in the history
  • Loading branch information
C committed Jan 30, 2023
1 parent d3fa482 commit fc2dfee
Show file tree
Hide file tree
Showing 8 changed files with 887 additions and 494 deletions.
1,074 changes: 649 additions & 425 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@solana/web3.js": "^1.73.0",
"@tailwindcss/typography": "^0.5.9",
"daisyui": "^1.24.3",
"date-fns": "^2.29.3",
"immer": "^9.0.12",
"next": "^13.1.5",
"next-compose-plugins": "^2.2.1",
Expand Down
39 changes: 23 additions & 16 deletions src/components/AppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dynamic from 'next/dynamic';
import React, { useState } from "react";
import { useAutoConnect } from '../contexts/AutoConnectProvider';
import NetworkSwitcher from './NetworkSwitcher';
import NavElement from './nav-element';

const WalletMultiButtonDynamic = dynamic(
async () => (await import('@solana/wallet-adapter-react-ui')).WalletMultiButton,
Expand All @@ -12,7 +13,7 @@ const WalletMultiButtonDynamic = dynamic(

export const AppBar: React.FC = () => {
const { autoConnect, setAutoConnect } = useAutoConnect();
const [isOpen, setIsOpen] = useState(false);
const [isNavOpen, setIsNavOpen] = useState(false);
return (
<div>
{/* NavBar / Header */}
Expand Down Expand Up @@ -50,28 +51,34 @@ export const AppBar: React.FC = () => {
{/* Nav Links */}
{/* Wallet & Settings */}
<div className="navbar-end">
<div className="hidden md:inline-flex align-items-center">
<Link href="/">
<span className="text-lg font-medium sm:text-xl mr-6">Home</span>
</Link>
<Link href="/basics">
<span className="text-lg font-medium sm:text-xl mr-4">Basics</span>
</Link>
<WalletMultiButtonDynamic className="btn-ghost btn-sm rounded-btn text-lg mr-6 " />
<div className="hidden md:inline-flex align-items-center justify-items gap-6">
<NavElement
label="Home"
href="/"
navigationStarts={() => setIsNavOpen(false)}
/>
<NavElement
label="Basics"
href="/basics"
navigationStarts={() => setIsNavOpen(false)}
/>


<WalletMultiButtonDynamic className="btn-ghost btn-sm rounded-btn text-lg mr-6 " />
</div>
<label
htmlFor="my-drawer"
className="btn btn-ghost items-center justify-between md:hidden"
onClick={() => setIsOpen(!isOpen)}>
className="btn-gh items-center justify-between md:hidden mr-5"
onClick={() => setIsNavOpen(!isNavOpen)}>
<div className="HAMBURGER-ICON space-y-2.5 ml-5">
<div className={`h-0.5 w-8 bg-purple-600 ${isOpen ? 'hidden' : ''}`} />
<div className={`h-0.5 w-8 bg-purple-600 ${isOpen ? 'hidden' : ''}`} />
<div className={`h-0.5 w-8 bg-purple-600 ${isOpen ? 'hidden' : ''}`} />
<div className={`h-0.5 w-8 bg-purple-600 ${isNavOpen ? 'hidden' : ''}`} />
<div className={`h-0.5 w-8 bg-purple-600 ${isNavOpen ? 'hidden' : ''}`} />
<div className={`h-0.5 w-8 bg-purple-600 ${isNavOpen ? 'hidden' : ''}`} />
</div>
<div className={`absolute block h-0.5 w-8 animate-pulse bg-purple-600 ${isOpen ? "" : "hidden"}`}
<div className={`absolute block h-0.5 w-8 animate-pulse bg-purple-600 ${isNavOpen ? "" : "hidden"}`}
style={{ transform: "rotate(45deg)" }}>
</div>
<div className={`absolute block h-0.5 w-8 animate-pulse bg-purple-600 ${isOpen ? "" : "hidden"}`}
<div className={`absolute block h-0.5 w-8 animate-pulse bg-purple-600 ${isNavOpen ? "" : "hidden"}`}
style={{ transform: "rotate(135deg)" }}>
</div>
</label>
Expand Down
26 changes: 16 additions & 10 deletions src/components/ContentContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FC } from 'react';
import Link from "next/link";

import Text from './Text';
import NavElement from './nav-element';
interface Props {
children: React.ReactNode;
}
Expand All @@ -17,20 +18,25 @@ export const ContentContainer: React.FC<Props> = ({ children }) => {

{/* SideBar / Drawer */}
<div className="drawer-side">
<label htmlFor="my-drawer" className="drawer-overlay"></label>
<ul className="p-4 overflow-y-auto menu w-80 bg-base-100">
<label htmlFor="my-drawer" className="drawer-overlay gap-6"></label>

<ul className="p-4 overflow-y-auto menu w-80 bg-base-100 gap-10 sm:flex">
<li>
<h1>Menu</h1>
<Text variant="heading" className='font-extrabold tracking-tighter text-center'>Menu</Text>
</li>
<li>
<Link href="/">
<span>Home</span>
</Link>

<NavElement
label="Home"
href="/"
/>

</li>
<li>
<Link href="/basics">
<span>Basics</span>
</Link>
<NavElement
label="Basics"
href="/basics"
/>
</li>
</ul>
</div>
Expand Down
58 changes: 58 additions & 0 deletions src/components/Text/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import Link from 'next/link';
import React from 'react';
import { cn } from 'utils';

/**
* Properties for a card component.
*/
type TextProps = {
variant:
| 'big-heading'
| 'heading'
| 'sub-heading'
| 'nav-heading'
| 'nav'
| 'input'
| 'label';
className?: string;
href?: string;
children?: React.ReactNode;
id?: string;
};

/**
* Pre-defined styling, according to agreed-upon design-system.
*/
const variants = {
heading: 'text-3xl font-medium',
'sub-heading': 'text-2xl font-medium',
'nav-heading': 'text-lg font-medium sm:text-xl',
nav: 'font-medium',
paragraph: 'text-lg',
'sub-paragraph': 'text-base font-medium text-inherit',
input: 'text-sm uppercase tracking-wide',
label: 'text-xs uppercase tracking-wide',
};

/**
* Definition of a card component,the main purpose of
* which is to neatly display information. Can be both
* interactive and static.
*
* @param variant Variations relating to pre-defined styling of the element.
* @param className Custom classes to be applied to the element.
* @param children Child elements to be rendered within the component.
*/
const Text = ({ variant, className, href, children }: TextProps) => (
<p className={cn(className, variants[variant])}>
{href ? (
<Link href={href} className="min-w-0 overflow-hidden text-ellipsis whitespace-nowrap">
{children}
</Link>
) : (
children
)}
</p>
);

export default Text;
63 changes: 63 additions & 0 deletions src/components/nav-element/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* tslint:disable:no-empty */
import Link from 'next/link';
import Text from '../Text';
import { cn } from '../../utils';
import { useRouter } from 'next/router';
import { useEffect, useRef } from 'react';

type NavElementProps = {
label: string;
href: string;
as?: string;
scroll?: boolean;
chipLabel?: string;
disabled?: boolean;
navigationStarts?: () => void;
};

const NavElement = ({
label,
href,
as,
scroll,
disabled,
navigationStarts = () => {},
}: NavElementProps) => {
const router = useRouter();
const isActive = href === router.asPath || (as && as === router.asPath);
const divRef = useRef<HTMLDivElement | null>(null);

useEffect(() => {
if (divRef.current) {
divRef.current.className = cn(
'h-0.5 w-1/4 transition-all duration-300 ease-out',
isActive
? '!w-full bg-gradient-to-l from-fuchsia-500 to-pink-500 '
: 'group-hover:w-1/2 group-hover:bg-fuchsia-500',
);
}
}, [isActive]);

return (
<Link
href={href}
as={as}
scroll={scroll}
passHref
className={cn(
'group flex h-full flex-col items-center justify-between',
disabled &&
'pointer-events-none cursor-not-allowed opacity-50',
)}
onClick={() => navigationStarts()}
>
<div className="flex flex-row items-center gap-3">
<Text variant="nav-heading"> {label} </Text>
</div>
<div ref={divRef} />
</Link>
);
};

export default NavElement;

34 changes: 34 additions & 0 deletions src/utils/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { format } from 'date-fns';

// Concatenates classes into a single className string
const cn = (...args: string[]) => args.join(' ');

const formatDate = (date: string) => format(new Date(date), 'MM/dd/yyyy h:mm:ss');

/**
* Formats number as currency string.
*
* @param number Number to format.
*/
const numberToCurrencyString = (number: number) =>
number.toLocaleString('en-US');

/**
* Returns a number whose value is limited to the given range.
*
* Example: limit the output of this computation to between 0 and 255
* (x * 255).clamp(0, 255)
*
* @param {Number} min The lower boundary of the output range
* @param {Number} max The upper boundary of the output range
* @returns A number in the range [min, max]
* @type Number
*/
const clamp = (current, min, max) => Math.min(Math.max(current, min), max);

export {
cn,
formatDate,
numberToCurrencyString,
clamp,
};
Loading

0 comments on commit fc2dfee

Please sign in to comment.