-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathChildRowDeleteButton.tsx
More file actions
72 lines (64 loc) · 1.38 KB
/
ChildRowDeleteButton.tsx
File metadata and controls
72 lines (64 loc) · 1.38 KB
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
import { css } from '@linaria/core';
const childRowActionCrossClassname = css`
block-size: 100%;
&::before,
&::after {
content: '';
position: absolute;
background: grey;
}
&::before {
inset-inline-start: 21px;
inline-size: 1px;
block-size: 100%;
}
&::after {
inset-block-start: 50%;
inset-inline-start: 21px;
block-size: 1px;
inline-size: 15px;
}
&:hover {
background: red;
}
`;
const childRowButtonClassname = css`
cursor: pointer;
position: absolute;
inset-inline-start: 21px;
transform: translateX(-50%);
filter: grayscale(1);
&:dir(rtl) {
transform: translateX(50%);
}
`;
interface ChildRowDeleteButtonProps {
tabIndex: number;
isDeleteSubRowEnabled: boolean;
onDeleteSubRow: () => void;
}
export function ChildRowDeleteButton({
tabIndex,
onDeleteSubRow,
isDeleteSubRowEnabled
}: ChildRowDeleteButtonProps) {
function handleKeyDown(e: React.KeyboardEvent<HTMLSpanElement>) {
if (e.key === 'Enter') {
// prevent scrolling
e.preventDefault();
onDeleteSubRow();
}
}
return (
<>
<div className={childRowActionCrossClassname} />
{isDeleteSubRowEnabled && (
<div className={childRowButtonClassname} onClick={onDeleteSubRow}>
<span tabIndex={tabIndex} onKeyDown={handleKeyDown}>
❌
</span>
</div>
)}
</>
);
}