gitscope
← marzneshin / v0.6.3 / dashboard/src/common/components/no-propogation-button/index.tsx
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/common/components/no-propogation-button/index.tsx · TypeScript
Blame Raw
 1import { Row } from "@tanstack/react-table"
 2import { type PropsWithChildren, useCallback } from 'react'
 3import {
 4    type ColumnActions
 5} from "@marzneshin/libs/entity-table";
 6
 7interface NoPropogationButtonProps<T> {
 8    actions: ColumnActions<T>,
 9    row: Row<T>,
10}
11
12export function NoPropogationButton<T>({ children, actions, row }: NoPropogationButtonProps<T> & PropsWithChildren) {
13    const handleKeyDown = useCallback((e: React.KeyboardEvent<HTMLDivElement>) => {
14        if (e.key === 'Enter' || e.key === ' ') {
15            e.preventDefault();
16            e.stopPropagation();
17            actions.onOpen(row.original);
18        }
19    }, [actions, row.original]);
20
21    return (
22        <div
23            className="flex flex-row gap-2 items-center"
24            onClick={(e) => e.stopPropagation()}
25            onKeyDown={handleKeyDown}
26            tabIndex={0}
27            role="button"
28        >
29            {children}
30        </div>
31    )
32}
33