Created
March 22, 2016 17:36
-
-
Save barneycarroll/59d6adbc02e85f9bf1dc to your computer and use it in GitHub Desktop.
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
const calendar = { | |
controller : ( date = moment() ) => { | |
const weeks = [] | |
const end = date.endOf( 'month' ).startOf( 'week' ) | |
let current = date.startOf( 'month' ).startOf( 'week' ) | |
do { | |
weeks.push( { | |
start : current.clone() | |
} ) | |
current = current.add( 1, 'week' ) | |
} | |
while( | |
current.isBefore( end ) | |
) | |
return { weeks } | |
}, | |
view : ctrl => | |
m( `.month[style=" | |
display : flex; | |
align-items : stretch; | |
flex-direction : column; | |
"]`, | |
ctrl.weeks.map( week => | |
m( `.week[" | |
display : flex; | |
align-items : stretch; | |
"]`, | |
( new Array( 7 ) ).fill( 0 ) | |
.map( ( _, index ) => | |
m( `.day[" | |
display : flex; | |
align-items : stretch; | |
flex-direction : column; | |
"]`, | |
m( '.label', | |
week.start.add( index, 'days' ).calendar() | |
) | |
) | |
) | |
) | |
) | |
) | |
} | |
m.mount( document.body, { | |
view : () => | |
m( `.app[style=" | |
position : fixed; | |
width : 100%; | |
height : 100%; | |
"]` ), | |
m( calendar ) | |
} ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment