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-20 09:11:27 +00:00
|
|
|
interface IProps {
|
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
|
|
|
}
|
|
|
|
|
2022-11-15 07:50:22 +00:00
|
|
|
const useStyles = makeStyles()(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',
|
|
|
|
margin: '0 0 4px 4px',
|
2022-11-08 10:24:32 +00:00
|
|
|
padding: '6px',
|
|
|
|
height: 28,
|
|
|
|
boxSizing: 'border-box'
|
2021-09-29 12:06:03 +00:00
|
|
|
},
|
|
|
|
withIcon: {
|
|
|
|
marginLeft: 8
|
|
|
|
},
|
|
|
|
clickable: {
|
|
|
|
cursor: 'pointer'
|
|
|
|
},
|
|
|
|
[COLORS.white]: {
|
2022-11-08 10:24:32 +00:00
|
|
|
background: theme.palette.ui09,
|
|
|
|
color: theme.palette.text04,
|
2021-09-29 12:06:03 +00:00
|
|
|
|
|
|
|
'& svg': {
|
2022-11-08 10:24:32 +00:00
|
|
|
fill: theme.palette.icon04
|
2021-09-29 12:06:03 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
[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
|
2022-10-20 09:11:27 +00:00
|
|
|
}: IProps) => {
|
2022-10-13 07:46:00 +00:00
|
|
|
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;
|