123

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.

            
              
	<title>Image filter with React.js (get from jSON)</title>
	 <link rel="stylesheet" href="css/style.css">
	<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.0/react-dom.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser.js"></script>
   
</head>
<body>
	<div id="main"></div>
    
    	
    </script>
</body>
</html>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Open+Sans);

* {
    transition: 0.25s ease-in-out all;
}

/* h1#headline {
  font-family: "Open Sans", sans-serif;
  text-align: center;
  margin-bottom: 1em;
  color: white;
  font-size: 2em;
} */

.PhotoGallery {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: center;
    overflow: hidden;
}

.photo-container {
    margin: 10px;
    position:relative;
    animation: fadeUP .5s;
}
.photo-container h2 { 
  font-family: Open Sans, sans-serif; 
  font-weight: 400;
  font-size: 1em;
}
.photo-container img {
    max-width: 100%;
}

@keyframes fadeUP {
    from {top: -40px; opacity:0;}
    to {top: 0; opacity:1}
}

.filter-panel {
    display: flex;
    background: #F8F8F8;
    padding: 25px;
    justify-content: center;
    align-items: center;
    box-shadow: 0 3px 10px rgba(0,0,0,.085);
}

.filter-panel a {
  background: #ED7669;
  color: white;
  font-family: Open Sans, sans-serif; 
/*   padding: 1em; */
  padding: 10px 25px;
  margin: 5px 15px;
/*   margin-bottom: 1em; */
  border-radius: 4px;
  outline: none;
  border: none;
  cursor: pointer;
  display: inline-block;
}

.filter-panel a:hover {
    background: #ea5e4f;
}

.filter-panel a.active {
    top:-8px;
}

.filter-panel a.resetBtn {background: #D8D8D8; color: #333;}

.filter-panel a.resetBtn:hover {
    background: #C8C8C8;
}
            
          
!
            
              {/* Get an array of photos with parameters */}
var PHOTODATA = [{
			id: 1,
			title: "The Beatles - Sgt. Pepper's Lonely Hearts Club Band",
			category: 'rock',
			imageUrl: 'http://chuckmcquilkin.com/five-hundred/AlbumArt/SgtPepper.jpg'
		},{
			id: 2,
 			title: 'The Beach Boys - Pet Sounds',
			category: 'rock',
			imageUrl: 'http://chuckmcquilkin.com/five-hundred/AlbumArt/PetSounds.jpg'
		},
		{
			id: 3,
 			title: 'The Beatles - Revolver',
			category: 'rock',
			imageUrl: 'http://chuckmcquilkin.com/five-hundred/AlbumArt/Revolver.jpg'
		},{
			id: 4,
			title: 'Bob Dylan - Highway 61 Revisited',
			category: 'rock',
			imageUrl: 'http://chuckmcquilkin.com/five-hundred/AlbumArt/Highway61.jpg'
		},{
			id: 5,
 			title: 'The Beatles - Rubber Soul',
			category: 'rock',
			imageUrl: 'http://chuckmcquilkin.com/five-hundred/AlbumArt/RubberSoul.jpg'
		},{
			id: 6,
 			title: "Marvin Gaye - What's Going On",
			category: 'soul',
			imageUrl: 'http://chuckmcquilkin.com/five-hundred/AlbumArt/WhatsGoingOn.jpg'
		},{
			id: 7,
 			title: "Rolling Stones* - Exile On Main St.",
			category: 'rock',
			imageUrl: 'http://chuckmcquilkin.com/five-hundred/AlbumArt/ExileOnMain.jpg'
		},{
			id: 8,
 			title: "The Clash - London Calling",
			category: 'rock',
			imageUrl: 'http://chuckmcquilkin.com/five-hundred/AlbumArt/Clash.jpg'
		},{
			id: 9,
 			title: "Bob Dylan - Blonde On Blonde",
			category: 'rock',
			imageUrl: 'http://chuckmcquilkin.com/five-hundred/AlbumArt/BlondeOnBlonde.jpg'
		},{
			id: 10,
 			title: "The Beatles - The Beatles",
			category: 'rock',
			imageUrl: 'http://chuckmcquilkin.com/five-hundred/AlbumArt/TheBeatles.jpg'
		},{
			id: 11,
 			title: "Elvis Presley - The Sun Sessions",
			category: 'rock',
			imageUrl: 'http://chuckmcquilkin.com/five-hundred/AlbumArt/TheSunSessions.jpg'
		},{
			id: 12,
 			title: "Miles Davis - Kind Of Blue",
			category: 'jazz',
			imageUrl: 'http://chuckmcquilkin.com/five-hundred/AlbumArt/KindOfBlue.jpg'
		}];
{/*Create a component of the filter panel*/}
var FilterPanel = React.createClass({
	render: function(){
		return (
			<a onClick={this.props.onClick}>{this.props.category}</a>
		)
	}
});
{/*Create a layout component for one photo*/}
var Photo =  React.createClass({
	render: function(){
		return (
				<div className="photo-container" data-category={this.props.category} ><img src={this.props.imageUrl} /><h2>{this.props.title}</h2></div>
			   );
	}
});
{/*Create a final collection of photos in photoGallery*/}
var PhotoGallery = React.createClass({
	getInitialState: function() {
                return {
                    displayedCategories: PHOTODATA,
                    active: false
                };
            },
     toggleActive: function() {
        this.setState({
            active: !this.state.active
        });
    },
	selectCategory: function(element){
		console.log('element is: '+ element);
		  var categoryName = element.toLowerCase();
                var displayedCategories = PHOTODATA.filter(function(el) {
                    var searchValue = el.category.toLowerCase();
                    return searchValue.indexOf(categoryName) !== -1;
                });
                this.setState({
                    displayedCategories: displayedCategories
                });
	},
	resetFilter: function(element){
		this.setState({
                    displayedCategories: PHOTODATA
                });
	},
	render: function(){
		var buttonClass = this.state.active ? 'active' : '';
		var categoryToSelect = this.selectCategory;
		var getUniqueCategories=[];
		PHOTODATA.forEach(function(el){
			if(getUniqueCategories.indexOf(el.category) === -1 ) getUniqueCategories.push(el.category);
		})
		return (
			<div className="overlay-photogallery">
				<div className="filter-panel">
					{
						getUniqueCategories.map(function(el,i){
							var boundClick = categoryToSelect.bind(null,el);
							return <FilterPanel onClick={boundClick} category={el} key={i} />
						})
					}		
					<a className="resetBtn" onClick={this.resetFilter}> Reset Filter </a>
				</div>
				<div className="PhotoGallery">
					{
						this.state.displayedCategories.map(function(el){
									return <Photo key={el.id} imageUrl={el.imageUrl} category={el.category} title={el.title} />
								})
					}
				</div>
			</div>
			);
	}
});

ReactDOM.render(<PhotoGallery />, document.getElementById('main'));
            
          
!
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.

Console