Files
supabase/apps/www/components/Nav/RightClickBrandLogo.tsx
Anthony Lio 9eaae4cd2c feat(www): brand page (#52295)
## Problem

- a person or an agent cannot link one logo file or pick the file for a
light or a dark background as the brand assets page has one preview
image and two zip downloads only
- `apps/www/lib/json-ld.ts` sets `Organization.logo` to the open graph
banner instead of a logo file

## Solution

- [proposal] Brand Assets -> Brand Guidelines
- [proposal] `/brand-assets` -> `/brand`
- adds the official logos as separate svg and png files in
`/brand-assets/`, with a catalog that tells the background that each
file is for
- show each file on its background, with copy and download actions
- adds `/brand.md` and a "Copy agent prompt" button, so an agent can
read which file to use for each background
- adds a "Copy wordmark" item to the nav logo menu, which copies the
wordmark file for the site theme
- changes `Organization.logo` from the open graph banner to the wordmark
png

`brand assets page`
| before | after |
| -------|------|
| <img width="1637" height="901" alt="image"
src="https://github.com/user-attachments/assets/6b5361c8-0995-4e61-bc29-b5a7ccab7d69"
/> | <img width="1637" height="901" alt="image"
src="https://github.com/user-attachments/assets/0f65ab36-d6f2-427e-8973-eb559139cf8e"
/> |

`logo right click`
| before | after |
| -------|------|
| <img width="676" height="362" alt="image"
src="https://github.com/user-attachments/assets/5abde373-8a37-4ab8-8193-fb7112b97104"
/> | <img width="676" height="362" alt="image"
src="https://github.com/user-attachments/assets/ef5d0724-6a91-4af7-8e9d-59025a9eba87"
/> |

<!--
## Preview links

If relevant, include links to changed pages for easy review access.

Copy the preview base URL from the Vercel bot comment on this PR. Use
the following table as an example template.

| Site | Live | Preview | Search for |
| -------------- |
-------------------------------------------------------------------------
|
------------------------------------------------------------------------------------------------------------
| ----------------------------- |
| WWW | [/blog/your-post](https://supabase.com/blog/your-post) |
[/blog/your-post](https://zone-www-dot-com-git-branch-name-supabase.vercel.app/blog/your-post)
| unique phrase from the change |
| Docs |
[/docs/guides/your-page](https://supabase.com/docs/guides/your-page) |
[/docs/guides/your-page](https://docs-git-branch-name-supabase.vercel.app/docs/guides/your-page)
| unique phrase from the change |
| Studio | [/dashboard](https://supabase.com/dashboard) |
[/dashboard](https://studio-git-branch-name-supabase.vercel.app/dashboard)
| unique phrase from the change |
| Design system | [/design-system](https://supabase.com/design-system) |
[/design-system](https://design-system-git-branch-name-supabase.vercel.app/design-system)
| unique phrase from the change |
| UI library | [/library](https://supabase.com/library) |
[/library](https://ui-library-git-branch-name-supabase.vercel.app/library)
| unique phrase from the change |
| Knowledge base |
[/kb/guides/your-page](https://supabase.com/kb/guides/your-page) |
[/kb/guides/your-page](https://kb-git-branch-name-supabase.vercel.app/kb/guides/your-page)
| unique phrase from the change |
-->

<!-- ## Additional context

Optionally add any other context or screenshots.

-->

## Review instructions

1. run `pnpm dev:www` and open `http://localhost:3000/brand-assets`
2. in the gallery, copy and download one file of each group, and make
sure that each file opens
3. click "Copy agent prompt", and make sure that the copied text names
`https://supabase.com/brand-assets.md`
4. open `http://localhost:3000/brand-assets.md`, and make sure that it
links each svg and png file
5. right-click the nav logo, hover "Copy logo" and "Copy wordmark", and
make sure that the frame moves to the part that each item copies
6. click "Copy wordmark" in the light theme and in the dark theme, and
make sure that the pasted svg has black and then white lettering
7. run `pnpm --filter www exec vitest run data/brand-assets.test.ts`,
and make sure that the tests pass

## Checklist

Check all before review:

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [ ] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
2026-10-29 09:57:35 +11:00

298 lines
9.1 KiB
TypeScript

'use client'
import { CircleCheckFilled, CrossfadeIcon } from '~/components/CrossfadeIcon'
import { Copy, Download } from 'lucide-react'
import { useTheme } from 'next-themes'
import { useRouter } from 'next/compat/router'
import Link from 'next/link'
import { Fragment, MouseEvent, ReactNode, useEffect, useRef, useState } from 'react'
import { useClickAway } from 'react-use'
import {
cn,
copyToClipboard,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from 'ui'
import SupabaseWordmark from './SupabaseWordmark'
/**
* Right click on the Supabase logo in the website navbar
* for quick access to brand assets.
*/
const RightClickBrandLogo = () => {
const ref = useRef(null)
const router = useRouter()
const [open, setOpen] = useState<boolean>(false)
const [copiedLabel, setCopiedLabel] = useState<string | null>(null)
const copiedTimeoutRef = useRef<ReturnType<typeof setTimeout>>(undefined)
const [logoHighlight, setLogoHighlight] = useState<MenuItemProps['logoHighlight']>()
const { resolvedTheme } = useTheme()
/**
* Close dropdown by clicking outside
*/
useClickAway(ref, () => {
setOpen(false)
})
/**
* Close dropdown by using the Escape key
*/
useEffect(() => {
const onKeyDown = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
setOpen(false)
}
}
window.addEventListener('keydown', onKeyDown)
return () => window.removeEventListener('keydown', onKeyDown)
}, [setOpen])
/**
* Open dropdown by right clicking on the Supabase logo
*/
const handleRightClick = (e: MouseEvent) => {
e.preventDefault()
if (e.type === 'contextmenu' || e.nativeEvent.button === 2) {
setLogoHighlight(undefined)
setOpen(true)
}
}
/**
* A11y open dropdown by typing Shift+Enter when the logo is focused
*/
const handleKeyboardOpen = () => {
const onKeyDown = (e: KeyboardEvent) => {
if (e.shiftKey && e.key === 'Enter') {
setOpen(true)
}
}
document?.addEventListener('keydown', onKeyDown)
return () => {
document?.removeEventListener('keydown', onKeyDown)
}
}
/**
* Copy to clipboard logo SVG
*/
const handleCopyToClipboard = (menuItem: MenuItemProps) => {
// the ClipboardItem promise keeps the fetched copy inside the user gesture in safari
// the copied file matches the nav logo, which follows the site theme
const clipboardUrl =
menuItem.clipboardUrls?.[resolvedTheme?.includes('dark') ? 'dark' : 'light']
if (!clipboardUrl) return
copyToClipboard(
fetch(clipboardUrl).then((response) => {
if (!response.ok) throw new Error(`${response.status} ${clipboardUrl}`)
return response.text()
}),
() => {
setCopiedLabel(menuItem.label)
// an older timer would clear the newer feedback early
clearTimeout(copiedTimeoutRef.current)
copiedTimeoutRef.current = setTimeout(() => {
setCopiedLabel(null)
}, 2000)
}
)
}
const handleItemPointerEnter = (menuItem: MenuItemProps) =>
setLogoHighlight(menuItem.logoHighlight)
const handleMenuPointerLeave = () => setLogoHighlight(undefined)
const isFrameVisible = open && logoHighlight !== undefined
const isFrameOnSymbol = logoHighlight !== 'wordmark'
return (
<DropdownMenu open={open}>
<DropdownMenuTrigger asChild>
<Link
href="/"
onContextMenu={handleRightClick}
onFocus={handleKeyboardOpen}
onKeyDown={(e) => e.key === 'Enter' && router?.push('/')}
className={cn(
'relative isolate block w-auto h-6 box-content -mx-2 -my-3 px-2 py-3 focus-ring focus-visible:ring-offset-background-alternative rounded-md',
'transition-colors duration-200 ease-out motion-reduce:transition-none',
isFrameVisible && isFrameOnSymbol && 'text-foreground-muted'
)}
>
<SupabaseWordmark />
<span
aria-hidden
className={cn(
'pointer-events-none absolute inset-y-1.5 left-0.5 -z-10',
'rounded-md bg-overlay',
'transition-[width,scale,opacity] duration-200 ease-out motion-reduce:transition-none',
isFrameOnSymbol ? 'w-9' : 'w-[calc(100%-0.25rem)]',
isFrameVisible ? 'scale-100 opacity-100' : 'scale-95 opacity-0'
)}
/>
</Link>
</DropdownMenuTrigger>
<DropdownMenuContent
autoFocus
ref={ref}
align="start"
alignOffset={2}
side="bottom"
className="mt-2 p-0 w-52"
onPointerLeave={handleMenuPointerLeave}
>
{menuItems.map((section, sectionIdx) => (
<Fragment key={`cxtMenu-section-${sectionIdx}`}>
{sectionIdx !== 0 && <DropdownSeparator />}
<div className="p-1">
{section.map((menuItem, i) => (
<DropdownMenuItem
asChild
key={menuItem.label}
onPointerEnter={() => handleItemPointerEnter(menuItem)}
className="w-full flex justify-between gap-2 items-center p-2! cursor-pointer"
>
{menuItem.type === 'download' || menuItem.type === 'link' ? (
<Link
href={menuItem.href ?? ''}
download={menuItem.type === 'download'}
className="w-full text-left flex justify-between gap-2 items-center"
>
<MenuItemContent {...menuItem} />
</Link>
) : (
menuItem.type === 'clipboard' && (
// DropdownMenuItem asChild manages roving tabIndex; don't override it.
// eslint-disable-next-line supabase/require-explicit-tabindex -- in-menu item
<button
className="w-full text-left flex justify-between gap-2 items-center"
onClick={() => handleCopyToClipboard(menuItem)}
>
<MenuItemContent copied={copiedLabel === menuItem.label} {...menuItem} />
</button>
)
)}
</DropdownMenuItem>
))}
</div>
</Fragment>
))}
</DropdownMenuContent>
<span className="sr-only" role="status">
{copiedLabel ? 'Copied to clipboard' : ''}
</span>
</DropdownMenu>
)
}
const DropdownSeparator = () => <div className="h-px w-full bg-border" />
interface MenuItemProps {
label: string
type: 'clipboard' | 'download' | 'link'
icon?: ReactNode
href?: string
clipboardUrls?: Record<'light' | 'dark', string>
logoHighlight?: 'icon' | 'wordmark'
}
/**
* Brand assets dropdown menu items.
* First array is to divide the menu by sections;
* Second array is the list of items inside each section.
*/
const menuItems: MenuItemProps[][] = [
[
{
label: 'Copy logo',
logoHighlight: 'icon',
type: 'clipboard',
icon: (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M7.95127 2.53536C7.94394 2.04707 7.3269 1.83752 7.02259 2.21997L2.43035 7.99124C1.88831 8.67243 2.37446 9.67704 3.24613 9.67704H7.99525L8.05109 13.3962C8.05842 13.8844 8.67544 14.094 8.97976 13.7116L13.572 7.94026C14.114 7.25907 13.6279 6.25446 12.7562 6.25446H7.97574L7.95127 2.53536Z"
fill="currentColor"
/>
</svg>
),
clipboardUrls: {
light: '/brand-assets/supabase-icon-green-transparent.svg',
dark: '/brand-assets/supabase-icon-green-transparent.svg',
},
},
{
label: 'Copy wordmark',
logoHighlight: 'wordmark',
type: 'clipboard',
icon: <Copy strokeWidth={1.5} className="size-4" />,
clipboardUrls: {
light: '/brand-assets/supabase-logo-green-black-transparent.svg',
dark: '/brand-assets/supabase-logo-green-white-transparent.svg',
},
},
{
label: 'Download wordmark',
type: 'download',
icon: <Download strokeWidth={1.5} className="size-4" />,
href: '/supabase-wordmark.zip',
},
{
label: 'Download brand assets',
type: 'download',
href: '/brand-assets.zip',
icon: <Download strokeWidth={1.5} className="size-4" />,
},
],
[
{
label: 'Go to Brand Guidelines',
type: 'link',
href: '/brand',
},
],
]
interface MenuItemContentProps {
icon?: ReactNode
label: string
copied?: boolean
}
/**
* MenuItem content
*/
const MenuItemContent = ({ icon, label, copied }: MenuItemContentProps) => (
<>
{icon && (
<span className="text-foreground-lighter">
{copied === undefined ? (
icon
) : (
<CrossfadeIcon
isActive={copied}
activeIcon={<CircleCheckFilled className="size-4" />}
inactiveIcon={icon}
className="size-4"
/>
)}
</span>
)}
<span className="grow">{label}</span>
</>
)
export default RightClickBrandLogo