Skip to content

Commit

Permalink
fix: horizontal Menu style with (ant-design#40105)
Browse files Browse the repository at this point in the history
* fix: horizontal Menu style with

* chore: update snapshot

* chore: code clean
  • Loading branch information
MadCcc authored Jan 9, 2023
1 parent fadba4c commit d24c55a
Show file tree
Hide file tree
Showing 8 changed files with 682 additions and 14 deletions.
406 changes: 406 additions & 0 deletions components/menu/__tests__/__snapshots__/demo-extend.test.ts.snap

Large diffs are not rendered by default.

174 changes: 174 additions & 0 deletions components/menu/__tests__/__snapshots__/demo.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,180 @@ Array [
]
`;

exports[`renders ./components/menu/demo/horizontal-dark.tsx correctly 1`] = `
Array [
<ul
class="ant-menu-overflow ant-menu ant-menu-root ant-menu-horizontal ant-menu-dark"
data-menu-list="true"
role="menu"
tabindex="0"
>
<li
class="ant-menu-overflow-item ant-menu-item ant-menu-item-selected"
role="menuitem"
style="opacity:1;order:0"
tabindex="-1"
>
<span
aria-label="mail"
class="anticon anticon-mail ant-menu-item-icon"
role="img"
>
<svg
aria-hidden="true"
data-icon="mail"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M928 160H96c-17.7 0-32 14.3-32 32v640c0 17.7 14.3 32 32 32h832c17.7 0 32-14.3 32-32V192c0-17.7-14.3-32-32-32zm-40 110.8V792H136V270.8l-27.6-21.5 39.3-50.5 42.8 33.3h643.1l42.8-33.3 39.3 50.5-27.7 21.5zM833.6 232L512 482 190.4 232l-42.8-33.3-39.3 50.5 27.6 21.5 341.6 265.6a55.99 55.99 0 0068.7 0L888 270.8l27.6-21.5-39.3-50.5-42.7 33.2z"
/>
</svg>
</span>
<span
class="ant-menu-title-content"
>
Navigation One
</span>
</li>
<li
aria-disabled="true"
class="ant-menu-overflow-item ant-menu-item ant-menu-item-disabled"
role="menuitem"
style="opacity:1;order:1"
>
<span
aria-label="appstore"
class="anticon anticon-appstore ant-menu-item-icon"
role="img"
>
<svg
aria-hidden="true"
data-icon="appstore"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M464 144H160c-8.8 0-16 7.2-16 16v304c0 8.8 7.2 16 16 16h304c8.8 0 16-7.2 16-16V160c0-8.8-7.2-16-16-16zm-52 268H212V212h200v200zm452-268H560c-8.8 0-16 7.2-16 16v304c0 8.8 7.2 16 16 16h304c8.8 0 16-7.2 16-16V160c0-8.8-7.2-16-16-16zm-52 268H612V212h200v200zM464 544H160c-8.8 0-16 7.2-16 16v304c0 8.8 7.2 16 16 16h304c8.8 0 16-7.2 16-16V560c0-8.8-7.2-16-16-16zm-52 268H212V612h200v200zm452-268H560c-8.8 0-16 7.2-16 16v304c0 8.8 7.2 16 16 16h304c8.8 0 16-7.2 16-16V560c0-8.8-7.2-16-16-16zm-52 268H612V612h200v200z"
/>
</svg>
</span>
<span
class="ant-menu-title-content"
>
Navigation Two
</span>
</li>
<li
class="ant-menu-overflow-item ant-menu-submenu ant-menu-submenu-horizontal"
role="none"
style="opacity:1;order:2"
>
<div
aria-expanded="false"
aria-haspopup="true"
class="ant-menu-submenu-title"
role="menuitem"
tabindex="-1"
>
<span
aria-label="setting"
class="anticon anticon-setting ant-menu-item-icon"
role="img"
>
<svg
aria-hidden="true"
data-icon="setting"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M924.8 625.7l-65.5-56c3.1-19 4.7-38.4 4.7-57.8s-1.6-38.8-4.7-57.8l65.5-56a32.03 32.03 0 009.3-35.2l-.9-2.6a443.74 443.74 0 00-79.7-137.9l-1.8-2.1a32.12 32.12 0 00-35.1-9.5l-81.3 28.9c-30-24.6-63.5-44-99.7-57.6l-15.7-85a32.05 32.05 0 00-25.8-25.7l-2.7-.5c-52.1-9.4-106.9-9.4-159 0l-2.7.5a32.05 32.05 0 00-25.8 25.7l-15.8 85.4a351.86 351.86 0 00-99 57.4l-81.9-29.1a32 32 0 00-35.1 9.5l-1.8 2.1a446.02 446.02 0 00-79.7 137.9l-.9 2.6c-4.5 12.5-.8 26.5 9.3 35.2l66.3 56.6c-3.1 18.8-4.6 38-4.6 57.1 0 19.2 1.5 38.4 4.6 57.1L99 625.5a32.03 32.03 0 00-9.3 35.2l.9 2.6c18.1 50.4 44.9 96.9 79.7 137.9l1.8 2.1a32.12 32.12 0 0035.1 9.5l81.9-29.1c29.8 24.5 63.1 43.9 99 57.4l15.8 85.4a32.05 32.05 0 0025.8 25.7l2.7.5a449.4 449.4 0 00159 0l2.7-.5a32.05 32.05 0 0025.8-25.7l15.7-85a350 350 0 0099.7-57.6l81.3 28.9a32 32 0 0035.1-9.5l1.8-2.1c34.8-41.1 61.6-87.5 79.7-137.9l.9-2.6c4.5-12.3.8-26.3-9.3-35zM788.3 465.9c2.5 15.1 3.8 30.6 3.8 46.1s-1.3 31-3.8 46.1l-6.6 40.1 74.7 63.9a370.03 370.03 0 01-42.6 73.6L721 702.8l-31.4 25.8c-23.9 19.6-50.5 35-79.3 45.8l-38.1 14.3-17.9 97a377.5 377.5 0 01-85 0l-17.9-97.2-37.8-14.5c-28.5-10.8-55-26.2-78.7-45.7l-31.4-25.9-93.4 33.2c-17-22.9-31.2-47.6-42.6-73.6l75.5-64.5-6.5-40c-2.4-14.9-3.7-30.3-3.7-45.5 0-15.3 1.2-30.6 3.7-45.5l6.5-40-75.5-64.5c11.3-26.1 25.6-50.7 42.6-73.6l93.4 33.2 31.4-25.9c23.7-19.5 50.2-34.9 78.7-45.7l37.9-14.3 17.9-97.2c28.1-3.2 56.8-3.2 85 0l17.9 97 38.1 14.3c28.7 10.8 55.4 26.2 79.3 45.8l31.4 25.8 92.8-32.9c17 22.9 31.2 47.6 42.6 73.6L781.8 426l6.5 39.9zM512 326c-97.2 0-176 78.8-176 176s78.8 176 176 176 176-78.8 176-176-78.8-176-176-176zm79.2 255.2A111.6 111.6 0 01512 614c-29.9 0-58-11.7-79.2-32.8A111.6 111.6 0 01400 502c0-29.9 11.7-58 32.8-79.2C454 401.6 482.1 390 512 390c29.9 0 58 11.6 79.2 32.8A111.6 111.6 0 01624 502c0 29.9-11.7 58-32.8 79.2z"
/>
</svg>
</span>
<span
class="ant-menu-title-content"
>
Navigation Three - Submenu
</span>
<i
class="ant-menu-submenu-arrow"
/>
</div>
</li>
<li
class="ant-menu-overflow-item ant-menu-item ant-menu-item-only-child"
role="menuitem"
style="opacity:1;order:3"
tabindex="-1"
>
<span
class="ant-menu-title-content"
>
<a
href="https://ant.design"
rel="noopener noreferrer"
target="_blank"
>
Navigation Four - Link
</a>
</span>
</li>
<li
aria-hidden="true"
class="ant-menu-overflow-item ant-menu-overflow-item-rest ant-menu-submenu ant-menu-submenu-horizontal"
role="none"
style="opacity:0;height:0;overflow-y:hidden;order:9007199254740991;pointer-events:none;position:absolute"
>
<div
aria-expanded="false"
aria-haspopup="true"
class="ant-menu-submenu-title"
role="menuitem"
tabindex="-1"
>
<span
aria-label="ellipsis"
class="anticon anticon-ellipsis"
role="img"
>
<svg
aria-hidden="true"
data-icon="ellipsis"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M176 511a56 56 0 10112 0 56 56 0 10-112 0zm280 0a56 56 0 10112 0 56 56 0 10-112 0zm280 0a56 56 0 10112 0 56 56 0 10-112 0z"
/>
</svg>
</span>
<i
class="ant-menu-submenu-arrow"
/>
</div>
</li>
</ul>,
<div
aria-hidden="true"
style="display:none"
/>,
]
`;

exports[`renders ./components/menu/demo/inline.tsx correctly 1`] = `
Array [
<ul
Expand Down
7 changes: 7 additions & 0 deletions components/menu/demo/horizontal-dark.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## zh-CN

水平的顶部导航菜单。

## en-US

Horizontal top navigation menu.
76 changes: 76 additions & 0 deletions components/menu/demo/horizontal-dark.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React, { useState } from 'react';
import { AppstoreOutlined, MailOutlined, SettingOutlined } from '@ant-design/icons';
import type { MenuProps } from 'antd';
import { Menu } from 'antd';

const items: MenuProps['items'] = [
{
label: 'Navigation One',
key: 'mail',
icon: <MailOutlined />,
},
{
label: 'Navigation Two',
key: 'app',
icon: <AppstoreOutlined />,
disabled: true,
},
{
label: 'Navigation Three - Submenu',
key: 'SubMenu',
icon: <SettingOutlined />,
children: [
{
type: 'group',
label: 'Item 1',
children: [
{
label: 'Option 1',
key: 'setting:1',
},
{
label: 'Option 2',
key: 'setting:2',
},
],
},
{
type: 'group',
label: 'Item 2',
children: [
{
label: 'Option 3',
key: 'setting:3',
},
{
label: 'Option 4',
key: 'setting:4',
},
],
},
],
},
{
label: (
<a href="https://ant.design" target="_blank" rel="noopener noreferrer">
Navigation Four - Link
</a>
),
key: 'alipay',
},
];

const App: React.FC = () => {
const [current, setCurrent] = useState('mail');

const onClick: MenuProps['onClick'] = (e) => {
console.log('click ', e);
setCurrent(e.key);
};

return (
<Menu onClick={onClick} selectedKeys={[current]} mode="horizontal" items={items} theme="dark" />
);
};

export default App;
1 change: 1 addition & 0 deletions components/menu/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ More layouts with navigation: [Layout](/components/layout).

<!-- prettier-ignore -->
<code src="./demo/horizontal.tsx">Top Navigation</code>
<code src="./demo/horizontal-dark.tsx" debug>Top Navigation (dark)</code>
<code src="./demo/inline.tsx">Inline menu</code>
<code src="./demo/inline-collapsed.tsx">Collapsed inline menu</code>
<code src="./demo/sider-current.tsx">Open current submenu only</code>
Expand Down
1 change: 1 addition & 0 deletions components/menu/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*KeyQQL5iKkkAAAAAAA

<!-- prettier-ignore -->
<code src="./demo/horizontal.tsx">顶部导航</code>
<code src="./demo/horizontal-dark.tsx" debug>顶部导航(dark)</code>
<code src="./demo/inline.tsx">内嵌菜单</code>
<code src="./demo/inline-collapsed.tsx">缩起内嵌菜单</code>
<code src="./demo/sider-current.tsx">只展开当前父级菜单</code>
Expand Down
20 changes: 10 additions & 10 deletions components/menu/style/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,8 @@ export default (prefixCls: string, injectStyle: boolean): UseComponentStyleResul
return [];
}

const {
colorBgElevated,
colorPrimary,
colorError,
colorErrorHover,
colorTextLightSolid,
colorTextSecondary,
} = token;
const { colorBgElevated, colorPrimary, colorError, colorErrorHover, colorTextLightSolid } =
token;

const { controlHeightLG, fontSize } = token;

Expand All @@ -465,12 +459,14 @@ export default (prefixCls: string, injectStyle: boolean): UseComponentStyleResul
menuSubMenuBg: colorBgElevated,
});

