diff --git a/packages/ui-app/src/Dropdown.tsx b/packages/ui-app/src/Dropdown.tsx index 7c895de585..dfb4bfc9b3 100644 --- a/packages/ui-app/src/Dropdown.tsx +++ b/packages/ui-app/src/Dropdown.tsx @@ -30,6 +30,7 @@ type Props = BareProps & { renderLabel?: (item: any) => any, transform?: (value: any) => any, value?: any, + withEllipsis?: boolean, withLabel?: boolean }; @@ -60,7 +61,7 @@ export default class Dropdown extends React.PureComponent> } render () { - const { allowAdd = false, className, defaultValue, dropdownClassName, help, isButton, isDisabled, isError, isMultiple, label, onSearch, options, placeholder, renderLabel, style, withLabel, value } = this.props; + const { allowAdd = false, className, defaultValue, dropdownClassName, help, isButton, isDisabled, isError, isMultiple, label, onSearch, options, placeholder, renderLabel, style, withEllipsis, withLabel, value } = this.props; const dropdown = ( extends React.PureComponent> help={help} label={label} style={style} + withEllipsis={withEllipsis} withLabel={withLabel} > {dropdown} diff --git a/packages/ui-app/src/Input.tsx b/packages/ui-app/src/Input.tsx index f34be2da68..66907cf9d6 100644 --- a/packages/ui-app/src/Input.tsx +++ b/packages/ui-app/src/Input.tsx @@ -39,7 +39,8 @@ type Props = BareProps & { tabIndex?: number, type?: Input$Type, value?: any, - withLabel?: boolean + withLabel?: boolean, + withEllipsis?: boolean }; type State = { @@ -93,7 +94,7 @@ export default class Input extends React.PureComponent { }; render () { - const { autoFocus = false, children, className, defaultValue, help, icon, isEditable = false, isAction = false, isDisabled = false, isError = false, isHidden = false, label, max, maxLength, min, name, placeholder, style, tabIndex, type = 'text', value, withLabel } = this.props; + const { autoFocus = false, children, className, defaultValue, help, icon, isEditable = false, isAction = false, isDisabled = false, isError = false, isHidden = false, label, max, maxLength, min, name, placeholder, style, tabIndex, type = 'text', value, withEllipsis, withLabel } = this.props; return ( { help={help} label={label} style={style} + withEllipsis={withEllipsis} withLabel={withLabel} > , + withEllipsis?: boolean, withLabel?: boolean }; @@ -121,7 +122,7 @@ class InputAddress extends React.PureComponent { } render () { - const { className, defaultValue, help, hideAddress = false, isDisabled = false, isError, isMultiple, label, options, optionsAll, placeholder, type = DEFAULT_TYPE, style, withLabel } = this.props; + const { className, defaultValue, help, hideAddress = false, isDisabled = false, isError, isMultiple, label, options, optionsAll, placeholder, type = DEFAULT_TYPE, style, withEllipsis, withLabel } = this.props; const { value } = this.state; const hasOptions = (options && options.length !== 0) || (optionsAll && Object.keys(optionsAll[type]).length !== 0); @@ -180,6 +181,7 @@ class InputAddress extends React.PureComponent { ? undefined : value } + withEllipsis={withEllipsis} withLabel={withLabel} /> ); diff --git a/packages/ui-app/src/InputBalance.tsx b/packages/ui-app/src/InputBalance.tsx index b93132296c..53ed1bd262 100644 --- a/packages/ui-app/src/InputBalance.tsx +++ b/packages/ui-app/src/InputBalance.tsx @@ -20,6 +20,7 @@ type Props = BareProps & { onChange?: (value?: BN) => void, placeholder?: string, value?: BN | string, + withEllipsis?: boolean, withLabel?: boolean, withMax?: boolean }; @@ -28,7 +29,7 @@ const DEFAULT_BITLENGTH = BitLengthOption.CHAIN_SPEC as BitLength; export default class InputBalance extends React.PureComponent { render () { - const { autoFocus, className, defaultValue, help, isDisabled, isError, label, maxValue, onChange, placeholder, style, value, withLabel, withMax } = this.props; + const { autoFocus, className, defaultValue, help, isDisabled, isError, label, maxValue, onChange, placeholder, style, value, withEllipsis, withLabel, withMax } = this.props; return ( { placeholder={placeholder} style={style} value={value} + withEllipsis={withEllipsis} withLabel={withLabel} withMax={withMax} /> diff --git a/packages/ui-app/src/InputFile.tsx b/packages/ui-app/src/InputFile.tsx index b0e7572fd3..901cf3b332 100644 --- a/packages/ui-app/src/InputFile.tsx +++ b/packages/ui-app/src/InputFile.tsx @@ -23,6 +23,7 @@ type Props = BareProps & WithTranslation & { label: React.ReactNode, onChange?: (contents: Uint8Array, name: string) => void, placeholder?: React.ReactNode | null, + withEllipsis?: boolean, withLabel?: boolean }; @@ -43,13 +44,14 @@ class InputFile extends React.PureComponent { state: State = {}; render () { - const { accept, className, clearContent, help, isDisabled, isError = false, label, placeholder, t, withLabel } = this.props; + const { accept, className, clearContent, help, isDisabled, isError = false, label, placeholder, t, withEllipsis, withLabel } = this.props; const { file } = this.state; return ( void, placeholder?: string, value?: BN | string, + withEllipsis?: boolean, withLabel?: boolean, withMax?: boolean }; @@ -108,8 +109,8 @@ class InputNumber extends React.PureComponent { onPaste={this.onPaste} placeholder={t('Positive number')} style={style} - value={value} type='text' + value={value} > {(withMax && !!maxValue) && this.renderMaxButton()} {isSi && this.renderSiDropdown()} diff --git a/packages/ui-app/src/Labelled.tsx b/packages/ui-app/src/Labelled.tsx index 8050f2dc3c..324a9117a2 100644 --- a/packages/ui-app/src/Labelled.tsx +++ b/packages/ui-app/src/Labelled.tsx @@ -18,7 +18,8 @@ type Props = BareProps & { isSmall?: boolean, label?: React.ReactNode, children: React.ReactNode, - withLabel?: boolean + withLabel?: boolean, + withEllipsis?: boolean }; type State = { @@ -32,6 +33,12 @@ const defaultLabel: any = (// node? const Wrapper = styled.div` display: block; + .withEllipsis { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + } + > label { margin: 0.25rem 0 0 0; padding-right: 0.5rem; @@ -88,32 +95,6 @@ export default class Labelled extends React.PureComponent { }; } - toggleTooltip () { - const { tooltipOpen } = this.state; - this.setState({ tooltipOpen: !tooltipOpen }); - } - - renderLabel () { - const { help, label = defaultLabel } = this.props; - const { tooltipOpen } = this.state; - - return help - ? - {label} - this.toggleTooltip()} - onMouseOut={() => this.toggleTooltip()} - /> - {tooltipOpen && ( - - {help} - )} - - : {label}; - } render () { const { className, children, isSmall, isHidden, style, withLabel = true } = this.props; @@ -137,4 +118,36 @@ export default class Labelled extends React.PureComponent { ); } + + private renderLabel () { + const { help, label = defaultLabel, withEllipsis } = this.props; + const { tooltipOpen } = this.state; + const displayLabel = withEllipsis + ? {label} + : label; + + return help + ? + {displayLabel} + + {tooltipOpen && ( + + {help} + + )} + + : {displayLabel}; + } + + private toggleTooltip = () => { + this.setState(({ tooltipOpen }: State) => ({ + tooltipOpen: !tooltipOpen + })); + } } diff --git a/packages/ui-params/src/Param/Account.tsx b/packages/ui-params/src/Param/Account.tsx index 021b116c90..03ad9702e7 100644 --- a/packages/ui-params/src/Param/Account.tsx +++ b/packages/ui-params/src/Param/Account.tsx @@ -29,6 +29,7 @@ export default class Account extends React.PureComponent { label={label} onChange={this.onChange} placeholder='5...' + withEllipsis withLabel={withLabel} /> diff --git a/packages/ui-params/src/Param/Amount.tsx b/packages/ui-params/src/Param/Amount.tsx index 7347134a5a..c22a1e6266 100644 --- a/packages/ui-params/src/Param/Amount.tsx +++ b/packages/ui-params/src/Param/Amount.tsx @@ -41,6 +41,7 @@ export default class Amount extends React.PureComponent { ? 'text' : 'number' } + withEllipsis withLabel={withLabel} /> diff --git a/packages/ui-params/src/Param/Balance.tsx b/packages/ui-params/src/Param/Balance.tsx index e85c9dc85d..fc7db3981a 100644 --- a/packages/ui-params/src/Param/Balance.tsx +++ b/packages/ui-params/src/Param/Balance.tsx @@ -29,6 +29,7 @@ class Balance extends React.PureComponent { isError={isError} label={label} onChange={this.onChange} + withEllipsis withLabel={withLabel} /> diff --git a/packages/ui-params/src/Param/Base.tsx b/packages/ui-params/src/Param/Base.tsx index e5a49f3504..b468a3266b 100644 --- a/packages/ui-params/src/Param/Base.tsx +++ b/packages/ui-params/src/Param/Base.tsx @@ -30,6 +30,7 @@ export default class Base extends React.PureComponent { {children} diff --git a/packages/ui-params/src/Param/BaseBytes.tsx b/packages/ui-params/src/Param/BaseBytes.tsx index 60edc00a0c..5b39b0713f 100644 --- a/packages/ui-params/src/Param/BaseBytes.tsx +++ b/packages/ui-params/src/Param/BaseBytes.tsx @@ -48,6 +48,7 @@ export default class BaseBytes extends React.PureComponent { onChange={this.onChange} placeholder='0x...' type='text' + withEllipsis withLabel={withLabel} > {children} diff --git a/packages/ui-params/src/Param/Bool.tsx b/packages/ui-params/src/Param/Bool.tsx index f18ee4b32c..5bb6a04086 100644 --- a/packages/ui-params/src/Param/Bool.tsx +++ b/packages/ui-params/src/Param/Bool.tsx @@ -34,6 +34,7 @@ export default class BoolParam extends React.PureComponent { label={label} options={options} onChange={this.onChange} + withEllipsis withLabel={withLabel} /> diff --git a/packages/ui-params/src/Param/File.tsx b/packages/ui-params/src/Param/File.tsx index 8bee048e1d..fcbef86328 100644 --- a/packages/ui-params/src/Param/File.tsx +++ b/packages/ui-params/src/Param/File.tsx @@ -34,6 +34,7 @@ export default class File extends React.PureComponent { label={label} onChange={onChange} placeholder={placeholder} + withEllipsis withLabel={withLabel} /> diff --git a/packages/ui-params/src/Param/KeyValueArray.tsx b/packages/ui-params/src/Param/KeyValueArray.tsx index ced3a2b467..ebfd700d5d 100644 --- a/packages/ui-params/src/Param/KeyValueArray.tsx +++ b/packages/ui-params/src/Param/KeyValueArray.tsx @@ -73,27 +73,32 @@ class KeyValueArray extends React.PureComponent { const pairs = value as Vector; return ( - - {pairs.map(({ key, value }) => { - const keyHex = u8aToHex(key.toU8a(true)); + <> + + + + + {pairs.map(({ key, value }) => { + const keyHex = u8aToHex(key.toU8a(true)); - return ( - - ); - })} - + return ( + + ); + })} + + > ); }