/
index.tsx
34 lines (31 loc) · 1004 Bytes
/
index.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
import React from 'react';
import { classNames, prefixClaName } from 'mo/common/className';
import '@vscode/codicons/dist/codicon.css';
import { ComponentProps } from 'react';
export interface IIconProps extends ComponentProps<'span'> {
type?: string | JSX.Element;
onClick?: (e: React.MouseEvent) => void;
}
export function Icon(props: React.PropsWithChildren<IIconProps>) {
const { className, type, children, ...restProps } = props;
if (type) {
return typeof type === 'string' ? (
<span
className={classNames(
className,
'codicon',
type.includes('~spin') && 'codicon-spin',
prefixClaName(type.split('~spin')[0], 'codicon')
)}
{...restProps}
/>
) : (
type
);
}
return children ? (
<span className={className} {...restProps}>
{children}
</span>
) : null;
}