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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

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

CSS

              
                .responsive-image{
	max-width: 400px;
}
all{
	font-family: "Roboto" , serif;
}
/* post styles */
article.post{
	border: 1px solid #ccc;
	margin: 20px auto;
	border-radius: 5px;
	box-shadow: 4px 6px 5px #615353;
	padding: 20px;
}
h2.post-title{
	margin: 0px;	
}
/* form styles */
.new-post-form{
	border: 4px solid #eee;
	padding: 10px;
	background: #eec;
	display: flex;
	flex-direction: column;
}
.new-post-form label{
	margin: 10px 0px;
	display: flex;
	flex-direction: column;
}
.new-post-form input{
	padding: 5px 10px;
}
.submit-button{
	background: #000;
	color: #fff;
	font-size: 20px;
	padding: 10px 20px;
	border-radius: 5px;
}
              
            
!

JS

              
                // The individual post component
const Post = props => (
	<article className="post">
		<h2 className="post-title">{props.title}</h2>
		<hr/>
		<p className="post-content">{props.content}</p>	
	</article>
);

// The form component

class Forms extends React.Component {

// 	handleContentChange = event => {
// 		this.props.content = event.target.value;
// 	};

// 	handleSubmit = event => {
// 		alert();
// 		event.preventDefault();
// 	};
}

// The posts loop component

class Posts extends React.Component {
	state = {
		posts: [
			{
				title: "This is the post title",
				content: "This is the post content",
				// imgURL: "https://image.ibb.co/moXNRp/javascript_arrays.jpg"
				// category: {React, Javascript, Es6}
			},
			{
				title: "This is the second post title",
				content: "This is the post content",
				// imgURL: "https://image.ibb.co/jRzfCU/cascade.jpg"
				// category: {React, CSS, Es6}
			},
			{
				title: "This is the third post title",
				content: "This is the post content",
				// imgURL: "https://image.ibb.co/cb4DXU/minmax_function.jpg"
				// category: {React, HTML}
			}
		],
		post: {
			title: "",
			content: ""
		}
	};

	handleChange =  (event) =>  {
		const name = event.target.name;
		const value = event.target.value;
		// const title = this.state.post.title;
		// const content = this.state.post.content;
		// let newTitle ="";
		// let newContent ="";
		const { post } = this.state;
		// if (name === 'title'){
		// 	newTitle = value;
		// }
		// if (name === 'content'){
		// 	newContent = value;
		// }
		const newPost = {
      ...post,
      [name] : value
    };
		this.setState({ post: newPost });
		console.log(event.target.value);
		console.log(this.state.post.title);
		console.log(name);
		// this.setState({ [name] : value });
  }

	handleSubmit = (event) => {
		const post = this.state.post;
		const posts = this.state.posts;
		const newPosts = Array.from(posts);
		newPosts.push(post);
		this.setState({
			posts: newPosts
		});
		console.log(post);
		event.preventDefault();
	};


	render() {
		const posts = this.state.posts.map(post => {
			return (
				<Post
					key={post.id}
					{...post}
					// category={post.category}
				/>
			);
		});

		return (
			<React.Fragment>
				{posts}
				<form  className="new-post-form" onSubmit={this.handleSubmit}>
					<label>
						Post title
						<input
							className="title-input"
							type="text"
							name="title"
							onChange={this.handleChange}
						/>
					</label>
					<label>
						Post content
						<input
							className="content-input"
							type="text"
							name="content"
							onChange={this.handleChange}
						/>
					</label>
					<input className="submit-button" type="submit" value="submit" />
				</form>
			</React.Fragment>
		);
	}
}

class App extends React.Component {
	render() {
		return (
			<React.Fragment>
				<Posts />
			</React.Fragment>
		);
	}
}
// Render method to run the app

ReactDOM.render(<App />, document.getElementById("id"));

              
            
!
999px

Console