From a74a1cc5241e2ccf1e6b1021a3831da9875d2522 Mon Sep 17 00:00:00 2001 From: nikogoli Date: Thu, 2 Nov 2023 11:44:46 +0900 Subject: [PATCH] =?UTF-8?q?Change=EF=BC=9ATooltip=20=E5=AF=BE=E5=BF=9C=20(?= =?UTF-8?q?=E5=88=A9=E7=94=A8=E4=B8=8D=E5=8F=AF)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hover 状態でも tooltip の表示が永続化されず、表示後即座に消えてしまう ([issue](https://github.com/preactjs/preact/issues/3805)) --- _examples/Tooltip.tsx | 10 +++++----- components/ui/tooltip.tsx | 12 +++++++----- deno.json | 1 + islands/App.tsx | 4 ++-- lib/components/tooltip.d.ts | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 lib/components/tooltip.d.ts diff --git a/_examples/Tooltip.tsx b/_examples/Tooltip.tsx index d852910..98a0a33 100644 --- a/_examples/Tooltip.tsx +++ b/_examples/Tooltip.tsx @@ -1,14 +1,14 @@ -import { Button } from '@/components/ui/button' -import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip' +import { Button } from '../components/ui/button.tsx' +import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../components/ui/tooltip.tsx' export function TooltipDemo() { return ( - diff --git a/components/ui/tooltip.tsx b/components/ui/tooltip.tsx index 2054a36..fb2573b 100644 --- a/components/ui/tooltip.tsx +++ b/components/ui/tooltip.tsx @@ -1,9 +1,11 @@ 'use client' -import * as React from 'react' +import * as React from 'preact/compat' import * as TooltipPrimitive from '@radix-ui/react-tooltip' +import * as AlitTooltipPrimitive from "../../lib/components/tooltip.d.ts" -import { cn } from '../../lib/utils' +import { cn } from '../../lib/utils.ts' +import { ElementRef, ComponentPropsWithoutRef } from "../../lib/type-utils.ts" const TooltipProvider = TooltipPrimitive.Provider @@ -12,9 +14,9 @@ const Tooltip = TooltipPrimitive.Root const TooltipTrigger = TooltipPrimitive.Trigger const TooltipContent = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, sideOffset = 4, ...props }, ref) => ( + ElementRef, + ComponentPropsWithoutRef +>(({ class:className, sideOffset = 4, ...props }, ref) => ( - {/**/} + diff --git a/lib/components/tooltip.d.ts b/lib/components/tooltip.d.ts new file mode 100644 index 0000000..1b640d0 --- /dev/null +++ b/lib/components/tooltip.d.ts @@ -0,0 +1,33 @@ +import * as React from "preact/compat" +import { DismissableLayerProps } from "../type-utils-DismissableLayer.d.ts"; +import { PopperContentProps } from "../type-utils-PopperPrimitive.d.ts"; + +/** + * Following type-definitions are based on "https://esm.sh/v133/@radix-ui/react-tooltip@1.0.7/X-YS9AdHlwZXMvcmVhY3Q6cHJlYWN0L2NvbXBhdCxyZWFjdDpwcmVhY3QvY29tcGF0CmUvKg/dist/index.d.mts" + */ + + +interface TooltipContentImplProps extends Omit { + /** + * A more descriptive label for accessibility purpose + */ + 'aria-label'?: string; + /** + * Event handler called when the escape key is down. + * Can be prevented. + */ + onEscapeKeyDown?: DismissableLayerProps['onEscapeKeyDown']; + /** + * Event handler called when the a `pointerdown` event happens outside of the `Tooltip`. + * Can be prevented. + */ + onPointerDownOutside?: DismissableLayerProps['onPointerDownOutside']; +} +interface TooltipContentProps extends TooltipContentImplProps { + /** + * Used to force mounting when more control is needed. Useful when + * controlling animation with React animation libraries. + */ + forceMount?: true; +} +export const Content: React.ForwardRefExoticComponent>; \ No newline at end of file