Skip to content

Commit

Permalink
fix: Optimize the custom-dropdown demo style (#39626)
Browse files Browse the repository at this point in the history
* fix: Optimize the custom-dropdown demo style

* chore: Using the token variable
  • Loading branch information
JarvisArt committed Dec 19, 2022
1 parent 254e0a9 commit 1ce7d3a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3126,12 +3126,15 @@ Array [
style="opacity:0"
>
<div
class="dropdown-content"
style="background-color:#ffffff;border-radius:8px;box-shadow:0 6px 16px 0 rgba(0, 0, 0, 0.08),
0 3px 6px -4px rgba(0, 0, 0, 0.12),
0 9px 28px 8px rgba(0, 0, 0, 0.05)"
>
<ul
class="ant-dropdown-menu ant-dropdown-menu-root ant-dropdown-menu-vertical ant-dropdown-menu-light"
data-menu-list="true"
role="menu"
style="box-shadow:none"
tabindex="0"
>
<li
Expand Down
17 changes: 0 additions & 17 deletions components/dropdown/demo/custom-dropdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,3 @@
## en-US

Customize the dropdown menu via `dropdownRender`. If you don't need the Menu content, use the Popover component directly.

```css
.dropdown-content {
background: #fff;
box-shadow: 0 3px 6px -4px rgb(0 0 0 / 12%), 0 6px 16px 0 rgb(0 0 0 / 8%),
0 9px 28px 8px rgb(0 0 0 / 5%);
}
.dropdown-content .ant-dropdown-menu {
box-shadow: none;
}
```

<style>
[data-theme="dark"] .head-example {
background: #1f1f1f;
}
</style>
58 changes: 37 additions & 21 deletions components/dropdown/demo/custom-dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react';
import { DownOutlined } from '@ant-design/icons';
import { Dropdown, Space, Divider, Button, theme } from 'antd';
import type { MenuProps } from 'antd';
import { Dropdown, Space, Divider, Button } from 'antd';

const { useToken } = theme;

const items: MenuProps['items'] = [
{
Expand Down Expand Up @@ -32,26 +34,40 @@ const items: MenuProps['items'] = [
},
];

const App: React.FC = () => (
<Dropdown
menu={{ items }}
dropdownRender={(menu) => (
<div className="dropdown-content">
{menu}
<Divider style={{ margin: 0 }} />
<Space style={{ padding: 8 }}>
<Button type="primary">Click me!</Button>
const App: React.FC = () => {
const { token } = useToken();

const contentStyle = {
backgroundColor: token.colorBgElevated,
borderRadius: token.borderRadiusLG,
boxShadow: token.boxShadowSecondary,
};

const menuStyle = {
boxShadow: 'none',
};

return (
<Dropdown
menu={{ items }}
dropdownRender={(menu) => (
<div style={contentStyle}>
{React.cloneElement(menu as React.ReactElement, { style: menuStyle })}
<Divider style={{ margin: 0 }} />
<Space style={{ padding: 8 }}>
<Button type="primary">Click me!</Button>
</Space>
</div>
)}
>
<a onClick={(e) => e.preventDefault()}>
<Space>
Hover me
<DownOutlined />
</Space>
</div>
)}
>
<a onClick={(e) => e.preventDefault()}>
<Space>
Hover me
<DownOutlined />
</Space>
</a>
</Dropdown>
);
</a>
</Dropdown>
);
};

export default App;

0 comments on commit 1ce7d3a

Please sign in to comment.