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

              
                <section>
	<div class="lists">
		<div class="list-container">
			<h4>Default</h4>
			<ol id="list" class="list">
				<li data-id="1" data-foo="bar" class="item">Item 1</li>
				<li data-id="2" class="item">Item 2
					<ol>
						<li data-id="3" class="item">Item 3</li>
						<li data-id="4" class="item">Item 4
							<ol>
								<li data-id="5" class="item">Item 5</li>
								<li data-id="6" class="item">Item 6</li>
							</ol>					
						</li>
					</ol>
				</li>
				<li data-id="7" class="item">Item 7</li>
				<li data-id="8" class="item">Item 8</li>
				<li data-id="9" class="item">Item 9</li>
				<li data-id="10" class="item">Item 10</li>
				<li data-id="11" class="item">
					Item 11
					<ol>
						<li data-id="12" class="item">Item 12</li>
					</ol>					
				</li>
			</ol>
		</div>
		<div class="list-container">
			<h4>Custom Handles</h4>
			<ol id="list2" class="list">
				<li data-id="1" data-foo="bar" class="item"><div class="nst-handle custom-handle"><span class="mdi mdi-menu"></span></div> Item 1</li>
				<li data-id="2" class="item"><div class="nst-handle custom-handle"><span class="mdi mdi-menu"></span></div> Item 2
					<ol>
						<li data-id="3" class="item"><div class="nst-handle custom-handle"><span class="mdi mdi-menu"></span></div> Item 3</li>
						<li data-id="4" class="item"><div class="nst-handle custom-handle"><span class="mdi mdi-menu"></span></div> Item 4
							<ol>
								<li data-id="5" class="item"><div class="nst-handle custom-handle"><span class="mdi mdi-menu"></span></div> Item 5</li>
								<li data-id="6" class="item"><div class="nst-handle custom-handle"><span class="mdi mdi-menu"></span></div> Item 6</li>
							</ol>					
						</li>
					</ol>
				</li>
				<li data-id="7" class="item"><div class="nst-handle custom-handle"><span class="mdi mdi-menu"></span></div> Item 7</li>
				<li data-id="8" class="item"><div class="nst-handle custom-handle"><span class="mdi mdi-menu"></span></div> Item 8</li>
				<li data-id="9" class="item"><div class="nst-handle custom-handle"><span class="mdi mdi-menu"></span></div> Item 9</li>
				<li data-id="10" class="item"><div class="nst-handle custom-handle"><span class="mdi mdi-menu"></span></div> Item 10</li>
				<li data-id="11" class="item"><div class="nst-handle custom-handle"><span class="mdi mdi-menu"></span></div> 
					Item 11
					<ol>
						<li data-id="12" class="item"><div class="nst-handle custom-handle"><span class="mdi mdi-menu"></span></div> Item 12</li>
					</ol>					
				</li>
			</ol>
		</div>
		<div class="list-container">
			<h4>Custom Icons</h4>
			<ol id="list3" class="list">
				<li data-id="1" data-foo="bar" class="item">Item 1</li>
				<li data-id="2" class="item">Item 2
					<ol>
						<li data-id="3" class="item">Item 3</li>
						<li data-id="4" class="item">Item 4
							<ol>
								<li data-id="5" class="item">Item 5</li>
								<li data-id="6" class="item">Item 6</li>
							</ol>					
						</li>
					</ol>
				</li>
				<li data-id="7" class="item">Item 7</li>
				<li data-id="8" class="item">Item 8</li>
				<li data-id="9" class="item">Item 9</li>
				<li data-id="10" class="item">Item 10</li>
				<li data-id="11" class="item">
					Item 11
					<ol>
						<li data-id="12" class="item">Item 12</li>
					</ol>					
				</li>
			</ol>
		</div>
	</div>
	<div class="lists">
		<div class="list-container">
			<h4>Collpased Items</h4>
			<ol id="list4" class="list">
				<li data-id="1" data-foo="bar" class="item">Item 1</li>
				<li data-id="2" class="item nst-collapsed">Item 2
					<ol>
						<li data-id="3" class="item">Item 3</li>
						<li data-id="4" class="item nst-collapsed">Item 4
							<ol>
								<li data-id="5" class="item">Item 5</li>
								<li data-id="6" class="item">Item 6</li>
							</ol>					
						</li>
					</ol>
				</li>
				<li data-id="7" class="item">Item 7</li>
				<li data-id="8" class="item">Item 8</li>
				<li data-id="9" class="item">Item 9</li>
				<li data-id="10" class="item">Item 10</li>
				<li data-id="11" class="item nst-collapsed">
					Item 11
					<ol>
						<li data-id="12" class="item">Item 12</li>
					</ol>					
				</li>
			</ol>
		</div>
		<div class="list-container">
			<h4>Disabled Items</h4>
			<ol id="list5" class="list">
				<li data-id="1" data-foo="bar" class="item">Item 1</li>
				<li data-id="2" class="item">Item 2
					<ol>
						<li data-id="3" class="item">Item 3</li>
						<li data-id="4" class="item" data-nestable-disabled>Item 4
							<ol>
								<li data-id="5" class="item">Item 5</li>
								<li data-id="6" class="item">Item 6</li>
							</ol>					
						</li>
					</ol>
				</li>
				<li data-id="7" class="item">Item 7</li>
				<li data-id="8" class="item" data-nestable-disabled>Item 8</li>
				<li data-id="9" class="item">Item 9</li>
				<li data-id="10" class="item" data-nestable-disabled>Item 10</li>
				<li data-id="11" class="item">
					Item 11
					<ol>
						<li data-id="12" class="item" data-nestable-disabled>Item 12</li>
					</ol>					
				</li>
			</ol>
		</div>
		<div class="list-container">
			<h4>Animation</h4>
			<ol id="list6" class="list">
				<li data-id="1" data-foo="bar" class="item">Item 1</li>
				<li data-id="2" class="item">Item 2
					<ol>
						<li data-id="2-1" class="item">Item 2-1</li>
						<li data-id="2-2" class="item">Item 2-2
							<ol>
								<li data-id="2-2-1" class="item">Item 2-2-1</li>
								<li data-id="2-2-2" class="item">Item 2-2-2</li>
							</ol>					
						</li>
					</ol>
				</li>
				<li data-id="3" class="item">Item 3</li>
				<li data-id="4" class="item">Item 4</li>
				<li data-id="5" class="item">Item 5</li>
				<li data-id="6" class="item">Item 6</li>
				<li data-id="7" class="item">Item 7</li>
				<li data-id="8" class="item">Item 8
					<ol>
						<li data-id="8-1" class="item">Item 8-1</li>
					</ol>
				</li>
			</ol>
		</div>		
	</div>
	<div class="lists">
		<div class="list-container">

		</div>
		<div class="list-container">
			<h4>Confined Items</h4>
			<ol id="list8" class="list">
				<li data-id="1" data-foo="bar" class="item">Item 1</li>
				<li data-id="2" class="item">Item 2
					<ol>
						<li data-id="2-1" class="item">Item 3</li>
						<li data-id="2-2" class="item" id="nest1">Item 4
							<ol>
								<li data-id="2-2-1" class="item" data-nestable-parent="nest1">Item 5 <span class="label">Confined to Item 4</span></li>
								<li data-id="2-2-2" class="item" data-nestable-parent="nest1">Item 6 <span class="label">Confined to Item 4</span></li>
							</ol>
						</li>
					</ol>
				</li>
				<li data-id="3" class="item">Item 7</li>
				<li data-id="4" class="item">Item 8</li>
				<li data-id="5" class="item" id="nest2">Item 9
					<ol>
						<li data-id="6" class="item" data-nestable-parent="nest2">Item 10
						<span class="label">Confined to Item 9</span>
						</li>
					</ol>
				</li>
				<li data-id="7" class="item">Item 11</li>
				<li data-id="8" class="item">Item 12</li>
			</ol>
		</div>
		<div class="list-container">

		</div>		
	</div>	
