Fixes for Option<enum/struct> rendering (#1653)
* Fixes for Option<enum/struct> rendering * Update Struct.tsx * Update Struct.tsx
This commit is contained in:
parent
f33b4b7f91
commit
8148047e96
@ -13,12 +13,13 @@ import { classes } from './util';
|
||||
interface Props extends BareProps {
|
||||
help?: React.ReactNode;
|
||||
isHidden?: boolean;
|
||||
isOuter?: boolean;
|
||||
isSmall?: boolean;
|
||||
label?: React.ReactNode;
|
||||
labelExtra?: React.ReactNode;
|
||||
children: React.ReactNode;
|
||||
withLabel?: boolean;
|
||||
withEllipsis?: boolean;
|
||||
withLabel?: boolean;
|
||||
}
|
||||
|
||||
const defaultLabel: React.ReactNode = (
|
||||
@ -48,17 +49,19 @@ const Wrapper = styled.div`
|
||||
&:not(.label-small) {
|
||||
padding-left: 2rem;
|
||||
|
||||
> label,
|
||||
.labelExtra {
|
||||
position: absolute;
|
||||
text-align: left;
|
||||
top: 0.5rem;
|
||||
z-index: 1;
|
||||
}
|
||||
&:not(.label-outer) {
|
||||
> label,
|
||||
.labelExtra {
|
||||
position: absolute;
|
||||
text-align: left;
|
||||
top: 0.5rem;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
> label {
|
||||
left: 3.55rem;
|
||||
text-align: left;
|
||||
> label {
|
||||
left: 3.55rem;
|
||||
text-align: left;
|
||||
}
|
||||
}
|
||||
|
||||
.labelExtra {
|
||||
@ -116,7 +119,7 @@ const Wrapper = styled.div`
|
||||
}
|
||||
`;
|
||||
|
||||
export default function Labelled ({ className, children, help, isSmall, isHidden, label = defaultLabel, labelExtra, style, withEllipsis, withLabel = true }: Props): React.ReactElement<Props> | null {
|
||||
export default function Labelled ({ className, children, help, isHidden, isOuter, isSmall, label = defaultLabel, labelExtra, style, withEllipsis, withLabel = true }: Props): React.ReactElement<Props> | null {
|
||||
if (isHidden) {
|
||||
return null;
|
||||
} else if (!withLabel) {
|
||||
@ -127,7 +130,7 @@ export default function Labelled ({ className, children, help, isSmall, isHidden
|
||||
|
||||
return (
|
||||
<Wrapper
|
||||
className={classes('ui--Labelled', isSmall ? 'label-small' : '', className)}
|
||||
className={classes('ui--Labelled', isSmall && 'label-small', isOuter && 'label-outer', className)}
|
||||
style={style}
|
||||
>
|
||||
<label>
|
||||
|
||||
@ -5,13 +5,14 @@
|
||||
import { BareProps } from '@polkadot/react-components/types';
|
||||
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { classes } from '@polkadot/react-components/util';
|
||||
|
||||
interface Props extends BareProps {
|
||||
children: React.ReactNode;
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
export default function Bare ({ children, className, style }: Props): React.ReactElement<Props> {
|
||||
function Bare ({ children, className, style }: Props): React.ReactElement<Props> {
|
||||
return (
|
||||
<div
|
||||
className={classes('ui--row', className)}
|
||||
@ -21,3 +22,7 @@ export default function Bare ({ children, className, style }: Props): React.Reac
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default styled(Bare)`
|
||||
position: relative;
|
||||
`;
|
||||
|
||||
@ -11,7 +11,7 @@ import { Labelled } from '@polkadot/react-components';
|
||||
import Bare from './Bare';
|
||||
|
||||
interface Props extends BareProps {
|
||||
children: React.ReactNode;
|
||||
children?: React.ReactNode;
|
||||
isDisabled?: boolean;
|
||||
label?: React.ReactNode;
|
||||
size?: Size;
|
||||
@ -26,6 +26,7 @@ export default function Base ({ children, className, label, size = 'full', style
|
||||
>
|
||||
<Labelled
|
||||
className={size}
|
||||
isOuter
|
||||
label={label}
|
||||
withEllipsis
|
||||
withLabel={withLabel}
|
||||
|
||||
@ -38,16 +38,21 @@ export default class EnumParam extends React.PureComponent<Props, State> {
|
||||
return null;
|
||||
}
|
||||
|
||||
const sub = getTypeDef(createType(type as any).toRawType()).sub as TypeDef[];
|
||||
const options = sub.map(({ name }): Option => ({
|
||||
text: name,
|
||||
value: name
|
||||
}));
|
||||
const def = prevState.def || sub[0];
|
||||
const rawType = createType(type as any).toRawType();
|
||||
const typeDef = getTypeDef(rawType);
|
||||
|
||||
// HACK This is a quick hack to allow `Option<struct>` ... this is certainly not the right
|
||||
// place for this, so we need to move it (even the detection just sucks)... also see struct
|
||||
const sub = typeDef.type.startsWith('Option<')
|
||||
? (typeDef.sub as TypeDef).sub as TypeDef[]
|
||||
: typeDef.sub as TypeDef[];
|
||||
|
||||
return {
|
||||
def,
|
||||
options,
|
||||
def: prevState.def || sub[0],
|
||||
options: sub.map(({ name }): Option => ({
|
||||
text: name,
|
||||
value: name
|
||||
})),
|
||||
sub,
|
||||
type
|
||||
};
|
||||
|
||||
@ -28,7 +28,14 @@ export default class StructParam extends React.PureComponent<Props, State> {
|
||||
return null;
|
||||
}
|
||||
|
||||
const defs = getTypeDef(createType(type as any).toRawType()).sub as TypeDef[];
|
||||
const rawType = createType(type as any).toRawType();
|
||||
const typeDef = getTypeDef(rawType);
|
||||
|
||||
// HACK This is a quick hack to allow `Option<struct>` ... this is certainly not the right
|
||||
// place for this, so we need to move it (even the detection just sucks)... also see enum
|
||||
const defs = typeDef.type.startsWith('Option<')
|
||||
? (typeDef.sub as TypeDef).sub as TypeDef[]
|
||||
: typeDef.sub as TypeDef[];
|
||||
|
||||
return {
|
||||
defs,
|
||||
@ -53,9 +60,7 @@ export default class StructParam extends React.PureComponent<Props, State> {
|
||||
label={label}
|
||||
style={style}
|
||||
withLabel={withLabel}
|
||||
>
|
||||
|
||||
</Base>
|
||||
/>
|
||||
<Params
|
||||
onChange={this.onChangeParams}
|
||||
params={params}
|
||||
|
||||
@ -12,7 +12,7 @@ import translate from '@polkadot/react-components/translate';
|
||||
import { isUndefined } from '@polkadot/util';
|
||||
|
||||
import getInitValue from '../initValue';
|
||||
import Bare from './Bare';
|
||||
import Base from './Base';
|
||||
import findComponent from './findComponent';
|
||||
|
||||
interface Props extends BareProps, WithTranslation {}
|
||||
@ -53,7 +53,7 @@ class Vector extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
public render (): React.ReactNode {
|
||||
const { className, isDisabled, onEnter, style, type, withLabel } = this.props;
|
||||
const { className, isDisabled, label, onEnter, style, type, withLabel } = this.props;
|
||||
const { Component, values } = this.state;
|
||||
const subType = type.sub as TypeDef;
|
||||
|
||||
@ -62,9 +62,11 @@ class Vector extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
return (
|
||||
<Bare
|
||||
<Base
|
||||
className={className}
|
||||
label={label}
|
||||
style={style}
|
||||
withLabel={withLabel}
|
||||
>
|
||||
{values.map((value, index): React.ReactNode => (
|
||||
this.isParamHidden(index)
|
||||
@ -84,7 +86,7 @@ class Vector extends React.PureComponent<Props, State> {
|
||||
)
|
||||
))}
|
||||
{this.renderButtons()}
|
||||
</Bare>
|
||||
</Base>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -22,10 +22,6 @@
|
||||
.ui--Params-Content {
|
||||
box-sizing: border-box;
|
||||
padding: 0 0 0 1.75rem;
|
||||
|
||||
label .withEllipsis {
|
||||
white-space: normal;
|
||||
}
|
||||
}
|
||||
|
||||
.ui--Param-text {
|
||||
|
||||
@ -63,7 +63,7 @@ export function Transfer ({ amount, balances_all = ZERO_BALANCE, fees, onChange,
|
||||
isCreation,
|
||||
isNoEffect
|
||||
});
|
||||
}, [balances_all, fees]);
|
||||
}, [amount, balances_all, fees]);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user