-
-
Notifications
You must be signed in to change notification settings - Fork 490
Expand file tree
/
Copy pathTransBtn.tsx
More file actions
43 lines (38 loc) · 1.15 KB
/
TransBtn.tsx
File metadata and controls
43 lines (38 loc) · 1.15 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
import * as React from 'react';
import { clsx } from 'clsx';
import type { RenderNode } from './BaseSelect';
export interface TransBtnProps {
className: string;
style?: React.CSSProperties;
customizeIcon: RenderNode;
customizeIconProps?: any;
onMouseDown?: React.MouseEventHandler<HTMLSpanElement>;
onClick?: React.MouseEventHandler<HTMLSpanElement>;
children?: React.ReactNode;
}
const TransBtn: React.FC<TransBtnProps> = (props) => {
const { className, style, customizeIcon, customizeIconProps, children, onMouseDown, onClick } =
props;
const icon =
typeof customizeIcon === 'function' ? customizeIcon(customizeIconProps) : customizeIcon;
return (
<span
className={className}
onMouseDown={(event) => {
event.preventDefault();
onMouseDown?.(event);
}}
style={{ userSelect: 'none', WebkitUserSelect: 'none', ...style }}
unselectable="on"
onClick={onClick}
aria-hidden
>
{icon !== undefined ? (
icon
) : (
<span className={clsx(className.split(/\s+/).map((cls) => `${cls}-icon`))}>{children}</span>
)}
</span>
);
};
export default TransBtn;