Mouse actions on the queryList added, as well as better queryListElement styling
This commit is contained in:
parent
dd186dd612
commit
ca3910f5a8
2 changed files with 62 additions and 7 deletions
|
@ -57,6 +57,7 @@ module.exports = React.createClass({
|
||||||
queryList: [],
|
queryList: [],
|
||||||
addressSelected: false,
|
addressSelected: false,
|
||||||
selected: 0,
|
selected: 0,
|
||||||
|
hover: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -70,9 +71,10 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
componentDidUpdate: function() {
|
componentDidUpdate: function() {
|
||||||
// As the user scrolls with the arrow keys keep the selected item
|
// As the user scrolls with the arrow keys keep the selected item
|
||||||
// at the top of the window. Each item is 29px high.
|
// at the top of the window.
|
||||||
if (this.scrollElement) {
|
if (this.scrollElement && !this.state.hover) {
|
||||||
this.scrollElement.scrollTop = (this.state.selected * 29) - 29;
|
var elementHeight = this.queryListElement.getBoundingClientRect().height;
|
||||||
|
this.scrollElement.scrollTop = (this.state.selected * elementHeight) - elementHeight;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -107,13 +109,19 @@ module.exports = React.createClass({
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (this.state.selected > 0) {
|
if (this.state.selected > 0) {
|
||||||
this.setState({ selected: this.state.selected - 1 });
|
this.setState({
|
||||||
|
selected: this.state.selected - 1,
|
||||||
|
hover : false,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else if (e.keyCode === 40) { // down arrow
|
} else if (e.keyCode === 40) { // down arrow
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (this.state.selected < this._maxSelected(this.state.queryList)) {
|
if (this.state.selected < this._maxSelected(this.state.queryList)) {
|
||||||
this.setState({ selected: this.state.selected + 1 });
|
this.setState({
|
||||||
|
selected: this.state.selected + 1,
|
||||||
|
hover : false,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else if (e.keyCode === 13) { // enter
|
} else if (e.keyCode === 13) { // enter
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
@ -123,6 +131,7 @@ module.exports = React.createClass({
|
||||||
user: this.state.queryList[this.state.selected],
|
user: this.state.queryList[this.state.selected],
|
||||||
addressSelected: true,
|
addressSelected: true,
|
||||||
queryList: [],
|
queryList: [],
|
||||||
|
hover : false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,11 +170,40 @@ module.exports = React.createClass({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onClick: function(index) {
|
||||||
|
var self = this;
|
||||||
|
return function() {
|
||||||
|
self.setState({
|
||||||
|
user: self.state.queryList[index],
|
||||||
|
addressSelected: true,
|
||||||
|
queryList: [],
|
||||||
|
hover: false,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
onMouseEnter: function(index) {
|
||||||
|
var self = this;
|
||||||
|
return function() {
|
||||||
|
self.setState({
|
||||||
|
selected: index,
|
||||||
|
hover: true,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
onMouseLeave: function() {
|
||||||
|
this.setState({ hover : false });
|
||||||
|
},
|
||||||
|
|
||||||
createQueryListTiles: function() {
|
createQueryListTiles: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var TintableSvg = sdk.getComponent("elements.TintableSvg");
|
||||||
var AddressTile = sdk.getComponent("elements.AddressTile");
|
var AddressTile = sdk.getComponent("elements.AddressTile");
|
||||||
var maxSelected = this._maxSelected(this.state.queryList);
|
var maxSelected = this._maxSelected(this.state.queryList);
|
||||||
var queryList = [];
|
var queryList = [];
|
||||||
|
|
||||||
|
// Only create the query elements if there are queries
|
||||||
if (this.state.queryList.length > 0) {
|
if (this.state.queryList.length > 0) {
|
||||||
for (var i = 0; i <= maxSelected; i++) {
|
for (var i = 0; i <= maxSelected; i++) {
|
||||||
var classes = classNames({
|
var classes = classNames({
|
||||||
|
@ -173,9 +211,12 @@ module.exports = React.createClass({
|
||||||
"mx_ChatInviteDialog_selected": this.state.selected === i,
|
"mx_ChatInviteDialog_selected": this.state.selected === i,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// NOTE: Defaulting to "vector" as the network, until the network backend stuff is done
|
||||||
|
// Saving the queryListElement so we can use it to work out, in the componentDidUpdate
|
||||||
|
// method, how far to scroll when using the arrow keys
|
||||||
queryList.push(
|
queryList.push(
|
||||||
<div className={classes} key={i} >
|
<div className={classes} onClick={this.onClick(i)} onMouseEnter={this.onMouseEnter(i)} onMouseLeave={this.onMouseLeave} key={i} ref={(ref) => { this.queryListElement = ref; }} >
|
||||||
<AddressTile user={this.state.queryList[i]} justified={true} />
|
<AddressTile user={this.state.queryList[i]} justified={true} networkName="vector" networkUrl="img/search-icon-vector.svg" />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,8 @@ module.exports = React.createClass({
|
||||||
canDismiss: React.PropTypes.bool,
|
canDismiss: React.PropTypes.bool,
|
||||||
onDismissed: React.PropTypes.func,
|
onDismissed: React.PropTypes.func,
|
||||||
justified: React.PropTypes.bool,
|
justified: React.PropTypes.bool,
|
||||||
|
networkName: React.PropTypes.string,
|
||||||
|
networkUrl: React.PropTypes.string,
|
||||||
},
|
},
|
||||||
|
|
||||||
getDefaultProps: function() {
|
getDefaultProps: function() {
|
||||||
|
@ -36,6 +38,8 @@ module.exports = React.createClass({
|
||||||
canDismiss: false,
|
canDismiss: false,
|
||||||
onDismissed: function() {}, // NOP
|
onDismissed: function() {}, // NOP
|
||||||
justified: false,
|
justified: false,
|
||||||
|
networkName: "",
|
||||||
|
networkUrl: "",
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -46,6 +50,15 @@ module.exports = React.createClass({
|
||||||
var name = this.props.user.displayName || userId;
|
var name = this.props.user.displayName || userId;
|
||||||
var imgUrl = Avatar.avatarUrlForUser(this.props.user, 25, 25, "crop");
|
var imgUrl = Avatar.avatarUrlForUser(this.props.user, 25, 25, "crop");
|
||||||
|
|
||||||
|
var network;
|
||||||
|
if (this.props.networkUrl !== "") {
|
||||||
|
network = (
|
||||||
|
<div className="mx_AddressTile_network">
|
||||||
|
<BaseAvatar width={25} height={25} name={this.props.networkName} title="vector" url={this.props.networkUrl} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
var dismiss;
|
var dismiss;
|
||||||
if (this.props.canDismiss) {
|
if (this.props.canDismiss) {
|
||||||
dismiss = (
|
dismiss = (
|
||||||
|
@ -67,6 +80,7 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="mx_AddressTile">
|
<div className="mx_AddressTile">
|
||||||
|
{ network }
|
||||||
<div className="mx_AddressTile_avatar">
|
<div className="mx_AddressTile_avatar">
|
||||||
<BaseAvatar width={25} height={25} name={name} title={name} url={imgUrl} />
|
<BaseAvatar width={25} height={25} name={name} title={name} url={imgUrl} />
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue