Skip to content

Commit

Permalink
add copy for tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahgm committed May 22, 2024
1 parent fe31b63 commit 37f6411
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions docs/app/_components/SiteMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Button, Dialog, useClassNames } from '@/ui';
import { Command, CommandGroup } from 'cmdk';
import { allContentPages } from 'contentlayer/generated';
import { useEffect, useState } from 'react';
import { useCopyToClipboard } from 'react-use';
import useClipboard from 'react-use-clipboard';

Check warning on line 11 in docs/app/_components/SiteMenu.tsx

View workflow job for this annotation

GitHub Actions / Lint

'useClipboard' is defined but never used

import { useRouter } from 'next/navigation';

Expand Down Expand Up @@ -48,7 +50,7 @@ const Hotkey = () => {

// Component
// ---------------
export const SiteMenu = () => {
export const SiteMenu = (value: string) => {
const router = useRouter();
const [open, setOpen] = useState(false);
const [query, setQuery] = useState('');
Expand All @@ -64,6 +66,12 @@ export const SiteMenu = () => {
setOpen(false);
};

const [, setCopy] = useCopyToClipboard();
const copy = (value: string) => {
setCopy(value);
setOpen(false);
};

// register global cmd+k hotkey
useEffect(() => {
const onKeydown = (e: KeyboardEvent) => {
Expand Down Expand Up @@ -175,8 +183,9 @@ export const SiteMenu = () => {
className={classNames.item}
key={token}
value={token}
onSelect={() => copy(token.replace('-DEFAULT', ''))}
>
{token}
{token.replace('-DEFAULT', '')}
</Command.Item>
))}
</CommandGroup>
Expand Down

0 comments on commit 37f6411

Please sign in to comment.