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,35 @@
1
+ var React = require('react');
2
+ var Classable = require('../mixins/classable');
3
+
4
+ var RippleCircle = React.createClass({
5
+
6
+ mixins: [Classable],
7
+
8
+ propTypes: {
9
+ className: React.PropTypes.string,
10
+ started: React.PropTypes.bool,
11
+ ending: React.PropTypes.bool
12
+ },
13
+
14
+ render: function() {
15
+ var {
16
+ innerClassName,
17
+ started,
18
+ ending,
19
+ ...other
20
+ } = this.props;
21
+ var classes = this.getClasses('mui-ripple-circle', {
22
+ 'mui-is-started': this.props.started,
23
+ 'mui-is-ending': this.props.ending
24
+ });
25
+
26
+ return (
27
+ <div {...other} className={classes}>
28
+ <div className="mui-ripple-circle-inner" />
29
+ </div>
30
+ );
31
+ }
32
+
33
+ });
34
+
35
+ module.exports = RippleCircle;
@@ -0,0 +1,40 @@
1
+ var React = require('react');
2
+ var Classable = require('../mixins/classable');
3
+
4
+ var FocusRipple = React.createClass({
5
+
6
+ mixins: [Classable],
7
+
8
+ propTypes: {
9
+ show: React.PropTypes.bool
10
+ },
11
+
12
+ componentDidMount: function() {
13
+ this._setRippleSize();
14
+ },
15
+
16
+ render: function() {
17
+ var classes = this.getClasses('mui-focus-ripple', {
18
+ 'mui-is-shown': this.props.show
19
+ });
20
+
21
+ return (
22
+ <div className={classes}>
23
+ <div className="mui-focus-ripple-inner" />
24
+ </div>
25
+ );
26
+ },
27
+
28
+ _setRippleSize: function() {
29
+ var el = this.getDOMNode();
30
+ var height = el.offsetHeight;
31
+ var width = el.offsetWidth;
32
+ var size = Math.max(height, width);
33
+
34
+ el.style.height = size + 'px';
35
+ el.style.top = (size / 2 * -1) + (height / 2) + 'px';
36
+ }
37
+
38
+ });
39
+
40
+ module.exports = FocusRipple;
@@ -0,0 +1,174 @@
1
+ var React = require('react');
2
+ var Classable = require('../mixins/classable');
3
+ var Dom = require('../utils/dom');
4
+ var RippleCircle = require('./circle');
5
+
6
+ var TouchRipple = React.createClass({
7
+
8
+ mixins: [Classable],
9
+
10
+ propTypes: {
11
+ centerRipple: React.PropTypes.bool,
12
+ className: React.PropTypes.string
13
+ },
14
+
15
+ getInitialState: function() {
16
+ return {
17
+ ripples: [{
18
+ key: 0,
19
+ started: false,
20
+ ending: false
21
+ }]
22
+ };
23
+ },
24
+
25
+ render: function() {
26
+ var classes = this.getClasses('mui-touch-ripple');
27
+
28
+ return (
29
+ <div
30
+ onMouseUp={this._handleMouseUp}
31
+ onMouseDown={this._handleMouseDown}
32
+ onMouseOut={this._handleMouseOut}
33
+ onTouchStart={this._handleTouchStart}
34
+ onTouchEnd={this._handleTouchEnd}>
35
+ <div className={classes}>
36
+ {this._getRippleElements()}
37
+ </div>
38
+ {this.props.children}
39
+ </div>
40
+ );
41
+ },
42
+
43
+ start: function(e) {
44
+ var ripples = this.state.ripples;
45
+ var nextKey = ripples[ripples.length-1].key + 1;
46
+ var style = !this.props.centerRipple ? this._getRippleStyle(e) : {};
47
+ var ripple;
48
+
49
+ //Start the next unstarted ripple
50
+ for (var i = 0; i < ripples.length; i++) {
51
+ ripple = ripples[i];
52
+ if (!ripple.started) {
53
+ ripple.started = true;
54
+ ripple.style = style;
55
+ break;
56
+ }
57
+ };
58
+
59
+ //Add an unstarted ripple at the end
60
+ ripples.push({
61
+ key: nextKey,
62
+ started: false,
63
+ ending: false
64
+ });
65
+
66
+ //Re-render
67
+ this.setState({
68
+ ripples: ripples
69
+ });
70
+ },
71
+
72
+ end: function() {
73
+ var ripples = this.state.ripples;
74
+ var ripple;
75
+ var endingRipple;
76
+
77
+ //End the the next un-ended ripple
78
+ for (var i = 0; i < ripples.length; i++) {
79
+ ripple = ripples[i];
80
+ if (ripple.started && !ripple.ending) {
81
+ ripple.ending = true;
82
+ endingRipple = ripple;
83
+ break;
84
+ }
85
+ };
86
+
87
+ //Only update if a ripple was found
88
+ if (endingRipple) {
89
+ //Re-render
90
+ this.setState({
91
+ ripples: ripples
92
+ });
93
+
94
+ //Wait 2 seconds and remove the ripple from DOM
95
+ setTimeout(function() {
96
+ ripples.shift();
97
+ if (this.isMounted()) {
98
+ this.setState({
99
+ ripples: ripples
100
+ });
101
+ }
102
+ }.bind(this), 2000);
103
+ }
104
+ },
105
+
106
+ _handleMouseDown: function(e) {
107
+ //only listen to left clicks
108
+ if (e.button === 0) this.start(e);
109
+ },
110
+
111
+ _handleMouseUp: function(e) {
112
+ this.end();
113
+ },
114
+
115
+ _handleMouseOut: function(e) {
116
+ this.end();
117
+ },
118
+
119
+ _handleTouchStart: function(e) {
120
+ this.start(e);
121
+ },
122
+
123
+ _handleTouchEnd: function(e) {
124
+ this.end();
125
+ },
126
+
127
+ _getRippleStyle: function(e) {
128
+ var style = {};
129
+ var el = this.getDOMNode();
130
+ var elHeight = el.offsetHeight;
131
+ var elWidth = el.offsetWidth;
132
+ var offset = Dom.offset(el);
133
+ var pageX = e.pageX == undefined ? e.nativeEvent.pageX : e.pageX;
134
+ var pageY = e.pageY == undefined ? e.nativeEvent.pageY : e.pageY;
135
+ var pointerX = pageX - offset.left;
136
+ var pointerY = pageY - offset.top;
137
+ var topLeftDiag = this._calcDiag(pointerX, pointerY);
138
+ var topRightDiag = this._calcDiag(elWidth - pointerX, pointerY);
139
+ var botRightDiag = this._calcDiag(elWidth - pointerX, elHeight - pointerY);
140
+ var botLeftDiag = this._calcDiag(pointerX, elHeight - pointerY);
141
+ var rippleRadius = Math.max(
142
+ topLeftDiag, topRightDiag, botRightDiag, botLeftDiag
143
+ );
144
+ var rippleSize = rippleRadius * 2;
145
+ var left = pointerX - rippleRadius;
146
+ var top = pointerY - rippleRadius;
147
+
148
+ style.height = rippleSize + 'px';
149
+ style.width = rippleSize + 'px';
150
+ style.top = top + 'px';
151
+ style.left = left + 'px';
152
+
153
+ return style;
154
+ },
155
+
156
+ _calcDiag: function(a, b) {
157
+ return Math.sqrt((a * a) + (b * b));
158
+ },
159
+
160
+ _getRippleElements: function() {
161
+ return this.state.ripples.map(function(ripple) {
162
+ return (
163
+ <RippleCircle
164
+ key={ripple.key}
165
+ started={ripple.started}
166
+ ending={ripple.ending}
167
+ style={ripple.style} />
168
+ );
169
+ }.bind(this));
170
+ }
171
+
172
+ });
173
+
174
+ module.exports = TouchRipple;
@@ -0,0 +1,178 @@
1
+ var React = require('react'),
2
+ Paper = require('./paper'),
3
+ Classable = require('./mixins/classable'),
4
+ Draggable = require('react-draggable2');
5
+
6
+ var Slider = React.createClass({
7
+
8
+ propTypes: {
9
+ required: React.PropTypes.bool,
10
+ disabled: React.PropTypes.bool,
11
+ min: React.PropTypes.number,
12
+ max: React.PropTypes.number,
13
+ step: React.PropTypes.number,
14
+ error: React.PropTypes.string,
15
+ description: React.PropTypes.string,
16
+ name: React.PropTypes.string.isRequired,
17
+ onChange: React.PropTypes.func,
18
+ onDragStart: React.PropTypes.func,
19
+ onDragStop: React.PropTypes.func
20
+ },
21
+
22
+ mixins: [Classable],
23
+
24
+ getDefaultProps: function() {
25
+ return {
26
+ required: true,
27
+ disabled: false,
28
+ defaultValue: 0,
29
+ min: 0,
30
+ max: 1,
31
+ dragging: false
32
+ };
33
+ },
34
+
35
+ getInitialState: function() {
36
+ var value = this.props.value;
37
+ if (value == null) value = this.props.defaultValue;
38
+ var percent = (value - this.props.min) / (this.props.max - this.props.min);
39
+ if (isNaN(percent)) percent = 0;
40
+ return {
41
+ value: value,
42
+ percent: percent
43
+ }
44
+ },
45
+
46
+ componentWillReceiveProps: function(nextProps) {
47
+ if (nextProps.value != null) {
48
+ this.setValue(nextProps.value);
49
+ }
50
+ },
51
+
52
+ render: function() {
53
+ var classes = this.getClasses('mui-input', {
54
+ 'mui-error': this.props.error != null
55
+ });
56
+
57
+ var sliderClasses = this.getClasses('mui-slider', {
58
+ 'mui-slider-zero': this.state.percent == 0,
59
+ 'mui-disabled': this.props.disabled
60
+ });
61
+
62
+ var percent = this.state.percent;
63
+ if (percent > 1) percent = 1; else if (percent < 0) percent = 0;
64
+
65
+ return (
66
+ <div className={classes} style={this.props.style}>
67
+ <span className="mui-input-highlight"></span>
68
+ <span className="mui-input-bar"></span>
69
+ <span className="mui-input-description">{this.props.description}</span>
70
+ <span className="mui-input-error">{this.props.error}</span>
71
+ <div className={sliderClasses} onClick={this._onClick}>
72
+ <div ref="track" className="mui-slider-track">
73
+ <Draggable axis="x" bound="point"
74
+ cancel={this.props.disabled ? '*' : null}
75
+ start={{x: (percent * 100) + '%'}}
76
+ onStart={this._onDragStart}
77
+ onStop={this._onDragStop}
78
+ onDrag={this._onDragUpdate}>
79
+ <div className="mui-slider-handle" tabIndex={0}></div>
80
+ </Draggable>
81
+ <div className="mui-slider-selection mui-slider-selection-low"
82
+ style={{width: (percent * 100) + '%'}}>
83
+ <div className="mui-slider-selection-fill"></div>
84
+ </div>
85
+ <div className="mui-slider-selection mui-slider-selection-high"
86
+ style={{width: ((1 - percent) * 100) + '%'}}>
87
+ <div className="mui-slider-selection-fill"></div>
88
+ </div>
89
+ </div>
90
+ </div>
91
+ <input ref="input" type="hidden"
92
+ name={this.props.name}
93
+ value={this.state.value}
94
+ required={this.props.required}
95
+ min={this.props.min}
96
+ max={this.props.max}
97
+ step={this.props.step} />
98
+ </div>
99
+ );
100
+ },
101
+
102
+ getValue: function() {
103
+ return this.state.value;
104
+ },
105
+
106
+ setValue: function(i) {
107
+ // calculate percentage
108
+ var percent = (i - this.props.min) / (this.props.max - this.props.min);
109
+ if (isNaN(percent)) percent = 0;
110
+ // update state
111
+ this.setState({
112
+ value: i,
113
+ percent: percent
114
+ });
115
+ },
116
+
117
+ getPercent: function() {
118
+ return this.state.percent;
119
+ },
120
+
121
+ setPercent: function (percent) {
122
+ var value = this._percentToValue(percent);
123
+ this.setState({value: value, percent: percent});
124
+ },
125
+
126
+ clearValue: function() {
127
+ this.setValue(0);
128
+ },
129
+
130
+ _onClick: function (e) {
131
+ // let draggable handle the slider
132
+ if (this.state.dragging || this.props.disabled) return;
133
+ var value = this.state.value;
134
+ var node = this.refs.track.getDOMNode();
135
+ var boundingClientRect = node.getBoundingClientRect();
136
+ var offset = e.clientX - boundingClientRect.left;
137
+ this._updateWithChangeEvent(e, offset / node.clientWidth);
138
+ },
139
+
140
+ _onDragStart: function(e, ui) {
141
+ this.setState({
142
+ dragging: true
143
+ });
144
+ if (this.props.onDragStart) this.props.onDragStart(e, ui);
145
+ },
146
+
147
+ _onDragStop: function(e, ui) {
148
+ this.setState({
149
+ dragging: false
150
+ });
151
+ if (this.props.onDragStop) this.props.onDragStop(e, ui);
152
+ },
153
+
154
+ _onDragUpdate: function(e, ui) {
155
+ if (!this.state.dragging) return;
156
+ if (!this.props.disabled) this._dragX(e, ui.position.left);
157
+ },
158
+
159
+ _dragX: function(e, pos) {
160
+ var max = this.refs.track.getDOMNode().clientWidth;
161
+ if (pos < 0) pos = 0; else if (pos > max) pos = max;
162
+ this._updateWithChangeEvent(e, pos / max);
163
+ },
164
+
165
+ _updateWithChangeEvent: function(e, percent) {
166
+ if (this.state.percent === percent) return;
167
+ this.setPercent(percent);
168
+ var value = this._percentToValue(percent);
169
+ if (this.props.onChange) this.props.onChange(e, value);
170
+ },
171
+
172
+ _percentToValue: function(percent) {
173
+ return percent * (this.props.max - this.props.min) + this.props.min;
174
+ }
175
+
176
+ });
177
+
178
+ module.exports = Slider;
@@ -0,0 +1,76 @@
1
+ var React = require('react');
2
+ var CssEvent = require('./utils/css-event');
3
+ var Classable = require('./mixins/classable');
4
+ var ClickAwayable = require('./mixins/click-awayable');
5
+ var FlatButton = require('./flat-button');
6
+
7
+ var Snackbar = React.createClass({
8
+
9
+ mixins: [Classable, ClickAwayable],
10
+
11
+ manuallyBindClickAway: true,
12
+
13
+ propTypes: {
14
+ action: React.PropTypes.string,
15
+ message: React.PropTypes.string.isRequired,
16
+ openOnMount: React.PropTypes.bool,
17
+ onActionTouchTap: React.PropTypes.func
18
+ },
19
+
20
+ getInitialState: function() {
21
+ return {
22
+ open: this.props.openOnMount || false
23
+ };
24
+ },
25
+
26
+ componentClickAway: function() {
27
+ this.dismiss();
28
+ },
29
+
30
+ componentDidUpdate: function(prevProps, prevState) {
31
+ if (prevState.open != this.state.open) {
32
+ if (this.state.open) {
33
+ //Only Bind clickaway after transition finishes
34
+ CssEvent.onTransitionEnd(this.getDOMNode(), function() {
35
+ this._bindClickAway();
36
+ }.bind(this));
37
+ } else {
38
+ this._unbindClickAway();
39
+ }
40
+ }
41
+ },
42
+
43
+ render: function() {
44
+ var classes = this.getClasses('mui-snackbar', {
45
+ 'mui-is-open': this.state.open
46
+ });
47
+ var action;
48
+
49
+ if (this.props.action) {
50
+ action = (
51
+ <FlatButton
52
+ className="mui-snackbar-action"
53
+ label={this.props.action}
54
+ onTouchTap={this.props.onActionTouchTap} />
55
+ );
56
+ }
57
+
58
+ return (
59
+ <span className={classes}>
60
+ <span className="mui-snackbar-message">{this.props.message}</span>
61
+ {action}
62
+ </span>
63
+ );
64
+ },
65
+
66
+ show: function() {
67
+ this.setState({ open: true });
68
+ },
69
+
70
+ dismiss: function() {
71
+ this.setState({ open: false });
72
+ }
73
+
74
+ });
75
+
76
+ module.exports = Snackbar;