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

              
                <head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<div id="root">
</div>


<style>
  @import url('https://fonts.googleapis.com/css?family=Poppins&display=swap');
</style>

<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
              
            
!

CSS

              
                /* prefixed by https://autoprefixer.github.io (PostCSS: v7.0.23, autoprefixer: v9.7.3) */

html,
body {
  height: 100%;
  -webkit-box-sizing: border-box;
          box-sizing: border-box;
}
body {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  font-family: "Poppins", sans-serif;
  text-align: justify;
}

.main-container {
  width: 40vw;
  background: #d9d9d9;
  padding: 2rem;
  border-radius: 1rem;
  -webkit-box-shadow: 0px 0px 30px #e4e7e8;
          box-shadow: 0px 0px 30px #e4e7e8;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
      -ms-flex-direction: column;
          flex-direction: column;
  -ms-flex-wrap: wrap;
      flex-wrap: wrap;
}
#text {
  font-size: 1.5rem;
  
}

#author {
  font-size: 1.2rem;
  font-style: italic;
  
  display: -webkit-box;
  
  display: -ms-flexbox;
  
  display: flex;
  -webkit-box-pack: end;
      -ms-flex-pack: end;
          justify-content: flex-end;
}
.button-row {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
}
#tweet-button {
  width: 80%;
}

#next-back-buttons {
  width: 20%;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: justify;
      -ms-flex-pack: justify;
          justify-content: space-between;
}
#back-button {
  width: 48%;
}
#next-button {
  width: 48%;
}

button {
  border: none;
  border-radius: 0.3rem;
  cursor: pointer;
  height: 100%;
  width: 100%;
  font-size: 0.95em;
  background-color: #d9d9d9;
}
button:focus {
  outline: none;
}

#back-quote {
  
  color: black;
  -webkit-transition-duration: 0.2s;
       -o-transition-duration: 0.2s;
          transition-duration: 0.2s;
}
#back-quote:hover {
  background-color: #313131;
  color: white;
  -webkit-box-shadow: 1px 1px 5px gray;
          box-shadow: 1px 1px 5px gray;
}
#new-quote {
  
  color: black;
  -webkit-transition-duration: 0.2s;
       -o-transition-duration: 0.2s;
          transition-duration: 0.2s;
}
#new-quote:hover {
  background-color: #313131;
  color: white;
  -webkit-box-shadow: 1px 1px 5px gray;
          box-shadow: 1px 1px 5px gray;
}

@media screen and (max-width: 1280px) {
  .main-container {
    width: 60vw;
  }
  button {
    font-size: 0.75rem;
  }
  #text {
    font-size: 1.35rem;
  }
  #author {
    font-size: 1.05rem;
  }
  #tweet-button {
    width: 50%;
  }
  #next-back-buttons {
    width: 50%;
    -webkit-box-pack: flex-end space-between;
        -ms-flex-pack: flex-end space-between;
            justify-content: flex-end space-between;
  }
}

@media screen and (max-width: 768px) {
  .main-container {
    width: 80vw;
    padding: 1rem;
  }
  #text {
    font-size: 1.2rem;
  }
  #author {
    font-size: 0.9rem;
  }
  #tweet-button {
    width: 30%;
  }
  #next-back-buttons {
    width: 70%;
    -webkit-box-pack: flex-end space-between;
        -ms-flex-pack: flex-end space-between;
            justify-content: flex-end space-between;
  }
}
@media screen and (max-width: 414px) {
  #text {
    font-size: 0.9rem;
  }
  #author {
    font-size: 0.65rem;
  }
  button {
    font-size: 0.7rem;
  }
  .button-row {
    -webkit-box-orient: vertical;
    -webkit-box-direction: reverse;
        -ms-flex-direction: column-reverse;
            flex-direction: column-reverse;
    -webkit-box-align: center;
        -ms-flex-align: center;
            align-items: center;
    -ms-flex-line-pack: justify;
        align-content: space-between;
  }
  #tweet-button {
    -webkit-box-pack: end;
        -ms-flex-pack: end;
            justify-content: flex-end;
    margin-top: 0.7rem;
  }
  #next-back-buttons {
    -webkit-box-pack: justify;
        -ms-flex-pack: justify;
            justify-content: space-between;
  }
  .main-container {
    padding: 0.5rem 1.5rem;
  }
}
              
            
!

