Adjust global field toggle locations (#8803)

* Adjust global field toggle locations

* Additional adjustments

* Additional build fixes

* labelExtra Toggle formatting

* Wrap Option

* Remove "Some" label

* None for Option empty

* Remove debug log

* Adjust
This commit is contained in:
Jaco 2023-01-15 10:13:38 +02:00 committed by GitHub
parent 6159735e12
commit 4d0bc5cbfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 238 additions and 234 deletions

View File

@ -5,7 +5,6 @@ import type { Data, Option } from '@polkadot/types';
import type { Registration } from '@polkadot/types/interfaces';
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import { Input, InputBalance, Modal, Toggle, TxButton } from '@polkadot/react-components';
import { getAddressMeta } from '@polkadot/react-components/util';
@ -20,12 +19,6 @@ interface Props {
onClose: () => void;
}
interface WrapProps {
children: React.ReactNode;
onChange: (isChecked: boolean) => void;
value: boolean;
}
interface ValueState {
info: Record<string, unknown>;
okAll: boolean;
@ -46,22 +39,6 @@ function setData (data: Data, setActive: null | ((isActive: boolean) => void), s
}
}
function WrapToggle ({ children, onChange, value }: WrapProps): React.ReactElement<WrapProps> {
const { t } = useTranslation();
return (
<div className='toggle-Wrap'>
{children}
<Toggle
isOverlay
label={t<string>('include field')}
onChange={onChange}
value={value}
/>
</div>
);
}
function checkValue (hasValue: boolean, value: string | null | undefined, minLength: number, includes: string[], excludes: string[], starting: string[], notStarting: string[] = WHITESPACE, notEnding: string[] = WHITESPACE): boolean {
return !hasValue || (
!!value &&
@ -143,7 +120,7 @@ function IdentityMain ({ address, className = '', onClose }: Props): React.React
}, [hasEmail, hasLegal, hasRiot, hasTwitter, hasWeb, valDisplay, valEmail, valLegal, valRiot, valTwitter, valWeb]);
return (
<StyledModal
<Modal
className={className}
header={t<string>('Register identity')}
onClose={onClose}
@ -158,75 +135,85 @@ function IdentityMain ({ address, className = '', onClose }: Props): React.React
placeholder={t('My On-Chain Name')}
value={valDisplay}
/>
<WrapToggle
onChange={setHasLegal}
value={hasLegal}
>
<Input
isDisabled={!hasLegal}
isError={!okLegal}
label={t<string>('legal name')}
maxLength={32}
onChange={setValLegal}
placeholder={t('Full Legal Name')}
value={hasLegal ? valLegal : '<none>'}
/>
</WrapToggle>
<WrapToggle
onChange={setHasEmail}
value={hasEmail}
>
<Input
isDisabled={!hasEmail}
isError={!okEmail}
label={t<string>('email')}
maxLength={32}
onChange={setValEmail}
placeholder={t('somebody@example.com')}
value={hasEmail ? valEmail : '<none>'}
/>
</WrapToggle>
<WrapToggle
onChange={setHasWeb}
value={hasWeb}
>
<Input
isDisabled={!hasWeb}
isError={!okWeb}
label={t<string>('web')}
maxLength={32}
onChange={setValWeb}
placeholder={t('https://example.com')}
value={hasWeb ? valWeb : '<none>'}
/>
</WrapToggle>
<WrapToggle
onChange={setHasTwitter}
value={hasTwitter}
>
<Input
isDisabled={!hasTwitter}
isError={!okTwitter}
label={t<string>('twitter')}
onChange={setValTwitter}
placeholder={t('@YourTwitterName')}
value={hasTwitter ? valTwitter : '<none>'}
/>
</WrapToggle>
<WrapToggle
onChange={setHasRiot}
value={hasRiot}
>
<Input
isDisabled={!hasRiot}
isError={!okRiot}
label={t<string>('riot name')}
maxLength={32}
onChange={setValRiot}
placeholder={t('@yourname:matrix.org')}
value={hasRiot ? valRiot : '<none>'}
/>
</WrapToggle>
<Input
isDisabled={!hasLegal}
isError={!okLegal}
label={t<string>('legal name')}
labelExtra={
<Toggle
label={t<string>('include field')}
onChange={setHasLegal}
value={hasLegal}
/>
}
maxLength={32}
onChange={setValLegal}
placeholder={t('Full Legal Name')}
value={hasLegal ? valLegal : '<none>'}
/>
<Input
isDisabled={!hasEmail}
isError={!okEmail}
label={t<string>('email')}
labelExtra={
<Toggle
label={t<string>('include field')}
onChange={setHasEmail}
value={hasEmail}
/>
}
maxLength={32}
onChange={setValEmail}
placeholder={t('somebody@example.com')}
value={hasEmail ? valEmail : '<none>'}
/>
<Input
isDisabled={!hasWeb}
isError={!okWeb}
label={t<string>('web')}
labelExtra={
<Toggle
label={t<string>('include field')}
onChange={setHasWeb}
value={hasWeb}
/>
}
maxLength={32}
onChange={setValWeb}
placeholder={t('https://example.com')}
value={hasWeb ? valWeb : '<none>'}
/>
<Input
isDisabled={!hasTwitter}
isError={!okTwitter}
label={t<string>('twitter')}
labelExtra={
<Toggle
label={t<string>('include field')}
onChange={setHasTwitter}
value={hasTwitter}
/>
}
onChange={setValTwitter}
placeholder={t('@YourTwitterName')}
value={hasTwitter ? valTwitter : '<none>'}
/>
<Input
isDisabled={!hasRiot}
isError={!okRiot}
label={t<string>('riot name')}
labelExtra={
<Toggle
label={t<string>('include field')}
onChange={setHasRiot}
value={hasRiot}
/>
}
maxLength={32}
onChange={setValRiot}
placeholder={t('@yourname:matrix.org')}
value={hasRiot ? valRiot : '<none>'}
/>
<InputBalance
defaultValue={api.consts.identity?.basicDeposit}
isDisabled
@ -251,14 +238,8 @@ function IdentityMain ({ address, className = '', onClose }: Props): React.React
tx={api.tx.identity.setIdentity}
/>
</Modal.Actions>
</StyledModal>
</Modal>
);
}
const StyledModal = styled(Modal)`
.toggle-Wrap {
position: relative;
}
`;
export default React.memo(IdentityMain);