</section>

<!-- <textarea name="" id="output" cols="60" rows="20"></textarea> -->
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css?family=Inconsolata:400,700");
@import url("https://fonts.googleapis.com/css?family=Roboto:400,400i,700");
body {
  margin: 0;
  width: 100vw;
  display: flex;
	overflow-x: hidden;
  justify-content: center;
	font-family: "Inconsolata";
}

ul, ol {
	padding: 0;
	margin: 0;
	width: 100%;
	box-sizing: border-box;
	
	li {
		width: 100%;
	}
}

section {
	margin-top: 10vh;
	width: 80vw;
	display: flex;
	align-items: center;
	justify-content: start;
	flex-flow: column;
}

.lists {
	display: flex;
}

.list {
	width: 400px;
	margin: 0 20px;
}

.nst-list {
	li {
		list-style: none;
	}
}

.nst-parent.nst-disabled {
	opacity: 0.6;
	cursor: not-allowed;
	
	.nst-content, .nst-item .nst-button {
		cursor: not-allowed;
	}
}

[data-nestable-disabled] {
	& > .nst-content {
		opacity: 0.6;
		cursor: not-allowed;
		// background-color: #FFEBEE;
	}
}

.nst-error.nst-placeholder {
	border-color: #B71C1C;
	background-color: #FFEBEE;
	position: relative;
	
	&::after {
		position: absolute;
		left: 4px;
		top: 3px;
		color: #B71C1C;
		font-size: 21px;
		font-family: "Material Design Icons";
		content: "\F5D6";
	}

}

