css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!--
	Nothing here, JSX is injected in document body
-->
            
          
!
            
              // using SCSS as the CSS preprocessor (more readable). Autoprefixer is also acitvated.

@import url('https://fonts.googleapis.com/css?family=Roboto:400,500,700');

html, body {
	padding-top: 35px;
	font-family: Roboto, Helvetica, Arial;
	box-sizing: border-box;
	background: #FAFAFA;
	width: 100%;
	margin: 0;
}

::-webkit-scrollbar {
    display: none;
}

* {
	box-sizing: border-box;
}

header {
	
	h1 {
		font-size: 1.5em;
		margin: 14px 20px;
		color: rgba(255,255,255,.87);
		font-weight: normal;
	}
	
	svg {
		z-index: 1000;
		position: fixed;
		right: 320px;
		top: 15px;
	}
	
	input {
		font-size: 1.5em;
		color: white;
		z-index: 1000;
		max-width: 300px;
		min-width: 300px;
		height: 28px;
		top: 14px;
		right: 20px;
		background: transparent;
		border: none;
		position: fixed;
		
		&:focus {
			outline:none;
			top: 15px;
			border-bottom: 2px solid white;
		}
		
		&::placeholder {
			color: rgba(255,255,255,.56);
		}
		
	}
	
	div {
		height: 2px;
		background-color: #fff;
		width: 0%;
		margin-top: -1px;
	}
	
	z-index: 999;
	position: fixed;
	background: #c2185b;
	top: 0;
	left: 0;
	height: 56px;
	width: 100%;
	width: 100vw;
	box-shadow: 0px 2px 4px -1px rgba(0, 0, 0, 0.2),
							0px 4px 5px 0px rgba(0, 0, 0, 0.14),
							0px 1px 10px 0px rgba(0, 0, 0, 0.12);
}

#infocontainer {
	display: inline-block;
	max-width: 810px;
	margin-left: calc( 50% - 405px );
}

@media (max-width: 845px) {
	#infocontainer {
		display: inline-block;
		max-width: 540px;
		margin-left: calc( 50% - 270px );
	}
}

@media (max-width: 570px) {
	#infocontainer {
		display: inline-block;
		width: 100%;
		margin-left: 0;
	}
	
	.infobox {
		width: calc( 100% - 20px) !important;
	}
	
	header {
		h1 {
			font-size: 1.2em;
			margin: 16px 10px;
		}
		svg {
			right: 195px;
			height: 24px;
			top: 17px;
		}
		input {
			max-width: 180px;
			min-width: 180px;
			font-size: 1.2em;
		}
	}
}

.infobox {
	border-radius: 2px;
	float: left;
	display: block;
	margin: 12px 10px;
	width: 250px;
	background: #fff;
	box-shadow: 0px 3px 1px -2px rgba(0, 0, 0, 0.2),
							0px 2px 2px 0px rgba(0, 0, 0, 0.14),
							0px 1px 5px 0px rgba(0, 0, 0, 0.12);
	padding: 0;
	
	h2 {
		
		svg {
			position: absolute;
			margin-top: -1.3rem;
			margin-left: 200px;
			fill: rgba(0,0,0,.87);
		}
		
		margin: 0;
		padding-top: 8px;
		color: rgba(0,0,0,.87);
		font-size: 1.5rem;
    font-weight: 400;
    letter-spacing: normal;
    line-height: 2rem;
	}
	
	h3 {
		margin: -.063rem 0;
		font-size: 0.875rem;
    font-weight: 400;
    letter-spacing: 0.04em;
    line-height: 1.25rem;
	}
	
	div.img {
		border-top-right-radius: 2px;
		border-top-left-radius: 2px;
		width: 100%;
		padding-top: calc(100% / 1.77777);
		background-position-x: center;
		background-size: cover;
	}
	
	section.stats {
		padding: 16px;
		width: 100%;
	  span {
			color: rgba(0,0,0,.87);
			font-size: 0.875rem;
			line-height: 2;
		}
	}
	
	section.actions {
		
		padding: 0 8px 8px 8px;
		float: right;
		
		button {
			margin: 0 8px 0 0;
			-webkit-tap-highlight-color: rgba(0, 0, 0, 0.3);
			padding: 0 8px;
			font-size: 0.875rem;
			font-weight: 500;
			letter-spacing: 0.04em;
			line-height: 2.20rem;
			text-decoration: none;
			color: rgba(0, 0, 0, 0.87);
			display: inline-block;
    	position: relative;
    	min-width: 72px;
			height: 34px;
			border: none;
    	border-radius: 2px;
			outline: none;
			background: transparent;
			text-align: center;
			overflow: hidden;
			vertical-align: middle;
			user-select: none;
    	-webkit-appearance: none;
			transition: background .1s;
			
			&:hover {
				background: rgba(0,0,0,.1);
				cursor: pointer;
			}
			
			&:active {
				background: rgba(0,0,0,.3);
			}
		}
	}
}

