The Coline design system: accessible React components for Coline Apps, themed live by the host workspace, and for Coline Sites in light and dark. Tailwind v4 stylesheet included. MIT.
| 5 | import { IconCheck, IconChevronRight } from "@tabler/icons-react"; |
| 6 |
| 7 | import { menuItemClasses } from "./menu-item-styles"; |
| 8 | import { LiquidGlass, useLiquidGlass } from "./liquid-glass"; |
| 9 | import { menuSurfaceClasses } from "./liquid-menu-surface"; |
| 10 | import { |
| 11 | MenuHighlightContext, |
| 12 | SUPER_HOVER_ATTR, |
| 13 | useMenuHighlight, |
| 14 | } from "./menu-highlight"; |
| 15 | import { cn } from "../lib/utils"; |
| 16 |
| 17 | const contentClasses = "relative z-50 overflow-x-hidden overflow-y-auto p-1"; |
| 18 |
| 19 | const subContentClasses = |
| 20 | "relative z-50 isolate overflow-x-hidden overflow-y-auto p-1"; |
| 21 |
| 22 | // ── Primitives ────────────────────────────────────────────────────────────── |
| 23 |
| 24 | function DropdownMenu({ |
| 25 | ...props |
| 26 | }: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) { |
| 27 | return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />; |
| 28 | } |
| 29 |
| 30 | function DropdownMenuPortal({ |
| 31 | ...props |
| 32 | }: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) { |
| 33 | return ( |
| 34 | <DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} /> |
| 35 | ); |
| 36 | } |
| 37 |
| 38 | function DropdownMenuTrigger({ |
| 39 | ...props |
| 40 | }: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) { |
| 41 | return ( |
| 42 | <DropdownMenuPrimitive.Trigger |
| 43 | data-slot="dropdown-menu-trigger" |
| 44 | {...props} |
| 45 | /> |
| 46 | ); |
| 47 | } |
| 48 |
| 49 | function DropdownMenuContent({ |
| 50 | className, |
| 51 | align = "start", |
| 52 | sideOffset = 4, |
| 53 | children, |
| 54 | ...props |
| 55 | }: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) { |
| 56 | const contentRef = React.useRef<HTMLDivElement>(null); |
| 57 | const glass = useMenuHighlight(contentRef); |
| 58 | const liquid = useLiquidGlass(); |
| 59 |
| 60 | return ( |
| 61 | <DropdownMenuPrimitive.Portal> |
| 62 | <DropdownMenuPrimitive.Content |
| 63 | ref={contentRef} |
| 64 | data-slot="dropdown-menu-content" |
| 65 | sideOffset={sideOffset} |
| 66 | align={align} |
| 67 | onPointerLeave={glass.clear} |
| 68 | className={cn( |
| 69 | contentClasses, |
| 70 | menuSurfaceClasses(liquid), |
| 71 | "max-h-(--radix-dropdown-menu-content-available-height) w-(--radix-dropdown-menu-trigger-width) min-w-48 origin-(--radix-dropdown-menu-content-transform-origin) duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] data-[state=closed]:overflow-hidden data-[side=bottom]:slide-in-from-top-1 data-[side=left]:slide-in-from-right-1 data-[side=right]:slide-in-from-left-1 data-[side=top]:slide-in-from-bottom-1 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95", |
| 72 | className, |
| 73 | )} |
| 74 | {...props} |
| 75 | > |
| 76 | {liquid ? <LiquidGlass fit="popper" morph /> : null} |
| 77 | {glass.element} |
| 78 | <div className="relative z-10"> |
| 79 | <MenuHighlightContext.Provider value={glass.ctx}> |
| 80 | {children} |
| 81 | </MenuHighlightContext.Provider> |
| 82 | </div> |
| 83 | </DropdownMenuPrimitive.Content> |
| 84 | </DropdownMenuPrimitive.Portal> |
| 85 | ); |
| 86 | } |
| 87 |
| 88 | function DropdownMenuGroup({ |
| 89 | ...props |
| 90 | }: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) { |
| 91 | return ( |
| 92 | <DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} /> |
| 93 | ); |
| 94 | } |
| 95 |
| 96 | function DropdownMenuItem({ |
| 97 | className, |
| 98 | inset, |
| 99 | variant = "default", |
| 100 | onPointerEnter, |
| 101 | onFocus, |
| 102 | ...props |
| 103 | }: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & { |
| 104 | inset?: boolean; |
| 105 | variant?: "default" | "destructive"; |
| 106 | }) { |
| 107 | const { reportHover } = React.useContext(MenuHighlightContext); |
| 108 |
| 109 | return ( |
| 110 | <DropdownMenuPrimitive.Item |
| 111 | data-slot="dropdown-menu-item" |
| 112 | {...SUPER_HOVER_ATTR} |
| 113 | data-inset={inset} |
| 114 | data-variant={variant} |
| 115 | onFocus={(e) => { |
| 116 | reportHover(e.currentTarget); |
| 117 | onFocus?.(e); |
| 118 | }} |
| 119 | onPointerEnter={(e) => { |
| 120 | reportHover(e.currentTarget); |
| 121 | onPointerEnter?.(e); |
| 122 | }} |
| 123 | className={cn( |
| 124 | menuItemClasses, |
| 125 | className, |
| 126 | )} |
| 127 | {...props} |
| 128 | /> |
| 129 | ); |
| 130 | } |
| 131 |
| 132 | function DropdownMenuCheckboxItem({ |
| 133 | className, |
| 134 | children, |
| 135 | checked, |
| 136 | inset, |
| 137 | onPointerEnter, |
| 138 | onFocus, |
| 139 | ...props |
| 140 | }: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem> & { |
| 141 | inset?: boolean; |
| 142 | }) { |
| 143 | const { reportHover } = React.useContext(MenuHighlightContext); |
| 144 |
| 145 | return ( |
| 146 | <DropdownMenuPrimitive.CheckboxItem |
| 147 | data-slot="dropdown-menu-checkbox-item" |
| 148 | {...SUPER_HOVER_ATTR} |
| 149 | data-inset={inset} |
| 150 | onFocus={(e) => { |
| 151 | reportHover(e.currentTarget); |
| 152 | onFocus?.(e); |
| 153 | }} |
| 154 | onPointerEnter={(e) => { |
| 155 | reportHover(e.currentTarget); |
| 156 | onPointerEnter?.(e); |
| 157 | }} |
| 158 | className={cn( |
| 159 | "relative flex cursor-default items-center gap-2 rounded-lg py-1.5 pr-8 pl-2.5 text-sm font-medium leading-5 outline-hidden select-none focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-8 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg]:text-muted-foreground/75", |
| 160 | className, |
| 161 | )} |
| 162 | {...(checked !== undefined ? { checked } : {})} |
| 163 | {...props} |
| 164 | > |
| 165 | <span |
| 166 | className="pointer-events-none absolute right-2 flex items-center justify-center" |
| 167 | data-slot="dropdown-menu-checkbox-item-indicator" |
| 168 | > |
| 169 | <DropdownMenuPrimitive.ItemIndicator> |
| 170 | <IconCheck /> |
| 171 | </DropdownMenuPrimitive.ItemIndicator> |
| 172 | </span> |
| 173 | {children} |
| 174 | </DropdownMenuPrimitive.CheckboxItem> |
| 175 | ); |
| 176 | } |
| 177 |
| 178 | function DropdownMenuRadioGroup({ |
| 179 | ...props |
| 180 | }: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) { |
| 181 | return ( |
| 182 | <DropdownMenuPrimitive.RadioGroup |
| 183 | data-slot="dropdown-menu-radio-group" |
| 184 | {...props} |
| 185 | /> |
| 186 | ); |
| 187 | } |
| 188 |
| 189 | function DropdownMenuRadioItem({ |
| 190 | className, |
| 191 | children, |
| 192 | inset, |
| 193 | onPointerEnter, |
| 194 | onFocus, |
| 195 | ...props |
| 196 | }: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem> & { |
| 197 | inset?: boolean; |
| 198 | }) { |
| 199 | const { reportHover } = React.useContext(MenuHighlightContext); |
| 200 |
| 201 | return ( |
| 202 | <DropdownMenuPrimitive.RadioItem |
| 203 | data-slot="dropdown-menu-radio-item" |
| 204 | {...SUPER_HOVER_ATTR} |
| 205 | data-inset={inset} |
| 206 | onFocus={(e) => { |
| 207 | reportHover(e.currentTarget); |
| 208 | onFocus?.(e); |
| 209 | }} |
| 210 | onPointerEnter={(e) => { |
| 211 | reportHover(e.currentTarget); |
| 212 | onPointerEnter?.(e); |
| 213 | }} |
| 214 | className={cn( |
| 215 | "relative flex cursor-default items-center gap-2 rounded-lg py-1.5 pr-8 pl-2.5 text-sm font-medium leading-5 outline-hidden select-none focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-8 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg]:text-muted-foreground/75", |
| 216 | className, |
| 217 | )} |
| 218 | {...props} |
| 219 | > |
| 220 | <span |
| 221 | className="pointer-events-none absolute right-2 flex items-center justify-center" |
| 222 | data-slot="dropdown-menu-radio-item-indicator" |
| 223 | > |
| 224 | <DropdownMenuPrimitive.ItemIndicator> |
| 225 | <IconCheck /> |
| 226 | </DropdownMenuPrimitive.ItemIndicator> |
| 227 | </span> |
| 228 | {children} |
| 229 | </DropdownMenuPrimitive.RadioItem> |
| 230 | ); |
| 231 | } |
| 232 |
| 233 | function DropdownMenuLabel({ |
| 234 | className, |
| 235 | inset, |
| 236 | ...props |
| 237 | }: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & { |
| 238 | inset?: boolean; |
| 239 | }) { |
| 240 | return ( |
| 241 | <DropdownMenuPrimitive.Label |
| 242 | data-slot="dropdown-menu-label" |
| 243 | data-inset={inset} |
| 244 | className={cn( |
| 245 | "px-2.5 pt-2 pb-1 text-xs font-medium text-muted-foreground/60 data-inset:pl-8", |
| 246 | className, |
| 247 | )} |
| 248 | {...props} |
| 249 | /> |
| 250 | ); |
| 251 | } |
| 252 |
| 253 | function DropdownMenuSeparator({ |
| 254 | className, |
| 255 | ...props |
| 256 | }: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) { |
| 257 | return ( |
| 258 | <DropdownMenuPrimitive.Separator |
| 259 | data-slot="dropdown-menu-separator" |
| 260 | className={cn("mx-1.5 my-1 h-px bg-black/[0.06] dark:bg-white/[0.07]", className)} |
| 261 | {...props} |
| 262 | /> |
| 263 | ); |
| 264 | } |
| 265 |
| 266 | function DropdownMenuShortcut({ |
| 267 | className, |
| 268 | ...props |
| 269 | }: React.ComponentProps<"span">) { |
| 270 | return ( |
| 271 | <span |
| 272 | data-slot="dropdown-menu-shortcut" |
| 273 | className={cn( |
| 274 | "ml-auto text-xs text-muted-foreground/60 group-focus-visible/dropdown-menu-item:text-accent-foreground", |
| 275 | className, |
| 276 | )} |
| 277 | {...props} |
| 278 | /> |
| 279 | ); |
| 280 | } |
| 281 |
| 282 | function DropdownMenuSub({ |
| 283 | ...props |
| 284 | }: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) { |
| 285 | return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />; |
| 286 | } |
| 287 |
| 288 | function DropdownMenuSubTrigger({ |
| 289 | className, |
| 290 | inset, |
| 291 | children, |
| 292 | onPointerEnter, |
| 293 | onFocus, |
| 294 | ...props |
| 295 | }: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & { |
| 296 | inset?: boolean; |
| 297 | }) { |
| 298 | const { reportHover } = React.useContext(MenuHighlightContext); |
| 299 |
| 300 | return ( |
| 301 | <DropdownMenuPrimitive.SubTrigger |
| 302 | data-slot="dropdown-menu-sub-trigger" |
| 303 | {...SUPER_HOVER_ATTR} |
| 304 | data-inset={inset} |
| 305 | onFocus={(e) => { |
| 306 | reportHover(e.currentTarget); |
| 307 | onFocus?.(e); |
| 308 | }} |
| 309 | onPointerEnter={(e) => { |
| 310 | reportHover(e.currentTarget); |
| 311 | onPointerEnter?.(e); |
| 312 | }} |
| 313 | className={cn( |
| 314 | "flex cursor-default items-center gap-2 rounded-lg px-2.5 py-1.5 text-sm font-medium leading-5 outline-hidden select-none focus-visible:text-accent-foreground not-data-[variant=destructive]:focus-visible:**:text-accent-foreground data-inset:pl-8 data-[state=open]:bg-black/[0.045] dark:data-[state=open]:bg-white/[0.08] [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg]:text-muted-foreground/75", |
| 315 | className, |
| 316 | )} |
| 317 | {...props} |
| 318 | > |
| 319 | {children} |
| 320 | <IconChevronRight className="ml-auto" /> |
| 321 | </DropdownMenuPrimitive.SubTrigger> |
| 322 | ); |
| 323 | } |
| 324 |
| 325 | function DropdownMenuSubContent({ |
| 326 | className, |
| 327 | children, |
| 328 | ...props |
| 329 | }: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) { |
| 330 | const contentRef = React.useRef<HTMLDivElement>(null); |
| 331 | const glass = useMenuHighlight(contentRef); |
| 332 | const liquid = useLiquidGlass(); |
| 333 |
| 334 | return ( |
| 335 | <DropdownMenuPrimitive.Portal> |
| 336 | <DropdownMenuPrimitive.SubContent |
| 337 | ref={contentRef} |
| 338 | data-slot="dropdown-menu-sub-content" |
| 339 | onPointerLeave={glass.clear} |
| 340 | className={cn( |
| 341 | subContentClasses, |
| 342 | menuSurfaceClasses(liquid), |
| 343 | "min-w-36 origin-(--radix-dropdown-menu-content-transform-origin) transform-gpu will-change-[opacity,transform] duration-160 ease-[cubic-bezier(0.23,1,0.32,1)] data-[state=closed]:overflow-hidden data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95", |
| 344 | className, |
| 345 | )} |
| 346 | {...props} |
| 347 | > |
| 348 | {liquid ? <LiquidGlass fit="popper" morph /> : null} |
| 349 | {glass.element} |
| 350 | <div className="relative z-10"> |
| 351 | <MenuHighlightContext.Provider value={glass.ctx}> |
| 352 | {children} |
| 353 | </MenuHighlightContext.Provider> |
| 354 | </div> |
| 355 | </DropdownMenuPrimitive.SubContent> |
| 356 | </DropdownMenuPrimitive.Portal> |
| 357 | ); |
| 358 | } |
| 359 |
| 360 | export { |
| 361 | DropdownMenu, |
| 362 | DropdownMenuPortal, |
| 363 | DropdownMenuTrigger, |
| 364 | DropdownMenuContent, |
| 365 | DropdownMenuGroup, |
| 366 | DropdownMenuLabel, |
| 367 | DropdownMenuItem, |
| 368 | DropdownMenuCheckboxItem, |
| 369 | DropdownMenuRadioGroup, |
| 370 | DropdownMenuRadioItem, |
| 371 | DropdownMenuSeparator, |
| 372 | DropdownMenuShortcut, |
| 373 | DropdownMenuSub, |
| 374 | DropdownMenuSubTrigger, |
| 375 | DropdownMenuSubContent, |
| 376 | }; |
| 377 |