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

              
                #app
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Lato:400,700,900)
$primary = #0099aa

*
  box-sizing border-box
  
body
  margin-top 2rem
  font-family 'Lato', sans-serif
  background lighten($primary, 7)
  color white
  -webkit-font-smoothing antialiased
  font-size 1.1rem
  
  
// searchbox component
.searchbox
  max-width 20rem
  margin 1rem auto
  
  &__input
    height 3rem
    width 100%
    box-shadow none
    border none
    padding 0 1rem
    color darken($primary, 20)
    border-radius .2rem
    
  &__button
    width 100%
    padding 1rem 2rem
    border none
    margin 1rem 0 0 0
    background lighten($primary, 20)
    color darken($primary, 10)
    font-weight 700
    border-radius .4rem
    
    &:hover 
      background lighten($primary, 15)

// the card component
.card
  position relative
  background lighten($primary, 5)
  max-width 20rem
  margin 7rem auto 2rem
  border solid 5px $primary
  border-radius .4rem
  padding 5.5rem 2.5rem 1rem
  
  &__avatar
    position absolute
    top 0
    left 50%
    transform translate(-50%, -50%)
    width 10rem
    height auto
    text-align center
    margin 0 auto
    display block
    border-radius 50%
    background $primary
    padding 5px
    max-width 100%
    
    transition 0.2s
    
    &:hover
      background darken($primary, 5)
    
  &__username
    font-size 2rem
    font-weight 900
    text-align center
    margin 1rem auto
    
  &__link
    color white
    border-bottom solid 2px white
    text-decoration none
    margin-bottom 0
    padding-bottom 0
    
    &:hover
      opacity 0.8
    
  &__notfound
    text-align center
    margin 0 auto
    padding 1rem
    
/* some non-BEM stuff to avoid overloading the JSX for demo purposes */
dl
  margin 0
  padding 0

dt, dd
  text-align center

dt
  font-weight 900
  margin-bottom .2rem
  
dd
  margin 0 0 1rem 0
  
              
            
!

JS

              
                const Component = React.Component

class App extends Component {
  constructor(props) {
    super(props)
    
    this.state = {
      username: 'simonswiss',
      realName: '',
      avatar: '',
      location: '',
      repos: '',
      followers: '',
      url: '',
      notFound: ''
    }
  }
  render() {
    return (
      <div>
        <SearchBox fetchUser={this.fetchUser.bind(this)}/>
        <Card data={this.state} />
      </div>
    )
  }
  
  // the api request function
  fetchApi(url) { 
    
    fetch(url)
      .then((res) => res.json() )
      .then((data) => {
        
        // update state with API data
        this.setState({
          username: data.login,
          realName: data.name,
          avatar: data.avatar_url,
          location: data.location,
          repos: data.public_repos,
          followers: data.followers,
          url: data.html_url,
          notFound: data.message
        })
      })
      .catch((err) => console.log('oh no!') )
  }
  
  fetchUser(username) {
    let url = `https://api.github.com/users/${username}`
    this.fetchApi(url)
  }
  
  componentDidMount() {
    let url = `https://api.github.com/users/${this.state.username}`
    this.fetchApi(url)
  }
}

class SearchBox extends Component {
  render() {
    return (
      <form 
        className="searchbox" 
        onSubmit={this.handleClick.bind(this)}>
        <input
          ref="search"
          className="searchbox__input" 
          type="text" 
          placeholder="type username..."/>
        
        <input
          type="submit"
          className="searchbox__button"
          value="Search GitHub User" />
      </form>
    )
  }
  
  handleClick(e) {
    e.preventDefault()
    let username = this.refs.search.getDOMNode().value
    // sending the username value to parent component to fetch new data from API
    this.props.fetchUser(username)
    this.refs.search.getDOMNode().value = ''
  }
}

class Card extends Component {
  render() {
    let data = this.props.data
    
    if (data.notFound === 'Not Found') {
      // when username is not found...
      return <h3 className="card__notfound">User not found. Try again!</h3>
    } else {
      // if username found, then...
      return (
        <div className="card">
          <a href={data.url} target="_blank">
            <img className="card__avatar" src={data.avatar} />             
          </a>
          <h2 className="card__username">
            <a className="card__link" href={data.url} target="_blank">{data.username}</a></h2>
          <dl>
            <dt>Real name</dt>
            <dd>{data.realName}</dd>

            <dt>Location</dt>
            <dd>{data.location}</dd>

            <dt>Number of public repos</dt>
            <dd>{data.repos}</dd>

            <dt>Number of followers</dt>
            <dd>{data.followers}</dd>
          </dl>
        </div>
      )
    }
  }
}

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

Console