.noresult {
	margin: 20px 0 0 0;
	font-size: 18px;
	color: rgba(0,0,0,.87);
	background-color: rgba(255,0,0,.13);
	max-width: 540px;
	padding: 18px;
	border-radius: 5px;
}

footer {
	font-size: 18px;
	color: rgba(0,0,0,.57);
	margin: 30px auto 20px auto;
	width: 100%;
	text-align: center;
	
	a {
		color: inherit;
		text-decoration: none;
		
		&:hover {
			color: rgba(0,0,0,.87);
		}
	}
}

            
          
!
            
              /*
	Displays different characters from the cartoon "Rick and Morty". Made by Marius Niveri
	The JavaScript libary used for building the components and managing the state is Preact,
	a new more lightweight React alernative (https://preactjs.com/).
	All the code is written by me. Only the images are sourced from 3rd party pages.
*/


// load Preact and tell JSX to use h() as the provider
let { render, h, Component } = preact;
/**@jsx h*/

/*
	Some functions:
*/

const getCurrentYear = () => {
	const d = new Date();
	return d.getFullYear();
};

const evolve = (char, setState) => {
	alert("Sorry, you can't evolve "+char+" yet :/");
};

const equip = (char, setState) => {
	setState({equiped: char});
};

const search = (nameKey, myArray) => {
	const patt = new RegExp(nameKey);
	let result = [];
	
	if (!nameKey.replace(/\s/g, '').length) return myArray;
	for (var i=0; i < myArray.length; i++) {
		if (patt.test(myArray[i].keywords.toLowerCase())) {
    	result.push(myArray[i]);
    }
  }
	if (result.length > 0) {
		if (result.length > 0) return result;
		return [result];
	}
	return result;
}


/*
	Components:
*/

class TopBar extends Component {
	
	filterList(state, setState) {
		let updatedList = state.initialCharacter;
		updatedList = search(event.target.value.toLowerCase(), updatedList);
		setState({character: updatedList });
  }
	
	render() {
		return(
			<header>
				<h1>Rick 'n' Morty Characters</h1>
				<svg xmlns="http://www.w3.org/2000/svg" fill="#fff" height="28" viewBox="0 0 28 28" width="28">
					<path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/>
					<path d="M0 0h24v24H0z" fill="none"/>
				</svg>
				<input placeholder="Search" onKeyUp={() => this.filterList(this.props.state, this.props.setstate)}></input>
				<div style={{ width: this.props.state.scrollposition+'%' }} />
			</header>
		)
	}
}

class Footer extends Component {
	render() {
		return(
			<footer>
				{{/* getCurrentYear() is defined above */}}
				<span>&lt;coded/&gt; with ❤️ and ☕ by <a target="_blank" href="https://maniyt.de/">Marius Niveri</a> | © {getCurrentYear()}</span>
			</footer>
		)
	}
}

// The box which displays the information about the character
class Infobox extends Component {
	
	isEquiped() {
		if (this.props.equiped === this.props.character.name) return true;
		return false;
	}
	
	render() {
		
		return (
			<div class="infobox">
				<div class="img" style={{ backgroundImage: 'url('+this.props.character.image+')' }}></div>
				
				<section class="stats">
					<h2>
						<span style={{ display: this.isEquiped() ? 'inline-block' : 'none' }}>
							<svg xmlns="http://www.w3.org/2000/svg" fill="#000000" height="24" viewBox="0 0 24 24" width="24">
								<path d="M0 0h24v24H0z" fill="none"/>
								<path d="M12 17.27L18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z"/>
								<path d="M0 0h24v24H0z" fill="none"/>
							</svg>
						</span>
						{this.props.character.name}
					</h2>
					<h3>
						{this.props.character.description}
					</h3><br />
					<span><b>Speed:</b> {this.props.character.speed}</span><br />
					<span><b>Height:</b> {this.props.character.height}cm</span><br />
					<span><b>Strenght:</b> {this.props.character.strenght}</span><br />
					<span><b>Intelligence:</b> {this.props.character.intelligence}</span><br />
					<span><b>Endurance:</b> {this.props.character.endurance}</span><br />
					<span><b>Aggression:</b> {this.props.character.aggression}</span><br />
					<span><b>Creativity:</b> {this.props.character.creativity}</span><br />
				</section>
				<section class="actions">
					<button onClick={() => evolve(this.props.character.name, this.props.setstate)}>Evolve</button>
					<button onClick={() => equip(this.props.character.name, this.props.setstate)}>Equip</button>
				</section>
			</div>
		)
	}
}

