Add "Copy" icon to the User Sidebar (#7235)
* PR 7209 fixes * Update packages/page-accounts/src/Sidebar/AddressSection.tsx Co-authored-by: Jaco <jacogr@gmail.com> * Update packages/page-accounts/src/Sidebar/AddressSection.tsx Co-authored-by: Jaco <jacogr@gmail.com> * Update packages/page-accounts/src/Sidebar/AddressSection.tsx Co-authored-by: Jaco <jacogr@gmail.com> * Update packages/page-accounts/src/Sidebar/AddressSection.tsx Co-authored-by: Jaco <jacogr@gmail.com> * corrections on PR 7209 * corrections on PR 7209 * fixed based on Jegor s comments * replaced donothing with NOOP function Co-authored-by: Jaco <jacogr@gmail.com>
This commit is contained in:
parent
132a4a6b7d
commit
7429414fb6
@ -2,8 +2,10 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import React from 'react';
|
||||
import { CopyToClipboard } from 'react-copy-to-clipboard';
|
||||
|
||||
import { AccountName, IdentityIcon, Input } from '@polkadot/react-components';
|
||||
import { AccountName, Button, IdentityIcon, Input } from '@polkadot/react-components';
|
||||
import { useToggle } from '@polkadot/react-hooks';
|
||||
import { AddressFlags } from '@polkadot/react-hooks/types';
|
||||
|
||||
import { useTranslation } from '../translate';
|
||||
@ -19,6 +21,8 @@ interface Props {
|
||||
|
||||
function AddressSection ({ accountIndex, defaultValue, editingName, flags, onChange, value }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const [isCopyShown, toggleIsCopyShown] = useToggle();
|
||||
const NOOP = () => undefined;
|
||||
|
||||
return (
|
||||
<div className='ui--AddressSection'>
|
||||
@ -46,15 +50,36 @@ function AddressSection ({ accountIndex, defaultValue, editingName, flags, onCha
|
||||
value={value}
|
||||
withSidebar={false}
|
||||
/>
|
||||
|
||||
<div className='ui--AddressMenu-addr'>
|
||||
{value}
|
||||
</div>
|
||||
|
||||
{accountIndex && (
|
||||
<div className='ui--AddressMenu-index'>
|
||||
<label>{t<string>('index')}:</label> {accountIndex}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className='ui--AddressSection__CopyColumn'>
|
||||
<div className='ui--AddressMenu-copyaddr'>
|
||||
<CopyToClipboard
|
||||
text={value}
|
||||
>
|
||||
<span>
|
||||
<Button.Group>
|
||||
<Button
|
||||
icon={isCopyShown ? 'check' : 'copy'}
|
||||
label={isCopyShown ? t<string>('Copied') : t<string>('Copy')}
|
||||
onClick={isCopyShown ? NOOP : toggleIsCopyShown }
|
||||
onMouseLeave={isCopyShown ? toggleIsCopyShown : NOOP }
|
||||
/>
|
||||
</Button.Group>
|
||||
</span>
|
||||
</CopyToClipboard>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@ -110,6 +110,15 @@ export default React.memo(styled(FullSidebar)`
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
.ui--AddressSection__CopyColumn {
|
||||
margin-left: 1rem;
|
||||
|
||||
.ui--AccountName {
|
||||
max-width: 10rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ui--AddressMenu-addr,
|
||||
@ -121,11 +130,26 @@ export default React.memo(styled(FullSidebar)`
|
||||
|
||||
.ui--AddressMenu-addr {
|
||||
word-break: break-all;
|
||||
width: 26ch;
|
||||
width: 24ch;
|
||||
margin: 0.571rem 0;
|
||||
color: var(--color-label);
|
||||
}
|
||||
|
||||
.ui--AddressMenu-copyaddr,
|
||||
.ui--AddressMenu-index {
|
||||
font: var(--font-mono);
|
||||
text-align: left;
|
||||
font-size: 0.857rem;
|
||||
}
|
||||
|
||||
.ui--AddressMenu-copyaaddr {
|
||||
word-break: break-all;
|
||||
width: 12ch;
|
||||
margin: 0.371rem 0;
|
||||
color: var(--color-label);
|
||||
}
|
||||
|
||||
|
||||
.ui--AddressMenu-index {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user