Commit 176b19a0 authored by timel's avatar timel

feat: menu dropdown

parent 94bd5f03
Pipeline #22407 failed with stages
in 15 minutes and 43 seconds
...@@ -173,7 +173,7 @@ export const Card: React.FC<{ idx: number }> = React.memo(({ idx }) => { ...@@ -173,7 +173,7 @@ export const Card: React.FC<{ idx: number }> = React.memo(({ idx }) => {
<div className="card-focus" /> <div className="card-focus" />
<div className="card-shadow" /> <div className="card-shadow" />
<Dropdown <Dropdown
menu={{ items: menuItems.value as any, onClick: onDropdownClick }} menu={{ items: menuItems.value as any }}
placement="bottom" placement="bottom"
overlayClassName="card-dropdown" overlayClassName="card-dropdown"
arrow arrow
...@@ -266,7 +266,6 @@ const handleEffectActivation = ( ...@@ -266,7 +266,6 @@ const handleEffectActivation = (
// 2. 如果是非效果发动,那么直接选择哪张卡(单张卡直接选择那张) // 2. 如果是非效果发动,那么直接选择哪张卡(单张卡直接选择那张)
// 3. 如果是效果发动,那么选择哪张卡,然后选择效果 // 3. 如果是效果发动,那么选择哪张卡,然后选择效果
const handleDropdownMenu = (cards: CardType[], isField: boolean) => { const handleDropdownMenu = (cards: CardType[], isField: boolean) => {
console.log("here");
const map = new Map<Interactivity<number>["interactType"], CardType[]>(); const map = new Map<Interactivity<number>["interactType"], CardType[]>();
cards.forEach((card) => { cards.forEach((card) => {
card.idleInteractivities.forEach(({ interactType }) => { card.idleInteractivities.forEach(({ interactType }) => {
......
...@@ -8,9 +8,9 @@ import { ...@@ -8,9 +8,9 @@ import {
theme, theme,
Divider, Divider,
Space, Space,
Popconfirm, type DropdownProps,
} from "antd"; } from "antd";
import React, { useState } from "react"; import { useState, cloneElement } from "react";
import { useSnapshot } from "valtio"; import { useSnapshot } from "valtio";
import { import {
StepForwardFilled, StepForwardFilled,
...@@ -65,7 +65,7 @@ export const Menu = () => { ...@@ -65,7 +65,7 @@ export const Menu = () => {
// [PhaseType.UNKNOWN, "未知阶段", response], // [PhaseType.UNKNOWN, "未知阶段", response],
]; ];
const items: MenuProps["items"] = phaseBind.map( const phaseSwitchItems: MenuProps["items"] = phaseBind.map(
([phase, str, response], i) => ({ ([phase, str, response], i) => ({
key: i, key: i,
label: str, label: str,
...@@ -80,38 +80,26 @@ export const Menu = () => { ...@@ -80,38 +80,26 @@ export const Menu = () => {
}) })
); );
const { token } = useToken(); const surrenderMenuItems: MenuProps["items"] = [
{
const contentStyle = { key: 0,
backgroundColor: token.colorBgElevated, label: "取消",
borderRadius: token.borderRadiusLG, },
boxShadow: token.boxShadowSecondary, {
}; key: 1,
label: "确定",
const menuStyle = { danger: true,
boxShadow: "none", onClick: sendSurrender,
}; },
];
const [showRendererTooltips, setShowRendererTooltips] = useState<
boolean | undefined
>(undefined);
const globalDisable = !matStore.isMe(currentPlayer); const globalDisable = !matStore.isMe(currentPlayer);
return ( return (
<> <>
<div className="menu-container"> <div className="menu-container">
<Dropdown <DropdownWithTitle
menu={{ items }} title="请选择要进入的阶段"
dropdownRender={(menu) => ( menu={{ items: phaseSwitchItems }}
<div style={contentStyle}>
{React.cloneElement(menu as React.ReactElement, {
style: menuStyle,
})}
<Divider style={{ margin: 0 }} />
<Space style={{ padding: 16 }}>请选择要进入的阶段</Space>
</div>
)}
arrow
disabled={globalDisable} disabled={globalDisable}
> >
<Button <Button
...@@ -121,7 +109,7 @@ export const Menu = () => { ...@@ -121,7 +109,7 @@ export const Menu = () => {
> >
{phaseBind.find(([key]) => key === currentPhase)?.[1]} {phaseBind.find(([key]) => key === currentPhase)?.[1]}
</Button> </Button>
</Dropdown> </DropdownWithTitle>
<Tooltip title="聊天室"> <Tooltip title="聊天室">
<Button <Button
icon={<MessageFilled />} icon={<MessageFilled />}
...@@ -129,23 +117,46 @@ export const Menu = () => { ...@@ -129,23 +117,46 @@ export const Menu = () => {
disabled={globalDisable} disabled={globalDisable}
></Button> ></Button>
</Tooltip> </Tooltip>
<Tooltip title="投降" color="red" open={showRendererTooltips}> <DropdownWithTitle
<Popconfirm title="是否投降?"
title="投降" menu={{ items: surrenderMenuItems }}
description="您确认要投降?" disabled={globalDisable}
onConfirm={sendSurrender} >
okText="确认" <Button icon={<CloseCircleFilled />} type="text"></Button>
cancelText="取消" </DropdownWithTitle>
placement="topRight"
arrow
onOpenChange={(open) =>
setShowRendererTooltips(!open ? undefined : !open)
}
>
<Button icon={<CloseCircleFilled />} type="text"></Button>
</Popconfirm>
</Tooltip>
</div> </div>
</> </>
); );
}; };
const DropdownWithTitle: React.FC<DropdownProps & { title: string }> = (
props
) => {
const { token } = useToken();
const contentStyle = {
backgroundColor: token.colorBgElevated,
borderRadius: token.borderRadiusLG,
boxShadow: token.boxShadowSecondary,
};
const menuStyle = {
boxShadow: "none",
};
return (
<Dropdown
{...props}
dropdownRender={(menu) => (
<div style={contentStyle}>
<Space style={{ padding: "12px 16px" }}>{props.title}</Space>
<Divider style={{ margin: 0 }} />
{cloneElement(menu as React.ReactElement, {
style: menuStyle,
})}
</div>
)}
arrow
trigger={["click", "hover"]}
>
{props.children}
</Dropdown>
);
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment