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,49 @@
1
+ var React = require('react');
2
+ var Classable = require('../mixins/classable');
3
+ var DateTime = require('../utils/date-time');
4
+ var EnhancedButton = require('../enhanced-button');
5
+
6
+ var DayButton = React.createClass({
7
+
8
+ mixins: [Classable],
9
+
10
+ propTypes: {
11
+ date: React.PropTypes.object,
12
+ onTouchTap: React.PropTypes.func,
13
+ selected: React.PropTypes.bool
14
+ },
15
+
16
+ render: function() {
17
+ var {
18
+ className,
19
+ date,
20
+ onTouchTap,
21
+ selected,
22
+ ...other
23
+ } = this.props;
24
+ var classes = this.getClasses('mui-date-picker-day-button', {
25
+ 'mui-is-current-date': DateTime.isEqualDate(this.props.date, new Date()),
26
+ 'mui-is-selected': this.props.selected
27
+ });
28
+
29
+ return this.props.date ? (
30
+ <EnhancedButton {...other}
31
+ className={classes}
32
+ disableFocusRipple={true}
33
+ disableTouchRipple={true}
34
+ onTouchTap={this._handleTouchTap}>
35
+ <div className="mui-date-picker-day-button-select" />
36
+ <span className="mui-date-picker-day-button-label">{this.props.date.getDate()}</span>
37
+ </EnhancedButton>
38
+ ) : (
39
+ <span className={classes} />
40
+ );
41
+ },
42
+
43
+ _handleTouchTap: function(e) {
44
+ if (this.props.onTouchTap) this.props.onTouchTap(e, this.props.date);
45
+ }
46
+
47
+ });
48
+
49
+ module.exports = DayButton;
@@ -0,0 +1,183 @@
1
+ var React = require('react');
2
+ var WindowListenable = require('./mixins/window-listenable');
3
+ var CssEvent = require('./utils/css-event');
4
+ var KeyCode = require('./utils/key-code');
5
+ var Classable = require('./mixins/classable');
6
+ var FlatButton = require('./flat-button');
7
+ var Overlay = require('./overlay');
8
+ var Paper = require('./paper');
9
+
10
+ var DialogWindow = React.createClass({
11
+
12
+ mixins: [Classable, WindowListenable],
13
+
14
+ propTypes: {
15
+ actions: React.PropTypes.array,
16
+ contentClassName: React.PropTypes.string,
17
+ openImmediately: React.PropTypes.bool,
18
+ onClickAway: React.PropTypes.func,
19
+ onDismiss: React.PropTypes.func,
20
+ onShow: React.PropTypes.func,
21
+ repositionOnUpdate: React.PropTypes.bool
22
+ },
23
+
24
+ windowListeners: {
25
+ 'keyup': '_handleWindowKeyUp'
26
+ },
27
+
28
+ getDefaultProps: function() {
29
+ return {
30
+ actions: [],
31
+ repositionOnUpdate: true
32
+ };
33
+ },
34
+
35
+ getInitialState: function() {
36
+ return {
37
+ open: this.props.openImmediately || false
38
+ };
39
+ },
40
+
41
+ componentDidMount: function() {
42
+ this._positionDialog();
43
+ if (this.props.openImmediately) {
44
+ this.refs.dialogOverlay.preventScrolling();
45
+ this._onShow();
46
+ }
47
+ },
48
+
49
+ componentDidUpdate: function (prevProps, prevState) {
50
+ this._positionDialog();
51
+ },
52
+
53
+ render: function() {
54
+ var classes = this.getClasses('mui-dialog-window', {
55
+ 'mui-is-shown': this.state.open
56
+ });
57
+ var contentClasses = 'mui-dialog-window-contents';
58
+ var actions = this._getActionsContainer(this.props.actions);
59
+
60
+ if (this.props.contentClassName) {
61
+ contentClasses += ' ' + this.props.contentClassName;
62
+ }
63
+
64
+ return (
65
+ <div className={classes}>
66
+ <Paper ref="dialogWindow" className={contentClasses} zDepth={4}>
67
+ {this.props.children}
68
+ {actions}
69
+ </Paper>
70
+ <Overlay ref="dialogOverlay" show={this.state.open} autoLockScrolling={false} onTouchTap={this._handleOverlayTouchTap} />
71
+ </div>
72
+ );
73
+ },
74
+
75
+ isOpen: function() {
76
+ return this.state.open;
77
+ },
78
+
79
+ dismiss: function() {
80
+ CssEvent.onTransitionEnd(this.getDOMNode(), function() {
81
+ this.refs.dialogOverlay.allowScrolling();
82
+ }.bind(this));
83
+
84
+ this.setState({ open: false });
85
+ this._onDismiss();
86
+ },
87
+
88
+ show: function() {
89
+ this.refs.dialogOverlay.preventScrolling();
90
+
91
+ this.setState({ open: true });
92
+ this._onShow();
93
+ },
94
+
95
+ _addClassName: function(reactObject, className) {
96
+ var originalClassName = reactObject.props.className;
97
+
98
+ reactObject.props.className = originalClassName ?
99
+ originalClassName + ' ' + className : className;
100
+ },
101
+
102
+ _getAction: function(actionJSON, key) {
103
+ var onClickHandler = actionJSON.onClick ? actionJSON.onClick : this.dismiss;
104
+ return (
105
+ <FlatButton
106
+ key={key}
107
+ secondary={true}
108
+ onClick={onClickHandler}
109
+ label={actionJSON.text} />
110
+ );
111
+ },
112
+
113
+ _getActionsContainer: function(actions) {
114
+ var actionContainer;
115
+ var actionObjects = [];
116
+
117
+ if (actions.length) {
118
+ for (var i = 0; i < actions.length; i++) {
119
+ currentAction = actions[i];
120
+
121
+ //if the current action isn't a react object, create one
122
+ if (!React.isValidElement(currentAction)) {
123
+ currentAction = this._getAction(currentAction, i);
124
+ }
125
+
126
+ this._addClassName(currentAction, 'mui-dialog-window-action');
127
+ actionObjects.push(currentAction);
128
+ };
129
+
130
+ actionContainer = (
131
+ <div className="mui-dialog-window-actions">
132
+ {actionObjects}
133
+ </div>
134
+ );
135
+ }
136
+
137
+ return actionContainer;
138
+ },
139
+
140
+ _positionDialog: function() {
141
+ var container, dialogWindow, containerHeight, dialogWindowHeight;
142
+
143
+ if (this.state.open) {
144
+
145
+ container = this.getDOMNode(),
146
+ dialogWindow = this.refs.dialogWindow.getDOMNode(),
147
+ containerHeight = container.offsetHeight,
148
+
149
+ //Reset the height in case the window was resized.
150
+ dialogWindow.style.height = '';
151
+ dialogWindowHeight = dialogWindow.offsetHeight;
152
+
153
+ //Vertically center the dialog window, but make sure it doesn't
154
+ //transition to that position.
155
+ if (this.props.repositionOnUpdate || !container.style.paddingTop) {
156
+ container.style.paddingTop =
157
+ ((containerHeight - dialogWindowHeight) / 2) - 64 + 'px';
158
+ }
159
+ }
160
+ },
161
+
162
+ _onShow: function() {
163
+ if (this.props.onShow) this.props.onShow();
164
+ },
165
+
166
+ _onDismiss: function() {
167
+ if (this.props.onDismiss) this.props.onDismiss();
168
+ },
169
+
170
+ _handleOverlayTouchTap: function() {
171
+ this.dismiss();
172
+ if (this.props.onClickAway) this.props.onClickAway();
173
+ },
174
+
175
+ _handleWindowKeyUp: function(e) {
176
+ if (e.keyCode == KeyCode.ESC) {
177
+ this.dismiss();
178
+ }
179
+ }
180
+
181
+ });
182
+
183
+ module.exports = DialogWindow;
@@ -0,0 +1,54 @@
1
+ var React = require('react');
2
+ var Classable = require('./mixins/classable');
3
+ var DialogWindow = require('./dialog-window');
4
+
5
+ var Dialog = React.createClass({
6
+
7
+ mixins: [Classable],
8
+
9
+ propTypes: {
10
+ title: React.PropTypes.node
11
+ },
12
+
13
+ render: function() {
14
+ var {
15
+ className,
16
+ ...other
17
+ } = this.props;
18
+ var classes = this.getClasses('mui-dialog');
19
+ var title;
20
+
21
+ if (this.props.title) {
22
+ // If the title is a string, wrap in an h3 tag.
23
+ // If not, just use it as a node.
24
+ title = toString.call(this.props.title) === '[object String]' ?
25
+ <h3 className="mui-dialog-title">{this.props.title}</h3> :
26
+ this.props.title;
27
+ }
28
+
29
+ return (
30
+ <DialogWindow
31
+ {...other}
32
+ ref="dialogWindow"
33
+ className={classes}>
34
+
35
+ {title}
36
+ <div ref="dialogContent" className="mui-dialog-content">
37
+ {this.props.children}
38
+ </div>
39
+
40
+ </DialogWindow>
41
+ );
42
+ },
43
+
44
+ dismiss: function() {
45
+ this.refs.dialogWindow.dismiss();
46
+ },
47
+
48
+ show: function() {
49
+ this.refs.dialogWindow.show();
50
+ }
51
+
52
+ });
53
+
54
+ module.exports = Dialog;
@@ -0,0 +1,68 @@
1
+ var React = require('react');
2
+ var Classable = require('./mixins/classable');
3
+ var ClickAwayable = require('./mixins/click-awayable');
4
+ var KeyLine = require('./utils/key-line');
5
+ var Paper = require('./paper');
6
+ var FontIcon = require('./font-icon');
7
+ var Menu = require('./menu/menu');
8
+
9
+ var DropDownIcon = React.createClass({
10
+
11
+ mixins: [Classable, ClickAwayable],
12
+
13
+ propTypes: {
14
+ onChange: React.PropTypes.func,
15
+ menuItems: React.PropTypes.array.isRequired,
16
+ closeOnMenuItemClick: React.PropTypes.bool
17
+ },
18
+
19
+ getInitialState: function() {
20
+ return {
21
+ open: false
22
+ }
23
+ },
24
+
25
+ getDefaultProps: function() {
26
+ return {
27
+ closeOnMenuItemClick: true
28
+ }
29
+ },
30
+
31
+ componentClickAway: function() {
32
+ this.setState({ open: false });
33
+ },
34
+
35
+ render: function() {
36
+ var classes = this.getClasses('mui-drop-down-icon', {
37
+ 'mui-open': this.state.open
38
+ });
39
+
40
+ var icon;
41
+ if (this.props.iconClassName) icon = <FontIcon className={this.props.iconClassName} />;
42
+
43
+ return (
44
+ <div className={classes}>
45
+ <div className="mui-menu-control" onClick={this._onControlClick}>
46
+ {icon}
47
+ {this.props.children}
48
+ </div>
49
+ <Menu ref="menuItems" menuItems={this.props.menuItems} hideable={true} visible={this.state.open} onItemClick={this._onMenuItemClick} />
50
+ </div>
51
+ );
52
+ },
53
+
54
+ _onControlClick: function(e) {
55
+ this.setState({ open: !this.state.open });
56
+ },
57
+
58
+ _onMenuItemClick: function(e, key, payload) {
59
+ if (this.props.onChange) this.props.onChange(e, key, payload);
60
+
61
+ if (this.props.closeOnMenuItemClick) {
62
+ this.setState({ open: false });
63
+ }
64
+ }
65
+
66
+ });
67
+
68
+ module.exports = DropDownIcon;
@@ -0,0 +1,94 @@
1
+ var React = require('react');
2
+ var Classable = require('./mixins/classable');
3
+ var ClickAwayable = require('./mixins/click-awayable');
4
+ var DropDownArrow = require('./svg-icons/drop-down-arrow');
5
+ var KeyLine = require('./utils/key-line');
6
+ var Paper = require('./paper');
7
+ var Menu = require('./menu/menu');
8
+
9
+ var DropDownMenu = React.createClass({
10
+
11
+ mixins: [Classable, ClickAwayable],
12
+
13
+ propTypes: {
14
+ autoWidth: React.PropTypes.bool,
15
+ onChange: React.PropTypes.func,
16
+ menuItems: React.PropTypes.array.isRequired
17
+ },
18
+
19
+ getDefaultProps: function() {
20
+ return {
21
+ autoWidth: true
22
+ };
23
+ },
24
+
25
+ getInitialState: function() {
26
+ return {
27
+ open: false,
28
+ selectedIndex: this.props.selectedIndex || 0
29
+ }
30
+ },
31
+
32
+ componentClickAway: function() {
33
+ this.setState({ open: false });
34
+ },
35
+
36
+ componentDidMount: function() {
37
+ if (this.props.autoWidth) this._setWidth();
38
+ },
39
+
40
+ componentWillReceiveProps: function(nextProps) {
41
+ if (nextProps.hasOwnProperty('selectedIndex')) {
42
+ this.setState({selectedIndex: nextProps.selectedIndex});
43
+ }
44
+ },
45
+
46
+ render: function() {
47
+ var classes = this.getClasses('mui-drop-down-menu', {
48
+ 'mui-open': this.state.open
49
+ });
50
+
51
+ return (
52
+ <div className={classes}>
53
+ <div className="mui-menu-control" onClick={this._onControlClick}>
54
+ <Paper className="mui-menu-control-bg" zDepth={0} />
55
+ <div className="mui-menu-label">
56
+ {this.props.menuItems[this.state.selectedIndex].text}
57
+ </div>
58
+ <DropDownArrow className="mui-menu-drop-down-icon" />
59
+ <div className="mui-menu-control-underline" />
60
+ </div>
61
+ <Menu
62
+ ref="menuItems"
63
+ autoWidth={this.props.autoWidth}
64
+ selectedIndex={this.state.selectedIndex}
65
+ menuItems={this.props.menuItems}
66
+ hideable={true}
67
+ visible={this.state.open}
68
+ onItemClick={this._onMenuItemClick} />
69
+ </div>
70
+ );
71
+ },
72
+
73
+ _setWidth: function() {
74
+ var el = this.getDOMNode(),
75
+ menuItemsDom = this.refs.menuItems.getDOMNode();
76
+
77
+ el.style.width = menuItemsDom.offsetWidth + 'px';
78
+ },
79
+
80
+ _onControlClick: function(e) {
81
+ this.setState({ open: !this.state.open });
82
+ },
83
+
84
+ _onMenuItemClick: function(e, key, payload) {
85
+ if (this.props.onChange && this.state.selectedIndex !== key) this.props.onChange(e, key, payload);
86
+ this.setState({
87
+ selectedIndex: key,
88
+ open: false
89
+ });
90
+ }
91
+
92
+ });
93
+
94
+ module.exports = DropDownMenu;