Pen Settings

HTML

CSS

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

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

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.

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

              
                <div class="filemanager">
	<div class="filemanager--headerside"><h4 id="filecount">12 Files (0 Selected)</h4></div>
	<div class="filemanager--headermain">
		<div class="filemanager--controls">
			<button type="button" class="view icon active" title="Grid View" data-view="grid"><span class="mdi mdi-view-grid"></span></button>
			<button type="button" class="view icon" title="List View" data-view="list"><span class="mdi mdi-view-sequential"></span></button>
		</div>
			<div class="filemanager--controls">
				<button type="button" class="danger hidden toggle" onclick="remove()"><span class="mdi mdi-delete"></span>Remove Selected</button>
				<button type="button" class="danger hidden toggle" onclick="clearAll()"><span class="mdi mdi-cancel"></span>Clear</button>
								<button type="button" class="primary hidden toggle" onclick="invert()"><span class="mdi mdi-swap-horizontal"></span>Invert</button>		
				<button type="button" class="primary" onclick="selectAll()"><span class="mdi mdi-check"></span>Select All</button>
				<button type="button" class="primary" onclick="add()"><span class="mdi mdi-upload"></span>Add File</button>
			</div>
		</div>	
	<div class="filemanager--sidebar">
		<div class="filemanager--tabs">
			<ul>
				<li class="active"><a href="#" data-filter="*"><span class="mdi mdi-file-multiple"></span> All</a></li>
				<li><a href="#" data-filter="image"><span class="mdi mdi-file-image"></span> Images</a></li>
				<li><a href="#" data-filter="audio"><span class="mdi mdi-headphones"></span> Music</a></li>
				<li><a href="#" data-filter="doc"><span class="mdi mdi-file-document"></span> Documents</a></li>
				<li><a href="#" data-filter="archive"><span class="mdi mdi-zip-box"></span> Archives</a></li>
				<li><a href="#" data-filter="trash"><span class="mdi mdi-delete"></span>Recycle Bin</a></li>
			</ul>
		</div>
	</div>
	<div class="filemanager--main">
		<div class="filemanager--files">
			<ul>

			</ul>
		</div>
	</div>
	<div class="filemanager--info">
		<ul></ul>
	</div>
</div>
              
            
!

CSS

              
                $border: #c8d6dd;
