2022-09-13 07:36:00 +00:00
|
|
|
import { Theme } from '@mui/material';
|
2021-04-08 08:35:26 +00:00
|
|
|
import React from 'react';
|
2022-10-13 07:46:00 +00:00
|
|
|
import { makeStyles } from 'tss-react/mui';
|
2021-04-08 08:35:26 +00:00
|
|
|
|
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
|
|
|
|
2022-10-13 07:46:00 +00:00
|
|
|
interface Props {
|
2021-04-08 08:35:26 +00:00
|
|
|
|
|
|
|
/**
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* The color of the label.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
color?: string;
|
2021-09-29 12:06:03 +00:00
|
|
|
|
2022-10-13 07:46:00 +00:00
|
|
|
/**
|
|
|
|
* An SVG icon to be rendered as the content of the label.
|
|
|
|
*/
|
|
|
|
icon?: Function;
|
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
|
|
|
|
2022-10-13 07:46:00 +00:00
|
|
|
/**
|
|
|
|
* String or component that will be rendered as the label itself.
|
|
|
|
*/
|
|
|
|
text?: string;
|
2021-04-08 08:35:26 +00:00
|
|
|
|
2022-10-13 07:46:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const useStyles = makeStyles()((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
|
|
|
|
}
|
|
|
|
};
|
2022-10-13 07:46:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const Label = ({
|
|
|
|
className,
|
|
|
|
color,
|
|
|
|
icon,
|
|
|
|
iconColor,
|
|
|
|
id,
|
|
|
|
onClick,
|
|
|
|
text
|
|
|
|
}: Props) => {
|
|
|
|
const { classes, cx } = useStyles();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className = { cx(classes.label, onClick && classes.clickable,
|
|
|
|
color && classes[color], className
|
|
|
|
) }
|
|
|
|
id = { id }
|
|
|
|
onClick = { onClick }>
|
|
|
|
{icon && <Icon
|
|
|
|
color = { iconColor }
|
|
|
|
size = '16'
|
|
|
|
src = { icon } />}
|
|
|
|
{text && <span className = { icon && classes.withIcon }>{text}</span>}
|
|
|
|
</div>
|
|
|
|
);
|
2021-09-29 12:06:03 +00:00
|
|
|
};
|
|
|
|
|
2022-10-13 07:46:00 +00:00
|
|
|
export default Label;
|