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,194 @@
1
+ var React = require('react');
2
+ var Classable = require('../mixins/classable');
3
+ var WindowListenable = require('../mixins/window-listenable');
4
+ var DateTime = require('../utils/date-time');
5
+ var KeyCode = require('../utils/key-code');
6
+ var CalendarMonth = require('./calendar-month');
7
+ var CalendarToolbar = require('./calendar-toolbar');
8
+ var DateDisplay = require('./date-display');
9
+ var SlideInTransitionGroup = require('../transition-groups/slide-in');
10
+
11
+ var Calendar = React.createClass({
12
+
13
+ mixins: [Classable, WindowListenable],
14
+
15
+ propTypes: {
16
+ initialDate: React.PropTypes.object,
17
+ isActive: React.PropTypes.bool
18
+ },
19
+
20
+ windowListeners: {
21
+ 'keydown': '_handleWindowKeyDown'
22
+ },
23
+
24
+ getDefaultProps: function() {
25
+ return {
26
+ initialDate: new Date()
27
+ };
28
+ },
29
+
30
+ getInitialState: function() {
31
+ return {
32
+ displayDate: DateTime.getFirstDayOfMonth(this.props.initialDate),
33
+ selectedDate: this.props.initialDate,
34
+ transitionDirection: 'left'
35
+ };
36
+ },
37
+
38
+ componentWillReceiveProps: function(nextProps) {
39
+ if (nextProps.initialDate !== this.props.initialDate) {
40
+ var d = nextProps.initialDate || new Date();
41
+ this.setState({
42
+ displayDate: DateTime.getFirstDayOfMonth(d),
43
+ selectedDate: d
44
+ });
45
+ }
46
+ },
47
+
48
+ render: function() {
49
+ var weekCount = DateTime.getWeekArray(this.state.displayDate).length;
50
+ var classes = this.getClasses('mui-date-picker-calendar', {
51
+ 'mui-is-4week': weekCount === 4,
52
+ 'mui-is-5week': weekCount === 5,
53
+ 'mui-is-6week': weekCount === 6
54
+ });
55
+
56
+ return (
57
+ <div className={classes}>
58
+
59
+ <DateDisplay
60
+ className="mui-date-picker-calendar-date-display"
61
+ selectedDate={this.state.selectedDate} />
62
+
63
+ <div
64
+ className="mui-date-picker-calendar-container">
65
+ <CalendarToolbar
66
+ displayDate={this.state.displayDate}
67
+ onLeftTouchTap={this._handleLeftTouchTap}
68
+ onRightTouchTap={this._handleRightTouchTap} />
69
+
70
+ <ul className="mui-date-picker-calendar-week-title">
71
+ <li className="mui-date-picker-calendar-week-title-day">S</li>
72
+ <li className="mui-date-picker-calendar-week-title-day">M</li>
73
+ <li className="mui-date-picker-calendar-week-title-day">T</li>
74
+ <li className="mui-date-picker-calendar-week-title-day">W</li>
75
+ <li className="mui-date-picker-calendar-week-title-day">T</li>
76
+ <li className="mui-date-picker-calendar-week-title-day">F</li>
77
+ <li className="mui-date-picker-calendar-week-title-day">S</li>
78
+ </ul>
79
+
80
+ <SlideInTransitionGroup
81
+ direction={this.state.transitionDirection}>
82
+ <CalendarMonth
83
+ key={this.state.displayDate.toDateString()}
84
+ displayDate={this.state.displayDate}
85
+ onDayTouchTap={this._handleDayTouchTap}
86
+ selectedDate={this.state.selectedDate} />
87
+ </SlideInTransitionGroup>
88
+ </div>
89
+ </div>
90
+ );
91
+ },
92
+
93
+ getSelectedDate: function() {
94
+ return this.state.selectedDate;
95
+ },
96
+
97
+ _addDisplayDate: function(m) {
98
+ var newDisplayDate = DateTime.clone(this.state.displayDate);
99
+ newDisplayDate.setMonth(newDisplayDate.getMonth() + m);
100
+ this._setDisplayDate(newDisplayDate);
101
+ },
102
+
103
+ _addSelectedDays: function(days) {
104
+ this._setSelectedDate(DateTime.addDays(this.state.selectedDate, days));
105
+ },
106
+
107
+ _addSelectedMonths: function(months) {
108
+ this._setSelectedDate(DateTime.addMonths(this.state.selectedDate, months));
109
+ },
110
+
111
+ _setDisplayDate: function(d, newSelectedDate) {
112
+ var newDisplayDate = DateTime.getFirstDayOfMonth(d);
113
+ var direction = newDisplayDate > this.state.displayDate ? 'left' : 'right';
114
+
115
+ if (newDisplayDate !== this.state.displayDate) {
116
+ this.setState({
117
+ displayDate: newDisplayDate,
118
+ transitionDirection: direction,
119
+ selectedDate: newSelectedDate || this.state.selectedDate
120
+ });
121
+ }
122
+ },
123
+
124
+ _setSelectedDate: function(d) {
125
+ var newDisplayDate = DateTime.getFirstDayOfMonth(d);
126
+
127
+ if (newDisplayDate !== this.state.displayDate) {
128
+ this._setDisplayDate(newDisplayDate, d);
129
+ } else {
130
+ this.setState({
131
+ selectedDate: d
132
+ });
133
+ }
134
+ },
135
+
136
+ _handleDayTouchTap: function(e, date) {
137
+ this._setSelectedDate(date);
138
+ },
139
+
140
+ _handleLeftTouchTap: function() {
141
+ this._addDisplayDate(-1);
142
+ },
143
+
144
+ _handleRightTouchTap: function() {
145
+ this._addDisplayDate(1);
146
+ },
147
+
148
+ _handleWindowKeyDown: function(e) {
149
+ var newSelectedDate;
150
+
151
+ if (this.props.isActive) {
152
+
153
+ switch (e.keyCode) {
154
+
155
+ case KeyCode.UP:
156
+ if (e.shiftKey) {
157
+ this._addSelectedMonths(-1);
158
+ } else {
159
+ this._addSelectedDays(-7);
160
+ }
161
+ break;
162
+
163
+ case KeyCode.DOWN:
164
+ if (e.shiftKey) {
165
+ this._addSelectedMonths(1);
166
+ } else {
167
+ this._addSelectedDays(7);
168
+ }
169
+ break;
170
+
171
+ case KeyCode.RIGHT:
172
+ if (e.shiftKey) {
173
+ this._addSelectedMonths(1);
174
+ } else {
175
+ this._addSelectedDays(1);
176
+ }
177
+ break;
178
+
179
+ case KeyCode.LEFT:
180
+ if (e.shiftKey) {
181
+ this._addSelectedMonths(-1);
182
+ } else {
183
+ this._addSelectedDays(-1);
184
+ }
185
+ break;
186
+
187
+ }
188
+
189
+ }
190
+ }
191
+
192
+ });
193
+
194
+ module.exports = Calendar;
@@ -0,0 +1,79 @@
1
+ var React = require('react');
2
+ var Classable = require('../mixins/classable');
3
+ var DateTime = require('../utils/date-time');
4
+ var SlideInTransitionGroup = require('../transition-groups/slide-in');
5
+
6
+ var DateDisplay = React.createClass({
7
+
8
+ mixins: [Classable],
9
+
10
+ propTypes: {
11
+ selectedDate: React.PropTypes.object.isRequired
12
+ },
13
+
14
+ getInitialState: function() {
15
+ return {
16
+ transitionDirection: 'up'
17
+ };
18
+ },
19
+
20
+ componentWillReceiveProps: function(nextProps) {
21
+ var direction;
22
+
23
+ if (nextProps.selectedDate !== this.props.selectedDate) {
24
+ direction = nextProps.selectedDate > this.props.selectedDate ? 'up' : 'down';
25
+ this.setState({
26
+ transitionDirection: direction
27
+ });
28
+ }
29
+ },
30
+
31
+ render: function() {
32
+ var {
33
+ selectedDate,
34
+ ...other
35
+ } = this.props;
36
+ var classes = this.getClasses('mui-date-picker-date-display');
37
+ var dayOfWeek = DateTime.getDayOfWeek(this.props.selectedDate);
38
+ var month = DateTime.getShortMonth(this.props.selectedDate);
39
+ var day = this.props.selectedDate.getDate();
40
+ var year = this.props.selectedDate.getFullYear();
41
+
42
+ return (
43
+ <div {...other} className={classes}>
44
+
45
+ <SlideInTransitionGroup
46
+ className="mui-date-picker-date-display-dow"
47
+ direction={this.state.transitionDirection}>
48
+ <div key={dayOfWeek}>{dayOfWeek}</div>
49
+ </SlideInTransitionGroup>
50
+
51
+ <div className="mui-date-picker-date-display-date">
52
+
53
+ <SlideInTransitionGroup
54
+ className="mui-date-picker-date-display-month"
55
+ direction={this.state.transitionDirection}>
56
+ <div key={month}>{month}</div>
57
+ </SlideInTransitionGroup>
58
+
59
+ <SlideInTransitionGroup
60
+ className="mui-date-picker-date-display-day"
61
+ direction={this.state.transitionDirection}>
62
+ <div key={day}>{day}</div>
63
+ </SlideInTransitionGroup>
64
+
65
+ <SlideInTransitionGroup
66
+ className="mui-date-picker-date-display-year"
67
+ direction={this.state.transitionDirection}>
68
+ <div key={year}>{year}</div>
69
+ </SlideInTransitionGroup>
70
+
71
+ </div>
72
+
73
+ </div>
74
+ );
75
+ }
76
+
77
+ });
78
+
79
+ module.exports = DateDisplay;
@@ -0,0 +1,118 @@
1
+ var React = require('react');
2
+ var Classable = require('../mixins/classable');
3
+ var WindowListenable = require('../mixins/window-listenable');
4
+ var KeyCode = require('../utils/key-code');
5
+ var Calendar = require('./calendar');
6
+ var DialogWindow = require('../dialog-window');
7
+ var FlatButton = require('../flat-button');
8
+
9
+ var DatePickerDialog = React.createClass({
10
+
11
+ mixins: [Classable, WindowListenable],
12
+
13
+ propTypes: {
14
+ initialDate: React.PropTypes.object,
15
+ onAccept: React.PropTypes.func,
16
+ onShow: React.PropTypes.func,
17
+ onDismiss: React.PropTypes.func,
18
+ },
19
+
20
+ windowListeners: {
21
+ 'keyup': '_handleWindowKeyUp'
22
+ },
23
+
24
+ getInitialState: function() {
25
+ return {
26
+ isCalendarActive: false
27
+ };
28
+ },
29
+
30
+ render: function() {
31
+ var {
32
+ initialDate,
33
+ onAccept,
34
+ ...other
35
+ } = this.props;
36
+ var classes = this.getClasses('mui-date-picker-dialog');
37
+ var actions = [
38
+ <FlatButton
39
+ key={0}
40
+ label="Cancel"
41
+ secondary={true}
42
+ onTouchTap={this._handleCancelTouchTap} />,
43
+ <FlatButton
44
+ key={1}
45
+ label="OK"
46
+ secondary={true}
47
+ onTouchTap={this._handleOKTouchTap} />
48
+ ];
49
+
50
+ return (
51
+ <DialogWindow {...other}
52
+ ref="dialogWindow"
53
+ className={classes}
54
+ actions={actions}
55
+ contentClassName="mui-date-picker-dialog-window"
56
+ onDismiss={this._handleDialogDismiss}
57
+ onShow={this._handleDialogShow}
58
+ repositionOnUpdate={false}>
59
+ <Calendar
60
+ ref="calendar"
61
+ initialDate={this.props.initialDate}
62
+ isActive={this.state.isCalendarActive} />
63
+ </DialogWindow>
64
+ );
65
+ },
66
+
67
+ show: function() {
68
+ this.refs.dialogWindow.show();
69
+ },
70
+
71
+ dismiss: function() {
72
+ this.refs.dialogWindow.dismiss();
73
+ },
74
+
75
+ _handleCancelTouchTap: function() {
76
+ this.dismiss();
77
+ },
78
+
79
+ _handleOKTouchTap: function() {
80
+ this.dismiss();
81
+ if (this.props.onAccept) {
82
+ this.props.onAccept(this.refs.calendar.getSelectedDate());
83
+ }
84
+ },
85
+
86
+ _handleDialogShow: function() {
87
+ this.setState({
88
+ isCalendarActive: true
89
+ });
90
+
91
+ if(this.props.onShow) {
92
+ this.props.onShow();
93
+ }
94
+ },
95
+
96
+ _handleDialogDismiss: function() {
97
+ this.setState({
98
+ isCalendarActive: false
99
+ });
100
+
101
+ if(this.props.onDismiss) {
102
+ this.props.onDismiss();
103
+ }
104
+ },
105
+
106
+ _handleWindowKeyUp: function(e) {
107
+ if (this.refs.dialogWindow.isOpen()) {
108
+ switch (e.keyCode) {
109
+ case KeyCode.ENTER:
110
+ this._handleOKTouchTap();
111
+ break;
112
+ }
113
+ }
114
+ }
115
+
116
+ });
117
+
118
+ module.exports = DatePickerDialog;
@@ -0,0 +1,116 @@
1
+ var React = require('react');
2
+ var Classable = require('../mixins/classable');
3
+ var WindowListenable = require('../mixins/window-listenable');
4
+ var DateTime = require('../utils/date-time');
5
+ var KeyCode = require('../utils/key-code');
6
+ var DatePickerDialog = require('./date-picker-dialog');
7
+ var TextField = require('../text-field');
8
+
9
+ var DatePicker = React.createClass({
10
+
11
+ mixins: [Classable, WindowListenable],
12
+
13
+ propTypes: {
14
+ defaultDate: React.PropTypes.object,
15
+ formatDate: React.PropTypes.func,
16
+ mode: React.PropTypes.oneOf(['portrait', 'landscape', 'inline']),
17
+ onFocus: React.PropTypes.func,
18
+ onTouchTap: React.PropTypes.func,
19
+ onChange: React.PropTypes.func,
20
+ onShow: React.PropTypes.func,
21
+ onDismiss: React.PropTypes.func,
22
+ },
23
+
24
+ windowListeners: {
25
+ 'keyup': '_handleWindowKeyUp'
26
+ },
27
+
28
+ getDefaultProps: function() {
29
+ return {
30
+ formatDate: DateTime.format
31
+ };
32
+ },
33
+
34
+ getInitialState: function() {
35
+ return {
36
+ date: this.props.defaultDate,
37
+ dialogDate: new Date()
38
+ };
39
+ },
40
+
41
+ render: function() {
42
+ var {
43
+ formatDate,
44
+ mode,
45
+ onFocus,
46
+ onTouchTap,
47
+ onShow,
48
+ onDismiss,
49
+ ...other
50
+ } = this.props;
51
+ var classes = this.getClasses('mui-date-picker', {
52
+ 'mui-is-landscape': this.props.mode === 'landscape',
53
+ 'mui-is-inline': this.props.mode === 'inline'
54
+ });
55
+ var defaultInputValue;
56
+
57
+ if (this.props.defaultDate) {
58
+ defaultInputValue = this.props.formatDate(this.props.defaultDate);
59
+ }
60
+
61
+ return (
62
+ <div className={classes}>
63
+ <TextField
64
+ {...other}
65
+ ref="input"
66
+ defaultValue={defaultInputValue}
67
+ onFocus={this._handleInputFocus}
68
+ onTouchTap={this._handleInputTouchTap} />
69
+ <DatePickerDialog
70
+ ref="dialogWindow"
71
+ initialDate={this.state.dialogDate}
72
+ onAccept={this._handleDialogAccept}
73
+ onShow={onShow}
74
+ onDismiss={onDismiss} />
75
+ </div>
76
+
77
+ );
78
+ },
79
+
80
+ getDate: function() {
81
+ return this.state.date;
82
+ },
83
+
84
+ setDate: function(d) {
85
+ this.setState({
86
+ date: d
87
+ });
88
+ this.refs.input.setValue(this.props.formatDate(d));
89
+ },
90
+
91
+ _handleDialogAccept: function(d) {
92
+ this.setDate(d);
93
+ if (this.props.onChange) this.props.onChange(null, d);
94
+ },
95
+
96
+ _handleInputFocus: function(e) {
97
+ e.target.blur();
98
+ if (this.props.onFocus) this.props.onFocus(e);
99
+ },
100
+
101
+ _handleInputTouchTap: function(e) {
102
+ this.setState({
103
+ dialogDate: this.getDate()
104
+ });
105
+
106
+ this.refs.dialogWindow.show();
107
+ if (this.props.onTouchTap) this.props.onTouchTap(e);
108
+ },
109
+
110
+ _handleWindowKeyUp: function(e) {
111
+ //TO DO: open the dialog if input has focus
112
+ }
113
+
114
+ });
115
+
116
+ module.exports = DatePicker;