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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

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

CSS

              
                * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Noto Serif", serif;
  font-weight: 200;
}

#site-body {
  width: 100vw;
  height: 100vh;

  display: flex;
  justify-content: center;
  align-items: center;

  background: linear-gradient(rgba(0, 0, 0, 0.25), rgba(0, 0, 0, 0.25)),
    url(https://www.dropbox.com/s/raw/wg8y27g5pqkxurl/lukasz-szmigiel-41435-unsplash-min.jpg)
      rgb(224, 162, 120);
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
}

#quote-box {
  margin: 0 10vw;
  border-radius: 5px;
  text-align: center;
  padding: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: rgba(216, 216, 216, 0.8);
  animation: slideIn 1s;
}

#tweet-quote {
  font-size: 3em;
  color: rgb(218, 129, 70);
  font-family: sans-serif;
  line-height: 0;
  transition: color 0.2s;
}

#tweet-quote:hover {
  color: rgb(255, 151, 81);
}

#author {
  color: rgb(58, 58, 58);
  align-self: flex-end;
  padding: 10px 0;
  transition: opacity 0.4s;
}

#text {
  color: rgb(32, 32, 32);
  padding: 15px 0;
  transition: opacity 0.4s;
}

#new-quote {
  font-weight: bold;
  color: white;
  background-color: rgb(218, 129, 70);
  border: none;
  border-bottom: 5px solid rgb(175, 108, 63);
  cursor: pointer;
  outline: none;
  padding: 0 20px;
  height: 50px;
  transition: border-width 0.2s, transform 0.2s, background-color 0.2s;
  border-radius: 2px;
}

#new-quote:hover {
  border-width: 0;
  background-color: rgb(255, 151, 81);
  transform: translateY(5px);
}

#new-quote:active {
  background-color: rgb(161, 99, 58);
}

#footer-text {
  position: absolute;
  color: white;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
  padding: 0 15px 10px 15px;
  font-size: 0.8em;
}

#footer-text a {
  color: white;
}

#footer-text a:visited {
  color: rgb(218, 129, 70);
}

@media (max-width: 860px) {
  #text {
    font-size: 1.5em;
  }

  #author {
    font-size: 1em;
  }
}

@media (max-width: 450px) {
  #text {
    font-size: 1em;
  }

  #author {
    font-size: 0.8em;
    align-self: center;
  }

  #tweet-quote {
    font-size: 2em;
  }
}

/* ANIMATIONS */
@keyframes slideIn {
  from {
    transform: translate3d(0, -1000px, 0);
  }
  to {
    transform: translate3d(0, 0, 0);
  }
}

              
            
!

JS

              
                class QuoteBox extends React.Component {
  constructor() {
    super();
    this.state = {
      quotes: [],
      currentQuote: "",
      hideText: false
    };

    this.handleClick = this.handleClick.bind(this);
  }

  // Fetch the quotes.json when mounting first time
  componentDidMount() {
    fetch(
      "https://gist.githubusercontent.com/camperbot/5a022b72e96c4c9585c32bf6a75f62d9/raw/e3c6895ce42069f0ee7e991229064f167fe8ccdc/quotes.json"
    )
      .then(response => response.json())
      .then(data => {
        // Store quotes in state and choose a random one to show initially
        const randomIndex = Math.floor(Math.random() * data.quotes.length);
        const { quote, author } = data.quotes[randomIndex];
        this.setState({
          quotes: data.quotes,
          currentQuote: quote,
          currentAuthor: author
        });
      });
  }

  // Choose a new random quote when button is clicked (fade transition first)
  handleClick() {
    const randomIndex = Math.floor(Math.random() * this.state.quotes.length);
    const { quote, author } = this.state.quotes[randomIndex];
    this.setState({ hideText: true });

    // After 0.4s the old quote will have faded away, so fade in new quote
    setTimeout(() => {
      this.setState({
        currentQuote: quote,
        currentAuthor: author,
        hideText: false
      });
    }, 400);
  }

  render() {
    const tweetParameters = encodeURIComponent(
      this.state.currentQuote + ` (${this.state.currentAuthor})`
    );

    const textOpacity = this.state.hideText ? { opacity: 0 } : { opacity: 1 };

    return (
      <main>
        <div id="quote-box">
          <a
            id="tweet-quote"
            href={
              "https://www.twitter.com/intent/tweet?text=" + tweetParameters
            }
            title="Share this quote on Twitter"
            target="_blank"
            rel="noopener noreferrer"
          >
            <span className="fab fa-twitter" />
          </a>
          <h1 id="text" style={textOpacity}>
            {this.state.currentQuote}
          </h1>
          <h2 id="author" style={textOpacity}>
            {this.state.currentAuthor}
          </h2>
          <button
            id="new-quote"
            onClick={this.handleClick}
            title="Show a new quote"
          >
            New Quote
          </button>
        </div>
      </main>
    );
  }
}

const Credits = () => {
  return (
    <footer>
      <p id="footer-text">
        Made by Bilal Ahmad for a freeCodeCamp challenge.{" "}
        <a
          href="https://unsplash.com/photos/ps2daRcXYes"
          title="Link to image"
          target="_blank"
          rel="noopener noreferrer"
        >
          Image by Lukasz Szmigiel
        </a>
      </p>
    </footer>
  );
};

class App extends React.Component {
  render() {
    return (
      <div id="site-body">
        <QuoteBox />
        <Credits />
      </div>
    );
  }
}


  ReactDOM.render(
    <App/>,
    document.getElementById('root')
  );



              
            
!
999px

Console