Skip to content

Commit

Permalink
fix already declared TooltipProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyanideankst committed Oct 22, 2023
1 parent 6016c58 commit a008105
Showing 1 changed file with 37 additions and 26 deletions.
63 changes: 37 additions & 26 deletions packages/cyberstorm/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import React, {
useRef,
} from "react";
import styles from "./Button.module.css";
import { TooltipProvider } from "@radix-ui/react-tooltip";
import { Tooltip } from "../Tooltip/Tooltip";

export interface ButtonProps {
Expand Down Expand Up @@ -54,7 +53,7 @@ const Button = React.forwardRef<
const {
children,
plain = false,
type = "button",
type,
colorScheme = "default",
onClick,
paddingSize = "medium",
Expand All @@ -63,41 +62,53 @@ const Button = React.forwardRef<
...forwardedProps
} = props;

interface TooltipWrapperProps extends PropsWithChildren {
tooltipText?: string;
}

const TooltipWrapper = (props: TooltipWrapperProps) =>
props.tooltipText ? (
<Tooltip content={props.tooltipText} side="bottom">
{props.children}
</Tooltip>
) : (
<>{props.children}</>
);
const fallbackRef = useRef(null);

if (plain) {
const fRef = forwardedRef as React.ForwardedRef<HTMLDivElement>;
const ref = fRef || fallbackRef;
return (
<div
{...forwardedProps}
ref={ref}
className={`${styles.root} ${getIconAlignment(
iconAlignment
)} ${getStyle(colorScheme)} ${getPaddingSize(paddingSize)}`}
>
{children}
</div>
<TooltipWrapper tooltipText={tooltipText}>
<div
{...forwardedProps}
ref={ref}
className={`${styles.root} ${getIconAlignment(
iconAlignment
)} ${getStyle(colorScheme)} ${getPaddingSize(paddingSize)}`}
>
{children}
</div>
</TooltipWrapper>
);
} else {
const fRef = forwardedRef as React.ForwardedRef<HTMLButtonElement>;
const ref = fRef || fallbackRef;
return (
<TooltipProvider>
<Tooltip content={tooltipText} side="bottom">
<button
{...forwardedProps}
ref={ref}
type={type}
className={`${styles.root} ${getIconAlignment(
iconAlignment
)} ${getStyle(colorScheme)} ${getPaddingSize(paddingSize)}`}
onClick={onClick}
>
{children}
</button>
</Tooltip>
</TooltipProvider>
<TooltipWrapper tooltipText={tooltipText}>
<button
{...forwardedProps}
ref={ref}
type={type}
className={`${styles.root} ${getIconAlignment(
iconAlignment
)} ${getStyle(colorScheme)} ${getPaddingSize(paddingSize)}`}
onClick={onClick}
>
{children}
</button>
</TooltipWrapper>
);
}
});
Expand Down

0 comments on commit a008105

Please sign in to comment.