Skip to content

Commit

Permalink
[pi-ui] use pi-ui ButtonIcon and ditch SmallButton component (#3610)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgptr committed Dec 13, 2021
1 parent d357df7 commit dcee1b4
Show file tree
Hide file tree
Showing 48 changed files with 230 additions and 409 deletions.
4 changes: 4 additions & 0 deletions app/actions/ClientActions.js
Expand Up @@ -51,6 +51,10 @@ export const goToError = () => (dispatch) => {
dispatch(pushHistory("/error"));
};

export const goToAccounts = () => (dispatch) => {
dispatch(pushHistory("/accounts"));
};

export const GETWALLETSERVICE_ATTEMPT = "GETWALLETSERVICE_ATTEMPT";
export const GETWALLETSERVICE_FAILED = "GETWALLETSERVICE_FAILED";
export const GETWALLETSERVICE_SUCCESS = "GETWALLETSERVICE_SUCCESS";
Expand Down
@@ -1,11 +1,14 @@
// @flow
import copy from "clipboard-copy";
import { FormattedMessage as T } from "react-intl";
import styles from "./CopyToClipboard.module.css";
import { classNames } from "pi-ui";
import styles from "./CopyToClipboardButton.module.css";
import { classNames, ButtonIcon, useTheme, getThemeProperty } from "pi-ui";
import { useState } from "react";

const CopyToClipboard = ({ textToCopy, ButtonComponent, className }) => {
const CopyToClipboardButton = ({ textToCopy, className }) => {
const { theme } = useTheme();
const iconColor = getThemeProperty(theme, "accent-blue");

const [isSuccessHidden, setIsSuccessHidden] = useState(true);

const onClick = () => {
Expand All @@ -25,25 +28,17 @@ const CopyToClipboard = ({ textToCopy, ButtonComponent, className }) => {
)}>
<T id="clipboard.copied" m="Copied" />
</div>
{ButtonComponent ? (
<ButtonComponent
className={styles.icon}
onClick={onClick}
onMouseLeave={onMouseLeave}
aria-label="Copy"
/>
) : (
<button
className={styles.icon}
onClick={onClick}
onMouseLeave={onMouseLeave}
aria-label="Copy"
/>
)}
<ButtonIcon
type="copyToClipboard"
iconBackgroundColor={iconColor}
onClick={onClick}
onMouseLeave={onMouseLeave}
aria-label="Copy"
/>
</div>
);
};

CopyToClipboard.propTypes = { textToCopy: PropTypes.string.isRequired };
CopyToClipboardButton.propTypes = { textToCopy: PropTypes.string.isRequired };

export default CopyToClipboard;
export default CopyToClipboardButton;
Expand Up @@ -3,20 +3,7 @@
display: inline-block;
}
.icon {
display: inline-block;
width: 20px;
height: 18px;
background-image: var(--copy-to-clipboard-icon);
background-position: 0 0;
background-size: 20px auto;
background-repeat: no-repeat;
cursor: pointer;
background-color: initial;
border: none;
outline: 0;
}
.icon:hover {
opacity: 0.8;
margin-left: 1rem;
}
.success {
font-size: 12px;
Expand Down
1 change: 1 addition & 0 deletions app/components/buttons/CopyToClipboardButton/index.js
@@ -0,0 +1 @@
export { default } from "./CopyToClipboardButton";
10 changes: 0 additions & 10 deletions app/components/buttons/SmallButton/SmallButton.jsx

This file was deleted.

18 changes: 0 additions & 18 deletions app/components/buttons/SmallButton/SmallButton.module.css

This file was deleted.

1 change: 0 additions & 1 deletion app/components/buttons/SmallButton/index.js

This file was deleted.

4 changes: 2 additions & 2 deletions app/components/buttons/index.js
Expand Up @@ -26,8 +26,8 @@ import CloseButton from "./CloseButton";
import HelpLink from "./HelpLink/HelpLink";
import InvisibleButton from "./InvisibleButton";
import Button from "./Button/Button";
import SmallButton from "./SmallButton";
import PiUiButton from "./PiUiButton";
import CopyToClipboardButton from "./CopyToClipboardButton";
export {
ModalButton,
ToggleSwitch,
Expand All @@ -37,7 +37,7 @@ export {
CloseButton,
InvisibleButton,
Button,
SmallButton
CopyToClipboardButton
};

/***************************************************
Expand Down
3 changes: 2 additions & 1 deletion app/components/inputs/AccountsSelect/AccountsSelect.jsx
@@ -1,8 +1,9 @@
import Select from "react-select";
import { useAccountsSelect } from "./hooks";
import { Balance, LinkToAccounts } from "shared";
import { Balance } from "shared";
import styles from "./AccountsSelect.module.css";
import { classNames } from "pi-ui";
import LinkToAccounts from "./LinkToAccounts";

const AccountsSelect = ({
accountsType,
Expand Down
@@ -0,0 +1,20 @@
import { Tooltip, ButtonIcon } from "pi-ui";
import { FormattedMessage as T } from "react-intl";
import styles from "./LinkToAccounts.module.css";
import { useLinkToAccounts } from "./hooks";

const LinkToAccounts = () => {
const { goToAccounts, iconColor } = useLinkToAccounts();
return (
<Tooltip content={<T id="accountsButton.tip" m="Accounts" />}>
<ButtonIcon
type="accounts"
iconColor={iconColor}
className={styles.icon}
onClick={goToAccounts}
/>
</Tooltip>
);
};

export default LinkToAccounts;
@@ -0,0 +1,6 @@
.icon {
display: inline-block;
background-color: var(--input-color) !important;
vertical-align: middle;
margin-left: 1rem;
}
16 changes: 16 additions & 0 deletions app/components/inputs/AccountsSelect/LinkToAccounts/hooks.js
@@ -0,0 +1,16 @@
import { useDispatch } from "react-redux";
import * as cla from "actions/ClientActions";
import { useTheme, getThemeProperty } from "pi-ui";

export function useLinkToAccounts() {
const dispatch = useDispatch();

const { theme } = useTheme();
const iconColor = getThemeProperty(theme, "color-white");
const goToAccounts = () => dispatch(cla.goToAccounts());

return {
goToAccounts,
iconColor
};
}
5 changes: 3 additions & 2 deletions app/components/modals/ListUTXOsModal/ListUTXOsModal.jsx
Expand Up @@ -3,7 +3,8 @@ import Modal from "../Modal";
import styles from "./ListUTXOsModal.module.css";
import { Table } from "pi-ui";
import { useListUtxo } from "./hooks";
import { Balance, CopyToClipboard } from "shared";
import { Balance } from "shared";
import { CopyToClipboardButton } from "buttons";
import { AccountsSelect } from "inputs";

const messages = defineMessages({
Expand All @@ -27,7 +28,7 @@ const ListUTXOsModal = ({ onCancelModal, show }) => {
UTXO: (
<div className={styles.utxoValue}>
<span>{utxoValue}</span>
<CopyToClipboard
<CopyToClipboardButton
textToCopy={utxoValue}
className={styles.copyIcon}
/>
Expand Down
Expand Up @@ -61,6 +61,7 @@
.tableHeader tr th:first-child,
.tableBody tr td:first-child {
width: 35em;
max-width: 35em;
overflow: inherit;
}

Expand Down
16 changes: 6 additions & 10 deletions app/components/shared/DetailsTable/DetailsTable.jsx
@@ -1,13 +1,8 @@
import { useState } from "react";
import { classNames } from "pi-ui";
import { classNames, ButtonIcon } from "pi-ui";
import styles from "./DetailsTable.module.css";
import { SmallButton } from "buttons";
import {
CopyToClipboard,
TruncatedText,
ExternalLink,
ExternalButton
} from "shared";
import { TruncatedText, ExternalLink, ExternalButton } from "shared";
import { CopyToClipboardButton } from "buttons";

const ValueField = ({ data }) => {
const { value, copyable, truncate, href } = data;
Expand All @@ -32,17 +27,18 @@ const ValueField = ({ data }) => {
{copyable ? (
<>
<div className={styles.copyableText}>{text}</div>
<CopyToClipboard textToCopy={value} ButtonComponent={SmallButton} />
<CopyToClipboardButton textToCopy={value} />
</>
) : href ? (
<>
<ExternalLink href={href} className={styles.link}>
{text}
</ExternalLink>
<ExternalButton
type="searchBlock"
className={styles.linkButton}
href={href}
ButtonComponent={SmallButton}
ButtonComponent={ButtonIcon}
/>
</>
) : (
Expand Down
5 changes: 3 additions & 2 deletions app/components/shared/ExternalButton.jsx
Expand Up @@ -13,7 +13,8 @@ const ExternalButton = ({
href,
children,
hrefTestNet,
ButtonComponent
ButtonComponent,
type
}) => {
const { isTestNet } = useNetwork();
return (
Expand All @@ -23,7 +24,7 @@ const ExternalButton = ({
size={size ? size : "md"}
customComponent={(props) =>
ButtonComponent ? (
<ButtonComponent {...props}>{children}</ButtonComponent>
<ButtonComponent {...{ type, ...props }}>{children}</ButtonComponent>
) : (
<Button {...props}>{children}</Button>
)
Expand Down
12 changes: 0 additions & 12 deletions app/components/shared/LinkToAccounts/LinkToAccounts.jsx

This file was deleted.

19 changes: 0 additions & 19 deletions app/components/shared/LinkToAccounts/LinkToAccounts.module.css

This file was deleted.

4 changes: 2 additions & 2 deletions app/components/shared/UnsignedTx/UnsignedTx.jsx
@@ -1,11 +1,11 @@
import { CopyToClipboard } from "shared";
import { CopyToClipboardButton } from "buttons";
import styles from "./UnsignedTx.module.css";

const UnsignedTx = ({ tx, title }) => (
<div className={styles.txArea}>
<div className={styles.txTitle}>{title}</div>
<div className={styles.tx}>{tx}</div>
<CopyToClipboard textToCopy={tx} className={styles.copyIcon} />
<CopyToClipboardButton textToCopy={tx} className={styles.copyIcon} />
</div>
);

Expand Down
2 changes: 0 additions & 2 deletions app/components/shared/index.js
@@ -1,6 +1,4 @@
export * from "./Balance";
export { default as CopyToClipboard } from "./CopyToClipboard/CopyToClipboard";
export { default as LinkToAccounts } from "./LinkToAccounts";
export { default as TransitionMotionWrapper } from "./TransitionMotionWrapper";
export { default as ExternalLink } from "./ExternalLink";
export { default as ExternalButton } from "./ExternalButton";
Expand Down
@@ -1,7 +1,7 @@
import { FormattedMessage as T } from "react-intl";
import { Tooltip, classNames } from "pi-ui";
import { Balance, CopyToClipboard } from "shared";
import { SlateGrayButton } from "buttons";
import { Balance } from "shared";
import { SlateGrayButton, CopyToClipboardButton } from "buttons";
import { IMPORTED_ACCOUNT, DEFAULT_ACCOUNT } from "constants";
import DataLine from "./DataLine";
import styles from "./AccountDetails.module.css";
Expand Down Expand Up @@ -94,7 +94,7 @@ const AccountsDetails = ({
{showPubKey && accountExtendedKey ? (
<>
<div className={styles.pubkeyArea}>{accountExtendedKey}</div>
<CopyToClipboard
<CopyToClipboardButton
textToCopy={accountExtendedKey}
className={styles.pubkeyClipboard}
/>
Expand Down
7 changes: 4 additions & 3 deletions app/components/views/FatalErrorPage/FatalErrorPage.jsx
@@ -1,7 +1,8 @@
import { FormattedMessage as T } from "react-intl";
import { KeyBlueButton, RemoveDaemonButton } from "buttons";
import { PageBody } from "layout";
import { CopyToClipboard, ExternalLink } from "shared";
import { ExternalLink } from "shared";
import { CopyToClipboardButton } from "buttons";
import { DIFF_CONNECTION_ERROR } from "constants";
import { wallet } from "wallet-preload-shim";
import { useFatalErrorPage } from "./hooks";
Expand Down Expand Up @@ -112,15 +113,15 @@ function FatalErrorPage() {
<T id="fatal.daemon.title" m="Daemon Error" />
</div>
<textarea rows="10" value={daemonError} disabled />
<CopyToClipboard textToCopy={daemonError} />
<CopyToClipboardButton textToCopy={daemonError} />
</>
)}
{walletError && (
<>
<div className={styles.error}>
<T id="fatal.wallet.title" m="Wallet Error" />
</div>
<CopyToClipboard textToCopy={walletError} />
<CopyToClipboardButton textToCopy={walletError} />
<textarea rows="10" value={walletError} disabled />
</>
)}
Expand Down

0 comments on commit dcee1b4

Please sign in to comment.