JS

              
                const colors = {
  0: {
    backColor: "linear-gradient(to bottom right, #00465F, #5FBEE0)",
    lightColor: "#5FBEE0",
    darkColor: "#00465F",
    lightBorder: "2px solid #5FBEE0",
    darkBorder: "2px solid #00465F"
  },
  1: {
    backColor: "radial-gradient(#88EE23, #1F5003)",
    lightColor: "#88EE23",
    darkColor: "#1F5003",
    lightBorder: "2px solid #88EE23",
    darkBorder: "2px solid #1F5003"
  },
  2: {
    backColor: "radial-gradient(#FA931F, #542F04)",
    lightColor: "#FA931F",
    darkColor: "#542F04",
    lightBorder: "2px solid #FA931F",
    darkBorder: "2px solid #542F04"
  },
  3: {
    backColor: "radial-gradient(#FC9424, #D03900)",
    lightColor: "#D03900",
    darkColor: "#FC9424",
    lightBorder: "2px solid #D03900",
    darkBorder: "2px solid #FC9424"
  },
  4: {
    backColor: "radial-gradient(#00E6DB, #050073)",
    lightColor: "#00E6DB",
    darkColor: "#050073",
    lightBorder: "2px solid #00E6DB",
    darkBorder: "2px solid #050073"
  },
  5: {
    backColor: "radial-gradient(#FF8F2C, #B20000 )",
    lightColor: "#FF8F2C",
    darkColor: " #B20000",
    lightBorder: "2px solid #FF8F2C",
    darkBorder: "2px solid  #B20000"
  },
  6: {
    backColor: "radial-gradient(#858585 , #2F2F2F )",
    lightColor: "#858585",
    darkColor: "#2F2F2F",
    lightBorder: "2px solid #858585",
    darkBorder: "2px solid #2F2F2F"
  },
  7: {
    backColor: "radial-gradient(#CBCB0D , #313131)",
    lightColor: "#CBCB0D",
    darkColor: "#313131",
    lightBorder: "2px solid #CBCB0D",
    darkBorder: "2px solid #313131"
  },
  8: {
    backColor: "radial-gradient(#EA5AC5 , #45007F)",
    lightColor: "#EA5AC5",
    darkColor: "#45007F",
    lightBorder: "2px solid #EA5AC5",
    darkBorder: "2px solid #45007F"
  },
  9: {
    backColor: "radial-gradient(#04D5B2 , #00594A)",
    lightColor: "#04D5B2",
    darkColor: "#00594A",
    lightBorder: "2px solid #04D5B2",
    darkBorder: "2px solid #00594A"
  }
};

const quotes = {
  0: {
    text:
      "In three words I can sum up everything I've learned about life: it goes on.",
    author: "― Robert Frost"
  },
  1: {
    text:
      "I'm selfish, impatient and a little insecure. I make mistakes, I am out of control and at times hard to handle. But if you can't handle me at my worst, then you sure as hell don't deserve me at my best.",
    author: "― Marilyn Monroe"
  },
  2: {
    text: "Be yourself; everyone else is already taken.",
    author: "― Oscar Wilde"
  },
  3: {
    text:
      "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.",
    author: "― Albert Einstein"
  },
  4: {
    text: "So many books, so little time.",
    author: "― Frank Zappa"
  },
  5: {
    text:
      "Be who you are and say what you feel, because those who mind don't matter, and those who matter don't mind.",
    author: "― Bernard M. Baruch"
  },
  6: {
    text: "A room without books is like a body without a soul.",
    author: "― Marcus Tullius Cicero"
  },
  7: {
    text: "You've gotta dance like there's nobody watching",
    author: "― William W. Purkey"
  },
  8: {
    text:
      "You know you're in love when you can't fall asleep because reality is finally better than your dreams.",
    author: "― Dr. Seuss"
  },
  9: {
    text: "You only live once, but if you do it right, once is enough.",
    author: "― Mae West"
  }
};

