-
-
Notifications
You must be signed in to change notification settings - Fork 459
/
Copy pathTransBtn.tsx
45 lines (40 loc) · 1.18 KB
/
TransBtn.tsx
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
import * as React from 'react';
import classNames from 'classnames';
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={classNames(className.split(/\s+/).map((cls) => `${cls}-icon`))}>
{children}
</span>
)}
</span>
);
};
export default TransBtn;