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

chore: improve dropdowns #626

Merged
merged 27 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b693fb4
chore: add shadcn cli
Apr 5, 2024
739c4b1
chore: update network dropdown to shadcn-ui
Apr 12, 2024
db2ca4a
chore: add network logo to dropdown
Apr 15, 2024
c95f858
chore: add padding to network dropdown
Apr 15, 2024
02b7fd4
chore: update method dropdown to shadcn-ui
Apr 15, 2024
da1860d
chore: add logo to sepolia & polygon mumbai
Apr 15, 2024
4d80c96
chore: remove back button from settings page
Apr 15, 2024
88147e6
chore: update pnpm-lock.yaml
Apr 15, 2024
6e81aeb
chore: add changeset
Apr 16, 2024
22c39d9
chore: update changeset
pseudobun Apr 18, 2024
d6f7679
chore: resolve conflicts
pseudobun Apr 18, 2024
4fa6840
chore: resolve conflicts
pseudobun Apr 18, 2024
9da43b5
chore: resolve conflicts
pseudobun Apr 18, 2024
b4d8478
chore: merge origin/develop
pseudobun Apr 18, 2024
f177d33
chore: resolve pnpm lock
pseudobun Apr 18, 2024
4515113
chore: add gap between dropdowns
Apr 19, 2024
a1c5a16
chore: change network logos
Apr 19, 2024
b2c0081
chore: add testnet switch button
Apr 21, 2024
0f2713e
chore: remove unused imports
Apr 22, 2024
01ef3ee
chore: add dark mode network backgrounds
Apr 22, 2024
8d18060
chore: add amoy testnet network
Apr 22, 2024
7662976
Merge branch 'develop' into chore/improve-dropdowns
SinanovicEdis Apr 22, 2024
746692f
chore: bump react query version
pseudobun Apr 23, 2024
72b4cfe
chore: add sync testnet switch state
Apr 24, 2024
7d31850
chore: add hover and refactor metod dropdown layout
Apr 24, 2024
43fa935
chore: change testnet switch button color
Apr 24, 2024
c24dc13
chore: move toggle theme button to address popover
Apr 24, 2024
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
5 changes: 5 additions & 0 deletions .changeset/slow-cats-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blockchain-lab-um/dapp": patch
---

Improves dropdowns.
17 changes: 17 additions & 0 deletions packages/dapp/components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "default",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "tailwind.config.js",
"css": "src/styles/globals.css",
"baseColor": "neutral",
"cssVariables": false,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils"
}
}
10 changes: 9 additions & 1 deletion packages/dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@
"@headlessui/react": "^1.7.18",
"@heroicons/react": "^2.1.1",
"@nextui-org/react": "^2.2.10",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-toast": "^1.1.5",
"@react-oauth/google": "^0.12.1",
"@supabase/supabase-js": "^2.39.7",
"@tanstack/react-query": "^5.28.4",
"@tanstack/react-query": "^5.32.0",
"@tanstack/react-table": "^8.13.2",
"@types/dompurify": "^3.0.5",
"@types/js-cookie": "^3.0.6",
Expand All @@ -46,6 +50,7 @@
"@veramo/utils": "6.0.0",
"@vercel/analytics": "^1.2.2",
"@vercel/og": "^0.6.2",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"date-fns": "^3.3.1",
"did-jwt-vc": "^3.2.13",
Expand All @@ -63,6 +68,7 @@
"js-cookie": "^3.0.5",
"jsdom": "^24.0.0",
"jsonwebtoken": "^9.0.2",
"lucide-react": "^0.367.0",
"luxon": "^3.4.4",
"marked": "^12.0.1",
"next": "14.1.3",
Expand All @@ -77,7 +83,9 @@
"sharp": "^0.33.2",
"siwe": "^2.1.4",
"swr": "^2.2.5",
"tailwind-merge": "^2.2.2",
"tailwind-scrollbar": "^3.1.0",
"tailwindcss-animate": "^1.0.7",
"viem": "^2.9.23",
"wagmi": "^2.5.20",
"zustand": "^4.5.2"
Expand Down
4 changes: 4 additions & 0 deletions packages/dapp/public/images/ethereum_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/dapp/public/images/polygon_matic_logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 14 additions & 8 deletions packages/dapp/src/components/AddressPopover/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Image from 'next/image';
import { mainnet } from 'viem/chains';
import { normalize } from 'viem/ens';
import { useAccount, useEnsAvatar, useEnsName } from 'wagmi';
import ToggleTheme from '@/components/ToggleTheme';

