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 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>
  <div class="container">
    <h2 class="title">How was your day?</h2>
    <div class="buttons">
      <button class="button" value="negative">
        <span class="emoji">😩</span>
      </button>
      <button class="button" value="negative">
        <span class="emoji">😕</span>
      </button>
      <button class="button" value="positive">
        <span class="emoji">🙂</span>
      </button>
      <button class="button" value="positive">
        <span class="emoji">😍</span>
      </button>
    </div>
    <div class="feedback">
      <div class="content"></div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                :root {
  --container-width: 350px;
}
.container {
  padding: var(--space-6);
  width: var(--container-width);
  border: var(--border);
  box-shadow: var(--shadow-large);
  border-radius: var(--radius);
  background-color: var(--color-white);
}
.title {
  font-size: var(--text-md);
  margin-bottom: var(--space-4);
  color: var(--color-gray-700);
  text-align: center;
  font-weight: bold;
}
.buttons {
  display: grid;
  grid-auto-flow: column;
  gap: var(--space-4);
}
.button {
  font-size: var(--text-xl);
  height: var(--space-12);
  border: var(--border);
  border-radius: var(--radius);
  background-color: var(--color-white);
  cursor: pointer;
  outline: none;
  user-select: none;
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition-speed) var(--transition-curve);
  filter: grayscale(1) brightness(105%);
}
.button.selected {
  z-index: 2;
  background-color: var(--color-blue-200);
  filter: none;
  box-shadow: none;
  border-color: var(--color-blue-500);
}
.emoji {
  display: block;
  transition: var(--transition-bounce);
  /* Allows quicker subsequent clicks on adjecent buttons */
  pointer-events: none;
}
.emoji.emphasize {
  transform: scale(3);
}
.button:hover {
  border-color: var(--color-gray-300);
  filter: grayscale(0);
}
.button:focus {
  box-shadow: var(--shadow-focus);
  filter: grayscale(0);
}
.button:active {
  border-color: var(--color-blue-500);
  box-shadow: inset var(--shadow), var(--shadow-focus);
}
.feedback {
  height: 0;
  transition: var(--transition-bounce);
}
.content {
  visibility: hidden;
  pointer-events: none;
  opacity: 0;
}
.content.visible {
  visibility: visible;
  opacity: 1;
  pointer-events: all;
  transition: var(--transition);
}
.field {
  /* As the default is inline-block, there's unwanted margin below the field */
  display: block;
  width: 100%;
  font-size: var(--text-md);
  padding: var(--space-2);
  margin-top: var(--space-4);
  border-radius: var(--radius);
  border: var(--border);
  /* For iOS Safari */
  -webkit-appearance: none;
}
.submit {
  font-size: var(--text-md);
  padding: var(--space-3) var(--space-5);
  margin-top: var(--space-4);
  border: none;
  font-weight: bold;
  border-radius: var(--radius);
  background-color: var(--color-blue-500);
  color: var(--color-white);
  cursor: pointer;
}
.submit:hover {
  background-color: var(--color-blue-400);
}

              
            
!

JS

              
                // Get elements
const buttons = document.querySelectorAll(".button");
const title = document.querySelector(".title");
const feedback = document.querySelector(".feedback");
const content = feedback.querySelector(".content");

const giveRating = (event) => {
  // Button that was clicked
  const element = event.currentTarget;
  // Current value (negative or positive)
  const value = element.value;
  // Emoji of the button that was clicked
  const emoji = element.querySelector(".emoji");
  // If the current button is already pressed, return early
  if (element.classList.contains("selected")) {
    return;
  }
  // Remove selected statuses (class ".selected")
  buttons.forEach((button) => button.classList.remove("selected"));
  // Add selected class to the button that was clicked
  element.classList.add("selected");
  // Animate emoji within the button
  emoji.classList.add("emphasize");
  // Show proper feedback based on button value
  showFeedback(value);
  emoji.addEventListener("transitionend", () => {
    // Remove emphasis animation
    emoji.classList.remove("emphasize");
    // Defocus button
    element.blur();
  });
};

const createContent = (value) => {
  if (value === "positive") {
    content.innerHTML = `
          <p>That's great to hear, keep on rocking! 🙏🏻</p>
          `;
  } else {
    content.innerHTML = `
          <p>Oh no! We probably could've done something better. Could you shortly tell us what went wrong and we'll try to make it up for you?</p>
          <textarea rows="4" class="field" placeholder="What happened?"></textarea>
          <button class="submit">Submit</button>
          `;
  }
};

const showFeedback = (value) => {
  createContent(value);
  if (content.dataset.value === value) {
    return;
  } else {
    content.dataset.value = value;
  }
  // Hide content while transitioning
  content.classList.remove("visible");
  // Set feedback container height to be the same as the height of the current content
  feedback.style.height = `${content.scrollHeight}px`;
  // Grab top margin from title and add it to feedback container
  feedback.style.marginTop = getComputedStyle(title).marginBottom;
  feedback.addEventListener("transitionend", () => {
    // Show content after transition has ended
    content.classList.add("visible");
  });
};

// Listen for buttons
buttons.forEach((button) => {
  button.addEventListener("click", giveRating);
});

              
            
!
999px

Console