$light: #919fa9;
$dark: #343434;
$highlight: darken(#eceff4, 3);
$white: #fff;
$primary: #00a8ff;
$danger: #fa424a;

@mixin for-size($size) {
  @if $size == phone-only {
    @media (max-width: 599px) { @content; }
  } @else if $size == tablet-portrait-up {
    @media (min-width: 600px) { @content; }
  } @else if $size == tablet-landscape-up {
    @media (min-width: 900px) { @content; }
  } @else if $size == desktop-up {
    @media (min-width: 1200px) { @content; }
  } @else if $size == big-desktop-up {
    @media (min-width: 1800px) { @content; }
  }
}

body {
	margin: 0;
	width: 100vw;
	height: 100vh;
	display: flex;
	align-items: center;
	justify-content: center;
	background: $highlight;
	font-family: "Lato";
	color: $light;
	font-size: 16px;
	font-style: normal;
	font-variant: normal;
	font-weight: 400;
	line-height: 20px;	
}

* {
	box-sizing: border-box;
}

a {
	color: inherit;
	text-decoration: none;
	
	&:visited,
	&:active {
		color: inherit;
	}
}

h4 {
	margin: 0;
}

ul {
	margin: 0;
	padding: 0;
	
	li {
		list-style: none;
	}
}

button {
	color: $white;
	border: 2px solid $light;
	background-color: $light;
	
	padding: 6px 12px;
	border-radius: 3px;
	
	font-family: inherit;
	font-size: inherit;
	font-weight: 700;
	line-height: inherit;
	
	cursor: pointer;
	
	&.icon {
		color: $light;
		border-color: $white;
		background-color: $white;
		font-size: 21px;

		padding: 6px 12px 5px 12px;
		
		&.active {
			color: $white;
			border-color: $primary;
			background-color: $primary;
		}
		
		span {
			margin: 0;
		}
	}	
	
	span {
		margin: 0 5px 0 -5px;	
	}
	
	&.hidden {
		display: none;
	}
	
	&.primary {
		border-color: $primary;
		background-color: $primary;
	}
	
	&.danger {
		border-color: $danger;
		background-color: $danger;
	}	
}

.ui-multiple {
    cursor: crosshair;
}

.filemanager {
	width: 80vw;
	height: 80vh;
	border: 2px solid $border;
	border-radius: 5px;
	background: $white;
	
	display: grid;
	
	@include for-size(phone-only) {
		
		grid-template-rows: 1fr 9fr;
		grid-template-columns: 2fr 8fr;

		grid-template-areas:
			"headleft headmain headmain"
			"left main main";
	}		
	
	@include for-size(tablet-portrait-up) {
		
		grid-template-rows: 1fr 9fr;
		grid-template-columns: 2fr 8fr;

		grid-template-areas:
			"headleft headmain headmain"
			"left main main";
	}	
	
	@include for-size(tablet-landscape-up) {
		
		grid-template-rows: 1fr 9fr;
		grid-template-columns: 2fr 9fr 3fr;

		grid-template-areas:
			"headleft headmain headmain"
			"left main right";
	}		

	
	.filemanager--headerside,
	.filemanager--headermain {
		border-bottom: 2px solid $border;
		display: flex;
		align-items: center;
		justify-content: space-between;		
		
		color: $dark;
		font-weight: 700;
		width: 100%;
		padding: 10px 20px;		
	}
	
	.filemanager--headerside {
		grid-area: headleft;
		
		border-right: 2px solid $border;
	}	
	
	
	.filemanager--sidebar {
		border-right: 2px solid $border;
		
		grid-area: left;
		
		.filemanager--tabs {
			font-weight: 700;
			overflow: auto;
			padding: 20px 0;
			
			grid-area: sidemain;
			
			li {
				position: relative;
				
				span {
						margin-right: 5px;
						vertical-align: middle;
				}				
				
				&.active {
					color: $dark;
					
					a {
						background-color: $highlight;				
					}
					
					&::before {
						position: absolute;
						left: 0;
						top: 0;
						width: 3px;
						height: 100%;
						background-color: $primary;
						content: "";
					}
				}
			}
			
			a {
				display: block;
				padding: 10px 20px;
			}

		}
	}
	
	.filemanager--headermain {
		grid-area: headmain;

		.filemanager--controls {

		}
	}
		
	.filemanager--main {

		display: flex;
		flex-grow: 1;
		overflow: auto;

		grid-column: main;

		.filemanager--files {
			overflow: auto;
			padding: 20px;
			
			&.filemanager--list {
				ul {
					.filemanager--file {
						width: 100%;
						flex-flow: row;
						height: auto;
						
						.filemanager--fileicon {
							width: auto;
							flex-grow: unset;
							margin-right: 20px;
							
							span {
								font-size: 27px;
							}
						}
						
						.filemanager--fileinfo {
							display: flex;
							flex-flow: row;							
							flex-grow: 1;
							width: auto;
							justify-content: space-between;
							padding-right: 30px;
							
						
							div {
								overflow: auto;
								white-space: initial;
								text-overflow: initial;
							}			
						}
					}
				}
			}			

			ul {

			display: flex;
			flex-wrap: wrap;

				.filemanager--file {
					position: relative;
					width: 112px;
					height: 165px;
					border: 2px solid $border;
					border-radius: 5px;
					margin: 0 10px 10px 0;							

					display: flex;
					flex-flow: column;
					align-items: stretch;

					padding: 6px;			
					
					.filemanager--remove {
						position: absolute;
						top: 5px;
						right: 5px;
						width: 20px;
						height: 20px;
						display: flex;
						align-items: center;
						justify-content: center;
						border-radius: 50%;
						border: 2px solid $border;
						padding-top: 1px;
						cursor: pointer;
					}

					&.ui-selecting {
						border-color: $primary;
						color: $primary;
						
						.filemanager--remove {
							border-color: $primary;
						}
						
						.filemanager--fileicon {
							color: $primary;
						}

						.filemanager--fileinfo .filemanager--filename {
							color: $primary;
						}
					}

					&.ui-unselecting {
						border-color: $danger;
						color: $danger;
						
						.filemanager--remove {
							border-color: $danger;
						}
						
						.filemanager--fileicon {
							color: $danger;
						}								

						.filemanager--fileinfo .filemanager--filename {
							color: $danger;
						}
					}							

					&.ui-selected {
						border-color: $primary;
						background-color: $primary;
						color: $white;
						
						.filemanager--remove {
							border-color: $white;
						}

						.filemanager--fileicon {
							color: $white;
						}

						.filemanager--fileinfo .filemanager--filename {
							color: $white;
						}
					}						

					&.doc {
						.filemanager--fileicon span::before {
							content: "\F21A";
						}
					}						

					&.image {
						.filemanager--fileicon span::before {
							content: "\F2E9";
						}
					}

					&.audio {
						.filemanager--fileicon span::before {
							content: "\F759";
						}
					}		

					&.archive {
						.filemanager--fileicon span::before {
							content: "\F5C4";
						}
					}
					
					&.trash {
						
						.filemanager--remove {
							display: none;
						}
						
						.filemanager--fileicon span::before {
							content: "\F1C0";
						}
					}					

					.filemanager--fileicon {
						display: flex;
						flex-grow: 1;
						width: 100%;
						color: $light;

						span {
							font-size: 63px;
							display: flex;
							width: 100%;
							align-items: center;
							justify-content: center;									
						}
					}

					.filemanager--fileinfo {
						width: 100%;
						display: flex;
						flex-flow: column;
						font-weight: 700;

						.filemanager--filename {
							color: $dark;
						}

						div {
							font-size: 13px;
							text-align: center;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;									
						}
					}							
				}
			}
		}
	}

	
	.filemanager--info {
		padding: 20px;
		color: $dark;
		
		border-left: 2px solid $border;

		grid-area: right;

		li {
			height: 50px;
		}
		
		@include for-size(phone-only) {
			display: none;
		}		

		@include for-size(tablet-portrait-up) {
			display: none;
		}	

		@include for-size(tablet-landscape-up) {
			display: flex;
		}
	}	
}
              
            
!

JS

              
                const num = 50;
const files = document.querySelector(".filemanager--files").firstElementChild;
const info = document.querySelector(".filemanager--info").firstElementChild;
const tabs = document.querySelector(".filemanager--tabs");
const controls = document.querySelectorAll(".filemanager--controls");
const btns = Array.from(document.querySelectorAll(".toggle"));
const types = [{type: "audio", ext: ".mp3"}, {type: "image", ext: "jpg"}, {type: "archive", ext: "zip"}, {type: "doc", ext: "txt"}];

let currentFilter = "*";

// Init instance
const SELECTABLE = new Selectable({
	appendTo: ".filemanager--files",
	ignore: ".filemanager--remove", // allow remove buttons to work
});

// Listen for init event
SELECTABLE.on("init", update);

// Listen for update event
SELECTABLE.on("update", update);

// Listen for end event
SELECTABLE.on("end", update);

init();

function init() {
	const frag = document.createDocumentFragment();
	
	for ( let i = 0; i < num; i++ ) {
		frag.appendChild(createFile({
			size: getRandomInt(10, 150),
			name: generateId()
		}));
	}
	
	files.appendChild(frag);
	
	files.addEventListener("click", e => {
		if ( e.target.classList.contains("filemanager--remove") ) {
			var confim = confirm("Remove file?");
			if ( confirm )
				remove(e.target.closest(".filemanager--file"), true);
		}
	}, false);
	
	SELECTABLE.add(".filemanager--file");
	
	tabs.addEventListener("click", e => {
		var node = e.target;
		
		if ( node.nodeName === "A" && "filter" in node.dataset ) {
			
			e.preventDefault();
			
			Array.from(tabs.getElementsByTagName("li")).forEach(el => el.classList.toggle("active", el === node.parentNode));

			filter(node.dataset.filter);
			
			// disable selecting if in recycle bin
			if ( node.dataset.filter === "trash" ) {
				SELECTABLE.disable();
			} else {
				SELECTABLE.enable();
			}
		}
	}, false);
	
	controls[0].addEventListener("click", view);
}

function filter(type) {
	type = type || currentFilter;
	if ( type === "*" ) {
		Array.from(files.children).forEach(node => {
			node.style.display = !node.classList.contains("trash") ? "" : "none";
		});
	} else {
		Array.from(files.children).forEach(node => {
			if ( type === "trash"  ) {
				node.style.display = node.classList.contains("trash") ? "" : "none";
			} else {
				node.style.display = node.classList.contains(type) && !node.classList.contains("trash") ? "" : "none";
			}
		});
	}
	currentFilter = type;
}

function view(e) {
	
	const node = e.target, data = node.dataset;

	if ( "view" in data ) {
		Array.from(controls[0].children).map(el => el.classList.toggle("active", el === node))
		
		files.parentNode.classList.toggle("filemanager--list", data.view === "list");
	}
}

function update() {
	const selected = SELECTABLE.getSelectedItems();
	btns.forEach(btn => btn.classList.toggle("hidden", !selected.length));	
	document.getElementById("filecount").textContent = `${SELECTABLE.items.length} Files (${selected.length} Selected)`
}

function createFile(o) {
	const type = random(types);
	const li = document.createElement("li");
	const template = `
		<div class="filemanager--fileicon">
			<span class="mdi"></span>
		</div>
    <div class="filemanager--remove">&times;</div>
		<div class="filemanager--fileinfo">
			<div class="filemanager--filename">${o.name}.${type.ext}</div>
			<div class="filemanager--filesize">${o.size} ${type.type === "doc" || type.type === "image" ? "KB" : "MB"}</div>
		</div>
`;
	
	li.classList.add("filemanager--file", type.type);
	li.innerHTML = template;
	
	return li;
}

function add() {
	filter("*");
	
	Array.from(tabs.getElementsByTagName("li")).forEach((el, i) => el.classList.toggle("active", i < 1));
	
	const newfile = createFile({
			size: getRandomInt(10, 150),
			name: generateId()
		});
	
	if ( files.childElementCount ) {
		files.insertBefore(newfile, files.firstElementChild);
	} else {
		files.appendChild(newfile);
	}
	
	SELECTABLE.add(newfile);
}

function remove(file, single) {
	let selected = Array.from(document.getElementsByClassName("ui-selected"));
	
	const data = [];
	const els = Array.from(files.children);
	let index = 0;
		
	if ( !file ) {
		if ( selected.length ) {
			file = selected;
		} else {
			file = files.firstElementChild;
		}
	}
	
	if ( files.childElementCount > 0 ) {
		if ( single ) {
			index = els.indexOf(file);
			SELECTABLE.remove(file);
			file.classList.add("trash");
		} else {
			SELECTABLE.remove(selected);
			if ( Array.isArray(file) ) {
				index = selected.length - 1;
				for ( let i = index; i >= 0; i-- ) {
					selected[i].classList.add("trash");
				}
			} else {
				index = els.indexOf(file);
				file.classList.add("trash");
			}

			btns.forEach(btn => btn.classList.add("hidden"));

			info.innerHTML = "";
		}
		
		els.forEach((el, i) => {
			// Only animate the tags proceeding the deleted tag
			if ( i >= index ) {
				data.push({
					el: el,
					position: el.getBoundingClientRect()
				});
			}
		});
		
		filter();
		
		// Animate the tags affected by the change in the DOM
		// when the tag is removed
		data.forEach(function(obj, i) {
			animate(obj);
		});		
	}
}

function invert() {
	if ( files.childElementCount ) {
		SELECTABLE.invert();
		update();
	}
}

function selectAll() {
	if ( files.childElementCount ) {
		SELECTABLE.selectAll();
		update();
	}
}

function clearAll() {
	SELECTABLE.clear();
	update();
	btns.forEach(btn => btn.classList.add("hidden"));
}

function random(arr) {
	return arr[Math.floor(Math.random() * arr.length)];	
}

function getRandomInt(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

// Random filename generation
function generateId(len) {
	len = len || getRandomInt(6,18) / 2;
  var arr = new Uint8Array(parseInt(len, 10));
  window.crypto.getRandomValues(arr)
  return Array.from(arr, dec2hex).join('')
}

// Random filename generation
function dec2hex (dec) {
  return ('0' + dec.toString(16)).substr(-2)
}

// Animate an element's change in position
// caused by a change in the DOM order
function animate(obj) {
	let css = obj.el.style;
	
	// Get the node's positon AFTER the change
	let r = obj.el.getBoundingClientRect();
	
	// Calculate the difference in position
	let x = obj.position.left - r.left;
	let y = obj.position.top - r.top;
	
	// Move the node to it's original position before the DOM change
	css.transform = `translate3d(${x}px, ${y}px, 0px)`;
	
	// Trigger a repaint so the next bit works
	obj.el.offsetHeight;
	
	// Reset the transform, but add a transition so it's smooth
	css.transform = `translate3d(0px, 0px, 0px)`;
	css.transition = `transform 250ms`;

	// Reset the style
	setTimeout(function() {
		css.transform = ``;
		css.transition = ``;
	}, 250);
}
              
            
!
999px

Console