Skip to content

Commit

Permalink
create a CopyButton component
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-sz committed Oct 24, 2023
1 parent e75e9bf commit c9e57b9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
18 changes: 18 additions & 0 deletions web/src/components/CopyButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import { useTranslation } from 'react-i18not';
import { IoCopy } from 'react-icons/io5/index.js';

import { IconButton, IconButtonProps } from './IconButton.js';

export interface CopyButtonProps
extends Omit<IconButtonProps, 'title' | 'href' | 'download' | 'children'> {}

export const CopyButton: React.FC<CopyButtonProps> = ({ ...props }) => {
const { t } = useTranslation();

return (
<IconButton {...props} title={t('copy')}>
<IoCopy />
</IconButton>
);
};
2 changes: 1 addition & 1 deletion web/src/components/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import clsx from 'clsx';

import styles from './IconButton.module.scss';

interface IconButtonProps
export interface IconButtonProps
extends Omit<
React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>,
'ref'
Expand Down
7 changes: 2 additions & 5 deletions web/src/sections/Chat/ChatItem.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useLayoutEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18not';
import { motion } from 'nanoanim';
import { IoCopy } from 'react-icons/io5/index.js';
import { observer } from 'mobx-react-lite';
import clsx from 'clsx';

Expand All @@ -10,7 +9,7 @@ import { animationPropsSlide } from '../../animationSettings.js';
import { ChatItemModel } from '../../types/Models.js';
import { copy } from '../../utils/copy.js';
import { TargetTile } from '../../components/TargetTile.js';
import { IconButton } from '../../components/IconButton.js';
import { CopyButton } from '../../components/CopyButton.js';
import { connection } from '../../stores/index.js';

export interface ChatItemProps {
Expand Down Expand Up @@ -58,9 +57,7 @@ export const ChatItem: React.FC<ChatItemProps> = observer(({ item }) => {
<div>
{item.date.toLocaleTimeString(language, { timeStyle: 'short' })}
</div>
<IconButton onClick={() => copy(item.message)} title={t('copy')}>
<IoCopy />
</IconButton>
<CopyButton onClick={() => copy(item.message)} />
</div>
<div className={styles.message} ref={messageRef}>
{urlify(item.message)}
Expand Down
7 changes: 3 additions & 4 deletions web/src/sections/Connect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import React, { useMemo } from 'react';
import clsx from 'clsx';
import { QRCodeSVG } from 'qrcode.react';
import { useTranslation } from 'react-i18not';
import { IoSend, IoCopy } from 'react-icons/io5/index.js';
import { IoSend } from 'react-icons/io5/index.js';
import { useLocation } from 'react-router-dom';
import { observer } from 'mobx-react-lite';

import styles from './index.module.scss';
import { copy } from '../../utils/copy.js';
import { isShareSupported } from '../../utils/browser.js';
import { IconButton } from '../../components/IconButton.js';
import { CopyButton } from '../../components/CopyButton.js';
import { applicationStore, networkStore } from '../../stores/index.js';
import { LocalNetworks } from '../LocalNetworks/index.js';

Expand All @@ -32,9 +33,7 @@ export const ConnectSection: React.FC = observer(() => {
<div className={styles.copy}>
<pre>{href}</pre>
<div className={styles.buttons}>
<IconButton onClick={() => copy(href)} title={t('copy')}>
<IoCopy />
</IconButton>
<CopyButton onClick={() => copy(href)} />
{isShareSupported && (
<IconButton
onClick={() => applicationStore.share(href)}
Expand Down
9 changes: 3 additions & 6 deletions web/src/sections/Transfers/Transfer/TransferActions.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import {
IoCopy,
IoCloseSharp,
IoCheckmark,
IoArrowDown,
Expand All @@ -10,6 +9,7 @@ import { useTranslation } from 'react-i18not';

import styles from './TransferActions.module.scss';
import { IconButton } from '../../../components/IconButton.js';
import { CopyButton } from '../../../components/CopyButton.js';
import { Transfer } from '../../../stores/Transfer.js';

interface TransferProps {
Expand All @@ -33,14 +33,11 @@ export const TransferActions: React.FC<TransferProps> = observer(
</IconButton>
)}
{transfer.canCopy && (
<IconButton
<CopyButton
round
onClick={() => transfer.copy()}
className={styles.copy}
title={t('copy')}
>
<IoCopy />
</IconButton>
/>
)}
{transfer.canAccept && (
<IconButton
Expand Down

0 comments on commit c9e57b9

Please sign in to comment.