From 0836e7bde89a2ebd1842ee4d09c3007160726d1c Mon Sep 17 00:00:00 2001 From: Jack Westbrook Date: Thu, 29 Apr 2021 10:47:06 +0200 Subject: [PATCH] IconButton: introduce variant for red and blue icon buttons (#33479) * feat(iconbutton): introduce variant for red and blue icon buttons * refactor(iconbutton): give variants breathing space in story * docs(iconbutton): add docblock comment for variant prop * refactor(iconbutton): prefer secondary to undefined variant prop and add default * refactor(iconbutton): use icon color for hover --- .../IconButton/IconButton.story.tsx | 28 +++++++++++++------ .../src/components/IconButton/IconButton.tsx | 28 ++++++++++++++----- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/packages/grafana-ui/src/components/IconButton/IconButton.story.tsx b/packages/grafana-ui/src/components/IconButton/IconButton.story.tsx index 5294fee2b45..3a0737d31c0 100644 --- a/packages/grafana-ui/src/components/IconButton/IconButton.story.tsx +++ b/packages/grafana-ui/src/components/IconButton/IconButton.story.tsx @@ -1,10 +1,11 @@ import React from 'react'; import { css } from '@emotion/css'; -import { IconButton } from '@grafana/ui'; +import { IconButton, IconButtonVariant } from './IconButton'; import { withCenteredStory } from '../../utils/storybook/withCenteredStory'; import { useTheme2 } from '../../themes'; import { IconSize, IconName } from '../../types'; import mdx from './IconButton.mdx'; +import { VerticalGroup } from '../Layout/Layout'; export default { title: 'Buttons/IconButton', @@ -35,6 +36,7 @@ const RenderScenario = ({ background }: ScenarioProps) => { const theme = useTheme2(); const sizes: IconSize[] = ['sm', 'md', 'lg', 'xl', 'xxl']; const icons: IconName[] = ['search', 'trash-alt', 'arrow-left', 'times']; + const variants: IconButtonVariant[] = ['secondary', 'primary', 'destructive']; return (
{ } `} > -
{background}
- {icons.map((icon) => { - return sizes.map((size) => ( - - - - )); - })} + +
{background}
+ {variants.map((variant) => { + return ( +
+ {icons.map((icon) => { + return sizes.map((size) => ( + + + + )); + })} +
+ ); + })} +
); }; diff --git a/packages/grafana-ui/src/components/IconButton/IconButton.tsx b/packages/grafana-ui/src/components/IconButton/IconButton.tsx index aa0d10f906f..ec9da91e4dd 100644 --- a/packages/grafana-ui/src/components/IconButton/IconButton.tsx +++ b/packages/grafana-ui/src/components/IconButton/IconButton.tsx @@ -4,11 +4,13 @@ import { IconName, IconSize, IconType } from '../../types/icon'; import { stylesFactory } from '../../themes/stylesFactory'; import { css, cx } from '@emotion/css'; import { useTheme2 } from '../../themes/ThemeContext'; -import { GrafanaThemeV2 } from '@grafana/data'; +import { GrafanaThemeV2, colorManipulator } from '@grafana/data'; import { Tooltip } from '../Tooltip/Tooltip'; import { TooltipPlacement } from '../Tooltip/PopoverController'; import { getFocusStyles, getMouseFocusStyles } from '../../themes/mixins'; +export type IconButtonVariant = 'primary' | 'secondary' | 'destructive'; + export interface Props extends React.ButtonHTMLAttributes { /** Name of the icon **/ name: IconName; @@ -22,14 +24,16 @@ export interface Props extends React.ButtonHTMLAttributes { tooltip?: string; /** Position of the tooltip */ tooltipPlacement?: TooltipPlacement; + /** Variant to change the color of the Icon */ + variant?: IconButtonVariant; } type SurfaceType = 'dashboard' | 'panel' | 'header'; export const IconButton = React.forwardRef( - ({ name, size = 'md', iconType, tooltip, tooltipPlacement, className, ...restProps }, ref) => { + ({ name, size = 'md', iconType, tooltip, tooltipPlacement, className, variant = 'secondary', ...restProps }, ref) => { const theme = useTheme2(); - const styles = getStyles(theme, size); + const styles = getStyles(theme, size, variant); const button = (