COMPONENTS/OVERLAYS
Hover card.
A little context before you go.
In practice
Supplement a link with nonessential information. Essential content must also be available at the destination.
Installation
Install Coal once. Components and TypeScript declarations are included. React 19 and React DOM 19 are peer dependencies.
Terminal · local package
npm install http://localhost:3100/downloads/chlohal-coal-ui-0.5.0.tgzThis installs the local package. It is not yet published on npm. See installation for stylesheet setup and integration.
Usage
example.tsx
"use client";
import * as React from "react";
import "@chlohal/coal-ui/styles.css";
import { ArrowUpRight } from "lucide-react";
import { HoverCard, HoverCardTrigger, HoverCardContent } from "@chlohal/coal-ui";
export default function Example() {
return (<HoverCard>
<HoverCardTrigger href="https://github.com/chlohal/coal-ui">
Made by Chlohal <ArrowUpRight size={14}/>
</HoverCardTrigger>
<HoverCardContent>
<strong>Chlohal</strong>
<p>
Independent design. Thoughtful components.
</p>
</HoverCardContent>
</HoverCard>);
}
Source
The original Coal implementation. Use the package export to integrate it.
packages/react/src/hover-card.tsx
"use client";
import * as React from "react";
import {
FloatingRoot,
FloatingContent,
useFloating,
type FloatingProps,
type FloatingContentProps,
} from "./floating.js";
export function HoverCard(props: FloatingProps) {
return <FloatingRoot {...props} />;
}
export function HoverCardTrigger({
onFocus,
onBlur,
onPointerEnter,
onPointerLeave,
...props
}: React.ComponentPropsWithRef<"a">) {
const c = useFloating();
return (
<a
{...props}
ref={(node) => {
c.anchor.current = node;
}}
aria-describedby={c.open ? c.id : undefined}
onFocus={(e) => {
onFocus?.(e);
{
c.cancelClose();
c.set(true);
}
}}
onBlur={(e) => {
onBlur?.(e);
c.scheduleClose();
}}
onPointerEnter={(e) => {
onPointerEnter?.(e);
{
c.cancelClose();
c.set(true);
}
}}
onPointerLeave={(e) => {
onPointerLeave?.(e);
if (!c.content.current?.contains(e.relatedTarget as Node))
c.scheduleClose();
}}
/>
);
}
export function HoverCardContent(props: FloatingContentProps) {
const c = useFloating();
return (
<FloatingContent
autoFocus={false}
onPointerEnter={() => c.cancelClose()}
onPointerLeave={() => c.scheduleClose()}
onFocus={() => c.cancelClose()}
onBlur={() => c.scheduleClose()}
{...props}
/>
);
}
Accessibility checklist
- Provide an accessible name for controls, including icon-only buttons.
- Check keyboard navigation, visible focus and disabled states in your application.
- Do not rely on color alone to communicate status.