Skip to content

(CDPE-4655) Add tooltip to Sidebar.Footer #552

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

Merged
merged 2 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
## react-components 5.33.1 (2022-03-04)

- [SidebarFooter] Add tooltip option (by [@chrisleicester](https://github.com/chrisleicester) in [#552](https://github.com/puppetlabs/design-system/pull/552))

## react-components 5.33.0 (2022-02-28)

- [Breadcrumb] Add Back type (by [@Lukeaber](https://github.com/Lukeaber) in [#549](https://github.com/puppetlabs/design-system/pull/549))

## react-components 5.32.5 (2022-02-24)

- [Icon] Add change and change warning icon

## react-components 5.32.4 (2022-02-11)

- [Icon] Add exception icon
Expand Down
4 changes: 2 additions & 2 deletions packages/react-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@puppet/react-components",
"version": "5.33.0",
"version": "5.33.1",
"author": "Puppet, Inc.",
"license": "Apache-2.0",
"main": "build/library.js",
Expand Down Expand Up @@ -90,4 +90,4 @@
"regenerator-runtime": "^0.13.7",
"scroll-into-view-if-needed": "^2.2.25"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import Badge from '../badge';
onClick={console.log}
enableSignout
onSignout={console.log}
signoutTooltip="This is a custom tooltip"
/>
</Sidebar>
</div>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Heading from '../heading';
import Text from '../text';
import Avatar from '../avatar';
import Button from '../button';
import TooltipHoverArea from '../tooltips/TooltipHoverArea';

const propTypes = {
/** The root HTML element */
Expand All @@ -20,6 +21,8 @@ const propTypes = {
profileIcon: PropTypes.node,
/** Boolean flag to enable or disable (default) signout button */
enableSignout: PropTypes.bool,
/** Sign-out icon tooltip text */
signoutTooltip: PropTypes.string,
/** Signout callback function */
onSignout: PropTypes.func,
};
Expand All @@ -31,6 +34,7 @@ const defaultProps = {
minimized: false,
profileIcon: null,
enableSignout: false,
signoutTooltip: 'Sign out',
onSignout: () => {},
};

Expand All @@ -41,6 +45,7 @@ const SidebarFooter = ({
minimized,
profileIcon: profileIconProp,
enableSignout,
signoutTooltip,
onSignout,
...rest
}) => {
Expand All @@ -65,12 +70,14 @@ const SidebarFooter = ({

if (enableSignout) {
signout = (
<Button
className="rc-sidebar-footer-button-signout"
onClick={onSignout}
>
<Icon type="sign-out" className="rc-sidebar-footer-signout-icon" />
</Button>
<TooltipHoverArea anchor="top" tooltip={signoutTooltip}>
<Button
className="rc-sidebar-footer-button-signout"
onClick={onSignout}
>
<Icon type="sign-out" className="rc-sidebar-footer-signout-icon" />
</Button>
</TooltipHoverArea>
);
}
}
Expand Down
34 changes: 34 additions & 0 deletions packages/react-components/test/sidebar/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,39 @@ describe('<Sidebar />', () => {
wrapper.find('.rc-sidebar-footer-button-signout').simulate('click');
expect(callback.calledOnce).to.be.true;
});

it('should not render tooltip when sigout is disabled', () => {
const callback = sinon.fake();
const wrapper = shallow(
<Sidebar.Footer tooltip="I love being a tooltip" />,
);

expect(wrapper.find('TooltipHoverArea').length).to.eql(0);
});

it('should render the default tooltip when no tooltip is specified', () => {
const callback = sinon.fake();
const wrapper = shallow(
<Sidebar.Footer enableSignout onSignout={callback} />,
);
expect(wrapper.find('TooltipHoverArea').prop('tooltip')).to.eql(
'Sign out',
);
});

it('should render a a custom tooltip when specified', () => {
const callback = sinon.fake();
const wrapper = shallow(
<Sidebar.Footer
enableSignout
onSignout={callback}
signoutTooltip="I love being a tooltip"
/>,
);

expect(wrapper.find('TooltipHoverArea').prop('tooltip')).to.eql(
'I love being a tooltip',
);
});
});
});