Adjust popup & tooltip spacing (#8741)

This commit is contained in:
Jaco 2023-01-10 06:36:00 +02:00 committed by GitHub
parent 9098225538
commit 0fa680789b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 82 deletions

View File

@ -278,36 +278,31 @@ function createBalanceItems (formatIndex: number, lookup: Record<string, string>
}
value={deriveBalances.vestedBalance}
>
<Tooltip
text={
<>
<Tooltip trigger={`${address}-vested-trigger`}>
<div>
{formatBalance(deriveBalances.vestedClaimable, { forceUnit: '-' })}
<div className='faded'>{t('available to be unlocked')}</div>
</div>
{allVesting.map(({ endBlock, locked, perBlock, vested }, index) => (
<div
className='inner'
key={`item:${index}`}
>
<div>
{formatBalance(deriveBalances.vestedClaimable, { forceUnit: '-' })}
<div className='faded'>{t('available to be unlocked')}</div>
{formatBalance(vested, { forceUnit: '-' })}
<div className='faded'>{t('of {{locked}} vested', { replace: { locked: formatBalance(locked, { forceUnit: '-' }) } })}</div>
</div>
{allVesting.map(({ endBlock, locked, perBlock, vested }, index) => (
<div
className='inner'
key={`item:${index}`}
>
<div>
{formatBalance(vested, { forceUnit: '-' })}
<div className='faded'>{t('of {{locked}} vested', { replace: { locked: formatBalance(locked, { forceUnit: '-' }) } })}</div>
</div>
<div>
<BlockToTime value={endBlock.sub(bestNumber)} />
<div className='faded'>{t('until block')} {formatNumber(endBlock)}</div>
</div>
<div>
{formatBalance(perBlock)}
<div className='faded'>{t('per block')}</div>
</div>
</div>
))}
</>
}
trigger={`${address}-vested-trigger`}
/>
<div>
<BlockToTime value={endBlock.sub(bestNumber)} />
<div className='faded'>{t('until block')} {formatNumber(endBlock)}</div>
</div>
<div>
{formatBalance(perBlock)}
<div className='faded'>{t('per block')}</div>
</div>
</div>
))}
</Tooltip>
</FormatBalance>
</React.Fragment>
);
@ -328,17 +323,19 @@ function createBalanceItems (formatIndex: number, lookup: Record<string, string>
icon='info-circle'
tooltip={`${address}-locks-trigger`}
/>
<Tooltip
text={deriveBalances.lockedBreakdown.map(({ amount, id, reasons }, index): React.ReactNode => (
<div key={index}>
<Tooltip trigger={`${address}-locks-trigger`}>
{deriveBalances.lockedBreakdown.map(({ amount, id, reasons }, index): React.ReactNode => (
<div
className='row'
key={index}
>
{amount?.isMax()
? t<string>('everything')
: formatBalance(amount, { forceUnit: '-' })
}{id && <div className='faded'>{lookupLock(lookup, id)}</div>}<div className='faded'>{reasons.toString()}</div>
</div>
))}
trigger={`${address}-locks-trigger`}
/>
</Tooltip>
</>
}
value={isAllLocked ? 'all' : deriveBalances.lockedBalance}
@ -359,15 +356,14 @@ function createBalanceItems (formatIndex: number, lookup: Record<string, string>
icon='info-circle'
tooltip={`${address}-named-reserves-trigger`}
/>
<Tooltip
text={allReserves.map(({ amount, id }, index): React.ReactNode => (
<Tooltip trigger={`${address}-named-reserves-trigger`}>
{allReserves.map(({ amount, id }, index): React.ReactNode => (
<div key={index}>
{formatBalance(amount, { forceUnit: '-' })
}{id && <div className='faded'>{lookupLock(lookup, id)}</div>}
</div>
))}
trigger={`${address}-named-reserves-trigger`}
/>
</Tooltip>
</>
)
: <IconVoid />
@ -457,9 +453,12 @@ function createBalanceItems (formatIndex: number, lookup: Record<string, string>
icon='clock'
tooltip={`${address}-conviction-locks-trigger`}
/>
<Tooltip
text={convictionLocks.map(({ endBlock, locked, refId, total }, index): React.ReactNode => (
<div key={index}>
<Tooltip trigger={`${address}-conviction-locks-trigger`}>
{convictionLocks.map(({ endBlock, locked, refId, total }, index): React.ReactNode => (
<div
className='row'
key={index}
>
<div className='nowrap'>#{refId.toString()} {formatBalance(total, { forceUnit: '-' })} {locked}</div>
<div className='faded nowrap'>{
endBlock.eq(BN_MAX_INTEGER)
@ -474,8 +473,7 @@ function createBalanceItems (formatIndex: number, lookup: Record<string, string>
}</div>
</div>
))}
trigger={`${address}-conviction-locks-trigger`}
/>
</Tooltip>
</>
}
value={max}

View File

@ -119,8 +119,8 @@ function DemocracyLocks ({ className = '', value }: Props): React.ReactElement<P
}
value={maxBalance}
/>
<Tooltip
text={sorted.map(({ details, headers }, index): React.ReactNode => (
<Tooltip trigger={trigger}>
{sorted.map(({ details, headers }, index): React.ReactNode => (
<div
className='row'
key={index}
@ -131,8 +131,7 @@ function DemocracyLocks ({ className = '', value }: Props): React.ReactElement<P
<div className='faded'>{details}</div>
</div>
))}
trigger={trigger}
/>
</Tooltip>
</div>
);
}

View File

@ -1,31 +1,28 @@
// Copyright 2017-2023 @polkadot/react-components authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { PopupWindowProps } from './types';
import type { PopupWindowProps as Props } from './types';
import React, { useMemo } from 'react';
import React from 'react';
import { createPortal } from 'react-dom';
import styled, { css } from 'styled-components';
import { usePopupWindow } from '@polkadot/react-hooks/usePopupWindow';
function PopupWindow ({ children, className = '', position, triggerRef, windowRef }: PopupWindowProps) {
const { pointerStyle, renderCoords } = usePopupWindow(windowRef, triggerRef, position);
const style = useMemo(
() => ({
transform: `translate3d(${renderCoords.x}px, ${renderCoords.y}px, 0)`,
zIndex: 1000
}),
[renderCoords]
);
function PopupWindow ({ children, className = '', position, triggerRef, windowRef }: Props): React.ReactElement<Props> {
const { pointerStyle, renderCoords: { x, y } } = usePopupWindow(windowRef, triggerRef, position);
return createPortal(
<div
className={`${className} ${pointerStyle}Pointer`}
data-testid='popup-window'
ref={windowRef}
style={style}
style={
(x && y && {
transform: `translate3d(${x}px, ${y}px, 0)`,
zIndex: 1000
}) || undefined
}
>
{children}
</div>,
@ -47,7 +44,7 @@ export default React.memo(styled(PopupWindow)`
z-index: -1;
&::before {
bottom: -0.45rem;
bottom: -0.5rem;
box-shadow: 1px 1px 0 0 #bababc;
position: absolute;
right: 50%;
@ -55,11 +52,11 @@ export default React.memo(styled(PopupWindow)`
${({ position }) => position === 'left' && css`
left: unset;
right: 0.8rem;
right: 0.75rem;
`}
${({ position }) => position === 'right' && css`
left: 0.8rem;
left: 0.75rem;
right: unset;
`}
@ -75,7 +72,7 @@ export default React.memo(styled(PopupWindow)`
&.bottomPointer::before {
box-shadow: -1px -1px 0 0 #bababc;
top: -0.45rem;
top: -0.5rem;
bottom: unset;
}

View File

@ -77,8 +77,8 @@ function StakingUnbonding ({ className = '', iconPosition = 'left', stakingInfo
/>
)}
<FormatBalance value={total} />
<Tooltip
text={mapped.map(([{ value }, eras, blocks], index): React.ReactNode => (
<Tooltip trigger={trigger}>
{mapped.map(([{ value }, eras, blocks], index): React.ReactNode => (
<div
className='row'
key={index}
@ -97,8 +97,7 @@ function StakingUnbonding ({ className = '', iconPosition = 'left', stakingInfo
</div>
</div>
))}
trigger={trigger}
/>
</Tooltip>
{iconPosition === 'right' && (
<Icon
className='right'

View File

@ -13,22 +13,15 @@ function rootElement () {
}
interface Props {
children?: React.ReactNode;
className?: string;
clickable?: boolean;
dataFor?: string;
effect?: 'solid' | 'float';
offset?: {
bottom?: number;
left?: number;
right?: number;
top?: number;
};
isCickable?: boolean;
place?: 'bottom' | 'top' | 'right' | 'left';
text: React.ReactNode;
text?: React.ReactNode;
trigger: string;
}
function Tooltip ({ className = '', clickable = false, effect = 'solid', offset, place = 'top', text, trigger }: Props): React.ReactElement<Props> | null {
function Tooltip ({ children, className = '', isCickable = false, place, text, trigger }: Props): React.ReactElement<Props> | null {
const [tooltipContainer] = useState(
typeof document === 'undefined'
? {} as HTMLElement // This hack is required for server side rendering
@ -48,19 +41,24 @@ function Tooltip ({ className = '', clickable = false, effect = 'solid', offset,
return createPortal(
<ReactTooltip
className={`ui--Tooltip ${className}`}
clickable={clickable}
effect={effect}
clickable={isCickable}
effect='solid'
id={trigger}
offset={offset}
place={place}
>
{className?.includes('address') ? <div>{text}</div> : text}
<div className='tooltipSpacer'>
{text}{children}
</div>
</ReactTooltip>,
tooltipContainer
);
}
export default React.memo(styled(Tooltip)`
.tooltipSpacer {
padding: 0.375rem;
}
> div {
overflow: hidden;
}