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' |