2022-09-13 07:36:00 +00:00
|
|
|
import { Theme } from '@mui/material';
|
|
|
|
import { withStyles } from '@mui/styles';
|
2021-09-29 12:06:03 +00:00
|
|
|
import clsx from 'clsx';
|
2021-04-08 08:35:26 +00:00
|
|
|
import React from 'react';
|
|
|
|
|
2022-08-25 11:35:19 +00:00
|
|
|
import Icon from '../../../icons/components/Icon';
|
|
|
|
import { withPixelLineHeight } from '../../../styles/functions.web';
|
|
|
|
import { COLORS } from '../../constants';
|
2021-04-08 08:35:26 +00:00
|
|
|
import AbstractLabel, {
|
|
|
|
type Props as AbstractProps
|
2022-08-25 11:35:19 +00:00
|
|
|
} from '../AbstractLabel';
|
2021-04-08 08:35:26 +00:00
|
|
|
|
|
|
|
type Props = AbstractProps & {
|
|
|
|
|
|
|
|
/**
|
2022-08-25 11:35:19 +00:00
|
|
|
* Own CSS class name.
|
2021-09-29 12:06:03 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
className?: string;
|
2021-09-29 12:06:03 +00:00
|
|
|
|
|
|
|
/**
|
2022-08-25 11:35:19 +00:00
|
|
|
* An object containing the CSS classes.
|
2021-04-08 08:35:26 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
classes: any;
|
2021-04-08 08:35:26 +00:00
|
|
|
|
2021-09-29 12:06:03 +00:00
|
|
|
/**
|
|
|
|
* The color of the label.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
color?: string;
|
2021-09-29 12:06:03 +00:00
|
|
|
|
|
|
|
|
2021-04-08 08:35:26 +00:00
|
|
|
/**
|
2022-08-25 11:35:19 +00:00
|
|
|
* Color for the icon.
|
2021-04-08 08:35:26 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
iconColor?: string;
|
2021-09-29 12:06:03 +00:00
|
|
|
|
2021-12-21 10:22:30 +00:00
|
|
|
/**
|
2022-08-25 11:35:19 +00:00
|
|
|
* HTML ID attribute to add to the root of {@code Label}.
|
2021-12-21 10:22:30 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
id?: string;
|
2021-12-21 10:22:30 +00:00
|
|
|
|
2021-09-29 12:06:03 +00:00
|
|
|
/**
|
|
|
|
* Click handler if any.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
onClick?: (e?: React.MouseEvent) => void;
|
2021-04-08 08:35:26 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-09-29 12:06:03 +00:00
|
|
|
/**
|
|
|
|
* Creates the styles for the component.
|
|
|
|
*
|
|
|
|
* @param {Object} theme - The current UI theme.
|
|
|
|
*
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2022-09-13 07:36:00 +00:00
|
|
|
const styles = (theme: Theme) => {
|
2021-09-29 12:06:03 +00:00
|
|
|
return {
|
|
|
|
label: {
|
|
|
|
...withPixelLineHeight(theme.typography.labelRegular),
|
|
|
|
alignItems: 'center',
|
|
|
|
background: theme.palette.ui04,
|
2022-09-13 07:36:00 +00:00
|
|
|
borderRadius: Number(theme.shape.borderRadius) / 2,
|
2021-09-29 12:06:03 +00:00
|
|
|
color: theme.palette.text01,
|
|
|
|
display: 'flex',
|
|
|
|
height: 28,
|
|
|
|
margin: '0 0 4px 4px',
|
|
|
|
padding: '0 8px'
|
|
|
|
},
|
|
|
|
withIcon: {
|
|
|
|
marginLeft: 8
|
|
|
|
},
|
|
|
|
clickable: {
|
|
|
|
cursor: 'pointer'
|
|
|
|
},
|
|
|
|
[COLORS.white]: {
|
|
|
|
background: theme.palette.text01,
|
|
|
|
color: theme.palette.ui04,
|
|
|
|
|
|
|
|
'& svg': {
|
|
|
|
fill: theme.palette.ui04
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[COLORS.green]: {
|
|
|
|
background: theme.palette.success02
|
|
|
|
},
|
|
|
|
[COLORS.red]: {
|
|
|
|
background: theme.palette.actionDanger
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-04-08 08:35:26 +00:00
|
|
|
/**
|
|
|
|
* React Component for showing short text in a circle.
|
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @augments Component
|
2021-04-08 08:35:26 +00:00
|
|
|
*/
|
2022-08-25 11:35:19 +00:00
|
|
|
class Label extends AbstractLabel<Props, any> {
|
2021-04-08 08:35:26 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const {
|
2021-09-29 12:06:03 +00:00
|
|
|
classes,
|
2021-04-08 08:35:26 +00:00
|
|
|
className,
|
2021-09-29 12:06:03 +00:00
|
|
|
color,
|
2021-04-08 08:35:26 +00:00
|
|
|
icon,
|
2021-12-21 10:22:30 +00:00
|
|
|
iconColor,
|
2021-04-08 08:35:26 +00:00
|
|
|
id,
|
2021-09-29 12:06:03 +00:00
|
|
|
onClick,
|
2021-04-08 08:35:26 +00:00
|
|
|
text
|
|
|
|
} = this.props;
|
2021-09-29 12:06:03 +00:00
|
|
|
const labelClassName = clsx(
|
|
|
|
classes.label,
|
|
|
|
onClick && classes.clickable,
|
|
|
|
color && classes[color],
|
|
|
|
className
|
|
|
|
);
|
2021-04-08 08:35:26 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2021-09-29 12:06:03 +00:00
|
|
|
className = { labelClassName }
|
|
|
|
id = { id }
|
|
|
|
onClick = { onClick }>
|
2021-04-08 08:35:26 +00:00
|
|
|
{ icon && <Icon
|
2021-12-21 10:22:30 +00:00
|
|
|
color = { iconColor }
|
2021-04-08 08:35:26 +00:00
|
|
|
size = '16'
|
|
|
|
src = { icon } /> }
|
2021-09-29 12:06:03 +00:00
|
|
|
{ text && <span className = { icon && classes.withIcon }>{text}</span> }
|
2021-04-08 08:35:26 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2021-09-29 12:06:03 +00:00
|
|
|
|
|
|
|
export default withStyles(styles)(Label);
|