Skip to content

Instantly share code, notes, and snippets.

@Natanagar
Last active October 3, 2019 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Natanagar/f65a0785f7c98a39f9699f636da1e1ee to your computer and use it in GitHub Desktop.
Save Natanagar/f65a0785f7c98a39f9699f636da1e1ee to your computer and use it in GitHub Desktop.
import { Icon, Tag } from 'antd';
import React, { FC, useEffect, useMemo, useState } from 'react';
import styles from './Label.module.scss';
import {
LabelProps,
IconLeftProps,
IconRightProps,
IconTagProps,
CheckLabelProps,
CrossLabelProps,
} from './interfaces';
let className;
const BaseLabel: FC<LabelProps> = (props) => {
const [values, changeValues] = useState(
props || {
color: 'default',
textLabel: 'Label',
backgroundColor: 'rgba(1,113,211,0.05)',
opacity: 1,
size: 'default',
}
);
useEffect(() => {
changeValues(props);
}, [props]);
const { color, textLabel, opacity, backgroundColor, size } = values;
console.log(backgroundColor);
className = `ant-label-${size}`;
const style = [styles.label, className, styles.position].join(' ');
const labelStyle = { color, opacity, backgroundColor };
return (
<Tag style={labelStyle} className={style}>
{textLabel}
</Tag>
);
};
const IconLeft: FC<IconLeftProps> = (props) => {
return (
<>
<Icon className={styles.icon} type={props.iconType} />
{props.textLabel}
</>
);
};
const IconRight: FC<IconRightProps> = (props) => {
return (
<>
{props.textLabel}
<Icon className={styles.icon} type={props.iconType} />
</>
);
};
const IconTag: FC<IconTagProps> = (props) => {
if (props.position === 'left') {
return <IconLeft {...props} />;
} else {
return <IconRight {...props} />;
}
};
const CheckLabel: FC<CheckLabelProps> = (props) => {
const {
color,
textLabel,
opacity,
backgroundColor,
size,
iconPosition,
} = props;
className = `ant-label-${size}`;
const style = [styles.label, className, styles.position].join(' ');
const labelStyle = { color, opacity, backgroundColor };
const [text, changeText] = useState(textLabel);
useEffect(() => changeText(textLabel), [textLabel]);
return (
<Tag style={labelStyle} className={style}>
<IconTag {...props} />
</Tag>
);
};
const CrossLabel: FC<CrossLabelProps> = (props) => {
const {
color,
textLabel,
opacity,
backgroundColor,
size,
iconPosition,
} = props;
className = `ant-label-${size}`;
const style = [styles.label, className, styles.position].join(' ');
const labelStyle = { color, opacity, backgroundColor };
const [text, changeText] = useState(textLabel);
useEffect(() => changeText(textLabel));
return (
<Tag style={labelStyle} className={style}>
<IconTag {...props} />
</Tag>
);
};
const Label = {
BaseLabel,
CheckLabel,
CrossLabel,
};
export default Label;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment