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.

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

$white: #fff;
$bg: #eaeef7;
$radius: 5px;
$blue: #2faeff;
$label: #777;
$dark: #333;
$primary: #254984;
* {
	box-sizing: border-box;
}
html {
	height: 100%;
	width: 100%;
}

body {
	background-color: $bg;
	font-family: "Lato";
	margin: 0;
	height: 100%;
	width: 100%;
}

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

h1,
h2,
h3,
h4 {
	font-weight: normal;
	display: table;
}

.card {
	&__wrapper {
		flex-wrap: wrap;
		flex-grow: 1;
	}
	&__container {
		//flex-grow: 1;
		flex-basis: 100%;
		flex-grow: 1;
		min-width: 200px;
		position: relative;
		padding: 8px 0;
	}
	&__content {
		padding: 50px 30px;
		flex-grow: 1;
		background-color: $white;
		border-radius: $radius;
		position: relative;
		box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
	}
	&__list {
		list-style: none;
		display: inline-block;
	}
}

.text {
	&--primary {
		font-size: 1.2rem;
		margin-right: 20px;
	}
	&--small {
		font-size: 0.9rem;
		color: $primary;
		font-weight: 100;
	}
	&--link {
		cursor: pointer;
	}
	&--link:hover {
		text-decoration: underline;
	}
}

.wrapper {
	height: 100%;
	padding: 30px;
	max-width: 800px;
	min-width: 667px;
	margin: 0 auto;
}

.close {
	position: absolute;
	right: 0;
	top: 0;
	bottom: 0;
	margin: auto;
	font-size: 1.5rem;
	border: 0 none;
	background-color: transparent;
	outline: none;
	color: rgba(#f00, 0.4);
	padding: 30px;
	cursor: pointer;
	&:hover {
		color: rgba(#f00, 0.7);
	}
}

.disabled {
	opacity: 0.3;
	cursor: default;
	&:hover {
		background-color: $blue;
		box-shadow: none;
	}
}
.example-enter {
	opacity: 0;
}

.example-enter.example-enter-active {
	//top: 10em;
	opacity: 1;
	transition: opacity 0.3s ease-in-out;
}

.example-leave {
	opacity: 1;
	max-height: 200px;

	transition: max-height 0.3s ease-in, opacity 0.3s ease-in;
}

.example-leave.example-leave-active {
	opacity: 0;

	max-height: 0;
}

.example-appear {
	opacity: 0.01;
	transform: translateY(100px);
	transition: all 0.5s ease;
}

.example-enter {
	opacity: 0.01;
	max-height: 0;
	transform: translateY(100px);
}

.example-enter.example-enter-active {
	opacity: 1;
	max-height: 200px;
	transform: translateY(0px);
	transition: all 0.5s ease;
}

.example-appear.example-appear-active {
	opacity: 1;
	transform: translateY(0px);
}

.btn {
	font-family: 'Lato';
	box-shadow: none;
	border: 0 none;
	border-radius: 4px;
	font-size: 16px;
	cursor: pointer;

	padding: 15px 25px;
	&--secondary {
		background-color: rgba(255, 255, 255, 0.5);
		border: 1px solid #ddd;
	}
	&--primary {
		background-color: $primary;
		color: #fff;
		transition: background-color 0.2s ease-in;
		&:hover {
			background-color: darken($primary, 5%);
		}
	}
}

#app {
	height: 100%;
}

.header {
	height: 80px;
	margin: 10px 0 40px;
	display: flex;
	h1 {
		flex-grow: 1;
		display: flex;
	}
	.btn {
		margin-top: 8px;
		margin-left: 20px;
	}
	
}

:disabled {
	opacity: 0.7;
	outline: 0 none;
	cursor: default;
	border: 1px solid darken($bg, 5%);

	&:hover {
		background-color: rgba(255, 255, 255, 0.5);
	}
}

h1 {
	font-weight: 300;
}

p {
	font-size: 18px;
	font-weight: 300;
}

            
          
!
            
              var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup;
function uniqueKey() {
	const guid =
		s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4();

	return guid;
}

function s4() {
	return Math.floor((1 + Math.random()) * 0x10000)
		.toString(16)
		.substring(1);
}

var dataArray = [
	{
		message: "User Error",
		link: "Try again",
		key: uniqueKey()
	},
	{
		message: "404",
		link: "Refresh",
		key: uniqueKey()
	},
	{
		message: "Oops",
		link: "Keep fishing",
		key: uniqueKey()
	}
];

class Notification extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			message: this.props.data.message,
			link: this.props.data.link
		};
	}
	deleteMessage() {
		var newObject = {
			message: this.state.message,
			link: this.state.link
		};
		this.props.deleteMessage(newObject);
		this.setState({
			btn: false
		})
	}
	render() {
		return (
			<div>
				<ul>
					<li className="card__list text--primary">{this.props.data.message}</li>
					<li className="card__list text--small text--link">{this.props.data.link}</li>
				</ul>
				<button
					type="button"
					className="close"
					onClick={this.deleteMessage.bind(this)}
				>
					&times;
				</button>
			</div>
		);
	}
}
class Header extends React.Component {
	constructor(props) {
		super(props);
	}
	
