Skip to content

Commit

Permalink
add tooltip to button component
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyanideankst committed Oct 16, 2023
1 parent 189871a commit 7dcfdca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const meta = {
component: Button.Root,
} as Meta<typeof Button.Root>;

const defaultArgs = {};
const defaultArgs = {
tooltipText: "tooltip text",
};

const Template: StoryFn<typeof Button> = (args) => (
<div
Expand Down
30 changes: 19 additions & 11 deletions packages/cyberstorm/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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 {
children?: ReactNode | ReactNode[];
Expand Down Expand Up @@ -39,6 +41,7 @@ export interface ButtonProps {
onMouseOut?: MouseEventHandler<HTMLElement>;
style?: { [key: string]: string };
type?: "button" | "submit" | "reset";
tooltipText?: string;
}

/**
Expand All @@ -56,6 +59,7 @@ const Button = React.forwardRef<
onClick,
paddingSize = "medium",
iconAlignment = "default",
tooltipText,
...forwardedProps
} = props;

Expand All @@ -79,17 +83,21 @@ const Button = React.forwardRef<
const fRef = forwardedRef as React.ForwardedRef<HTMLButtonElement>;
const ref = fRef || fallbackRef;
return (
<button
{...forwardedProps}
ref={ref}
type={type}
className={`${styles.root} ${getIconAlignment(
iconAlignment
)} ${getStyle(colorScheme)} ${getPaddingSize(paddingSize)}`}
onClick={onClick}
>
{children}
</button>
<TooltipProvider>
<Tooltip content={tooltipText}>
<button
{...forwardedProps}
ref={ref}
type={type}
className={`${styles.root} ${getIconAlignment(
iconAlignment
)} ${getStyle(colorScheme)} ${getPaddingSize(paddingSize)}`}
onClick={onClick}
>
{children}
</button>
</Tooltip>
</TooltipProvider>
);
}
});
Expand Down

0 comments on commit 7dcfdca

Please sign in to comment.