You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // @flow
  2. import { withStyles } from '@material-ui/core/styles';
  3. import clsx from 'clsx';
  4. import React from 'react';
  5. import Icon from '../../icons/components/Icon';
  6. import { withPixelLineHeight } from '../../styles/functions.web';
  7. import { COLORS } from '../constants';
  8. import AbstractLabel, {
  9. type Props as AbstractProps
  10. } from './AbstractLabel';
  11. type Props = AbstractProps & {
  12. /**
  13. * An object containing the CSS classes.
  14. */
  15. classes: Object,
  16. /**
  17. * Own CSS class name.
  18. */
  19. className: string,
  20. /**
  21. * The color of the label.
  22. */
  23. color: string,
  24. /**
  25. * HTML ID attribute to add to the root of {@code Label}.
  26. */
  27. id: string,
  28. /**
  29. * Color for the icon.
  30. */
  31. iconColor?: string,
  32. /**
  33. * Click handler if any.
  34. */
  35. onClick?: Function,
  36. };
  37. /**
  38. * Creates the styles for the component.
  39. *
  40. * @param {Object} theme - The current UI theme.
  41. *
  42. * @returns {Object}
  43. */
  44. const styles = theme => {
  45. return {
  46. label: {
  47. ...withPixelLineHeight(theme.typography.labelRegular),
  48. alignItems: 'center',
  49. background: theme.palette.ui04,
  50. borderRadius: theme.shape.borderRadius / 2,
  51. color: theme.palette.text01,
  52. display: 'flex',
  53. height: 28,
  54. margin: '0 0 4px 4px',
  55. padding: '0 8px'
  56. },
  57. withIcon: {
  58. marginLeft: 8
  59. },
  60. clickable: {
  61. cursor: 'pointer'
  62. },
  63. [COLORS.white]: {
  64. background: theme.palette.text01,
  65. color: theme.palette.ui04,
  66. '& svg': {
  67. fill: theme.palette.ui04
  68. }
  69. },
  70. [COLORS.green]: {
  71. background: theme.palette.success02
  72. },
  73. [COLORS.red]: {
  74. background: theme.palette.actionDanger
  75. }
  76. };
  77. };
  78. /**
  79. * React Component for showing short text in a circle.
  80. *
  81. * @augments Component
  82. */
  83. class Label extends AbstractLabel<Props, *> {
  84. /**
  85. * Implements React's {@link Component#render()}.
  86. *
  87. * @inheritdoc
  88. */
  89. render() {
  90. const {
  91. classes,
  92. className,
  93. color,
  94. icon,
  95. iconColor,
  96. id,
  97. onClick,
  98. text
  99. } = this.props;
  100. const labelClassName = clsx(
  101. classes.label,
  102. onClick && classes.clickable,
  103. color && classes[color],
  104. className
  105. );
  106. return (
  107. <div
  108. className = { labelClassName }
  109. id = { id }
  110. onClick = { onClick }>
  111. { icon && <Icon
  112. color = { iconColor }
  113. size = '16'
  114. src = { icon } /> }
  115. { text && <span className = { icon && classes.withIcon }>{text}</span> }
  116. </div>
  117. );
  118. }
  119. }
  120. export default withStyles(styles)(Label);