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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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.

            
              * {
  font-family: Roboto;
  font-weight: 300;
  font-size: 1rem;
}

body {
  background: no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  background-image: url('https://wapcr.surge.sh/0vdMnby.jpg');
  background-color: #CCCCCC;
}

h1 {
  font-family: "Shadows Into Light";
  text-align: center;
  font-size: 10rem;
  color: #2C2416;
}

a {
  text-decoration: none;
}

.mdl-layout__content {
  width: 100%;
}

span.highlighted {
  background-color: lightgreen;
}

/* Following CSS is for the search bar,
 * from https://codepen.io/912lab/pen/LsplC
 */  

input {
	outline: none;
}

input[type=search] {
	-webkit-appearance: textfield;
	-webkit-box-sizing: content-box;
	font-family: inherit;
	font-size: 100%;
}

input::-webkit-search-decoration,
input::-webkit-search-cancel-button {
	display: none; 
}

input[type=search] {
	background: #ededed url(https://static.tumblr.com/ftv85bp/MIXmud4tx/search-icon.png) no-repeat 9px center;
	border: solid 1px #ccc;
	padding: 9px 10px 9px 32px;
	width: 55px;
	
	-webkit-border-radius: 10em;
	-moz-border-radius: 10em;
	border-radius: 10em;
	
	-webkit-transition: all .5s;
	-moz-transition: all .5s;
	transition: all .5s;
}

input[type=search]:focus {
	width: 130px;
	background-color: #fff;
	border-color: #66CC75;
	
	-webkit-box-shadow: 0 0 5px rgba(109,207,246,.5);
	-moz-box-shadow: 0 0 5px rgba(109,207,246,.5);
	box-shadow: 0 0 5px rgba(109,207,246,.5);
}

input:-moz-placeholder {
	color: #999;
}
input::-webkit-input-placeholder {
	color: #999;
}
            
          
!
            
              class CamperNews extends React.Component {
  constructor(props) {
    super(props);
    this.state = {data: [], search: ''};
  }
  componentDidMount() {
    $.getJSON(this.props.url, data => this.setState({data}));
  }
  searchArticles = (search) => {
    this.setState({search});
  };
  render() {
    const data = this.state.data.filter(article => {
      return ~article.headline.toLowerCase().indexOf(this.state.search.toLowerCase());
    });
    return <div>
      <h1>Camper News</h1>
      <SearchBar onSearch={this.searchArticles} />
      <ArticleList data={data} search={this.state.search} />
    </div>
  }
}

class SearchBar extends React.Component {
  handleInput = (e) => {
    this.props.onSearch(e.target.value);
  };
  render() {
    const style = {textAlign: 'center', marginTop: '-1.5rem', marginBottom: '1rem'};
    return <div style={style}>
      <input
        type="search"
        placeholder="Search"
        value={this.props.search}
        onInput={this.handleInput}
      />
    </div>
  }
}

class ArticleList extends React.Component {
  render() {
    var articles = this.props.data.map(article => {
      return <Article data={article} search={this.props.search} key={article._id} />
    });
    return <main className="mdl-layout__content">
      <div className="mdl-grid">
        {articles}
      </div>
    </main>
  }
}

class Article extends React.Component {
  render() {
    return <div className="mdl-card mdl-shadow--4dp mdl-cell mdl-cell--4-col">
      <a href={this.props.data.link} target="_blank">
        <ArticleMedia data={this.props.data} />
        <ArticleText data={this.props.data} search={this.props.search} />
      </a>
    </div>
  }
}
    
class ArticleMedia extends React.Component {
  render() {
    const {data} = this.props;
    const image = data.image || 'https://pbs.twimg.com/profile_images/562385977390272512/AK29YaTf.png';
    const style = {backgroundImage: 'url(' + image + ')', height: '21rem'};
    const upVotesStyle = {
      width: '4.6rem',
      height: '2.3rem',
      lineHeight: '2.3rem',
      textAlign: 'center',
      backgroundColor: '#666',
      color: '#fafafa',
      opacity: '0.65'
    };
    return <div className="mdl-card__media" style={style}>
      <div style={upVotesStyle}>
        +{data.upVotes.length}
      </div>
    </div>
  }
}
    
class ArticleText extends React.Component {
  render() {
    const {search} = this.props;
    const re = new RegExp(search, 'gim');
    let {headline} = this.props.data;
    if (search) headline = headline.replace(re, '<span class="highlighted">$&</span>');
    return <div className="mdl-card__supporting-text meta mdl-color-text--grey-600">
      <div dangerouslySetInnerHTML={{__html: headline}} />
    </div>
  }
}

ReactDOM.render(
  <CamperNews url="https://www.freecodecamp.com/stories/hotStories" />,
  document.getElementById('content'));
            
          
!
999px
Loading ..................

Console