123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="workspace" ng-app="app" ng-controller="controller">

	<div class="case">
		<!-- this is the thing -->
		<calendar-dial date="date" config="config"></calendar-dial>
	</div>

	<div class="output">
		<span data-title="before today ok" class="tooltip" ng-class="{'show-tooltip': config.allowBeforeToday}">
			<i tap="config.allowBeforeToday = !config.allowBeforeToday" class="fa fa-history fa-fw fa-lg" ng-class="{'fg-ok': config.allowBeforeToday}"></i>
		</span>
		<span>
			<i ng-click="reset()" class="fa fa-refresh fa-fw fa-lg"></i>
		</span>
		<span data-title="weekend alert" class="tooltip" ng-class="{'show-tooltip':config.useWeekendAlert}">
			<i tap="config.useWeekendAlert = !config.useWeekendAlert" class="fa fa-exclamation-circle fa-fw fa-lg" ng-class="{'fg-alert': config.useWeekendAlert}"></i>
		</span>
	</div>

</div>
            
          
!
            
              $dark: #9BCE5F;
$light: #fff;
$warning: #FF3B80;
$alert: #FFF048;
$ok: #9BCE5F;
$timing: .3s;

.fg-alert {
	color: $alert;
}

.fg-warning {
	color: $warning;
}

.fg-ok {
	color: $ok;
}

.bezel {
  font-size: 65vmin;
  width: 1em;
  height: 1em;
  position: relative;
  line-height: 1;
  color: inherit; /* inherit from parent element or set explicitly: $light */
  border-radius: 100%;
	transition: background $timing ease-out;
  &::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    transform: scale(1.05);
    border: .04em solid;
    border-radius: 100%;
  }
	// just because we can, doesn't mean we should, unless we should.
	// &.is-weekend {background: #FFF048;}
	// &.weekday-1 {color: #FF703A;} // monday
	// &.weekday-2 {color: #FBA900;} // tuesday
	// &.weekday-3 {color: #FFF048;} // wednesday
	// &.weekday-4 {color: #63BC66;} // thursday
	// &.weekday-5 {color: #19A79A;} // friday
	// &.weekday-6 {color: #FFF048;} //color: #7E53C5;} // saturday
	// &.weekday-7 {color: #FFF048;} //color: #FF3B80;} // sunday
	&.is-past {
		background: $warning;
	}
	.lcd {
    position: absolute;
    z-index: 1;
    top: 65%;
    left: 50%;
		width: 100%;
		line-height: 1;
    transform: translate(-50%, -50%);
		text-align: center;
		display: flex;
		flex-direction: column;
		justify-content: space-around;
    font-size: 80%;
    font-family: "DIN Condensed", Impact, Helvetica, sans-serif;
    user-select: none;
		white-space: nowrap;
    pointer-events: auto;
    -webkit-font-smoothing: subpixel-antialiased;
    transition:
      color $timing ease-out,
      background $timing ease-out,
      top $timing ease-out;
		> div {
	    position: relative;
		}
  }
  .date {
    font-size: 15%;
  }
  .day {
    font-size: 25%;
  }
  .when {
    font-size: 13%;
		text-transform: uppercase;
		opacity: .6;
  }
	.icon {
			line-height: 1;
			font-size: 20%;
			position: absolute;
			left: 50%;
			top: 30%;
			transition: $timing ease-out;
		&.weekend-alert {
			opacity: 0;
			color: $alert;
			pointer-events: none;
			transform: translate(-50%, -50%) scale(1.3);
		}
		&.calendar-action {
			opacity: 1;
	    cursor: pointer;
			transform: translate(-50%, -50%);
		}
	}
	&.is-weekend {
		.calendar-action {opacity: 0;}
		.weekend-alert {opacity: 1;}
	}
  .crown {
    position: absolute;
    top: 0;
    right: 50%;
    bottom: 50%;
    left: 50%;
		transition: transform $timing*2 ease-out;
    transform-origin: center bottom;
    pointer-events: none;
    > span {
      position: absolute;
      top: 0;
      left: 50%;
			text-align: center;
      pointer-events: auto;
			// transition: transform $timing/2 ease-out; // too much fun
	    font-family: "DIN Alternate", Impact, Helvetica, sans-serif;
    }
		&.step {
			z-index: 1;
			> span {
				font-size: 8.5%;
				line-height: 2.2;
				cursor: pointer;
				background: $dark;
				transform: translate(-50%, -50%) rotate(0deg);
				box-shadow: 0 0 0 .2em currentColor;
				border-radius: 2em;
				width: 2.2em;
				height: 2.2em;
			}
		}
		&.today > span {
	    font-size: 6%;
			color: #fff;
      background: currentColor;
      transform: translate(-50%, -50%) rotate(45deg);
      box-shadow: 0 0 0 .15em $dark;
      border-radius: 1em;
      width: 1em;
      height: 1em;
			span {
				position: absolute;
				blend-mode: screen;
				top: 50%;
				left: 300%;
				line-height: 2;
		    -webkit-font-smoothing: subpixel-antialiased;
	      transform: translate(-50%, -50%) rotate(0deg);
				border-radius: 2em;
				width: 2em;
				height: 2em;
			}
		}
  }
	
	// ACTIVE
	&.active {
		.crown {
			transition: none;
		}
	}

  // TOUCH BOX
  &.touch {
		z-index: 0;
		.icon {
			top: 50%;
			&.calendar-action {
				opacity: 0;
			}
		}
    .lcd {
      top: 0%;
      background: rgba(#000, .05);
      pointer-events: none;
      padding: .1em;
			line-height: 1;
      z-index: 2;
      left: 50%;
			width: 120%;
      transform: translate(-50%, -50%);
      border-radius: .05em;
      backdrop-filter: blur(.05em);
    }
  }
}

