material-ui 0.7.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +31 -0
  6. data/Rakefile +20 -0
  7. data/lib/material-ui.rb +4 -0
  8. data/material-ui-gem.gemspec +33 -0
  9. data/vendor/assets/javascripts/material-ui.js +1 -0
  10. data/vendor/assets/javascripts/material-ui/components/app-bar.jsx +93 -0
  11. data/vendor/assets/javascripts/material-ui/components/app-canvas.jsx +27 -0
  12. data/vendor/assets/javascripts/material-ui/components/checkbox.jsx +60 -0
  13. data/vendor/assets/javascripts/material-ui/components/date-picker/calendar-month.jsx +59 -0
  14. data/vendor/assets/javascripts/material-ui/components/date-picker/calendar-toolbar.jsx +64 -0
  15. data/vendor/assets/javascripts/material-ui/components/date-picker/calendar.jsx +194 -0
  16. data/vendor/assets/javascripts/material-ui/components/date-picker/date-display.jsx +79 -0
  17. data/vendor/assets/javascripts/material-ui/components/date-picker/date-picker-dialog.jsx +118 -0
  18. data/vendor/assets/javascripts/material-ui/components/date-picker/date-picker.jsx +116 -0
  19. data/vendor/assets/javascripts/material-ui/components/date-picker/day-button.jsx +49 -0
  20. data/vendor/assets/javascripts/material-ui/components/dialog-window.jsx +183 -0
  21. data/vendor/assets/javascripts/material-ui/components/dialog.jsx +54 -0
  22. data/vendor/assets/javascripts/material-ui/components/drop-down-icon.jsx +68 -0
  23. data/vendor/assets/javascripts/material-ui/components/drop-down-menu.jsx +94 -0
  24. data/vendor/assets/javascripts/material-ui/components/enhanced-button.jsx +147 -0
  25. data/vendor/assets/javascripts/material-ui/components/enhanced-switch.jsx +296 -0
  26. data/vendor/assets/javascripts/material-ui/components/enhanced-textarea.jsx +113 -0
  27. data/vendor/assets/javascripts/material-ui/components/flat-button.jsx +46 -0
  28. data/vendor/assets/javascripts/material-ui/components/floating-action-button.jsx +123 -0
  29. data/vendor/assets/javascripts/material-ui/components/font-icon.jsx +23 -0
  30. data/vendor/assets/javascripts/material-ui/components/icon-button.jsx +123 -0
  31. data/vendor/assets/javascripts/material-ui/components/ink-bar.jsx +25 -0
  32. data/vendor/assets/javascripts/material-ui/components/input.jsx +143 -0
  33. data/vendor/assets/javascripts/material-ui/components/left-nav.jsx +105 -0
  34. data/vendor/assets/javascripts/material-ui/components/menu/link-menu-item.jsx +42 -0
  35. data/vendor/assets/javascripts/material-ui/components/menu/menu-item.jsx +105 -0
  36. data/vendor/assets/javascripts/material-ui/components/menu/menu.jsx +325 -0
  37. data/vendor/assets/javascripts/material-ui/components/menu/subheader-menu-item.jsx +18 -0
  38. data/vendor/assets/javascripts/material-ui/components/mixins/classable.js +42 -0
  39. data/vendor/assets/javascripts/material-ui/components/mixins/click-awayable.js +35 -0
  40. data/vendor/assets/javascripts/material-ui/components/mixins/window-listenable.js +23 -0
  41. data/vendor/assets/javascripts/material-ui/components/overlay.jsx +58 -0
  42. data/vendor/assets/javascripts/material-ui/components/paper.jsx +58 -0
  43. data/vendor/assets/javascripts/material-ui/components/radio-button-group.jsx +112 -0
  44. data/vendor/assets/javascripts/material-ui/components/radio-button.jsx +65 -0
  45. data/vendor/assets/javascripts/material-ui/components/raised-button.jsx +102 -0
  46. data/vendor/assets/javascripts/material-ui/components/ripples/circle.jsx +35 -0
  47. data/vendor/assets/javascripts/material-ui/components/ripples/focus-ripple.jsx +40 -0
  48. data/vendor/assets/javascripts/material-ui/components/ripples/touch-ripple.jsx +174 -0
  49. data/vendor/assets/javascripts/material-ui/components/slider.jsx +178 -0
  50. data/vendor/assets/javascripts/material-ui/components/snackbar.jsx +76 -0
  51. data/vendor/assets/javascripts/material-ui/components/svg-icons/drop-down-arrow.jsx +16 -0
  52. data/vendor/assets/javascripts/material-ui/components/svg-icons/navigation-chevron-left.jsx +16 -0
  53. data/vendor/assets/javascripts/material-ui/components/svg-icons/navigation-chevron-right.jsx +17 -0
  54. data/vendor/assets/javascripts/material-ui/components/svg-icons/navigation-menu.jsx +16 -0
  55. data/vendor/assets/javascripts/material-ui/components/svg-icons/svg-icon.jsx +23 -0
  56. data/vendor/assets/javascripts/material-ui/components/svg-icons/toggle-check-box-checked.jsx +16 -0
  57. data/vendor/assets/javascripts/material-ui/components/svg-icons/toggle-check-box-outline-blank.jsx +16 -0
  58. data/vendor/assets/javascripts/material-ui/components/svg-icons/toggle-radio-button-off.jsx +16 -0
  59. data/vendor/assets/javascripts/material-ui/components/svg-icons/toggle-radio-button-on.jsx +16 -0
  60. data/vendor/assets/javascripts/material-ui/components/table-header.jsx +50 -0
  61. data/vendor/assets/javascripts/material-ui/components/table-rows-item.jsx +31 -0
  62. data/vendor/assets/javascripts/material-ui/components/table-rows.jsx +57 -0
  63. data/vendor/assets/javascripts/material-ui/components/tabs/tab.jsx +38 -0
  64. data/vendor/assets/javascripts/material-ui/components/tabs/tabTemplate.jsx +15 -0
  65. data/vendor/assets/javascripts/material-ui/components/tabs/tabs.jsx +96 -0
  66. data/vendor/assets/javascripts/material-ui/components/text-field.jsx +215 -0
  67. data/vendor/assets/javascripts/material-ui/components/toggle.jsx +62 -0
  68. data/vendor/assets/javascripts/material-ui/components/toolbar-group.jsx +28 -0
  69. data/vendor/assets/javascripts/material-ui/components/toolbar.jsx +21 -0
  70. data/vendor/assets/javascripts/material-ui/components/tooltip.jsx +58 -0
  71. data/vendor/assets/javascripts/material-ui/components/transition-groups/slide-in.jsx +48 -0
  72. data/vendor/assets/javascripts/material-ui/components/utils/css-event.js +52 -0
  73. data/vendor/assets/javascripts/material-ui/components/utils/date-time.js +132 -0
  74. data/vendor/assets/javascripts/material-ui/components/utils/dom.js +71 -0
  75. data/vendor/assets/javascripts/material-ui/components/utils/events.js +34 -0
  76. data/vendor/assets/javascripts/material-ui/components/utils/key-code.js +10 -0
  77. data/vendor/assets/javascripts/material-ui/components/utils/key-line.js +13 -0
  78. data/vendor/assets/javascripts/material-ui/components/utils/unique-id.js +7 -0
  79. data/vendor/assets/stylesheets/material-ui.less +2 -0
  80. data/vendor/assets/stylesheets/material-ui/components.less +5 -0
  81. data/vendor/assets/stylesheets/material-ui/components/app-bar.less +37 -0
  82. data/vendor/assets/stylesheets/material-ui/components/card.less +20 -0
  83. data/vendor/assets/stylesheets/material-ui/components/checkbox.less +66 -0
  84. data/vendor/assets/stylesheets/material-ui/components/components.less +37 -0
  85. data/vendor/assets/stylesheets/material-ui/components/date-picker/calendar-month.less +11 -0
  86. data/vendor/assets/stylesheets/material-ui/components/date-picker/calendar-toolbar.less +23 -0
  87. data/vendor/assets/stylesheets/material-ui/components/date-picker/calendar.less +59 -0
  88. data/vendor/assets/stylesheets/material-ui/components/date-picker/date-display.less +84 -0
  89. data/vendor/assets/stylesheets/material-ui/components/date-picker/date-picker-dialog.less +18 -0
  90. data/vendor/assets/stylesheets/material-ui/components/date-picker/date-picker.less +9 -0
  91. data/vendor/assets/stylesheets/material-ui/components/date-picker/day-button.less +35 -0
  92. data/vendor/assets/stylesheets/material-ui/components/dialog-window.less +42 -0
  93. data/vendor/assets/stylesheets/material-ui/components/dialog.less +10 -0
  94. data/vendor/assets/stylesheets/material-ui/components/drop-down-icon.less +43 -0
  95. data/vendor/assets/stylesheets/material-ui/components/drop-down-menu.less +77 -0
  96. data/vendor/assets/stylesheets/material-ui/components/enhanced-button.less +24 -0
  97. data/vendor/assets/stylesheets/material-ui/components/enhanced-switch.less +52 -0
  98. data/vendor/assets/stylesheets/material-ui/components/enhanced-textarea.less +16 -0
  99. data/vendor/assets/stylesheets/material-ui/components/flat-button.less +93 -0
  100. data/vendor/assets/stylesheets/material-ui/components/floating-action-button.less +95 -0
  101. data/vendor/assets/stylesheets/material-ui/components/font-icon.less +6 -0
  102. data/vendor/assets/stylesheets/material-ui/components/icon-button.less +46 -0
  103. data/vendor/assets/stylesheets/material-ui/components/ink-bar.less +9 -0
  104. data/vendor/assets/stylesheets/material-ui/components/input.less +186 -0
  105. data/vendor/assets/stylesheets/material-ui/components/left-nav.less +31 -0
  106. data/vendor/assets/stylesheets/material-ui/components/menu-item.less +69 -0
  107. data/vendor/assets/stylesheets/material-ui/components/menu.less +50 -0
  108. data/vendor/assets/stylesheets/material-ui/components/overlay.less +21 -0
  109. data/vendor/assets/stylesheets/material-ui/components/paper.less +59 -0
  110. data/vendor/assets/stylesheets/material-ui/components/radio-button.less +67 -0
  111. data/vendor/assets/stylesheets/material-ui/components/raised-button.less +132 -0
  112. data/vendor/assets/stylesheets/material-ui/components/ripples/circle.less +31 -0
  113. data/vendor/assets/stylesheets/material-ui/components/ripples/focus-ripple.less +30 -0
  114. data/vendor/assets/stylesheets/material-ui/components/ripples/touch-ripple.less +9 -0
  115. data/vendor/assets/stylesheets/material-ui/components/slider.less +163 -0
  116. data/vendor/assets/stylesheets/material-ui/components/snackbar.less +44 -0
  117. data/vendor/assets/stylesheets/material-ui/components/subheader.less +17 -0
  118. data/vendor/assets/stylesheets/material-ui/components/svg-icon.less +11 -0
  119. data/vendor/assets/stylesheets/material-ui/components/table.less +46 -0
  120. data/vendor/assets/stylesheets/material-ui/components/tabs.less +41 -0
  121. data/vendor/assets/stylesheets/material-ui/components/text-field.less +168 -0
  122. data/vendor/assets/stylesheets/material-ui/components/toggle.less +83 -0
  123. data/vendor/assets/stylesheets/material-ui/components/toolbar.less +95 -0
  124. data/vendor/assets/stylesheets/material-ui/components/tooltip.less +73 -0
  125. data/vendor/assets/stylesheets/material-ui/components/transition-groups/slide-in.less +92 -0
  126. data/vendor/assets/stylesheets/material-ui/core/base.less +31 -0
  127. data/vendor/assets/stylesheets/material-ui/core/core.less +4 -0
  128. data/vendor/assets/stylesheets/material-ui/core/keylines.less +29 -0
  129. data/vendor/assets/stylesheets/material-ui/core/layouts.less +12 -0
  130. data/vendor/assets/stylesheets/material-ui/core/typography.less +158 -0
  131. data/vendor/assets/stylesheets/material-ui/mixins/clearfix.less +22 -0
  132. data/vendor/assets/stylesheets/material-ui/mixins/mixins.less +3 -0
  133. data/vendor/assets/stylesheets/material-ui/mixins/no-wrap.less +3 -0
  134. data/vendor/assets/stylesheets/material-ui/mixins/transitions.less +17 -0
  135. data/vendor/assets/stylesheets/material-ui/resets/normalize.css +430 -0
  136. data/vendor/assets/stylesheets/material-ui/resets/typography-resets.less +34 -0
  137. data/vendor/assets/stylesheets/material-ui/scaffolding.less +10 -0
  138. data/vendor/assets/stylesheets/material-ui/variables/colors.less +285 -0
  139. data/vendor/assets/stylesheets/material-ui/variables/custom-variables.less +163 -0
  140. data/vendor/assets/stylesheets/material-ui/variables/media-queries.less +4 -0
  141. data/vendor/assets/stylesheets/material-ui/variables/spacing.less +16 -0
  142. metadata +268 -0
