Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Created March 22, 2016 17:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save barneycarroll/59d6adbc02e85f9bf1dc to your computer and use it in GitHub Desktop.
Save barneycarroll/59d6adbc02e85f9bf1dc to your computer and use it in GitHub Desktop.
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