element-web/src/components/views/elements/AddressTile.js

94 lines
3 KiB
JavaScript
Raw Normal View History

2016-09-05 16:28:08 +00:00
/*
Copyright 2015, 2016 OpenMarket Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
'use strict';
var React = require('react');
var classNames = require('classnames');
2016-09-05 16:28:08 +00:00
var sdk = require("../../../index");
var Avatar = require('../../../Avatar');
module.exports = React.createClass({
displayName: 'AddressTile',
propTypes: {
user: React.PropTypes.object.isRequired,
canDismiss: React.PropTypes.bool,
onDismissed: React.PropTypes.func,
justified: React.PropTypes.bool,
networkName: React.PropTypes.string,
networkUrl: React.PropTypes.string,
2016-09-05 16:28:08 +00:00
},
getDefaultProps: function() {
return {
canDismiss: false,
onDismissed: function() {}, // NOP
justified: false,
networkName: "",
networkUrl: "",
2016-09-05 16:28:08 +00:00
};
},
render: function() {
var BaseAvatar = sdk.getComponent('avatars.BaseAvatar');
var TintableSvg = sdk.getComponent("elements.TintableSvg");
2016-09-06 12:07:06 +00:00
var userId = this.props.user.userId;
var name = this.props.user.displayName || userId;
2016-09-05 16:28:08 +00:00
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>
);
}
2016-09-05 16:28:08 +00:00
var dismiss;
if (this.props.canDismiss) {
dismiss = (
<div className="mx_AddressTile_dismiss" onClick={this.props.onDismissed} >
<TintableSvg src="img/icon-address-delete.svg" width="9" height="9" />
</div>
);
}
var nameClasses = classNames({
"mx_AddressTile_name": true,
"mx_AddressTile_justified": this.props.justified,
});
var idClasses = classNames({
"mx_AddressTile_id": true,
"mx_AddressTile_justified": this.props.justified,
});
2016-09-05 16:28:08 +00:00
return (
<div className="mx_AddressTile">
{ network }
2016-09-05 16:28:08 +00:00
<div className="mx_AddressTile_avatar">
2016-09-06 12:07:06 +00:00
<BaseAvatar width={25} height={25} name={name} title={name} url={imgUrl} />
2016-09-05 16:28:08 +00:00
</div>
<div className={nameClasses}>{ name }</div>
<div className={idClasses}>{ userId }</div>
2016-09-05 16:28:08 +00:00
{ dismiss }
</div>
);
}
});