Giter VIP home page Giter VIP logo

react-push-menu's Introduction

react-push-menu

Notice: There are breaking changes. Do not upgrade from v1.* if you do not intend to adjust the interfaces seen below. The interface to manage the menu has changed. Please see the examples below

npm version

Prerequisites

Install peer dependencies

npm install react react-dom styled-components --save

Install

npm install --save react-push-menu

How to use

import { PushMenu, usePushMenu } from 'react-push-menu';
import { FaChevronRight, FaChevronLeft } from 'react-icons/fa';

function Content() {
  const { toggleMenu } = usePushMenu();
  return (
    <div
      onClick={() => {
        toggleMenu();
      }}
    >
      trigger
    </div>
  );
}

/* ... */

function App() {
  return (
    <PushMenu
      backIcon={<FaChevronLeft />}
      expanderComponent={FaChevronRight}
      nodes={menuData}
      propMap={{ url: 'link' }}
    >
      <Content />
    </PushMenu>
  );
}

See example for more details

Properties

openOnMount (boolean)

This option allows you to initialize the push menu as open on load.

nodes (Object)

This property accepts an object with the definition for the menu. see the example for a sample menu definition

propMap (Object)

APIs can define/give a different structure or property names for required fields. This give the user the option to tell react-push-menu which property on the node/menu item to find the value it's looking for.