// Main Component, holds state of app
class Main extends Component {
	
	constructor(props) {
		super(props);
		
		// The state. It contains the information about characters
		this.state = {
			scrollposition: 0,
			equiped: "",
			character: [
				{
					name: "Rick",
					keywords: "Rick grandparent granddad old weird scientist",
					image: "http://ll-c.ooyala.com/e1/JmYnVjYjE60O1HaYdHp9HjcHiOtE86ob/promo320097983",
					description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
					speed: 27,
					height: 178,
					strenght: 14,
					intelligence: 100,
					endurance: 23,
					aggression: 89,
					creativity: 100
				},
				{
					name: "Morty",
					keywords: "morty young boy shy school",
					image: "https://i.ytimg.com/vi/Zw1Du7OmoU8/maxresdefault.jpg",
					description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
					speed: 87,
					height: 162,
					strenght: 36,
					intelligence: 100,
					endurance: 11,
					aggression: 17,
					creativity: 16
				},
				{
					name: "Jerry",
					keywords: "jerry dad",
					image: "https://vignette1.wikia.nocookie.net/rickandmorty/images/0/03/S2e4_jerry_crying.png/revision/latest?cb=20160922010459",
					description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
					speed: 91,
					height: 183,
					strenght: 58,
					endurance: 36,
					intelligence: 100,
					aggression: 8,
					creativity: 18
				},
				{
					name: "Summer",
					keywords: "summer sister girl aggressive",
					image: "http://nerdist.com/wp-content/uploads/2017/06/rick-and-morty-summer-fury-road-gun.jpg",
					description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
					speed: 71,
					height: 169,
					strenght: 25,
					intelligence: 100,
					endurance: 46,
					aggression: 85,
					creativity: 21
				},
				{
					name: "King Flippy Nips",
					keywords: "king flippy nips pluto",
					image: "http://pm1.narvii.com/6219/c701d4db8aadeb5cf471ff0b3b7839d7639f9ee3_hq.jpg",
					description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
					speed: 71,
					height: 169,
					strenght: 25,
					intelligence: 100,
					endurance: 46,
					aggression: 85,
					creativity: 21
				},
				{
					name: "Mr. Meeseeks",
					keywords: "mr. meeseeks help servant death die",
					image: "http://i.imgur.com/pthc8Ve.png",
					description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
					speed: 71,
					height: 169,
					strenght: 25,
					intelligence: 100,
					endurance: 46,
					aggression: 85,
					creativity: 21
				},
				{
					name: "Mr. Poopybutthole",
					keywords: "mr. poopybutthole pizza injured",
					image: "https://img.cinemablend.com/filter:scale/quill/7/b/9/2/1/c/7b921ceaa963ae635fe535165b452fde8459fdd2.jpg?mw=600",
					description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
					speed: 71,
					height: 169,
					strenght: 25,
					intelligence: 100,
					endurance: 46,
					aggression: 85,
					creativity: 21
				},
				{
					name: "Pickle Rick",
					keywords: "pickle rick transformed meme",
					image: "http://ll-c.ooyala.com/e1/g4ZGJmYzE6S6UTEGF8ghEtSZE8XUmFoM/AZ2ZgMjz0LFGHCPn4xMDoxOjBzMTt2bJ",
					description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
					speed: 71,
					height: 169,
					strenght: 25,
					intelligence: 100,
					endurance: 46,
					aggression: 85,
					creativity: 21
				},
				{
					name: "Noob Noob",
					keywords: "noob noob damn meme nice cleaner",
					image: "https://cdn.vox-cdn.com/thumbor/WAmHiQFLd2wydWvET4vLUikvxD8=/0x0:1280x720/1600x900/cdn.vox-cdn.com/uploads/chorus_image/image/56254065/noob_noob.0.jpg",
					description: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
					speed: 71,
					height: 169,
					strenght: 25,
					intelligence: 100,
					endurance: 46,
					aggression: 85,
					creativity: 21
				}
			]
		};
  };
	
	componentWillMount() {
		this.setState({ initialCharacter: this.state.character });
	}
	
	componentDidMount() {
		document.documentElement.addEventListener('scroll', this.handleScroll);
	}
	
	// Initial render of app
	render() {
		return (
			<div>
				<TopBar state={this.state} setstate={this.setState.bind(this)} />
				<center>
					<div class="noresult" style={{ display: this.state.character.length ? 'none' : 'block' }}>
						No search results!
					</div>
				</center>
				<div id="infocontainer">
					{ this.state.character.map( char => (
						<Infobox setstate={this.setState.bind(this)} equiped={this.state.equiped} character={char} />
					)) }
				</div>
				<Footer />
			</div>
		);
	}
}

// hook the app to the document body
render(<Main />, document.body);
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console