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