menu

v0.9.6arrow_drop_down
v0.9.6
STATUS
Passing
DOWNLOADS
2,355
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
4 months ago
subject
Our flexible menu component makes it easy to build many common navigation patterns, all with the same markup.
Like
Use menu in your project ?
Copied
npm i @bit/digiaonline.react-foundation.menu
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
components/menu.js
83 Lines(55 sloc)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React from 'react';
import PropTypes from 'prop-types';
import { MenuAlignments } from '../enums';
import { GeneralPropTypes, FlexboxPropTypes, createClassName, generalClassNames, removeProps, objectKeys, objectValues } from '../utils';

/**
 * Menu component.
 * http://foundation.zurb.com/sites/docs/menu.html
 *
 * @param {Object} props
 * @returns {Object}
 */
export const Menu = (props) => {
  const className = createClassName(
    props.noDefaultClassName ? null : 'menu',
    props.className,
    {
      'align-right': props.alignment === MenuAlignments.RIGHT,
      'align-center': props.alignment === MenuAlignments.CENTER,
      'icon-top': props.iconsOnTop,
      'expanded': props.isExpanded,
      'vertical': props.isVertical,
      'simple': props.isSimple,
      'nested': props.isNested,
      'dropdown': props.isDropdown,
      'medium-horizontal': props.horizontalOnMedium
    },
    generalClassNames(props)
  );

  const passProps = removeProps(props, objectKeys(Menu.propTypes));

  return <ul {...passProps} className={className}/>;
};

Menu.propTypes = {
  ...GeneralPropTypes,
  ...FlexboxPropTypes,
  alignment: PropTypes.oneOf(objectValues(MenuAlignments)),
  iconsOnTop: PropTypes.bool,
  isExpanded: PropTypes.bool,
  isVertical: PropTypes.bool,
  isDropdown: PropTypes.bool,
  isSimple: PropTypes.bool,
  isNested: PropTypes.bool,
  horizontalOnMedium: PropTypes.bool
};

/**
 * Menu item component.
 *
 * @param {Object} props
 * @returns {Object}
 */
export const MenuItem = (props) => {
  const className = createClassName(
    props.className,
    {
      'active': props.isActive
    },
    generalClassNames(props)
  );

  const passProps = removeProps(props, objectKeys(MenuItem.propTypes));

  return <li {...passProps} className={className}/>;
};

MenuItem.propTypes = {
  ...GeneralPropTypes,
  ...FlexboxPropTypes,
  isActive: PropTypes.bool
};

/**
 * Menu text wrapper-component.
 *
 * @param {Object} props
 * @returns {XML}
 */
export const MenuText = (props) => (
  <MenuItem {...props} className={props.className || 'menu-text'}/>
);