Skip to content

Commit

Permalink
Merge pull request #1119 from easyops-cn/williamcai/basic_mini-action…
Browse files Browse the repository at this point in the history
…s_add_url_support_for_non-dropdown_action

feat(eo-mini-actions): Add url support for non-dropdown action
  • Loading branch information
qiaofengxi committed Jun 21, 2024
2 parents 898bc11 + caab00c commit 6905d13
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
35 changes: 33 additions & 2 deletions bricks/basic/src/mini-actions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
GeneralIcon,
GeneralIconProps,
} from "@next-bricks/icons/general-icon";
import type { Link, LinkProps } from "../link";
import type {
Popover,
PopoverProps,
Expand All @@ -29,6 +30,7 @@ const WrappedTooltip = wrapBrick<EoTooltip, ToolTipProps>("eo-tooltip");
const { defineElement, property, event } = createDecorators();

const WrappedIcon = wrapBrick<GeneralIcon, GeneralIconProps>("eo-icon");
const WrappedLink = wrapBrick<Link, LinkProps>("eo-link");
const WrappedPopover = wrapBrick<
Popover,
PopoverProps,
Expand Down Expand Up @@ -113,6 +115,10 @@ interface EoMiniActionsComponentProps extends EoMiniActionsProps {
onActionClick: (action: SimpleActionType) => void;
}

const stopPropagationListener = (e: Event) => {
e.stopPropagation();
};

export function EoMiniActionsComponent(props: EoMiniActionsComponentProps) {
const { actions, onActionClick } = props;

Expand Down Expand Up @@ -148,6 +154,31 @@ export function EoMiniActionsComponent(props: EoMiniActionsComponentProps) {
return (
<div className="group-wrapper">
{outSideActions.map((action, i) => {
let contentNode = (
<WrappedIcon className="button-item-icon" {...action.icon!} />
);

if (action.url || action.href) {
contentNode = (
<WrappedLink
type="plain"
href={action.href}
target={action.target}
url={action.url}
disabled={action.disabled}
ref={(el) => {
el?.addEventListener("click", stopPropagationListener);

return () => {
el?.removeEventListener("click", stopPropagationListener);
};
}}
>
{contentNode}
</WrappedLink>
);
}

return (
<div
key={i}
Expand All @@ -162,10 +193,10 @@ export function EoMiniActionsComponent(props: EoMiniActionsComponentProps) {
key={i}
content={action.tooltip}
>
<WrappedIcon className="button-item-icon" {...action.icon!} />
{contentNode}
</WrappedTooltip>
) : (
<WrappedIcon className="button-item-icon" {...action.icon!} />
contentNode
)}
</div>
);
Expand Down
14 changes: 11 additions & 3 deletions bricks/presentational/src/card-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ interface EoCardItemComponentProps extends EoCardItemProps {
onTagClick?: () => void;
}

const preventDefaultListener = (e: Event) => {
e.preventDefault();
};

export function EoCardItemComponent(props: EoCardItemComponentProps) {
const {
hasHeader,
Expand Down Expand Up @@ -341,11 +345,15 @@ export function EoCardItemComponent(props: EoCardItemComponentProps) {
return (
<WrappedMiniActions
onActionClick={handleActionClick}
onClickCapture={(e) => {
e.preventDefault();
}}
className="operator"
actions={actions}
ref={(el) => {
el?.addEventListener("click", preventDefaultListener);

return () => {
el?.removeEventListener("click", preventDefaultListener);
};
}}
/>
);
}, [actions, handleActionClick]);
Expand Down

0 comments on commit 6905d13

Please sign in to comment.