View File

@ -180,17 +180,17 @@ function Deploy ({ codeHash, constructorIndex = 0, onClose, setConstructorIndex
<Input
isDisabled={!withSalt}
label={t<string>('unique deployment salt')}
labelExtra={
<Toggle
label={t<string>('use deployment salt')}
onChange={setWithSalt}
value={withSalt}
/>
}
onChange={setSalt}
placeholder={t<string>('0x prefixed hex, e.g. 0x1234 or ascii data')}
value={withSalt ? salt : t<string>('<none>')}
>
<Toggle
isOverlay
label={t<string>('use deployment salt')}
onChange={setWithSalt}
value={withSalt}
/>
</Input>
/>
<InputMegaGas
weight={weight}
/>

View File

@ -52,12 +52,8 @@ function InputMegaGas ({ className, estimatedWeight, isCall, weight: { execution
? t<string>('max gas allowed (M, {{estimatedMg}} estimated)', { replace: { estimatedMg: estimatedMg.toString() } })
: t<string>('max gas allowed (M)')
}
onChange={isDisabled ? undefined : setMegaGas}
value={isDisabled ? undefined : ((isCall && withEstimate) ? BN_ZERO : megaGas)}
>
{(estimatedWeight || isCall) && (
labelExtra={(estimatedWeight || isCall) && (
<Toggle
isOverlay
label={
isCall
? t<string>('max read gas')
@ -67,7 +63,9 @@ function InputMegaGas ({ className, estimatedWeight, isCall, weight: { execution
value={withEstimate}
/>
)}
</InputNumber>
onChange={isDisabled ? undefined : setMegaGas}
value={isDisabled ? undefined : ((isCall && withEstimate) ? BN_ZERO : megaGas)}
/>
<div className='contracts--InputMegaGas-meter'>
{t<string>('{{executionTime}}s execution time', { replace: { executionTime: executionTime.toFixed(3) } })}{', '}
{t<string>('{{percentage}}% of block weight', { replace: { percentage: percentage.toFixed(2) } })}

View File

@ -7,9 +7,10 @@ import type { BN } from '@polkadot/util';
import React, { useState } from 'react';
import styled from 'styled-components';
import { InputAddress, InputBalance, Modal, Static, Toggle, TxButton } from '@polkadot/react-components';
import { InputAddress, InputBalance, Modal, Static, TxButton } from '@polkadot/react-components';
import { useApi } from '@polkadot/react-hooks';
import { BlockToTime } from '@polkadot/react-query';
import { BlockToTime, FormatBalance } from '@polkadot/react-query';
import { BN_ZERO } from '@polkadot/util';
import { useTranslation } from '../../translate';
import useUnbondDuration from '../useUnbondDuration';
@ -27,7 +28,6 @@ function Unbond ({ controllerId, onClose, stakingLedger, stashId }: Props): Reac
const bondedBlocks = useUnbondDuration();
const [maxBalance] = useState<BN | null>(() => stakingLedger?.active?.unwrap() || null);
const [maxUnbond, setMaxUnbond] = useState<BN | undefined>();
const [withMax, setWithMax] = useState(false);
return (
<StyledModal
@ -52,20 +52,17 @@ function Unbond ({ controllerId, onClose, stakingLedger, stashId }: Props): Reac
<InputBalance
autoFocus
defaultValue={maxBalance}
isDisabled={withMax}
key={`unbondAmount-${withMax.toString()}`}
label={t<string>('unbond amount')}
labelExtra={
<FormatBalance
label={<span className='label'>{t<string>('bonded')}</span>}
value={maxBalance}
/>
}
maxValue={maxBalance}
onChange={setMaxUnbond}
withMax
>
<Toggle
isOverlay
label={t<string>('all bonded')}
onChange={setWithMax}
value={withMax}
/>
</InputBalance>
/>
{bondedBlocks?.gtn(0) && (
<Static
label={t<string>('on-chain bonding duration')}
@ -79,10 +76,10 @@ function Unbond ({ controllerId, onClose, stakingLedger, stashId }: Props): Reac
<TxButton
accountId={controllerId}
icon='unlock'
isDisabled={!((withMax ? maxBalance : maxUnbond)?.gtn(0))}
isDisabled={!maxUnbond?.gt(BN_ZERO)}
label={t<string>('Unbond')}
onStart={onClose}
params={[withMax ? maxBalance : maxUnbond]}
params={[maxUnbond]}
tx={api.tx.staking.unbond}
/>
</Modal.Actions>

View File

@ -5,7 +5,7 @@ import type { BN } from '@polkadot/util';
import React, { useState } from 'react';
import { InputBalance, Modal, Static, Toggle, TxButton } from '@polkadot/react-components';
import { InputBalance, Modal, Static, TxButton } from '@polkadot/react-components';
import { useApi } from '@polkadot/react-hooks';
import { BlockToTime, FormatBalance } from '@polkadot/react-query';
@ -25,7 +25,6 @@ function Unbond ({ className, controllerId, maxUnbond, onClose, poolId }: Props)
const { t } = useTranslation();
const { api } = useApi();
const [amount, setAmount] = useState<BN | undefined>();
const [withMax, setWithMax] = useState(false);
const bondedBlocks = useUnbondDuration();
const isAmountError = !amount || !maxUnbond || amount.gt(maxUnbond);
@ -46,9 +45,7 @@ function Unbond ({ className, controllerId, maxUnbond, onClose, poolId }: Props)
<InputBalance
autoFocus
defaultValue={maxUnbond}
isDisabled={withMax}
isError={isAmountError}
key={`unbondAmount-${withMax.toString()}`}
label={t<string>('amount to unbond')}
labelExtra={
<FormatBalance
@ -59,14 +56,7 @@ function Unbond ({ className, controllerId, maxUnbond, onClose, poolId }: Props)
maxValue={maxUnbond}
onChange={setAmount}
withMax
>
<Toggle
isOverlay
label={t<string>('all bonded')}
onChange={setWithMax}
value={withMax}
/>
</InputBalance>
/>
{bondedBlocks?.gtn(0) && (
<Static
label={t<string>('on-chain bonding duration')}
@ -80,10 +70,10 @@ function Unbond ({ className, controllerId, maxUnbond, onClose, poolId }: Props)
<TxButton
accountId={controllerId}
icon='unlock'
isDisabled={!withMax && isAmountError}
isDisabled={isAmountError}
label={t<string>('Unbond')}
onStart={onClose}
params={[controllerId, withMax ? maxUnbond : amount]}
params={[controllerId, amount]}
tx={api.tx.nominationPools.unbond}
/>
</Modal.Actions>

View File

@ -21,7 +21,7 @@ import { compactStripLength, isHex, isNull, isUndefined, u8aToHex } from '@polka
import { useTranslation } from '../translate';
type ParamsType = { type: TypeDefExt }[];
type ParamsType = { name?: string, type: TypeDefExt }[];
interface KeyState {
defaultValues: RawParams | undefined | null;
@ -61,16 +61,18 @@ function expandParams (registry: Registry, st: StorageEntryTypeLatest, isIterabl
}
return types.map((str, index) => {
let name: string | undefined;
let type: TypeDefExt;
if (isIterable && index === (types.length - 1)) {
// name = 'entryKey';
type = getTypeDef(`Option<${str}>`);
type.withOptionActive = true;
} else {
type = getTypeDef(str);
}
return { type };
return { name, type };
});
}

View File

@ -50,17 +50,17 @@ function Sudo ({ className, isMine, sudoKey }: Props): React.ReactElement<Props>
isError={weight.eq(BN_ZERO)}
isZeroable={false}
label={t<string>('unchecked weight for this call')}
labelExtra={
<Toggle
className='sudoToggle'
label={t<string>('with weight override')}
onChange={toggleWithWeight}
value={withWeight}
/>
}
onChange={_onChangeWeight}
value={weight}
>
<Toggle
className='sudoToggle'
isOverlay
label={t<string>('with weight override')}
onChange={toggleWithWeight}
value={withWeight}
/>
</InputNumber>
/>
)}
<Button.Group>
<TxButton

View File

@ -17,6 +17,7 @@ export interface InputFilePropsBase {
isError?: boolean;
isFull?: boolean;
label: React.ReactNode;
labelExtra?: React.ReactNode;
placeholder?: React.ReactNode | null | false;
withEllipsis?: boolean;
withLabel?: boolean;
@ -58,7 +59,7 @@ function convertResult (result: ArrayBuffer): Uint8Array {
return data;
}
function InputFile ({ accept, className = '', clearContent, isDisabled, isError = false, isFull, label, onChange, placeholder, withEllipsis, withLabel }: InputFileProps): React.ReactElement<InputFileProps> {
function InputFile ({ accept, className = '', clearContent, isDisabled, isError = false, isFull, label, labelExtra, onChange, placeholder, withEllipsis, withLabel }: InputFileProps): React.ReactElement<InputFileProps> {
const { t } = useTranslation();
const dropRef = createRef<DropzoneRef>();
const [file, setFile] = useState<FileState | undefined>();
@ -123,6 +124,7 @@ function InputFile ({ accept, className = '', clearContent, isDisabled, isError
<Labelled
isFull={isFull}
label={label}
labelExtra={labelExtra}
withEllipsis={withEllipsis}
withLabel={withLabel}
>

View File

@ -102,15 +102,27 @@ export default React.memo(styled(Labelled)`
&.isOuter {
margin: 0.25rem 0;
.labelExtra {
top: -0.125rem;
// right: 0;
}
}
.labelExtra {
color: var(--color-label);
font-size: var(--font-size-label);
font-weight: var(--font-weight-label);
position: absolute;
right: 1.25rem;
text-align: right;
text-transform: var(--text-transform-label);
top: 0.75rem;
z-index: 1;
> .ui--Toggle > label {
padding-right: 0 !important;
}
}
> .ui--Labelled-content {

View File

@ -7,7 +7,6 @@ import styled from 'styled-components';
interface Props {
className?: string;
isDisabled?: boolean;
isOverlay?: boolean;
isRadio?: boolean;
label: React.ReactNode;
onChange?: (isChecked: boolean) => void;
@ -15,7 +14,7 @@ interface Props {
value?: boolean;
}
function Toggle ({ className = '', isDisabled, isOverlay, isRadio, label, onChange, preventDefault, value }: Props): React.ReactElement<Props> {
function Toggle ({ className = '', isDisabled, isRadio, label, onChange, preventDefault, value }: Props): React.ReactElement<Props> {
const _onClick = useCallback(
(event: React.MouseEvent<HTMLDivElement, MouseEvent>): void => {
if (!isDisabled) {
@ -31,20 +30,20 @@ function Toggle ({ className = '', isDisabled, isOverlay, isRadio, label, onChan
);
return (
<div
className={`ui--Toggle${value ? ' isChecked' : ''}${isDisabled ? ' isDisabled' : ''}${isOverlay ? ' isOverlay' : ''}${isRadio ? ' isRadio' : ''} ${className}`}
<StyledDiv
className={`ui--Toggle${value ? ' isChecked' : ''}${isDisabled ? ' isDisabled' : ''}${isRadio ? ' isRadio' : ''} ${className}`}
onClick={_onClick}
>
{label && <label>{label}</label>}
<div className={`ui--Toggle-Slider${isRadio ? ' highlight--before-border' : ''}`} />
</div>
</StyledDiv>
);
}
export default React.memo(styled(Toggle)`
const StyledDiv = styled.div`
> label {
display: inline-block;
margin: 0 0.5rem;
margin: 0 0.5rem !important;
}
> label,
@ -100,10 +99,6 @@ export default React.memo(styled(Toggle)`
width: 1.5rem;
}
}
`;
&.isOverlay {
bottom: 1.375rem;
position: absolute;
right: 3.5rem;
}
`);
export default React.memo(Toggle);

View File

@ -27,7 +27,7 @@ function isValidAddress (value?: string | null): boolean {
}
function Account (props: Props): React.ReactElement<Props> {
const { className = '', defaultValue: { value }, isDisabled, isError, isInOption, label, onChange, type, withLabel } = props;
const { className = '', defaultValue: { value }, isDisabled, isError, label, onChange, type, withLabel } = props;
const [defaultValue] = useState(() => (value as string)?.toString());
const _onChange = useCallback(
@ -51,7 +51,6 @@ function Account (props: Props): React.ReactElement<Props> {
<InputAddress
className='full'
defaultValue={defaultValue}
hideAddress={isInOption}
isDisabled={isDisabled}
isError={isError}
isInput

View File

@ -15,17 +15,19 @@ interface Props {
isDisabled?: boolean;
isOuter?: boolean;
label?: React.ReactNode;
labelExtra?: React.ReactNode;
size?: Size;
withLabel?: boolean;
}
function Base ({ children, className = '', isOuter, label, size = 'full', withLabel }: Props): React.ReactElement<Props> {
function Base ({ children, className = '', isOuter, label, labelExtra, size = 'full', withLabel }: Props): React.ReactElement<Props> {
return (
<Bare className={className}>
<Labelled
className={size}
isOuter
label={label}
labelExtra={labelExtra}
withEllipsis
withLabel={withLabel}
>

View File

@ -20,8 +20,8 @@ interface Props {
defaultValue: RawParam;
isDisabled?: boolean;
isError?: boolean;
isInOption?: boolean;
label?: React.ReactNode;
labelExtra?: React.ReactNode;
length?: number;
name?: string;
onChange?: RawParamOnChange;
@ -67,7 +67,7 @@ function convertInput (value: string): [boolean, boolean, Uint8Array] {
: [value === '0x', false, new Uint8Array([])];
}
function BaseBytes ({ asHex, children, className = '', defaultValue: { value }, isDisabled, isError, label, length = -1, onChange, onEnter, onEscape, size = 'full', validate = defaultValidate, withCopy, withLabel, withLength }: Props): React.ReactElement<Props> {
function BaseBytes ({ asHex, children, className = '', defaultValue: { value }, isDisabled, isError, label, labelExtra, length = -1, onChange, onEnter, onEscape, size = 'full', validate = defaultValidate, withCopy, withLabel, withLength }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const [defaultValue] = useState(
(): string | undefined => {
@ -122,6 +122,7 @@ function BaseBytes ({ asHex, children, className = '', defaultValue: { value },
isDisabled={isDisabled}
isError={isError || !isValid}
label={label}
labelExtra={labelExtra}
onChange={_onChange}
onEnter={onEnter}
onEscape={onEscape}

View File

@ -33,7 +33,7 @@ function isValidAddress (value: string | null | undefined, isEthereum: boolean):
}
function BasicAccountIdBase (props: Props): React.ReactElement<Props> {
const { bytesLength, className = '', defaultValue: { value }, isDisabled, isError, isInOption, label, onChange, withLabel } = props;
const { bytesLength, className = '', defaultValue: { value }, isDisabled, isError, label, onChange, withLabel } = props;
const [defaultValue] = useState(() => (value as string)?.toString());
const _onChange = useCallback(
@ -52,7 +52,6 @@ function BasicAccountIdBase (props: Props): React.ReactElement<Props> {
className='full'
defaultValue={defaultValue}
forceIconType={bytesLength === 20 ? 'ethereum' : 'substrate'}
hideAddress={isInOption}
isDisabled={isDisabled}
isError={isError}
isInput

View File

@ -12,7 +12,7 @@ import { useTranslation } from '../translate';
import BaseBytes from './BaseBytes';
import File from './File';
function Bytes ({ className = '', defaultValue, isDisabled, isError, isInOption, label, name, onChange, onEnter, onEscape, type, withLabel }: Props): React.ReactElement<Props> {
function Bytes ({ className = '', defaultValue, isDisabled, isError, label, name, onChange, onEnter, onEscape, type, withLabel }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const [isValid, setIsValid] = useState(false);
const [isFileDrop, setFileInput] = useState(false);
@ -31,6 +31,14 @@ function Bytes ({ className = '', defaultValue, isDisabled, isError, isInOption,
[onChange]
);
const toggleLabel = !isDisabled && (
<Toggle
label={t<string>('file upload')}
onChange={setFileInput}
value={isFileDrop}
/>
);
return (
<div className={`${className} --relative`}>
{!isDisabled && isFileDrop
@ -39,6 +47,7 @@ function Bytes ({ className = '', defaultValue, isDisabled, isError, isInOption,
isDisabled={isDisabled}
isError={isError || !isValid}
label={label}
labelExtra={toggleLabel}
onChange={_onChangeFile}
withLabel={withLabel}
/>
@ -48,8 +57,8 @@ function Bytes ({ className = '', defaultValue, isDisabled, isError, isInOption,
defaultValue={defaultValue}
isDisabled={isDisabled}
isError={isError}
isInOption={isInOption}
label={label}
labelExtra={toggleLabel}
length={-1}
name={name}
onChange={onChange}
@ -61,14 +70,7 @@ function Bytes ({ className = '', defaultValue, isDisabled, isError, isInOption,
/>
)
}
{!isDisabled && !isInOption && (
<Toggle
isOverlay
label={t<string>('file upload')}
onChange={setFileInput}
value={isFileDrop}
/>
)}
{}
</div>
);
}

View File

@ -13,18 +13,20 @@ interface Props {
isDisabled?: boolean;
isError?: boolean;
label?: React.ReactNode;
labelExtra?: React.ReactNode;
onChange?: (contents: Uint8Array) => void;
placeholder?: string;
withLabel?: boolean;
}
function File ({ className = '', isDisabled, isError = false, label, onChange, placeholder, withLabel }: Props): React.ReactElement<Props> {
function File ({ className = '', isDisabled, isError = false, label, labelExtra, onChange, placeholder, withLabel }: Props): React.ReactElement<Props> {
return (
<Bare className={className}>
<InputFile
isDisabled={isDisabled}
isError={isError}
label={label}
labelExtra={labelExtra}
onChange={onChange}
placeholder={placeholder}
withEllipsis

View File

@ -12,7 +12,7 @@ import { useTranslation } from '../translate';
import BaseBytes from './BaseBytes';
import File from './File';
function Hash256 ({ className = '', defaultValue, isDisabled, isError, isInOption, label, name, onChange, onEnter, onEscape, registry, type, withLabel }: Props): React.ReactElement<Props> {
function Hash256 ({ className = '', defaultValue, isDisabled, isError, label, name, onChange, onEnter, onEscape, registry, type, withLabel }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const [isFileDrop, setFileInput] = useState(false);
const [placeholder, setPlaceholder] = useState<string | null>(null);
@ -38,6 +38,14 @@ function Hash256 ({ className = '', defaultValue, isDisabled, isError, isInOptio
[setFileInput, setPlaceholder]
);
const toggleLabel = !isDisabled && (
<Toggle
label={t<string>('hash a file')}
onChange={_setFileInput}
value={isFileDrop}
/>
);
return (
<div className={className}>
{!isDisabled && isFileDrop
@ -46,6 +54,7 @@ function Hash256 ({ className = '', defaultValue, isDisabled, isError, isInOptio
isDisabled={isDisabled}
isError={isError}
label={label}
labelExtra={toggleLabel}
onChange={_onChangeFile}
placeholder={placeholder || undefined}
withLabel={withLabel}
@ -58,6 +67,7 @@ function Hash256 ({ className = '', defaultValue, isDisabled, isError, isInOptio
isDisabled={isDisabled}
isError={isError}
label={label}
labelExtra={toggleLabel}
length={32}
name={name}
onChange={onChange}
@ -67,15 +77,8 @@ function Hash256 ({ className = '', defaultValue, isDisabled, isError, isInOptio
withCopy={isDisabled}
withLabel={withLabel}
/>
)}
{!isDisabled && !isInOption && (
<Toggle
isOverlay
label={t<string>('hash a file')}
onChange={_setFileInput}
value={isFileDrop}
/>
)}
)
}
</div>
);
}

View File

@ -10,15 +10,19 @@ import { Toggle } from '@polkadot/react-components';
import { Option } from '@polkadot/types';
import { isU8a, u8aConcat } from '@polkadot/util';
import Holder from '../Holder';
import { useTranslation } from '../translate';
import Base from './Base';
import Param from './index';
import Static from './Static';
const DEF_VALUE = { isValid: true, value: undefined };
const OPT_PREFIX = new Uint8Array([1]);
function OptionDisplay ({ className = '', defaultValue: _defaultValue, isDisabled, name, onChange, onEnter, onEscape, registry, type: { sub, withOptionActive } }: Props): React.ReactElement<Props> {
function OptionDisplay ({ className = '', defaultValue: _defaultValue, isDisabled, label, onChange, onEnter, onEscape, registry, type: { sub, withOptionActive }, withLabel }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const [isActive, setIsActive] = useState(() => withOptionActive || !!(_defaultValue && _defaultValue.value instanceof Option && _defaultValue.value.isSome) || false);
const [defaultValue] = useState(
() => isActive || isDisabled
? _defaultValue && (
@ -48,29 +52,43 @@ function OptionDisplay ({ className = '', defaultValue: _defaultValue, isDisable
return (
<div className={`${className} --relative`}>
<Param
defaultValue={
isActive
? defaultValue
: DEF_VALUE}
isDisabled={isDisabled || !isActive}
isInOption
isOptional={!isActive && !isDisabled}
name={name}
onChange={_onChange}
onEnter={onEnter}
onEscape={onEscape}
registry={registry}
type={sub as TypeDef}
<Base
className='--relative'
label={label}
labelExtra={!isDisabled && (
<Toggle
label={t<string>('include option')}
onChange={setIsActive}
value={isActive}
/>
)}
withLabel={withLabel}
/>
{!isDisabled && (
<Toggle
isOverlay
label={t<string>('include option')}
onChange={setIsActive}
value={isActive}
/>
)}
<Holder>
<div className='ui--Params-Content'>
{isActive
? (
<Param
defaultValue={defaultValue}
isDisabled={isDisabled || !isActive}
isOptional={!isActive && !isDisabled}
onChange={_onChange}
onEnter={onEnter}
onEscape={onEscape}
registry={registry}
type={sub as TypeDef}
/>
)
: (
<Static
defaultValue={DEF_VALUE}
isOptional
label='None'
/>
)
}
</div>
</Holder>
</div>
);
}

View File

@ -19,11 +19,12 @@ interface Props {
childrenPre?: React.ReactNode;
className?: string;
defaultValue: RawParam;
isOptional?: boolean;
label?: React.ReactNode;
withLabel?: boolean;
}
function StaticParam ({ asHex, children, childrenPre, className = '', defaultValue, label }: Props): React.ReactElement<Props> {
function StaticParam ({ asHex, children, childrenPre, className = '', defaultValue, isOptional, label }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const value = useMemo(
@ -45,7 +46,7 @@ function StaticParam ({ asHex, children, childrenPre, className = '', defaultVal
<Static
className='full'
label={label}
value={<pre>{value || t<string>('<empty>')}</pre>}
value={<pre>{value || (isOptional ? <>&nbsp;</> : t<string>('<empty>'))}</pre>}
/>
{children}
</StyledBare>

View File

@ -22,7 +22,7 @@ function formatJSON (input: string): string {
.replace(/^{_alias: {.*}, /, '{');
}
function Param ({ className = '', defaultValue, isDisabled, isError, isInOption, isOptional, name, onChange, onEnter, onEscape, overrides, registry, type }: Props): React.ReactElement<Props> | null {
function Param ({ className = '', defaultValue, isDisabled, isError, isOptional, name, onChange, onEnter, onEscape, overrides, registry, type }: Props): React.ReactElement<Props> | null {
const Component = useMemo(
() => findComponent(registry, type, overrides),
[registry, type, overrides]
@ -37,11 +37,11 @@ function Param ({ className = '', defaultValue, isDisabled, isError, isInOption,
? getTypeDef(registry.createType(type.type).toRawType())
: type
);
const fmtType = formatJSON(`${isDisabled && isInOption ? 'Option<' : ''}${inner}${isDisabled && isInOption ? '>' : ''}`);
const fmtType = formatJSON(inner);
return `${isUndefined(name) ? '' : `${name}: `}${fmtType}${type.typeName && !fmtType.includes(type.typeName) ? ` (${type.typeName})` : ''}`;
},
[isDisabled, isInOption, name, registry, type]
[name, registry, type]
);
if (!Component) {
@ -52,7 +52,8 @@ function Param ({ className = '', defaultValue, isDisabled, isError, isInOption,
? (
<Static
defaultValue={defaultValue}
label={label}
isOptional
label='None'
/>
)
: (
@ -61,7 +62,6 @@ function Param ({ className = '', defaultValue, isDisabled, isError, isInOption,
defaultValue={defaultValue}
isDisabled={isDisabled}
isError={isError}
isInOption={isInOption}
key={`${name || 'unknown'}:${label}`}
label={label}
name={name}

View File

@ -56,18 +56,18 @@ function Unlock ({ address, className, error, onChange, onEnter, tabIndex }: Pro
autoFocus
isError={!!error}
label={t<string>('unlock account with password')}
labelExtra={
<Toggle
label={t<string>('unlock for {{expiry}} min', { replace: { expiry: UNLOCK_MINS } })}
onChange={setIsUnlockCached}
value={isUnlockCached}
/>
}
onChange={setPassword}
onEnter={onEnter}
tabIndex={tabIndex}
value={password}
>
<Toggle
isOverlay
label={t<string>('unlock for {{expiry}} min', { replace: { expiry: UNLOCK_MINS } })}
onChange={setIsUnlockCached}
value={isUnlockCached}
/>
</Password>
/>
</StyledModalColumns>
);
}