Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import type { PropsWithChildren, CSSProperties } from "react";
import { cnm } from "@humansignal/ui";
 
interface ChipProps extends PropsWithChildren {
  /**
   * Optional prefix content (e.g., count, percentage) that appears before the main content with a divider
   */
  prefix?: React.ReactNode;
 
  /**
   * Optional color configuration from label_attrs
   */
  colors?: {
    background?: string;
    border?: string;
    color?: string;
  };
 
  /**
   * Additional inline styles to apply
   */
  style?: CSSProperties;
 
  /**
   * Whether to show a thick left border (typically for labels)
   */
  thickBorder?: boolean;
 
  /**
   * Additional CSS classes
   */
  className?: string;
}
 
/**
 * Unified chip component for displaying labels, badges, and tags throughout the Task Summary.
 * Supports various styling options including colors, borders, and prefixes for counts/percentages.
 */
export const Chip = ({ children, prefix, colors, style, thickBorder = false, className }: ChipProps) => {
  const combinedStyles: CSSProperties = {
    ...style,
    ...(colors?.background && { background: colors.background }),
    ...(colors?.border && { borderColor: colors.border }),
    ...(colors?.color && { color: colors.color }),
    ...(thickBorder && colors?.border && { borderLeft: `3px solid ${colors.border}` }),
  };
  const isPercentage = typeof prefix === "string" && prefix.endsWith("%");
 
  if (!children) return null;
 
  return (
    <span
      className={cnm(
        "inline-flex items-center whitespace-nowrap rounded-4 px-2 py-0.5",
        "text-xs border",
        !colors?.background && "bg-neutral-surface-subtle",
        !colors?.border && "border-neutral-border",
        !colors?.color && "text-neutral-content",
        className,
      )}
      style={combinedStyles}
    >
      {prefix && (
        <>
          <span className="font-semibold">{prefix}</span>
          {isPercentage ? (
            <span className="opacity-50 mx-tighter">|</span>
          ) : (
            <span className="opacity-50 mx-tightest">×</span>
          )}
        </>
      )}
      {children}
    </span>
  );
};