Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EuiButtonGroup] Add support for EuiToolTip for button tooltips #7461

Merged
merged 18 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/upcoming/7461.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Added support for showing `EuiTooltip` components on `EuiButtonGroup` buttons

53 changes: 53 additions & 0 deletions src-docs/src/views/button/button_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,28 @@ const buttonGroupCompressedSnippet = [
/>`,
];

import ButtonGroupToolTips from './button_group_tooltips';
const buttonGroupToolTipsSource = require('!!raw-loader!./button_group_tooltips');
const buttonGroupToolTipsSnippet = [
`<EuiButtonGroup
legend={legend}
options={[
{
id,
label,
toolTipContent,
toolTipProps: {
title,
delay,
position,
},
},
]}
idSelected={idSelected}
onChange={(optionId) => {}}
/>`,
];

export const ButtonExample = {
title: 'Button',
intro: (
Expand Down Expand Up @@ -697,6 +719,37 @@ export const ButtonExample = {
props: { EuiButtonGroup, EuiButtonGroupOptionProps },
demoPanelProps: { color: 'subdued' },
},
{
source: [
{
type: GuideSectionTypes.JS,
code: buttonGroupToolTipsSource,
},
],

text: (
<>
<h3>Button group tooltips</h3>
<p>
Buttons within a button group will automatically get a{' '}
<EuiCode>title</EuiCode> attribute containing the button{' '}
<EuiCode>label</EuiCode>, which displays a default browser tooltip.
</p>
<p>
To instead display an <EuiCode>EuiToolTip</EuiCode> containing
custom content, you can add a <EuiCode>toolTipContent</EuiCode> prop
to the button options.
</p>
<p>
You can also use <EuiCode>toolTipProps</EuiCode> to customize
tooltip placement, title, and other behaviors.
</p>
</>
),
demo: <ButtonGroupToolTips />,
snippet: buttonGroupToolTipsSnippet,
props: { EuiButtonGroup, EuiButtonGroupOptionProps },
},
],
guidelines: <Guidelines />,
};
42 changes: 42 additions & 0 deletions src-docs/src/views/button/button_group_tooltips.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React, { useState } from 'react';

import { EuiButtonGroup } from '../../../../src/components';

export default () => {
const toggleButtons = [
{
id: 'buttonGroup__0',
label: 'Default title',
},
{
id: 'buttonGroup__1',
label: 'Custom tooltip content',
toolTipContent: 'This is a custom tooltip',
},
{
id: 'buttonGroup__2',
label: 'Custom tooltip props',
toolTipContent: 'This is another custom tooltip',
toolTipProps: {
title: 'My custom title',
delay: 'regular',
position: 'right',
},
},
];

const [toggleIdSelected, setToggleIdSelected] = useState('buttonGroup__1');

const onChange = (optionId) => {
setToggleIdSelected(optionId);
};

return (
<EuiButtonGroup
legend="This is a group with tooltips"
options={toggleButtons}
idSelected={toggleIdSelected}
onChange={(id) => onChange(id)}
/>
);
};
Loading
Loading