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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>

<div id="root">
    <!-- This element's contents will be replaced with your component. -->
</div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Alegreya:ital,wght@0,500;1,400&family=Oswald&display=swap');

* {
	box-sizing: border-box;
  line-height: var(--s1);
}

/* Ratios */
:root {
  --ratio: 1.5;
  --s-5: calc(var(--s-4) / var(--ratio));
  --s-4: calc(var(--s-3) / var(--ratio));
  --s-3: calc(var(--s-2) / var(--ratio));
  --s-2: calc(var(--s-1) / var(--ratio));
  --s-1: calc(var(--s0) / var(--ratio));
  --s0: 1rem;
  --s1: calc(var(--s0) * var(--ratio));
  --s2: calc(var(--s1) * var(--ratio));
  --s3: calc(var(--s2) * var(--ratio));
  --s4: calc(var(--s3) * var(--ratio));
  --s5: calc(var(--s4) * var(--ratio));
}

/* Colors */

:root {
  --primary: #3da9fc;
  --secondary: #90b4ce;
  --tertiary: #ef4565;
  --background: #fffffe;
  --text: #094067;
}

[data-theme="dark"] {
  --primary: #ef4565;
  --secondary: #90b4ce;
  --tertiary: #3da9fc;
  --background: #094067;
  --text: #fffffe;
}

body {
  background-color: var(--background);
  color: var(--text);
}

h1, cite {
  font-family: 'Alegreya', serif;
}

p, blockquote, a {
  font-family: 'Oswald', sans-serif;
}

.quote {
  font-size: 1.2em;
  margin-bottom: var(--s-1);
}

a {
  color: var(--secondary);
}

.content {
	box-sizing: content-box;
  max-width: 80ch;
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--s1);
  padding-right: var(--s1);
  display: flex;
  flex-direction: column;
  align-items: center;
}

#quote-box {
    box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
  transition: all 0.3s cubic-bezier(.25,.8,.25,1);
}

#quote-box:hover {
  box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
}

.buttons {
  margin-top: var(--s-1);
  margin-bottom: var(--s-1);
}

.button {
  box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
  transition: all 0.3s cubic-bezier(.25,.8,.25,1);
  background-color: var(--primary);
  border: none;
  color: white;
  padding: var(--s-1) var(--s-1);
  margin-right: var(--s-1);
  margin-left: var(--s-1);
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
}

.button:hover {
  box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
}

.tweet {
  background-color: var(--tertiary);
}

              
            
!

JS

              
                
const App = () => {
  const [title, setTitle] = React.useState('Random Quote Generator');
  const [quote, setQuote] = React.useState('');
  const [quoteAuthor, setQuoteAuthor] = React.useState('');
  const [random, setRandom] = React.useState(randInt());
  // const [loading, setLoading] = React.useState(false);
  
  function handleClick(e) {
    e.preventDefault();
    console.log('Button clicked...')
    setRandom(randInt());
  }
  
  getQuote().then(response => {
    setQuote(response[random].quote);
    setQuoteAuthor(response[random].author);
    done();
  })
  
  return (
    <div class="content">
      <h1>{title}</h1>
      <div id="quote-box">
        <blockquote id="text">
          <p className="quote">
          "{quote}"
          </p>
          <cite id="author">{quoteAuthor} | <a href={`https://www.google.com/search?q=${quoteAuthor}`} target="_blank">Google them ↗</a></cite>
        </blockquote>
      </div>
      <div className="buttons">
        <a className="button" id="new-quote" onClick={handleClick} href="#"><i className="fas fa-retweet"></i> Get new quote!</a>
        <a className="button tweet" id="tweet-quote" href={`https://twitter.com/intent/tweet?text="${quote}" - ${quoteAuthor} - via https://codepen.io/originalzedders/pen/vYNzMVe`} target="_blank"><i className="fab fa-twitter"></i> Tweet this Quote!</a>
        </div>
      <ThemeSwitch />
      <Clock />
    </div>
  )
}

const element = (
  <h2>
    Hello, world!
  </h2>
);

const ThemeSwitch = () => {
  const [theme, setTheme] = React.useState('dark');
  
  function toggleTheme() {
    const currentTheme = theme === 'dark' ? 'light' : 'dark';
    setTheme(currentTheme);
    document.documentElement.setAttribute("data-theme", theme);
  }
  
  function handleClick(e) {
    e.preventDefault();
    toggleTheme();
  }
  
  return (<a className="button" href="#" onClick={handleClick}><i className="fas fa-toggle-off"></i> Switch Theme</a>);
}

class Clock extends React.Component {
  constructor(props) {
    super(props);
    this.state = { date: new Date() }
  }
  
  componentDidMount() {
    this.timerID = setInterval(
    () => this.tick(), 1000)
  }
  componentWillUnmount() {
    clearInterval(this.timerID);
  }
  
  tick() {
    this.setState({
      date: new Date()
    })
  }
  
  render() {
    return (
        <p>The time now is: {this.state.date.toLocaleTimeString()}.</p>
    );
  }
}

async function getQuote() {
  const response = await fetch('https://quotesondesign.com/wp-json/wp/v2/posts/?orderby=rand');
  const json = await response.json();
  
  return json.map((item, i) => {
     return {
       index: i,
       quote: json[i].excerpt.rendered.replace(/(<([^>]+)>)/ig,"").replace(/(&#([a-zA-Z0-9_\-]+;))/ig, "\'").trim(),
       author: json[i].title.rendered
     }
  });
}

const randInt = () => {
  return Math.floor(Math.random() * 10);
}

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

              
            
!
999px

Console