2021-11-09 14:52:49 +02:00
|
|
|
import React, { ButtonHTMLAttributes, FC } from 'react';
|
|
|
|
|
import { css } from '@emotion/css';
|
|
|
|
|
import { GrafanaTheme } from '@grafana/data';
|
2022-01-18 10:46:36 -08:00
|
|
|
import { Button, ButtonVariant, IconName, LinkButton, useStyles } from '@grafana/ui';
|
2021-11-09 14:52:49 +02:00
|
|
|
import { EmptyArea } from './EmptyArea';
|
|
|
|
|
|
|
|
|
|
export interface EmptyAreaWithCTAProps {
|
|
|
|
|
buttonLabel: string;
|
2022-01-18 10:46:36 -08:00
|
|
|
href?: string;
|
|
|
|
|
onButtonClick?: ButtonHTMLAttributes<HTMLButtonElement>['onClick'];
|
2021-11-09 14:52:49 +02:00
|
|
|
text: string;
|
|
|
|
|
|
|
|
|
|
buttonIcon?: IconName;
|
|
|
|
|
buttonSize?: 'xs' | 'sm' | 'md' | 'lg';
|
|
|
|
|
buttonVariant?: ButtonVariant;
|
2022-04-06 09:24:33 -07:00
|
|
|
showButton?: boolean;
|
2021-11-09 14:52:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const EmptyAreaWithCTA: FC<EmptyAreaWithCTAProps> = ({
|
|
|
|
|
buttonIcon,
|
|
|
|
|
buttonLabel,
|
|
|
|
|
buttonSize = 'lg',
|
|
|
|
|
buttonVariant = 'primary',
|
|
|
|
|
onButtonClick,
|
|
|
|
|
text,
|
2022-01-18 10:46:36 -08:00
|
|
|
href,
|
2022-04-06 09:24:33 -07:00
|
|
|
showButton = true,
|
2021-11-09 14:52:49 +02:00
|
|
|
}) => {
|
|
|
|
|
const styles = useStyles(getStyles);
|
|
|
|
|
|
2022-01-18 10:46:36 -08:00
|
|
|
const commonProps = {
|
|
|
|
|
className: styles.button,
|
|
|
|
|
icon: buttonIcon,
|
|
|
|
|
size: buttonSize,
|
|
|
|
|
variant: buttonVariant,
|
|
|
|
|
};
|
|
|
|
|
|
2021-11-09 14:52:49 +02:00
|
|
|
return (
|
|
|
|
|
<EmptyArea>
|
|
|
|
|
<>
|
|
|
|
|
<p className={styles.text}>{text}</p>
|
2022-04-06 09:24:33 -07:00
|
|
|
{showButton &&
|
|
|
|
|
(href ? (
|
|
|
|
|
<LinkButton href={href} type="button" {...commonProps}>
|
|
|
|
|
{buttonLabel}
|
|
|
|
|
</LinkButton>
|
|
|
|
|
) : (
|
|
|
|
|
<Button onClick={onButtonClick} type="button" {...commonProps}>
|
|
|
|
|
{buttonLabel}
|
|
|
|
|
</Button>
|
|
|
|
|
))}
|
2021-11-09 14:52:49 +02:00
|
|
|
</>
|
|
|
|
|
</EmptyArea>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getStyles = (theme: GrafanaTheme) => {
|
|
|
|
|
return {
|
|
|
|
|
container: css`
|
|
|
|
|
background-color: ${theme.colors.bg2};
|
|
|
|
|
color: ${theme.colors.textSemiWeak};
|
|
|
|
|
padding: ${theme.spacing.xl};
|
|
|
|
|
text-align: center;
|
|
|
|
|
`,
|
|
|
|
|
text: css`
|
|
|
|
|
margin-bottom: ${theme.spacing.md};
|
|
|
|
|
`,
|
|
|
|
|
button: css`
|
|
|
|
|
margin: ${theme.spacing.md} 0 ${theme.spacing.sm};
|
|
|
|
|
`,
|
|
|
|
|
};
|
|
|
|
|
};
|