-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
icon.tsx
49 lines (43 loc) · 1.14 KB
/
icon.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
46
47
48
49
import React from 'react';
import { Icon as SUIIcon } from 'semantic-ui-react';
import { SemanticDatepickerProps } from '../types';
type CustomIconProps = {
clearIcon: SemanticDatepickerProps['clearIcon'];
icon: SemanticDatepickerProps['icon'];
isClearIconVisible: boolean;
onClear: () => void;
onClick: () => void;
};
const CustomIcon = ({
clearIcon,
icon,
isClearIconVisible,
onClear,
onClick,
}: CustomIconProps) => {
if (isClearIconVisible && clearIcon && React.isValidElement(clearIcon)) {
return React.cloneElement<any>(clearIcon, {
'data-testid': 'datepicker-clear-icon',
onClick: onClear,
});
}
if (isClearIconVisible && clearIcon && !React.isValidElement(clearIcon)) {
return (
<SUIIcon
aria-pressed="false"
data-testid="datepicker-clear-icon"
link
name={clearIcon}
onClick={onClear}
/>
);
}
if (icon && React.isValidElement(icon)) {
return React.cloneElement<any>(icon, {
'data-testid': 'datepicker-icon',
onClick,
});
}
return <SUIIcon data-testid="datepicker-icon" name={icon} />;
};
export default CustomIcon;