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

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

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Biryani" rel="stylesheet">

<div id="app"></div>
            
          
!
            
              html,
body {
  margin: 0;

  #quote-box {
    display: grid;
    grid-template-columns: auto 400px auto;
    grid-template-rows: 20vh 60vh 20vh;
    transition: all 0.5s linear;

    #display-box {
      background-color: ivory;
      grid-column: 2;
      grid-row: 2;
      border-radius: 10px 10px 10px 10px;
      text-align: center;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      padding: 10% 0% 10% 0%;

      #text,
      #author {
        font-family: Biryani;
        font-size: 12px;
        transition: 0.5s linear;
        margin: 5px 15px 5px 15px;
      }

      .lowerButtons {
        display: flex;
        justify-content: center;
        align-items: center;

        .buttonBorder {
          border-radius: 5px;
          border: 2px solid;
          margin-right: 10px;
          transition: 0.5s linear;

          #new-quote {
            border: none;
            border-radius: 5px;
            height: 30px;
            width: 80px;
            font-size: 9px;
            transition: 0.5s linear;
          }

          #new-quote:hover {
            border-radius: 0;
            cursor: pointer;
            //transition: 1s linear;
          }
        }

        #tweet-quote {
          border: 2px solid;
          border-radius: 5px;
          display: flex;
          justify-content: center;
          align-items: center;
          height: 30px;
          width: 80px;
          text-decoration: none;
          margin-left: 10px;
          transition: 0.5s linear;

          i {
            font-size: 25px;
            transition: 0.5s linear;
          }
        }
      }
    }
    
    footer {
      grid-column: 2;
      grid-row: 3;
      text-align: center;
      font-size: 10px;
      font-family: Biryani;
    }
  }
  
}
            
          
!
            
              //const colors = ["#00a8b5", "#774898", "#e62a76", "#fbb901"];
const colors = ["#EB376D", "#EC5D63", "#E3A858", "#2BB5C4", "#249389"];
const quoteAndAuthor = [
  {
    quote:
      "No man ever wetted clay and then left it, as if there would be bricks by chance and fortune.",
    author: "Plutarch"
  },
  {
    quote:
      "I am fond of pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals.",
    author: "Winston S. Churchill"
  },
  {
    quote:
      "It is not that life ashore is distasteful to me. But life at sea is better.",
    author: "Sir Francis Drake"
  },
  {
    quote:
      "I don’t believe in astrology; I’m a Sagittarius and we’re skeptical.",
    author: "Arthur C. Clarke"
  },
  {
    quote: "Thousands have lived without love, not one without water.",
    author: "W. H. Auden"
  },
  {
    quote: "Writing is easy. All you have to do is cross out the wrong words.",
    author: "Mark Twain"
  },
  {
    quote:
      "Each of us is carving a stone, erecting a column, or cutting a piece of stained glass in the construction of something much bigger than ourselves.",
    author: "Adrienne Clarkson"
  },
  {
    quote: "Bronze is the mirror of the form, wine of the mind.",
    author: "Aeschylus"
  },
  {
    quote: "Sometimes the wheel turns slowly, but it turns.",
    author: "Lorne Michaels"
  },
  {
    quote:
      "Wealth consists not in having great possessions, but in having few wants.",
    author: "Epictetus"
  },
  {
    quote: "Everything has its limit – iron ore cannot be educated into gold.",
    author: "Mark Twain"
  }
];

const randomizer = arr => Math.floor(Math.random() * arr.length);
let randomQuote = randomizer(quoteAndAuthor);
let randomColor = randomizer(colors);

class Container extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      quote: quoteAndAuthor[randomQuote].quote,
      author: quoteAndAuthor[randomQuote].author,
      color: colors[randomColor]
    };
    this.handleClick = () => {
      do {
        randomColor = randomizer(colors);
      } while (colors[randomColor] == this.state.color);
      do {
        randomQuote = randomizer(quoteAndAuthor);
      } while (quoteAndAuthor[randomQuote].quote == this.state.quote);
      this.setState({
        quote: quoteAndAuthor[randomQuote].quote,
        author: quoteAndAuthor[randomQuote].author,
        color: colors[randomColor]
      });
    };
  }

  render() {
    return (
      <div id="quote-box" style={{ background: this.state.color }}>
        <div id="display-box">
          <TextAndAuthor
            quote={this.state.quote}
            author={this.state.author}
            color={this.state.color}
          />
          <div className="lowerButtons">
            <NewQuote color={this.state.color} onClick={this.handleClick} />
            <NewTweet
              quote={this.state.quote}
              author={this.state.author}
              color={this.state.color}
            />
          </div>
        </div>
        <footer style={{ color: "ivory" }}>by Iker</footer>
      </div>
    );
  }
}

class TextAndAuthor extends React.Component {
  render() {
    return (
      <div>
        <h1 id="text" style={{ color: this.props.color }}>
          <i class="fas fa-quote-left" style={{ marginRight: "10px" }} />
          {this.props.quote}
          {/*<i class="fas fa-quote-right" />*/}
        </h1>
        <h2 id="author" style={{ color: this.props.color }}>
          -{this.props.author}
        </h2>
      </div>
    );
  }
}

class NewQuote extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      hover: false
    };
    this.handleHover = () => {
      this.setState({
        hover: !this.state.hover
      });
    };
  }
  render() {
    const iconStyle = {
      backgroundColor: this.state.hover ? this.props.color : "ivory",
      color: this.state.hover ? "ivory" : this.props.color
    };
    return (
      <div className="buttonBorder" style={{ borderColor: this.props.color }}>
        <button
          id="new-quote"
          onClick={this.props.onClick}
          style={iconStyle}
          onMouseEnter={this.handleHover}
          onMouseLeave={this.handleHover}
        >
          NEW QUOTE
        </button>
      </div>
    );
  }
}

class NewTweet extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      hover: false
    };
    this.handleHover = () => {
      this.setState({
        hover: !this.state.hover
      });
    };
  }
  render() {
    const iconStyle = {
      backgroundColor: this.state.hover ? this.props.color : "ivory",
      color: this.state.hover ? "ivory" : this.props.color,
      borderColor: this.props.color
    };
    const tweetLink = `https://twitter.com/intent/tweet?text=${encodeURIComponent(
      `"${this.props.quote}" ${this.props.author}`
    )}`;
    return (
      <div>
        <a
          id="tweet-quote"
          className="twitter-share-button"
          href={tweetLink}
          target="_blank"
          style={iconStyle}
          onMouseEnter={this.handleHover}
          onMouseLeave={this.handleHover}
        >
          <i className="fab fa-twitter" style={iconStyle} />
        </a>
      </div>
    );
  }
}

ReactDOM.render(<Container />, document.getElementById("app"));

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

Console