import { copyToClipboard } from '@/utils/string';
import { TextSkeleton } from '../Skeletons/TextSkeleton';
Expand Down Expand Up @@ -119,14 +120,19 @@ const AddressPopover = ({ did, disconnect }: AddressPopoverProps) => {
</button>
</div>
</div>
<div className="mt-2 flex justify-start">
<button
type="button"
onClick={disconnect}
className="animated-transition mt-auto text-xs font-semibold text-red-500 hover:text-red-700 dark:text-red-300 hover:dark:text-red-500"
>
{t('address.disconnect')}
</button>
<div className="mt-2 flex justify-between items-center">
<div>
<button
type="button"
onClick={disconnect}
className="animated-transition mt-auto text-xs font-semibold text-red-500 hover:text-red-700 dark:text-red-300 hover:dark:text-red-500"
>
{t('address.disconnect')}
</button>
</div>
<div>
<ToggleTheme />
</div>
</div>
</div>
</div>
Expand Down
14 changes: 9 additions & 5 deletions packages/dapp/src/components/AppNavbar/NavConnection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useAccount, useChainId, useDisconnect, useSwitchChain } from 'wagmi';

import AddressPopover from '@/components/AddressPopover';
import ConnectButton from '@/components/ConnectButton';
import DropdownMenu from '@/components/DropdownMenu';

import MethodDropdownMenu from '@/components/MethodDropdownMenu';
import { useMascaStore } from '@/stores';
import {
Expand All @@ -16,6 +16,8 @@ import {
getAvailableNetworksList,
} from '@/utils/networks';

import NetworkDropDownMenu from '@/components/NetworkDropDownMenu';

export const NavConnection = () => {
const { switchChain } = useSwitchChain();
const t = useTranslations('NavConnection');
Expand All @@ -39,7 +41,7 @@ export const NavConnection = () => {
(NETWORKS_BY_DID[currMethod].includes(stringified) ||
NETWORKS_BY_DID[currMethod].includes('*'))
) {
return network;
return network.name;
}
return t('unsupported-network');
};
Expand All @@ -57,7 +59,9 @@ export const NavConnection = () => {
}, [chainId, currMethod]);

