Expander adjustment (right-align, icons) (#3668)
* Expander adjustment (right-align, icons) * Alignements * caret * caret alignment
This commit is contained in:
parent
82a9231ecf
commit
fab8c86dfa
@ -29,7 +29,7 @@ function Proposals ({ className = '', motions, prime }: Props): React.ReactEleme
|
||||
[t('motions'), 'start', 2],
|
||||
[t('threshold')],
|
||||
[t('voting end')],
|
||||
[t('votes'), 'start'],
|
||||
[t('votes'), 'expand'],
|
||||
[],
|
||||
[undefined, 'badge'],
|
||||
[]
|
||||
|
||||
@ -28,7 +28,7 @@ function Candidates ({ allVotes = {}, electionsInfo }: Props): React.ReactElemen
|
||||
|
||||
const headerRunnersRef = useRef([
|
||||
[t('runners up'), 'start', 2],
|
||||
[t('backing')],
|
||||
[t('backing'), 'expand'],
|
||||
[t('votes')]
|
||||
]);
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ function Members ({ allVotes = {}, className = '', electionsInfo, prime }: Props
|
||||
|
||||
const headerRef = useRef([
|
||||
[t('members'), 'start', 2],
|
||||
[t('backing')],
|
||||
[t('backing'), 'expand'],
|
||||
[t('votes')]
|
||||
]);
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ function Voters ({ balance, voters }: Props): React.ReactElement<Props> {
|
||||
|
||||
return (
|
||||
<>
|
||||
<td className='all number'>
|
||||
<td className='all expand'>
|
||||
<Expander summary={<FormatBalance value={balance} />} >
|
||||
{voters.map((who): React.ReactNode =>
|
||||
<AddressMini
|
||||
|
||||
@ -37,7 +37,7 @@ function Proposal ({ className = '', value: { balance, image, imageHash, index,
|
||||
<td className='number together media--1200'>
|
||||
<FormatBalance value={balance} />
|
||||
</td>
|
||||
<td>
|
||||
<td className='expand'>
|
||||
{seconding.length !== 0 && (
|
||||
<Expander summary={t<string>('Seconds ({{count}})', { replace: { count: seconding.length } })}>
|
||||
{seconding.map((address, count): React.ReactNode => (
|
||||
|
||||
@ -126,7 +126,6 @@ function Referendum ({ className = '', value: { allAye, allNay, image, imageHash
|
||||
<ReferendumVotes
|
||||
change={changeAye}
|
||||
count={voteCountAye}
|
||||
index={index}
|
||||
isAye
|
||||
isWinning={isPassing}
|
||||
total={votedAye}
|
||||
@ -135,7 +134,6 @@ function Referendum ({ className = '', value: { allAye, allNay, image, imageHash
|
||||
<ReferendumVotes
|
||||
change={changeNay}
|
||||
count={voteCountNay}
|
||||
index={index}
|
||||
isAye={false}
|
||||
isWinning={!isPassing}
|
||||
total={votedNay}
|
||||
|
||||
@ -5,8 +5,8 @@
|
||||
import { DeriveReferendumVote } from '@polkadot/api-derive/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import React, { useMemo, useState } from 'react';
|
||||
import { Expander, Icon, Tooltip } from '@polkadot/react-components';
|
||||
import React, { useMemo } from 'react';
|
||||
import { Expander } from '@polkadot/react-components';
|
||||
import { FormatBalance } from '@polkadot/react-query';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
|
||||
@ -19,18 +19,14 @@ interface Props {
|
||||
count: number;
|
||||
isAye: boolean;
|
||||
isWinning: boolean;
|
||||
index: BN;
|
||||
total: BN;
|
||||
votes: DeriveReferendumVote[];
|
||||
}
|
||||
|
||||
const LOCKS = [1, 10, 20, 30, 40, 50, 60];
|
||||
|
||||
let id = 0;
|
||||
|
||||
function ReferendumVotes ({ change, className, count, index, isAye, isWinning, total, votes }: Props): React.ReactElement<Props> | null {
|
||||
function ReferendumVotes ({ change, className, count, isAye, isWinning, total, votes }: Props): React.ReactElement<Props> | null {
|
||||
const { t } = useTranslation();
|
||||
const [trigger] = useState(`votes-${index.toString()}-${++id}`);
|
||||
|
||||
const sorted = useMemo(
|
||||
() => votes.sort((a, b) => {
|
||||
@ -45,36 +41,23 @@ function ReferendumVotes ({ change, className, count, index, isAye, isWinning, t
|
||||
return (
|
||||
<Expander
|
||||
className={className}
|
||||
help={change.gtn(0) && (
|
||||
<>
|
||||
<FormatBalance value={change} />
|
||||
<p>{isWinning
|
||||
? t<string>('The amount this total can be reduced by to change the referendum outcome. This assumes changes to the convictions of the existing votes, with no additional turnout.')
|
||||
: t<string>('The amount this total should be increased by to change the referendum outcome. This assumes additional turnout with new votes at 1x conviction.')
|
||||
}</p>
|
||||
</>
|
||||
)}
|
||||
helpIcon={isWinning ? 'arrow-circle-down' : 'arrow-circle-up'}
|
||||
summary={
|
||||
<>
|
||||
{isAye
|
||||
? t<string>('Aye {{count}}', { replace: { count: count ? ` (${formatNumber(count)})` : '' } })
|
||||
: t<string>('Nay {{count}}', { replace: { count: count ? ` (${formatNumber(count)})` : '' } })
|
||||
}{change.gtn(0) && (
|
||||
<>
|
||||
{' '}
|
||||
<Icon
|
||||
className='double-icon'
|
||||
icon={isWinning ? 'arrow-circle-down' : 'arrow-circle-up'}
|
||||
tooltip={trigger}
|
||||
/>
|
||||
<Tooltip
|
||||
text={
|
||||
<>
|
||||
<FormatBalance value={change} />
|
||||
<p>{isWinning
|
||||
? t<string>('The amount this total can be reduced by to change the referendum outcome. This assumes changes to the convictions of the existing votes, with no additional turnout.')
|
||||
: t<string>('The amount this total should be increased by to change the referendum outcome. This assumes additional turnout with new votes at 1x conviction.')
|
||||
}</p>
|
||||
</>
|
||||
}
|
||||
trigger={trigger}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<div>
|
||||
<FormatBalance value={total} />
|
||||
</div>
|
||||
}
|
||||
<div><FormatBalance value={total} /></div>
|
||||
</>
|
||||
}
|
||||
>
|
||||
|
||||
@ -24,7 +24,7 @@ function Referendums ({ className = '', referendums }: Props): React.ReactElemen
|
||||
[t('activate'), 'media--1400'],
|
||||
[t('turnout'), 'media--1400'],
|
||||
[undefined, 'badge'],
|
||||
[t('votes'), 'start'],
|
||||
[t('votes'), 'expand'],
|
||||
[undefined, undefined, 2],
|
||||
[undefined, 'media--1000']
|
||||
]);
|
||||
|
||||
@ -27,7 +27,7 @@ function Candidates ({ allMembers, className = '', isMember, ownMembers }: Props
|
||||
[t('candidates'), 'start'],
|
||||
[t('kind')],
|
||||
[t('value')],
|
||||
[t('votes'), 'start'],
|
||||
[t('votes'), 'expand'],
|
||||
[]
|
||||
]);
|
||||
|
||||
|
||||
@ -36,7 +36,7 @@ function Defender ({ className = '', info, isMember, ownMembers }: Props): React
|
||||
|
||||
const headerRef = useRef([
|
||||
[t('defender'), 'start'],
|
||||
[t('votes'), 'start'],
|
||||
[t('votes'), 'expand'],
|
||||
[]
|
||||
]);
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ function Votes ({ votes }: Props): React.ReactElement<Props> {
|
||||
}, [votes]);
|
||||
|
||||
return (
|
||||
<td className='start'>
|
||||
<td className='expand'>
|
||||
<VotesExpander
|
||||
label={t<string>('Skeptics')}
|
||||
votes={allSkeptic}
|
||||
|
||||
@ -203,7 +203,7 @@ function Account ({ allSlashes, className = '', info: { controllerId, destinatio
|
||||
</td>
|
||||
)
|
||||
: (
|
||||
<td className='all'>
|
||||
<td className='all expand left'>
|
||||
{isStashNominating && (
|
||||
<ListNominees
|
||||
nominating={nominating}
|
||||
|
||||
@ -42,7 +42,7 @@ function NominatedBy ({ nominators, slashingSpans }: Props): React.ReactElement<
|
||||
);
|
||||
|
||||
return (
|
||||
<td className='start all'>
|
||||
<td className='expand all'>
|
||||
{nominators
|
||||
? (
|
||||
<>
|
||||
|
||||
@ -39,7 +39,7 @@ function StakeOther ({ nominators, stakeOther }: Props): React.ReactElement<Prop
|
||||
);
|
||||
|
||||
return (
|
||||
<td className='number all'>
|
||||
<td className='expand all'>
|
||||
{!!rewarded.length && (
|
||||
<>
|
||||
<Expander summary={
|
||||
|
||||
@ -126,7 +126,7 @@ function CurrentList ({ favorites, hasQueries, isIntentions, next, stakingOvervi
|
||||
|
||||
const headerWaitingRef = useRef([
|
||||
[t('intentions'), 'start', 2],
|
||||
[t('nominators'), 'start', 2],
|
||||
[t('nominators'), 'expand', 2],
|
||||
[t('commission'), 'number', 1],
|
||||
[],
|
||||
[]
|
||||
|
||||
@ -68,7 +68,7 @@ function Validator ({ className = '', isDisabled, payout }: Props): React.ReactE
|
||||
<td className='number'><FormatBalance value={payout.available} /></td>
|
||||
<td className='number'>{eraBlocks && <BlockToTime blocks={eraBlocks} />}</td>
|
||||
<td
|
||||
className='start'
|
||||
className='expand'
|
||||
colSpan={2}
|
||||
>
|
||||
<Expander summary={t<string>('{{count}} own stashes', { replace: { count: numNominators } })}>
|
||||
|
||||
@ -39,7 +39,7 @@ function Row ({ index, isSelected, onSelect, slash: { isMine, slash: { others, o
|
||||
<td className='address'>
|
||||
<AddressSmall value={validator} />
|
||||
</td>
|
||||
<td className='start all'>
|
||||
<td className='expand all'>
|
||||
{!!others.length && (
|
||||
<Expander summary={t<string>('Nominators ({{count}})', { replace: { count: formatNumber(others.length) } })}>
|
||||
{others.map(([accountId, balance], index): React.ReactNode => (
|
||||
|
||||
@ -113,21 +113,23 @@ function Tip ({ bestNumber, className = '', defaultId, hash, isMember, members,
|
||||
)}
|
||||
</td>
|
||||
<TipReason hash={reason} />
|
||||
<td className='start'>
|
||||
<td className='expand'>
|
||||
{tips.length !== 0 && (
|
||||
<>
|
||||
<Expander summary={t<string>('Tippers ({{count}})', { replace: { count: tips.length } })}>
|
||||
{tips.map(([tipper, balance]) => (
|
||||
<AddressMini
|
||||
balance={balance}
|
||||
key={tipper.toString()}
|
||||
value={tipper}
|
||||
withBalance
|
||||
/>
|
||||
))}
|
||||
</Expander>
|
||||
<FormatBalance value={median} />
|
||||
</>
|
||||
<Expander summary={
|
||||
<>
|
||||
<div>{t<string>('Tippers ({{count}})', { replace: { count: tips.length } })}</div>
|
||||
<FormatBalance value={median} />
|
||||
</>
|
||||
}>
|
||||
{tips.map(([tipper, balance]) => (
|
||||
<AddressMini
|
||||
balance={balance}
|
||||
key={tipper.toString()}
|
||||
value={tipper}
|
||||
withBalance
|
||||
/>
|
||||
))}
|
||||
</Expander>
|
||||
)}
|
||||
</td>
|
||||
<td className='button together'>
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { IconName } from '@fortawesome/fontawesome-svg-core';
|
||||
import React, { useMemo } from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { LabelHelp } from '@polkadot/react-components';
|
||||
@ -19,12 +20,12 @@ export interface Props {
|
||||
children?: React.ReactNode;
|
||||
className?: string;
|
||||
help?: string;
|
||||
helpIcon?: IconName;
|
||||
isOpen?: boolean;
|
||||
isPadded?: boolean;
|
||||
summary?: React.ReactNode;
|
||||
summaryMeta?: Meta;
|
||||
summarySub?: React.ReactNode;
|
||||
withDot?: boolean;
|
||||
withHidden?: boolean;
|
||||
}
|
||||
|
||||
@ -43,7 +44,7 @@ function formatMeta (meta?: Meta): React.ReactNode | null {
|
||||
).join(' ');
|
||||
}
|
||||
|
||||
function Expander ({ children, className = '', help, isOpen, isPadded, summary, summaryMeta, summarySub, withDot, withHidden }: Props): React.ReactElement<Props> {
|
||||
function Expander ({ children, className = '', help, helpIcon, isOpen, isPadded, summary, summaryMeta, summarySub, withHidden }: Props): React.ReactElement<Props> {
|
||||
const { t } = useTranslation();
|
||||
const [isExpanded, toggleExpanded] = useToggle(isOpen);
|
||||
const headerMain = useMemo(
|
||||
@ -66,17 +67,20 @@ function Expander ({ children, className = '', help, isOpen, isPadded, summary,
|
||||
onClick={toggleExpanded}
|
||||
>
|
||||
<div className='ui--Expander-summary-header'>
|
||||
{help && <LabelHelp help={help}/>}
|
||||
{hasContent
|
||||
? <Icon icon={isExpanded ? 'angle-double-down' : 'angle-double-right'} />
|
||||
: withDot
|
||||
? <Icon icon='circle' />
|
||||
: undefined
|
||||
}{headerMain || t<string>('Details')}
|
||||
{help && (
|
||||
<LabelHelp
|
||||
help={help}
|
||||
icon={helpIcon}
|
||||
/>
|
||||
)}
|
||||
{headerMain || t<string>('Details')}
|
||||
{headerSub && (
|
||||
<div className='ui--Expander-summary-header-sub'>{headerSub}</div>
|
||||
)}
|
||||
</div>
|
||||
{headerSub && (
|
||||
<div className='ui--Expander-summary-sub'>{headerSub}</div>
|
||||
)}
|
||||
{hasContent &&
|
||||
<Icon icon={isExpanded ? 'caret-up' : 'caret-down'} />
|
||||
}
|
||||
</div>
|
||||
{hasContent && (isExpanded || withHidden) && (
|
||||
<div className='ui--Expander-content'>{children}</div>
|
||||
@ -117,22 +121,31 @@ export default React.memo(styled(Expander)`
|
||||
min-width: 13.5rem;
|
||||
overflow: hidden;
|
||||
|
||||
.ui--Expander-summary-header > .ui--FormatBalance {
|
||||
min-width: 11rem;
|
||||
}
|
||||
|
||||
> div {
|
||||
.ui--Expander-summary-header {
|
||||
display: inline-block;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.ui--Icon {
|
||||
margin-right: 0.5rem;
|
||||
margin-left: 0.75rem;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.ui--Expander-summary-sub {
|
||||
.ui--LabelHelp {
|
||||
.ui--Icon {
|
||||
margin-left: 0;
|
||||
margin-right: 0.5rem;
|
||||
vertical-align: text-bottom;
|
||||
}
|
||||
}
|
||||
|
||||
.ui--Expander-summary-header-sub {
|
||||
font-size: 1rem;
|
||||
opacity: 0.6;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
}
|
||||
`);
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { IconName } from '@fortawesome/fontawesome-svg-core';
|
||||
import React, { useState } from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
@ -11,18 +12,19 @@ import Tooltip from './Tooltip';
|
||||
|
||||
interface Props {
|
||||
help: React.ReactNode;
|
||||
icon?: IconName;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
let id = 0;
|
||||
|
||||
function LabelHelp ({ className = '', help }: Props): React.ReactElement<Props> {
|
||||
function LabelHelp ({ className = '', help, icon = 'question-circle' }: Props): React.ReactElement<Props> {
|
||||
const [trigger] = useState(`label-help-${++id}`);
|
||||
|
||||
return (
|
||||
<div className={classes('ui--LabelHelp', className)}>
|
||||
<Icon
|
||||
icon='question-circle'
|
||||
icon={icon}
|
||||
tooltip={trigger}
|
||||
/>
|
||||
<Tooltip
|
||||
|
||||
@ -85,10 +85,12 @@ export default React.memo(styled(Body)`
|
||||
}
|
||||
|
||||
&.expand {
|
||||
text-align: left;
|
||||
&:not(.left) {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.ui--Expander+.ui--Expander {
|
||||
margin-top: 0.5rem;
|
||||
margin-top: 0.375rem;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -80,6 +80,10 @@ export default React.memo(styled(Head)`
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
&.expand {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
&.isClickable {
|
||||
border-bottom: 2px solid transparent;
|
||||
cursor: pointer;
|
||||
|
||||
@ -53,7 +53,6 @@ function PaymentInfo ({ accountId, className = '', extrinsic }: Props): React.Re
|
||||
Fees of <span className='highlight'>{formatBalance(dispatchInfo.partialFee, { withSiFull: true })}</span> will be applied to the submission
|
||||
</Trans>
|
||||
}
|
||||
withDot
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user