-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
86 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,55 @@ | ||
import { JSXOutput, PropsOf, component$, useSignal } from '@builder.io/qwik' | ||
import { PropsOf, Slot, component$, useSignal } from '@builder.io/qwik' | ||
import { Placement } from '@floating-ui/dom' | ||
import { TooltipStyle } from './tooltip-types' | ||
import { FloatingTrigger } from '../Floating/floating-types' | ||
import { RenderFloatingArrow, RenderFloatingElement, RenderFloatingTrigger } from '../Floating/Floating' | ||
import { RenderFloatingArrow, RenderFloatingElement } from '../Floating/Floating' | ||
import { useFloating } from '~/composables/use-floating' | ||
|
||
type TooltipProps = PropsOf<'div'> & { | ||
placement?: Placement | ||
style?: TooltipStyle | ||
triggerStrategy?: FloatingTrigger | ||
trigger?: FloatingTrigger | ||
noArrow?: boolean | ||
trigger?: JSXOutput | ||
content?: JSXOutput | ||
} | ||
|
||
export const Tooltip = component$<TooltipProps>( | ||
({ placement = 'top', trigger, content, triggerStrategy = 'hover', style = 'auto', noArrow = false }) => { | ||
const isVisible = useSignal(false) | ||
const { floatingRef, arrowRef, triggerRef } = useFloating(placement, triggerStrategy, noArrow, isVisible) | ||
export const Tooltip = component$<TooltipProps>(({ placement = 'top', trigger = 'hover', style = 'auto', noArrow = false }) => { | ||
const isVisible = useSignal(false) | ||
const { floatingRef, arrowRef, triggerRef } = useFloating(placement, trigger, noArrow, isVisible) | ||
|
||
return ( | ||
<> | ||
<RenderFloatingTrigger ref={triggerRef} triggerEl={trigger} /> | ||
return ( | ||
<> | ||
<div ref={triggerRef}> | ||
<Slot name="trigger" /> | ||
</div> | ||
|
||
<RenderFloatingElement | ||
q:slot="floating" | ||
ref={floatingRef} | ||
isVisible={isVisible.value} | ||
class={[ | ||
'inline-block px-3 py-2 text-sm font-medium transition-opacity duration-300 rounded-lg shadow-sm', | ||
{ | ||
'bg-gray-900 text-white dark:bg-gray-700': style === 'dark', | ||
'border border-gray-200 bg-white text-gray-900': style === 'light', | ||
'border border-gray-200 bg-white text-gray-900 dark:border-none dark:bg-gray-700 dark:text-white': style === 'auto', | ||
}, | ||
]} | ||
> | ||
{content} | ||
<RenderFloatingElement | ||
q:slot="floating" | ||
ref={floatingRef} | ||
isVisible={isVisible.value} | ||
class={[ | ||
'inline-block px-3 py-2 text-sm font-medium transition-opacity duration-300 rounded-lg shadow-sm', | ||
{ | ||
'bg-gray-900 text-white dark:bg-gray-700': style === 'dark', | ||
'border border-gray-200 bg-white text-gray-900': style === 'light', | ||
'border border-gray-200 bg-white text-gray-900 dark:border-none dark:bg-gray-700 dark:text-white': style === 'auto', | ||
}, | ||
]} | ||
> | ||
<Slot name="content" /> | ||
|
||
{!noArrow && ( | ||
<RenderFloatingArrow | ||
ref={arrowRef} | ||
class={[ | ||
{ | ||
'bg-gray-900 dark:bg-gray-700': style === 'dark', | ||
'bg-white': style === 'light', | ||
'bg-white dark:bg-gray-700': style === 'auto', | ||
}, | ||
]} | ||
/> | ||
)} | ||
</RenderFloatingElement> | ||
</> | ||
) | ||
}, | ||
) | ||
{!noArrow && ( | ||
<RenderFloatingArrow | ||
ref={arrowRef} | ||
class={[ | ||
{ | ||
'bg-gray-900 dark:bg-gray-700': style === 'dark', | ||
'bg-white': style === 'light', | ||
'bg-white dark:bg-gray-700': style === 'auto', | ||
}, | ||
]} | ||
/> | ||
)} | ||
</RenderFloatingElement> | ||
</> | ||
) | ||
}) |