Style upper part of sidebar (#6115)
* Style address section in sidebar * Extract AddressSection component
This commit is contained in:
parent
74c640b293
commit
fe2414f689
@ -293,6 +293,7 @@
|
||||
"https://example.com": "https://example.com",
|
||||
"identity": "identity",
|
||||
"include field": "include field",
|
||||
"index": "index",
|
||||
"invalid/unknown registrar account": "invalid/unknown registrar account",
|
||||
"judgement": "judgement",
|
||||
"keypair crypto type": "keypair crypto type",
|
||||
|
||||
62
packages/page-accounts/src/Sidebar/AddressSection.tsx
Normal file
62
packages/page-accounts/src/Sidebar/AddressSection.tsx
Normal file
@ -0,0 +1,62 @@
|
||||
// Copyright 2017-2021 @polkadot/page-accounts authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { AccountName, IdentityIcon, Input } from '@polkadot/react-components';
|
||||
import { AddressFlags } from '@polkadot/react-hooks/types';
|
||||
|
||||
import { useTranslation } from '../translate';
|
||||
|
||||
interface Props {
|
||||
value: string,
|
||||
editingName: boolean,
|
||||
defaultValue: string,
|
||||
onChange: (value: string) => void,
|
||||
flags: AddressFlags,
|
||||
accountIndex: string | undefined,
|
||||
}
|
||||
|
||||
function AddressSection ({ accountIndex, defaultValue, editingName, flags, onChange, value }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<div className='ui--AddressSection'>
|
||||
<IdentityIcon
|
||||
size={80}
|
||||
value={value}
|
||||
/>
|
||||
<div className='ui--AddressSection__AddressColumn'>
|
||||
<AccountName
|
||||
override={
|
||||
editingName
|
||||
? (
|
||||
<Input
|
||||
className='name--input'
|
||||
defaultValue={defaultValue}
|
||||
label='name-input'
|
||||
onChange={onChange}
|
||||
withLabel={false}
|
||||
/>
|
||||
)
|
||||
: flags.isEditable
|
||||
? (defaultValue.toUpperCase() || t<string>('<unknown>'))
|
||||
: undefined
|
||||
}
|
||||
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>
|
||||
);
|
||||
}
|
||||
|
||||
export default React.memo(AddressSection);
|
||||
@ -4,14 +4,14 @@
|
||||
import React, { useRef, useState } from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import SidebarEditableSection from '@polkadot/app-accounts/Sidebar/SidebarEditableSection';
|
||||
import { IdentityIcon, LinkExternal, Sidebar } from '@polkadot/react-components';
|
||||
import { LinkExternal, Sidebar } from '@polkadot/react-components';
|
||||
import { colorLink } from '@polkadot/react-components/styles/theme';
|
||||
import { useAccountInfo } from '@polkadot/react-hooks';
|
||||
|
||||
import Balances from './Balances';
|
||||
import Identity from './Identity';
|
||||
import Multisig from './Multisig';
|
||||
import SidebarEditableSection from './SidebarEditableSection';
|
||||
|
||||
interface Props {
|
||||
address: string;
|
||||
@ -39,19 +39,8 @@ function FullSidebar ({ address, className = '', dataTestId, onClose, onUpdateNa
|
||||
className='ui--AddressMenu-header'
|
||||
data-testid='sidebar-address-menu'
|
||||
>
|
||||
<IdentityIcon
|
||||
size={80}
|
||||
value={address}
|
||||
/>
|
||||
<div className='ui--AddressMenu-addr'>
|
||||
{address}
|
||||
</div>
|
||||
{accountIndex && (
|
||||
<div className='ui--AddressMenu-addr'>
|
||||
{accountIndex}
|
||||
</div>
|
||||
)}
|
||||
<SidebarEditableSection
|
||||
accountIndex={accountIndex}
|
||||
address={address}
|
||||
isBeingEdited={setInEditMode}
|
||||
onUpdateName={onUpdateName}
|
||||
@ -98,19 +87,51 @@ export default React.memo(styled(FullSidebar)`
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
margin: -1rem -1rem 1rem -1rem;
|
||||
padding: 1rem;
|
||||
padding: 1.35rem 1rem 1rem 1rem;
|
||||
}
|
||||
|
||||
.ui--AddressSection {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
align-items: center;
|
||||
|
||||
|
||||
width: 100%;
|
||||
|
||||
.ui--AddressSection__AddressColumn {
|
||||
margin-left: 1rem;
|
||||
|
||||
.ui--AccountName {
|
||||
max-width: 21.5rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ui--AddressMenu-addr,
|
||||
.ui--AddressMenu-index {
|
||||
font: var(--font-mono);
|
||||
text-align: left;
|
||||
font-size: 0.857rem;
|
||||
}
|
||||
|
||||
.ui--AddressMenu-addr {
|
||||
font: var(--font-mono);
|
||||
margin: 0.75rem 0;
|
||||
text-align: center;
|
||||
word-break: break-all;
|
||||
width: 26ch;
|
||||
margin: 0.571rem 0;
|
||||
color: var(--color-label);
|
||||
}
|
||||
|
||||
.ui--AddressMenu-addr+.ui--AddressMenu-addr {
|
||||
margin-top: -0.25rem;
|
||||
.ui--AddressMenu-index {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
label {
|
||||
font-size: 0.857rem;
|
||||
margin-right: 0.4rem;
|
||||
text-transform: capitalize;
|
||||
}
|
||||
}
|
||||
|
||||
section {
|
||||
|
||||
@ -3,22 +3,23 @@
|
||||
|
||||
import React, { useCallback, useEffect } from 'react';
|
||||
|
||||
import AccountMenuButtons from '@polkadot/app-accounts/Sidebar/AccountMenuButtons';
|
||||
import Flags from '@polkadot/app-accounts/Sidebar/Flags';
|
||||
import { useTranslation } from '@polkadot/app-accounts/translate';
|
||||
import { AccountName, Input, Tags } from '@polkadot/react-components';
|
||||
import { Tags } from '@polkadot/react-components';
|
||||
import { useAccountInfo, useOutsideClick } from '@polkadot/react-hooks';
|
||||
import { keyring } from '@polkadot/ui-keyring';
|
||||
|
||||
import AccountMenuButtons from './AccountMenuButtons';
|
||||
import AddressSection from './AddressSection';
|
||||
import Flags from './Flags';
|
||||
|
||||
interface Props {
|
||||
accountIndex: string | undefined;
|
||||
address: string;
|
||||
isBeingEdited: (arg: boolean) => void;
|
||||
onUpdateName: () => void;
|
||||
sidebarRef: React.RefObject<HTMLDivElement>;
|
||||
}
|
||||
|
||||
function SidebarEditableSection ({ address, isBeingEdited, onUpdateName, sidebarRef }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
function SidebarEditableSection ({ accountIndex, address, isBeingEdited, onUpdateName, sidebarRef }: Props): React.ReactElement<Props> {
|
||||
const { flags, isEditing, isEditingName, isEditingTags, name, onForgetAddress, onSaveName, onSaveTags, setIsEditingName, setIsEditingTags, setName, setTags, tags, toggleIsEditingName, toggleIsEditingTags } = useAccountInfo(address);
|
||||
|
||||
useEffect(() => {
|
||||
@ -45,24 +46,13 @@ function SidebarEditableSection ({ address, isBeingEdited, onUpdateName, sidebar
|
||||
|
||||
return (
|
||||
<>
|
||||
<AccountName
|
||||
override={
|
||||
isEditingName
|
||||
? (
|
||||
<Input
|
||||
className='name--input'
|
||||
defaultValue={name}
|
||||
label='name-input'
|
||||
onChange={setName}
|
||||
withLabel={false}
|
||||
/>
|
||||
)
|
||||
: flags.isEditable
|
||||
? (name.toUpperCase() || t<string>('<unknown>'))
|
||||
: undefined
|
||||
}
|
||||
<AddressSection
|
||||
accountIndex={accountIndex}
|
||||
defaultValue={name}
|
||||
editingName={isEditingName}
|
||||
flags={flags}
|
||||
onChange={setName}
|
||||
value={address}
|
||||
withSidebar={false}
|
||||
/>
|
||||
<div
|
||||
className='ui--AddressMenu-tags'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user