From fe2414f6899c35c383232eaaff7e291d519f6eb1 Mon Sep 17 00:00:00 2001 From: MiZiet <55240109+MiZiet@users.noreply.github.com> Date: Tue, 14 Sep 2021 08:52:11 +0200 Subject: [PATCH] Style upper part of sidebar (#6115) * Style address section in sidebar * Extract AddressSection component --- .../apps/public/locales/en/app-accounts.json | 1 + .../src/Sidebar/AddressSection.tsx | 62 +++++++++++++++++++ .../page-accounts/src/Sidebar/Sidebar.tsx | 61 ++++++++++++------ .../src/Sidebar/SidebarEditableSection.tsx | 36 ++++------- 4 files changed, 117 insertions(+), 43 deletions(-) create mode 100644 packages/page-accounts/src/Sidebar/AddressSection.tsx diff --git a/packages/apps/public/locales/en/app-accounts.json b/packages/apps/public/locales/en/app-accounts.json index 51863480e5..9da8893091 100644 --- a/packages/apps/public/locales/en/app-accounts.json +++ b/packages/apps/public/locales/en/app-accounts.json @@ -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", diff --git a/packages/page-accounts/src/Sidebar/AddressSection.tsx b/packages/page-accounts/src/Sidebar/AddressSection.tsx new file mode 100644 index 0000000000..dd87d9486a --- /dev/null +++ b/packages/page-accounts/src/Sidebar/AddressSection.tsx @@ -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 { + const { t } = useTranslation(); + + return ( +
+ +
+ + ) + : flags.isEditable + ? (defaultValue.toUpperCase() || t('')) + : undefined + } + value={value} + withSidebar={false} + /> +
+ {value} +
+ {accountIndex && ( +
+ {accountIndex} +
+ )} +
+
+ ); +} + +export default React.memo(AddressSection); diff --git a/packages/page-accounts/src/Sidebar/Sidebar.tsx b/packages/page-accounts/src/Sidebar/Sidebar.tsx index 127b915717..99d531effd 100644 --- a/packages/page-accounts/src/Sidebar/Sidebar.tsx +++ b/packages/page-accounts/src/Sidebar/Sidebar.tsx @@ -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' > - -
- {address} -
- {accountIndex && ( -
- {accountIndex} -
- )} void; onUpdateName: () => void; sidebarRef: React.RefObject; } -function SidebarEditableSection ({ address, isBeingEdited, onUpdateName, sidebarRef }: Props): React.ReactElement { - const { t } = useTranslation(); +function SidebarEditableSection ({ accountIndex, address, isBeingEdited, onUpdateName, sidebarRef }: Props): React.ReactElement { 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 ( <> - - ) - : flags.isEditable - ? (name.toUpperCase() || t('')) - : undefined - } +