added UI for tag handling

This commit is contained in:
or-else
2018-03-03 18:24:13 -08:00
parent ea55bde395
commit bacaadfd86
+51 -13
View File
@@ -795,7 +795,8 @@
componentWillReceiveProps: function(newProps) { componentWillReceiveProps: function(newProps) {
this.setState({ this.setState({
sortedChips: this.sortChips(newProps.chips, newProps.required), sortedChips: this.sortChips(newProps.chips, newProps.required),
chipIndex: this.indexChips(newProps.chips) chipIndex: this.indexChips(newProps.chips),
input: ''
}); });
}, },
@@ -856,6 +857,10 @@
this.removeChipAt(at); this.removeChipAt(at);
} }
} }
} else if (e.key === 'Enter') {
if (this.props.onEnter) {
this.props.onEnter(this.state.input);
}
} }
}, },
@@ -870,6 +875,7 @@
onCancel={instance.handleChipCancel} onCancel={instance.handleChipCancel}
avatar={makeImageUrl(item.public ? item.public.photo : null)} avatar={makeImageUrl(item.public ? item.public.photo : null)}
title={item.public ? item.public.fn : undefined} title={item.public ? item.public.fn : undefined}
noAvatar={instance.props.avatarDisabled}
topic={item.user} topic={item.user}
required={item.user === instance.props.required} required={item.user === instance.props.required}
index={count} index={count}
@@ -900,15 +906,19 @@
}, },
render: function() { render: function() {
var title = this.props.title || this.props.topic;
return ( return (
<div className="chip"> <div className="chip">
<div className="avatar-box"> {this.props.noAvatar ?
<LetterTile <span className="spacer" /> :
avatar={this.props.avatar || true} <div className="avatar-box">
topic={this.props.topic} <LetterTile
title={this.props.title} /> avatar={this.props.avatar || true}
</div> topic={this.props.topic}
<span>{this.props.title}</span> title={this.props.title} />
</div>
}
<span>{title}</span>
{this.props.onCancel && !this.props.required ? {this.props.onCancel && !this.props.required ?
<a href="#" onClick={this.handleCancel} >&times;</a> <a href="#" onClick={this.handleCancel} >&times;</a>
: <span className="spacer" />} : <span className="spacer" />}
@@ -1354,6 +1364,7 @@
avatar: null, avatar: null,
login: undefined, login: undefined,
password: undefined, password: undefined,
tagInput: '',
tags: [] tags: []
}; };
}, },
@@ -1387,13 +1398,34 @@
this.props.onSubmit(null, vcard(this.state.fullName, img)); this.props.onSubmit(null, vcard(this.state.fullName, img));
}, },
handleTagInput: function(text) {
// Check if user entered ',', ' ' or ';'
if (text.length > 0) {
var last = text[text.length-1];
if (last == ',' || last == ' ' || last == ';') {
this.handleAddTag(text.substr(0, text.length-1));
}
}
console.log(text);
},
handleAddTag: function(tag) {
var tags = this.state.tags.slice(0);
tags.push(tag);
this.setState({tags: tags});
console.log("add tag", tag, tags);
},
handleRemoveTag: function(tag, index) {
var tags = this.state.tags.slice(0);
tags.splice(index, 1);
this.setState({tags: tags});
console.log("tag removed", tag, index, tags);
},
render: function() { render: function() {
var tags = []; var tags = [];
var instance = this;
this.state.tags.map(function(tag) { this.state.tags.map(function(tag) {
if (tags.length > 0) { tags.push({user: tag});
tags.push(" ");
}
tags.push(<tt key={tag}>{tag}</tt>);
}); });
if (tags.length == 0) { if (tags.length == 0) {
tags = <i>none</i>; tags = <i>none</i>;
@@ -1441,7 +1473,13 @@
<div className="hr" /> <div className="hr" />
<div className="panel-form-column"> <div className="panel-form-column">
<div><label className="small">Tags (user discovery):</label></div> <div><label className="small">Tags (user discovery):</label></div>
<div className="quoted">{tags}</div> <ChipInput
chips={tags}
avatarDisabled={true}
prompt="Add tags"
onEnter={this.handleAddTag}
onChipRemoved={this.handleRemoveTag}
filterFunc={this.handleTagInput} />
</div> </div>
</div> </div>
); );