2022-01-26 01:15:45 -06:00
|
|
|
import { css, cx } from '@emotion/css';
|
2022-04-22 08:33:13 -05:00
|
|
|
import React, { HTMLAttributes, useEffect } from 'react';
|
|
|
|
|
2022-01-26 01:15:45 -06:00
|
|
|
import { GrafanaTheme2 } from '@grafana/data';
|
2022-02-09 04:18:27 -06:00
|
|
|
import { reportExperimentView } from '@grafana/runtime';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { useStyles2 } from '@grafana/ui';
|
2022-01-26 01:15:45 -06:00
|
|
|
|
|
|
|
export interface Props extends HTMLAttributes<HTMLSpanElement> {
|
|
|
|
text?: string;
|
2022-02-09 04:18:27 -06:00
|
|
|
experimentId?: string;
|
2022-04-20 07:08:49 -05:00
|
|
|
eventVariant?: string;
|
2022-01-26 01:15:45 -06:00
|
|
|
}
|
|
|
|
|
2022-04-20 07:08:49 -05:00
|
|
|
export const ProBadge = ({ text = 'PRO', className, experimentId, eventVariant = '', ...htmlProps }: Props) => {
|
2022-01-26 01:15:45 -06:00
|
|
|
const styles = useStyles2(getStyles);
|
|
|
|
|
|
|
|
useEffect(() => {
|
2022-02-09 04:18:27 -06:00
|
|
|
if (experimentId) {
|
2022-04-20 07:08:49 -05:00
|
|
|
reportExperimentView(experimentId, 'test', eventVariant);
|
2022-01-26 01:15:45 -06:00
|
|
|
}
|
2022-04-20 07:08:49 -05:00
|
|
|
}, [experimentId, eventVariant]);
|
2022-01-26 01:15:45 -06:00
|
|
|
|
|
|
|
return (
|
|
|
|
<span className={cx(styles.badge, className)} {...htmlProps}>
|
|
|
|
{text}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const getStyles = (theme: GrafanaTheme2) => {
|
|
|
|
return {
|
|
|
|
badge: css`
|
|
|
|
margin-left: ${theme.spacing(1.25)};
|
|
|
|
border-radius: ${theme.shape.borderRadius(5)};
|
|
|
|
background-color: ${theme.colors.success.main};
|
|
|
|
padding: ${theme.spacing(0.25, 0.75)};
|
2022-03-30 07:46:56 -05:00
|
|
|
color: white; // use the same color for both themes
|
2022-01-26 01:15:45 -06:00
|
|
|
font-weight: ${theme.typography.fontWeightMedium};
|
|
|
|
font-size: ${theme.typography.pxToRem(10)};
|
|
|
|
`,
|
|
|
|
};
|
|
|
|
};
|