Skip to content

Commit d5d5691

Browse files
committed
Allow custom click handler on result tag
1 parent c5a2ab3 commit d5d5691

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/components/result/GenericResultViewTag.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,20 @@ export interface GenericResultViewTagProps {
3131
* @param value
3232
*/
3333
singleValueMapper?: (value: string) => ReactNode
34+
onClick?: (e: MouseEvent<HTMLDivElement>, tagValue: ReactNode) => void
35+
clickBehavior?: "copy-text"
3436
}
3537

36-
export function GenericResultViewTag({ field, result, icon, label, valueMapper, singleValueMapper }: GenericResultViewTagProps) {
38+
export function GenericResultViewTag({
39+
field,
40+
result,
41+
icon,
42+
label,
43+
valueMapper,
44+
singleValueMapper,
45+
clickBehavior = "copy-text",
46+
onClick
47+
}: GenericResultViewTagProps) {
3748
const value = useMemo(() => {
3849
const value: string | string[] = autoUnwrap(result[field])
3950
if (!value) return undefined
@@ -53,17 +64,27 @@ export function GenericResultViewTag({ field, result, icon, label, valueMapper,
5364
[copy]
5465
)
5566

67+
const handleClick = useCallback(
68+
(value: ReactNode, e: MouseEvent<HTMLDivElement>) => {
69+
if (onClick) onClick(e, value)
70+
if (clickBehavior === "copy-text") {
71+
copyTagValue(e)
72+
}
73+
},
74+
[clickBehavior, copyTagValue, onClick]
75+
)
76+
5677
const base = useCallback(
5778
(value: ReactNode) => {
5879
return (
59-
<Badge variant="secondary" className="rfs-truncate" onClick={copyTagValue}>
80+
<Badge variant="secondary" className="rfs-truncate" onClick={(e) => handleClick(value, e)}>
6081
<span className="rfs-flex rfs-truncate">
6182
{icon} {value}
6283
</span>
6384
</Badge>
6485
)
6586
},
66-
[copyTagValue, icon]
87+
[handleClick, icon]
6788
)
6889

6990
if (!label) return base(value)

0 commit comments

Comments
 (0)