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

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

CSS

              
                body {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
}

#app {
  width: 100%;
  height: 100%;
}

.wiki-option {
  position: relative;
  right: 40px;
  list-style: none;
  border: 1px solid grey;
  padding: 5px 10px;
  margin-bottom: 1px;
  box-shadow: 0px 3px 5px #89C4F4;
  border-radius: 3px;
  transition: 0.6s;
  cursor: pointer;
}

li:hover {
  background-color: #FDE3A7;
}

#search-button {
  padding: 5px 10px;
  border: 1px solid black;
  margin-top: 10px;
  margin-right: 15px;
}

#random-button {
  padding: 5px 10px;
  border: 1px solid black;
  margin-bottom: 25px;
}

.search-box {
 width: 100%;
 margin-left: auto;
 margin-right: auto;
 display: flex;
 justify-content: center;
 align-items: center;
}

.search-box > input {
  width: 20%;
  border: none;
  border-bottom: 1px solid #9e9e9e;
  margin-bottom: 20px;
  margin-right: 30px;
  box-sizing: content-box;
  background-color: white transparent;
  outline: none;
}

.search-box > a {
  border-radius: 3px;
  background-color: #049372;
  color: white;
}

.app-container {
  width: 100%;
  height: 50vh;
  margin-top: 100px;
}

.results {
  position: relative;
  right: 40px;
  top: 10px;
  width: 25%;
}

.article {
  width: 50%;
  border: 1px solid black;
  padding: 10px 20px;
  box-sizing: border-box;
  margin-top: 20px;
  border-radius: 5px;
}


.app-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.heading {

  margin-bottom: 50px;
}
              
            
!

JS

              
                
// Container for the App

class App extends React.Component {
  constructor(props) {
    super(props)
   
   
   this.state = {
     url: "https://en.wikipedia.org/w/api.php",
     options: []
   }
  this.getArticle = this.getArticle.bind(this)
  this.getOptions = this.getOptions.bind(this);    
 }
 
  
  // https://en.wikipedia.org/w/api.php?/w/api.php?action=opensearch&format=json&search=moose
   
  getWiki (text) {
    let self = this;
    $.ajax({
      url: this.state.url,
      dataType: "jsonp",
          data: {
            'action': "opensearch",
            'format': "json",
            'search': text
          },
          success: function(data) {
            console.log(data);
            self.setState({
              options: data[1],
              articles: data[2],
              links: data[3]
            })
          }
    });   
  }
  
  getOptions (text) {
    // make api call with text
    let self = this;  
    console.log(text, "tis is text");
    this.getWiki(text);    
  }
  
  getArticle (index) {
    let self = this;
    this.setState({
      article: self.state.articles[index],
      link: self.state.links[index],
      title: self.state.options[index]
    })
  }
  
  render () {
    return (
     <div className="app-container">
        <div>
          <h2 className="heading"> WikiPedia Viewer </h2>
        </div>
        <SearchBox handleResults={this.getOptions}/>
        <Results showOption={this.getArticle} options={this.state.options} />
        <Article data={this.state} article={this.state.article} />
     </div>
    )
  }
}


class SearchBox extends React.Component {
  
  constructor (props) {
    super(props)  
    
    this.state = {
      query: ""
    }
  
    this.handleChange = this.handleChange.bind(this);
  }
  
  // take the value of e
  handleChange (e) {
    console.log(e.target.value, "this is e");
    this.setState({
      query: e.target.value
    }, function () {
      this.props.handleResults(this.state.query)
    }) 
  }
   
  render () {
    return (
       <div className="search-box">     
         <input type="text" placeholder="Query" onChange={this.handleChange} value={this.state.term} />
         <a target="_blank" href="https://en.wikipedia.org/wiki/Special:Random" id="random-button">Random Article</a>        
       </div>
    )
  }  
}

class Results extends React.Component {
  constructor (props) {
    super(props) 
      
    
    this.state = {
      choice: ""
    }
  }
  
  componentWillRecieveProps (props) {
    console.log(props);
  }
  
  handleClick (index) {
    let self = this;
    this.setState({
      choice: index
    }, function () {
      this.props.showOption(self.state.choice)
    })
  }
  
  
  render () {
    console.log(this.props.options, "this is options");
    let self = this;
    let options;
    if (this.props.options) {
      options = this.props.options.map(function (e, i) {
      return (
        <li onClick={self.handleClick.bind(self, i)} className="wiki-option">{e}</li>
       )
    }); 
    } else {
      options = null;
    }
      
    return (
      <div className="results">
        <ul>
         {options || ""}
        </ul>
      </div>
    )
  }
}

class Article extends React.Component {
  
  
  render () {
    return (
      <div className="article">
        <h4>{this.props.data.title || ""}</h4>
        <p>{this.props.article || ""}</p>
        <a>{this.props.data.link || ""}</a>
      </div>
    )
  }
  
  
}


ReactDOM.render(
  <App />,
  document.getElementById('app')
)
              
            
!
999px

Console