Accent popovers
Five accent popovers: a border, glow, ring, top bar and fill. Each is self-contained (no radix), sized, driven by a token accent color, opens on click and closes on outside click or Escape.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/popover-accentDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install motion lucide-reactCopy the source
components/ui/popover-accent.tsx"use client"
import * as React from "react"
import { Droplet, Focus, PanelTop, Sparkles, SquareDashed } from "lucide-react"
import { AnimatePresence, motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"
/* Accent popover family: 5 anchored panels in a token accent color. Each export is
a complete popover and SELF-CONTAINED (no radix, no portal): a relative
inline-flex wrapper + a panel absolutely positioned BELOW the trigger (top-full
mt-2). The trigger toggles on CLICK; it closes on an outside click (window
pointerdown, with inner clicks ignored via the wrapper ref) and on Escape. The
trigger is a real button. AnimatePresence fade+scale (from above); only a fade
under reduced motion. Color comes ONLY from tokens; transparency ONLY via
color-mix(in oklab, var(--color-x) N%, transparent). The accent color is the
primary token; the variants apply the accent to a DIFFERENT part of the panel: a
pronounced border, a glow box-shadow, a double-ring box-shadow, a top strip, a
soft filled surface. */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const panelSize: Record<StyledSize, string> = {
sm: "w-56",
md: "w-64",
lg: "w-72",
xl: "w-80",
}
interface PopoverProps {
size?: StyledSize
trigger?: React.ReactNode
children?: React.ReactNode
className?: string
open?: boolean
defaultOpen?: boolean
onOpenChange?: (o: boolean) => void
}
const panelBase =
"absolute left-0 top-full z-50 mt-2 origin-top rounded-xl border border-border bg-popover p-4 text-sm text-popover-foreground shadow-lg outline-none"
const triggerBtn =
"inline-flex h-9 shrink-0 select-none items-center justify-center gap-2 whitespace-nowrap rounded-lg border border-border bg-secondary px-4 text-sm font-medium text-secondary-foreground outline-none transition-colors hover:bg-[color-mix(in_oklab,var(--color-foreground)_6%,transparent)] focus-visible:ring-[3px] focus-visible:ring-ring/50 [&_svg]:size-4 [&_svg]:shrink-0 [&_i]:text-base [&_i]:leading-none"
/* Panel basligindaki aksan ikon kabugu: lucide <svg> ve remixicon <i> ikisiyle de
dogru boyutlanir (token primary renkte). */
const iconWrap =
"flex size-7 shrink-0 items-center justify-center rounded-md bg-[color-mix(in_oklab,var(--color-primary)_12%,transparent)] text-primary [&_svg]:size-4 [&_svg]:shrink-0 [&_i]:text-base [&_i]:leading-none"
/* Controlled/uncontrolled acik durum yonetimi. */
function usePopoverState(props: PopoverProps) {
const { open, defaultOpen, onOpenChange } = props
const isControlled = open !== undefined
const [internal, setInternal] = React.useState(defaultOpen ?? false)
const isOpen = isControlled ? open : internal
const setOpen = React.useCallback(
(next: boolean) => {
if (!isControlled) setInternal(next)
onOpenChange?.(next)
},
[isControlled, onOpenChange]
)
return { isOpen, setOpen }
}
const panelMotion = {
initial: { opacity: 0, scale: 0.96, y: -6 },
animate: { opacity: 1, scale: 1, y: 0 },
exit: { opacity: 0, scale: 0.96, y: -6 },
transition: { type: "spring" as const, stiffness: 340, damping: 26 },
}
type AccentCoreProps = PopoverProps & {
/** Panelin cerceve / box-shadow / dolgu aksan siniflari. */
panelClassName?: string
/** The decorative layer added inside the panel (a top strip and so on). */
accent?: React.ReactNode
icon: React.ReactNode
title: React.ReactNode
}
/* Shared shell: a relative wrapper plus trigger plus an AnimatePresence panel. The accent carries the panel's frame, shadow and fill styling through panelClassName, and an extra decorative layer through accent. */
function AccentPopover({
size = "md",
trigger,
children,
className,
panelClassName,
accent,
icon,
title,
...state
}: AccentCoreProps) {
const { isOpen, setOpen } = usePopoverState(state)
const reduce = useReducedMotion()
const wrapperRef = React.useRef<HTMLDivElement>(null)
React.useEffect(() => {
if (!isOpen) return
const onKey = (e: KeyboardEvent) => {
if (e.key === "Escape") setOpen(false)
}
const onPointer = (e: PointerEvent) => {
const node = wrapperRef.current
if (node && e.target instanceof Node && !node.contains(e.target)) {
setOpen(false)
}
}
window.addEventListener("keydown", onKey)
window.addEventListener("pointerdown", onPointer)
return () => {
window.removeEventListener("keydown", onKey)
window.removeEventListener("pointerdown", onPointer)
}
}, [isOpen, setOpen])
const fade = { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 } }
const motionProps = reduce ? fade : panelMotion
return (
<div ref={wrapperRef} data-slot="styled-popover" className="relative inline-flex">
<span
data-slot="styled-popover-trigger"
className="inline-flex"
onClick={() => setOpen(!isOpen)}
>
{trigger ?? (
<button
type="button"
aria-haspopup="dialog"
aria-expanded={isOpen}
className={triggerBtn}
>
Open
</button>
)}
</span>
<AnimatePresence>
{isOpen ? (
<motion.div
role="dialog"
className={cn(panelBase, panelSize[size], panelClassName, className)}
initial={motionProps.initial}
animate={motionProps.animate}
exit={motionProps.exit}
transition={reduce ? { duration: 0.16, ease: "easeOut" } : panelMotion.transition}
>
{accent}
<div className="relative flex gap-3">
<span data-slot="styled-popover-icon" className={iconWrap}>
{icon}
</span>
<div className="min-w-0 flex-1">
<div className="text-sm font-semibold text-foreground">{title}</div>
<p className="mt-1 text-sm text-muted-foreground">
{children ?? "A token accent treatment on a self-contained anchored panel."}
</p>
</div>
</div>
</motion.div>
) : null}
</AnimatePresence>
</div>
)
}
/* BorderPopover: belirgin primary token cerceve (guclu color-mix border rengi). */
export function BorderPopover(props: PopoverProps) {
return (
<AccentPopover
icon={<SquareDashed />}
title="Border accent"
panelClassName="border-[color-mix(in_oklab,var(--color-primary)_55%,transparent)]"
{...props}
/>
)
}
/* GlowPopover: panel etrafinda genis, dusuk yogunluklu primary token glow. */
export function GlowPopover(props: PopoverProps) {
return (
<AccentPopover
icon={<Sparkles />}
title="Glow accent"
panelClassName="border-[color-mix(in_oklab,var(--color-primary)_35%,transparent)] shadow-[0_0_35px_color-mix(in_oklab,var(--color-primary)_28%,transparent),0_0_0_1px_color-mix(in_oklab,var(--color-primary)_20%,transparent)]"
{...props}
/>
)
}
/* RingPopover: panel etrafinda cift halka. Border + iki azalan yogunlukta primary
token box-shadow cizgisi (color-mix ile). */
export function RingPopover(props: PopoverProps) {
return (
<AccentPopover
icon={<Focus />}
title="Ring accent"
panelClassName="border-[color-mix(in_oklab,var(--color-primary)_40%,transparent)] shadow-[0_0_0_1px_color-mix(in_oklab,var(--color-primary)_45%,transparent),0_0_0_5px_color-mix(in_oklab,var(--color-primary)_18%,transparent)]"
{...props}
/>
)
}
/* TopBarPopover: a full-width primary token accent strip above the panel (h-1); overflow-hidden clips the top corners to match the panel. */
export function TopBarPopover(props: PopoverProps) {
return (
<AccentPopover
icon={<PanelTop />}
title="Top bar accent"
panelClassName="overflow-hidden"
accent={
<span
aria-hidden="true"
className="pointer-events-none absolute inset-x-0 top-0 h-1 bg-primary"
/>
}
{...props}
/>
)
}
/* FillPopover: the panel background is a light primary token soft fill (mixed over
popover with color-mix), plus a thin accent border. */
export function FillPopover(props: PopoverProps) {
return (
<AccentPopover
icon={<Droplet />}
title="Fill accent"
panelClassName="border-[color-mix(in_oklab,var(--color-primary)_30%,transparent)] bg-[color-mix(in_oklab,var(--color-primary)_6%,var(--color-popover))]"
{...props}
/>
)
}Manual installs skip the @ai2/tokens theme, so add the token CSS from the theming guide or the tone colors will be missing.
Variations
5 takes on the same idea. Each is its own export, and every one accepts a size prop (sm, md, lg, xl) aligned to the base Button scale.
Border
A bold token accent border around the panel.
import { BorderPopover } from "@/components/ui/popover-accent"
<BorderPopover />Glow
A soft primary token glow shadow behind the panel.
import { GlowPopover } from "@/components/ui/popover-accent"
<GlowPopover />Ring
A double token ring via layered box-shadow.
import { RingPopover } from "@/components/ui/popover-accent"
<RingPopover />Top bar
A token accent strip across the top edge.
import { TopBarPopover } from "@/components/ui/popover-accent"
<TopBarPopover />Fill
A faint token soft fill on the panel surface.
import { FillPopover } from "@/components/ui/popover-accent"
<FillPopover />ai2 Accent popovers: 5 styled variations on the token system
The ai2 Accent popovers are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around click-anchored floating panels with token accent treatments on the panel. They are free and MIT licensed, and every color comes from a semantic token, so they theme with the rest of ai2 in light and dark.
Motion runs on framer-motion: framer-motion fades and scales the panel in from the trigger. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the scale is skipped and the panel appears instantly.
What is in the ai2 Accent popovers?
5 exports in one file: Border, Glow, Ring, Top bar and Fill. Each renders a native button and takes a size prop (sm, md, lg, xl) aligned to the base Button. They are separate from the base Button on purpose: the base keeps its clean variant, tone and size axes, while the styled layer carries the effects.
You own the file. Copy the one category file and you have all 5 variations, with no runtime dependency on ai2 itself.
Why use it
- On-system by construction: Every color resolves to an ai2 semantic token, so the buttons follow your theme in light and dark with no extra work.
- Effect without the sprawl: The decorations live in a dedicated styled file, so the base Button keeps its clean, predictable API.
- Accessible and honest: Each renders a real button element, keeps a visible focus ring, and respects prefers-reduced-motion.
Features
- Token-driven color: No hardcoded hex or oklch; the look recolors with your theme tokens.
- framer-motion: framer-motion fades and scales the panel in from the trigger.
- Reduced-motion aware: Under prefers-reduced-motion, the scale is skipped and the panel appears instantly.
- Size aligned to the base: Every variation takes sm, md, lg and xl matching the base Button height scale, so styled and base buttons line up in a row.
Production tips
- Use it for emphasis, not everywhere: Styled buttons draw the eye. Reserve them for the one action you want people to take on a screen, and use the base Button for the rest.
- Keep labels as verbs: The decoration adds weight, so a clear action label keeps the button scannable.
- Pick one variation per surface: The variations share a family; using two different ones in the same view competes for attention.
Works with the rest of ai2
The Accent popovers sit alongside the base Button and the rest of the @ai2 registry. They share the same token file, so a styled action next to a base button or a badge stays visually consistent in both modes.