|
| 1 | +import React from 'react'; |
| 2 | +import Menu, { SubMenu, Item as MenuItem } from '../../src'; |
| 3 | +import type { ReactElement } from 'react'; |
| 4 | +import './customPopupRender.less'; |
| 5 | + |
| 6 | +const NavigationDemo = () => { |
| 7 | + const menuItems = [ |
| 8 | + { |
| 9 | + key: 'home', |
| 10 | + label: 'Home', |
| 11 | + }, |
| 12 | + { |
| 13 | + key: 'features', |
| 14 | + label: 'Features', |
| 15 | + children: [ |
| 16 | + { |
| 17 | + key: 'getting-started', |
| 18 | + label: ( |
| 19 | + <a href="/docs"> |
| 20 | + <h3>Getting Started</h3> |
| 21 | + <p>Quick start guide and learn the basics.</p> |
| 22 | + </a> |
| 23 | + ), |
| 24 | + }, |
| 25 | + { |
| 26 | + key: 'components', |
| 27 | + label: ( |
| 28 | + <a href="/components"> |
| 29 | + <h3>Components</h3> |
| 30 | + <p>Explore our component library.</p> |
| 31 | + </a> |
| 32 | + ), |
| 33 | + }, |
| 34 | + { |
| 35 | + key: 'templates', |
| 36 | + label: ( |
| 37 | + <a href="/templates"> |
| 38 | + <h3>Templates</h3> |
| 39 | + <p>Ready-to-use template designs.</p> |
| 40 | + </a> |
| 41 | + ), |
| 42 | + }, |
| 43 | + ], |
| 44 | + }, |
| 45 | + { |
| 46 | + key: 'resources', |
| 47 | + label: 'Resources', |
| 48 | + children: [ |
| 49 | + { |
| 50 | + key: 'blog', |
| 51 | + label: ( |
| 52 | + <a href="/blog"> |
| 53 | + <h3>Blog</h3> |
| 54 | + <p>Latest updates and articles.</p> |
| 55 | + </a> |
| 56 | + ), |
| 57 | + }, |
| 58 | + { |
| 59 | + key: 'community', |
| 60 | + label: ( |
| 61 | + <a href="/community"> |
| 62 | + <h3>Community</h3> |
| 63 | + <p>Join our developer community.</p> |
| 64 | + </a> |
| 65 | + ), |
| 66 | + }, |
| 67 | + ], |
| 68 | + }, |
| 69 | + ]; |
| 70 | + const popupRender = (node: ReactElement) => ( |
| 71 | + <div className="navigation-popup"> |
| 72 | + <div className="navigation-grid"> |
| 73 | + {React.Children.map(node.props.children.props.children, child => ( |
| 74 | + <div className="navigation-item"> |
| 75 | + {React.cloneElement(child, { |
| 76 | + className: `${child.props.className || ''} navigation-menu-item`, |
| 77 | + })} |
| 78 | + </div> |
| 79 | + ))} |
| 80 | + </div> |
| 81 | + </div> |
| 82 | + ); |
| 83 | + |
| 84 | + return <Menu mode="horizontal" popupRender={popupRender} items={menuItems} />; |
| 85 | +}; |
| 86 | + |
| 87 | +const MixedPanelDemo = () => { |
| 88 | + const totalPopupRender = (node: ReactElement, info: { item: any; keys: string[] }) => { |
| 89 | + const isSecondLevel = info.keys.length == 2; |
| 90 | + if (isSecondLevel) { |
| 91 | + return ( |
| 92 | + <div className="navigation-popup"> |
| 93 | + <div className="navigation-grid"> |
| 94 | + {React.Children.map(node.props.children.props.children, child => ( |
| 95 | + <div className="navigation-item"> |
| 96 | + {React.cloneElement(child, { |
| 97 | + className: `${child.props.className || ''} navigation-menu-item`, |
| 98 | + })} |
| 99 | + </div> |
| 100 | + ))} |
| 101 | + </div> |
| 102 | + </div> |
| 103 | + ); |
| 104 | + } |
| 105 | + return node; |
| 106 | + }; |
| 107 | + const singlePopupRender = (node: ReactElement, info: { item: any; keys: string[] }) => { |
| 108 | + const isSecondLevel = info.keys.length == 2; |
| 109 | + if (isSecondLevel) { |
| 110 | + return ( |
| 111 | + <div className="panel-popup"> |
| 112 | + <div className="panel-header"> |
| 113 | + <h4>{info.item.title}</h4> |
| 114 | + </div> |
| 115 | + <div className="panel-content">{node}</div> |
| 116 | + </div> |
| 117 | + ); |
| 118 | + } |
| 119 | + return node; |
| 120 | + }; |
| 121 | + return ( |
| 122 | + <Menu mode="horizontal" popupRender={totalPopupRender}> |
| 123 | + <MenuItem key="home">Home</MenuItem> |
| 124 | + <SubMenu key="products" title="Products"> |
| 125 | + <MenuItem key="product-a">Product A</MenuItem> |
| 126 | + <MenuItem key="product-b">Product B</MenuItem> |
| 127 | + <SubMenu key="more-products" title="More Products"> |
| 128 | + <MenuItem key="product-c"> |
| 129 | + <a href="/product-c"> |
| 130 | + <h3>Product C</h3> |
| 131 | + <p>Description for Product C.</p> |
| 132 | + </a> |
| 133 | + </MenuItem> |
| 134 | + <MenuItem key="product-d"> |
| 135 | + <a href="/product-d"> |
| 136 | + <h3>Product D</h3> |
| 137 | + <p>Description for Product D.</p> |
| 138 | + </a> |
| 139 | + </MenuItem> |
| 140 | + </SubMenu> |
| 141 | + </SubMenu> |
| 142 | + <SubMenu key="solutions" title="Solutions"> |
| 143 | + <MenuItem key="enterprise">Enterprise</MenuItem> |
| 144 | + <MenuItem key="personal">Personal</MenuItem> |
| 145 | + <SubMenu key="industry" title="Industry" popupRender={singlePopupRender}> |
| 146 | + <MenuItem key="healthcare">Healthcare</MenuItem> |
| 147 | + <MenuItem key="education">Education</MenuItem> |
| 148 | + </SubMenu> |
| 149 | + </SubMenu> |
| 150 | + </Menu> |
| 151 | + ); |
| 152 | +}; |
| 153 | + |
| 154 | +const Demo = () => { |
| 155 | + return ( |
| 156 | + <div> |
| 157 | + <h3>NavigationDemo</h3> |
| 158 | + <NavigationDemo /> |
| 159 | + <h3>MixedPanelDemo</h3> |
| 160 | + <MixedPanelDemo /> |
| 161 | + </div> |
| 162 | + ); |
| 163 | +}; |
| 164 | +export default Demo; |
0 commit comments