kitbash Sign in Connect agent
Components

Subscribe pill

A scattered heading, one centred sentence and the black pill. Pressing the pill widens it into an email field with a white send button; it validates in place, answers in a scattered line and closes again.

Part of the style

Ink Bleed Serif

7 parts that belong together, with their tokens, type and rules.

Preview

Code
<style>
/* Goes after the pack's base.css */
@import url("https://fonts.googleapis.com/css2?family=Inter:opsz,wght@14..32,400..700&family=Fraunces:ital,opsz,wght@1,9..144,400..600&display=swap");
:root {
  --page: #e4e4e4;
  --ink: #0b111f;
  --paper: #ffffff;
  --paper-soft: rgba(255, 255, 255, 0.6);
  --font-text: "Inter", "Helvetica Neue", Arial, sans-serif;
  --font-button: "Fraunces", Georgia, serif;
}
</style>

<section class="subscribe">
  <svg class="subscribe__defs" width="0" height="0" aria-hidden="true" focusable="false">
    <filter id="subscribe-heading" x="-10%" y="-25%" width="120%" height="150%" color-interpolation-filters="sRGB">
      <feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="1" seed="5" />
      <feDisplacementMap in="SourceGraphic" scale="22" xChannelSelector="R" yChannelSelector="G" />
    </filter>
    <filter id="subscribe-grain" x="-5%" y="-25%" width="110%" height="150%" color-interpolation-filters="sRGB">
      <feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="1" seed="3" />
      <feDisplacementMap in="SourceGraphic" scale="11" xChannelSelector="R" yChannelSelector="G" />
    </filter>
  </svg>

  <h2 class="subscribe__title">Letters from the boiler room</h2>
  <p class="subscribe__text">One short letter on the first Sunday of the month: new hours, guest hosts and what is in the tubs.</p>

  <form class="subscribe__pill" novalidate>
    <button class="subscribe__open" type="button" aria-expanded="false">Join the Mild Steam list</button>
    <div class="subscribe__fields" inert>
      <label class="subscribe__field">
        <span class="subscribe__label">Email</span>
        <input class="subscribe__input" type="email" name="email" autocomplete="email" placeholder="you@example.com" required />
      </label>
      <button class="subscribe__send" type="submit">Send</button>
    </div>
  </form>
  <p class="subscribe__status" role="status"></p>
</section>

<style>
  .subscribe {
    display: grid;
    justify-items: center;
    padding: var(--space-l) var(--edge) var(--section-space);
    text-align: center;
  }
  .subscribe__defs {
    position: absolute;
  }
  .subscribe__title {
    max-width: var(--measure);
    margin: 0;
    font: inherit;
    font-size: var(--text-l);
    line-height: var(--leading-tight);
    letter-spacing: var(--tracking-display);
    text-wrap: balance;
    filter: url("#subscribe-heading");
  }
  .subscribe__text {
    max-width: var(--measure);
    margin: var(--space-l) 0;
    line-height: var(--leading-tight);
    text-wrap: balance;
  }

  /* One black pill. It is a button first, then widens into an email field with its own send button. */
  .subscribe__pill {
    display: grid;
    width: min(100%, var(--pill-closed));
    height: var(--pill-height);
    border-radius: var(--radius-pill);
    background: var(--ink);
    color: var(--paper);
    box-shadow: var(--pill-shadow);
    font-family: var(--font-button);
    font-size: var(--text-s);
    font-weight: 600;
    letter-spacing: 0;
    transition: width var(--time) var(--ease), scale var(--time) var(--ease);
  }
  .subscribe__pill:hover {
    scale: 1.03;
  }
  .subscribe__pill.is-open {
    width: min(100%, var(--pill-open));
    scale: 1;
  }
  /* The hidden half fades out first and only then leaves the tab order; the shown half is there at once, so it can take focus. */
  .subscribe__open,
  .subscribe__fields {
    grid-area: 1 / 1;
    min-width: 0;
    transition: opacity var(--time) var(--ease), visibility 0s;
  }
  .subscribe__open,
  .subscribe__send {
    border: 0;
    border-radius: var(--radius-pill);
    background: none;
    color: inherit;
    font: inherit;
    white-space: nowrap;
    cursor: pointer;
  }
  .subscribe__fields {
    display: flex;
    align-items: center;
    padding: 0 var(--space-s) 0 var(--space-m);
  }
  .subscribe__fields,
  .subscribe__pill.is-open .subscribe__open {
    opacity: 0;
    visibility: hidden;
    transition-delay: 0s, var(--time);
  }
  .subscribe__pill.is-open .subscribe__fields {
    opacity: 1;
    visibility: visible;
    transition-delay: 0s;
  }

  .subscribe__field {
    flex: 1;
    min-width: 0;
  }
  .subscribe__label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .subscribe__input {
    width: 100%;
    min-height: var(--tap);
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
  }
  .subscribe__input::placeholder {
    color: var(--paper-soft);
  }
  .subscribe__input:focus {
    outline: none;
  }
  .subscribe__input[aria-invalid="true"] {
    text-decoration: underline wavy var(--paper-soft);
  }
  .subscribe__send {
    min-width: var(--tap);
    min-height: var(--tap);
    padding: 0 var(--space-m);
    background: var(--paper);
    color: var(--ink);
  }
  .subscribe__open:focus-visible,
  .subscribe__send:focus-visible {
    outline: var(--rule) solid var(--ink);
    outline-offset: var(--rule);
  }
  .subscribe__send:focus-visible {
    outline-color: var(--paper-soft);
    outline-offset: calc(var(--rule) * -3);
  }

  .subscribe__status {
    margin: var(--space-m) 0 0;
    line-height: var(--leading-tight);
    filter: url("#subscribe-grain");
  }
  .subscribe__status:empty {
    display: none;
  }

  /* On small screens the heading takes the light scatter and the answer stays sharp. */
  @media (max-width: 44rem) {
    .subscribe__title {
      filter: url("#subscribe-grain");
    }
    .subscribe__status {
      filter: none;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .subscribe__pill,
    .subscribe__open,
    .subscribe__fields {
      transition-duration: 0s;
    }
    .subscribe__pill:hover {
      scale: 1;
    }
  }
</style>

<script>
  (() => {
    const setUpPill = (pill) => {
      const openButton = pill.querySelector(".subscribe__open");
      const fields = pill.querySelector(".subscribe__fields");
      const input = pill.querySelector(".subscribe__input");
      const status = pill.parentElement.querySelector(".subscribe__status");

      const setOpen = (isOpen) => {
        pill.classList.toggle("is-open", isOpen);
        openButton.setAttribute("aria-expanded", String(isOpen));
        openButton.inert = isOpen;
        fields.inert = !isOpen;
      };

      openButton.addEventListener("click", () => {
        setOpen(true);
        input.focus();
      });

      pill.addEventListener("submit", (event) => {
        event.preventDefault();
        const isValid = input.checkValidity();
        input.setAttribute("aria-invalid", String(!isValid));
        status.textContent = isValid ? "You are on the list. The next letter goes out on Sunday." : "That address does not look right yet.";
        if (!isValid) return;
        pill.reset();
        setOpen(false);
      });
    };

    document.querySelectorAll(".subscribe__pill").forEach(setUpPill);
  })();
</script>

Similar components

Ground landing with form

Ground landing with form

Newsletter

Newsletter

Inquiry form

Inquiry form

Ruled newsletter footer

Ruled newsletter footer

Reopening sign-up

Reopening sign-up

Guest list form

Guest list form

Start a page

Start a page

Grid enquiry form

Grid enquiry form