Skip to content

Commit

Permalink
Add button group tooltip examples
Browse files Browse the repository at this point in the history
  • Loading branch information
davismcphee committed Feb 24, 2024
1 parent fabad0c commit 2a3872d
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 3 deletions.
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 />,
};
3 changes: 0 additions & 3 deletions src-docs/src/views/button/button_group_icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ export default () => {
label: 'Underline',
name: 'underline',
iconType: 'editorUnderline',
title: 'Underline with a custom title',
titleDelay: 'short',
titlePosition: 'bottom',
},
{
id: `${idPrefix3}6`,
Expand Down
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)}
/>
);
};

0 comments on commit 2a3872d

Please sign in to comment.