Tooltip
Tooltip Component Documentation
The Tooltip component in the Shadcn UI library provides a way to display additional information when users hover over or interact with an element. Tooltips are commonly used to provide context or explanations for UI elements.
Basic Usage
To use the Tooltip component, follow these steps:
- Import the
Tooltip
component from the Shadcn UI library. - Wrap the element you want to attach the tooltip to with the
Tooltip
component. - Set the
content
prop to define the text that should appear in the tooltip. - Specify the
position
prop to determine where the tooltip should appear (e.g., "top", "bottom", "left", or "right").
import { Tooltip } from 'shadcn-ui';
function App() {
return (
<Tooltip content="This is a tooltip" position="top">
<button>Hover Me</button>
</Tooltip>
);
}
Props
The Tooltip component accepts the following props:
content
(required): The content to be displayed in the tooltip.position
(optional): The position where the tooltip should appear in relation to the element. Possible values are "top", "bottom", "left", or "right". Default is "top".delay
(optional): The delay (in milliseconds) before the tooltip appears when the user hovers over the element. Default is 0.arrow
(optional): Whether to display an arrow pointing to the element. Default istrue
.
Custom Styling
The Tooltip component supports custom styling through CSS. You can target the .shadcn-tooltip
class for general styling and use modifier classes for specific positions (e.g., .shadcn-tooltip-top
, .shadcn-tooltip-bottom
, etc.).
.shadcn-tooltip {
background-color: #333;
color: white;
border-radius: 4px;
padding: 8px;
}
.shadcn-tooltip-bottom {
/* Custom styling for tooltips at the bottom */
background-color: #555;
}
Examples
Tooltip with Different Positions
import { Tooltip } from 'shadcn-ui';
function App() {
return (
<div>
<Tooltip content="Top Tooltip" position="top">
<button>Top</button>
</Tooltip>
<Tooltip content="Bottom Tooltip" position="bottom">
<button>Bottom</button>
</Tooltip>
<Tooltip content="Left Tooltip" position="left">
<button>Left</button>
</Tooltip>
<Tooltip content="Right Tooltip" position="right">
<button>Right</button>
</Tooltip>
</div>
);
}
Tooltip with Delay
import { Tooltip } from 'shadcn-ui';
function App() {
return (
<Tooltip content="Delayed Tooltip" delay={500}>
<button>Hover Me</button>
</Tooltip>
);
}
Conclusion
The Tooltip component from the Shadcn UI library simplifies the process of adding helpful tooltips to your user interface. By following the provided examples and understanding the available props, you can enhance the user experience of your applications.
For more details and advanced usage, refer to the official Shadcn UI Tooltip Documentation.
Please note that this Markdown representation is based on the information provided in the Shadcn UI
Tooltip Component with Tailwind CSS
The Tooltip component from Shadcn UI allows you to create interactive tooltips that provide additional information when users hover over an element. You can easily integrate Tooltip with Tailwind CSS to style both the element and the tooltip content.
Installation To get started, make sure you have the Shadcn UI library and Tailwind CSS set up in your project.
- Install Shadcn UI:
npm install shadcn-ui
Install Tailwindcss (if not already installed):
npm install tailwindcss
## Usage
Wrap the element you want to add a tooltip to with the `Tooltip` component. Apply Tailwind CSS classes to style the element and the tooltip content.
```jsx
import { Tooltip } from 'shadcn-ui';
function App() {
return (
<div className="flex justify-center items-center h-screen">
{/* Wrap the element with the Tooltip component */}
<Tooltip content="This is a tooltip" position="top">
{/* Apply Tailwind CSS classes to style the element */}
<button className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">Hover Me</button>
</Tooltip>
</div>
);
}
In this example, the Tooltip
component wraps a button
element. The button has Tailwind CSS classes applied to style its appearance. The tooltip inherits the styles from the button and the default tooltip styles from the Shadcn UI library.
You can further customize the appearance by targeting the .shadcn-tooltip
class or using modifier classes like .shadcn-tooltip-top
, .shadcn-tooltip-bottom
, etc.
Remember to include the necessary Tailwind CSS classes and styles in your project to achieve the desired appearance for both the element and the tooltip.
Now you have an interactive tooltip that's beautifully styled with Tailwind CSS!
Feel free to use this Markdown guide as a reference to integrate the Tooltip component with Tailwind CSS in