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';
|
2022-03-25 20:05:49 +00:00
|
|
|
import { IStatus } from './definition';
|
2019-03-01 16:49:11 +00:00
|
|
|
|
2022-03-25 20:05:49 +00:00
|
|
|
const Status = React.memo(({ style, status = 'offline', size = 32, ...props }: Omit<IStatus, 'id'>) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
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;
|