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

              
                * {
  margin: 0;
  padding: 0;
  box-sizing: border-box; 
}

input[type="submit"],
button {
  -webkit-appearance: none;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  padding: 0; }

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

a {
  text-decoration: none; }

input[type="text"]:focus, input[type="text"]:active,
input[type="email"]:focus,
input[type="email"]:active,
input[type="password"]:focus,
input[type="password"]:active,
input[type="submit"]:focus,
input[type="submit"]:active {
  outline: none; }

input[type="submit"] {
  border: none; }

/*18px*/
/*14px*/
/*12px*/
h1, h2, h3 {
  font-weight: 500; }

h4, h5, h6 {
  font-weight: 400; }

h1 {
  font-size: 1.125rem;
  margin: 1rem 0; }

h2 {
  font-size: 16px;
  margin: 0.875rem 0; }

h3 {
  font-size: 0.875rem;
  margin: 0.75rem 0; }

/*
h4 {
	
}
h5 {
	
}
h6 {
	
}
*/
a {
  color: #26A69A; }

body {
  font-family: 'Roboto', sans-serif;
  font-size: 16px;
  line-height: 1.4;
  font-weight: 400;
  color: #4A4A4A;
  background: #ECF3F7; }

.container {
  max-width: 600px;
  width: 100%;
  margin: 0 auto; }

.list__actions span, .list__actions:before, .list__actions:after {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 50%;
  width: 5px;
  height: 5px;
  margin-left: 4px; }

.list__actions {
  width: 24px;
  height: 5px;
  text-align: center;
  cursor: pointer; }
  .list__actions span {
    display: inline-block;
    vertical-align: top; }
  .list__actions:before, .list__actions:after {
    content: "";
    display: inline-block;
    vertical-align: top; }
  .list__actions:before {
    margin: 0; }

.clearfix:after, .list__item:after {
  content: "";
  clear: both;
  display: block;
  height: 0;
  visibility: hidden; }

.float--left {
  float: left !important; }

.float--right {
  float: right !important; }

.is--hide {
  display: none !important; }

.is--show {
  display: block !important; }

.is--hidden {
  visibility: hidden !important; }

.is--visible {
  visibility: visible !important; }

.text--lg {
  font-size: 1.125rem !important; }

.text--sm {
  font-size: 0.875rem !important; }

.text--xs {
  font-size: 0.75rem !important; }

.text--reg {
  font-weight: 400 !important; }

.text--bold {
  font-weight: 500 !important; }

.spacer {
  margin: 1rem 0 !important; }

.spacer--lg {
  margin: 1.125rem 0 !important; }

.spacer--sm {
  margin: 0.875rem 0 !important; }

.spacer--xs {
  margin: 0.75rem 0 !important; }

.spacer--0 {
  margin: 0 !important; }

.spacer--top--xs {
  margin-top: 0.75rem !important; }

.important {
  color: #FF5252 !important; }

.list {
  display: block; }
  .list__item {
    position: relative;
    width: 100%;
    height: 60px;
    margin: 0 0 1px;
    border-radius: 2px;
    background: rgba(239, 83, 80, 0.85); }
    .list__item:last-child {
      margin: 0; }
    .list__item.disabled:before {
      content: "";
      display: block;
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: rgba(255, 255, 255, 0.7);
      z-index: 10; }
    .list__item.pink {
      background: rgba(240, 98, 146, 0.85); }
    .list__item.purple {
      background: rgba(126, 87, 194, 0.85); }
    .list__item.blue {
      background: rgba(66, 165, 245, 0.85); }
    .list__item.green {
      background: rgba(77, 208, 225, 0.85); }
    .list__item.yellow {
      background: #FFE082; }
  .list__checkbox {
    position: relative;
    float: left;
    width: 60px;
    height: 100%;
    border-right: 1px solid #FFFFFF;
    text-align: center;
    z-index: 11; }
    .list__checkbox input[type="checkbox"] {
      position: relative;
      height: 100%;
      top: 50%;
      transform: translateY(-50%);
      font-size: 1.125rem; }
  .list__name {
    position: relative;
    float: left;
    width: calc(100% - 60px); }
  .list__text {
    font-size: 1.125rem;
    color: #FFFFFF;
    line-height: 60px;
    padding: 0 0 0 25px; }
  .list__form {
    position: absolute;
    top: 5px;
    left: 12px;
    margin: 0;
    width: calc(100% - 25px);
    z-index: 10;
    display: none; }
    .list__form .colorSelector {
      right: 95px; }
  .list__actions {
    position: absolute;
    right: 25px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 9; }
    .list__actions + .dropdown {
      z-index: 100; }

.dropdown {
  position: absolute;
  top: calc(50% + 10px);
  right: -37px;
  width: 150px;
  background: #FFFFFF;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  z-index: 10;
  display: none; }
  .dropdown:before {
    content: "";
    position: absolute;
    top: -5px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-bottom: 5px solid #FFFFFF; }
  .dropdown__item {
    display: block;
    border-bottom: 1px solid #EEEEEE; }
    .dropdown__item:last-child {
      border: none; }
  .dropdown__link {
    display: block;
    width: 100%;
    padding: 12px 20px;
    font-size: 0.875rem;
    color: #4A4A4A; }

.button, input[type="submit"] {
  display: block;
  height: 35px;
  padding: 0 20px;
  color: #FFFFFF;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 35px;
  background: #26A69A;
  border-radius: 2px;
  border-bottom: 2px solid #00897B; }
  .button:active, input[type="submit"]:active {
    border-width: 0; }

form {
  position: relative;
  margin: 1rem 0; }

input[type="text"],
input[type="email"],
input[type="password"] {
  border-radius: 4px;
  border: 1px solid #DCDCDC;
  padding: 0 20px;
  color: #4A4A4A; }

textarea {
  border-radius: 4px;
  border: 1px solid #DCDCDC;
  padding: 5px 10px; }

input[type="submit"] {
  cursor: pointer; }

.form__inputText--lg {
  width: 100%;
  height: 50px;
  font-size: 16px; }

input[type="text"].form__inputText--addItem {
  padding-right: 220px; }

.form__inputSubmit--inside {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%); }

.colorSelector {
  position: absolute;
  height: 16px;
  right: 90px;
  top: 50%;
  transform: translateY(-50%); }
  .colorSelector__inputRadio {
    position: relative;
    display: inline-block;
    vertical-align: top;
    width: 16px;
    height: 16px;
    font-size: 16px;
    margin: 0 6px 0 0;
    visibility: hidden; }
    .colorSelector__inputRadio:after {
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      width: 16px;
      height: 16px;
      border-radius: 2px;
      visibility: visible; }
    .colorSelector__inputRadio:last-child {
      margin: 0; }
    .colorSelector__inputRadio.checked:after {
      border: 1px solid #CCCCCC;
      box-shadow: inset 0 0 0 1px #FFFFFF;
      top: -1px;
      left: -1px; }
    .colorSelector__inputRadio.red:after {
      background: rgba(239, 83, 80, 0.85); }
    .colorSelector__inputRadio.pink:after {
      background: rgba(240, 98, 146, 0.85); }
    .colorSelector__inputRadio.purple:after {
      background: rgba(126, 87, 194, 0.85); }
    .colorSelector__inputRadio.blue:after {
      background: rgba(66, 165, 245, 0.85); }
    .colorSelector__inputRadio.green:after {
      background: rgba(77, 208, 225, 0.85); }
    .colorSelector__inputRadio.yellow:after {
      background: #FFE082; }
              
            
!

JS

              
                var INIT_ITEMS = [
	{
		name: 'Todo item 1',
		color: '',
		checked: false,
		edit: false,
		id: 1
	},
	{
		name: 'Todo item 2',
		color: 'pink',
		checked: false,
		edit: false,
		id: 2
	},
	{
		name: 'Todo item 3',
		color: 'purple',
		checked: false,
		edit: false,
		id: 3
	}
];

var COLORS = [
	{
		name: 'red',
		checked: true,
		id: 1,
	},
	{
		name: 'pink',
		checked: false,
		id: 2,
	},
	{
		name: 'purple',
		checked: false,
		id: 3,
	},
	{
		name: 'blue',
		checked: false,
		id: 4,
	},
	{
		name: 'green',
		checked: false,
		id: 5,
	},
	{
		name: 'yellow',
		checked: false,
		id: 6,
	}
];

var itemId = 4;

function getIndex(value, arr, prop) {
  for(var i = 0; i < arr.length; i++) {
    if(arr[i][prop] === value) {
        return i;
    }
  }
  return -1; //to handle the case where the value doesn't exist
}

var Header = React.createClass({
	propTypes: ({
		title: React.PropTypes.string.isRequired,
		checkedItemsFlag: React.PropTypes.bool.isRequired,
		handleDeleteItems:  React.PropTypes.func.isRequired,
		number: React.PropTypes.number,
	}),

	getDefaultProps: function(){
		return {
			title: 'React Todo List 🐶',
		}
	},

	handleClick: function(e){
		e.preventDefault();
		this.props.handleDeleteItems();
	},

	render: function(){
		var showLinkClass = this.props.checkedItemsFlag ? 'is--visible' : '';
		var number = this.props.number;
		return (
			<header>
				<h1 className="clearfix">
					{this.props.title}
					<a
						className={`float--right text--xs spacer--top--xs text--reg is--hidden ${showLinkClass}`}
						href="#"
						onClick={this.handleClick}>
						Clear Completed Items ({number})
					</a>
				</h1>
			</header>
		);
	}
});


var AddItemForm = React.createClass({

	propTypes: {
		onAdd: React.PropTypes.func.isRequired,
		colorList: React.PropTypes.array.isRequired,
	},
	
	getInitialState: function(){
		return {
			name: '',
			color: 'red',
		}
	},

	onSubmit: function(e){
		e.preventDefault();

		var name = this.state.name;
		var color = this.state.color;

		if(name != ''){
			this.props.onAdd(name, color);
			this.setState({
				name: '',
				color: 'red'
			});
		}
	},

	onNameChange: function(e){
		this.state.name = e.target.value;
		this.setState(this.state);
	},

	onColorChange: function(e){
		this.state.color = e.target.getAttribute('data-color');
		this.setState(this.state);
	},

	render: function(){

		var radios = this.props.colorList.map(function(color, index){
			if(this.state.color == color.name){
				color.checked = true;
			}else {
				color.checked = false;
			}
			var checkedClass = color.checked ? 'checked' : '';
			return (
				<input type="radio" onChange={this.onColorChange} className={`colorSelector__inputRadio ${color.name} ${checkedClass}`} name="selectedColor" data-color={color.name} key={color.id} />
			);
		}.bind(this));

		return (
			<form onSubmit={this.onSubmit}>
				<input className="form__inputText--lg form__inputText--addItem" type="text" name="name" value={this.state.name} onChange={this.onNameChange} placeholder="Add New Item" />
				<div className="colorSelector">
					{radios}
				</div>
				<input className="form__inputSubmit--inside" type="submit" value="Add" />
			</form>
		);
	}
});


var EditItemForm = React.createClass({
	propTypes: {
		editMode: React.PropTypes.bool.isRequired,
		val: React.PropTypes.string.isRequired,
		colorList: React.PropTypes.array.isRequired,
		color: React.PropTypes.string,
	},

	getInitialState: function(){
		return {
			newName: this.props.val,
			newColor: this.props.color,
		}
	},
	componentWillReceiveProps: function(nextProps){
		if(nextProps.editMode === false){
			this.setState({ 
				newName: nextProps.val,
				newColor: nextProps.color,
			});
		}
	},
	onValueChange: function(e){
		this.state.newName = e.target.value;
		this.setState(this.state);
	},
	onColorChange: function(e){
		this.state.newColor = e.target.getAttribute('data-color');
		this.setState(this.state);
	},
	onSubmit: function(e){
		e.preventDefault();

		var name = this.state.newName;
		var color = this.state.newColor;
		var id = this.props.id;

		if(name != ''){
			this.props.notifyEdits(name, color, id);
		}
	},
	render: function(){
		var editClass = this.props.editMode ? 'is--show' : '';

		var radios = this.props.colorList.map(function(color, index){
			
			var checkedClass = (color.name == this.state.newColor) ? 'checked' : '';

			return (
				<input type="radio" onChange={this.onColorChange} className={`colorSelector__inputRadio ${color.name} ${checkedClass}`} name="selectedColor" data-color={color.name} key={color.id} />
			);
		}.bind(this));

		return (
			<form className={`list__form ${editClass}`} onSubmit={this.onSubmit}>
				<input
					className="form__inputText--lg form__inputText--addItem"
					type="text"
					ref="editInput"
					onChange={this.onValueChange}
					value={this.state.newName}
				/>
				<div className="colorSelector">
					{radios}
				</div>
				<input className="form__inputSubmit--inside" type="submit" value="Save" />
			</form>
		);
	}
});


var Item = React.createClass({
	propTypes: {
		name: React.PropTypes.string.isRequired,
		color: React.PropTypes.string,
		checked: React.PropTypes.bool.isRequired,
		edit: React.PropTypes.bool.isRequired,
		id: React.PropTypes.number.isRequired,
		onPassDelete: React.PropTypes.func.isRequired,
		onCheckedCheck: React.PropTypes.func.isRequired,
		editFlag: React.PropTypes.func.isRequired,
		editColorList: React.PropTypes.array.isRequired,
	},

	getInitialState: function(){
		return {
			clicked: false,
			checked: false,
			editSwitch: false,
		}
	},

	handleClick: function(){
		this.state.clicked = this.state.clicked ? false : true;
		this.setState(this.state);
	},

	handleChange: function(e){
		this.state.checked = e.target.checked;
		this.props.onCheckedCheck(this.state.checked, this.props.id);
		this.setState(this.state);
	},

	onEditSwitch: function(){
		this.state.editSwitch = true;
		this.setState(this.state);
		this.props.editFlag(this.state.editSwitch, this.props.id);
	},

	render: function(){
		var colorClass = this.props.color ? this.props.color : '';
		var checkedClass = this.state.checked ? 'disabled' : '';
		
		return (
			<li className={`list__item ${colorClass} ${checkedClass}`} data-id={this.props.id}>
				<div className="list__checkbox">
					<input type="checkbox" onChange={this.handleChange} />
				</div>

				<div className="list__name">
					<p className="list__text" onClick={this.onEditSwitch}>{this.props.name}</p>
					<EditItemForm 
						editMode={this.props.edit} 
						val={this.props.name} 
						color={this.props.color} 
						colorList={this.props.editColorList} 
						notifyEdits={this.props.onEdit}
						id={this.props.id} 
					/>
				</div>
			</li>
		);
	}
});

var App = React.createClass({

	propTypes: ({
		initialItems: React.PropTypes.array.isRequired,
		colors: React.PropTypes.array.isRequired,
	}),

	componentDidMount: function(){
		window.addEventListener('click', this.clickOutside);
	},

	getInitialState: function(){
		return {
			items: this.props.initialItems,
			countChecked: false,
			checkedNum: 1,
		}
	},

	onItemAdd: function(name, color){
		this.state.items.push({
			name: name,
			color: color,
			checked: false,
			edit: false,
			id: itemId,
		});
		this.setState(this.state);
		itemId += 1;
	},

	onItemEdit: function(name, color, id){
		var array = this.state.items;
		var index = getIndex(id, array, 'id');
		this.state.items[index].name = name;
		this.state.items[index].color = color;
		this.state.items[index].edit = false;
		this.setState(this.state);
		//console.log('new name: ' + name + ' new color: ' + color + ' id: ' + id);
	},

	onItemDelete: function(index){
		this.state.items.splice(index, 1);
		this.setState(this.state);
	},

	onCheckedChecker: function(checked, id){
		var array = this.state.items;
		var index = getIndex(id, array, 'id');
		var counter = [];
		
		if(this.state.items[index].edit === true){
			this.state.items[index].edit = false;	
		}
		this.state.items[index].checked = checked;
		this.setState(this.state);

		this.state.items.forEach(function(obj, index){
			if(obj.checked === true){
				counter.push(obj);
			}
		});
		if(counter.length > 0){
			this.state.countChecked = true;	
		}else {
			this.state.countChecked = false;
		}
		this.state.checkedNum = counter.length;
	},

	onMultiDelete: function(){
		var items = this.state.items;
		var keep = [];
		this.state.items.forEach(function(obj, index){
			if(obj.checked !== true){
				keep.push(items[index]);
			}
		});
		this.setState({
			items: keep,
			countChecked: false,
			checkedNum: 1,
		});
	},

	onEditCheck: function(flag, id){
		var array = this.state.items;
		var index = getIndex(id, array, 'id');
		var counter = [];

		this.state.items[index].edit = flag;
		this.setState(this.state);


		this.state.items.forEach(function(obj, index){
			if(obj.edit === true){
				counter.push(obj);
			}
		});

		if(counter.length > 1){
			this.state.items.forEach(function(obj, index){
				obj.edit = false;
			});
			this.state.items[index].edit = true;
			this.setState(this.state);
			
			counter.splice(0, 1);			
		}

	},

	clickOutside: function(e){
		if(!document.querySelector('[data-area]').contains(e.target)){
			this.state.items.forEach(function(obj, index){
				if(obj.edit === true){
					obj.edit = false;
				}
			});
			this.setState(this.state);
		}
	},

	render: function(){
		return (
			<div className="container">
				<Header checkedItemsFlag={this.state.countChecked} number={this.state.checkedNum} handleDeleteItems={this.onMultiDelete} />
        <ul className="list" data-area>
					{this.state.items.map(function(item, index){
						return (
							<Item 
								name={item.name}
								color={item.color}
								checked={item.checked}
								edit={item.edit}
								key={item.id}
								id={item.id}
								onCheckedCheck={this.onCheckedChecker}
								onPassDelete={function(){ this.onItemDelete(index) }.bind(this)} 
								editFlag={this.onEditCheck}
								editColorList={this.props.colors}
								onEdit={this.onItemEdit}
							/>
						);
					}.bind(this))}
				</ul>
        <AddItemForm onAdd={this.onItemAdd} colorList={this.props.colors} />
			</div>
		);
	}
});


ReactDOM.render(
  <App initialItems={INIT_ITEMS} colors={COLORS} />,      document.getElementById('app')
);
              
            
!
999px

Console