Tooltip
追加のコンテキストや情報を提供する、フローティング型のインテリジェントなラベル。ホバーまたはクリックでトリガーでき、視覚的な矢印が含まれており、エッジの衝突を回避します。
いつ使用するか
- Tooltipは複雑なテキストや操作をサポートしていません。マウスオーバーでヒントが表示され、マウスが離れると非表示になります。
- ボタン/テキスト/操作の説明を提供する場合。ボタン/テキスト/操作を説明するためにHTMLのtitle属性の代わりに頻繁に使用されます。
ラッパーコンポーネント
Tooltipコンポーネントを使用して要素をラップし、contentおよびpositionプロパティを構成できます。
astro
---
import Tooltip from '@/components/data-display/Tooltip.astro';
import Button from '@/components/general/Button.astro';
---
<Tooltip content="I appear on top" position="top">
<Button variant="outline">Top</Button>
</Tooltip> データ属性(ラッパーなし)
Tooltipはグローバルリスナーを作成するため、要素をインポートしたりラップしたりする必要はありません。任意のHTML要素にdata-tooltip属性を追加するだけです!これは、インラインテキストや動的コンテンツに最適です。
This is a paragraph with some inline tooltipable text that works without any wrappers.
astro
<p>
This is a paragraph with some <span data-tooltip="This is an inline explanation!" data-tooltip-pos="top">inline tooltipable text</span>.
</p> リッチコンテンツとクリック
trigger="click"を使用すると、ホバーの代わりにクリックでツールチップをトリガーすることもできます。スロット(または直接のプロパティ)を使用して、複雑なHTMLコンテンツやタイトルを渡すこともできます。
Rich Tooltip
This is a multi-line paragraph describing the complex content that can be passed to the Tooltip component using slots.
astro
---
import Tooltip from '@/components/data-display/Tooltip.astro';
import Button from '@/components/general/Button.astro';
import Icon from '@/components/general/Icon.astro';
---
<Tooltip trigger="click" position="bottom">
<Button variant="primary">Click Me</Button>
<div slot="title" class="flex items-center gap-2">
<Icon name="Info" class="h-4 w-4 text-blue-400" />
<span>Rich Tooltip</span>
</div>
<div slot="content" class="flex flex-col gap-2 p-1">
<p class="text-xs max-w-xs">
This is a multi-line paragraph describing the complex content that can be passed to the Tooltip component using slots.
</p>
</div>
</Tooltip> プロパティによるアプローチ
複雑なツールチップにスロットを使用する代わりに、title、description、およびiconをコンポーネントプロパティを介して直接渡すことで、よりクリーンな構文にすることができます。
Quick Tip
You can define the entire tooltip layout directly using props rather than slots.
astro
---
import Tooltip from '@/components/data-display/Tooltip.astro';
import Button from '@/components/general/Button.astro';
---
<Tooltip
title="Quick Tip"
description="You can define the entire tooltip layout directly using props rather than slots."
icon="Lightbulb"
position="right"
>
<Button variant="outline" >Hover for Tips</Button>
</Tooltip> API リファレンス
| プロパティ | 説明 | タイプ | デフォルト |
|---|---|---|---|
| content | 表示するメインテキストコンテンツ | string | '-' |
| title | Tooltip | string | '-' |
| description | コンテンツの下のオプションの控えめな説明テキスト | string | '-' |
| icon | テキストと一緒にレンダリングするオプションのIconName | IconName | '-' |
| position | トリガーの周囲の優先配置 | 'top' | 'bottom' | 'left' | 'right' | 'top' |
| trigger | ツールチップを表示させるイベント | 'hover' | 'click' | 'hover' |