class Quote extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      num: Math.floor(Math.random() * 10),
      prevNum: "",
      count: 1,
      lastFive: [],
      firstLoad: 0
    };
    this.handleBackClick = this.handleBackClick.bind(this);
    this.handleNextClick = this.handleNextClick.bind(this);
  }

  handleBackClick() {
    this.setState(prevState => ({
      num: prevState.prevNum,
      prevNum: "",
      nextNum: prevState.num,
      count: 0
    }));
  }
  handleNextClick() {
    var i = Math.floor(Math.random() * 10);
    if (this.state.count == 0) {
      this.setState(prevState => ({
        num: prevState.nextNum,
        prevNum: prevState.num,
        count: 1
      }));
    } else {
      if (this.state.lastFive.includes(i) || this.state.num == i) {
        while (this.state.lastFive.includes(i) || this.state.num == i) {
          i = Math.floor(Math.random() * 10);
        }
        this.setState(prevState => ({
          num: i,
          prevNum: prevState.num,
          count: 1,
          lastFive:
            prevState.lastFive.length < 5
              ? [...prevState.lastFive, prevState.num]
              : prevState.lastFive.slice(1).concat(prevState.num)
        }));
      } else {
        this.setState(prevState => ({
          num: i,
          prevNum: prevState.num,
          count: 1,
          lastFive:
            prevState.lastFive.length < 5
              ? [...prevState.lastFive, prevState.num]
              : prevState.lastFive.slice(1).concat(prevState.num)
        }));
      }
    }
  }

  componentDidMount() {
    if (this.state.firstLoad === 0) {
      var x = this.state.num;
      document.body.style.background = colors[x].backColor;
      document.getElementById("text").style.color = colors[x].darkColor;
      document.getElementById("author").style.color = colors[x].darkColor;
      document.getElementById("back-quote").style.border =
        colors[x].lightBorder;
      document.getElementById("new-quote").style.border = colors[x].darkBorder;
    }
  }
  componentDidUpdate(prevProps, prevState) {
    if (prevState.firstLoad === 0) {
      this.setState({ firstLoad: 1 });
    }

    var x = this.state.num;

    document.body.style.background = colors[x].backColor;
    document.getElementById("text").style.color = colors[x].darkColor;
    document.getElementById("author").style.color = colors[x].darkColor;
    document.getElementById("back-quote").style.border = colors[x].lightBorder;
    document.getElementById("new-quote").style.border = colors[x].darkBorder;
  }

  render() {
    const disabledButton = (
      <button
        id="back-quote"
        onClick={this.handleBackClick}
        disabled
        style={{ opacity: 0.2, cursor: "not-allowed" }}
      >
        Back
      </button>
    );
    const normalButton = (
      <button id="back-quote" onClick={this.handleBackClick}>
        Back
      </button>
    );

    return (
      <div>
        <div id="quote-box" class="main-container">
          {/*----------------------Text and Author----------------------*/}

          <div id="text">
            <p>{quotes[this.state.num] ? quotes[this.state.num].text : null}</p>
          </div>

          <div id="author">
            <p>
              {quotes[this.state.num] ? quotes[this.state.num].author : null}
            </p>
          </div>

          {/*====================Text and Author=======================*/}
          <div class="button-row">
            <div id="tweet-button">
              <a
                href={`twitter.com/intent/tweet?text=${
                  quotes[this.state.num] ? quotes[this.state.num].text : null
                }  ${
                  quotes[this.state.num] ? quotes[this.state.num].author : null
                }`}
                target="_blank"
                id="tweet-quote"
                className="twitter-share-button"
                data-size="large"
              >
                Tweet
              </a>
            </div>
            {/*---------Buttons----------*/}
            <div id="next-back-buttons">
              <div id="back-button">
                {this.state.count === 1 && this.state.firstLoad !== 0
                  ? normalButton
                  : disabledButton}
              </div>
              <div id="next-button">
                <button id="new-quote" onClick={this.handleNextClick}>
                  Next
                </button>
              </div>
            </div>
            {/*--------Buttons---------*/}
          </div>
        </div>
      </div>
    );
  }
}

ReactDOM.render(<Quote />, document.getElementById("root"));

              
            
!
999px

Console