Skip to content

Commit

Permalink
feat: add generic tooltip component FadingTooltip
Browse files Browse the repository at this point in the history
This component:
 - has a default fading transition for consistency in the webapp
 - lets users have newlines in the tooltips messages
 - adds a div wrapper to prevent some warnings (e.g. on disabled buttons)
 - increases tooltip max width to 600px
  • Loading branch information
csm-thu committed Dec 13, 2022
1 parent 1cb512b commit 722e95b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export { UserInfo, HelpMenu } from './menus';
export {
ErrorBanner,
ErrorsPanel,
FadingTooltip,
FixedRatioContainer,
LoadingLine,
PermissionsGate,
Expand Down
25 changes: 25 additions & 0 deletions src/misc/FadingTooltip/FadingTooltip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Fade, Tooltip as MuiTooltip, withStyles } from '@material-ui/core';

const Tooltip = ({ children, ...other }) => {
return (
<MuiTooltip TransitionComponent={Fade} TransitionProps={{ timeout: 600 }} {...other}>
<div>{children}</div>
</MuiTooltip>
);
};

Tooltip.propTypes = {
/**
* Elements that trigger the tooltip when hovered
*/
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
};

export const FadingTooltip = withStyles((theme) => ({
tooltip: {
whiteSpace: 'pre-wrap',
maxWidth: '600px',
},
}))(Tooltip);
1 change: 1 addition & 0 deletions src/misc/FadingTooltip/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { FadingTooltip } from './FadingTooltip';
1 change: 1 addition & 0 deletions src/misc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export { ScenarioValidationStatusChip } from './ScenarioValidationStatusChip';
export { LoadingLine } from './LoadingLine';
export { ErrorBanner } from './ErrorBanner';
export { DefaultAvatar } from './DefaultAvatar';
export { FadingTooltip } from './FadingTooltip';
export { PermissionsGate } from './PermissionsGate';

0 comments on commit 722e95b

Please sign in to comment.