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 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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

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.

            
              * {
  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
🕑 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