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

              
                // Colors
$color-bg--primary: #1A2732;
$color-bg--secondary: #29333E;
$color-primary: #6E63E6;

html {
  font-size: 100%;
  box-sizing: border-box;
  scroll-behavior: smooth;
}

*, *:before, *:after {
  box-sizing: inherit;
}

*:focus {
  outline: 3px dashed orange;
}

body {
  background-color: $color-bg--primary;
  overflow-x: hidden;
}

.wrapper {
  margin: 0 auto;
  width: 90vw;
  height: 100vh;
  
  @media only screen and (min-width: 1920px) {
    padding-top: 40px;
  }
}

.bg-container--secondary {
  background-color: $color-bg--secondary;
  padding: 30px;
  margin: 0;
  border-radius: 1.5rem;
  width: 90vw;
  height: 25rem;
  
  // very small screens
  @media only screen and (max-width: 340px) {
    width: 95vw;
  }
  
  @media only screen and (min-width: 640px) {
    width: 80vw;
    max-width: 600px;
    height: 30rem;
  }
}

// Flex helpers
.flex {
  display: flex;
}

.flex-vertical {
  flex-direction: column;
}

.flex-jc-sb {
  justify-content: space-between;
}

.flex-ai-c {
  align-items: center;
}

// Text and links
.heading-xl {
  font-family: 'Merriweather', serif;
  font-size: 1.75rem;
  color: #fff;
  line-height: 150%;
  text-align: center;
  
  @media only screen and (min-width: 640px) {
    font-size: 2rem; 
  }
  
  @media only screen and (min-width: 1024px) {
    font-size: 3rem; 
  }
}

.text-xl {
  font-family: 'Merriweather', serif;
  font-size: 1.25rem;
  color: #fff;
  line-height: 150%;
  
  @media only screen and (min-width: 480px) {
    font-size: 1.5rem; 
  }
  
  @media only screen and (min-width: 640px) {
    font-size: 1.75rem; 
  }
  
  @media only screen and (min-width: 1024px) {
    font-size: 2rem; 
  }
}

.text-xs {
  font-family: 'Merriweather', serif;
  font-size: 0.75rem;
  color: #fff;
  line-height: 150%;
}

a {
  font-family: 'Merriweather', sans-serif;
  color: #fff;
  text-decoration: underline;
  cursor: pointer;
}

// Buttons
.btn {
  display: inline-block;
  padding: 8px 12px;
  border: none;
  border-radius: 3rem;
  font-family: 'Merriweather', sans-serif;
  font-weight: 500;
  font-size: 1rem;
  line-height: 125%;
  
  &:hover {
    cursor: pointer;
    transform: scale(1.03);
    background-color: #7A6EFF;
  }
  
  &:focus:not(:focus-visible) {
    outline: none;
  }
}

.btn-primary {
  background-color: $color-primary;
  color: #fff;
}

.icon {
  margin-right: 8px;
}

// Text animation
.fadeIn {
  animation: 2s fade-in linear;
}

@keyframes fade-in {
  0% {
    opacity: 0;
  }
  25% {
    opacity: 0;
  }
  50% {
    opacity: 0;
  }
  75% {
    opacity: 0.25;
  }
  87% {
    opacity: 0.5;
  }
  100% {
    opacity: 1;
  }
}

// Box animation
.shadow {
  animation: pulse 2s;
  box-shadow: 0 0 0 40px rgba(#fff, 0);
}

@keyframes pulse {
  0% { 
    box-shadow: 0 0 0 0 rgba(40,50,62,100);
  }
}
              
            
!

JS

              
                class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      currentQuote: {text: '', author: ''},
      quotes: [{}]
    };
    this.getQuotes = this.getQuotes.bind(this);
    this.createQuote = this.createQuote.bind(this);
    this.animate = this.animate.bind(this);
    this.handleClick = this.handleClick.bind(this);
  }
  
  // Fetch the code from a JSON file
  getQuotes() {
    fetch('https://raw.githubusercontent.com/robaish/hosted-assets/main/quotes.json')
      .then(response => response.json())
      .then(jsonData => {
        this.setState({ 
          quotes: jsonData["quotes"]
        },
        this.createQuote
        );
      })
      .catch((error) => {
          console.error(error)
      });
  }
  
  // Show new random quote
  createQuote() {
    let randomInt = Math.floor(Math.random() * this.state.quotes.length);
    let randomQuote = this.state.quotes[randomInt];
    this.setState({
	      currentQuote: {
          text: randomQuote["text"],
          author: randomQuote["author"]
        }
	    });
  }
  
  animate() {
    let quoteBox = document.getElementById("quote-box");
    quoteBox.classList.add("shadow");
    
    let quoteContainer = document.getElementById("quote-container");
    quoteContainer.classList.add("fadeIn");
    
    setTimeout(() => {
      quoteBox.classList.remove("shadow");
      quoteContainer.classList.remove("fadeIn");
    }, 2100);
  }
  
  handleClick() {
    this.createQuote();
    this.animate();
  }
  
  componentDidMount() {
    this.getQuotes();
    this.createQuote();
  }

  render() {
    const lineBreak = '%0a';
    const tweetUrl = "https://twitter.com/intent/tweet?" + 'text=' + this.state.currentQuote.text + lineBreak + lineBreak + '– ' + this.state.currentQuote.author;
    
    return(
      <main className="wrapper flex flex-vertical flex-jc-sb flex-ai-c">
        <h1 className="heading-xl">The Great Quotes</h1>
        <div id="quote-box" className="bg-container--secondary flex flex-vertical flex-jc-sb">
          <div id="quote-container">
            <p id="text" className="text-xl">{this.state.currentQuote.text}</p>
            <p id="author" className="text-xl">– {this.state.currentQuote.author}</p>
          </div>
          <div className="flex flex-ai-c flex-jc-sb">
            <div className="flex flex-ai-c flex-jc-sb">
              <img className="icon" src="https://img.icons8.com/color/24/000000/twitter--v2.png" alt="" />
              <a id="tweet-quote" href={tweetUrl} target="_top">Tweet this</a>
            </div>             
            <button id="new-quote" class="btn btn-primary" onClick={this.handleClick}>New quote</button>
          </div>
        </div>
        <div className="footer">
          <p className="text-xs">〰 Made by <a id="profile-link" href="https://github.com/robaish" target="_blank"> @robaish</a> 〰</p>
        </div>
      </main>
    );
  }
}

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

Console