.nst-item.nst-error > .nst-content {
	border-color: #B71C1C;
	background-color: #FFEBEE;
}

.nst-item {
	position: relative;
	
	.nst-button {
    position: absolute;
    width: 20px;
    height: 20px;
    top: 5px;
    background-color: transparent;
    border: none;
    padding: 0;
    left: 7px;
		font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
		cursor: pointer;
		font-family: "Roboto";
	}
	
	&.nst-collapsed {
		.nst-list {
				display: none;
		}
	}
}

.nst-dragging {
	// opacity: 0.6;
}


.nst-container {
	 position: absolute;
	
	.nst-item .nst-content {
		box-shadow: 0px 0px 3px 0px rgba(0,0,0,0.4);
	}
}

.nst-content {
	border: 1px solid #999;
	border-radius: 0px;
	padding: 6px 12px 6px 30px;
	margin-bottom: 5px;
	background-color: #fff;

	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.nst-handle {
	cursor: move;	
}

.nst-placeholder {
	border: 1px dashed #999;
	border-radius: 0px;
	margin-bottom: 5px;
	box-sizing: border-box;
	background-color: #E1F5FE;
	box-sizing: border-box;
}

li {
	& > ul, & > ol {
		padding-left: 20px;
		box-sizing: border-box;
	}
}

#output {
	position: fixed;
	top: 0;
	right: 0;
}

.custom-handle {
    position: absolute;
    padding: 7px 10px;
}

#list2, #nestable_2 {
	.nst-item .nst-button {
		right: 10px;
		left: auto;
	}	
	.nst-content {
		padding-left: 50px;
		padding-right: 35px;
	}
}

#list3 {
	.nst-item .nst-button::before {
		position: absolute;
		top: 0px;
		width: 100%;
		height: 100%;
		font-family: "Material Design Icons";
		content: "\F140";
	}
	
	.nst-item.nst-collapsed .nst-button::before {
		content: "\F142";
	}	
}

.tall {
	// width: 250px;
}

.tall  > .nst-content {
	height: 50px;
	display: flex;
	align-items: center;
}

.nst-item.tall > .nst-button {
	top: 22px;
}

.text-faded {
	opacity: 0.4;
	// float: right;
}

.label {

    background-color: #90CAF9;
    color: #fff;
    padding: 3px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: bold;

}

/* CUSTOM DAT.GUI */

@import url('https://fonts.googleapis.com/css?family=Roboto+Mono:400,700');
@import url("//cdn.materialdesignicons.com/2.0.46/css/materialdesignicons.min.css");

/* CUSTOM DAT GUI STYLE */

$dark: #38354a;
$darker: #2b2838;
$light: #514d6a;
$primary: #01a8fe;
$font: #514d6a;
.dg {
  font: 11px "Roboto Mono",sans-serif !important;
	color: lighten($light, 50) !important;
}

.dg.ac {
  top: 10px !important;
}

.dg.main {
	padding: 15px 15px 35px 15px  !important;
	border-radius: 5px  !important;
	background-color: #2b2838 !important;
}

.dg li {
  box-sizing: border-box;
}

.dg ul li:last-child {
  margin-bottom: 10px;
}

.dg li:not(.folder) {
	background: $darker !important;
	padding: 0 4px 0 10px;
}

