mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Grafana UI: Fix tooltip prop of button component (#64765)
fix tooltip prop of Button component
This commit is contained in:
committed by
GitHub
parent
a6b2bc3997
commit
1c7921770c
@@ -2,6 +2,7 @@ import { ComponentStory } from '@storybook/react';
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { ComponentSize } from '../../types/size';
|
import { ComponentSize } from '../../types/size';
|
||||||
|
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
||||||
import { Card } from '../Card/Card';
|
import { Card } from '../Card/Card';
|
||||||
import { HorizontalGroup, VerticalGroup } from '../Layout/Layout';
|
import { HorizontalGroup, VerticalGroup } from '../Layout/Layout';
|
||||||
|
|
||||||
@@ -14,6 +15,7 @@ const sizes: ComponentSize[] = ['lg', 'md', 'sm'];
|
|||||||
export default {
|
export default {
|
||||||
title: 'Buttons/Button',
|
title: 'Buttons/Button',
|
||||||
component: Button,
|
component: Button,
|
||||||
|
decorators: [withCenteredStory],
|
||||||
parameters: {
|
parameters: {
|
||||||
docs: {
|
docs: {
|
||||||
page: mdx,
|
page: mdx,
|
||||||
@@ -24,14 +26,7 @@ export default {
|
|||||||
options: sizes,
|
options: sizes,
|
||||||
},
|
},
|
||||||
tooltip: {
|
tooltip: {
|
||||||
table: {
|
control: 'text',
|
||||||
disable: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
tooltipPlacement: {
|
|
||||||
table: {
|
|
||||||
disable: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
className: {
|
className: {
|
||||||
table: {
|
table: {
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|||||||
children,
|
children,
|
||||||
className,
|
className,
|
||||||
type = 'button',
|
type = 'button',
|
||||||
|
tooltip,
|
||||||
|
tooltipPlacement,
|
||||||
...otherProps
|
...otherProps
|
||||||
},
|
},
|
||||||
ref
|
ref
|
||||||
@@ -58,12 +60,22 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|||||||
iconOnly: !children,
|
iconOnly: !children,
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
const button = (
|
||||||
<button className={cx(styles.button, className)} type={type} {...otherProps} ref={ref}>
|
<button className={cx(styles.button, className)} type={type} {...otherProps} ref={ref}>
|
||||||
{icon && <Icon name={icon} size={size} className={styles.icon} />}
|
{icon && <Icon name={icon} size={size} className={styles.icon} />}
|
||||||
{children && <span className={styles.content}>{children}</span>}
|
{children && <span className={styles.content}>{children}</span>}
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (tooltip) {
|
||||||
|
return (
|
||||||
|
<Tooltip content={tooltip} placement={tooltipPlacement}>
|
||||||
|
{button}
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return button;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user