Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. import { Icon, Tag } from 'antd';
  2. import React, { FC, useEffect, useMemo, useState } from 'react';
  3. import styles from './Label.module.scss';
  4. import {
  5. LabelProps,
  6. IconLeftProps,
  7. IconRightProps,
  8. IconTagProps,
  9. CheckLabelProps,
  10. CrossLabelProps,
  11. } from './interfaces';
  12.  
  13. let className;
  14.  
  15. const BaseLabel: FC<LabelProps> = (props) => {
  16. const [values, changeValues] = useState(
  17. props || {
  18. color: 'default',
  19. textLabel: 'Label',
  20. backgroundColor: 'rgba(1,113,211,0.05)',
  21. opacity: 1,
  22. size: 'default',
  23. }
  24. );
  25. useEffect(() => {
  26. changeValues(props);
  27. }, [props]);
  28. const { color, textLabel, opacity, backgroundColor, size } = values;
  29. console.log(backgroundColor);
  30.  
  31. className = `ant-label-${size}`;
  32. const style = [styles.label, className, styles.position].join(' ');
  33. const labelStyle = { color, opacity, backgroundColor };
  34. return (
  35. <Tag style={labelStyle} className={style}>
  36. {textLabel}
  37. </Tag>
  38. );
  39. };
  40.  
  41. const IconLeft: FC<IconLeftProps> = (props) => {
  42. return (
  43. <>
  44. <Icon className={styles.icon} type={props.iconType} />
  45. {props.textLabel}
  46. </>
  47. );
  48. };
  49. const IconRight: FC<IconRightProps> = (props) => {
  50. return (
  51. <>
  52. {props.textLabel}
  53. <Icon className={styles.icon} type={props.iconType} />
  54. </>
  55. );
  56. };
  57. const IconTag: FC<IconTagProps> = (props) => {
  58. if (props.position === 'left') {
  59. return <IconLeft {...props} />;
  60. } else {
  61. return <IconRight {...props} />;
  62. }
  63. };
  64. const CheckLabel: FC<CheckLabelProps> = (props) => {
  65. const {
  66. color,
  67. textLabel,
  68. opacity,
  69. backgroundColor,
  70. size,
  71. iconPosition,
  72. } = props;
  73. className = `ant-label-${size}`;
  74. const style = [styles.label, className, styles.position].join(' ');
  75. const labelStyle = { color, opacity, backgroundColor };
  76. const [text, changeText] = useState(textLabel);
  77. useEffect(() => changeText(textLabel), [textLabel]);
  78. return (
  79. <Tag style={labelStyle} className={style}>
  80. <IconTag {...props} />
  81. </Tag>
  82. );
  83. };
  84. const CrossLabel: FC<CrossLabelProps> = (props) => {
  85. const {
  86. color,
  87. textLabel,
  88. opacity,
  89. backgroundColor,
  90. size,
  91. iconPosition,
  92. } = props;
  93. className = `ant-label-${size}`;
  94. const style = [styles.label, className, styles.position].join(' ');
  95. const labelStyle = { color, opacity, backgroundColor };
  96. const [text, changeText] = useState(textLabel);
  97. useEffect(() => changeText(textLabel));
  98.  
  99. return (
  100. <Tag style={labelStyle} className={style}>
  101. <IconTag {...props} />
  102. </Tag>
  103. );
  104. };
  105.  
  106. const Label = {
  107. BaseLabel,
  108. CheckLabel,
  109. CrossLabel,
  110. };
  111.  
  112. export default Label;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement