eletrotupi / tcc/ frontend/components/ui/Badge.tsx2bd9b6733f955a443d284beecfa664749fcb3900
1.8 KB | 63 lines Raw
1
import {
2
  StyleSheet,
3
  View,
4
  type StyleProp,
5
  type ViewStyle,
6
} from 'react-native';
7
import { Text } from '@/components/ui/Text';
8

9
// Badge color palettes
10
export const badgeVariants = {
11
  green:  { bg: "#d4f5e2", text: "#1a7a48", dot: "#34c272" },
12
  blue:   { bg: "#dbeafe", text: "#1d4ed8", dot: "#3b82f6" },
13
  yellow: { bg: "#fef9c3", text: "#854d0e", dot: "#eab308" },
14
  red:    { bg: "#fee2e2", text: "#991b1b", dot: "#ef4444" },
15
  purple: { bg: "#ede9fe", text: "#5b21b6", dot: "#8b5cf6" },
16
  gray:   { bg: "#f1f5f9", text: "#475569", dot: "#94a3b8" },
17
  orange: { bg: "#ffedd5", text: "#9a3412", dot: "#f97316" },
18
  pink:   { bg: "#fce7f3", text: "#9d174d", dot: "#ec4899" },
19
  indigo: { bg: "#e0e7ff", text: "#3730a3", dot: "#6366f1" },
20
};
21

22
export type BadgeVariant = keyof typeof badgeVariants;
23

24
type BadgeProps = {
25
  label: string;
26
  variant?: BadgeVariant;
27
  style?: StyleProp<ViewStyle>;
28
};
29

30
// TODO: Add a subtle variant and allow to drop the dot as well
31
// TODO: Experiment with a less round-ish version?
32
export const Badge = ({ label, variant = "green", style }: BadgeProps) => {
33
  const palette = badgeVariants[variant] ?? badgeVariants.green;
34

35
  const styles = StyleSheet.create({
36
    badge: {
37
      flexDirection: "row",
38
      alignItems: "center",
39
      gap: 5,
40
      paddingVertical: 5,
41
      paddingHorizontal: 12,
42
      borderRadius: 999,
43
      flexShrink: 0,
44
    },
45
    badgeDot: {
46
      width: 7,
47
      height: 7,
48
      borderRadius: 4,
49
    },
50
    badgeText: {
51
      fontSize: 13,
52
      fontWeight: "600",
53
      letterSpacing: 0.1,
54
    }
55
  });
56

57
  return (
58
    <View style={[styles.badge, { backgroundColor: palette.bg }, style]}>
59
      <View style={[styles.badgeDot, { backgroundColor: palette.dot }]} />
60
      <Text style={[styles.badgeText, { color: palette.text }]}>{label}</Text>
61
    </View>
62
  );
63
}