// general layout
// BORING
body {
  background: $dark;
	color: $light;
}
.workspace {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.output {
	text-align: center;
	display: flex;
	flex-direction:row;
	justify-content: space-around;
	align-items: center;
	background: #343439; //rgba($light, .3);
  padding: 1em 0;
	> span {
		position: relative;
	}
}

.case {
	flex: 1;
	display: flex;
	flex-direction:row;
	justify-content: space-around;
	align-items: center;
}

.config {
	display:flex;
	flex-direction:row;
	flex: none;
}

.tooltip {
	&::before,
	&::after {
		opacity: 0;
		pointer-events: none;
		font-size: 4vmin;
		white-space: nowrap;
		position: absolute;
		left: 50%;
		transition: .5s linear;
		bottom: 50%;
	}
	&::after {
		content: attr(data-title);
		background: #000;
		padding: .5em;
		border-radius: .3em;
		transform: translate(-50%, -40%);
	}
	&::before {
		content: '';
		transform: translate(-50%, 0%);
		border: .5em solid transparent;
		border-top-color: #000;
	}
	&.show-tooltip {
		&::before,
		&::after {
			bottom: 100%;
			opacity: 1;
		}
	}
}
            
          
!
            
              (function($angular, $moment, Hammer) {
  'use strict';

  $angular.module('app', [])
	.controller('controller', ['$scope', function($scope) {
		$scope.date = null; //$moment().add(1, 'day').startOf('day'); //.add(1, 'day');
		
		var calendarClick = function(date){
			console.log('caendar action clicked!', date);
			window.alert('Pancake says:\n\nload an actual calendar\nselect: ' + date.format('MMM D, YYYY'));
		};
		
		$scope.config = {
			useWeekendAlert: false,
			allowBeforeToday: false,
			calendarAction: calendarClick,
			text: {
				diff: 0,
				today: 'today',
				date: '',
				day: '',
				when: ''
			}
		};
		
		$scope.setDate = {
			month: $moment().month(),
			day: $moment().date(),
			year: $moment().year()
		};
		
		$scope.$watch('setDate', function(d){
			// console.log(d);
			$scope.$broadcast('set:date', $moment([d.year, d.month, d.day]));
		}, true);

    $scope.format = function(datetime) {
      return new Date(datetime);
    };

	  $scope.reset = function(date) {
			$scope.$broadcast('reset:date', date);
    };
	}])
	
	.directive('tap', [function() {
		return function(scope, element, attr) {
			var hammerTap = new Hammer(element[0], {});
			hammerTap.on('tap', function() {
				scope.$apply(function() {
					scope.$eval(attr.tap);
				});
			});
		};
	}])
	
	.directive('calendarDial', ['UiHelpers', function(ui) {
    var _rotate = function(el, degrees, shift) {
			var translate = shift ? 'translate(-50%, -50%) ' : '';
      $angular.element(el).css({
        transform: translate + 'rotate(' + degrees + 'deg)'
      });
    };

		var _getDayByDegree = function(max, d, s){
			var i = max - Math.floor(Math.abs(d + s/2)/s);
			var k = (i === 0 ? max : (max - i < 1 ? 1 : (max - i > max ? max : max - i)));
			return k;
		};

		var _getDegreeByDay = function(max, day){
			return (ui.maxDegrees/max * day);
		};

		return {
      restrict: 'E',
      replace: true,

      scope: {
        date: '=?',
				config: '=?'
      },

      template: '' +
        '<div class="calendar-dial bezel" ng-class="setClasses()">' +
        	'<div class="lcd">' +
        		'<div class="day">{{config.text.day}}</div>' +
        		'<div class="when">{{config.text.when}}</div>' +
        		// '<div class="date">{{config.text.date}}</div>' +
        	'</div>' +
					'<div ng-if="config.calendarAction" tap="config.calendarAction(date)" class="icon calendar-action fa fa-calendar-o"></div>' +
					'<div ng-if="config.useWeekendAlert" class="icon weekend-alert fa fa-exclamation-circle"></div>' +
        	'<div class="crown today"><span><span data-title="{{config.text.today}}"></span></span></div>' +
        	'<div class="crown step"><span>{{config.text.diff}}</span></div>' +
      	'</div>' +
        '',

      link: function(scope, element) {
				// if (!scope.date) {
				// 	scope.date = $moment().startOf('day'); // current date
				// }

				var max = 31; //scope.date.daysInMonth();
  
				scope.format = function(datetime) {
          return new Date(datetime);
        };
	
				var step = $angular.element(element[0].querySelector('.step'));
        var lcd = $angular.element(element[0].querySelector('.lcd'));

        var day = {
					deg: 0,
					max: max,
					step: ui.maxDegrees/max,
					element: step,
					handle: $angular.element(element[0].querySelector('.step > span')),
					canvas: element
				};

				var key = {
					deg: 0,
					max: max,
					step: ui.maxDegrees/max,
					element: $angular.element(element[0].querySelector('.today')),
					handle: $angular.element(element[0].querySelector('.today > span')),
					label: $angular.element(element[0].querySelector('.today > span span')),
					canvas: element
				};

				var _setDayTypes = function(date){
					scope.weekday = date.isoWeekday();
					scope.weekend = (scope.weekday === 6 || scope.weekday === 7);
				};

				var _setDisplay = function(date, mode){
					var diff = date.diff(scope.today, 'days');
					var f1 = scope.thisYear !== date.year() ? 'MMMM D, YYYY' : 'MMMM D';
					var f2 = 'ddd, MMM D';
					return {
						diff: (diff > 0 ? '+' + diff : diff),
						today: (Math.abs(diff) > 1 ? 'today':''),
						when: (diff === 0 || diff === 1) ? date.format(f2) : date.fromNow(), //(scope.today),
						date: date.format(f1),
						day: date.calendar(scope.today, {
							lastWeek: f2,
							lastDay: '[Yesterday]',
							sameDay: '[Today]',
							nextDay: '[Tomorrow]',
							nextWeek: f2,
							sameElse: f2
						})
					};
				};

				var init = function(reset) {
					if(!scope.date || reset) {
						scope.isPast = false;
						scope.date = $moment().add(1, 'day').startOf('day'); // set to today + 1 day
						// bypass weekends
						if(scope.config.useWeekendAlert) {
							if(scope.date.isoWeekday() === 6) {
								scope.date.add(1, 'day');
							}
							if(scope.date.isoWeekday() === 7) {
								scope.date.add(1, 'day');
							}
						}
					}
					_setDayTypes(scope.date);
					scope.today = $moment().startOf('day');
					scope.thisYear = scope.today.year();
					var initKey = _getDegreeByDay(max, scope.today.date());
					key.deg = initKey;
					_rotate(key.element[0], initKey);
					var initDay = _getDegreeByDay(max, scope.date.date());
					day.deg = initDay;
					_rotate(day.element[0], initDay);
					_rotate(day.handle[0], -initDay, true);
					scope.config.text = _setDisplay(scope.date, 'date');
				};
				
				var prek, input, n, k, dim, diff=0, deg=0, lastDeg=0, pointerDeg, relativeDeg, rotationDeg;
				
				var start = function(e, max, handle){
					n = ui.maxDegrees/max;
					input = e.srcEvent && e.srcEvent.changedTouches ? e.srcEvent.changedTouches : e.pointers;
					deg = ui.getDegrees(input[0], element[0]);
					lastDeg = handle.deg;
				};

				var pan = function(e){
					input = e.srcEvent && e.srcEvent.changedTouches ? e.srcEvent.changedTouches : e.pointers;
					pointerDeg = ui.getDegrees(input[0], element[0]);
					relativeDeg = pointerDeg - deg;
					rotationDeg = lastDeg + relativeDeg;
					rotationDeg = isNaN(rotationDeg) ? lastDeg : rotationDeg;
					rotationDeg = rotationDeg <= 0 ? ui.maxDegrees-Math.abs(rotationDeg) : rotationDeg;
					rotationDeg = rotationDeg >= ui.maxDegrees ? rotationDeg-ui.maxDegrees :  rotationDeg;
					deg = pointerDeg;
					lastDeg = rotationDeg;
				};

        // hammer time
        scope.touching = false;
        var hammerStep = new Hammer(day.canvas[0]);
        var hammerLcd = new Hammer(lcd[0], {});
        hammerStep.get('pan').set({direction: Hammer.DIRECTION_ALL, threshold: 0});
				hammerStep.on('panstart', function(e) {
					scope.touching = e.srcEvent && e.srcEvent.changedTouches ? true : false;
					scope.active = true;
					start(e, max, day);
				})
				.on('pan panmove', function(e) {
					pan(e);

					dim = scope.date.daysInMonth();
					k = _getDayByDegree(dim, rotationDeg, n);

					diff = scope.date.diff(scope.today, 'days');
					scope.isPast = (diff < 1);
					
					if(k && prek && prek !== k) {
						if(prek === 1 && k > 2) {
							//prev month
							scope.date = scope.date.subtract(1, 'day');
							k = scope.date.daysInMonth();
							// k = dim;
						}

						else if(k === 1 && prek === dim) {
							// next month
							scope.date.add(1, 'day');
							dim = scope.date.daysInMonth();
						}
						scope.date.date(k);
					}
					prek = k;

					scope.config.text = _setDisplay(scope.date);
					_setDayTypes(scope.date);						

					if(scope.isPast && !scope.config.allowBeforeToday) {
							k = scope.today.date();
							day.deg = k*n;
							// if(rotationDeg > day.deg) {
							// 		day.deg = rotationDeg;
							// }
							_rotate(day.element[0], day.deg);
							_rotate(day.handle[0], -day.deg, true);
					} else {
							_rotate(day.element[0], rotationDeg);
							_rotate(day.handle[0], -rotationDeg, true);
							scope.$apply();
					}
				})
				.on('panend pancancel', function() {
					scope.touching = false;
					scope.active = false;
					if(scope.isPast && !scope.config.allowBeforeToday) {
						k = scope.today.date();
						scope.date = $moment(scope.today); // clone today to reset past date
						scope.config.text = _setDisplay(scope.date);
						_setDayTypes(scope.date);						
						scope.isPast = false;
					}
					day.deg = k*n;
					_rotate(day.element[0], day.deg);
					_rotate(day.handle[0], -day.deg, true);
					scope.$apply();
				});
				
				scope.setClasses  = function(){
					var classes = [];
					if(scope.weekday) {classes.push('weekday-' + scope.weekday);}
					if(scope.isPast && !scope.config.allowBeforeToday) {classes.push('is-past');}
					if(scope.active) {classes.push('active');}
					if(scope.touching) {classes.push('touch');}
					if(scope.config.useWeekendAlert && scope.weekend) {classes.push('is-weekend');}
					if(scope.config.calendarAction) {classes.push('has-calendar');}
					return classes.join(' ');
				};

				init();

				scope.$on('reset:date', function(date){
					if(date) {
						scope.date = $moment(date);
					}
					init(true);
				});

				// scope.$on('set:date', function(date){
				// 	scope.date = $moment(date);
				// 	init();
				// });
			}
    };
  }])
	
	.factory('UiHelpers', [function(){
		var maxDegrees = 360;
		var maxRadians = 6.283185307179586;

		// helpers
		var _getNumbers = function(target){
			var numbers = {};
			if(target) {
				numbers = {
					t: target.offsetTop,
					r: target.offsetLeft + target.offsetWidth,
					b: target.offsetTop + target.offsetHeight,
					l: target.offsetLeft,
					w: target.offsetWidth,
					h: target.offsetHeight,
				};
				// find x|y center
				numbers.cx = (numbers.l + (numbers.w/2));
				numbers.cy = (numbers.t + (numbers.h/2));
			}
			return numbers;
		};

		var _getRadians = function(input, el){
			var metrics = _getNumbers(el);
			var radians = Math.atan2((input.clientY - metrics.cy), (input.clientX - metrics.cx));
			radians += maxRadians/4;
			if(radians < 0) {
				radians += maxRadians;
			}
			return radians;
		};

		var _getDegrees = function(input, el){
			var radians = _getRadians(input, el);
			var degree = radians * 180/Math.PI;
			return degree;
		};

		return {
			maxRadians: maxRadians,
			maxDegrees: maxDegrees,
			getNumbers: _getNumbers,
			getRadians: _getRadians,
			getDegrees: _getDegrees
		};
	}]);

})(window.angular, window.moment, window.Hammer);







/*
IDEAS:
add tappable logical time spots like, "tomorrow, 1 week, etc."
tap to open calendar anywhere in the ring
*/
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console