.dg li.title {
	background: $darker !important;
	border-bottom: none !important;
	color: lighten(#827ca1, 30) !important;
	margin: 10px 0;
	background-color: darken($darker, 5) !important;
	border-radius: 3px;
}

.dg li.folder:first-child .title {
	margin-top: 0px;
}

.dg li.folder:last-child {
	margin-bottom: 10px;
}

.dg.main .close-button {
	color: lighten(#827ca1, 30) !important;
	background-color: darken($darker, 5) !important;
}

.dg .c .slider {
  background: darken($darker, 5) !important;
}

.dg .c input[type="text"] {
  background: darken($darker, 5) !important;
}
.dg .cr.number input[type="text"] {
	color: lighten($light, 50) !important;
}

.dg .c .slider-fg {
    background: $primary !important;
}
              
            
!

JS

              
                const config = {
	items: ".item",

};

const instances = [
	new Nestable("#list", config),

	new Nestable("#list2", config),

	new Nestable("#list3", Object.assign({}, config, {
		collapseButtonContent: "",
		expandButtonContent: "",		
	})),
	new Nestable("#list4", config),
	new Nestable("#list5", config),
	new Nestable("#list6", Object.assign({}, config, {
		animation: 150		
	})),
	new Nestable("#list8", {
		items: ".item",	
	}),	
];

// update the nesting labels
function change(instance) {
		recur(instance.parent)

		function recur(element, id, index) {
			id = id || "";
			index = index || "";
			if (element.tagName === "LI") {
				let content = element.querySelector(".nst-content");
				
				if ( !content ) {
					content = instance.active.node.querySelector(".nst-content");
				}
				
				if ( !element._originalContent ) {
					element._originalContent = content.textContent;
				}
				
				
				id = id ? (id + "." + index) : index;
				content.innerHTML = `${element._originalContent} <span class="text-faded">${id}</span>`;
				element.dataset.id = id;
			}
			[].slice.call(element.children).forEach(function(el, ind) {
				ind++;
				recur(el, id, ind);
			})
		}	
}


const lists = document.querySelectorAll(".list");
const options = {
	expandAll: () => {
		instances.forEach(instance => instance.expandAll());
	},
	collapseAll: () => {
		instances.forEach(instance => instance.collapseAll());
	},
	lists: [],
}

function notify(message) {
	Toastify({
		text: message,
		duration: 3000,
		position: "center",
		backgroundColor: "#C51162"
	}).showToast();
}

for ( const instance of instances ) {
	
	instance.on("init", () => {
		change(instance);
	});
	
	instance.on("nest", () => {
		change(instance);
	});	
	
	instance.on("unnest", () => {
		change(instance);
	});		
	
	instance.on("reorder", () => {
		change(instance);
	});		
	
	instance.on("error.maxdepth", (el, max) => {
		notify(`Max nesting depth (${max}) reached!`);
	});

	instance.on("error.disabled", () => {
		notify("Can't nest in disabled list!");
	});

	instance.on("error.collapsed", () => {
		notify("Can't nest in collpased list!");
	});

	instance.on("error.confined", (item, parent, newParent) => {
		parent.classList.add("nst-error");
		notify(`Item is confined to element ${parent.querySelector(".nst-content").textContent} (#${parent.id})!`);
	});

	instance.on("stop", (data) => {
		instance.parent.querySelectorAll(".nst-error").forEach(el => el.classList.remove("nst-error"));
		
		change(instance);
	});
	
	
	options.lists.push({
		maxDepth: instance.config.maxDepth,
		expandAll: () => {
			instance.expandAll();
		},
		collapseAll: () => {
			instance.collapseAll();
		},
		enabled: !instance.disabled,
		init: () => {
			instance.init();
		},		
		destroy: () => {
			instance.destroy();
		},
	})
}

const gui = new dat.GUI();

for ( const [i, instance] of instances.entries() ) {
	const f = gui.addFolder(`List ${i + 1}`);
	f.add(instances[i].config, "maxDepth").step(1).min(0).max(10);
	f.add(options.lists[i], "enabled").onChange(bool => {
		if ( bool ) {
			instance.enable();
		} else {
			instance.disable();
		}
	});
	f.add(options.lists[i], "expandAll");
	f.add(options.lists[i], "collapseAll");
	f.add(options.lists[i], "init");
	f.add(options.lists[i], "destroy");
	
	if ( i === 0 ) {
		f.open();
	}
}

              
            
!
999px

Console