123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- import { Theme } from '@mui/material';
- import { withStyles } from '@mui/styles';
- import clsx from 'clsx';
- import React from 'react';
-
- import Icon from '../../../icons/components/Icon';
- import { withPixelLineHeight } from '../../../styles/functions.web';
- import { COLORS } from '../../constants';
- import AbstractLabel, {
- type Props as AbstractProps
- } from '../AbstractLabel';
-
- type Props = AbstractProps & {
-
- /**
- * Own CSS class name.
- */
- className?: string;
-
- /**
- * An object containing the CSS classes.
- */
- classes: any;
-
- /**
- * The color of the label.
- */
- color?: string;
-
-
- /**
- * Color for the icon.
- */
- iconColor?: string;
-
- /**
- * HTML ID attribute to add to the root of {@code Label}.
- */
- id?: string;
-
- /**
- * Click handler if any.
- */
- onClick?: (e?: React.MouseEvent) => void;
-
- };
-
- /**
- * Creates the styles for the component.
- *
- * @param {Object} theme - The current UI theme.
- *
- * @returns {Object}
- */
- const styles = (theme: Theme) => {
- return {
- label: {
- ...withPixelLineHeight(theme.typography.labelRegular),
- alignItems: 'center',
- background: theme.palette.ui04,
- borderRadius: Number(theme.shape.borderRadius) / 2,
- 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
- }
- };
- };
-
-
- /**
- * React Component for showing short text in a circle.
- *
- * @augments Component
- */
- class Label extends AbstractLabel<Props, any> {
- /**
- * Implements React's {@link Component#render()}.
- *
- * @inheritdoc
- */
- render() {
- const {
- classes,
- className,
- color,
- icon,
- iconColor,
- id,
- onClick,
- text
- } = this.props;
- const labelClassName = clsx(
- classes.label,
- onClick && classes.clickable,
- color && classes[color],
- className
- );
-
- return (
- <div
- className = { labelClassName }
- id = { id }
- onClick = { onClick }>
- { icon && <Icon
- color = { iconColor }
- size = '16'
- src = { icon } /> }
- { text && <span className = { icon && classes.withIcon }>{text}</span> }
- </div>
- );
- }
- }
-
- export default withStyles(styles)(Label);
|