2020-04-14 06:26:33 -05:00
|
|
|
import { GrafanaTheme } from '@grafana/data';
|
2021-02-24 07:18:52 -06:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Input,
|
|
|
|
Popover,
|
|
|
|
PopoverController,
|
|
|
|
stylesFactory,
|
|
|
|
Tooltip as GrafanaTooltip,
|
|
|
|
useTheme,
|
|
|
|
} from '@grafana/ui';
|
|
|
|
import { ButtonProps, Elements, PopoverProps, TooltipProps } from '@jaegertracing/jaeger-ui-components';
|
2020-04-14 06:26:33 -05:00
|
|
|
import cx from 'classnames';
|
2021-04-01 07:15:23 -05:00
|
|
|
import { css } from '@emotion/css';
|
2021-02-24 07:18:52 -06:00
|
|
|
import React, { useRef } from 'react';
|
2020-04-08 10:16:22 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Right now Jaeger components need some UI elements to be injected. This is to get rid of AntD UI library that was
|
|
|
|
* used by default.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// This needs to be static to prevent remounting on every render.
|
|
|
|
export const UIElements: Elements = {
|
2021-02-24 07:18:52 -06:00
|
|
|
Popover({ children, content, overlayClassName }: PopoverProps) {
|
|
|
|
const popoverRef = useRef<HTMLElement>(null);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<PopoverController content={content} hideAfter={300}>
|
|
|
|
{(showPopper, hidePopper, popperProps) => {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{popoverRef.current && (
|
|
|
|
<Popover
|
|
|
|
{...popperProps}
|
|
|
|
referenceElement={popoverRef.current}
|
|
|
|
wrapperClassName={overlayClassName}
|
|
|
|
onMouseLeave={hidePopper}
|
|
|
|
onMouseEnter={showPopper}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{React.cloneElement(children, {
|
|
|
|
ref: popoverRef,
|
|
|
|
onMouseEnter: showPopper,
|
|
|
|
onMouseLeave: hidePopper,
|
|
|
|
})}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</PopoverController>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
Tooltip({ children, title }: TooltipProps) {
|
|
|
|
return <GrafanaTooltip content={title}>{children}</GrafanaTooltip>;
|
|
|
|
},
|
2020-04-08 10:16:22 -05:00
|
|
|
Icon: (() => null as any) as any,
|
|
|
|
Dropdown: (() => null as any) as any,
|
|
|
|
Menu: (() => null as any) as any,
|
|
|
|
MenuItem: (() => null as any) as any,
|
2020-12-01 09:19:52 -06:00
|
|
|
Button({ onClick, children, className }: ButtonProps) {
|
|
|
|
return (
|
2021-02-24 07:18:52 -06:00
|
|
|
<Button variant="secondary" onClick={onClick} className={className}>
|
2020-12-01 09:19:52 -06:00
|
|
|
{children}
|
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
},
|
2020-04-08 10:16:22 -05:00
|
|
|
Divider,
|
2020-12-01 09:19:52 -06:00
|
|
|
Input(props) {
|
|
|
|
return <Input {...props} />;
|
|
|
|
},
|
|
|
|
InputGroup({ children, className, style }) {
|
|
|
|
return (
|
|
|
|
<span className={className} style={style}>
|
|
|
|
{children}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
},
|
2020-04-08 10:16:22 -05:00
|
|
|
};
|
|
|
|
|
2020-04-14 06:26:33 -05:00
|
|
|
const getStyles = stylesFactory((theme: GrafanaTheme) => {
|
|
|
|
return {
|
|
|
|
Divider: css`
|
|
|
|
display: inline-block;
|
|
|
|
background: ${theme.isDark ? '#242424' : '#e8e8e8'};
|
|
|
|
width: 1px;
|
|
|
|
height: 0.9em;
|
|
|
|
margin: 0 8px;
|
|
|
|
vertical-align: middle;
|
|
|
|
`,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2020-04-08 10:16:22 -05:00
|
|
|
function Divider({ className }: { className?: string }) {
|
2020-04-14 06:26:33 -05:00
|
|
|
const styles = getStyles(useTheme());
|
|
|
|
return <div style={{}} className={cx(styles.Divider, className)} />;
|
2020-04-08 10:16:22 -05:00
|
|
|
}
|