element-web/src/components/views/avatars/GroupAvatar.tsx

63 lines
1.9 KiB
TypeScript
Raw Normal View History

/*
Copyright 2017 Vector Creations 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.
*/
import React from 'react';
2019-12-21 00:13:46 +03:00
import {MatrixClientPeg} from '../../../MatrixClientPeg';
2020-07-07 00:42:46 +03:00
import BaseAvatar from './BaseAvatar';
export interface IProps {
groupId?: string,
groupName?: string,
groupAvatarUrl?: string,
width?: number,
height?: number,
resizeMethod?: string,
onClick?: React.MouseEventHandler,
}
export default class GroupAvatar extends React.Component<IProps> {
public static defaultProps = {
width: 36,
height: 36,
resizeMethod: 'crop',
};
getGroupAvatarUrl() {
return MatrixClientPeg.get().mxcUrlToHttp(
this.props.groupAvatarUrl,
this.props.width,
this.props.height,
this.props.resizeMethod,
);
2020-07-07 00:42:46 +03:00
}
2020-07-07 00:42:46 +03:00
render() {
// extract the props we use from props so we can pass any others through
2017-07-07 12:41:59 +03:00
// should consider adding this as a global rule in js-sdk?
/*eslint no-unused-vars: ["error", { "ignoreRestSiblings": true }]*/
2017-11-01 20:12:22 +03:00
const {groupId, groupAvatarUrl, groupName, ...otherProps} = this.props;
return (
<BaseAvatar
2017-11-01 20:12:22 +03:00
name={groupName || this.props.groupId[1]}
idName={this.props.groupId}
url={this.getGroupAvatarUrl()}
{...otherProps}
/>
);
2020-07-07 00:42:46 +03:00
}
}