2019-03-01 16:49:11 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
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
|
|
|
|
2019-12-17 14:08:06 +00:00
|
|
|
const Status = React.memo(({
|
2021-03-31 17:47:17 +00:00
|
|
|
status, size, style, ...props
|
|
|
|
}) => {
|
|
|
|
const name = `status-${ status }`;
|
|
|
|
const isNameValid = CustomIcon.hasIcon(name);
|
|
|
|
const iconName = isNameValid ? name : 'status-offline';
|
|
|
|
const calculatedStyle = [{
|
|
|
|
width: size, height: size, textAlignVertical: 'center'
|
|
|
|
}, style];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<CustomIcon
|
|
|
|
style={calculatedStyle}
|
|
|
|
size={size}
|
|
|
|
name={iconName}
|
|
|
|
color={STATUS_COLORS[status] ?? STATUS_COLORS.offline}
|
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2019-03-01 16:49:11 +00:00
|
|
|
Status.propTypes = {
|
|
|
|
status: PropTypes.string,
|
|
|
|
size: PropTypes.number,
|
2021-03-31 17:47:17 +00:00
|
|
|
style: PropTypes.any
|
2019-03-01 16:49:11 +00:00
|
|
|
};
|
|
|
|
Status.defaultProps = {
|
|
|
|
status: 'offline',
|
2021-03-31 17:47:17 +00:00
|
|
|
size: 32
|
2019-03-01 16:49:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default Status;
|