Skip to content

Commit

Permalink
Merge pull request #6111 from signalco-io/feat/ui-primitives/tooltip
Browse files Browse the repository at this point in the history
Feat/UI primitives/tooltip
  • Loading branch information
AleksandarDev authored Oct 20, 2024
2 parents 3130aa3 + 09a2fd6 commit c85e1a3
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 18 deletions.
37 changes: 37 additions & 0 deletions web/apps/ui-docs/stories/Primitives/Tooltip.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Info } from "@signalco/ui-icons";
import { Stack } from "@signalco/ui-primitives/Stack";
import { Tooltip, TooltipTrigger, TooltipContent } from "@signalco/ui-primitives/Tooltip";
import { Typography } from "@signalco/ui-primitives/Typography";
import { StoryObj } from "@storybook/react";

export default {
component: Tooltip,
tags: ['autodocs'],
args: {
delayDuration: 0,
children: (
<>
<TooltipTrigger>
<Info />
</TooltipTrigger>
<TooltipContent>
<Stack>
<Typography level="body1">Tooltip content</Typography>
<Typography level="body2">Example of tooltip with components as children</Typography>
</Stack>
</TooltipContent>
</>
)
}
};
type Story = StoryObj<typeof Tooltip>;

export const Default: Story = {
decorators: [
(Story) => (
<div className="p-8 flex flex-col items-center">
<Story />
</div>
)
]
};
3 changes: 2 additions & 1 deletion web/packages/ui-primitives/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@signalco/ui-primitives",
"version": "0.1.11",
"version": "0.1.12",
"license": "MIT",
"type": "module",
"sideEffects": false,
Expand Down Expand Up @@ -33,6 +33,7 @@
"@radix-ui/react-select": "2.1.2",
"@radix-ui/react-slot": "1.1.0",
"@radix-ui/react-tabs": "1.1.1",
"@radix-ui/react-tooltip": "1.1.3",
"@signalco/eslint-config-signalco": "workspace:*",
"@signalco/hooks": "workspace:*",
"@signalco/js": "workspace:*",
Expand Down
35 changes: 35 additions & 0 deletions web/packages/ui-primitives/src/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as TooltipPrimitive from "@radix-ui/react-tooltip"

import { ComponentPropsWithoutRef, ElementRef, forwardRef, ReactNode } from "react"
import { cx } from "../cx"
import { TooltipProviderProps } from "@radix-ui/react-tooltip"

const TooltipTrigger = TooltipPrimitive.Trigger

const TooltipContent = forwardRef<
ElementRef<typeof TooltipPrimitive.Content>,
ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
>(({ className, sideOffset = 4, ...props }, ref) => (
<TooltipPrimitive.Content
ref={ref}
sideOffset={sideOffset}
className={cx(
"z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
className
)}
{...props}
/>
))
TooltipContent.displayName = TooltipPrimitive.Content.displayName

export function Tooltip({ delayDuration, children }: { children: ReactNode, delayDuration: TooltipProviderProps['delayDuration'] }) {
return (
<TooltipPrimitive.Provider delayDuration={delayDuration}>
<TooltipPrimitive.Root>
{children}
</TooltipPrimitive.Root>
</TooltipPrimitive.Provider>
)
}

export { TooltipTrigger, TooltipContent }
3 changes: 3 additions & 0 deletions web/packages/ui-primitives/src/Tooltip/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use client';

export * from './Tooltip';
70 changes: 53 additions & 17 deletions web/pnpm-lock.yaml

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

0 comments on commit c85e1a3

Please sign in to comment.