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,147 @@
1
+ var React = require('react');
2
+ var KeyCode = require('./utils/key-code');
3
+ var Classable = require('./mixins/classable');
4
+ var WindowListenable = require('./mixins/window-listenable');
5
+ var FocusRipple = require('./ripples/focus-ripple');
6
+ var TouchRipple = require('./ripples/touch-ripple');
7
+
8
+ var EnhancedButton = React.createClass({
9
+
10
+ mixins: [Classable, WindowListenable],
11
+
12
+ propTypes: {
13
+ centerRipple: React.PropTypes.bool,
14
+ className: React.PropTypes.string,
15
+ disabled: React.PropTypes.bool,
16
+ disableFocusRipple: React.PropTypes.bool,
17
+ disableTouchRipple: React.PropTypes.bool,
18
+ linkButton: React.PropTypes.bool,
19
+ onBlur: React.PropTypes.func,
20
+ onFocus: React.PropTypes.func,
21
+ onTouchTap: React.PropTypes.func
22
+ },
23
+
24
+ windowListeners: {
25
+ 'keydown': '_handleWindowKeydown',
26
+ 'keyup': '_handleWindowKeyup'
27
+ },
28
+
29
+ getInitialState: function() {
30
+ return {
31
+ isKeyboardFocused: false
32
+ };
33
+ },
34
+
35
+ render: function() {
36
+ var {
37
+ centerRipple,
38
+ disabled,
39
+ disableFocusRipple,
40
+ disableTouchRipple,
41
+ linkButton,
42
+ onBlur,
43
+ onFocus,
44
+ onTouchTap,
45
+ ...other } = this.props;
46
+ var classes = this.getClasses('mui-enhanced-button', {
47
+ 'mui-is-disabled': disabled,
48
+ 'mui-is-keyboard-focused': this.state.isKeyboardFocused,
49
+ 'mui-is-link-button': linkButton
50
+ });
51
+ var touchRipple = (
52
+ <TouchRipple
53
+ ref="touchRipple"
54
+ key="touchRipple"
55
+ centerRipple={centerRipple}>
56
+ {this.props.children}
57
+ </TouchRipple>
58
+ );
59
+ var focusRipple = (
60
+ <FocusRipple
61
+ key="focusRipple"
62
+ show={this.state.isKeyboardFocused} />
63
+ );
64
+ var buttonProps = {
65
+ className: classes,
66
+ disabled: disabled,
67
+ onBlur: this._handleBlur,
68
+ onFocus: this._handleFocus,
69
+ onTouchTap: this._handleTouchTap
70
+ };
71
+ var buttonChildren = [
72
+ disabled || disableTouchRipple ? this.props.children : touchRipple,
73
+ disabled || disableFocusRipple ? null : focusRipple
74
+ ];
75
+
76
+ if (disabled && linkButton) {
77
+ return (
78
+ <span {...other}
79
+ className={classes}
80
+ disabled={disabled}>
81
+ {this.props.children}
82
+ </span>
83
+ );
84
+ }
85
+
86
+ return linkButton ? (
87
+ <a {...other} {...buttonProps}>
88
+ {buttonChildren}
89
+ </a>
90
+ ) : (
91
+ <button {...other} {...buttonProps}>
92
+ {buttonChildren}
93
+ </button>
94
+ );
95
+ },
96
+
97
+ isKeyboardFocused: function() {
98
+ return this.state.isKeyboardFocused;
99
+ },
100
+
101
+ _handleWindowKeydown: function(e) {
102
+ if (e.keyCode == KeyCode.TAB) this._tabPressed = true;
103
+ if (e.keyCode == KeyCode.ENTER && this.state.isKeyboardFocused) {
104
+ this._handleTouchTap(e);
105
+ }
106
+ },
107
+
108
+ _handleWindowKeyup: function(e) {
109
+ if (e.keyCode == KeyCode.SPACE && this.state.isKeyboardFocused) {
110
+ this._handleTouchTap(e);
111
+ }
112
+ },
113
+
114
+ _handleBlur: function(e) {
115
+ this.setState({
116
+ isKeyboardFocused: false
117
+ });
118
+
119
+ if (this.props.onBlur) this.props.onBlur(e);
120
+ },
121
+
122
+ _handleFocus: function(e) {
123
+ //setTimeout is needed becuase the focus event fires first
124
+ //Wait so that we can capture if this was a keyboard focus
125
+ //or touch focus
126
+ setTimeout(function() {
127
+ if (this._tabPressed) {
128
+ this.setState({
129
+ isKeyboardFocused: true
130
+ });
131
+ }
132
+ }.bind(this), 150);
133
+
134
+ if (this.props.onFocus) this.props.onFocus(e);
135
+ },
136
+
137
+ _handleTouchTap: function(e) {
138
+ this._tabPressed = false;
139
+ this.setState({
140
+ isKeyboardFocused: false
141
+ });
142
+ if (this.props.onTouchTap) this.props.onTouchTap(e);
143
+ }
144
+
145
+ });
146
+
147
+ module.exports = EnhancedButton;
@@ -0,0 +1,296 @@
1
+ var React = require('react');
2
+ var KeyCode = require('./utils/key-code');
3
+ var Classable = require('./mixins/classable');
4
+ var UniqueId = require('./utils/unique-id');
5
+ var WindowListenable = require('./mixins/window-listenable');
6
+ var FocusRipple = require('./ripples/focus-ripple');
7
+ var TouchRipple = require('./ripples/touch-ripple');
8
+ var Paper = require('./paper');
9
+
10
+ var EnhancedSwitch = React.createClass({
11
+
12
+ mixins: [Classable, WindowListenable],
13
+
14
+ propTypes: {
15
+ id: React.PropTypes.string,
16
+ inputType: React.PropTypes.string.isRequired,
17
+ switchElement: React.PropTypes.element.isRequired,
18
+ iconClassName: React.PropTypes.string.isRequired,
19
+ name: React.PropTypes.string,
20
+ value: React.PropTypes.string,
21
+ label: React.PropTypes.string,
22
+ onSwitch: React.PropTypes.func,
23
+ required: React.PropTypes.bool,
24
+ disabled: React.PropTypes.bool,
25
+ defaultSwitched: React.PropTypes.bool,
26
+ labelPosition: React.PropTypes.oneOf(['left', 'right']),
27
+ disableFocusRipple: React.PropTypes.bool,
28
+ disableTouchRipple: React.PropTypes.bool
29
+ },
30
+
31
+ windowListeners: {
32
+ 'keydown': '_handleWindowKeydown',
33
+ 'keyup': '_handleWindowKeyup'
34
+ },
35
+
36
+ getDefaultProps: function() {
37
+ return {
38
+ iconClassName: ''
39
+ };
40
+ },
41
+
42
+ getInitialState: function() {
43
+ return {
44
+ switched: this.props.defaultSwitched ||
45
+ (this.props.valueLink && this.props.valueLink.value),
46
+ isKeyboardFocused: false
47
+ }
48
+ },
49
+
50
+ componentDidMount: function() {
51
+ var inputNode = this.refs.checkbox.getDOMNode();
52
+ this.setState({switched: inputNode.checked});
53
+ },
54
+
55
+ componentWillReceiveProps: function(nextProps) {
56
+ var hasCheckedLinkProp = nextProps.hasOwnProperty('checkedLink');
57
+ var hasCheckedProp = nextProps.hasOwnProperty('checked');
58
+ var hasToggledProp = nextProps.hasOwnProperty('toggled');
59
+ var hasNewDefaultProp =
60
+ (nextProps.hasOwnProperty('defaultSwitched') &&
61
+ (nextProps.defaultSwitched != this.props.defaultSwitched));
62
+ var newState = {};
63
+
64
+ if (hasCheckedProp) {
65
+ newState.switched = nextProps.checked;
66
+ } else if (hasToggledProp) {
67
+ newState.switched = nextProps.toggled;
68
+ } else if (hasCheckedLinkProp) {
69
+ newState.switched = nextProps.checkedLink.value;
70
+ }
71
+
72
+ if (newState) this.setState(newState);
73
+ },
74
+
75
+ render: function() {
76
+ var {
77
+ type,
78
+ name,
79
+ value,
80
+ label,
81
+ onSwitch,
82
+ defaultSwitched,
83
+ onBlur,
84
+ onFocus,
85
+ onMouseUp,
86
+ onMouseDown,
87
+ onMouseOut,
88
+ onTouchStart,
89
+ onTouchEnd,
90
+ disableTouchRipple,
91
+ disableFocusRipple,
92
+ iconClassName,
93
+ ...other
94
+ } = this.props;
95
+
96
+ var classes = this.getClasses('mui-enhanced-switch', {
97
+ 'mui-is-switched': this.state.switched,
98
+ 'mui-is-disabled': this.props.disabled,
99
+ 'mui-is-required': this.props.required
100
+ });
101
+
102
+ var inputId = this.props.id || UniqueId.generate();
103
+
104
+ var labelElement = this.props.label ? (
105
+ <label className="mui-switch-label" htmlFor={inputId}>
106
+ {this.props.label}
107
+ </label>
108
+ ) : null;
109
+
110
+ var inputProps = {
111
+ ref: "checkbox",
112
+ type: this.props.inputType,
113
+ name: this.props.name,
114
+ value: this.props.value,
115
+ defaultChecked: this.props.defaultSwitched,
116
+ onBlur: this._handleBlur,
117
+ onFocus: this._handleFocus,
118
+ onMouseUp: this._handleMouseUp,
119
+ onMouseDown: this._handleMouseDown,
120
+ onMouseOut: this._handleMouseOut,
121
+ onTouchStart: this._handleTouchStart,
122
+ onTouchEnd: this._handleTouchEnd
123
+ };
124
+
125
+ if (!this.props.hasOwnProperty('checkedLink')) {
126
+ inputProps.onChange = this._handleChange;
127
+ }
128
+
129
+ var inputElement = (
130
+ <input
131
+ {...other}
132
+ {...inputProps}
133
+ className="mui-enhanced-switch-input"/>
134
+ );
135
+
136
+ var touchRipple = (
137
+ <TouchRipple
138
+ ref="touchRipple"
139
+ key="touchRipple"
140
+ centerRipple={true} />
141
+ );
142
+
143
+ var focusRipple = (
144
+ <FocusRipple
145
+ key="focusRipple"
146
+ show={this.state.isKeyboardFocused} />
147
+ );
148
+
149
+ var ripples = [
150
+ this.props.disabled || disableTouchRipple ? null : touchRipple,
151
+ this.props.disabled || disableFocusRipple ? null : focusRipple
152
+ ];
153
+
154
+ iconClassName += ' mui-enhanced-switch-wrap';
155
+
156
+ var switchElement = (this.props.iconClassName.indexOf("toggle") == -1) ? (
157
+ <div className={iconClassName}>
158
+ {this.props.switchElement}
159
+ {ripples}
160
+ </div>
161
+ ) : (
162
+ <div className={iconClassName}>
163
+ <div className="mui-toggle-track" />
164
+ <Paper className="mui-toggle-thumb" zDepth={1}> {ripples} </Paper>
165
+ </div>
166
+ );
167
+
168
+ var labelPositionExist = this.props.labelPosition;
169
+
170
+ // Position is left if not defined or invalid.
171
+ var elementsInOrder = (labelPositionExist &&
172
+ (this.props.labelPosition.toUpperCase() === "RIGHT")) ? (
173
+ <div>
174
+ {switchElement}
175
+ {labelElement}
176
+ </div>
177
+ ) : (
178
+ <div>
179
+ {labelElement}
180
+ {switchElement}
181
+ </div>
182
+ );
183
+
184
+ return (
185
+ <div className={classes}>
186
+ {inputElement}
187
+ {elementsInOrder}
188
+ </div>
189
+ );
190
+ },
191
+
192
+
193
+ isSwitched: function() {
194
+ return this.refs.checkbox.getDOMNode().checked;
195
+ },
196
+
197
+ // no callback here because there is no event
198
+ setSwitched: function(newSwitchedValue) {
199
+ if (!this.props.hasOwnProperty('checked') || this.props.checked == false) {
200
+ this.setState({switched: newSwitchedValue});
201
+ this.refs.checkbox.getDOMNode().checked = newSwitchedValue;
202
+ } else if (process.NODE_ENV !== 'production') {
203
+ var message = 'Cannot call set method while checked is defined as a property.';
204
+ console.error(message);
205
+ }
206
+ },
207
+
208
+ getValue: function() {
209
+ return this.refs.checkbox.getDOMNode().value;
210
+ },
211
+
212
+ isKeyboardFocused: function() {
213
+ return this.state.isKeyboardFocused;
214
+ },
215
+
216
+ _handleChange: function(e) {
217
+
218
+ this._tabPressed = false;
219
+ this.setState({
220
+ isKeyboardFocused: false
221
+ });
222
+
223
+ var isInputChecked = this.refs.checkbox.getDOMNode().checked;
224
+
225
+ if (!this.props.hasOwnProperty('checked')) this.setState({switched: isInputChecked});
226
+ if (this.props.onSwitch) this.props.onSwitch(e, isInputChecked);
227
+ },
228
+
229
+ /**
230
+ * Because both the ripples and the checkbox input cannot share pointer
231
+ * events, the checkbox input takes control of pointer events and calls
232
+ * ripple animations manually.
233
+ */
234
+
235
+ // Checkbox inputs only use SPACE to change their state. Using ENTER will
236
+ // update the ui but not the input.
237
+ _handleWindowKeydown: function(e) {
238
+ if (e.keyCode == KeyCode.TAB) this._tabPressed = true;
239
+ if (e.keyCode == KeyCode.SPACE && this.state.isKeyboardFocused) {
240
+ this._handleChange(e);
241
+ }
242
+ },
243
+
244
+ _handleWindowKeyup: function(e) {
245
+ if (e.keyCode == KeyCode.SPACE && this.state.isKeyboardFocused) {
246
+ this._handleChange(e);
247
+ }
248
+ },
249
+
250
+ _handleMouseDown: function(e) {
251
+ //only listen to left clicks
252
+ if (e.button === 0) this.refs.touchRipple.start(e);
253
+ },
254
+
255
+ _handleMouseUp: function(e) {
256
+ this.refs.touchRipple.end();
257
+ },
258
+
259
+ _handleMouseOut: function(e) {
260
+ this.refs.touchRipple.end();
261
+ },
262
+
263
+ _handleTouchStart: function(e) {
264
+ this.refs.touchRipple.start(e);
265
+ },
266
+
267
+ _handleTouchEnd: function(e) {
268
+ this.refs.touchRipple.end();
269
+ },
270
+
271
+ _handleBlur: function(e) {
272
+ this.setState({
273
+ isKeyboardFocused: false
274
+ });
275
+
276
+ if (this.props.onBlur) this.props.onBlur(e);
277
+ },
278
+
279
+ _handleFocus: function(e) {
280
+ //setTimeout is needed becuase the focus event fires first
281
+ //Wait so that we can capture if this was a keyboard focus
282
+ //or touch focus
283
+ setTimeout(function() {
284
+ if (this._tabPressed) {
285
+ this.setState({
286
+ isKeyboardFocused: true
287
+ });
288
+ }
289
+ }.bind(this), 150);
290
+
291
+ if (this.props.onFocus) this.props.onFocus(e);
292
+ }
293
+
294
+ });
295
+
296
+ module.exports = EnhancedSwitch;
@@ -0,0 +1,113 @@
1
+ var React = require('react');
2
+ var Classable = require('./mixins/classable');
3
+
4
+ var EnhancedTextarea = React.createClass({
5
+
6
+ mixins: [Classable],
7
+
8
+ propTypes: {
9
+ onChange: React.PropTypes.func,
10
+ onHeightChange: React.PropTypes.func,
11
+ textareaClassName: React.PropTypes.string,
12
+ rows: React.PropTypes.number
13
+ },
14
+
15
+ getDefaultProps: function() {
16
+ return {
17
+ rows: 1
18
+ };
19
+ },
20
+
21
+ getInitialState: function() {
22
+ return {
23
+ height: this.props.rows * 24
24
+ };
25
+ },
26
+
27
+ componentDidMount: function() {
28
+ this._syncHeightWithShadow();
29
+ },
30
+
31
+ render: function() {
32
+
33
+ var {
34
+ className,
35
+ onChange,
36
+ onHeightChange,
37
+ textareaClassName,
38
+ rows,
39
+ valueLink,
40
+ ...other,
41
+ } = this.props;
42
+
43
+ var classes = this.getClasses('mui-enhanced-textarea');
44
+ var textareaClassName = 'mui-enhanced-textarea-input';
45
+ var style = {
46
+ height: this.state.height + 'px'
47
+ };
48
+
49
+ if (this.props.textareaClassName) {
50
+ textareaClassName += ' ' + this.props.textareaClassName;
51
+ }
52
+
53
+ if (this.props.hasOwnProperty('valueLink')) {
54
+ other.value = this.props.valueLink.value;
55
+ }
56
+
57
+ return (
58
+ <div className={classes}>
59
+ <textarea
60
+ ref="shadow"
61
+ className="mui-enhanced-textarea-shadow"
62
+ tabIndex="-1"
63
+ rows={this.props.rows}
64
+ defaultValue={this.props.defaultValue}
65
+ readOnly={true}
66
+ value={this.props.value} />
67
+ <textarea
68
+ {...other}
69
+ ref="input"
70
+ className={textareaClassName}
71
+ rows={this.props.rows}
72
+ style={style}
73
+ onChange={this._handleChange} />
74
+ </div>
75
+ );
76
+ },
77
+
78
+ getInputNode: function() {
79
+ return this.refs.input.getDOMNode();
80
+ },
81
+
82
+ _syncHeightWithShadow: function(newValue, e) {
83
+ var shadow = this.refs.shadow.getDOMNode();
84
+ var currentHeight = this.state.height;
85
+ var newHeight;
86
+
87
+ if (newValue !== undefined) shadow.value = newValue;
88
+ newHeight = shadow.scrollHeight;
89
+
90
+ if (currentHeight !== newHeight) {
91
+ this.setState({height: newHeight});
92
+ if (this.props.onHeightChange) this.props.onHeightChange(e, newHeight);
93
+ }
94
+ },
95
+
96
+ _handleChange: function(e) {
97
+ this._syncHeightWithShadow(e.target.value);
98
+
99
+ if (this.props.hasOwnProperty('valueLink')) {
100
+ this.props.valueLink.requestChange(e.target.value);
101
+ }
102
+
103
+ if (this.props.onChange) this.props.onChange(e);
104
+ },
105
+
106
+ componentWillReceiveProps: function(nextProps) {
107
+ if (nextProps.value != this.props.value) {
108
+ this._syncHeightWithShadow(nextProps.value);
109
+ }
110
+ }
111
+ });
112
+
113
+ module.exports = EnhancedTextarea;