cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              *{
  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);
}
            
          
!
            
              console.clear();

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

//Enforcing Mobx Strict Mode
mobx.useStrict(true);

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

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

//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
@observer
class App extends React.Component {  
	renderSelection(){
		if (_.isEmpty(this.props.store.selectedUser)) return <noscript />;
		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
Loading ..................

Console