JSFiddle - React, Tailwind, and code Playground

by bmleite

HTML

<script src="https://raw.github.com/timrwood/moment/2.0.0/moment.js"></script>
<div ng-app="calendar" ng-controller="calendarCtrl" ng-cloak>
    <h4>{{ month.format('MMMM YYYY')|capitalize }}</h4>
	<a href="#m" ng-click="month.add('M', -1)">Pref</a>
	<a href="#m" ng-click="month.add('M', 1)" style="display: block; float: right;">Next</a>

    <ul class="calendar">
        <li class="otherDay" ng-repeat="n in [] | range:month.startOf('month').format('d')">	
            <span class="day-number">{{ month.clone().add('M', -1).daysInMonth() - month.startOf('month').format('d') + n }}</span>
        </li>
        <li class="day" ng-repeat="n in [] | range:month.daysInMonth()">	
            <span class="day-number" calendar-day="{{ n }}-{{ month.format('MM-YYYY') }}">{{ n }}</span>
        </li>
        
        <li class="otherDay" ng-repeat="n in [] | range:7-month.endOf('month').format('d')-1">	
            <span class="day-number">{{ n }}</span>
        </li>
    </ul>
</div>

CSS

.calendar { list-style: none; }
.calendar li { display: block; float: left; width: 14%; height: 50px; border: 1px solid #eee;}

JavaScript

angular.module('calendar', []).
value('month', moment()).

// Filters
filter('range', function () {
    return function (input, total) {
        total = parseInt(total, 10);
        for (i = 1; i <= total; i++) {
            input.push(i);
        }
        return input;
    };
}).
filter('capitalize', function () {
    return function (input) {
        return input.substring(0, 1).toUpperCase() + input.substring(1);
    };
}).

// Controllers
controller('calendarCtrl', ['$scope', 'month', function ($scope, month) {
    $scope.month = month;
}]).

// Directives
directive('calendarDay', ['month', function (month) {
    return function (scope, element, attrs) {
        scope.$watch('month', function (value) {
            var currentDate = moment(attrs.calendarDay, "DD-MM-YYYY");
            element.text(currentDate.format('DD-MM-YYYY'));
        }, true);

    };
}]);