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 id="app">
</div>
              
            
!

CSS

              
                body {
	background: #f4f5f7;
	font-family: helvetica, arial;
}

.Toggles {
	margin-top: 50px;
}

.toggleHolder {
	text-align: center;
}

	.toggleHolder h3, .toggleHolder p {
		text-align: center;
		margin: 5px;
		color: rgba(0, 0, 0, .8)
	}

	.toggleWrapper {
			width: 100%;
	}

	.toggleWrapper .toggleLabel {
			width: 50px;
			display: inline-block;
	}

			.toggleWrapper .toggleLabel p {
					color: rgba(0, 0, 0, .5);
					overflow: hidden;
					transition: all .3s ease-in-out;
			}

					.toggleWrapper .toggleLabel.active p {
							color: rgba(0, 0, 0, .8)
					}

	.toggle {
			display: inline-block;
			width: 50px;
			height: 25px;
			border-radius: 100px;
			position: relative;
			margin: auto;
			overflow: hidden;
			border: solid 1px rgba(0, 0, 0, .3);
			transition: all .3s ease-in-out;
			cursor: pointer;
	}

			.toggle.active {
				border: solid 1px #00cf67;
			}

			.toggle .inside {
					width: 75%;
					height: 100%;
					border-radius: 100px;
					background: rgba(0, 0, 0, .3);
					position: absolute;
					left: -25%;
					transition: all .3s ease-in-out;
			}

			.toggle.active .inside {
					left: 50%;
					background: #00cf67;
			}
              
            
!

JS

              
                /*
		A customizeable React toggle component.  All parameters are optional.
		@parameters: onToggle - A function to call anytime the component is toggled
								 activeLabel - The label to display on the active side
								 deactiveLabel - The label to display on the deactive side
								 activeColor - The color to make the toggle when active
								 deactiveColor - The color to make the toggle when deactive
								 borderMatch - Whether to match border color with activeColor and deactiveColor
*/

/*!
  Copyright (c) 2016 Jed Watson.
  Licensed under the MIT License (MIT), see
  https://jedwatson.github.io/classnames
*/
/* global define */

(function () {
	'use strict';

	var hasOwn = {}.hasOwnProperty;

	function classNames () {
		var classes = [];

		for (var i = 0; i < arguments.length; i++) {
			var arg = arguments[i];
			if (!arg) continue;

			var argType = typeof arg;

			if (argType === 'string' || argType === 'number') {
				classes.push(arg);
			} else if (Array.isArray(arg)) {
				classes.push(classNames.apply(null, arg));
			} else if (argType === 'object') {
				for (var key in arg) {
					if (hasOwn.call(arg, key) && arg[key]) {
						classes.push(key);
					}
				}
			}
		}

		return classes.join(' ');
	}

	if (typeof module !== 'undefined' && module.exports) {
		module.exports = classNames;
	} else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {
		// register as 'classnames', consistent with npm package name
		define('classnames', [], function () {
			return classNames;
		});
	} else {
		window.classNames = classNames;
	}
}());

/* App Start */

const {Component} = React

class Toggle extends Component {
	
	constructor(props) {
		super(props);
		this.state = {
			toggle: false
		}
		this.toggleState = this.toggleState.bind(this);
		this.insideStyles = this.insideStyles.bind(this);
		this.toggleStyles = this.toggleStyles.bind(this);
	 }
	
	getInitialState() {
		return ({
			state: false
		})
	}
	
	toggleState() {
		this.setState({
			toggle: !this.state.toggle
		})
		if (this.props.onToggle) {
			this.props.onToggle(!this.state.toggle ? this.props.activeLabel || !this.state.toggle : this.props.deactiveLabel || !this.state.toggle)
		}
	}
	
	insideStyles() {
		return ({
			background: this.state.toggle ? typeof this.props.activeColor !== "undefined" ? this.props.activeColor : "" : typeof this.props.deactiveColor !== "undefined" ? this.props.deactiveColor : ""
		})
	}
	
	toggleStyles() {
		if (!typeof this.props.borderMatch !== "undefined" && this.props.borderMatch) {
			return ({
				border: this.state.toggle ? typeof this.props.activeColor !== "undefined" ? "solid 1px " + this.props.activeColor : "" : typeof this.props.deactiveColor !== "undefined" ? "solid 1px " + this.props.deactiveColor : ""
			})
		}
	}
	
	render() {
		return (
			<div className="toggleHolder">
					<h3>{this.props.heading}</h3>
					<div className="toggleWrapper" onClick={this.toggleState}>
							<div className={classNames("toggleLabel", {active: !this.state.toggle})}>
									<p>{this.props.deactiveLabel || ""}</p>
							</div>
							<div className={classNames("toggle", {active: this.state.toggle}, {deactive: !this.state.toggle})} style={this.toggleStyles()}>
									<div className="inside" style={this.insideStyles()}>
									</div>
							</div>
							<div className={classNames("toggleLabel", {active: this.state.toggle})}>
									<p>{this.props.activeLabel || ""}</p>
							</div>
					</div>
			</div>
		)
	}
}

class App extends Component {
	
	constructor(props) {
		super(props)
		this.toggle = this.toggle.bind(this)
	}
	
	toggle(val) {
		alert(val)
	}
	
	render() {
		return (
			<div className="Toggles">
				<Toggle heading={"Custom Labels"} activeLabel={"Yes"} deactiveLabel={"No"} />
				<Toggle />
				<Toggle heading={"Custom Colors"} activeColor={"#17cae6"} deactiveColor={"#d72ee6"} borderMatch={true} />
				<Toggle activeColor={"#f7ff71"} deactiveColor={"#ff71cb"} borderMatch={false} />
				<Toggle heading={"Custom Toggle Callback"} onToggle={this.toggle} />
				<Toggle onToggle={this.toggle} activeLabel={"Steak"} deactiveLabel={"Chicken"} activeColor={"#17cae6"} deactiveColor={"#17cae6"} />
			</div>
		)
	}
}

ReactDOM.render(<App />, document.getElementById('app'))
              
            
!
999px

Console