Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                .page
	.page__current-date
	ul.page__grid.grid
		.grid__head.grid-head
			- 
				var listMonth = ['Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'Jan', 'Feb', 'Mar']
			each item in listMonth
				span.grid-head__cell= item
		.grid__cols.grid-cols
			-
				var listDay = ['', 'Mon', '', 'Wed', '', 'Fri', '']
			each item in listDay
				span.grid-cols__cell= item
		.grid__body
			- for (var x = 0; x < 371; x++)
				li.grid__cell
		.grid__footer.grid-footer
			span.grid-footer__first Less
			.grid-footer__cell
			.grid-footer__cell.grid-footer__cell_color_1
			.grid-footer__cell.grid-footer__cell_color_2
			.grid-footer__cell.grid-footer__cell_color_3
			.grid-footer__cell.grid-footer__cell_color_4
			span.grid-footer__last More
			
.tooltip
              
            
!

CSS

              
                
$commitColor0: #ebedf0;
$commitColor1: #c6e48b;
$commitColor2: #7bc96f;
$commitColor3: #239a3b;
$commitColor4: #196127;

.page {
	padding: 200px 0;
	display: flex;
	flex-diraction: column;
	justify-content: center;
	align-items: center;
}

.grid {
	position: relative;
	width: 822px;
	padding-left: 30px;
	
	&__head {
		width: 100%;
		margin-bottom: 10px;
	}
	
	&__cols {
		position: absolute;
		left: 0;
		top: 22px;
		width: 25px;
	}
	
	&__body {
		display: grid;
		grid-gap: 3px;
		grid-auto-flow: column;
		grid-template: repeat(7, 1fr) / repeat(53, 1fr);
		width: 100%;
		margin: 0;
		padding: 0;
		list-style: none;
		margin-bottom: 10px;
	}
	
	&__footer {
		width: 100%;
		display: flex;
		justify-content: flex-end;
	}
	
	&__cell {
		width: 12px;
		height: 12px;
		background-color: $commitColor0;
		&_color {
			&_1 {
				background-color: $commitColor1;
			}
			
			&_2 {
				background-color: $commitColor2;
			}
			
			&_3 {
				background-color: $commitColor3;
			}
			
			&_4 {
				background-color: $commitColor4;
			}
		}
	}
}

.grid-head {
	display: grid;
	grid-gap: 3px;
  grid-template-columns: repeat(53, 1fr);
	grid-template-rows: 12px;
	
	&__cell {
		font-size: 10px;
		color: #767676;
		
		&:nth-child(1) {
			grid-column-start: 1;
			grid-column-end: 3;
		}
		&:nth-child(2) {
			grid-column-start: 3;
			grid-column-end: 7;
		}
		&:nth-child(3) {
			grid-column-start: 7;
			grid-column-end: 11;
		}
		&:nth-child(4) {
			grid-column-start: 11;
			grid-column-end: 16;
		}
		&:nth-child(5) {
			grid-column-start: 16;
			grid-column-end: 20;
		}
		&:nth-child(6) {
			grid-column-start: 20;
			grid-column-end: 24;
		}
		&:nth-child(7) {
			grid-column-start: 24;
			grid-column-end: 29;
		}
		&:nth-child(8) {
			grid-column-start: 29;
			grid-column-end: 33;
		}
		&:nth-child(9) {
			grid-column-start: 33;
			grid-column-end: 37;
		}
		&:nth-child(10) {
			grid-column-start: 37;
			grid-column-end: 42;
		}
		&:nth-child(11) {
			grid-column-start: 42;
			grid-column-end: 46;
		}
		&:nth-child(12) {
			grid-column-start: 46;
			grid-column-end: 50;
		}
		&:nth-child(13) {
			grid-column-start: 50;
			grid-column-end: 54;
		}
	}
}

.grid-cols {
	display: grid;
	grid-gap: 3px;
	grid-auto-flow: column;
	grid-template-rows: repeat(7, 1fr);
	
	&__cell {
		font-size: 10px;
		color: #767676;
		width: 25px;
		height: 12px;
	}
}

.grid-footer {
	display: flex;
	justify-content: flex-end;
	
	&__cell {
		width: 12px;
		height: 12px;
		margin: 0 1.5px;
		background-color: $commitColor0;
		&_color {
			&_1 {
				background-color: $commitColor1;
			}
			
			&_2 {
				background-color: $commitColor2;
			}
			
			&_3 {
				background-color: $commitColor3;
			}
			
			&_4 {
				background-color: $commitColor4;
			}
		}
	}
	
	&__first,
	&__last {
		margin: 0 6px;
		font-size: 10px;
		color: #767676;
	}
}

.tooltip {
	position: absolute;
	left: -1000px;
	top: -1000px;
	transform: translate(-50%, -43px);
	padding: 10px;
	font-size: 12px;
	color: #959da5;
	text-align: center;
	background: rgba(0,0,0,.8);
	border-radius: 3px;
	white-space: nowrap;
	opacity: 0;
	display: none;
	transition: opacity .1s ease-out;
	pointer-events: none;
	
	strong {
		color: #fff;
	}
	
	&::before {
		content: '';
		position: absolute;
		z-index: 99999;
		left: 50%;
		bottom: -10px;
		transform: translateX(-50%);
		display: block;
		width: 0;
		height: 0;
		box-sizing: border-box;
		border: 5px solid transparent;
		border-top-color: rgba(0,0,0,.8);
		pointer-events: none;
	}
	
	&_display {
		display: block;
	}
	
	&_visible {
		opacity: 1;
	}
}

              
            
!

JS

              
                const gridCell = document.querySelectorAll('.grid__cell');
const tooltip = document.querySelector('.tooltip');

let timer = null;

const clearTooltip = () => {
	tooltip.innerHTML = '';
}

const closeTooltip = () => {
	tooltip.classList.remove('tooltip_visible');
	
	timer = setTimeout(() => {
		tooltip.classList.remove('tooltip_display');
		clearTooltip();
	}, 200);
}

const openTooltip = ({ x, y, commit, date }) => {
	clearTimeout(timer);
	clearTooltip();
	tooltip.style.top = y+'px';
	tooltip.style.left = x+'px';
	tooltip.classList.add('tooltip_display');
	setTimeout(() => {
		tooltip.classList.add('tooltip_visible');
	}, 1);
	
	const commitMsgNode = document.createElement("strong");
	const commitMsg = document.createTextNode(commit);
	commitMsgNode.appendChild(commitMsg);
	const dateMsg = document.createTextNode(` on ${date}`);
	tooltip.appendChild(commitMsgNode);
	tooltip.appendChild(dateMsg);
}

gridCell.forEach(cell => {
	cell.addEventListener('mouseover', () => {
		const coords = cell.getBoundingClientRect();
		const commit = cell.getAttribute('data-commit');
		const date = cell.getAttribute('data-date');

		openTooltip({
			x: coords.x + coords.width / 2,
			y: coords.y,
			commit,
			date
		});
	});
	cell.addEventListener('mouseout', closeTooltip);
});

const alphabet = {
	'D': [
		[0, 1, 1, 1, 1, 1, 0],
		[0, 1, 0, 0, 0, 1, 0],
		[0, 1, 0, 0, 0, 1, 0],
		[0, 0, 1, 1, 1, 0, 0]
	],
	'E': [
		[0, 1, 1, 1, 1, 1, 0],
		[0, 1, 0, 1, 0, 1, 0],
		[0, 1, 0, 0, 0, 1, 0]
	],
	'H': [
		[0, 1, 1, 1, 1, 1, 0],
		[0, 0, 0, 1, 0, 0, 0],
		[0, 1, 1, 1, 1, 1, 0]
	],
	'L': [
		[0, 1, 1, 1, 1, 1, 0],
		[0, 0, 0, 0, 0, 1, 0],
		[0, 0, 0, 0, 0, 1, 0]
	],
	'O': [
		[0, 1, 1, 1, 1, 1, 0],
		[0, 1, 0, 0, 0, 1, 0],
		[0, 1, 1, 1, 1, 1, 0]
	],
	'R': [
		[0, 1, 1, 1, 1, 1, 0],
		[0, 1, 0, 1, 0, 0, 0],
		[0, 1, 1, 0, 1, 1, 0]
	],
	'W': [
		[0, 1, 1, 1, 1, 1, 0],
		[0, 0, 0, 0, 0, 1, 0],
		[0, 0, 0, 1, 1, 1, 0],
		[0, 0, 0, 0, 0, 1, 0],
		[0, 1, 1, 1, 1, 1, 0]
	],
	',': [
		[0, 0, 0, 0, 0, 1, 1]
	],
	'<': [
		[0, 0, 0, 1, 0, 0, 0],
		[0, 0, 1, 0, 1, 0, 0]
	],
	'>': [
		[0, 0, 1, 0, 1, 0, 0],
		[0, 0, 0, 1, 0, 0, 0]
	]
}

const monthArr = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const msDay = 86400000;
const msFirstDay = 1553385600000;
let counter = 0;

const getDateString = (cnt) => {
	const date = new Date(msFirstDay + msDay * cnt);
	return `${monthArr[date.getMonth()]} ${date.getDate()}, ${date.getFullYear()}`;
}

const getContributionsObj = (cnt, isCommits) => {
	const min = 1;
	const max = 12;
	const rand = isCommits ? Math.floor(Math.random() * (+max - +min) + +min) : 0;
	
	return {
		rand,
		str: isCommits ? `${rand} contribution${rand > 1 ? 's' : ''}` : 'No contributions'
	};
}

const drawSymbol = l => {
	const data = alphabet[l] || [];
	for (let i = 0, commit = {}, date = '' ; i < data.length ; i++) {
		for (let j = 0 ; j < 7 ; j++) {
			date = getDateString(counter);
			commit = getContributionsObj(counter, data[i][j] === 1);
			
			if (data[i][j] === 1) {
				gridCell[counter].classList.add(`grid__cell_color_${Math.floor((commit.rand + 2) / 3)}`);
			}
			
			gridCell[counter].setAttribute('data-commit', commit.str);
			gridCell[counter].setAttribute('data-date', date);
			
			counter++;
		}
	}
}

const drawSpace = () => {
	for (let i = 0, commit = {}, date = '' ; i < 7 ; i++) {
		date = getDateString(counter);
		commit = getContributionsObj(counter, false);

		gridCell[counter].setAttribute('data-commit', commit.str);
		gridCell[counter].setAttribute('data-date', date);
		
		counter++;
	}
}

const drawString = string => {
	drawSpace();
	string.split('').forEach(symbol => {
		drawSymbol(symbol.toUpperCase());
		drawSpace();
	});
}


// init drawing

drawString('<Hello, World>');
              
            
!
999px

Console