Mapping Description
id the id property of the node
displayName This is the text that will appear in the menu option.
linkClasses These are class names that will be added to the menu option.
expanderClasses These are class names that will be added to the menu option's expander given it has defined children.
url This tells the library which prop the url for the menu item is located. will default to a hash (#) if none is found
childPropName This is the property name that holds the children of each menu item node. We realize that data driven menu may differ and it is important to customize the properties that may hold the required data. default: children

eg.

<PushMenu
  propMap={{
    displayName: 'title',
    id: 'id',
    linkClasses: 'classes',
    expanderClasses: 'expClasses',
    childPropName: 'children',
    url: 'url',
  }}
></PushMenu>

onNodeClick (function)

This is an onClick callback fired when you click the link of a menu item. Please note it won't be fired when you click the expand component for a menu item.

eg.

<PushMenu
  onNodeClick={(e, context) => {
    /**
      {
        // state
        node: Record<string, any>; // the current node
        nodes: Record<string, any>; // full menu tree
        propMap: PropMap;
        visibleMenus: Array;

        // actions
        addMenu: (node) => {};
        removeLastMenu: Function;
        closeMenu: Function;
        openMenu: Function;
        openSubMenu: (node) => {};
        toggleMenu: Function;
      }
     **/
    console.log(context);

    // following line will close the menu completely
    context.closeMenu();
  }}
></PushMenu>

onMenuExpand (function)

This function triggered when a sub menu is expanded.

<PushMenu
  onMenuExpand={(e, context) => {
    // do something
    // return false to prevent default behaviour
  }}
></PushMenu>

linkComponent (React.Component)

You can fully customize the link of the menu by passing in a React Component to this property. It will be instantiated with the data object which contains the current node being interacted with. (props.data). To see an example please see LinkComponent.js

backComponent (React.Component)

You can fully customize the back link of the sub menus by passing in a React Component to this property. It will be instantiated with the data object which contains the current node being interacted with. (props.data).

backIcon (ReactNode)

If you don't specify a backComponent, you can at least need specify an icon to use for the back component

<FaChevronLeft />

expanderComponent (React.Component) (Required)

You can fully customize the expander link of the sub menus by passing in a React Component to this property. The expander is the chevron-right that appears when a menu item has children. It will be instantiated with the data object which contains the current node being interacted with. (props.data).

Notes/Todos

  • add task to deploy to gh-pages
  • add more event handlers

Pull requests are welcome

Credits

react-push-menu's People

Contributors

atfergus avatar ddawkins7 avatar dependabot[bot] avatar lwhiteley avatar mpurgatori avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-push-menu's Issues

body scroll issue

Hi,
I have used react-push-menu package in my react project for mobile menu's. I am getting scrolling issue when I scroll on menu the body getting scrolled. I tried to get an event when menu's opened to apply css to handle this issue but couldn't get any event or couldn't apply any custom event also. Please help me to solve this.

Thank's.

error: when i changed propMap childPropName as customPropName

mlpushmenu.js:155 Uncaught TypeError: Cannot read property 'addEventListener' of null at eval (mlpushmenu.js:155) at Array.forEach (<anonymous>) at mlPushMenu._initEvents (mlpushmenu.js:151) at mlPushMenu._init (mlpushmenu.js:118) at new mlPushMenu (mlpushmenu.js:79) at PushMenu.componentDidMount (index.js:147) at commitLifeCycles (react-dom.development.js:22101) at commitLayoutEffects (react-dom.development.js:25344) at HTMLUnknownElement.callCallback (react-dom.development.js:336) at Object.invokeGuardedCallbackDev (react-dom.development.js:385)

data:
const a = { header: 'All Categories', childrenCate: [ { name: 'About', id: 1, link: '/about', childrenCate: [ {name: 'Mission', id: 11, link: null, childrenCate: []}, {name: 'Objectives', id: 12, link: null, childrenCate: []}, { name: 'Goals', id: 13, link: '/about/goals', childrenCate: [ {name: 'Charity', id: 131, link: null, childrenCate: []}, {name: 'Clean Environment Plan', id: 132, link: null, childrenCate: []}, ] } ] }, {name: 'Services', id: 2, link: '/services', childrenCate: []}, {name: 'People', id: 3, link: '/people', childrenCate: []}, {name: 'Careers', id: 4, link: '/careers', childrenCate: []}, {name: 'Contact', id: 5, link: null, childrenCate: []}, ] }

<PushMenu backIcon={<FaChevronLeft />} expanderComponent={FaChevronRight} onNodeClick={(e, {menu, node}) => { console.log(node) menu.tools.reset(); }} //linkComponent={LinkComponent} isOpen={true} nodes={ a } type={'overlap'} propMap={{ displayName: 'name', linkClasses: 'classes', expanderClasses: 'expClasses', childPropName: 'childrenCate', url: 'link'}}> <div className="rpm-trigger" id="rpm-trigger" > <FaBars /> </div> </PushMenu>

childPropName settings works only at the first level

It is expected that childPropName will work on entire tree. Instead it works only for the topmost element in data object for nodes.
It would be nice to make sure the rest of propMap settings work on entire tree.

Demo not working. Errors after installation

I expect following the docs in the example folder (npm install && npm start) would show the demo. Maybe you have to update them?

Also installing in my app I fall into some issues. ..like "react-items" are not included in the package.json but are used in the examples (why are they mandatory? Users should be able to choose their library.
or something like this error:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Are you willing to provide a codesandbox.io example?

thank you very much in advance

PS: Feature request: reverse sliding direction from right to left :-)

Installation Error

tried yarn add react-push-menu and failed with the postinstall script:

node_modules/react-push-menu: Command failed.
Exit code: 127
Command: install-peers -f && cd example && npm i
Arguments:

then tried with npm, npm install react-push-menu, got a bit insights:

npm ERR! [email protected] postinstall: `install-peers -f && cd example && npm i`
npm ERR! Exit status 1

sh: line 0: cd: example: No such file or directory

Why the example directory does not exit? And why do you force user to install the example app?

On starting: property 'string' of undefined

Hi,
What I do:
[react-icons v2.2.1]
yarn add react react-dom [email protected] --save (it doesn't work with newest version - they change icons loading, now they are in one file /index.js/!)
yarn add react-push-menu --save
After that I include everything the doc describe, but when add
import PushMenu from 'react-push-menu';
in one of my components the project return:
index.js:44 Uncaught TypeError: Cannot read property 'string' of undefined in the console!

index.js:44:
IconBase.propTypes = { color: _react.PropTypes.string, size: _react.PropTypes.oneOfType([_react.PropTypes.string, _react.PropTypes.number]), style: _react.PropTypes.object };

[react-icons v3+] You should edit
in: build/DefaultBackButton "require('react-icons/lib/fa/chevron-left');" --> require('react-icons/lib/fa');
in: build/index.js require('react-icons/lib/fa/chevron-right'); --> require('react-icons/lib/fa');
It is describe in react-icons doc

Thank's.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.