|
|
@@ -4,21 +4,9 @@ import { css, cx } from 'emotion';
|
|
|
import { Themeable, GrafanaTheme } from '../../types';
|
|
|
import { selectThemeVariant } from '../../themes/selectThemeVariant';
|
|
|
|
|
|
-export enum ButtonVariant {
|
|
|
- Primary = 'primary',
|
|
|
- Secondary = 'secondary',
|
|
|
- Danger = 'danger',
|
|
|
- Inverse = 'inverse',
|
|
|
- Transparent = 'transparent',
|
|
|
-}
|
|
|
+export type ButtonVariant = 'primary' | 'secondary' | 'danger' | 'inverse' | 'transparent';
|
|
|
|
|
|
-export enum ButtonSize {
|
|
|
- ExtraSmall = 'xs',
|
|
|
- Small = 'sm',
|
|
|
- Medium = 'md',
|
|
|
- Large = 'lg',
|
|
|
- ExtraLarge = 'xl',
|
|
|
-}
|
|
|
+export type ButtonSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
|
|
|
|
export interface CommonButtonProps {
|
|
|
size?: ButtonSize;
|
|
|
@@ -69,19 +57,19 @@ const getButtonStyles = (theme: GrafanaTheme, size: ButtonSize, variant: ButtonV
|
|
|
fontWeight = theme.typography.weight.semibold;
|
|
|
|
|
|
switch (size) {
|
|
|
- case ButtonSize.Small:
|
|
|
+ case 'sm':
|
|
|
padding = `${theme.spacing.xs} ${theme.spacing.sm}`;
|
|
|
fontSize = theme.typography.size.sm;
|
|
|
iconDistance = theme.spacing.xs;
|
|
|
height = theme.height.sm;
|
|
|
break;
|
|
|
- case ButtonSize.Medium:
|
|
|
+ case 'md':
|
|
|
padding = `${theme.spacing.sm} ${theme.spacing.md}`;
|
|
|
fontSize = theme.typography.size.md;
|
|
|
iconDistance = theme.spacing.sm;
|
|
|
height = theme.height.md;
|
|
|
break;
|
|
|
- case ButtonSize.Large:
|
|
|
+ case 'lg':
|
|
|
padding = `${theme.spacing.md} ${theme.spacing.lg}`;
|
|
|
fontSize = theme.typography.size.lg;
|
|
|
fontWeight = theme.typography.weight.regular;
|
|
|
@@ -96,16 +84,16 @@ const getButtonStyles = (theme: GrafanaTheme, size: ButtonSize, variant: ButtonV
|
|
|
}
|
|
|
|
|
|
switch (variant) {
|
|
|
- case ButtonVariant.Primary:
|
|
|
+ case 'primary':
|
|
|
background = buttonVariantStyles(theme.colors.greenBase, theme.colors.greenShade, theme.colors.white);
|
|
|
break;
|
|
|
- case ButtonVariant.Secondary:
|
|
|
+ case 'secondary':
|
|
|
background = buttonVariantStyles(theme.colors.blueBase, theme.colors.blueShade, theme.colors.white);
|
|
|
break;
|
|
|
- case ButtonVariant.Danger:
|
|
|
+ case 'danger':
|
|
|
background = buttonVariantStyles(theme.colors.redBase, theme.colors.redShade, theme.colors.white);
|
|
|
break;
|
|
|
- case ButtonVariant.Inverse:
|
|
|
+ case 'inverse':
|
|
|
const from = selectThemeVariant({ light: theme.colors.gray5, dark: theme.colors.dark6 }, theme.type) as string;
|
|
|
const to = selectThemeVariant(
|
|
|
{
|
|
|
@@ -121,7 +109,7 @@ const getButtonStyles = (theme: GrafanaTheme, size: ButtonSize, variant: ButtonV
|
|
|
|
|
|
background = buttonVariantStyles(from, to, theme.colors.link, 'rgba(0, 0, 0, 0.1)', true);
|
|
|
break;
|
|
|
- case ButtonVariant.Transparent:
|
|
|
+ case 'transparent':
|
|
|
background = css`
|
|
|
${buttonVariantStyles('', '', theme.colors.link, 'rgba(0, 0, 0, 0.1)', true)};
|
|
|
background: transparent;
|
|
|
@@ -170,8 +158,8 @@ const getButtonStyles = (theme: GrafanaTheme, size: ButtonSize, variant: ButtonV
|
|
|
export const AbstractButton: React.FunctionComponent<AbstractButtonProps> = ({
|
|
|
renderAs,
|
|
|
theme,
|
|
|
- size = ButtonSize.Medium,
|
|
|
- variant = ButtonVariant.Primary,
|
|
|
+ size = 'md',
|
|
|
+ variant = 'primary',
|
|
|
className,
|
|
|
icon,
|
|
|
children,
|