Skip to content

Commit 8165387

Browse files
210 Add a new doc component widget: <Label value="BETA"/>
1 parent 8b3cad5 commit 8165387

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

src/components/Label/index.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react';
2+
import styles from './styles.module.css';
3+
4+
5+
// Predefined label colors
6+
const labelColors = {
7+
beta: '#9912ec',
8+
// example to add other labels
9+
// bug: '#d73a49',
10+
// feature: '#28a745',
11+
};
12+
13+
// Utility function to generate random colors
14+
const generateRandomColor = () => {
15+
const letters = '0123456789ABCDEF';
16+
let color = '#';
17+
for (let i = 0; i < 6; i++) {
18+
color += letters[Math.floor(Math.random() * 16)];
19+
}
20+
return color;
21+
};
22+
23+
const Label = ({ value }) => {
24+
// Determine the color for the label
25+
const color = labelColors[value.toLowerCase()] || generateRandomColor();
26+
27+
return (
28+
<span
29+
className={styles.label}
30+
style={{backgroundColor: color}}
31+
>
32+
{value.toUpperCase()}
33+
</span>
34+
);
35+
};
36+
37+
export default Label;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* General Label Style */
2+
.label {
3+
display: inline-block;
4+
font-size: 12px; /* Similar to GitHub's small text */
5+
font-weight: 600; /* Bold text */
6+
color: #ffffff; /* Default text color (white) */
7+
background-color: #6e5494; /* Default background color */
8+
padding: 0.2em 0.6em; /* Padding for compact sizing */
9+
border-radius: 2em; /* Rounded corners */
10+
text-align: center;
11+
white-space: nowrap; /* Prevent text wrapping */
12+
vertical-align: middle;
13+
}
14+
15+
/* Example hover effect */
16+
.label:hover {
17+
opacity: 0.9; /* Slightly dim on hover */
18+
}

0 commit comments

Comments
 (0)