	addMessage() {
		this.props.addMessage();
	}
	resetForm() {
		this.props.resetForm();
	}

	render() {
		return (
			<div className="header">
				<h1>React Transition Demo</h1>
				<div className="btn-container">
					<button
						disabled={this.props.btn}
						className="btn btn--secondary"
						onClick={this.resetForm.bind(this)}
					>
						Reset
					</button>
					<button className="btn btn--primary" onClick={this.addMessage.bind(this)}>
						Add Message
					</button>
				</div>
			</div>
		);
	}
}

class Parent extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			data: this.props.data,
			btn: true
		};
	}

	addMessage(newObject) {
		var messageArray = [
    "Bleep",
    "Bloop",
		"Blop"
];

		
			var linkArray = [
    "Aren't you a little short for a stormtrooper?",
    "These aren't the droids you're looking for.",
		"I find your lack of faith disturbing.",
		"Help me, Obi-Wan Kenobi.",
		"I will not be the last Jedi.",
		"May the force be with you."
];
		
	
		var randomMessage=Math.floor(Math.random()*messageArray.length);
		var randomLink=Math.floor(Math.random()*linkArray.length);
		
		var newObject = {
			message: messageArray[randomMessage],
			link: linkArray[randomLink],
			key: uniqueKey()
		};
		
		var list = this.state.data; //get current array
		var newList = list.slice(); //copy the array
		newList.unshift(newObject); //add the newobject to the beginning
		if(this.state.data.length >= 3) {
			newList.pop();
		}
		this.setState({
			data: newList,
			btn: false
		});
	}

	deleteMessage(i, newObject) {
		var list = this.state.data;
		var newList = list.slice();
		newList.splice(i, 1);

		this.setState({
			data: newList,
			btn: false
		});
	}

	resetForm() {
		this.setState({
			data: this.props.data,
			btn: true
		});
	}
	
	
	render() {
		var items = this.state.data.map(
			function(data, i) {
				return (
					<div
						style={{ transitionDelay: `${i * 0.1}s` }}
						className="card__container"
						key={data.key}
					>
						<div className="card__content">
							<Notification
								data={data}
								key={data.key}
								deleteMessage={this.deleteMessage.bind(this, i)}
							/>
						</div>
					</div>
				);
			}.bind(this)
		);
		return (
			<div className="wrapper">
				<Header
					resetForm={this.resetForm.bind(this)}
					addMessage={this.addMessage.bind(this)}
					btn = {this.state.btn}
				/>
					
				<ReactCSSTransitionGroup
					component="div"
					transitionName="example"
					transitionAppear={true}
					transitionEnter={true}
					transitionLeave={true}
					className="card__wrapper"
				>
					{items}
				</ReactCSSTransitionGroup>
			</div>
		);
	}
}

ReactDOM.render(<Parent data={dataArray} />, document.getElementById("app"));

            
          
!
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