const setNetwork = async (network: string) => {
const key = Object.keys(NETWORKS).find((val) => NETWORKS[val] === network);
const key = Object.keys(NETWORKS).find(
(val) => NETWORKS[val].name === network
);
if (key) {
switchChain(
{ chainId: Number(key) },
Expand All @@ -73,14 +77,14 @@ export const NavConnection = () => {
};

return isConnected ? (
<div className="flex items-center justify-center">
<div className="flex items-center justify-center gap-2">
{(currMethod === 'did:ethr' ||
currMethod === 'did:pkh' ||
currMethod === 'did:polygonid' ||
currMethod === 'did:ens' ||
currMethod === 'did:iden3') && (
<div className="hidden md:block">
<DropdownMenu
<NetworkDropDownMenu
size="method"
rounded="full"
shadow="none"
Expand Down
2 changes: 0 additions & 2 deletions packages/dapp/src/components/AppNavbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { useAccount } from 'wagmi';

import MascaLogo from '@/components/MascaLogo';
import MenuPopover from '@/components/MenuPopover';
import ToggleTheme from '@/components/ToggleTheme';
import { NavConnection } from './NavConnection';

const MAIN_LINKS = [
Expand Down Expand Up @@ -70,7 +69,6 @@ export default function AppNavbar() {
<div className="flex-1 md:flex-none">
<div className="flex items-center justify-end">
<NavConnection />
<ToggleTheme />
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,49 +1,86 @@
import { Menu } from '@headlessui/react';
import { CheckIcon } from '@heroicons/react/24/solid';
import { DropdownMenuItem } from '@radix-ui/react-dropdown-menu';
import { clsx } from 'clsx';
import { useState } from 'react';

interface DropdownButtonProps {
children: React.ReactNode;
handleBtn: (text: string) => Promise<void>;
selected: boolean;
variant?:
| 'primary'
| 'secondary'
| 'primary-active'
| 'secondary-active'
| 'gray'
| 'method';
}

export const DropdownButton = ({
const variants: Record<string, string> = {
primary:
'dark:bg-navy-blue-500 dark:text-orange-accent-dark/95 animated-transition cursor-pointer bg-pink-50 text-pink-600',
secondary: 'bg-navy-blue-100 text-navy-blue-600 ',
'primary-active':
'dark:bg-navy-blue-500 dark:text-orange-accent-dark/95 animated-transition cursor-pointer bg-pink-50 text-pink-600',
'secondary-active': 'bg-navy-blue-100 text-navy-blue-600',
gray: 'bg-gray-100 text-gray-800 ',
method:
'dark:bg-navy-blue-500 dark:text-orange-accent-dark animated-transition cursor-pointer bg-pink-50 text-pink-600',
};

const variantsSelected: Record<string, string> = {
primary:
'dark:text-orange-accent-dark dark:bg-navy-blue-600 bg-white text-pink-700',
secondary: 'bg-navy-blue-100 text-navy-blue-600 font-semibold',
'primary-active':
'dark:text-orange-accent-dark dark:bg-navy-blue-600 bg-white text-pink-700',
'secondary-active': 'bg-navy-blue-100 text-navy-blue-600 font-semibold',
gray: 'bg-gray-100 font-semibold text-gray-900',
method:
'dark:text-orange-accent-dark dark:bg-navy-blue-600 bg-white text-pink-700',
};

const variantsSelectedElse: Record<string, string> = {
primary: 'dark:text-navy-blue-100 text-gray-600',
secondary: 'bg-navy-blue-100 text-navy-blue-600 font-semibold',
'primary-active': 'dark:text-navy-blue-100 text-gray-600 ',
'secondary-active': 'bg-navy-blue-100 text-navy-blue-600 font-semibold',
gray: 'bg-gray-100 font-semibold text-gray-900',
method: '',
};

export function DropdownButton({
children,
handleBtn,
selected,
}: DropdownButtonProps) => (
<Menu.Item>
{({ active }) => (
<span
onClick={() => {
handleBtn(children as string)
.then(() => {})
.catch(() => {});
}}
variant = 'primary',
}: DropdownButtonProps) {
const [isActive, setIsActive] = useState(false);
const handleMouseEnter = () => setIsActive(true);
const handleMouseLeave = () => setIsActive(false);

return (
<DropdownMenuItem>
<button
type="button"
className={clsx(
active
? 'dark:bg-navy-blue-500 dark:text-orange-accent-dark/95 animated-transition cursor-pointer bg-pink-50 text-pink-600 '
: '',
selected
? 'dark:text-orange-accent-dark dark:bg-navy-blue-600 bg-white text-pink-700'
: 'dark:text-navy-blue-100 text-gray-600',
'block rounded-full py-2 text-lg'
'md:text-md block w-full rounded-full py-2 px-1 text-sm',
isActive ? variants[variant] : null,
selected ? variantsSelected[variant] : variantsSelectedElse[variant]
)}
onClick={() => handleBtn(children as string)}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
<div className="grid grid-cols-6">
<span>
{selected ? (
<CheckIcon className="ml-3 h-4 w-4 lg:h-5 lg:w-5" />
) : (
''
)}
</span>
<span className="col-span-4 col-start-2 text-center">
<div className="grid grid-cols-8 items-center px-1">
<span className="col-span-6 flex justify-start items-center">
{children === 'did:key:jwk_jcs-pub' ? 'did:key (EBSI)' : children}
</span>
<span className="col-span-2">
{selected && <CheckIcon className="ml-3 h-4 w-4 lg:h-5 lg:w-5" />}
</span>
</div>
</span>
)}
</Menu.Item>
);
</button>
</DropdownMenuItem>
);
}
Loading