-
-
Save briandaviddavidson/789549a6d59d0f31bff229cac3852f9a to your computer and use it in GitHub Desktop.
Calendar POC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
/* | |
Notes: | |
- dst | |
- internationalization | |
- timezones | |
- leap year | |
*/ | |
init() { | |
this._super(...arguments); | |
const today = new Date(); | |
const todayDayOfYear = this.getDayOfYear(today); | |
const dayOfWeek = today.getDay(); | |
let startingDayOfYear = todayDayOfYear; | |
if (dayOfWeek > 0) { | |
startingDayOfYear = todayDayOfYear - dayOfWeek; | |
} | |
const days = []; | |
for (let dayOfYear = startingDayOfYear; dayOfYear < startingDayOfYear + 35; dayOfYear++) { | |
days.push({ | |
dayOfYear, | |
date: this.dateFromDay(today.getYear(), dayOfYear), | |
isToday: dayOfYear === todayDayOfYear | |
}); | |
} | |
this.set('days', days); | |
}, | |
getDayOfYear(date) { | |
var start = new Date(date.getFullYear(), 0, 0); | |
var diff = (date - start) + ((start.getTimezoneOffset() - date.getTimezoneOffset()) * 60 * 1000); | |
var oneDay = 1000 * 60 * 60 * 24; | |
var day = Math.floor(diff / oneDay); | |
return day; | |
}, | |
dateFromDay(year, day){ | |
var date = new Date(year, 0); // initialize a date in `year-01-01` | |
return new Date(date.setDate(day)); // add the number of days | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
tagName: 'li', | |
classNameBindings: [ 'isToday', 'isLastMonth', 'isNextMonth' ], | |
dayOfMonth: Ember.computed('model.date', function () { | |
return this.get('model.date').getDate(); | |
}), | |
isToday: Ember.computed.reads('model.isToday'), | |
isLastMonth: Ember.computed('model.date', function () { | |
return this.get('model.date').getMonth() < new Date().getMonth(); | |
}), | |
isNextMonth: Ember.computed('model.date', function () { | |
return this.get('model.date').getMonth() > new Date().getMonth(); | |
}) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
tagName: 'ol', | |
classNames: 'day-grid' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
ol { | |
display: grid; | |
grid-template-columns: repeat(7, 1fr); | |
grid-gap: 1em; | |
margin: 0 auto; | |
max-width: 64em; | |
padding: 0; | |
} | |
li { | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
list-style: none; | |
margin-left: 0; | |
font-size: calc(16px + (21 - 16) * ((100vw - 300px) / (1600 - 300))); | |
} | |
ol.day-grid li { | |
background-color: #fff; | |
border: 1px solid #eaeaea; | |
height: 12vw; | |
max-height: 125px; | |
} | |
ol.day-grid li.is-last-month, | |
ol.day-grid li.is-next-month { | |
color: lightgray | |
} | |
ol.day-grid li.is-today { | |
background-color: lightgray | |
} | |
@media all and (max-width: 800px) { | |
ul { | |
grid-gap: .25em; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.13.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": true, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.16.2", | |
"ember-template-compiler": "2.16.2", | |
"ember-testing": "2.16.2" | |
}, | |
"addons": { | |
"ember-data": "2.16.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment