ghost-portal/packages/react-components/src/AddressSmall.tsx
Keith Ingram 9703811f8b
AddressMenu popup when clicking on address name (#2563)
* AddressMenu

* use menu

* refactor

* draft

* cleanup

* Sidebar

* Sidebar

* improvements

* redesign

* bump

* Small adjustments

* Layout adjustments, useCallbacks (not perfect...)

* Remove _setName with extra effect, re-add badges (edit missing)

* Missing useCallback in Address

* no withSidebar on AddressToggle

* useAccountInfo CPU spikes (split effects, no useCallback deps)

* Alway have underline (even on address)

* secondary button color

* Add name callback

* Make identity appear with displayname

* Adjust judgement button position

* UI adjustments

Co-authored-by: Jaco Greeff <jacogr@gmail.com>
2020-04-22 19:43:20 +02:00

79 lines
2.0 KiB
TypeScript

// Copyright 2017-2020 @polkadot/react-components authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Address, AccountId } from '@polkadot/types/interfaces';
import React from 'react';
import styled from 'styled-components';
import { classes } from './util';
import AccountIndex from './AccountIndex';
import AccountName from './AccountName';
import IdentityIcon from './IdentityIcon';
interface Props {
children?: React.ReactNode;
className?: string;
defaultName?: string;
onClickName?: () => void;
overrideName?: React.ReactNode;
withIndex?: boolean;
withSidebar?: boolean;
toggle?: any;
value?: string | Address | AccountId | null | Uint8Array;
}
function AddressSmall ({ children, className, defaultName, onClickName, overrideName, toggle, value, withIndex, withSidebar = true }: Props): React.ReactElement<Props> {
return (
<div className={`ui--AddressSmall ${className}`}>
<IdentityIcon
size={32}
value={value as Uint8Array}
/>
<div className={classes('nameInfo', withSidebar && 'withSidebar')}>
<AccountName
className={(overrideName || !onClickName) ? '' : 'name--clickable'}
defaultName={defaultName}
onClick={onClickName}
override={overrideName}
toggle={toggle}
value={value}
withSidebar={withSidebar}
>
{children}
</AccountName>
{withIndex && (
<AccountIndex value={value} />
)}
</div>
</div>
);
}
export default React.memo(styled(AddressSmall)`
display: flex;
align-items: center;
.ui--IdentityIcon,
.nameInfo {
display: inline-block;
vertical-align: middle;
white-space: nowrap;
}
.ui--IdentityIcon {
margin-right: 0.75rem;
}
.nameInfo {
&.withSidebar {
cursor: help;
}
> div {
max-width: 12rem;
}
}
`);