feat(dashboard): Allow setting a tooltip for disabled action items (#10234)
**What**
- Allow passing a `disabledTooltip` for actions in a `ActionMenu`. Useful for providing context for the user why a option is disabled. E.g. `{ disabled: sales_channel.is_default, disabledTooltip: "Deleting the default Sales Channel is not allowed. Please assign a different default Sales Channel for your store". }`
This commit is contained in:
1 parent
1bd82a9b13
commit
3ab056e572
2 files changed
+42
-19
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/dashboard": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat(dashboard): Allow setting a tooltip for disabled action items
|
||||||
@@ -3,11 +3,16 @@ import { DropdownMenu, IconButton, clx } from "@medusajs/ui"
|
|||||||
import { EllipsisHorizontal } from "@medusajs/icons"
|
import { EllipsisHorizontal } from "@medusajs/icons"
|
||||||
import { ReactNode } from "react"
|
import { ReactNode } from "react"
|
||||||
import { Link } from "react-router-dom"
|
import { Link } from "react-router-dom"
|
||||||
|
import { ConditionalTooltip } from "../conditional-tooltip"
|
||||||
|
|
||||||
export type Action = {
|
export type Action = {
|
||||||
icon: ReactNode
|
icon: ReactNode
|
||||||
label: string
|
label: string
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
|
/**
|
||||||
|
* Optional tooltip to display when a disabled action is hovered.
|
||||||
|
*/
|
||||||
|
disabledTooltip?: string | ReactNode
|
||||||
} & (
|
} & (
|
||||||
| {
|
| {
|
||||||
to: string
|
to: string
|
||||||
@@ -46,30 +51,43 @@ export const ActionMenu = ({ groups }: ActionMenuProps) => {
|
|||||||
return (
|
return (
|
||||||
<DropdownMenu.Group key={index}>
|
<DropdownMenu.Group key={index}>
|
||||||
{group.actions.map((action, 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) {
|
if (action.onClick) {
|
||||||
return (
|
return (
|
||||||
<DropdownMenu.Item
|
<Wrapper key={index}>
|
||||||
disabled={action.disabled}
|
<DropdownMenu.Item
|
||||||
key={index}
|
disabled={action.disabled}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
action.onClick()
|
action.onClick()
|
||||||
}}
|
}}
|
||||||
className={clx(
|
className={clx(
|
||||||
"[&_svg]:text-ui-fg-subtle flex items-center gap-x-2",
|
"[&_svg]:text-ui-fg-subtle flex items-center gap-x-2",
|
||||||
{
|
{
|
||||||
"[&_svg]:text-ui-fg-disabled": action.disabled,
|
"[&_svg]:text-ui-fg-disabled": action.disabled,
|
||||||
}
|
}
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{action.icon}
|
{action.icon}
|
||||||
<span>{action.label}</span>
|
<span>{action.label}</span>
|
||||||
</DropdownMenu.Item>
|
</DropdownMenu.Item>
|
||||||
|
</Wrapper>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div key={index}>
|
<Wrapper key={index}>
|
||||||
<DropdownMenu.Item
|
<DropdownMenu.Item
|
||||||
className={clx(
|
className={clx(
|
||||||
"[&_svg]:text-ui-fg-subtle flex items-center gap-x-2",
|
"[&_svg]:text-ui-fg-subtle flex items-center gap-x-2",
|
||||||
@@ -85,7 +103,7 @@ export const ActionMenu = ({ groups }: ActionMenuProps) => {
|
|||||||
<span>{action.label}</span>
|
<span>{action.label}</span>
|
||||||
</Link>
|
</Link>
|
||||||
</DropdownMenu.Item>
|
</DropdownMenu.Item>
|
||||||
</div>
|
</Wrapper>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
{!isLast && <DropdownMenu.Separator />}
|
{!isLast && <DropdownMenu.Separator />}
|
||||||
|
|||||||
Reference in new issue
Block a user