Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat]: Action Menu #6815

Open
2 tasks done
spaceofnova opened this issue Feb 28, 2025 · 0 comments
Open
2 tasks done

[feat]: Action Menu #6815

spaceofnova opened this issue Feb 28, 2025 · 0 comments

Comments

@spaceofnova
Copy link

Feature description

This would be a simple material like action button. I know it's not too bad to make your own but I think this would be nice to have.

Affected component/components

Dropdown

Additional Context

Something like this:

Image

I already made my own, and want to contribute if this would fit with shadcn/ui

This is what I have so far. I'm not the best a programming but it works.

import * as React from "react";
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
import { cn } from "@/lib/utils";

const ActionMenu = DropdownMenuPrimitive.Root;

const ActionMenuTrigger = DropdownMenuPrimitive.Trigger;

const ActionMenuContent = React.forwardRef<
  React.ElementRef<typeof DropdownMenuPrimitive.Content>,
  React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
>(({ className, sideOffset = 4, ...props }, ref) => (
  <DropdownMenuPrimitive.Portal>
    <DropdownMenuPrimitive.Content
      ref={ref}
      sideOffset={sideOffset}
      className={cn(
        "bg-popover text-popover-foreground z-50 min-w-[8rem] overflow-hidden rounded-md border p-1 shadow-md",
        "animate-in fade-in-0 zoom-in-95 duration-100",
        "data-[side=bottom]:slide-in-from-top-2",
        "data-[side=left]:slide-in-from-right-2",
        "data-[side=right]:slide-in-from-left-2",
        "data-[side=top]:slide-in-from-bottom-2",
        className,
      )}
      {...props}
    />
  </DropdownMenuPrimitive.Portal>
));
ActionMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;

const ActionMenuItem = React.forwardRef<
  React.ElementRef<typeof DropdownMenuPrimitive.Item>,
  React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item>
>(({ className, ...props }, ref) => (
  <DropdownMenuPrimitive.Item
    ref={ref}
    className={cn(
      "relative flex cursor-default items-center rounded-sm px-2 py-1.5 text-sm outline-none select-none",
      "transition-colors duration-100",
      "focus:bg-accent focus:text-accent-foreground",
      "data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
      className,
    )}
    {...props}
  />
));
ActionMenuItem.displayName = DropdownMenuPrimitive.Item.displayName;

export { ActionMenu, ActionMenuTrigger, ActionMenuContent, ActionMenuItem };

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues and PRs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant