Skip to content

Commit

Permalink
fix: add tooltip to button
Browse files Browse the repository at this point in the history
  • Loading branch information
richardmichel committed May 29, 2023
1 parent 634ab72 commit 6153873
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"react-popper": "^2.2.4",
"react-select": "^5.7.0",
"react-spinners": "^0.13.8",
"react-tooltip": "^5.13.1",
"react-transition-group": "^4.4.2",
"uncontrollable": "^7.2.1",
"uuid": "^9.0.0",
Expand Down
31 changes: 12 additions & 19 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import {
import { useBootstrapPrefix } from './ThemeProvider';
import { BsPrefixProps, BsPrefixRefForwardingComponent } from './helpers';
import { ButtonVariant } from './types';
import OverlayTrigger from './OverlayTrigger';
import { Tooltip2 } from './Tooltip2';
import { v4 as uuid } from 'uuid';
import { Tooltip as ReactTooltip } from 'react-tooltip';

const faAsterisk = {
prefix: 'fal',
Expand Down Expand Up @@ -129,20 +128,20 @@ const defaultProps = {
const useTooltip = (tooltip: any) => {
if (!tooltip) {
return {
tooltipOpen: false,
/* tooltipOpen: false,
setTooltipOpen: null,
toggle: () => {},
toggle: () => {}, */
tooltipId: null,
};
}
const [tooltipOpen, setTooltipOpen] = React.useState(false);
const toggle = () => setTooltipOpen(!tooltipOpen);
/* const [tooltipOpen, setTooltipOpen] = React.useState(false);
const toggle = () => setTooltipOpen(!tooltipOpen); */
const [tooltipId] = React.useState(`button-tooltip-${uuid()}`);

return {
tooltipOpen,
/* tooltipOpen,
setTooltipOpen,
toggle,
toggle, */
tooltipId,
};
};
Expand Down Expand Up @@ -170,8 +169,8 @@ export const Button: BsPrefixRefForwardingComponent<'button', ButtonProps> =
},
ref
) => {
const { tooltipOpen, setTooltipOpen, toggle, tooltipId } =
useTooltip(tooltip);
const { tooltipId } = useTooltip(tooltip);
// tooltipOpen, setTooltipOpen, toggle,

const prefix = useBootstrapPrefix(bsPrefix, 'btn');
const [buttonProps, { tagName }] = useButtonProps({
Expand Down Expand Up @@ -247,7 +246,8 @@ export const Button: BsPrefixRefForwardingComponent<'button', ButtonProps> =
{...{
...(tooltip &&
tooltipId && {
id: tooltipId,
'data-tooltip-id': tooltipId,
'data-tooltip-content': tooltip,
}),
}}
>
Expand All @@ -266,14 +266,7 @@ export const Button: BsPrefixRefForwardingComponent<'button', ButtonProps> =
</Component>

{tooltip && tooltipId && (
<Tooltip2
placement={'top'}
isOpen={tooltipOpen}
target={tooltipId}
toggle={toggle}
>
<p>{tooltip}</p>
</Tooltip2>
<ReactTooltip id={tooltipId} place="top" />
)}
</React.Fragment>
);
Expand Down
7 changes: 2 additions & 5 deletions src/components/Tooltip2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface ITooltipProps {
isOpen?: boolean;
target?: any;
toggle?: () => void;
fade?: boolean;
}

export const Tooltip2 = React.forwardRef<HTMLInputElement, ITooltipProps>(
Expand All @@ -25,7 +26,6 @@ export const Tooltip2 = React.forwardRef<HTMLInputElement, ITooltipProps>(
children,
...propsMain
},
// @ts-ignore
ref
) => {
const props = {
Expand All @@ -37,10 +37,6 @@ export const Tooltip2 = React.forwardRef<HTMLInputElement, ITooltipProps>(
...propsMain,
};

/* if (ref) {
props.ref = ref;
} */

const popperClasses = classNames(
'tooltip',
'show',
Expand All @@ -54,6 +50,7 @@ export const Tooltip2 = React.forwardRef<HTMLInputElement, ITooltipProps>(
arrowClassName="tooltip-arrow"
popperClassName={popperClasses}
innerClassName={classes}
ref={ref}
/>
);
}
Expand Down

0 comments on commit 6153873

Please sign in to comment.