const colorTextDark = new TinyColor(colorTextLightSolid).setAlpha(0.65).toRgbString();

const menuDarkToken = mergeToken<MenuToken>(
menuToken,
{
colorItemText: new TinyColor(colorTextLightSolid).setAlpha(0.65).toRgbString(),
colorItemText: colorTextDark,
colorItemTextHover: colorTextLightSolid,
colorGroupTitle: colorTextSecondary,
colorGroupTitle: colorTextDark,
colorItemTextSelected: colorTextLightSolid,
colorItemBg: '#001529',
colorSubItemBg: '#000c17',
Expand All @@ -491,6 +487,10 @@ export default (prefixCls: string, injectStyle: boolean): UseComponentStyleResul
colorDangerItemBgSelected: colorError,

menuSubMenuBg: '#001529',

// Horizontal
colorItemTextSelectedHorizontal: colorTextLightSolid,
colorItemBgSelectedHorizontal: colorPrimary,
},
{
...overrideComponentToken,
Expand Down
11 changes: 7 additions & 4 deletions components/menu/style/theme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ const getThemeStyle = (token: MenuToken, themeSuffix: string): CSSInterpolation
componentCls,
colorItemText,
colorItemTextSelected,
colorItemTextSelectedHorizontal,
colorGroupTitle,
colorItemBg,
colorSubItemBg,
colorItemBgSelectedHorizontal,
colorItemBgSelected,
colorActiveBarHeight,
colorActiveBarWidth,
Expand All @@ -41,6 +39,10 @@ const getThemeStyle = (token: MenuToken, themeSuffix: string): CSSInterpolation

colorItemBgHover,
menuSubMenuBg,

// Horizontal
colorItemTextSelectedHorizontal,
colorItemBgSelectedHorizontal,
} = token;

return {
Expand Down Expand Up @@ -85,6 +87,7 @@ const getThemeStyle = (token: MenuToken, themeSuffix: string): CSSInterpolation
backgroundColor: colorItemBgSelected,
},
},

[`${componentCls}-submenu-title`]: {
'&:hover': {
backgroundColor: colorItemBgHover,
Expand Down Expand Up @@ -130,7 +133,7 @@ const getThemeStyle = (token: MenuToken, themeSuffix: string): CSSInterpolation
},
},

[`&:not(${componentCls}-horizontal) ${componentCls}-item-selected`]: {
[`& ${componentCls}-item-selected`]: {
backgroundColor: colorItemBgSelected,

// Danger
Expand Down Expand Up @@ -165,7 +168,7 @@ const getThemeStyle = (token: MenuToken, themeSuffix: string): CSSInterpolation
top: colorActiveBarBorderSize,
marginTop: -colorActiveBarBorderSize,
marginBottom: 0,
borderRadius: token.radiusItem,
borderRadius: 0,

'&::after': {
position: 'absolute',
Expand Down

0 comments on commit d24c55a

Please sign in to comment.