Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Working add/remove fields for var. length #3314
Browse files Browse the repository at this point in the history
  • Loading branch information
ngotchac committed Nov 14, 2016
1 parent 046d2f2 commit 9e2214c
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 27 deletions.
92 changes: 69 additions & 23 deletions js/src/modals/DeployContract/DetailsStep/detailsStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import React, { Component, PropTypes } from 'react';
import { MenuItem } from 'material-ui';
import { range } from 'lodash';

import IconButton from 'material-ui/IconButton';
import AddIcon from 'material-ui/svg-icons/content/add';
import RemoveIcon from 'material-ui/svg-icons/content/remove';

import { AddressSelect, Form, Input, InputAddressSelect, Select } from '../../../ui';
import { validateAbi } from '../../../util/validation';

Expand All @@ -43,37 +47,65 @@ class TypedInput extends Component {
const { accounts, label, value = param.default } = this.props;
const { subtype, length } = param;

if (length) {
const inputs = range(length).map((_, index) => {
const onChange = (inputValue) => {
const newValues = [].concat(this.props.value);
newValues[index] = inputValue;
this.props.onChange(newValues);
};

return (
<TypedInput
key={ `${subtype.type}_${index}` }
onChange={ onChange }
accounts={ accounts }
param={ subtype }
value={ value[index] }
/>
);
});
const fixedLength = !!length;

const inputs = range(length || value.length).map((_, index) => {
const onChange = (inputValue) => {
const newValues = [].concat(this.props.value);
newValues[index] = inputValue;
this.props.onChange(newValues);
};

return (
<div className={ styles.inputs }>
<label>{ label }</label>
{ inputs }
</div>
<TypedInput
key={ `${subtype.type}_${index}` }
onChange={ onChange }
accounts={ accounts }
param={ subtype }
value={ value[index] }
/>
);
}
});

return (
<div className={ styles.inputs }>
<label>{ label }</label>
{ fixedLength ? null : this.renderLength() }
{ inputs }
</div>
);
}

return this.renderType(type);
}

renderLength () {
const style = {
width: 16,
height: 16
};

return (
<div>
<IconButton
iconStyle={ style }
style={ style }
onClick={ this.onAddField }
>
<AddIcon />
</IconButton>

<IconButton
iconStyle={ style }
style={ style }
onClick={ this.onRemoveField }
>
<RemoveIcon />
</IconButton>
</div>
);
}

renderType (type) {
if (type === ADDRESS_TYPE) {
return this.renderAddress();
Expand Down Expand Up @@ -184,6 +216,20 @@ class TypedInput extends Component {
this.props.onChange(value);
}

onAddField = () => {
const { value, onChange, param } = this.props;
const newValues = [].concat(value, param.subtype.default);

onChange(newValues);
}

onRemoveField = () => {
const { value, onChange } = this.props;
const newValues = value.slice(0, -1);

onChange(newValues);
}

}

export default class DetailsStep extends Component {
Expand Down
4 changes: 2 additions & 2 deletions js/src/modals/DeployContract/deployContract.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
}

.inputs {
padding-top: 18px;
padding-top: 2px;

label {
line-height: 22px;
pointer-events: none;
color: rgba(255, 255, 255, 0.498039);
-webkit-user-select: none;
font-size: 12px;
top: 8px;
top: 11px;
position: relative;
}
}
4 changes: 4 additions & 0 deletions js/src/ui/Form/AddressSelect/addressSelect.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
position: absolute;
left: 0;
top: 35px;

&.noLabel {
top: 11px;
}
}

.paddedInput input {
Expand Down
10 changes: 8 additions & 2 deletions js/src/ui/Form/AddressSelect/addressSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,21 @@ export default class AddressSelect extends Component {
}

renderIdentityIcon (inputValue) {
const { error, value } = this.props;
const { error, value, label } = this.props;

if (error || !inputValue || value.length !== 42) {
return null;
}

const classes = [ styles.icon ];

if (!label) {
classes.push(styles.noLabel);
}

return (
<IdentityIcon
className={ styles.icon }
className={ classes.join(' ') }
inline center
address={ value } />
);
Expand Down

0 comments on commit 9e2214c

Please sign in to comment.