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

              
                body
	div#content
              
            
!

CSS

              
                // Variables
// =========
$dark:				#000411
$black:				#353535
$white:				#FCFCFC
$gray:				#F1FFFA
$green:				#3DDC97
$red:					#FF495C

$off-state: 	$red
$on-state: 		$green

$react-blue:	#61dafb

// Mixins
// ======

@mixin flex($dir: row, $wrap: nowrap, $justify: center, $align: center)
	display: flex
	flex-flow: $dir $wrap
	justify-content: $justify
	align-items: $align


// Base
// ====

\:root
	font-size: 20px

body
	width: 100%
	height: 100vh
	user-select: none

// Modules

.component-wrapper
	width: 100%
	height: 100vh
	@include flex(column, wrap, space-around)
	background-color: $dark
	transition: background-color 200ms ease-out

.header
	font-size: 3rem
	font-family: "Helvetica Neue", Helvetica, sans-serif
	color: $dark

.switch
	position: relative
	width: 8rem
	height: 5rem
	border-radius: 20%
	transition: background-color 100ms ease-out
	z-index: 1
	&:before, &:after
		content: ""
		position: absolute
		top: 0
		background-color: inherit
		border-radius: 50%
		width: 5rem
		height: 5rem
		z-index: 2
	&:before
		left: -1rem
	&:after
		right: -1rem
	
.toggle-button
	position: absolute
	width: 5rem
	height: 5rem
	background-color: $black
	border-radius: 50%
	transition: transform 100ms ease-in-out
	z-index: 3
	border: 0.05rem solid $black
	top: -0.05rem

// State

.component-wrapper_is-light
	background-color: $white
	
component-wrapper_is-dark
	background-color: $dark

.header_is-lit
	color: $react-blue
	text-shadow: 0

.header_is-dark
	color: $dark
	text-shadow: 0 0 3rem $react-blue

.switch_is-off
	background-color: $off-state

.switch_is-on
	background-color: $on-state

.toggle-button_position-left
	transform: translateX(-1.05rem)

.toggle-button_position-right
	transform: translateX(4.05rem)
              
            
!

JS

              
                class ComponentWrapper extends React.Component {
	constructor(props) {
		super(props);
		this.state = {isOn: false};
	}
	
	handleToggle(e) {
		this.setState({isOn: !this.state.isOn});
	}
	
	render() {
		let classNames = ["component-wrapper", (this.state.isOn) ? "component-wrapper_is-light" : "component-wrapper_is-dark"].join(" ");
		return (
			<div className={classNames}>
				<Header 
					isOn={this.state.isOn}	
				/>
				<Switch 
					isOn={this.state.isOn}	
					handleToggle={this.handleToggle.bind(this)}
				/>
			</div>		
		);
	}
}

const Header = function(props) {
	let classNames = ["header", (props.isOn) ? "header_is-lit" : "header_is-dark"].join(" ");
	return (
		<h1 className={classNames}>React</h1>
	);
}

const Switch = function(props) {
	let classNames = ["switch", (props.isOn) ? "switch_is-on" : "switch_is-off"].join(" ");
	return (
		<div className={classNames} onClick={props.handleToggle}>
			<ToggleButton 
				isOn={props.isOn}	
			/>
		</div>
	);
}

const ToggleButton = function(props) {
		let classNames = ["toggle-button", (props.isOn) ? "toggle-button_position-right" : "toggle-button_position-left"].join(" ");
		return (<div className={classNames}></div>);
};

ReactDOM.render(<ComponentWrapper />, document.getElementById("content"));
              
            
!
999px

Console