Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.