({
role,
onClick,
onDoubleClick,
onMiddleClick,
onAuxClick: externalOnAuxClick,
}: UseClickableTableRowConfig<TRole>)
| 43 | }; |
| 44 | |
| 45 | export const useClickableTableRow = < |
| 46 | TRole extends ClickableAriaRole = ClickableAriaRole, |
| 47 | >({ |
| 48 | role, |
| 49 | onClick, |
| 50 | onDoubleClick, |
| 51 | onMiddleClick, |
| 52 | onAuxClick: externalOnAuxClick, |
| 53 | }: UseClickableTableRowConfig<TRole>): UseClickableTableRowResult<TRole> => { |
| 54 | const clickableProps = useClickable(onClick, (role ?? "button") as TRole); |
| 55 | |
| 56 | return { |
| 57 | ...clickableProps, |
| 58 | className: cn([ |
| 59 | "cursor-pointer hover:outline focus-visible:outline outline-1 -outline-offset-1 outline-border-secondary", |
| 60 | "first:rounded-t-md last:rounded-b-md", |
| 61 | ]), |
| 62 | hover: true, |
| 63 | onDoubleClick, |
| 64 | onAuxClick: (event) => { |
| 65 | // Regardless of which callback gets called, the hook won't stop the event |
| 66 | // from bubbling further up the DOM |
| 67 | const isMiddleMouseButton = event.button === 1; |
| 68 | if (isMiddleMouseButton) { |
| 69 | onMiddleClick?.(event); |
| 70 | } else { |
| 71 | externalOnAuxClick?.(event); |
| 72 | } |
| 73 | }, |
| 74 | }; |
| 75 | }; |
no test coverage detected