diff --git a/api-generator/components/megamenu.js b/api-generator/components/megamenu.js index 5c295625ef..4398f863da 100644 --- a/api-generator/components/megamenu.js +++ b/api-generator/components/megamenu.js @@ -28,6 +28,18 @@ const MegaMenuProps = [ type: 'string', default: 'horizontal', description: 'Defines the orientation, valid values are horizontal and vertical.' + }, + { + name: 'start', + type: 'any', + default: 'null', + description: 'The template of starting element.' + }, + { + name: 'end', + type: 'any', + default: 'null', + description: 'The template of trailing element' } ]; diff --git a/components/doc/megamenu/index.js b/components/doc/megamenu/index.js index 4a599e1681..2ff3ce735b 100644 --- a/components/doc/megamenu/index.js +++ b/components/doc/megamenu/index.js @@ -132,12 +132,15 @@ export class MegaMenuDemo extends Component { ]; } + const start = logo e.target.src='https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} height="40" className="mr-2">; + const end = ; + render() { return (
Horizontal
- +
Vertical
@@ -269,11 +272,14 @@ const MegaMenuDemo = () => { } ]; + const start = logo e.target.src='https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} height="40" className="mr-2">; + const end = ; + return (
Horizontal
- +
Vertical
@@ -404,11 +410,14 @@ const MegaMenuDemo = () => { } ]; + const start = logo e.target.src='https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} height="40" className="mr-2">; + const end = ; + return (
Horizontal
- +
Vertical
@@ -542,11 +551,14 @@ const MegaMenuDemo = () => { } ]; + const start = logo e.target.src='https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} height="40" className="mr-2">; + const end = ; + return (
Horizontal
- +
Vertical
@@ -713,13 +725,14 @@ const items = [
Custom Content
-

Any content inside the megamenu will be displayed on the right side by default. You may use ".ui-megamenu-custom" style class to change the location of the content.

+

The megamenu can display custom content by using the "start" and "end" properties.

{` - - -
@@ -785,7 +810,7 @@ const items = [ Container element. - p-menu-list + p-megamenu-root-list List element. diff --git a/components/lib/megamenu/MegaMenu.css b/components/lib/megamenu/MegaMenu.css index 9ec0afc17b..e4d7dce3fc 100644 --- a/components/lib/megamenu/MegaMenu.css +++ b/components/lib/megamenu/MegaMenu.css @@ -38,6 +38,12 @@ list-style: none; } +.p-megamenu .p-megamenu-custom, +.p-megamenu .p-megamenu-end { + margin-left: auto; + align-self: center; +} + /* Horizontal */ .p-megamenu-horizontal .p-megamenu-root-list { display: flex; diff --git a/components/lib/megamenu/MegaMenu.d.ts b/components/lib/megamenu/MegaMenu.d.ts index 32e748a50e..5651bde880 100644 --- a/components/lib/megamenu/MegaMenu.d.ts +++ b/components/lib/megamenu/MegaMenu.d.ts @@ -3,12 +3,19 @@ import { MenuItem } from '../menuitem'; type MegaMenuOrientationType = 'vertical' | 'horizontal'; +type MegaMenuStartTemplate = React.ReactNode | ((props: MegaMenuProps) => React.ReactNode); + +type MegaMenuEndTemplate = React.ReactNode | ((props: MegaMenuProps) => React.ReactNode); + + export interface MegaMenuProps { id?: string; model?: MenuItem[]; style?: object; className?: string; orientation?: MegaMenuOrientationType; + start?: MegaMenuStartTemplate; + end?: MegaMenuEndTemplate; children?: React.ReactNode; } diff --git a/components/lib/megamenu/MegaMenu.js b/components/lib/megamenu/MegaMenu.js index db404685d1..bfff6e5007 100644 --- a/components/lib/megamenu/MegaMenu.js +++ b/components/lib/megamenu/MegaMenu.js @@ -338,12 +338,28 @@ export const MegaMenu = React.memo(React.forwardRef((props, ref) => { return null; } - const createCustomContent = () => { - if (props.children) { + const createStartContent = () => { + if (props.start) { + const start = ObjectUtils.getJSXElement(props.start, props); + return ( -
- {props.children} -
+
  • + {start} +
  • + ) + } + + return null; + } + + const createEndContent = () => { + if (props.end) { + const end = ObjectUtils.getJSXElement(props.end, props); + + return ( +
  • + {end} +
  • ) } @@ -357,14 +373,16 @@ export const MegaMenu = React.memo(React.forwardRef((props, ref) => { 'p-megamenu-vertical': props.orientation === 'vertical' }, props.className); const menu = createMenu(); - const customContent = createCustomContent(); + const start = createStartContent(); + const end = createEndContent(); return (
      + {start} {menu} + {end}
    - {customContent}
    ) })); @@ -376,5 +394,7 @@ MegaMenu.defaultProps = { model: null, style: null, className: null, - orientation: 'horizontal' + orientation: 'horizontal', + start: null, + end: null } diff --git a/components/lib/menubar/Menubar.js b/components/lib/menubar/Menubar.js index a0f1b6b0ab..7fe4c84156 100644 --- a/components/lib/menubar/Menubar.js +++ b/components/lib/menubar/Menubar.js @@ -52,18 +52,6 @@ export const Menubar = React.memo(React.forwardRef((props, ref) => { useCustomContent })); - const createCustomContent = () => { - if (props.children) { - return ( -
    - {props.children} -
    - ) - } - - return null; - } - const createStartContent = () => { if (props.start) { const start = ObjectUtils.getJSXElement(props.start, props); diff --git a/pages/megamenu/index.js b/pages/megamenu/index.js index f8f573724d..25ccb137a3 100644 --- a/pages/megamenu/index.js +++ b/pages/megamenu/index.js @@ -1,8 +1,10 @@ import React from 'react'; import { MegaMenu } from '../../components/lib/megamenu/MegaMenu'; +import { InputText } from '../../components/lib/inputtext/InputText'; import MegaMenuDoc from '../../components/doc/megamenu'; import { DocActions } from '../../components/doc/common/docactions'; import Head from 'next/head'; +import getConfig from 'next/config'; const MegaMenuDemo = () => { @@ -119,6 +121,10 @@ const MegaMenuDemo = () => { } ]; + const contextPath = getConfig().publicRuntimeConfig.contextPath; + const start = logo e.target.src = 'https://www.primefaces.org/wp-content/uploads/2020/05/placeholder.png'} height="40" className="mr-2">; + const end = ; + return (
    @@ -136,7 +142,7 @@ const MegaMenuDemo = () => {
    Horizontal
    - +
    Vertical