Skip to content

Commit

Permalink
chore: housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
DGiannaris committed Aug 28, 2024
1 parent ec1aab6 commit 2d37081
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 42 deletions.
50 changes: 18 additions & 32 deletions examples/storybook/src/stories/Tooltip.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ const meta: Meta<typeof Tooltip.Root> = {
title: "Components/Tooltip",
component: Tooltip.Root,
tags: ["autodocs"],
};

export default meta;

type Story = StoryObj<typeof Tooltip.Root>;

export const Uncontrolled: Story = {
decorators: [
(Story) => (
<div className="flex flex-col gap-4 items-start">
<Story />
</div>
),
],
};

export default meta;

type Story = StoryObj<typeof Tooltip.Root>;

export const Uncontrolled: Story = {
render: (args: TooltipProps["Root"]) => (
<Tooltip.Root {...args}>
<Tooltip.Trigger>
Expand Down Expand Up @@ -65,13 +65,6 @@ export const Uncontrolled: Story = {
};

export const Controlled: Story = {
decorators: [
(Story) => (
<div className="flex flex-col gap-4 items-start">
<Story />
</div>
),
],
render: (args) => {
const [open, setOpen] = React.useState(false);
return (
Expand All @@ -87,18 +80,18 @@ export const Controlled: Story = {
docs: {
source: {
code: `
const ControlledTooltip = () => {
const [open, setOpen] = React.useState(false);
const ControlledTooltip = () => {
const [open, setOpen] = React.useState(false);
return (
<Tooltip.Root open={open} onOpenChange={setOpen}>
<Tooltip.Trigger>
<span>Hover me</span>
</Tooltip.Trigger>
<Tooltip.Content label="Controlled Tooltip" />
</Tooltip.Root>
);
};
return (
<Tooltip.Root open={open} onOpenChange={setOpen}>
<Tooltip.Trigger>
<span>Hover me</span>
</Tooltip.Trigger>
<Tooltip.Content label="Controlled Tooltip" />
</Tooltip.Root>
);
};
`,
language: "jsx",
type: "code",
Expand All @@ -108,13 +101,6 @@ export const Controlled: Story = {
};

export const CustomContent: Story = {
decorators: [
(Story) => (
<div className="flex flex-col gap-4 items-start">
<Story />
</div>
),
],
render: (args: TooltipProps["Root"]) => (
<Tooltip.Root {...args}>
<Tooltip.Trigger>
Expand Down
12 changes: 2 additions & 10 deletions packages/ui/src/components/Tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
TooltipContentProps,
TooltipTriggerProps,
} from "./types";
import { sharedTooltipStyles } from "./styles";

export const TooltipRoot = ({
children,
Expand All @@ -29,15 +30,6 @@ export const TooltipRoot = ({

TooltipRoot.displayName = "Tooltip.Root";

const classnames = cn(
"py-2 px-3 rounded-md bg-gray-700 text-white max-w-[200px]",
"will-change-[transform,opacity]",
"data-[state=delayed-open]:data-[side=top]:animate-slide-up-and-fade",
"data-[state=delayed-open]:data-[side=right]:animate-slide-right-and-fade",
"data-[state=delayed-open]:data-[side=left]:animate-slide-left-and-fade",
"data-[state=delayed-open]:data-[side=bottom]:animate-slide-down-and-fade"
);

export const TooltipContent = ({
children,
label,
Expand All @@ -48,7 +40,7 @@ export const TooltipContent = ({
<TooltipPrimitive.Content
sideOffset={5}
forceMount
className={cn(classnames, className)}
className={cn(sharedTooltipStyles, className)}
>
{label ? (
<Text variant="body-small-200" noTranslations className="m-0 p-0">
Expand Down
10 changes: 10 additions & 0 deletions packages/ui/src/components/Tooltip/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { cn } from "../../utils/cn";

export const sharedTooltipStyles = cn(
"py-2 px-3 rounded-md bg-gray-700 text-white max-w-[200px]",
"will-change-[transform,opacity]",
"data-[state=delayed-open]:data-[side=top]:animate-slide-up-and-fade",
"data-[state=delayed-open]:data-[side=right]:animate-slide-right-and-fade",
"data-[state=delayed-open]:data-[side=left]:animate-slide-left-and-fade",
"data-[state=delayed-open]:data-[side=bottom]:animate-slide-down-and-fade",
);

0 comments on commit 2d37081

Please sign in to comment.