-
-
Notifications
You must be signed in to change notification settings - Fork 264
feat: add popupRender prop to support custom popup content #747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4780eb7
add popupRender for subMenu
Zyf665 378bf74
rename file
Zyf665 88b303a
modify test cases and optimize renderPopupContent method
Zyf665 f8124dd
modify test cases And popupContent code
Zyf665 38ac58d
fix type assertion for popupRender item prop
Zyf665 bd9f28a
merge: resolve conflicts with upstream
Zyf665 caaf56f
chore: fix tsc
MadCcc b32753e
chore: fix lint
MadCcc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ## customPopupRender | ||
|
|
||
| <code src="../examples/customPopupRender.tsx"></code> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| .navigation-popup { | ||
| padding: 24px; | ||
| min-width: 480px; | ||
| background: #fff; | ||
| border-radius: 8px; | ||
| box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08); | ||
|
|
||
| .navigation-grid { | ||
| display: grid; | ||
| grid-template-columns: repeat(2, 1fr); | ||
| gap: 16px; | ||
| } | ||
|
|
||
| .navigation-menu-item { | ||
| padding: 0; | ||
| margin: 0; | ||
|
|
||
| a { | ||
| display: block; | ||
| padding: 16px; | ||
| text-decoration: none; | ||
| color: inherit; | ||
| border-radius: 6px; | ||
| transition: all 0.3s; | ||
|
|
||
| h3 { | ||
| margin: 0 0 8px; | ||
| font-size: 16px; | ||
| font-weight: 500; | ||
| } | ||
|
|
||
| p { | ||
| margin: 0; | ||
| color: rgba(0, 0, 0, 0.45); | ||
| font-size: 14px; | ||
| line-height: 1.5; | ||
| } | ||
|
|
||
| &:hover { | ||
| background: rgba(0, 0, 0, 0.02); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .panel-popup { | ||
| padding: 16px; | ||
| min-width: 240px; | ||
| background: #fff; | ||
| border-radius: 8px; | ||
| box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08); | ||
|
|
||
| .panel-header { | ||
| padding: 0 8px 12px; | ||
| border-bottom: 1px solid rgba(0, 0, 0, 0.06); | ||
| margin-bottom: 8px; | ||
|
|
||
| h4 { | ||
| margin: 0; | ||
| font-size: 14px; | ||
| color: rgba(0, 0, 0, 0.45); | ||
| } | ||
| } | ||
|
|
||
| .panel-content { | ||
| .rc-menu-item { | ||
| padding: 8px 12px; | ||
| margin: 0; | ||
| border-radius: 4px; | ||
|
|
||
| &:hover { | ||
| background: rgba(0, 0, 0, 0.02); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| import React from 'react'; | ||
| import Menu, { SubMenu, Item as MenuItem } from '../../src'; | ||
| import type { ReactElement } from 'react'; | ||
| import './customPopupRender.less'; | ||
|
|
||
| const NavigationDemo = () => { | ||
| const menuItems = [ | ||
| { | ||
| key: 'home', | ||
| label: 'Home', | ||
| }, | ||
| { | ||
| key: 'features', | ||
| label: 'Features', | ||
| children: [ | ||
| { | ||
| key: 'getting-started', | ||
| label: ( | ||
| <a href="/docs"> | ||
| <h3>Getting Started</h3> | ||
| <p>Quick start guide and learn the basics.</p> | ||
| </a> | ||
| ), | ||
| }, | ||
| { | ||
| key: 'components', | ||
| label: ( | ||
| <a href="/components"> | ||
| <h3>Components</h3> | ||
| <p>Explore our component library.</p> | ||
| </a> | ||
| ), | ||
| }, | ||
| { | ||
| key: 'templates', | ||
| label: ( | ||
| <a href="/templates"> | ||
| <h3>Templates</h3> | ||
| <p>Ready-to-use template designs.</p> | ||
| </a> | ||
| ), | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| key: 'resources', | ||
| label: 'Resources', | ||
| children: [ | ||
| { | ||
| key: 'blog', | ||
| label: ( | ||
| <a href="/blog"> | ||
| <h3>Blog</h3> | ||
| <p>Latest updates and articles.</p> | ||
| </a> | ||
| ), | ||
| }, | ||
| { | ||
| key: 'community', | ||
| label: ( | ||
| <a href="/community"> | ||
| <h3>Community</h3> | ||
| <p>Join our developer community.</p> | ||
| </a> | ||
| ), | ||
| }, | ||
| ], | ||
| }, | ||
| ]; | ||
| const popupRender = (node: ReactElement) => ( | ||
| <div className="navigation-popup"> | ||
| <div className="navigation-grid"> | ||
| {React.Children.map(node.props.children.props.children, child => ( | ||
| <div className="navigation-item"> | ||
| {React.cloneElement(child, { | ||
| className: `${child.props.className || ''} navigation-menu-item`, | ||
| })} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ); | ||
|
|
||
| return <Menu mode="horizontal" popupRender={popupRender} items={menuItems} />; | ||
| }; | ||
|
|
||
| const MixedPanelDemo = () => { | ||
| const totalPopupRender = (node: ReactElement, info: { item: any; keys: string[] }) => { | ||
| const isSecondLevel = info.keys.length == 2; | ||
| if (isSecondLevel) { | ||
| return ( | ||
| <div className="navigation-popup"> | ||
| <div className="navigation-grid"> | ||
| {React.Children.map(node.props.children.props.children, child => ( | ||
| <div className="navigation-item"> | ||
| {React.cloneElement(child, { | ||
| className: `${child.props.className || ''} navigation-menu-item`, | ||
| })} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
| return node; | ||
| }; | ||
| const singlePopupRender = (node: ReactElement, info: { item: any; keys: string[] }) => { | ||
| const isSecondLevel = info.keys.length == 2; | ||
| if (isSecondLevel) { | ||
| return ( | ||
| <div className="panel-popup"> | ||
| <div className="panel-header"> | ||
| <h4>{info.item.title}</h4> | ||
| </div> | ||
| <div className="panel-content">{node}</div> | ||
| </div> | ||
| ); | ||
| } | ||
| return node; | ||
| }; | ||
| return ( | ||
| <Menu mode="horizontal" popupRender={totalPopupRender}> | ||
| <MenuItem key="home">Home</MenuItem> | ||
| <SubMenu key="products" title="Products"> | ||
| <MenuItem key="product-a">Product A</MenuItem> | ||
| <MenuItem key="product-b">Product B</MenuItem> | ||
| <SubMenu key="more-products" title="More Products"> | ||
| <MenuItem key="product-c"> | ||
| <a href="/product-c"> | ||
| <h3>Product C</h3> | ||
| <p>Description for Product C.</p> | ||
| </a> | ||
| </MenuItem> | ||
| <MenuItem key="product-d"> | ||
| <a href="/product-d"> | ||
| <h3>Product D</h3> | ||
| <p>Description for Product D.</p> | ||
| </a> | ||
| </MenuItem> | ||
| </SubMenu> | ||
| </SubMenu> | ||
| <SubMenu key="solutions" title="Solutions"> | ||
| <MenuItem key="enterprise">Enterprise</MenuItem> | ||
| <MenuItem key="personal">Personal</MenuItem> | ||
| <SubMenu key="industry" title="Industry" popupRender={singlePopupRender}> | ||
| <MenuItem key="healthcare">Healthcare</MenuItem> | ||
| <MenuItem key="education">Education</MenuItem> | ||
| </SubMenu> | ||
| </SubMenu> | ||
| </Menu> | ||
| ); | ||
| }; | ||
|
|
||
| const Demo = () => { | ||
| return ( | ||
| <div> | ||
| <h3>NavigationDemo</h3> | ||
| <NavigationDemo /> | ||
| <h3>MixedPanelDemo</h3> | ||
| <MixedPanelDemo /> | ||
| </div> | ||
| ); | ||
| }; | ||
| export default Demo; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
修复相等性比较
使用
==进行相等性比较不是最佳实践,建议使用===。建议如下修改:
Also applies to: 114-114