2019-03-01 16:49:11 +00:00
|
|
|
import React from 'react';
|
2021-11-10 20:14:45 +00:00
|
|
|
import { StyleProp, TextStyle } from 'react-native';
|
2021-09-13 20:41:05 +00:00
|
|
|
|
2021-03-31 17:47:17 +00:00
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
|
|
|
import { STATUS_COLORS } from '../../constants/colors';
|
2019-03-01 16:49:11 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
interface IStatus {
|
|
|
|
status: string;
|
|
|
|
size: number;
|
2021-11-10 20:14:45 +00:00
|
|
|
style?: StyleProp<TextStyle>;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const Status = React.memo(({ style, status = 'offline', size = 32, ...props }: IStatus) => {
|
|
|
|
const name = `status-${status}`;
|
2021-03-31 17:47:17 +00:00
|
|
|
const isNameValid = CustomIcon.hasIcon(name);
|
|
|
|
const iconName = isNameValid ? name : 'status-offline';
|
2021-11-10 20:14:45 +00:00
|
|
|
const calculatedStyle: StyleProp<TextStyle> = [
|
2021-09-13 20:41:05 +00:00
|
|
|
{
|
|
|
|
width: size,
|
|
|
|
height: size,
|
|
|
|
textAlignVertical: 'center'
|
|
|
|
},
|
|
|
|
style
|
|
|
|
];
|
2021-03-31 17:47:17 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<CustomIcon
|
|
|
|
style={calculatedStyle}
|
|
|
|
size={size}
|
|
|
|
name={iconName}
|
|
|
|
color={STATUS_COLORS[status] ?? STATUS_COLORS.offline}
|
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-03-01 16:49:11 +00:00
|
|
|
export default Status;
|