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

CSS

              
                *{
  box-sizing: border-box;
}
body{
  background: rgb(0,127,180);
}

h3{
  color: #fff;
  text-align:center;
  text-shadow: 0px 1px 5px rgba(0,0,0,0.5);
}

li{
  cursor: pointer;
  list-style: none;
  display: block;
  border: 1px solid black;
  background: #fff;
  margin: 1% 5%;
  padding: 1%;
  box-shadow: 0px 1px 5px rgba(0,0,0,0.5);
}
  li:hover{
    background:beige;
  }
button{
  -webkit-appearance: none;
  background: white;
  border: 1px solid black;
  border-radius: 5px;
  padding: 0.5em;
  box-shadow: 0px 1px 5px rgba(0,0,0,0.5);
  display:inline-block;
  margin-right:5%;
  margin-bottom:25px;
  cursor:pointer;
}
button:hover{
  color: #fff;
  background: rgb(255,85,0);
}
button:active{
  box-shadow: inset 0px 1px 5px rgba(0,0,0,0.5);
}
button:focus{outline:0;}
.selection{
  text-align:right;
}
.fa{
  margin-right: 5px;
}
.selection ul{
  border: 1px solid black;
  background: #fff;
  margin: 1% 5%;
  padding: 2% 4%;
  box-shadow: 0px 1px 5px rgba(0,0,0,0.5);
}
.selection li{
  text-align:left;
  cursor: auto;
  display: block;
  border: none;
  background: #fff;
  margin: 0;
  padding: 0;
  box-shadow: none;
}
.bold,.bold:hover{
  font-weight:bolder;
  color: #fff;
  background: rgb(255,85,0);
}
              
            
!

JS

              
                //Importing all needed modules by destructuring
const { 
	observable, 
	action, 
	computed,
	decorate
} = mobx;
const { observer } = mobxReact;
const { Component } = React;

/*Mobx Store*/
class UserStore {
	//Observable values can be watched by Observers
	users = [];
	selectedUser = {};
	get selectedId() { 
		return this.selectedUser.id;
	}

	constructor() {
		//Managing Async tasks like ajax calls with Mobx actions
		$.get('https://jsonplaceholder.typicode.com/users').then( users => {
			console.log(users)
			this.setUsers(users); 
		});
	}
	//In strict mode, only actions can modify mobx state
	setUsers = (users) => {
		this.users = [...users];
	}
	selectUser = (user) => {
		this.selectedUser = user;
	}
}

decorate(UserStore, {
	users: observable,
	selectedUser: observable,
	selectedId: computed,
	setUsers: action,
	selectUser: action
});

//Child Component / Profile (Functional Component)
const Profile = ({ onClick, label, selected }) => {
	const classes = selected ? 'bold' : '';
	return (
		<li onClick={ onClick } className={classes}>
			<i className="fa fa-user"></i> { label } 
		</li>
	);
};

//Child Component /  (Functional Component)
const Selection = ({ user }) => {
	return (
		<ul>
			<li><i className="fa fa-book fa-fw"></i> Name: {user.name}</li>
			<li><i className="fa fa-user fa-fw"></i> Username: { user.username }</li>
			<li><i className="fa fa-phone fa-fw"></i> Phone: {user.phone}</li>
			<li>
				<i className="fa fa-envelope fa-fw"></i> Email: 
				<a href={"mailto:"+user.email}>{user.email}</a>
			</li>
		</ul>
	);
};

//Main Component / Parent Component / App (Class Based Component)
//Observers can react (ba dum tss) to changes in observables
const App = observer(
class App extends React.Component {  
	renderSelection(){
		if (_.isEmpty(this.props.store.selectedUser)) return <noscript />;
		console.log(this.props.store);
		return (
			<div className='selection'>
				<Selection user={this.props.store.selectedUser}/>
				<button onClick={() => {this.props.store.selectUser({})}}>Close Profile</button>
			</div>
		)
	}

	renderProfiles(){
		return this.props.store.users.map((user) => {
			return (
				<Profile
					selected = {user.id === this.props.store.selectedId}
					key = {user.id} 
					label = {user.name} 
					onClick = { () => {this.props.store.selectUser(user)} }
					/>
			);
		});
	}

	render(){
		return (
			<div>
				<h3>Employee Directory</h3>
				{this.renderSelection()}
				{this.renderProfiles()}
			</div>
		);
	}
});

/*Implementation Details*/
//Creating a new Mobx Store Object for our App
const Store = new UserStore();

//Rendering the app to the container and passing in the Mobx Store
ReactDOM.render( <App store={Store} />, document.querySelector("#container"));
              
            
!
999px

Console