mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-25 21:56:08 +00:00
67 lines
1.4 KiB
Plaintext
67 lines
1.4 KiB
Plaintext
---
|
|
title: Tooltip
|
|
description: A popup that displays information related to an element when the element receives keyboard focus or the mouse hovers over it.
|
|
component: true
|
|
radix:
|
|
link: https://www.radix-ui.com/docs/primitives/components/tooltip
|
|
api: https://www.radix-ui.com/docs/primitives/components/tooltip#api-reference
|
|
---
|
|
|
|
<ComponentExample src="/components/examples/tooltip/demo.tsx">
|
|
<TooltipDemo />
|
|
</ComponentExample>
|
|
|
|
## Installation
|
|
|
|
```bash
|
|
npx shadcn-ui add tooltip
|
|
```
|
|
|
|
<Accordion type="single" collapsible>
|
|
<AccordionItem value="manual-installation">
|
|
<AccordionTrigger>Manual Installation</AccordionTrigger>
|
|
<AccordionContent>
|
|
|
|
1. Install the `@radix-ui/react-tooltip` component from radix-ui:
|
|
|
|
```bash
|
|
npm install @radix-ui/react-tooltip
|
|
```
|
|
|
|
2. Copy and paste the following code into your project.
|
|
|
|
<ComponentSource src="/components/ui/tooltip.tsx" />
|
|
|
|
<Callout>
|
|
|
|
This is the `<Tooltip />` primitive. You can place it in a file at `components/ui/tooltip.tsx`.
|
|
|
|
</Callout>
|
|
|
|
</AccordionContent>
|
|
|
|
</AccordionItem>
|
|
</Accordion>
|
|
|
|
## Usage
|
|
|
|
```tsx
|
|
import {
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipProvider,
|
|
TooltipTrigger,
|
|
} from "@/components/ui/tooltip"
|
|
```
|
|
|
|
```tsx
|
|
<TooltipProvider>
|
|
<Tooltip>
|
|
<TooltipTrigger>Hover</TooltipTrigger>
|
|
<TooltipContent>
|
|
<p>Add to library</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</TooltipProvider>
|
|
```
|