@@ -0,0 +1,105 @@
1
+ var React = require('react'),
2
+ KeyCode = require('./utils/key-code'),
3
+ Classable = require('./mixins/classable'),
4
+ WindowListenable = require('./mixins/window-listenable'),
5
+ Overlay = require('./overlay'),
6
+ Paper = require('./paper'),
7
+ Menu = require('./menu/menu');
8
+
9
+ var LeftNav = React.createClass({
10
+
11
+ mixins: [Classable, WindowListenable],
12
+
13
+ propTypes: {
14
+ docked: React.PropTypes.bool,
15
+ header: React.PropTypes.element,
16
+ onChange: React.PropTypes.func,
17
+ menuItems: React.PropTypes.array.isRequired,
18
+ selectedIndex: React.PropTypes.number
19
+ },
20
+
21
+ windowListeners: {
22
+ 'keyup': '_onWindowKeyUp'
23
+ },
24
+
25
+ getDefaultProps: function() {
26
+ return {
27
+ docked: true
28
+ };
29
+ },
30
+
31
+ getInitialState: function() {
32
+ return {
33
+ open: this.props.docked
34
+ };
35
+ },
36
+
37
+ toggle: function() {
38
+ this.setState({ open: !this.state.open });
39
+ return this;
40
+ },
41
+
42
+ close: function() {
43
+ this.setState({ open: false });
44
+ return this;
45
+ },
46
+
47
+ open: function() {
48
+ this.setState({ open: true });
49
+ return this;
50
+ },
51
+
52
+ render: function() {
53
+ var classes = this.getClasses('mui-left-nav', {
54
+ 'mui-closed': !this.state.open
55
+ }),
56
+ selectedIndex = this.props.selectedIndex,
57
+ overlay;
58
+
59
+ if (!this.props.docked) overlay = <Overlay show={this.state.open} onTouchTap={this._onOverlayTouchTap} />;
60
+
61
+ return (
62
+ <div className={classes}>
63
+
64
+ {overlay}
65
+ <Paper
66
+ ref="clickAwayableElement"
67
+ className="mui-left-nav-menu"
68
+ zDepth={2}
69
+ rounded={false}>
70
+
71
+ {this.props.header}
72
+ <Menu
73
+ ref="menuItems"
74
+ zDepth={0}
75
+ menuItems={this.props.menuItems}
76
+ selectedIndex={selectedIndex}
77
+ onItemClick={this._onMenuItemClick} />
78
+
79
+ </Paper>
80
+ </div>
81
+ );
82
+ },
83
+
84
+ _onMenuItemClick: function(e, key, payload) {
85
+ if (this.props.onChange && this.props.selectedIndex !== key) {
86
+ this.props.onChange(e, key, payload);
87
+ }
88
+ if (!this.props.docked) this.close();
89
+ },
90
+
91
+ _onOverlayTouchTap: function() {
92
+ this.close();
93
+ },
94
+
95
+ _onWindowKeyUp: function(e) {
96
+ if (e.keyCode == KeyCode.ESC &&
97
+ !this.props.docked &&
98
+ this.state.open) {
99
+ this.close();
100
+ }
101
+ }
102
+
103
+ });
104
+
105
+ module.exports = LeftNav;
@@ -0,0 +1,42 @@
1
+ var React = require('react');
2
+ var Classable = require('../mixins/classable');
3
+
4
+ var LinkMenuItem = React.createClass({
5
+
6
+ mixins: [Classable],
7
+
8
+ propTypes: {
9
+ index: React.PropTypes.number.isRequired,
10
+ payload: React.PropTypes.string.isRequired,
11
+ text: React.PropTypes.string.isRequired,
12
+ target: React.PropTypes.string,
13
+ disabled: React.PropTypes.bool
14
+ },
15
+
16
+ getDefaultProps: function() {
17
+ return {
18
+ disabled: false
19
+ };
20
+ },
21
+
22
+ render: function() {
23
+ var classes = this.getClasses('mui-menu-item', {
24
+ 'mui-is-disabled': this.props.disabled
25
+ });
26
+ var onClickHandler = (this.props.disabled) ? this._stopLink : undefined;
27
+ // Prevent context menu 'Open In New Tab/Window'
28
+ var linkAttribute = (this.props.disabled) ? 'data-href' : 'href';
29
+ var link = {};
30
+ link[linkAttribute] = this.props.payload
31
+
32
+ return (
33
+ <a key={this.props.index} className={classes} {...link} target={this.props.target} onClick={onClickHandler}>{this.props.text}</a>
34
+ );
35
+ },
36
+
37
+ _stopLink: function(event) {
38
+ event.preventDefault();
39
+ }
40
+ });
41
+
42
+ module.exports = LinkMenuItem;
@@ -0,0 +1,105 @@
1
+ var React = require('react');
2
+ var Classable = require('../mixins/classable');
3
+ var FontIcon = require('../font-icon');
4
+ var Toggle = require('../toggle');
5
+
6
+ var Types = {
7
+ LINK: 'LINK',
8
+ SUBHEADER: 'SUBHEADER',
9
+ NESTED: 'NESTED'
10
+ };
11
+
12
+ var MenuItem = React.createClass({
13
+
14
+ mixins: [Classable],
15
+
16
+ propTypes: {
17
+ index: React.PropTypes.number.isRequired,
18
+ iconClassName: React.PropTypes.string,
19
+ iconRightClassName: React.PropTypes.string,
20
+ attribute: React.PropTypes.string,
21
+ number: React.PropTypes.string,
22
+ data: React.PropTypes.string,
23
+ toggle: React.PropTypes.bool,
24
+ disabled: React.PropTypes.bool,
25
+ onTouchTap: React.PropTypes.func,
26
+ onClick: React.PropTypes.func,
27
+ onToggle: React.PropTypes.func,
28
+ selected: React.PropTypes.bool
29
+ },
30
+
31
+ statics: {
32
+ Types: Types
33
+ },
34
+
35
+ getDefaultProps: function() {
36
+ return {
37
+ toggle: false,
38
+ disabled: false
39
+ };
40
+ },
41
+
42
+ render: function() {
43
+ var classes = this.getClasses('mui-menu-item', {
44
+ 'mui-is-selected': this.props.selected,
45
+ 'mui-is-disabled': this.props.disabled
46
+ });
47
+ var icon;
48
+ var data;
49
+ var iconRight;
50
+ var attribute;
51
+ var number;
52
+ var toggle;
53
+
54
+ if (this.props.iconClassName) icon = <FontIcon className={'mui-menu-item-icon ' + this.props.iconClassName} />;
55
+ if (this.props.iconRightClassName) iconRight = <FontIcon className={'mui-menu-item-icon-right ' + this.props.iconRightClassName} />;
56
+ if (this.props.data) data = <span className="mui-menu-item-data">{this.props.data}</span>;
57
+ if (this.props.number !== undefined) number = <span className="mui-menu-item-number">{this.props.number}</span>;
58
+ if (this.props.attribute !== undefined) attribute = <span className="mui-menu-item-attribute">{this.props.attribute}</span>;
59
+
60
+ if (this.props.toggle) {
61
+ var {
62
+ toggle,
63
+ onClick,
64
+ onToggle,
65
+ children,
66
+ label,
67
+ ...other
68
+ } = this.props;
69
+ toggle = <Toggle {...other} onToggle={this._handleToggle}/>;
70
+ }
71
+
72
+ return (
73
+ <div
74
+ key={this.props.index}
75
+ className={classes}
76
+ onTouchTap={this._handleTouchTap}
77
+ onClick={this._handleOnClick}>
78
+
79
+ {icon}
80
+ {this.props.children}
81
+ {data}
82
+ {attribute}
83
+ {number}
84
+ {toggle}
85
+ {iconRight}
86
+
87
+ </div>
88
+ );
89
+ },
90
+
91
+ _handleTouchTap: function(e) {
92
+ if (!this.props.disabled && this.props.onTouchTap) this.props.onTouchTap(e, this.props.index);
93
+ },
94
+
95
+ _handleOnClick: function(e) {
96
+ if (!this.props.disabled && this.props.onClick) this.props.onClick(e, this.props.index);
97
+ },
98
+
99
+ _handleToggle: function(e, toggled) {
100
+ if (!this.props.disabled && this.props.onToggle) this.props.onToggle(e, this.props.index, toggled);
101
+ }
102
+
103
+ });
104
+
105
+ module.exports = MenuItem;
@@ -0,0 +1,325 @@
1
+ var React = require('react');
2
+ var CssEvent = require('../utils/css-event');
3
+ var Dom = require('../utils/dom');
4
+ var KeyLine = require('../utils/key-line');
5
+ var Classable = require('../mixins/classable');
6
+ var ClickAwayable = require('../mixins/click-awayable');
7
+ var Paper = require('../paper');
8
+ var MenuItem = require('./menu-item');
9
+ var LinkMenuItem = require('./link-menu-item');
10
+ var SubheaderMenuItem = require('./subheader-menu-item');
11
+
12
+ /***********************
13
+ * Nested Menu Component
14
+ ***********************/
15
+ var NestedMenuItem = React.createClass({
16
+
17
+ mixins: [Classable, ClickAwayable],
18
+
19
+ propTypes: {
20
+ index: React.PropTypes.number.isRequired,
21
+ text: React.PropTypes.string,
22
+ menuItems: React.PropTypes.array.isRequired,
23
+ zDepth: React.PropTypes.number,
24
+ disabled: React.PropTypes.bool,
25
+ onItemClick: React.PropTypes.func,
26
+ onItemTap: React.PropTypes.func
27
+ },
28
+
29
+ getDefaultProps: function() {
30
+ return {
31
+ disabled: false
32
+ };
33
+ },
34
+
35
+ getInitialState: function() {
36
+ return { open: false }
37
+ },
38
+
39
+ componentClickAway: function() {
40
+ this._closeNestedMenu();
41
+ },
42
+
43
+ componentDidMount: function() {
44
+ this._positionNestedMenu();
45
+ },
46
+
47
+ componentDidUpdate: function(prevProps, prevState) {
48
+ this._positionNestedMenu();
49
+ },
50
+
51
+ render: function() {
52
+ var classes = this.getClasses('mui-nested-menu-item', {
53
+ 'mui-open': this.state.open,
54
+ 'mui-is-disabled': this.props.disabled
55
+ });
56
+
57
+ return (
58
+ <div className={classes} onMouseEnter={this._openNestedMenu} onMouseLeave={this._closeNestedMenu}>
59
+ <MenuItem index={this.props.index} disabled={this.props.disabled} iconRightClassName="muidocs-icon-custom-arrow-drop-right" onClick={this._onParentItemClick}>
60
+ {this.props.text}
61
+ </MenuItem>
62
+ <Menu
63
+ ref="nestedMenu"
64
+ menuItems={this.props.menuItems}
65
+ onItemClick={this._onMenuItemClick}
66
+ onItemTap={this._onMenuItemTap}
67
+ hideable={true}
68
+ visible={this.state.open}
69
+ zDepth={this.props.zDepth + 1} />
70
+ </div>
71
+ );
72
+ },
73
+
74
+ _positionNestedMenu: function() {
75
+ var el = this.getDOMNode(),
76
+ nestedMenu = this.refs.nestedMenu.getDOMNode();
77
+
78
+ nestedMenu.style.left = el.offsetWidth + 'px';
79
+ },
80
+
81
+ _openNestedMenu: function() {
82
+ if (!this.props.disabled) this.setState({ open: true });
83
+ },
84
+
85
+ _closeNestedMenu: function() {
86
+ this.setState({ open: false });
87
+ },
88
+
89
+ _toggleNestedMenu: function() {
90
+ if (!this.props.disabled) this.setState({ open: !this.state.open });
91
+ },
92
+
93
+ _onParentItemClick: function() {
94
+ this._toggleNestedMenu();
95
+ },
96
+
97
+ _onMenuItemClick: function(e, index, menuItem) {
98
+ if (this.props.onItemClick) this.props.onItemClick(e, index, menuItem);
99
+ this._closeNestedMenu();
100
+ },
101
+
102
+ _onMenuItemTap: function(e, index, menuItem) {
103
+ if (this.props.onItemTap) this.props.onItemTap(e, index, menuItem);
104
+ this._closeNestedMenu();
105
+ }
106
+
107
+ });
108
+
109
+
110
+ /****************
111
+ * Menu Component
112
+ ****************/
113
+ var Menu = React.createClass({
114
+
115
+ mixins: [Classable],
116
+
117
+ propTypes: {
118
+ autoWidth: React.PropTypes.bool,
119
+ onItemTap: React.PropTypes.func,
120
+ onItemClick: React.PropTypes.func,
121
+ onToggleClick: React.PropTypes.func,
122
+ menuItems: React.PropTypes.array.isRequired,
123
+ selectedIndex: React.PropTypes.number,
124
+ hideable: React.PropTypes.bool,
125
+ visible: React.PropTypes.bool,
126
+ zDepth: React.PropTypes.number
127
+ },
128
+
129
+ getInitialState: function() {
130
+ return { nestedMenuShown: false }
131
+ },
132
+
133
+ getDefaultProps: function() {
134
+ return {
135
+ autoWidth: true,
136
+ hideable: false,
137
+ visible: true,
138
+ zDepth: 1
139
+ };
140
+ },
141
+
142
+ componentDidMount: function() {
143
+ var el = this.getDOMNode();
144
+
145
+ //Set the menu with
146
+ this._setKeyWidth(el);
147
+
148
+ //Save the initial menu height for later
149
+ this._initialMenuHeight = el.offsetHeight + KeyLine.Desktop.GUTTER_LESS;
150
+
151
+ //Show or Hide the menu according to visibility
152
+ this._renderVisibility();
153
+ },
154
+
155
+ componentDidUpdate: function(prevProps, prevState) {
156
+ if (this.props.visible !== prevProps.visible) this._renderVisibility();
157
+ },
158
+
159
+ render: function() {
160
+ var classes = this.getClasses('mui-menu', {
161
+ 'mui-menu-hideable': this.props.hideable,
162
+ 'mui-visible': this.props.visible
163
+ });
164
+
165
+ return (
166
+ <Paper ref="paperContainer" zDepth={this.props.zDepth} className={classes}>
167
+ {this._getChildren()}
168
+ </Paper>
169
+ );
170
+ },
171
+
172
+ _getChildren: function() {
173
+ var children = [],
174
+ menuItem,
175
+ itemComponent,
176
+ isSelected,
177
+ isDisabled;
178
+
179
+ //This array is used to keep track of all nested menu refs
180
+ this._nestedChildren = [];
181
+
182
+ for (var i=0; i < this.props.menuItems.length; i++) {
183
+ menuItem = this.props.menuItems[i];
184
+ isSelected = i === this.props.selectedIndex;
185
+ isDisabled = (menuItem.disabled === undefined) ? false : menuItem.disabled;
186
+
187
+ var {
188
+ icon,
189
+ data,
190
+ attribute,
191
+ number,
192
+ toggle,
193
+ onClick,
194
+ ...other
195
+ } = menuItem;
196
+
197
+ switch (menuItem.type) {
198
+
199
+ case MenuItem.Types.LINK:
200
+ itemComponent = (
201
+ <LinkMenuItem
202
+ key={i}
203
+ index={i}
204
+ payload={menuItem.payload}
205
+ target={menuItem.target}
206
+ text={menuItem.text}
207
+ disabled={isDisabled} />
208
+ );
209
+ break;
210
+
211
+ case MenuItem.Types.SUBHEADER:
212
+ itemComponent = (
213
+ <SubheaderMenuItem
214
+ key={i}
215
+ index={i}
216
+ text={menuItem.text} />
217
+ );
218
+ break;
219
+
220
+ case MenuItem.Types.NESTED:
221
+ itemComponent = (
222
+ <NestedMenuItem
223
+ ref={i}
224
+ key={i}
225
+ index={i}
226
+ text={menuItem.text}
227
+ disabled={isDisabled}
228
+ menuItems={menuItem.items}
229
+ zDepth={this.props.zDepth}
230
+ onItemClick={this._onNestedItemClick}
231
+ onItemTap={this._onNestedItemClick} />
232
+ );
233
+ this._nestedChildren.push(i);
234
+ break;
235
+
236
+ default:
237
+ itemComponent = (
238
+ <MenuItem
239
+ {...other}
240
+ selected={isSelected}
241
+ key={i}
242
+ index={i}
243
+ icon={menuItem.icon}
244
+ data={menuItem.data}
245
+ attribute={menuItem.attribute}
246
+ number={menuItem.number}
247
+ toggle={menuItem.toggle}
248
+ disabled={isDisabled}
249
+ onClick={this._onItemClick}
250
+ onTouchTap={this._onItemTap}>
251
+ {menuItem.text}
252
+ </MenuItem>
253
+ );
254
+ }
255
+ children.push(itemComponent);
256
+ }
257
+
258
+ return children;
259
+ },
260
+
261
+ _setKeyWidth: function(el) {
262
+ var menuWidth = this.props.autoWidth ?
263
+ KeyLine.getIncrementalDim(el.offsetWidth) + 'px' :
264
+ '100%';
265
+
266
+ //Update the menu width
267
+ Dom.withoutTransition(el, function() {
268
+ el.style.width = menuWidth;
269
+ });
270
+ },
271
+
272
+ _renderVisibility: function() {
273
+ var el;
274
+
275
+ if (this.props.hideable) {
276
+ el = this.getDOMNode();
277
+ var innerContainer = this.refs.paperContainer.getInnerContainer().getDOMNode();
278
+
279
+ if (this.props.visible) {
280
+
281
+ //Open the menu
282
+ el.style.height = this._initialMenuHeight + 'px';
283
+
284
+ //Set the overflow to visible after the animation is done so
285
+ //that other nested menus can be shown
286
+ CssEvent.onTransitionEnd(el, function() {
287
+ //Make sure the menu is open before setting the overflow.
288
+ //This is to accout for fast clicks
289
+ if (this.props.visible) innerContainer.style.overflow = 'visible';
290
+ }.bind(this));
291
+
292
+ } else {
293
+
294
+ //Close the menu
295
+ el.style.height = '0px';
296
+
297
+ //Set the overflow to hidden so that animation works properly
298
+ innerContainer.style.overflow = 'hidden';
299
+ }
300
+ }
301
+ },
302
+
303
+ _onNestedItemClick: function(e, index, menuItem) {
304
+ if (this.props.onItemClick) this.props.onItemClick(e, index, menuItem);
305
+ },
306
+
307
+ _onNestedItemTap: function(e, index, menuItem) {
308
+ if (this.props.onItemTap) this.props.onItemTap(e, index, menuItem);
309
+ },
310
+
311
+ _onItemClick: function(e, index) {
312
+ if (this.props.onItemClick) this.props.onItemClick(e, index, this.props.menuItems[index]);
313
+ },
314
+
315
+ _onItemTap: function(e, index) {
316
+ if (this.props.onItemTap) this.props.onItemTap(e, index, this.props.menuItems[index]);
317
+ },
318
+
319
+ _onItemToggle: function(e, index, toggled) {
320
+ if (this.props.onItemToggle) this.props.onItemToggle(e, index, this.props.menuItems[index], toggled);
321
+ }
322
+
323
+ });
324
+
325
+ module.exports = Menu;