|
1 | 1 | import type { GitHubIssueLabel, GitHubIssueType } from "@t3tools/contracts"; |
2 | | -import type { MouseEvent, ReactNode } from "react"; |
| 2 | +import type { CSSProperties, ReactNode } from "react"; |
3 | 3 |
|
4 | 4 | import { cn } from "../../lib/utils"; |
| 5 | +import { Badge } from "../ui/badge"; |
5 | 6 | import { PullRequestLabelChip } from "../pullRequest/pullRequestPresentation"; |
6 | 7 | import { pullRequestLabelColor } from "../pullRequest/pullRequestList.logic"; |
7 | 8 | import { gitHubIssueTypeHexColor, gitHubIssueTypeLabel } from "./githubIssueChips.logic"; |
@@ -67,32 +68,39 @@ export function GitHubIssueChip({ |
67 | 68 | readonly children?: ReactNode; |
68 | 69 | }) { |
69 | 70 | const label = gitHubIssueChipName(kind, name); |
70 | | - const chip = ( |
| 71 | + const hex = gitHubIssueChipColor(kind, color); |
| 72 | + if (onFilter !== undefined) { |
| 73 | + return ( |
| 74 | + <Badge |
| 75 | + size={size ?? "sm"} |
| 76 | + variant={hex ? "label" : "secondary"} |
| 77 | + className={cn("min-w-0 max-w-40 shrink justify-start", className)} |
| 78 | + {...(hex ? { style: { "--label": hex } as CSSProperties } : {})} |
| 79 | + render={ |
| 80 | + <button |
| 81 | + type="button" |
| 82 | + aria-label={`Filter by ${label}`} |
| 83 | + onClick={(event) => { |
| 84 | + event.stopPropagation(); |
| 85 | + onFilter(); |
| 86 | + }} |
| 87 | + /> |
| 88 | + } |
| 89 | + > |
| 90 | + <span className="truncate">{label}</span> |
| 91 | + {children} |
| 92 | + </Badge> |
| 93 | + ); |
| 94 | + } |
| 95 | + return ( |
71 | 96 | <PullRequestLabelChip |
72 | | - label={{ name: label, color: gitHubIssueChipColor(kind, color) }} |
| 97 | + label={{ name: label, color: hex }} |
73 | 98 | {...(size ? { size } : {})} |
74 | | - className={cn(onFilter ? "max-w-full" : className)} |
| 99 | + className={cn(className)} |
75 | 100 | > |
76 | 101 | {children} |
77 | 102 | </PullRequestLabelChip> |
78 | 103 | ); |
79 | | - if (onFilter === undefined) return chip; |
80 | | - return ( |
81 | | - <button |
82 | | - type="button" |
83 | | - aria-label={`Filter by ${label}`} |
84 | | - className={cn( |
85 | | - "relative inline-flex min-w-0 max-w-40 shrink cursor-pointer rounded-sm outline-none transition-opacity hover:opacity-80 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset", |
86 | | - className, |
87 | | - )} |
88 | | - onClick={(event: MouseEvent) => { |
89 | | - event.stopPropagation(); |
90 | | - onFilter(); |
91 | | - }} |
92 | | - > |
93 | | - {chip} |
94 | | - </button> |
95 | | - ); |
96 | 104 | } |
97 | 105 |
|
98 | 106 | export function GitHubIssueLabelChip({ |
|
0 commit comments