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

              
                <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="description"
      content="Web site created using create-react-app"
    />
    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet"> 
    <!--
      manifest.json provides metadata used when your web app is installed on a
      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
    -->
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
    <!--
      Notice the use of %PUBLIC_URL% in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    -->
    <title>React App</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
  </body>
</html>


              
            
!

CSS

              
                body {
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background-color: rgb(247, 246, 242);
}

.quote-box {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border: 2px solid black;
  border-radius: 10px;
  min-height: 30vh;
  width: 35vw;
  background-color: rgb(240, 229, 207);
  padding: 1.5rem;
}

.quote-and-author-container {
  width:90%;
}

.quote {
  font-family: 'Open Sans', sans-serif;
  font-size: 1.125rem;
  font-weight: 700;
  color: rgb(75, 101, 135);
  text-align: center;
}

.author {
  font-family: 'Open Sans', sans-serif;
  color: rgb(75, 101, 135);
  width: 90%;
  text-align: right;
}

.actions-container {
  margin-top: 1em;
  width: 85%;
  display: flex;
  justify-content: space-between;
}

.tweet-quote {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #1DA1F2;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  font-size: 35px;
  color: white;
}

.new-Quote-button {
  font-family: "Open Sans", sans-serif;
  color: rgb(75, 101, 135);
  font-weight: 700;
  width: 100px;
  border: none;
  border-radius: 5px;
  background-color: rgb(200, 198, 198);
  box-shadow: 3px 3px black;
}

.new-Quote-button:hover {
  cursor: pointer;
}
              
            
!

JS

              
                import ReactDOM from "https://cdn.skypack.dev/react-dom";
import React from "https://cdn.skypack.dev/react";
import { AiOutlineTwitter } from "https://cdn.skypack.dev/react-icons/ai"

class Quotebox extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      QuoteJSON: this.props.quotes[Math.floor(Math.random() * this.props.quotes.length)]
    }
    this.generateNewQuote = this.generateNewQuote.bind(this);
  }

  generateNewQuote() {
    this.setState({
      QuoteJSON: this.props.quotes[Math.floor(Math.random() * this.props.quotes.length)]
    });
    console.log(this.state.QuoteJSON)
  }

  render() {
    return (
      <div id='quote-box' className="quote-box">
        <div className="quote-and-author-container">
          <Quote quote = {this.state.QuoteJSON.quote} />
          <Author author = {this.state.QuoteJSON.author}/>
        </div>
        <div className="actions-container">
          <a id='tweet-quote' className='tweet-quote' href='"twitter.com/intent/tweet"'><AiOutlineTwitter /></a>
          <NewQuoteButton id='new-quote' className='new-Quote-button' onClick={this.generateNewQuote}>New Quote</NewQuoteButton>
        </div>
      </div>
    );
  }
}

class Quote extends React.Component {
  render() {
    return (
      <p id="text" className="quote">{this.props.quote}</p>
    );
  };
}

class Author extends React.Component {
  render() {
    return(
      <p id="author" className="author">- {this.props.author}</p>
    )
  }
}

class NewQuoteButton extends React.Component {
  constructor(props) {
    super(props)
    this.handleButtonOnClick = this.handleButtonOnClick.bind(this);
  }

  handleButtonOnClick() {
    this.props.onClick()
  }

  render() {
    return (
      <button id='new-quote' className='new-Quote-button' onClick={this.handleButtonOnClick}>New Quote</button>
    )
  }
}

const QUOTES = [{
  "quote":"Life isn’t about getting and having, it’s about giving and being.","author":"Kevin Kruse"},
{
  "quote":"Whatever the mind of man can conceive and believe, it can achieve.","author":"Napoleon Hill"},
{
  "quote":"Strive not to be a success, but rather to be of value.","author":"Albert Einstein"},
{
  "quote":"Two roads diverged in a wood, and I—I took the one less traveled by, And that has made all the difference.","author":"Robert Frost"},
{
  "quote":"I attribute my success to this: I never gave or took any excuse.","author":"Florence Nightingale"},
{
  "quote":"You miss 100% of the shots you don’t take.","author":"Wayne Gretzky"},
{
  "quote":"I’ve missed more than 9000 shots in my career. I’ve lost almost 300 games. 26 times I’ve been trusted to take the game winning shot and missed. I’ve failed over and over and over again in my life. And that is why I succeed.","author":"Michael Jordan"},
{
  "quote":"The most difficult thing is the decision to act, the rest is merely tenacity.","author":"Amelia Earhart"}]

ReactDOM.render(
  <React.StrictMode>
    <Quotebox quotes={QUOTES}/>
  </React.StrictMode>,
  document.getElementById('root')
);

              
            
!
999px

Console