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(dashboard): Allow setting a tooltip for disabled action items #10234

Merged
merged 5 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/orange-buses-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/dashboard": patch
---

feat(dashboard): Allow setting a tooltip for disabled action items
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ import { DropdownMenu, IconButton, clx } from "@medusajs/ui"
import { EllipsisHorizontal } from "@medusajs/icons"
import { ReactNode } from "react"
import { Link } from "react-router-dom"
import { ConditionalTooltip } from "../conditional-tooltip"

export type Action = {
icon: ReactNode
label: string
disabled?: boolean
/**
* Optional tooltip to display when a disabled action is hovered.
*/
disabledTooltip?: string | ReactNode
} & (
| {
to: string
Expand Down Expand Up @@ -46,30 +51,43 @@ export const ActionMenu = ({ groups }: ActionMenuProps) => {
return (
<DropdownMenu.Group key={index}>
{group.actions.map((action, index) => {
const Wrapper = action.disabledTooltip
? ({ children }: { children: ReactNode }) => (
<ConditionalTooltip
showTooltip={action.disabled}
content={action.disabledTooltip}
side="right"
>
<div>{children}</div>
</ConditionalTooltip>
)
: "div"

if (action.onClick) {
return (
<DropdownMenu.Item
disabled={action.disabled}
key={index}
onClick={(e) => {
e.stopPropagation()
action.onClick()
}}
className={clx(
"[&_svg]:text-ui-fg-subtle flex items-center gap-x-2",
{
"[&_svg]:text-ui-fg-disabled": action.disabled,
}
)}
>
{action.icon}
<span>{action.label}</span>
</DropdownMenu.Item>
<Wrapper key={index}>
<DropdownMenu.Item
disabled={action.disabled}
onClick={(e) => {
e.stopPropagation()
action.onClick()
}}
className={clx(
"[&_svg]:text-ui-fg-subtle flex items-center gap-x-2",
{
"[&_svg]:text-ui-fg-disabled": action.disabled,
}
)}
>
{action.icon}
<span>{action.label}</span>
</DropdownMenu.Item>
</Wrapper>
)
}

return (
<div key={index}>
<Wrapper key={index}>
<DropdownMenu.Item
className={clx(
"[&_svg]:text-ui-fg-subtle flex items-center gap-x-2",
Expand All @@ -85,7 +103,7 @@ export const ActionMenu = ({ groups }: ActionMenuProps) => {
<span>{action.label}</span>
</Link>
</DropdownMenu.Item>
</div>
</Wrapper>
)
})}
{!isLast && <DropdownMenu.Separator />}
Expand Down
Loading