mattermost-mobile/app/components/tag.js
Malik 6287706452
Mm 32502 guest identification 2 (#5198)
* Add Guest Experience Test Cases

* Added testIDs and cleaned up tests

* Minor refactor

Co-authored-by: Furqan Malik <furqanmalik@Furqans-MacBook-Pro.local>
Co-authored-by: Malik <abc@abcs-MBP.phub.net.cable.rogers.com>
Co-authored-by: Furqan Malik <furqanmalik@Furqans-MBP.phub.net.cable.rogers.com>
Co-authored-by: Joseph Baylon <joseph.baylon@mattermost.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-03-15 08:25:19 -07:00

94 lines
2.5 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {PureComponent} from 'react';
import {View, ViewPropTypes} from 'react-native';
import PropTypes from 'prop-types';
import FormattedText from 'app/components/formatted_text';
import {changeOpacity, makeStyleSheetFromTheme} from 'app/utils/theme';
import {t} from 'app/utils/i18n';
export function BotTag(props) {
const id = t('post_info.bot');
const defaultMessage = 'BOT';
return (
<Tag
id={id}
defaultMessage={defaultMessage}
{...props}
/>
);
}
export function GuestTag(props) {
const id = t('post_info.guest');
const defaultMessage = 'GUEST';
return (
<Tag
id={id}
defaultMessage={defaultMessage}
{...props}
/>
);
}
export default class Tag extends PureComponent {
static propTypes = {
id: PropTypes.string.isRequired,
defaultMessage: PropTypes.string.isRequired,
inTitle: PropTypes.bool,
show: PropTypes.bool,
style: ViewPropTypes.style,
testID: PropTypes.string,
theme: PropTypes.object.isRequired,
};
static defaultProps = {
show: true,
};
render() {
if (!this.props.show) {
return null;
}
const style = createStyleSheet(this.props.theme);
return (
<View style={[style.container, this.props.style]}>
<FormattedText
id={this.props.id}
defaultMessage={this.props.defaultMessage}
style={[style.text, this.props.inTitle ? style.title : null]}
testID={this.props.testID}
/>
</View>
);
}
}
const createStyleSheet = makeStyleSheetFromTheme((theme) => {
return {
container: {
alignSelf: 'center',
backgroundColor: changeOpacity(theme.centerChannelColor, 0.15),
borderRadius: 2,
marginRight: 2,
marginBottom: 1,
marginLeft: 2,
paddingVertical: 2,
paddingHorizontal: 4,
},
text: {
color: theme.centerChannelColor,
fontSize: 10,
fontWeight: '600',
},
title: {
backgroundColor: changeOpacity(theme.sidebarHeaderTextColor, 0.15),
color: changeOpacity(theme.sidebarHeaderTextColor, 0.6),
},
};
});