diff --git a/packages/grafana-ui/src/components/IconButton/IconButton.mdx b/packages/grafana-ui/src/components/IconButton/IconButton.mdx index cc6a022d1c4..c8190bca17c 100644 --- a/packages/grafana-ui/src/components/IconButton/IconButton.mdx +++ b/packages/grafana-ui/src/components/IconButton/IconButton.mdx @@ -9,6 +9,7 @@ import { Alert } from '../Alert/Alert'; This component looks just like an icon but behaves like a button. It fulfils an action when you click it and has hover and focus states. You can choose which icon size you would like to use. `IconButton` is best used when you only want an icon instead of a button with text, for example when you want to place a solitary clickable icon next to text. An example where an `IconButton` is used in Grafana is the hamburger icon at the top left which opens the new navigation. +When using `IconButton` right next to a text element consider wrapping both in a flex container and use `align-items: center;` to make them align properly. Always keep in mind to add text for a tooltip and an aria label. diff --git a/packages/grafana-ui/src/components/IconButton/IconButton.story.tsx b/packages/grafana-ui/src/components/IconButton/IconButton.story.tsx index 8f5e3d40e97..399b1e247e8 100644 --- a/packages/grafana-ui/src/components/IconButton/IconButton.story.tsx +++ b/packages/grafana-ui/src/components/IconButton/IconButton.story.tsx @@ -44,63 +44,50 @@ export const Basic: StoryFn = (args: IconButtonProps) => { }; export const ExamplesSizes = () => { + const theme = useTheme2(); const sizes: IconSize[] = ['xs', 'sm', 'md', 'lg', 'xl']; const icons: IconName[] = ['search', 'trash-alt', 'arrow-left', 'times']; const variants: IconButtonVariant[] = ['primary', 'secondary', 'destructive']; + const rowStyle = css` + display: flex; + gap: ${theme.spacing(1)}; + margin-bottom: ${theme.spacing(2)}; + `; + return ( -
- - {variants.map((variant) => { - return ( -
-

{variant}

- {icons.map((icon) => { - return ( -
- {sizes.map((size) => ( - - - - ))} -
- ); - })} -
- ); - })} -
-

disabled

- {icons.map((icon) => ( -
- {sizes.map((size) => ( - - - - ))} -
- ))} -
-
-
+ + {variants.map((variant) => { + return ( +
+

{variant}

+ {icons.map((icon) => { + return ( +
+ {sizes.map((size) => ( + + + + ))} +
+ ); + })} +
+ ); + })} +
+

disabled

+ {icons.map((icon) => ( +
+ {sizes.map((size) => ( + + + + ))} +
+ ))} +
+
); }; @@ -123,10 +110,6 @@ const RenderBackgroundScenario = ({ background }: ScenarioProps) => { className={css` padding: 30px; background: ${theme.colors.background[background]}; - button { - margin-right: 8px; - margin-left: 8px; - } `} > @@ -134,6 +117,7 @@ const RenderBackgroundScenario = ({ background }: ScenarioProps) => {
{variants.map((variant) => { diff --git a/packages/grafana-ui/src/components/IconButton/IconButton.tsx b/packages/grafana-ui/src/components/IconButton/IconButton.tsx index 9c508075ebf..72dbc49d732 100644 --- a/packages/grafana-ui/src/components/IconButton/IconButton.tsx +++ b/packages/grafana-ui/src/components/IconButton/IconButton.tsx @@ -124,13 +124,14 @@ const getStyles = stylesFactory((theme: GrafanaTheme2, size, variant: IconButton &:before { z-index: -1; position: absolute; + opacity: 0; width: ${hoverSize}px; height: ${hoverSize}px; border-radius: ${theme.shape.radius.default}; content: ''; transition-duration: 0.2s; transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); - transition-property: transform, opacity; + transition-property: opacity; } &:focus, @@ -147,6 +148,7 @@ const getStyles = stylesFactory((theme: GrafanaTheme2, size, variant: IconButton background-color: ${variant === 'secondary' ? theme.colors.action.hover : colorManipulator.alpha(iconColor, 0.12)}; + opacity: 1; } } `,