material-ui 0.7.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +31 -0
- data/Rakefile +20 -0
- data/lib/material-ui.rb +4 -0
- data/material-ui-gem.gemspec +33 -0
- data/vendor/assets/javascripts/material-ui.js +1 -0
- data/vendor/assets/javascripts/material-ui/components/app-bar.jsx +93 -0
- data/vendor/assets/javascripts/material-ui/components/app-canvas.jsx +27 -0
- data/vendor/assets/javascripts/material-ui/components/checkbox.jsx +60 -0
- data/vendor/assets/javascripts/material-ui/components/date-picker/calendar-month.jsx +59 -0
- data/vendor/assets/javascripts/material-ui/components/date-picker/calendar-toolbar.jsx +64 -0
- data/vendor/assets/javascripts/material-ui/components/date-picker/calendar.jsx +194 -0
- data/vendor/assets/javascripts/material-ui/components/date-picker/date-display.jsx +79 -0
- data/vendor/assets/javascripts/material-ui/components/date-picker/date-picker-dialog.jsx +118 -0
- data/vendor/assets/javascripts/material-ui/components/date-picker/date-picker.jsx +116 -0
- data/vendor/assets/javascripts/material-ui/components/date-picker/day-button.jsx +49 -0
- data/vendor/assets/javascripts/material-ui/components/dialog-window.jsx +183 -0
- data/vendor/assets/javascripts/material-ui/components/dialog.jsx +54 -0
- data/vendor/assets/javascripts/material-ui/components/drop-down-icon.jsx +68 -0
- data/vendor/assets/javascripts/material-ui/components/drop-down-menu.jsx +94 -0
- data/vendor/assets/javascripts/material-ui/components/enhanced-button.jsx +147 -0
- data/vendor/assets/javascripts/material-ui/components/enhanced-switch.jsx +296 -0
- data/vendor/assets/javascripts/material-ui/components/enhanced-textarea.jsx +113 -0
- data/vendor/assets/javascripts/material-ui/components/flat-button.jsx +46 -0
- data/vendor/assets/javascripts/material-ui/components/floating-action-button.jsx +123 -0
- data/vendor/assets/javascripts/material-ui/components/font-icon.jsx +23 -0
- data/vendor/assets/javascripts/material-ui/components/icon-button.jsx +123 -0
- data/vendor/assets/javascripts/material-ui/components/ink-bar.jsx +25 -0
- data/vendor/assets/javascripts/material-ui/components/input.jsx +143 -0
- data/vendor/assets/javascripts/material-ui/components/left-nav.jsx +105 -0
- data/vendor/assets/javascripts/material-ui/components/menu/link-menu-item.jsx +42 -0
- data/vendor/assets/javascripts/material-ui/components/menu/menu-item.jsx +105 -0
- data/vendor/assets/javascripts/material-ui/components/menu/menu.jsx +325 -0
- data/vendor/assets/javascripts/material-ui/components/menu/subheader-menu-item.jsx +18 -0
- data/vendor/assets/javascripts/material-ui/components/mixins/classable.js +42 -0
- data/vendor/assets/javascripts/material-ui/components/mixins/click-awayable.js +35 -0
- data/vendor/assets/javascripts/material-ui/components/mixins/window-listenable.js +23 -0
- data/vendor/assets/javascripts/material-ui/components/overlay.jsx +58 -0
- data/vendor/assets/javascripts/material-ui/components/paper.jsx +58 -0
- data/vendor/assets/javascripts/material-ui/components/radio-button-group.jsx +112 -0
- data/vendor/assets/javascripts/material-ui/components/radio-button.jsx +65 -0
- data/vendor/assets/javascripts/material-ui/components/raised-button.jsx +102 -0
- data/vendor/assets/javascripts/material-ui/components/ripples/circle.jsx +35 -0
- data/vendor/assets/javascripts/material-ui/components/ripples/focus-ripple.jsx +40 -0
- data/vendor/assets/javascripts/material-ui/components/ripples/touch-ripple.jsx +174 -0
- data/vendor/assets/javascripts/material-ui/components/slider.jsx +178 -0
- data/vendor/assets/javascripts/material-ui/components/snackbar.jsx +76 -0
- data/vendor/assets/javascripts/material-ui/components/svg-icons/drop-down-arrow.jsx +16 -0
- data/vendor/assets/javascripts/material-ui/components/svg-icons/navigation-chevron-left.jsx +16 -0
- data/vendor/assets/javascripts/material-ui/components/svg-icons/navigation-chevron-right.jsx +17 -0
- data/vendor/assets/javascripts/material-ui/components/svg-icons/navigation-menu.jsx +16 -0
- data/vendor/assets/javascripts/material-ui/components/svg-icons/svg-icon.jsx +23 -0
- data/vendor/assets/javascripts/material-ui/components/svg-icons/toggle-check-box-checked.jsx +16 -0
- data/vendor/assets/javascripts/material-ui/components/svg-icons/toggle-check-box-outline-blank.jsx +16 -0
- data/vendor/assets/javascripts/material-ui/components/svg-icons/toggle-radio-button-off.jsx +16 -0
- data/vendor/assets/javascripts/material-ui/components/svg-icons/toggle-radio-button-on.jsx +16 -0
- data/vendor/assets/javascripts/material-ui/components/table-header.jsx +50 -0
- data/vendor/assets/javascripts/material-ui/components/table-rows-item.jsx +31 -0
- data/vendor/assets/javascripts/material-ui/components/table-rows.jsx +57 -0
- data/vendor/assets/javascripts/material-ui/components/tabs/tab.jsx +38 -0
- data/vendor/assets/javascripts/material-ui/components/tabs/tabTemplate.jsx +15 -0
- data/vendor/assets/javascripts/material-ui/components/tabs/tabs.jsx +96 -0
- data/vendor/assets/javascripts/material-ui/components/text-field.jsx +215 -0
- data/vendor/assets/javascripts/material-ui/components/toggle.jsx +62 -0
- data/vendor/assets/javascripts/material-ui/components/toolbar-group.jsx +28 -0
- data/vendor/assets/javascripts/material-ui/components/toolbar.jsx +21 -0
- data/vendor/assets/javascripts/material-ui/components/tooltip.jsx +58 -0
- data/vendor/assets/javascripts/material-ui/components/transition-groups/slide-in.jsx +48 -0
- data/vendor/assets/javascripts/material-ui/components/utils/css-event.js +52 -0
- data/vendor/assets/javascripts/material-ui/components/utils/date-time.js +132 -0
- data/vendor/assets/javascripts/material-ui/components/utils/dom.js +71 -0
- data/vendor/assets/javascripts/material-ui/components/utils/events.js +34 -0
- data/vendor/assets/javascripts/material-ui/components/utils/key-code.js +10 -0
- data/vendor/assets/javascripts/material-ui/components/utils/key-line.js +13 -0
- data/vendor/assets/javascripts/material-ui/components/utils/unique-id.js +7 -0
- data/vendor/assets/stylesheets/material-ui.less +2 -0
- data/vendor/assets/stylesheets/material-ui/components.less +5 -0
- data/vendor/assets/stylesheets/material-ui/components/app-bar.less +37 -0
- data/vendor/assets/stylesheets/material-ui/components/card.less +20 -0
- data/vendor/assets/stylesheets/material-ui/components/checkbox.less +66 -0
- data/vendor/assets/stylesheets/material-ui/components/components.less +37 -0
- data/vendor/assets/stylesheets/material-ui/components/date-picker/calendar-month.less +11 -0
- data/vendor/assets/stylesheets/material-ui/components/date-picker/calendar-toolbar.less +23 -0
- data/vendor/assets/stylesheets/material-ui/components/date-picker/calendar.less +59 -0
- data/vendor/assets/stylesheets/material-ui/components/date-picker/date-display.less +84 -0
- data/vendor/assets/stylesheets/material-ui/components/date-picker/date-picker-dialog.less +18 -0
- data/vendor/assets/stylesheets/material-ui/components/date-picker/date-picker.less +9 -0
- data/vendor/assets/stylesheets/material-ui/components/date-picker/day-button.less +35 -0
- data/vendor/assets/stylesheets/material-ui/components/dialog-window.less +42 -0
- data/vendor/assets/stylesheets/material-ui/components/dialog.less +10 -0
- data/vendor/assets/stylesheets/material-ui/components/drop-down-icon.less +43 -0
- data/vendor/assets/stylesheets/material-ui/components/drop-down-menu.less +77 -0
- data/vendor/assets/stylesheets/material-ui/components/enhanced-button.less +24 -0
- data/vendor/assets/stylesheets/material-ui/components/enhanced-switch.less +52 -0
- data/vendor/assets/stylesheets/material-ui/components/enhanced-textarea.less +16 -0
- data/vendor/assets/stylesheets/material-ui/components/flat-button.less +93 -0
- data/vendor/assets/stylesheets/material-ui/components/floating-action-button.less +95 -0
- data/vendor/assets/stylesheets/material-ui/components/font-icon.less +6 -0
- data/vendor/assets/stylesheets/material-ui/components/icon-button.less +46 -0
- data/vendor/assets/stylesheets/material-ui/components/ink-bar.less +9 -0
- data/vendor/assets/stylesheets/material-ui/components/input.less +186 -0
- data/vendor/assets/stylesheets/material-ui/components/left-nav.less +31 -0
- data/vendor/assets/stylesheets/material-ui/components/menu-item.less +69 -0
- data/vendor/assets/stylesheets/material-ui/components/menu.less +50 -0
- data/vendor/assets/stylesheets/material-ui/components/overlay.less +21 -0
- data/vendor/assets/stylesheets/material-ui/components/paper.less +59 -0
- data/vendor/assets/stylesheets/material-ui/components/radio-button.less +67 -0
- data/vendor/assets/stylesheets/material-ui/components/raised-button.less +132 -0
- data/vendor/assets/stylesheets/material-ui/components/ripples/circle.less +31 -0
- data/vendor/assets/stylesheets/material-ui/components/ripples/focus-ripple.less +30 -0
- data/vendor/assets/stylesheets/material-ui/components/ripples/touch-ripple.less +9 -0
- data/vendor/assets/stylesheets/material-ui/components/slider.less +163 -0
- data/vendor/assets/stylesheets/material-ui/components/snackbar.less +44 -0
- data/vendor/assets/stylesheets/material-ui/components/subheader.less +17 -0
- data/vendor/assets/stylesheets/material-ui/components/svg-icon.less +11 -0
- data/vendor/assets/stylesheets/material-ui/components/table.less +46 -0
- data/vendor/assets/stylesheets/material-ui/components/tabs.less +41 -0
- data/vendor/assets/stylesheets/material-ui/components/text-field.less +168 -0
- data/vendor/assets/stylesheets/material-ui/components/toggle.less +83 -0
- data/vendor/assets/stylesheets/material-ui/components/toolbar.less +95 -0
- data/vendor/assets/stylesheets/material-ui/components/tooltip.less +73 -0
- data/vendor/assets/stylesheets/material-ui/components/transition-groups/slide-in.less +92 -0
- data/vendor/assets/stylesheets/material-ui/core/base.less +31 -0
- data/vendor/assets/stylesheets/material-ui/core/core.less +4 -0
- data/vendor/assets/stylesheets/material-ui/core/keylines.less +29 -0
- data/vendor/assets/stylesheets/material-ui/core/layouts.less +12 -0
- data/vendor/assets/stylesheets/material-ui/core/typography.less +158 -0
- data/vendor/assets/stylesheets/material-ui/mixins/clearfix.less +22 -0
- data/vendor/assets/stylesheets/material-ui/mixins/mixins.less +3 -0
- data/vendor/assets/stylesheets/material-ui/mixins/no-wrap.less +3 -0
- data/vendor/assets/stylesheets/material-ui/mixins/transitions.less +17 -0
- data/vendor/assets/stylesheets/material-ui/resets/normalize.css +430 -0
- data/vendor/assets/stylesheets/material-ui/resets/typography-resets.less +34 -0
- data/vendor/assets/stylesheets/material-ui/scaffolding.less +10 -0
- data/vendor/assets/stylesheets/material-ui/variables/colors.less +285 -0
- data/vendor/assets/stylesheets/material-ui/variables/custom-variables.less +163 -0
- data/vendor/assets/stylesheets/material-ui/variables/media-queries.less +4 -0
- data/vendor/assets/stylesheets/material-ui/variables/spacing.less +16 -0
- 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;
|